More global cleanup. Now all SESSION and COOKIE use sqgetglobalvar, what's
[squirrelmail.git] / plugins / mail_fetch / fetch.php
index 2510b6cb36a5d3516430e8b7e8913e5831e10133..b2639f105228b568bd620f0700854a29be67b588 100644 (file)
@@ -1,26 +1,40 @@
 <?php
 
-   /**
   **  mail_fetch/fetch.php
   **
   **  Copyright (c) 1999-2002 The SquirrelMail Project Team
   **  Licensed under the GNU GPL. For full terms see the file COPYING.
   **
   **  Fetch code.
   **
   **  $Id$
   **/
+/**
* mail_fetch/fetch.php
+ *
* Copyright (c) 1999-2003 The SquirrelMail Project Team
* Licensed under the GNU GPL. For full terms see the file COPYING.
+ *
* Fetch code.
+ *
* $Id$
+ */
 
-    chdir('..');
-    require_once('../src/validate.php');
-    require_once('../functions/page_header.php');
-    require_once('../functions/imap.php');
-    require_once('../src/load_prefs.php');
-    require_once('../plugins/mail_fetch/class.POP3.php');
-    require_once('../functions/i18n.php');
-    require_once( '../plugins/mail_fetch/functions.php' );
-    require_once( '../functions/html.php' );
+define('SM_PATH','../../');
 
+require_once(SM_PATH . 'include/validate.php');
+require_once(SM_PATH . 'functions/page_header.php');
+require_once(SM_PATH . 'functions/imap.php');
+require_once(SM_PATH . 'include/load_prefs.php');
+require_once(SM_PATH . 'plugins/mail_fetch/class.POP3.php');
+require_once(SM_PATH . 'plugins/mail_fetch/functions.php' );
+require_once(SM_PATH . 'functions/html.php' );
+
+/* globals */ 
+sqgetGlobalVar('username',   $username,   SQ_SESSION);
+sqgetGlobalVar('key',        $key,        SQ_COOKIE);
+sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION);
+sqgetGlobalVar('delimiter',  $delimiter,  SQ_SESSION);
+
+/* FIXME: This form, like the advanced identities form
+ * uses dynamic post variable names so we need
+ * to extract the whole $_POST array to make 
+ * things work
+ */
+
+extract($_POST);
+/* end globals */
 
     function Mail_Fetch_Status($msg) {
         echo html_tag( 'table',
@@ -39,6 +53,7 @@
     if ($mailfetch_server_number<1) $mailfetch_server_number=0;
     for ($i=0;$i<$mailfetch_server_number;$i++) {
         $mailfetch_server_[$i] = getPref($data_dir, $username, "mailfetch_server_$i");
+               $mailfetch_port_[$i] = getPref($data_dir, $username, "mailfetch_port_$i");
         $mailfetch_alias_[$i] = getPref($data_dir, $username, "mailfetch_alias_$i");
         $mailfetch_user_[$i] = getPref($data_dir, $username, "mailfetch_user_$i");
         $mailfetch_pass_[$i] = getPref($data_dir, $username, "mailfetch_pass_$i");
@@ -71,7 +86,7 @@
                          '<option value="all" selected>..' . _("All") . "...\n";
         for ($i=0;$i<$mailfetch_server_number;$i++) {
              echo "<option value=\"$i\">" .
-                  (($mailfetch_alias_[$i]=='')?$mailfetch_server_[$i]:$mailfetch_alias_[$i]) .
+                 htmlspecialchars((($mailfetch_alias_[$i]=='')?$mailfetch_server_[$i]:$mailfetch_alias_[$i])) .
                   '</option>' . "\n";
         } 
         echo            '</select>' .
@@ -83,7 +98,7 @@
              if ($mailfetch_pass_[$i]=='') {
                   echo html_tag( 'tr',
                               html_tag( 'td', _("Password for") . ' <b>' .
-                                  (($mailfetch_alias_[$i]=='')?$mailfetch_server_[$i]:$mailfetch_alias_[$i]) .
+                                  htmlspecialchars((($mailfetch_alias_[$i]=='')?$mailfetch_server_[$i]:$mailfetch_alias_[$i])) .
                                   '</b>: &nbsp; &nbsp; ',
                               'right' ) .
                               html_tag( 'td', '<input type="password" name="pass_' . $i , '">', 'left' )
         echo html_tag( 'tr',
                    html_tag( 'td', '&nbsp;' ) .
                    html_tag( 'td', '<input type=submit name=submit_mailfetch value="' . _("Fetch Mail"). '">', 'left' )
-               );
-
+               ) .
              '</table></form>';
         exit();
     }
     
     for ($i_loop=$i_start;$i_loop<$i_stop;$i_loop++) {
         $mailfetch_server=$mailfetch_server_[$i_loop];
+               $mailfetch_port=$mailfetch_port_[$i_loop];
         $mailfetch_user=$mailfetch_user_[$i_loop];
         if ($mailfetch_pass_[$i_loop]=="") {
             $tmp="pass_$i_loop";
         html_tag( 'table',
             html_tag( 'tr',
                 html_tag( 'td', '<b>' . _("Fetching from ") . 
-                    (($mailfetch_alias_[$i_loop] == '')?$mailfetch_server:$mailfetch_alias_[$i_loop]) . 
+                    htmlspecialchars((($mailfetch_alias_[$i_loop] == '')?$mailfetch_server:$mailfetch_alias_[$i_loop])) . 
                     '</b>',
                 'center' ) ,
             '', $color[9] ) ,
           
         flush();
         
-        if (!$pop3->connect($mailfetch_server)) {
+        if (!$pop3->connect($mailfetch_server,$mailfetch_port)) {
             Mail_Fetch_Status(_("Oops, ") . $pop3->ERROR );
             continue;
         }
                  // re-connect pop3
                  Mail_Fetch_Status(_("Server error...Disconnect"));
                 $pop3->quit();
-                 Mail_Fetch_Status(_("Re-connect from dead connectoin"));
+                 Mail_Fetch_Status(_("Reconnect from dead connection"));
                  if (!$pop3->connect($mailfetch_server)) {
                      Mail_Fetch_Status(_("Oops, ") . $pop3->ERROR );
                      Mail_Fetch_Status(_("Saving UIDL"));
 
                      continue;
                  }
-                 Mail_Fetch_Status(_("Re-fetching message ") . "$i" );
+                 Mail_Fetch_Status(_("Refetching message ") . "$i" );
                 $MessArray = $pop3->get($i);
 
             } // end while