Source for file setup.php

Documentation is available at setup.php

  1. <?php
  2.  
  3. /**
  4.  * mail_fetch/setup.php
  5.  *
  6.  * Setup of the mailfetch plugin.
  7.  *
  8.  * @copyright 1999-2017 The SquirrelMail Project Team
  9.  * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  10.  * @version $Id: setup.php 14681 2017-06-15 22:05:17Z pdontthink $
  11.  * @package plugins
  12.  * @subpackage mail_fetch
  13.  */
  14.  
  15. /** @ignore*/
  16.  
  17. if (defined('SM_PATH')) define('SM_PATH','../../');
  18.  
  19. // FIXME: do we have to include them here.
  20. require_once(SM_PATH 'plugins/mail_fetch/functions.php' );
  21.  
  22.     global $squirrelmail_plugin_hooks;
  23.  
  24.     $squirrelmail_plugin_hooks['menuline']['mail_fetch''mail_fetch_link';
  25.     $squirrelmail_plugin_hooks['loading_prefs']['mail_fetch''mail_fetch_load_pref';
  26.     $squirrelmail_plugin_hooks['login_verified']['mail_fetch''mail_fetch_setnew';
  27.     $squirrelmail_plugin_hooks['left_main_before']['mail_fetch''mail_fetch_login';
  28.     $squirrelmail_plugin_hooks['optpage_register_block']['mail_fetch''mailfetch_optpage_register_block';
  29.     $squirrelmail_plugin_hooks['rename_or_delete_folder']['mail_fetch''mail_fetch_folderact';
  30. }
  31.  
  32. function mail_fetch_link({
  33.     global $username$data_dir;
  34.     $mailfetch_server_number getPref($data_dir$username'mailfetch_server_number'0)
  35.     if ($mailfetch_server_number 0{
  36.         displayInternalLink('plugins/mail_fetch/fetch.php'_("Fetch")'');
  37.         echo "&nbsp;&nbsp;\n";
  38.     }
  39.  
  40. }
  41.  
  42. function mail_fetch_load_pref({
  43.     global $data_dir;
  44.     global $mailfetch_server_number;
  45.     global $mailfetch_cypher$mailfetch_port_;
  46.     global $mailfetch_server_,$mailfetch_alias_,$mailfetch_user_,$mailfetch_pass_;
  47.     global $mailfetch_lmos_$mailfetch_uidl_$mailfetch_login_$mailfetch_fref_;
  48.     global $PHP_SELF;
  49.  
  50.     sqgetGlobalVar('username'$usernameSQ_SESSION);
  51.  
  52.     ifstristr$PHP_SELF'mail_fetch' ) ) {
  53.         $mailfetch_server_number getPref($data_dir$username'mailfetch_server_number'0);
  54.         $mailfetch_cypher getPref($data_dir$username'mailfetch_cypher''on' );
  55.         if ($mailfetch_server_number<1$mailfetch_server_number=0;
  56.         for ($i=0;$i<$mailfetch_server_number;$i++{
  57.             $mailfetch_server_[$igetPref($data_dir$username"mailfetch_server_$i");
  58.             $mailfetch_port_[$igetPref($data_dir$username"mailfetch_port_$i");
  59.             $mailfetch_alias_[$i]  getPref($data_dir$username"mailfetch_alias_$i");
  60.             $mailfetch_user_[$i]   getPref($data_dir$username"mailfetch_user_$i");
  61.             $mailfetch_pass_[$i]   getPref($data_dir$username"mailfetch_pass_$i");
  62.             $mailfetch_lmos_[$i]   getPref($data_dir$username"mailfetch_lmos_$i");
  63.             $mailfetch_login_[$i]  getPref($data_dir$username"mailfetch_login_$i");
  64.             $mailfetch_fref_[$i]   getPref($data_dir$username"mailfetch_fref_$i");
  65.             $mailfetch_uidl_[$i]   getPref($data_dir$username"mailfetch_uidl_$i");
  66.             if$mailfetch_cypher   == 'on' $mailfetch_pass_[$i=    decrypt$mailfetch_pass_[$i);
  67.         }
  68.     }
  69. }
  70.  
  71. function mail_fetch_login({
  72.     require_once (SM_PATH 'include/validate.php');
  73.     include_once (SM_PATH 'functions/imap.php');
  74.     require_once (SM_PATH 'plugins/mail_fetch/class.POP3.php');
  75.     require_once (SM_PATH 'plugins/mail_fetch/functions.php');
  76.  
  77.     global $data_dir$imapServerAddress$imapPort$imap_stream_options;
  78.         
  79.     sqgetGlobalVar('username'$usernameSQ_SESSION);
  80.     sqgetGlobalVar('key',      $key,      SQ_COOKIE);
  81.  
  82.     $mailfetch_newlog getPref($data_dir$username'mailfetch_newlog');
  83.  
  84.     $outMsg '';
  85.  
  86.     $mailfetch_server_number getPref($data_dir$username'mailfetch_server_number');
  87.     if (!isset($mailfetch_server_number)) $mailfetch_server_number=0;
  88.     $mailfetch_cypher getPref($data_dir$username'mailfetch_cypher');
  89.     if ($mailfetch_server_number<1$mailfetch_server_number=0;
  90.  
  91.     for ($i_loop=0;$i_loop<$mailfetch_server_number;$i_loop++{
  92.  
  93.         $mailfetch_login_[$i_loopgetPref($data_dir$username"mailfetch_login_$i_loop");
  94.         $mailfetch_fref_[$i_loopgetPref($data_dir$username"mailfetch_fref_$i_loop");
  95.         $mailfetch_pass_[$i_loopgetPref($data_dir$username"mailfetch_pass_$i_loop");
  96.         if$mailfetch_cypher == 'on' )
  97.             $mailfetch_pass_[$i_loopdecrypt$mailfetch_pass_[$i_loop);
  98.  
  99.         if$mailfetch_pass_[$i_loop<> '' &&          // Empty passwords no allowed
  100.             ( ( $mailfetch_login_[$i_loop== 'on' &&  $mailfetch_newlog == 'on' || $mailfetch_fref_[$i_loop== 'on' ) ) {
  101.  
  102.             $mailfetch_server_[$i_loopgetPref($data_dir$username"mailfetch_server_$i_loop");
  103.             $mailfetch_port_[$i_loopgetPref($data_dir$username "mailfetch_port_$i_loop");
  104.             $mailfetch_alias_[$i_loopgetPref($data_dir$username"mailfetch_alias_$i_loop");
  105.             $mailfetch_user_[$i_loopgetPref($data_dir$username"mailfetch_user_$i_loop");
  106.             $mailfetch_lmos_[$i_loopgetPref($data_dir$username"mailfetch_lmos_$i_loop");
  107.             $mailfetch_uidl_[$i_loopgetPref($data_dir$username"mailfetch_uidl_$i_loop");
  108.             $mailfetch_subfolder_[$i_loopgetPref($data_dir$username"mailfetch_subfolder_$i_loop");
  109.  
  110.             $mailfetch_server=$mailfetch_server_[$i_loop];
  111.             $mailfetch_port=$mailfetch_port_[$i_loop];
  112.             $mailfetch_user=$mailfetch_user_[$i_loop];
  113.             $mailfetch_alias=$mailfetch_alias_[$i_loop];
  114.             $mailfetch_pass=$mailfetch_pass_[$i_loop];
  115.             $mailfetch_lmos=$mailfetch_lmos_[$i_loop];
  116.             $mailfetch_login=$mailfetch_login_[$i_loop];
  117.             $mailfetch_uidl=$mailfetch_uidl_[$i_loop];
  118.             $mailfetch_subfolder=$mailfetch_subfolder_[$i_loop];
  119.  
  120.             // $outMsg .= "$mailfetch_alias checked<br>";
  121.  
  122.             // $outMsg .= "$mailfetch_alias_[$i_loop]<br>";
  123.  
  124.             $pop3 new POP3($mailfetch_server60);
  125.  
  126.             if (!$pop3->connect($mailfetch_server,$mailfetch_port)) {
  127.                 $outMsg .= _("Warning, "$pop3->ERROR;
  128.                 continue;
  129.             }
  130.  
  131.             $imap_stream sqimap_login($username$key$imapServerAddress$imapPort10$imap_stream_options);
  132.  
  133.             $Count $pop3->login($mailfetch_user$mailfetch_pass);
  134.             if (($Count == false || $Count == -1&& $pop3->ERROR != ''{
  135.                 $outMsg .= _("Login Failed:"$pop3->ERROR;
  136.                 continue;
  137.             }
  138.  
  139.             //   register_shutdown_function($pop3->quit());
  140.  
  141.             $msglist $pop3->uidl();
  142.  
  143.             $i 1;
  144.             for ($j 1$j sizeof($msglist)$j++{
  145.                 if ($msglist["$j"== $mailfetch_uidl{
  146.                     $i $j+1;
  147.                     break;
  148.                 }
  149.             }
  150.  
  151.             if ($Count $i{
  152.                 $pop3->quit();
  153.                 continue;
  154.             }
  155.             if ($Count == 0{
  156.                 $pop3->quit();
  157.                 continue;
  158.             else {
  159.                 $newmsgcount $Count $i 1;
  160.             }
  161.  
  162.             // Faster to get them all at once
  163.             $mailfetch_uidl $pop3->uidl();
  164.  
  165.             if (is_array($mailfetch_uidl&& $mailfetch_lmos == 'on')
  166.                 $outMsg .= _("Server does not support UIDL.");
  167.  
  168.             for ($i <= $Count$i++{
  169.                 if (!ini_get('safe_mode'))
  170.                     set_time_limit(20)// 20 seconds per message max
  171.                 $Message "";
  172.                 $MessArray $pop3->get($i);
  173.  
  174.                 if ( (!$MessArrayor (gettype($MessArray!= "array")) {
  175.                     $outMsg .= _("Warning, "$pop3->ERROR;
  176.                     continue 2;
  177.                 }
  178.  
  179.                 while (list($lineNum$lineeach ($MessArray)) {
  180.                     $Message .= $line;
  181.                 }
  182.  
  183.                 /**
  184.                  * check if mail folder is not null and subscribed
  185.                  * Function can check if mail folder is only unsubscribed 
  186.                  * and use unsubscribed mail folder.
  187.                  */
  188.                 if ($mailfetch_subfolder=='' || 
  189.                     mail_fetch_check_folder($imap_stream,$mailfetch_subfolder)) {
  190.                     fputs($imap_stream"A3$i APPEND INBOX {strlen($Message"}\r\n");
  191.                 else {
  192.                     fputs($imap_stream"A3$i APPEND $mailfetch_subfolder {strlen($Message"}\r\n");
  193.                 }
  194.                 $Line fgets($imap_stream1024);
  195.                 if (substr($Line01== '+'{
  196.                     fputs($imap_stream$Message);
  197.                     fputs($imap_stream"\r\n");
  198.                     sqimap_read_data($imap_stream"A3$i"false$response$message);
  199.  
  200.                     if ($mailfetch_lmos != 'on'{
  201.                         $pop3->delete($i);
  202.                     }
  203.                 else {
  204.                     echo "$Line";
  205.                     $outMsg .= _("Error Appending Message!");
  206.                 }
  207.             }
  208.  
  209.             $pop3->quit();
  210.             sqimap_logout($imap_stream);
  211.             if (is_array($mailfetch_uidl)) {
  212.                 setPref($data_dir,$username,"mailfetch_uidl_$i_loop"array_pop($mailfetch_uidl));
  213.             }
  214.         }
  215.     }
  216.  
  217.     iftrim$outMsg <> '' {
  218.         echo '<br><font size="1">' _("Mail Fetch Result:""<br>$outMsg</font>";
  219.     }
  220.     if$mailfetch_newlog == 'on' {
  221.         setPref($data_dir$username'mailfetch_newlog''off');
  222.     }
  223. }
  224.  
  225. function mail_fetch_setnew()    {
  226.  
  227.     global $data_dir;
  228.     require_once(SM_PATH 'functions/prefs.php');
  229.  
  230.     sqgetGlobalVar('username'$usernameSQ_SESSION);
  231.  
  232.     setPref$data_dir$username'mailfetch_newlog''on' );
  233. }
  234.  
  235.     global $optpage_blocks;
  236.  
  237.     $optpage_blocks[array(
  238.         'name' => _("POP3 Fetch Mail"),
  239.         'url'  => '../plugins/mail_fetch/options.php',
  240.         'desc' => _("This configures settings for downloading email from a POP3 mailbox to your account on this server."),
  241.         'js'   => false
  242.         );
  243. }
  244.  
  245. function mail_fetch_folderact($args{
  246.     global $username$data_dir;
  247.  
  248.     if (empty($args|| !is_array($args)) {
  249.         return;
  250.     }
  251.  
  252.     /* Should be 3 ars, 1: old folder, 2: action, 3: new folder */
  253.     if (count($args!= 3{
  254.         return;
  255.     }
  256.  
  257.     list($old_folder$action$new_folder$args;
  258.  
  259.     $mailfetch_server_number getPref($data_dir$username'mailfetch_server_number');
  260.  
  261.     for ($i 0$i $mailfetch_server_number$i++{
  262.         $mailfetch_subfolder getPref($data_dir$username'mailfetch_subfolder_' $i);
  263.  
  264.         if ($mailfetch_subfolder != $old_folder{
  265.             continue;
  266.         }
  267.  
  268.         if ($action == 'delete'{
  269.             setPref($data_dir$username'mailfetch_subfolder_' $i'INBOX');
  270.         elseif ($action == 'rename'{
  271.             setPref($data_dir$username'mailfetch_subfolder_' $i$new_folder);
  272.         }
  273.     }
  274. }

Documentation generated on Wed, 17 Jan 2018 04:27:07 +0100 by phpDocumentor 1.4.3