Source for file setup.php

Documentation is available at setup.php

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

Documentation generated on Sat, 07 Oct 2006 16:33:23 +0300 by phpDocumentor 1.3.0RC6