Official Mail_Fetch version
authorphilippe_mingo <philippe_mingo@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Fri, 23 Nov 2001 19:08:56 +0000 (19:08 +0000)
committerphilippe_mingo <philippe_mingo@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Fri, 23 Nov 2001 19:08:56 +0000 (19:08 +0000)
git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@1795 7612ce4b-ef26-0410-bec9-ea0150e637f0

plugins/mail_fetch/README [new file with mode: 0644]
plugins/mail_fetch/class.POP3.php [new file with mode: 0644]
plugins/mail_fetch/fetch.php [new file with mode: 0644]
plugins/mail_fetch/functions.php [new file with mode: 0644]
plugins/mail_fetch/mailfetch.po [new file with mode: 0644]
plugins/mail_fetch/options.php [new file with mode: 0644]
plugins/mail_fetch/setup.php [new file with mode: 0644]

diff --git a/plugins/mail_fetch/README b/plugins/mail_fetch/README
new file mode 100644 (file)
index 0000000..239f9fc
--- /dev/null
@@ -0,0 +1,181 @@
+Mail Fetch -- Version 1.3.0
+
+Downloads mail from a pop3 server to your SquirrelMail account.
+
+Features
+========
+
+* Copies messages from remote server
+* Saves server, alias, username, and password in prefs file...
+* Remembers where to resume downloading messages if 
+  your pop server supports UIDL.
+* Optionally deletes mail from the remote server.
+* Allow an infinite amount of remote servers
+* Optional to not save password - prompt on check
+* Save messages into a local IMAP folder instead of INBOX
+* Check mail during login (Needs SM 1.1.3 or older). 
+* Check mail during folder refreshes.
+* Allows gettext translations.
+
+
+Description
+===========
+
+Feel like grabbing your messages from a different mail server into
+SquirrelMail?  This might be able to help.
+
+
+Configuration
+=============
+
+Under the options you can add, delete or modify server list where
+fetching mail.  For each server you can set also username and password;
+if you leave password blank, the password whore required when you fetch
+mail.  Make sure "Leave Mail On Server" is checked if you do not want 
+Mail_Fetch to delete it from the remote server.  Once configured,
+click 'Fetch' in the SquirrelMail menu to get your mail; you can fetch
+mail from all server instead or from only one by selecting the options
+dispayed.
+
+If you want to check mail periodicaly choose "Check mail during login"
+or "Check mail during folder refresh". Of course passwords have to be
+entered in order for this to work.
+
+In order to secure a little bit the system, pop3 passwords can be encrypted.
+The encryption key may be defined in to places. The first, and more secure,
+is in the httpd configuration as an enviromental variable called MF_TIT 
+only accesible from the squirrelmail directory.
+the way you can do this from apache is adding the following directives to 
+httpd.conf (supposing that squirrelmail is located at /usr/local) or an
+included configuration file:
+
+<Directory "/usr/local/squirrelmail">
+    SetEnv MF_TIT "MailFetch Secure for SquirrelMail 1.x"
+</Directory>
+
+Of course, you should replace the text inside double quotes with the key
+you want to (some kind of secret text). A please remember that the file 
+where you decided to place this must be root only readable.
+
+The second way is to edit functions.php and look for:
+
+    if( !isset( $MF_TIT ) ) {
+        $MF_TIT = "MailFetch Secure for SquirrelMail 1.x";
+    }
+
+Once again change the text "MailFetch 0.8 Secure for SquirrelMail 1.x"
+with a secret text.
+
+Please note that you must redefine passwords each time you change the key.
+
+To maintain compatibilty with older systems, mail_fetch can work with old
+pref files, with no encrypted passwords. If this occurs, you'll see that
+the "Encrypt Password" checkbox in the option page is not checked. If you
+reenter account's passwords the system will switch to encrypted mode.
+
+
+Future Work
+===========
+
+* Add IMAP server stealing
+* Limit number of pop accounts
+
+
+Installation
+============
+
+As with other plugins, just uncompress the archive in the plugins
+directory, go back to the main directory, run configure and add the plugin.
+
+Questions/comments/flames/etc can be sent to the SquirrelMail plugins list.
+
+Old versionn (0.7) has been updated from 0.6 by Philippe Mingo <mingo@rotedic.com>
+    IMPORTANT!!! This is a "secured" version, it makes a little encryption
+    of the pop3 passwords. In order to use this facility, systems that
+    have been using older versions (0.6 and lessers) should reenter
+    passwords using the modify button at the options page in order to
+    encrypt the password. The Encrypt passwords checkbox is only informative,
+    and it lets you know if passwords are secure or not.
+
+Old version (0.4) has been updated from Joshua's version 0.3 by
+    Tomaso Minelli <minni@minnata.net>
+    and Tyler (but only VERY minor stuff -- not worth really mentioning)
+
+Old version (0.3) has been updated from Tyler's original version 0.1 by
+    Joshua Pollak <pardsbane@offthehill.org>
+
+
+Translations
+============
+Translation is made in the same manner than Squirrelmail's core does.
+You need to take <plugin_name>.po file, fill the template, store it
+in the appropriate locale folder under the plugin and compile the po
+file. Better than this fill the po file and send it back to the author.
+The translation will be included in the next release of the plugin.
+
+
+Note for mod_gzip users
+=======================
+
+As fetching module shows information while fetching is taking place, it
+is a good idea to disable compression for that operation. The way to do
+this with mod_gzip is:
+
+mod_gzip_item_exclude       file fetch.php
+
+
+Note for Newmail Plugin users
+=============================
+
+In order to Newmail plugin detect new mails during folder refreshes
+make sure that Mail_Fetch is listed first that Newmail in the
+SM configuration. To do so you only have to remove Newmail plugin
+and then add it again.
+
+
+ChangeLog
+=========
+
+---------------------------------------------------------------------------
+                   Philippe Mingo <mingo@rotedic.com>
+---------------------------------------------------------------------------
+1.3.0 Official SM Version - Moved into the SM package.
+1.2.6 BugFix
+1.2.5 Bugfix
+1.2.4 Optimized class.POP3. Fixed problem with spaces in folders name.
+1.2.3 non-gettext systems now works
+1.2.2 Fixed login problems.
+1.2.1 Added polish translation.
+1.2.0 Added spanish translation.
+1.1.2 Bugfix: Missing include at login check.
+1.1.1 Bugfix: Now works with SM 1.1.1 and 1.1.2. To do this check during
+      login is disabled with these versions.
+1.1   Bugfix: Now messages deletes correctly from pop servers.
+1.0   Added check during folder refresh and check during login code.
+0.9   Added an alias for each server. Changed default encryption key, please
+      reenter passwords if you're not using environment system.
+0.8   Better encryption security through env variables.
+0.7   Added password encryption and strings internationalization. 
+----------------------------------------------------------------------------
+0.6   Bugfix for folder list and typo
+      set_time_limit of 20 seconds per message (to avoid timeout errors)
+0.5   Works properly for servers that have 0 messages to fetch
+----------------------------------------------------------------------------
+                    Tomaso Minelli <minni@minnata.net>
+----------------------------------------------------------------------------
+0.4   Allow an infinite amount of remote servers
+      If password is empty, prompt on check
+      Save messages into a local IMAP folder instead of INBOX
+      (Tyler) Uses new 1.1.1 validate.php format
+----------------------------------------------------------------------------
+                 Joshua Pollak <pardsbane@offthehill.org>
+----------------------------------------------------------------------------
+0.3   Converted fetch routine to use the POP3 object from thewebmasters.net
+      Added Leave Mail on Server option
+      Now only downloads new messages if the pop server supports UIDL.
+----------------------------------------------------------------------------      
+0.2   Now saves account information
+0.1   Initial release by Tyler Akins
+----------------------------------------------------------------------------
\ No newline at end of file
diff --git a/plugins/mail_fetch/class.POP3.php b/plugins/mail_fetch/class.POP3.php
new file mode 100644 (file)
index 0000000..ba8cd77
--- /dev/null
@@ -0,0 +1,671 @@
+<?
+
+/*
+    class.POP3.php3 v1.0    99/03/24 CDI cdi@thewebmasters.net
+    Copyright (c) 1999 - CDI (cdi@thewebmasters.net) All Rights Reserved
+    Modified by Philippe Mingo 2001 mingo@rotedic.com
+    An RFC 1939 compliant wrapper class for the POP3 protocol.
+*/
+
+class POP3 {
+    var $ERROR      = "";       //  Error string.
+
+    var $TIMEOUT    = 60;       //  Default timeout before giving up on a
+                                //  network operation.
+
+    var $COUNT      = -1;       //  Mailbox msg count
+
+    var $BUFFER     = 512;      //  Socket buffer for socket fgets() calls.
+                                //  Per RFC 1939 the returned line a POP3
+                                //  server can send is 512 bytes.
+
+    var $FP         = "";       //  The connection to the server's
+                                //  file descriptor
+
+    var $MAILSERVER = "";       // Set this to hard code the server name
+
+    var $DEBUG      = false;    // set to true to echo pop3
+                                // commands and responses to error_log
+                                // this WILL log passwords!
+
+    var $BANNER     = "";       //  Holds the banner returned by the
+                                //  pop server - used for apop()
+
+    var $RFC1939    = true;     //  Set by noop(). See rfc1939.txt
+                                //
+
+    var $ALLOWAPOP  = false;    //  Allow or disallow apop()
+                                //  This must be set to true
+                                //  manually
+
+    function POP3 ( $server = "", $timeout = "" ) {
+        settype($this->BUFFER,"integer");
+        if( !empty($server) ) {
+            // Do not allow programs to alter MAILSERVER
+            // if it is already specified. They can get around
+            // this if they -really- want to, so don't count on it.
+            if(empty($this->MAILSERVER))
+                $this->MAILSERVER = $server;
+        }
+        if(!empty($timeout)) {
+            settype($timeout,"integer");
+            $this->TIMEOUT = $timeout;
+            set_time_limit($timeout);
+        }
+        return true;
+    }
+
+    function update_timer () {
+        set_time_limit($this->TIMEOUT);
+        return true;
+    }
+
+    function connect ($server, $port = 110)  {
+        //  Opens a socket to the specified server. Unless overridden,
+        //  port defaults to 110. Returns true on success, false on fail
+
+        // If MAILSERVER is set, override $server with it's value
+
+        if(!empty($this->MAILSERVER))
+            $server = $this->MAILSERVER;
+
+        if(empty($server)){
+            $this->ERROR = _("POP3 connect:") . ' ' . _("No server specified");
+            unset($this->FP);
+            return false;
+        }
+
+        $fp = fsockopen("$server", $port, $errno, $errstr);
+
+        if(!$fp) {
+            $this->ERROR = _("POP3 connect:") . ' ' . _("Error ") . "[$errno] [$errstr]";
+            unset($this->FP);
+            return false;
+        }
+
+        socket_set_blocking($fp,-1);
+        $this->update_timer();
+        $reply = fgets($fp,$this->BUFFER);
+        $reply = $this->strip_clf($reply);
+        if($this->DEBUG)
+            error_log("POP3 SEND [connect: $server] GOT [$reply]",0);
+        if(!$this->is_ok($reply)) {
+            $this->ERROR = _("POP3 connect:") . ' ' . _("Error ") . "[$reply]";
+            unset($this->FP);
+            return false;
+        }
+        $this->FP = $fp;
+        $this->BANNER = $this->parse_banner($reply);
+        $this->RFC1939 = $this->noop();
+        if($this->RFC1939) {
+            $this->ERROR = _("POP3: premature NOOP OK, NOT an RFC 1939 Compliant server");
+            $this->quit();
+            return false;
+        } else
+            return true;
+    }
+
+    function noop () {
+    
+        if(!isset($this->FP)) {
+            $this->ERROR = _("POP3 noop:") . ' ' . _("No connection to server");
+            return false;
+        } else {
+            $cmd = "NOOP";
+            $reply = $this->send_cmd( $cmd );
+            return( $this->is_ok( $reply ) );
+        }
+    }
+
+    function user ($user = "") {
+        // Sends the USER command, returns true or false
+
+        if( empty($user) ) {
+            $this->ERROR = _("POP3 user:") . ' ' . _("no login ID submitted");
+            return false;
+        } elseif(!isset($this->FP)) {
+            $this->ERROR = _("POP3 user:") . ' ' . _("connection not established");
+            return false;
+        } else {
+            $reply = $this->send_cmd("USER $user");
+            if(!$this->is_ok($reply)) {
+                $this->ERROR = _("POP3 user:") . ' ' . _("Error ") . "[$reply]";
+                return false;
+            } else
+                return true;
+        }
+    }
+
+    function pass ($pass = "")     {
+        // Sends the PASS command, returns # of msgs in mailbox,
+        // returns false (undef) on Auth failure
+
+        if(empty($pass)) {
+            $this->ERROR = _("POP3 pass:") . ' ' . _("No password submitted");
+            return false;
+        } elseif(!isset($this->FP)) {
+            $this->ERROR = _("POP3 pass:") . ' ' . _("connection not established");
+            return false;
+        } else {
+            $reply = $this->send_cmd("PASS $pass");
+            if(!$this->is_ok($reply)) {
+                $this->ERROR = _("POP3 pass:") . ' ' . _("authentication failed ") . "[$reply]";
+                $this->quit();
+                return false;
+            } else {
+                //  Auth successful.
+                $count = $this->last("count");
+                $this->COUNT = $count;
+                $this->RFC1939 = $this->noop();
+                if(!$this->RFC1939) {
+                    $this->ERROR = _("POP3 pass:") . ' ' . _("NOOP failed. Server not RFC 1939 compliant");
+                    $this->quit();
+                    return false;
+                } else
+                    return $count;
+            }
+        }
+    }
+
+    function apop ($login,$pass) {
+        //  Attempts an APOP login. If this fails, it'll
+        //  try a standard login. YOUR SERVER MUST SUPPORT
+        //  THE USE OF THE APOP COMMAND!
+        //  (apop is optional per rfc1939)
+
+        if(!isset($this->FP)) {
+            $this->ERROR = _("POP3 apop:") . ' ' . _("No connection to server");
+            return false;
+        } elseif(!$this->ALLOWAPOP) {
+            $retVal = $this->login($login,$pass);
+            return $retVal;
+        } elseif(empty($login)) {
+            $this->ERROR = _("POP3 apop:") . ' ' . _("No login ID submitted");
+            return false;
+        } elseif(empty($pass)) {
+            $this->ERROR = _("POP3 apop:") . ' ' . _("No password submitted");
+            return false;
+        } else {
+            $banner = $this->BANNER;
+            if( (!$banner) or (empty($banner)) ) {
+                $this->ERROR = _("POP3 apop:") . ' ' . _("No server banner") . ' - ' . _("abort");
+                $retVal = $this->login($login,$pass);
+                return $retVal;
+            } else {
+                $AuthString = $banner;
+                $AuthString .= $pass;
+                $APOPString = md5($AuthString);
+                $cmd = "APOP $login $APOPString";
+                $reply = $this->send_cmd($cmd);
+                if(!$this->is_ok($reply)) {
+                    $this->ERROR = _("POP3 apop:") . ' ' . _("apop authentication failed") . ' - ' . _("abort");
+                    $retVal = $this->login($login,$pass);
+                    return $retVal;
+                } else {
+                    //  Auth successful.
+                    $count = $this->last("count");
+                    $this->COUNT = $count;
+                    $this->RFC1939 = $this->noop();
+                    if(!$this->RFC1939) {
+                        $this->ERROR = _("POP3 apop:") . ' ' . _("NOOP failed. Server not RFC 1939 compliant");
+                        $this->quit();
+                        return false;
+                    } else
+                        return $count;
+                }
+            }
+        }
+    }
+
+    function login ($login = "", $pass = "") {
+        // Sends both user and pass. Returns # of msgs in mailbox or
+        // false on failure (or -1, if the error occurs while getting
+        // the number of messages.)
+
+        if( !isset($this->FP) ) {
+            $this->ERROR = _("POP3 login:") . ' ' . _("No connection to server");
+            return false;
+        } else {
+            $fp = $this->FP;
+            if( !$this->user( $login ) ) {
+                //  Preserve the error generated by user()
+                return false;
+            } else {
+                $count = $this->pass($pass);
+                if( (!$count) || ($count == -1) ) {
+                    //  Preserve the error generated by last() and pass()
+                    return false;
+                } else
+                    return $count;
+            }
+        }
+    }
+
+    function top ($msgNum, $numLines = "0") {
+        //  Gets the header and first $numLines of the msg body
+        //  returns data in an array with each returned line being
+        //  an array element. If $numLines is empty, returns
+        //  only the header information, and none of the body.
+
+        if(!isset($this->FP)) {
+            $this->ERROR = _("POP3 top:") . ' ' . _("No connection to server");
+            return false;
+        }
+        $this->update_timer();
+
+        $fp = $this->FP;
+        $buffer = $this->BUFFER;
+        $cmd = "TOP $msgNum $numLines";
+        fwrite($fp, "TOP $msgNum $numLines\r\n");
+        $reply = fgets($fp, $buffer);
+        $reply = $this->strip_clf($reply);
+        if($this->DEBUG) {
+            @error_log("POP3 SEND [$cmd] GOT [$reply]",0);
+        }
+        if(!$this->is_ok($reply))
+        {
+            $this->ERROR = _("POP3 top:") . ' ' . _("Error ") . "[$reply]";
+            return false;
+        }
+
+        $count = 0;
+        $MsgArray = array();
+
+        $line = fgets($fp,$buffer);
+        while ( !ereg("^\.\r\n",$line))
+        {
+            $MsgArray[$count] = $line;
+            $count++;
+            $line = fgets($fp,$buffer);
+            if(empty($line))    { break; }
+        }
+
+        return $MsgArray;
+    }
+
+    function pop_list ($msgNum = "") {
+        //  If called with an argument, returns that msgs' size in octets
+        //  No argument returns an associative array of undeleted
+        //  msg numbers and their sizes in octets
+
+        if(!isset($this->FP))
+        {
+            $this->ERROR = _("POP3 pop_list:") . ' ' . _("No connection to server");
+            return false;
+        }
+        $fp = $this->FP;
+        $Total = $this->COUNT;
+        if( (!$Total) or ($Total == -1) )
+        {
+            return false;
+        }
+        if($Total == 0)
+        {
+            return array("0","0");
+            // return -1;   // mailbox empty
+        }
+
+        $this->update_timer();
+
+        if(!empty($msgNum))
+        {
+            $cmd = "LIST $msgNum";
+            fwrite($fp,"$cmd\r\n");
+            $reply = fgets($fp,$this->BUFFER);
+            $reply = $this->strip_clf($reply);
+            if($this->DEBUG) {
+                @error_log("POP3 SEND [$cmd] GOT [$reply]",0);
+            }
+            if(!$this->is_ok($reply))
+            {
+                $this->ERROR = _("POP3 pop_list:") . ' ' . _("Error ") . "[$reply]";
+                return false;
+            }
+            list($junk,$num,$size) = explode(" ",$reply);
+            return $size;
+        }
+        $cmd = "LIST";
+        $reply = $this->send_cmd($cmd);
+        if(!$this->is_ok($reply))
+        {
+            $reply = $this->strip_clf($reply);
+            $this->ERROR = _("POP3 pop_list:") . ' ' . _("Error ") .  "[$reply]";
+            return false;
+        }
+        $MsgArray = array();
+        $MsgArray[0] = $Total;
+        for($msgC=1;$msgC <= $Total; $msgC++)
+        {
+            if($msgC > $Total) { break; }
+            $line = fgets($fp,$this->BUFFER);
+            $line = $this->strip_clf($line);
+            if(ereg("^\.",$line))
+            {
+                $this->ERROR = _("POP3 pop_list:") . ' ' . _("Premature end of list");
+                return false;
+            }
+            list($thisMsg,$msgSize) = explode(" ",$line);
+            settype($thisMsg,"integer");
+            if($thisMsg != $msgC)
+            {
+                $MsgArray[$msgC] = "deleted";
+            }
+            else
+            {
+                $MsgArray[$msgC] = $msgSize;
+            }
+        }
+        return $MsgArray;
+    }
+
+    function get ($msgNum) {
+        //  Retrieve the specified msg number. Returns an array
+        //  where each line of the msg is an array element.
+
+        if(!isset($this->FP))
+        {
+            $this->ERROR = _("POP3 get:") . ' ' . _("No connection to server");
+            return false;
+        }
+
+        $this->update_timer();
+
+        $fp = $this->FP;
+        $buffer = $this->BUFFER;
+        $cmd = "RETR $msgNum";
+        $reply = $this->send_cmd($cmd);
+
+        if(!$this->is_ok($reply))
+        {
+            $this->ERROR = _("POP3 get:") . ' ' . _("Error ") . "[$reply]";
+            return false;
+        }
+
+        $count = 0;
+        $MsgArray = array();
+
+        $line = fgets($fp,$buffer);
+        while ( !ereg("^\.\r\n",$line))
+        {
+            $MsgArray[$count] = $line;
+            $count++;
+            $line = fgets($fp,$buffer);
+            if(empty($line))    { break; }
+        }
+        return $MsgArray;
+    }
+
+    function last ( $type = "count" ) {
+        //  Returns the highest msg number in the mailbox.
+        //  returns -1 on error, 0+ on success, if type != count
+        //  results in a popstat() call (2 element array returned)
+
+        $last = -1;
+        if(!isset($this->FP))
+        {
+            $this->ERROR = _("POP3 last:") . ' ' . _("No connection to server");
+            return $last;
+        }
+
+        $reply = $this->send_cmd("STAT");
+        if(!$this->is_ok($reply))
+        {
+            $this->ERROR = _("POP3 last:") . ' ' . _("Error ") . "[$reply]";
+            return $last;
+        }
+
+        $Vars = explode(" ",$reply);
+        $count = $Vars[1];
+        $size = $Vars[2];
+        settype($count,"integer");
+        settype($size,"integer");
+        if($type != "count")
+        {
+            return array($count,$size);
+        }
+        return $count;
+    }
+
+    function reset () {
+        //  Resets the status of the remote server. This includes
+        //  resetting the status of ALL msgs to not be deleted.
+        //  This method automatically closes the connection to the server.
+
+        if(!isset($this->FP))
+        {
+            $this->ERROR = _("POP3 reset:") . ' ' . _("No connection to server");
+            return false;
+        }
+        $reply = $this->send_cmd("RSET");
+        if(!$this->is_ok($reply))
+        {
+            //  The POP3 RSET command -never- gives a -ERR
+            //  response - if it ever does, something truely
+            //  wild is going on.
+
+            $this->ERROR = _("POP3 reset:") . ' ' . _("Error ") . "[$reply]";
+            @error_log("POP3 reset: ERROR [$reply]",0);
+        }
+        $this->quit();
+        return true;
+    }
+
+    function send_cmd ( $cmd = "" )
+    {
+        //  Sends a user defined command string to the
+        //  POP server and returns the results. Useful for
+        //  non-compliant or custom POP servers.
+        //  Do NOT includ the \r\n as part of your command
+        //  string - it will be appended automatically.
+
+        //  The return value is a standard fgets() call, which
+        //  will read up to $this->BUFFER bytes of data, until it
+        //  encounters a new line, or EOF, whichever happens first.
+
+        //  This method works best if $cmd responds with only
+        //  one line of data.
+
+        if(!isset($this->FP))
+        {
+            $this->ERROR = _("POP3 send_cmd:") . ' ' . _("No connection to server");
+            return false;
+        }
+
+        if(empty($cmd))
+        {
+            $this->ERROR = _("POP3 send_cmd:") . ' ' . _("Empty command string");
+            return "";
+        }
+
+        $fp = $this->FP;
+        $buffer = $this->BUFFER;
+        $this->update_timer();
+        fwrite($fp,"$cmd\r\n");
+        $reply = fgets($fp,$buffer);
+        $reply = $this->strip_clf($reply);
+        if($this->DEBUG) { @error_log("POP3 SEND [$cmd] GOT [$reply]",0); }
+        return $reply;
+    }
+
+    function quit() {
+        //  Closes the connection to the POP3 server, deleting
+        //  any msgs marked as deleted.
+
+        if(!isset($this->FP))
+        {
+            $this->ERROR = _("POP3 quit:") . ' ' . _("connection does not exist");
+            return false;
+        }
+        $fp = $this->FP;
+        $cmd = "QUIT";
+        fwrite($fp,"$cmd\r\n");
+        $reply = fgets($fp,$this->BUFFER);
+        $reply = $this->strip_clf($reply);
+        if($this->DEBUG) { @error_log("POP3 SEND [$cmd] GOT [$reply]",0); }
+        fclose($fp);
+        unset($this->FP);
+        return true;
+    }
+
+    function popstat () {
+        //  Returns an array of 2 elements. The number of undeleted
+        //  msgs in the mailbox, and the size of the mbox in octets.
+
+        $PopArray = $this->last("array");
+
+        if($PopArray == -1) { return false; }
+
+        if( (!$PopArray) or (empty($PopArray)) )
+        {
+            return false;
+        }
+        return $PopArray;
+    }
+
+    function uidl ($msgNum = "")
+    {
+        //  Returns the UIDL of the msg specified. If called with
+        //  no arguments, returns an associative array where each
+        //  undeleted msg num is a key, and the msg's uidl is the element
+        //  Array element 0 will contain the total number of msgs
+
+        if(!isset($this->FP)) {
+            $this->ERROR = _("POP3 uidl:") . ' ' . _("No connection to server");
+            return false;
+        }
+
+        $fp = $this->FP;
+        $buffer = $this->BUFFER;
+
+        if(!empty($msgNum)) {
+            $cmd = "UIDL $msgNum";
+            $reply = $this->send_cmd($cmd);
+            if(!$this->is_ok($reply))
+            {
+                $this->ERROR = _("POP3 uidl:") . ' ' . _("Error ") . "[$reply]";
+                return false;
+            }
+            list ($ok,$num,$myUidl) = explode(" ",$reply);
+            return $myUidl;
+        } else {
+            $this->update_timer();
+
+            $UIDLArray = array();
+            $Total = $this->COUNT;
+            $UIDLArray[0] = $Total;
+
+            if ($Total < 1)
+            {
+                return $UIDLArray;
+            }
+            $cmd = "UIDL";
+            fwrite($fp, "UIDL\r\n");
+            $reply = fgets($fp, $buffer);
+            $reply = $this->strip_clf($reply);
+            if($this->DEBUG) { @error_log("POP3 SEND [$cmd] GOT [$reply]",0); }
+            if(!$this->is_ok($reply))
+            {
+                $this->ERROR = _("POP3 uidl:") . ' ' . _("Error ") . "[$reply]";
+                return false;
+            }
+
+            $line = "";
+            $count = 1;
+            $line = fgets($fp,$buffer);
+            while ( !ereg("^\.\r\n",$line)) {
+                if(ereg("^\.\r\n",$line)) {
+                    break;
+                }
+                list ($msg,$msgUidl) = explode(" ",$line);
+                $msgUidl = $this->strip_clf($msgUidl);
+                if($count == $msg) {
+                    $UIDLArray[$msg] = $msgUidl;
+                }
+                else
+                {
+                    $UIDLArray[$count] = "deleted";
+                }
+                $count++;
+                $line = fgets($fp,$buffer);
+            }
+        }
+        return $UIDLArray;
+    }
+
+    function delete ($msgNum = "") {
+        //  Flags a specified msg as deleted. The msg will not
+        //  be deleted until a quit() method is called.
+
+        if(!isset($this->FP))
+        {
+            $this->ERROR = _("POP3 delete:") . ' ' . _("No connection to server");
+            return false;
+        }
+        if(empty($msgNum))
+        {
+            $this->ERROR = _("POP3 delete:") . ' ' . _("No msg number submitted");
+            return false;
+        }
+        $reply = $this->send_cmd("DELE $msgNum");
+        if(!$this->is_ok($reply))
+        {
+            $this->ERROR = _("POP3 delete:") . ' ' . _("Command failed ") . "[$reply]";
+            return false;
+        }
+        return true;
+    }
+
+    //  *********************************************************
+
+    //  The following methods are internal to the class.
+
+    function is_ok ($cmd = "") {
+        //  Return true or false on +OK or -ERR
+
+        if( empty($cmd) )
+            return false;
+        else
+            return( ereg ("^\+OK", $cmd ) );
+    }
+
+    function strip_clf ($text = "") {
+        // Strips \r\n from server responses
+
+        if(empty($text))
+            return $text;
+        else {
+            $stripped = str_replace("\r",'',$text);
+            $stripped = str_replace("\n",'',$stripped);
+            return $stripped;
+        }
+    }
+
+    function parse_banner ( $server_text ) {
+        $outside = true;
+        $banner = "";
+        $length = strlen($server_text);
+        for($count =0; $count < $length; $count++)
+        {
+            $digit = substr($server_text,$count,1);
+            if(!empty($digit))             {
+                if( (!$outside) && ($digit != '<') && ($digit != '>') )
+                {
+                    $banner .= $digit;
+                }
+                if ($digit == '<')
+                {
+                    $outside = false;
+                }
+                if($digit == '>')
+                {
+                    $outside = true;
+                }
+            }
+        }
+        $banner = $this->strip_clf($banner);    // Just in case
+        return "<$banner>";
+    }
+
+}   // End class
+
+?>
diff --git a/plugins/mail_fetch/fetch.php b/plugins/mail_fetch/fetch.php
new file mode 100644 (file)
index 0000000..400707a
--- /dev/null
@@ -0,0 +1,224 @@
+<?php
+   /*
+    *  Mail Fetch
+    *
+    */
+
+   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' );
+
+    
+function Mail_Fetch_Status($msg) {
+    echo '<table width=90%><tr><td>' . 
+         htmlspecialchars( $msg ) . 
+         '</td></tr></table>';
+    flush();
+}
+    displayPageHeader($color, 'None');
+
+    $mailfetch_server_number = getPref($data_dir, $username, "mailfetch_server_number");
+    if (!isset($mailfetch_server_number)) $mailfetch_server_number=0;
+    $mailfetch_cypher = getPref($data_dir, $username, "mailfetch_cypher");
+    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_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");
+        $mailfetch_lmos_[$i] = getPref($data_dir, $username, "mailfetch_lmos_$i");
+        $mailfetch_login_[$i] = getPref($data_dir, $username, "mailfetch_login_$i");
+        $mailfetch_uidl_[$i] = getPref($data_dir, $username, "mailfetch_uidl_$i");
+        $mailfetch_subfolder_[$i] = getPref($data_dir, $username, "mailfetch_subfolder_$i");
+        if( $mailfetch_cypher == 'on' ) {
+            $mailfetch_pass_[$i] = decrypt( $mailfetch_pass_[$i] );
+        }
+    }
+    
+    echo '<br><center>';
+    
+    echo '<TABLE WIDTH=95% COLS=1 ALIGN=CENTER>' .
+            "<TR><TD BGCOLOR=\"$color[0]\" ALIGN=CENTER><b>" . _("Remote POP server Fetching Mail") . '</b></TD></TR>' .
+         '</TABLE>';
+    
+    if (!isset( $server_to_fetch ) ) {
+        
+        echo '<font size=-5><BR></font>' .
+             "<form action=\"$PHP_SELF\" METHOD=POST TARGET=_self>" .
+             '<TABLE WIDTH=70% COLS=2 ALIGN=CENTER>' .
+                '<TR>' .
+                    '<TD ALIGN=RIGHT>' . _("Select Server:") . ' &nbsp; &nbsp; </TD>' .
+                    '<TD><SELECT NAME=server_to_fetch SIZE=1>' .
+                        '<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]);
+        } 
+        echo            '</SELECT>' .
+                    '</TD>' .
+                '</TR>';
+        
+        //if password not set, ask for it
+        for ($i=0;$i<$mailfetch_server_number;$i++) {
+             if ($mailfetch_pass_[$i]=="") {
+                  echo "<tr>" .
+                       '<TD ALIGN=RIGHT>' . _("Password for") . ' <B>' . (($mailfetch_alias_[$i]=='')?$mailfetch_server_[$i]:$mailfetch_alias_[$i]) . '</B>: &nbsp; &nbsp; </TD>' .
+                       "<TD><INPUT TYPE=PASSWORD NAME=pass_$i></TD>" .
+                       "</TR>";
+             }
+        }
+        echo '<TR>' .
+                '<TD>&nbsp;</TD>' .
+                '<TD><input type=submit name=submit_mailfetch value="' . _("Fetch Mail"). '"></TD>'.
+                '</TR>' .
+             '</TABLE></form>';
+        exit();
+    }
+
+    if ( $server_to_fetch == 'all' ) {
+        $i_start = 0;
+        $i_stop = $mailfetch_server_number;
+    } else {
+        $i_start = $server_to_fetch;
+        $i_stop = $i_start+1;
+    }
+    
+    for ($i_loop=$i_start;$i_loop<$i_stop;$i_loop++) {
+        $mailfetch_server=$mailfetch_server_[$i_loop];
+        $mailfetch_user=$mailfetch_user_[$i_loop];
+        if ($mailfetch_pass_[$i_loop]=="") {
+            $tmp="pass_$i_loop";
+            $mailfetch_pass=$$tmp;
+        } else {
+            $mailfetch_pass=$mailfetch_pass_[$i_loop];
+        }
+        $mailfetch_lmos=$mailfetch_lmos_[$i_loop];
+        $mailfetch_login=$mailfetch_login_[$i_loop];
+        $mailfetch_uidl=$mailfetch_uidl_[$i_loop];
+        $mailfetch_subfolder=$mailfetch_subfolder_[$i_loop];
+        
+        
+        $pop3 = new POP3($mailfetch_server, 60);
+        
+        echo "<br><table width=90%><tr bgcolor=\"$color[9]\"><td><b>" . 
+            _("Fetching from ") . 
+            (($mailfetch_alias_[$i_loop] == '')?$mailfetch_server:$mailfetch_alias_[$i_loop]) . 
+            "</b></td></tr></table>";
+          
+        flush();
+        
+        if (!$pop3->connect($mailfetch_server)) {
+            Mail_Fetch_Status(_("Oops, ") . $pop3->ERROR );
+            continue;
+        }
+        
+        Mail_Fetch_Status(_("Opening IMAP server"));
+        $imap_stream = sqimap_login($username, $key, $imapServerAddress, $imapPort, 10);
+        
+        Mail_Fetch_Status(_("Opening POP server"));
+        $Count = $pop3->login($mailfetch_user, $mailfetch_pass);
+        if (($Count == false || $Count == -1) && $pop3->ERROR != '') {
+            Mail_Fetch_Status(_("Login Failed:") . $pop3->ERROR );
+            continue;
+        }
+        
+        //   register_shutdown_function($pop3->quit());
+        
+        $msglist = $pop3->uidl();
+        
+        $i = 1;
+        for ($j = 1; $j < sizeof($msglist); $j++) {
+           if ($msglist["$j"] == $mailfetch_uidl) {
+                $i = $j+1;
+                break;
+           }
+        }
+
+        if ($Count < $i) {
+            Mail_Fetch_Status(_("Login OK: No new messages"));
+            $pop3->quit();
+            continue;
+        }
+        if ($Count == 0) {
+            Mail_Fetch_Status(_("Login OK: Inbox EMPTY"));
+            $pop3->quit();
+            continue;
+        } else {
+            $newmsgcount = $Count - $i + 1;
+            Mail_Fetch_Status(_("Login OK: Inbox contains [") . $newmsgcount . _("] messages"));
+        }
+        
+        Mail_Fetch_Status(_("Fetching UIDL..."));
+        // Faster to get them all at once
+        $mailfetch_uidl = $pop3->uidl();
+        
+        if (! is_array($mailfetch_uidl) && $mailfetch_lmos == 'on')
+            Mail_Fetch_Status(_("Server does not support UIDL."));
+
+        if ($mailfetch_lmos == 'on') {
+            Mail_Fetch_Status(_("Leaving Mail on Server..."));
+        } else {
+            Mail_Fetch_Status(_("Deleting messages from server..."));
+        }
+        
+        for (; $i <= $Count; $i++) {
+            Mail_Fetch_Status(_("Fetching message ") . "$i" );
+            set_time_limit(20); // 20 seconds per message max
+            $Message = "";
+            $MessArray = $pop3->get($i);
+            
+            if ( (!$MessArray) or (gettype($MessArray) != "array")) {
+                  Mail_Fetch_Status(_("Oops, ") . $pop3->ERROR);
+                  continue 2;
+            }
+            
+            while (list($lineNum, $line) = each ($MessArray)) {
+                 $Message .= $line;
+            }
+            
+            if ($mailfetch_subfolder=="") {
+                fputs($imap_stream, "A3$i APPEND INBOX {" . (strlen($Message) - 1) . "}\r\n");
+            } else {
+                fputs($imap_stream, "A3$i APPEND \"$mailfetch_subfolder\" {" . (strlen($Message) - 1) . "}\r\n");
+            }
+            $Line = fgets($imap_stream, 1024);
+            if (substr($Line, 0, 1) == '+') {
+                fputs($imap_stream, $Message);
+                sqimap_read_data($imap_stream, "A3$i", false, $response, $message);
+                Mail_Fetch_Status(_("Message appended to mailbox"));
+                
+                if ($mailfetch_lmos != 'on') {
+                   if( $pop3->delete($i) ) {
+                        Mail_Fetch_Status(_("Message ") . $i . _(" deleted from Remote Server!"));
+                   } else {
+                        Mail_Fetch_Status(_("Delete failed:") . $pop3->ERROR );
+                   }
+                }
+            } else {
+                echo "$Line";
+                Mail_Fetch_Status(_("Error Appending Message!"));
+            }
+        }
+        
+        Mail_Fetch_Status(_("Closing POP"));
+        $pop3->quit();
+        Mail_Fetch_Status(_("Logging out from IMAP"));
+        sqimap_logout($imap_stream);
+        if (is_array($mailfetch_uidl)) {
+            Mail_Fetch_Status(_("Saving UIDL"));
+            setPref($data_dir,$username,"mailfetch_uidl_$i_loop", array_pop($mailfetch_uidl));
+        }
+        
+        Mail_Fetch_Status(_("Done"));
+
+   }
+
+?>
+</center>
+</body>
+</html>
\ No newline at end of file
diff --git a/plugins/mail_fetch/functions.php b/plugins/mail_fetch/functions.php
new file mode 100644 (file)
index 0000000..c426e27
--- /dev/null
@@ -0,0 +1,70 @@
+<?php
+
+/*
+ *
+ * Original code from LexZEUS <lexzeus@mifinca.com>
+ * and josh@superfork.com (extracted from php manual)
+ * Adapted for MailFetch by Philippe Mingo <mingo@rotedic.com>
+ *
+ */
+
+
+    function hex2bin( $data ) {
+
+        /* Original code by josh@superfork.com */
+
+        $len = strlen($data);
+        for( $i=0; $i < $len; $i += 2 ) {
+            $newdata .= pack( "C", hexdec( substr( $data, $i, 2) ) );
+        }
+        return $newdata;
+    }
+
+    function mf_keyED( $txt ) {
+
+        global $MF_TIT;
+
+        if( !isset( $MF_TIT ) ) {
+            $MF_TIT = "MailFetch Secure for SquirrelMail 1.x";
+        }
+
+        $encrypt_key = md5( $MF_TIT );
+        $ctr = 0;
+        $tmp = "";
+        for( $i = 0; $i < strlen( $txt ); $i++ ) {
+            if( $ctr == strlen( $encrypt_key ) ) $ctr=0;
+            $tmp.= substr( $txt, $i, 1 ) ^ substr( $encrypt_key, $ctr, 1 );
+            $ctr++;
+        }
+        return $tmp;
+    }
+
+    function encrypt( $txt ) {
+
+        srand( (double) microtime() * 1000000 );
+        $encrypt_key = md5( rand( 0, 32000 ) );
+        $ctr = 0;
+        $tmp = "";
+        for( $i = 0; $i < strlen( $txt ); $i++ ) {
+        if ($ctr==strlen($encrypt_key)) $ctr=0;
+            $tmp.= substr($encrypt_key,$ctr,1) .
+                (substr($txt,$i,1) ^ substr($encrypt_key,$ctr,1));
+        $ctr++;
+        }
+        return bin2hex( mf_keyED( $tmp ) );
+
+    }
+
+    function decrypt( $txt ) {
+
+        $txt = mf_keyED( hex2bin( $txt ) );
+        $tmp = '';
+        for ( $i=0; $i < strlen( $txt ); $i++ ) {
+            $md5 = substr( $txt, $i, 1 );
+            $i++;
+            $tmp.= ( substr( $txt, $i, 1 ) ^ $md5 );
+        }
+        return $tmp;
+    }
+
+?>
\ No newline at end of file
diff --git a/plugins/mail_fetch/mailfetch.po b/plugins/mail_fetch/mailfetch.po
new file mode 100644 (file)
index 0000000..b229071
--- /dev/null
@@ -0,0 +1,394 @@
+# SOME DESCRIPTIVE TITLE.
+# Copyright (C) YEAR Free Software Foundation, Inc.
+# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
+#
+#, fuzzy
+msgid ""
+msgstr ""
+"Project-Id-Version: PACKAGE VERSION\n"
+"POT-Creation-Date: 2001-08-01 17:22+0200\n"
+"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
+"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
+"Language-Team: LANGUAGE <LL@li.org>\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=CHARSET\n"
+"Content-Transfer-Encoding: ENCODING\n"
+
+#: fetch.php:198
+msgid " deleted from Remote Server!"
+msgstr ""
+
+#: options.php:58 options.php:90
+msgid "Add Server"
+msgstr ""
+
+#: options.php:63 options.php:153
+msgid "Alias:"
+msgstr ""
+
+#: fetch.php:57
+msgid "All"
+msgstr ""
+
+#: options.php:89 options.php:186
+msgid "Check mail during folder refresh"
+msgstr ""
+
+#: options.php:88 options.php:184
+msgid "Check mail during login"
+msgstr ""
+
+#: fetch.php:209
+msgid "Closing POP"
+msgstr ""
+
+#: class.POP3.php:668
+msgid "Command failed "
+msgstr ""
+
+#: options.php:132
+msgid "Confirm Deletion of a Server"
+msgstr ""
+
+#: options.php:137
+msgid "Confirm delete of selected server?"
+msgstr ""
+
+#: options.php:122
+msgid "Delete"
+msgstr ""
+
+#: options.php:112
+msgid "Delete Server"
+msgstr ""
+
+#: fetch.php:200
+msgid "Delete failed:"
+msgstr ""
+
+#: fetch.php:167
+msgid "Deleting messages from server..."
+msgstr ""
+
+#: fetch.php:218
+msgid "Done"
+msgstr ""
+
+#: class.POP3.php:522
+msgid "Empty command string"
+msgstr ""
+
+#: options.php:51
+msgid "Encrypt passwords (informative only)"
+msgstr ""
+
+#: class.POP3.php:94 class.POP3.php:108 class.POP3.php:157 class.POP3.php:309
+#: class.POP3.php:364 class.POP3.php:375 class.POP3.php:424 class.POP3.php:458
+#: class.POP3.php:492 class.POP3.php:595 class.POP3.php:620
+msgid "Error "
+msgstr ""
+
+#: fetch.php:205 setup.php:267
+msgid "Error Appending Message!"
+msgstr ""
+
+#: setup.php:21
+msgid "Fetch"
+msgstr ""
+
+#: fetch.php:77
+msgid "Fetch Mail"
+msgstr ""
+
+#: options.php:128 options.php:142 options.php:191
+msgid "Fetching Servers"
+msgstr ""
+
+#: fetch.php:157
+msgid "Fetching UIDL..."
+msgstr ""
+
+#: fetch.php:110
+msgid "Fetching from "
+msgstr ""
+
+#: fetch.php:171
+msgid "Fetching message "
+msgstr ""
+
+#: options.php:196
+msgid "Hey! Wath do You are looking for?"
+msgstr ""
+
+#: options.php:47
+msgid "If you leave password empty, it will be required when you fetch mail."
+msgstr ""
+
+#: options.php:87 options.php:182
+msgid "Leave Mail on Server"
+msgstr ""
+
+#: fetch.php:165
+msgid "Leaving Mail on Server..."
+msgstr ""
+
+#: fetch.php:211
+msgid "Logging out from IMAP"
+msgstr ""
+
+#: fetch.php:127 setup.php:205
+msgid "Login Failed:"
+msgstr ""
+
+#: fetch.php:149
+msgid "Login OK: Inbox EMPTY"
+msgstr ""
+
+#: fetch.php:154
+msgid "Login OK: Inbox contains ["
+msgstr ""
+
+#: fetch.php:144
+msgid "Login OK: No new messages"
+msgstr ""
+
+#: setup.php:280
+msgid "Mail Fetch Result:"
+msgstr ""
+
+#: fetch.php:198
+msgid "Message "
+msgstr ""
+
+#: fetch.php:194
+msgid "Message appended to mailbox"
+msgstr ""
+
+#: options.php:105
+msgid "Modify"
+msgstr ""
+
+#: options.php:96 options.php:187
+msgid "Modify Server"
+msgstr ""
+
+#: options.php:146
+msgid "Mofify a Server"
+msgstr ""
+
+#: class.POP3.php:191 class.POP3.php:251
+msgid "NOOP failed. Server not RFC 1939 compliant"
+msgstr ""
+
+#: class.POP3.php:128 class.POP3.php:207 class.POP3.php:266 class.POP3.php:293
+#: class.POP3.php:336 class.POP3.php:411 class.POP3.php:451 class.POP3.php:482
+#: class.POP3.php:516 class.POP3.php:582 class.POP3.php:657
+msgid "No connection to server"
+msgstr ""
+
+#: class.POP3.php:219
+msgid "No login ID submitted"
+msgstr ""
+
+#: class.POP3.php:662
+msgid "No msg number submitted"
+msgstr ""
+
+#: class.POP3.php:170 class.POP3.php:224
+msgid "No password submitted"
+msgstr ""
+
+#: class.POP3.php:230
+msgid "No server banner"
+msgstr ""
+
+#: class.POP3.php:85
+msgid "No server specified"
+msgstr ""
+
+#: options.php:106 options.php:123
+msgid "No-one server in use. Try to add."
+msgstr ""
+
+#: fetch.php:117 fetch.php:177
+msgid "Oops, "
+msgstr ""
+
+#: fetch.php:121
+msgid "Opening IMAP server"
+msgstr ""
+
+#: fetch.php:124
+msgid "Opening POP server"
+msgstr ""
+
+#: class.POP3.php:207 class.POP3.php:219 class.POP3.php:224 class.POP3.php:230
+#: class.POP3.php:241 class.POP3.php:251
+msgid "POP3 apop:"
+msgstr ""
+
+#: class.POP3.php:85 class.POP3.php:94 class.POP3.php:108
+msgid "POP3 connect:"
+msgstr ""
+
+#: class.POP3.php:657 class.POP3.php:662 class.POP3.php:668
+msgid "POP3 delete:"
+msgstr ""
+
+#: class.POP3.php:411 class.POP3.php:424
+msgid "POP3 get:"
+msgstr ""
+
+#: class.POP3.php:451 class.POP3.php:458
+msgid "POP3 last:"
+msgstr ""
+
+#: class.POP3.php:266
+msgid "POP3 login:"
+msgstr ""
+
+#: class.POP3.php:128
+msgid "POP3 noop:"
+msgstr ""
+
+#: class.POP3.php:170 class.POP3.php:175 class.POP3.php:181 class.POP3.php:191
+msgid "POP3 pass:"
+msgstr ""
+
+#: class.POP3.php:336 class.POP3.php:364 class.POP3.php:375 class.POP3.php:387
+msgid "POP3 pop_list:"
+msgstr ""
+
+#: class.POP3.php:543
+msgid "POP3 quit:"
+msgstr ""
+
+#: class.POP3.php:482 class.POP3.php:492
+msgid "POP3 reset:"
+msgstr ""
+
+#: class.POP3.php:516 class.POP3.php:522
+msgid "POP3 send_cmd:"
+msgstr ""
+
+#: class.POP3.php:293 class.POP3.php:309
+msgid "POP3 top:"
+msgstr ""
+
+#: class.POP3.php:582 class.POP3.php:595 class.POP3.php:620
+msgid "POP3 uidl:"
+msgstr ""
+
+#: class.POP3.php:146 class.POP3.php:151 class.POP3.php:157
+msgid "POP3 user:"
+msgstr ""
+
+#: class.POP3.php:117
+msgid "POP3: premature NOOP OK, NOT an RFC 1939 Compliant server"
+msgstr ""
+
+#: fetch.php:70
+msgid "Password for"
+msgstr ""
+
+#: options.php:65 options.php:157
+msgid "Password:"
+msgstr ""
+
+#: class.POP3.php:387
+msgid "Premature end of list"
+msgstr ""
+
+#: fetch.php:46
+msgid "Remote POP server Fetching Mail"
+msgstr ""
+
+#: options.php:43
+msgid "Remote POP server settings"
+msgstr ""
+
+#: fetch.php:214
+msgid "Saving UIDL"
+msgstr ""
+
+#: fetch.php:55
+msgid "Select Server:"
+msgstr ""
+
+#: options.php:136
+msgid "Selected Server:"
+msgstr ""
+
+#: options.php:100 options.php:116
+msgid "Server Name:"
+msgstr ""
+
+#: fetch.php:162 setup.php:236
+msgid "Server does not support UIDL."
+msgstr ""
+
+#: options.php:62 options.php:151
+msgid "Server:"
+msgstr ""
+
+#: setup.php:35
+msgid "Simple POP3 Fetch Mail"
+msgstr ""
+
+#: options.php:66 options.php:159
+msgid "Store in Folder:"
+msgstr ""
+
+#: setup.php:38
+msgid ""
+"This configures settings for downloading email from a pop3 mailbox to your "
+"account on this server."
+msgstr ""
+
+#: options.php:194
+msgid "Undefined Function"
+msgstr ""
+
+#: options.php:64 options.php:155
+msgid "Username:"
+msgstr ""
+
+#: setup.php:197 setup.php:244
+msgid "Warning, "
+msgstr ""
+
+#: options.php:45
+msgid ""
+"You should be aware that the encryption used to store your password is not "
+"perfectly secure.  However, if you are using pop, there is inherently no "
+"encryption anyway. Additionally, the encryption that we do to save it on the "
+"server can be undone by a hacker reading the source to this file."
+msgstr ""
+
+#: fetch.php:154
+msgid "] messages"
+msgstr ""
+
+#: class.POP3.php:230 class.POP3.php:241
+msgid "abort"
+msgstr ""
+
+#: class.POP3.php:241
+msgid "apop authentication failed"
+msgstr ""
+
+#: class.POP3.php:181
+msgid "authentication failed "
+msgstr ""
+
+#: class.POP3.php:543
+msgid "connection does not exist"
+msgstr ""
+
+#: class.POP3.php:151 class.POP3.php:175
+msgid "connection not established"
+msgstr ""
+
+#: class.POP3.php:146
+msgid "no login ID submitted"
+msgstr ""
diff --git a/plugins/mail_fetch/options.php b/plugins/mail_fetch/options.php
new file mode 100644 (file)
index 0000000..55f0077
--- /dev/null
@@ -0,0 +1,197 @@
+<?php
+   /*
+    *  Mail Fetch
+    *  ==========
+    *
+    *  Original idea and code by Tyler Akins
+    *
+    *  10/07/2001 mingo@rotedic.com modified to encrypt stored passwords
+    *
+    */
+
+    chdir('..');
+    require_once('../src/validate.php');
+    require_once('../functions/imap.php');
+    require_once('../src/load_prefs.php');
+    require_once('../functions/i18n.php');
+
+    displayPageHeader( $color, _("None") );
+
+    $mailfetch_server_number = getPref($data_dir, $username, "mailfetch_server_number");
+    if (!isset($mailfetch_server_number)) $mailfetch_server_number=0;
+
+    $mailfetch_cypher = getPref( $data_dir, $username, "mailfetch_cypher" );
+    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_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");
+        $mailfetch_lmos_[$i] = getPref($data_dir, $username, "mailfetch_lmos_$i");
+        $mailfetch_login_[$i] = getPref($data_dir, $username, "mailfetch_login_$i");
+        $mailfetch_fref_[$i] = getPref($data_dir, $username, "mailfetch_fref_$i");
+        $mailfetch_uidl_[$i] = getPref($data_dir, $username, "mailfetch_uidl_$i");
+        $mailfetch_subfolder_[$i] = getPref($data_dir, $username, "mailfetch_subfolder_$i");
+        if( $mailfetch_cypher == 'on' ) $mailfetch_pass_[$i] = decrypt( $mailfetch_pass_[$i] );
+    }
+
+
+    echo '<BR><form method=post action="../../src/options.php">' .
+            "<TABLE WIDTH=95% COLS=1 ALIGN=CENTER><TR><TD BGCOLOR=\"$color[0]\" ALIGN=CENTER><b>" . _("Remote POP server settings") . '</b></TD></TR></TABLE>' .
+            '<TABLE WIDTH=95% COLS=1 ALIGN=CENTER><TR><TD>' .
+            _("You should be aware that the encryption used to store your password is not perfectly secure.  However, if you are using pop, there is inherently no encryption anyway. Additionally, the encryption that we do to save it on the server can be undone by a hacker reading the source to this file." ) .
+            '</TD></TR><TR><TD>' .
+            _("If you leave password empty, it will be required when you fetch mail.") .
+            '</TD></TR>' .
+            '<tr><td align=right><input type=checkbox name=mf_cypher ' .
+            (($mailfetch_cypher=='on')?'checked >':'>') .
+            _("Encrypt passwords (informative only)") . ' </td><tr>' .
+            '</TABLE></td></tr>';
+
+    //if dosen't select any option
+    if (!isset($mf_action)) {
+
+            echo '<TABLE WIDTH=70% COLS=1 ALIGN=CENTER>' .
+                "  <TR><TD BGCOLOR=\"$color[9]\" ALIGN=CENTER><b>" . _("Add Server") . '</b></TD></TR>' .
+                "  <TR><TD BGCOLOR=\"$color[0]\" ALIGN=CENTER>" .
+                "<INPUT TYPE=\"hidden\" NAME=\"mf_sn\" VALUE=\"$mailfetch_server_number\">" .
+                '<INPUT TYPE="hidden" NAME="mf_action" VALUE="add"><table>' .
+                '<tr><th align=right>' . _("Server:") . '</th><td><input type=text name=mf_server value="" size=40></td></tr>' .
+                '<tr><th align=right>' . _("Alias:") . '</th><td><input type=text name=mf_alias value="" size=20></td></tr>' .
+                '<tr><th align=right>' . _("Username:") . '</th><td><input type=text name=mf_user value="" size=20></td></tr>' .
+                '<tr><th align=right>' . _("Password:") . '</th><td><input type=password name=mf_pass value="" size=20></td></tr>' .
+                '<tr><th align=right>' . _("Store in Folder:") . '</th><td>';
+            $imapConnection = sqimap_login ($username, $key, $imapServerAddress, $imapPort, 0);
+            $boxes = sqimap_mailbox_list($imapConnection);
+            echo '<SELECT NAME=mf_subfolder><OPTION SELECTED VALUE="">INBOX';
+            for ($i = 0; $i < count($boxes); $i++) {
+                if (in_array('noinferiors', $boxes[$i]['flags'])) {
+                    if ((strtolower($boxes[$i]["unformatted"]) == 'inbox') &&
+                ($default_sub_of_inbox == true)) {
+                            $box = $boxes[$i]["unformatted"];
+                            $box2 = str_replace(' ', '&nbsp;', $boxes[$i]["unformatted-disp"]);
+                            echo "<OPTION VALUE=\"$box\">$box2";
+                    } else {
+                            $box = $boxes[$i]["unformatted"];
+                            $box2 = str_replace(' ', '&nbsp;', $boxes[$i]["unformatted-disp"]);
+                            if (strtolower($imap_server_type) != "courier" ||
+                                strtolower($box) != "inbox.trash")
+                                echo "<OPTION VALUE=\"$box\">$box2";
+                    }
+                }
+            }
+            echo '</SELECT></td></tr>' .
+                '<tr><th align=right>&nbsp;</th><td><input type=checkbox name=mf_lmos checked>' . _("Leave Mail on Server") . '</td></tr>' .
+                '<tr><th align=right>&nbsp;</th><td><input type=checkbox name=mf_login>' . _("Check mail during login") . '</td></tr>' .
+                '<tr><th align=right>&nbsp;</th><td><input type=checkbox name=mf_fref>' . _("Check mail during folder refresh") . '</td></tr>' .
+                '<tr><td align=center colspan=2><input type=submit name=submit_mailfetch value="' . _("Add Server") . '"></td></tr>' .
+                '</table></form></td></tr></TABLE>';
+
+            // Modify Server
+            echo '<font size=-5><BR></font>' .
+                '<TABLE WIDTH=70% COLS=1 ALIGN=CENTER>' .
+                "<TR><TD BGCOLOR=\"$color[9]\" ALIGN=CENTER><b>" . _("Modify Server") . '</b></TD></TR>' .
+                "<TR><TD BGCOLOR=\"$color[0]\" ALIGN=CENTER>";
+            if ($mailfetch_server_number>0) {
+                echo "<form action=\"$PHP_SELF\" METHOD=\"GET\" TARGET=_self>";
+                echo '<b>' . _("Server Name:") . '</b> <SELECT NAME="mf_sn">';
+                for ($i=0;$i<$mailfetch_server_number;$i++) {
+                    echo "<OPTION VALUE=\"$i\">" .
+                        (($mailfetch_alias_[$i]=='')?$mailfetch_server_[$i]:$mailfetch_alias_[$i]) . "</OPTION>>";
+                }
+                echo '</SELECT>&nbsp;&nbsp;<INPUT TYPE="hidden" NAME="mf_action" VALUE="modify"><INPUT TYPE=submit name=submit_mailfetch value="' . _("Modify") . '"></form>';
+            } else { echo _("No-one server in use. Try to add."); }
+            echo '</TD></TR></TABLE>';
+
+            // Delete Server
+            echo '<font size=-5><BR></font>' .
+                '<TABLE WIDTH=70% COLS=1 ALIGN=CENTER>' .
+                "<TR><TD BGCOLOR=\"$color[9]\" ALIGN=CENTER><b>" . _("Delete Server") . '</b></TD></TR>' .
+                "<TR><TD BGCOLOR=\"$color[0]\" ALIGN=CENTER>";
+            if ($mailfetch_server_number>0) {
+                echo "<form action=\"$PHP_SELF\" METHOD=\"GET\" TARGET=_self>" .
+                    '<b>' . _("Server Name:") . '</b> <SELECT NAME="mf_sn">';
+
+                for ($i=0;$i<$mailfetch_server_number;$i++) {
+                    echo "<OPTION VALUE=\"$i\">" .
+                        (($mailfetch_alias_[$i]=='')?$mailfetch_server_[$i]:$mailfetch_alias_[$i]) . "</OPTION>>";
+                }
+                echo '</SELECT>&nbsp;&nbsp;<INPUT TYPE="hidden" NAME="mf_action" VALUE="delete"><INPUT TYPE=submit name=submit_mailfetch value="' . _("Delete") . '"></form>';
+            } else { echo _("No-one server in use. Try to add."); }
+            echo '</TD></TR></TABLE>';
+
+        } elseif ($mf_action=="delete") { //erase confirmation about a server
+            echo '<TABLE WIDTH=95% COLS=1 ALIGN=CENTER>' .
+                "<TR><TD BGCOLOR=\"$color[0]\" ALIGN=CENTER><b>" . _("Fetching Servers") . '</b></TD></TR>' .
+                '</TABLE>' .
+                '<font size=-5><BR></font>' .
+                '<TABLE WIDTH=70% COLS=1 ALIGN=CENTER>' .
+                "<TR><TD BGCOLOR=\"$color[9]\" ALIGN=CENTER><b>" . _("Confirm Deletion of a Server") . '</b></TD></TR>' .
+                "<TR><TD BGCOLOR=\"$color[0]\" ALIGN=CENTER>" .
+                "<INPUT TYPE=\"hidden\" NAME=\"mf_sn\" VALUE=\"$mf_sn\">" .
+                '<INPUT TYPE="hidden" NAME="mf_action" VALUE="confirm_delete">' .
+                '<br>' . _("Selected Server:") . "<b>$mailfetch_server_[$mf_sn]</b><br>" .
+                _("Confirm delete of selected server?") . '<br><br>' .
+                '<input type=submit name=submit_mailfetch value="Confirm Delete">' .
+                '</form></TD></TR></TABLE>';
+        } elseif ($mf_action=="modify") { //modify a server
+            echo '<TABLE WIDTH=95% COLS=1 ALIGN=CENTER>' .
+                "<TR><TD BGCOLOR=\"$color[0]\" ALIGN=CENTER><b>" . _("Fetching Servers") . '</b></TD></TR>' .
+                '</TABLE>' .
+                '<font size=-5><BR></font>' .
+                '<TABLE WIDTH=70% COLS=1 ALIGN=CENTER>' .
+                "<TR><TD BGCOLOR=\"$color[9]\" ALIGN=CENTER><b>" . _("Mofify a Server") . '</b></TD></TR>' .
+                "<TR><TD BGCOLOR=\"$color[0]\" ALIGN=CENTER>" .
+                "<INPUT TYPE=\"hidden\" NAME=\"mf_sn\" VALUE=\"$mf_sn\">" .
+                '<INPUT TYPE="hidden" NAME="mf_action" VALUE="confirm_modify">' .
+                '<table>' .
+                '<tr><th align=right>' . _("Server:") . '</th>' .
+                "<td><input type=text name=mf_server value=\"$mailfetch_server_[$mf_sn]\" size=40></td></tr>" .
+                '<tr><th align=right>' . _("Alias:") . '</th>' .
+                "<td><input type=text name=mf_alias value=\"$mailfetch_alias_[$mf_sn]\" size=40></td></tr>" .
+                '<tr><th align=right>' . _("Username:") . '</th>' .
+                "<td><input type=text name=mf_user value=\"$mailfetch_user_[$mf_sn]\" size=20></td></tr>" .
+                '<tr><th align=right>' . _("Password:") . '</th>' .
+                "<td><input type=password name=mf_pass value=\"$mailfetch_pass_[$mf_sn]\" size=20></td></tr>" .
+                '<tr><th align=right>' . _("Store in Folder:") . '</th><td>';
+            $imapConnection = sqimap_login ($username, $key, $imapServerAddress, $imapPort, 0);
+            $boxes = sqimap_mailbox_list($imapConnection);
+            echo "<SELECT NAME=mf_subfolder>";
+            echo "<OPTION " . ($mailfetch_subfolder_[$mf_sn]==""?"SELECTED":"") . ' VALUE="">INBOX';
+            for ($i = 0; $i < count($boxes); $i++) {
+                if (in_array('noinferiors', $boxes[$i]['flags'])) {
+                    if ((strtolower($boxes[$i]["unformatted"]) == "inbox") && ($default_sub_of_inbox == true)) {
+                            $box = $boxes[$i]["unformatted"];
+                            $box2 = str_replace(' ', '&nbsp;', $boxes[$i]["unformatted-disp"]);
+                            echo "<OPTION " . (strcmp($mailfetch_subfolder_[$mf_sn],$box)==0?"SELECTED":"") . " VALUE=\"$box\">$box2";
+                    } else {
+                            $box = $boxes[$i]["unformatted"];
+                            $box2 = str_replace(' ', '&nbsp;', $boxes[$i]["unformatted-disp"]);
+                            if (strtolower($imap_server_type) != "courier" ||
+                                strtolower($box) != "inbox.trash")
+                                echo "<OPTION " . (strcmp($mailfetch_subfolder_[$mf_sn],$box)==0?"SELECTED":"") . " VALUE=\"$box\">$box2";
+                    }
+                }
+            }
+            echo '</SELECT></td></tr>' .
+                '<tr><th align=right>&nbsp;</th>' .
+                '<td><input type=checkbox name=mf_lmos ' . (($mailfetch_lmos_[$mf_sn] == 'on')?'checked':'') .
+                '>' . _("Leave Mail on Server") . '</td></tr>' .
+                '<tr><th align=right>&nbsp;</TH><td><input type=checkbox name=mf_login ' . ( ($mailfetch_login_[$mf_sn] == 'on')?'checked':'') .
+                '>' . _("Check mail during login") . '</td></tr>' .
+                '<tr><th align=right>&nbsp;</TH><td><input type=checkbox name=mf_fref ' . ( ($mailfetch_fref_[$mf_sn] == 'on')?'checked':'') .
+                '>' . _("Check mail during folder refresh") . '</td></tr>' .
+                '<tr><td align=center colspan=2><input type=submit name=submit_mailfetch value="' . _("Modify Server") . '"></td></tr>' .
+                '</table></form></TD></TR></TABLE>';
+        } else { //unsupported action
+            echo '</form><TABLE WIDTH=95% COLS=1 ALIGN=CENTER>' .
+                "<TR><TD BGCOLOR=\"$color[0]\" ALIGN=CENTER><b>" . _("Fetching Servers") . '</b></TD></TR>' .
+                '</TABLE><BR>' .
+                '<TABLE WIDTH=70% COLS=1 ALIGN=CENTER>' .
+                "<TR><TD BGCOLOR=\"$color[9]\" ALIGN=CENTER><b>" . _("Undefined Function") . '</b></TD></TR>' .
+                "<TR><TD BGCOLOR=\"$color[0]\" ALIGN=CENTER><b>" .
+                _("Hey! Wath do You are looking for?") . '</b></TD></TR></TABLE>';
+        }
+
+    ?>
+</body></html>
\ No newline at end of file
diff --git a/plugins/mail_fetch/setup.php b/plugins/mail_fetch/setup.php
new file mode 100644 (file)
index 0000000..cbf4d91
--- /dev/null
@@ -0,0 +1,287 @@
+<?php
+
+    require_once( '../plugins/mail_fetch/functions.php' );
+
+    function squirrelmail_plugin_init_mail_fetch() {
+        global $squirrelmail_plugin_hooks;
+        global $mailbox, $imap_stream, $imapConnection;
+
+        $squirrelmail_plugin_hooks["menuline"]["mail_fetch"] = 'mail_fetch_link';
+        $squirrelmail_plugin_hooks["options_save"]["mail_fetch"] = "mail_fetch_save_pref";
+        $squirrelmail_plugin_hooks["loading_prefs"]["mail_fetch"] = "mail_fetch_load_pref";
+        $squirrelmail_plugin_hooks["login_verified"]["mail_fetch"] = "mail_fetch_setnew";
+        $squirrelmail_plugin_hooks["left_main_before"]["mail_fetch"] = "mail_fetch_login";
+        $squirrelmail_plugin_hooks['optpage_register_block']['mail_fetch'] = 'mailfetch_optpage_register_block';
+
+    }
+
+    function mail_fetch_link() {
+
+        displayInternalLink('plugins/mail_fetch/fetch.php', _("Fetch"), '');
+        echo '&nbsp;&nbsp;';
+
+    }
+
+    function mail_fetch_load_pref() {
+
+        global $username,$data_dir;
+        global $mailfetch_server_number;
+        global $mailfetch_cypher;
+        global $mailfetch_server_,$mailfetch_alias_,$mailfetch_user_,$mailfetch_pass_;
+        global $mailfetch_lmos_, $mailfetch_uidl_, $mailfetch_login_, $mailfetch_fref_;
+        global $PHP_SELF;
+
+        if( stristr( $PHP_SELF, 'mail_fetch'    ) ) {
+            $mailfetch_server_number = getPref($data_dir, $username,    "mailfetch_server_number");
+            if (!isset($mailfetch_server_number)) $mailfetch_server_number=0;
+            $mailfetch_cypher = getPref($data_dir, $username, "mailfetch_cypher");
+            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_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");
+                $mailfetch_lmos_[$i]   = getPref($data_dir, $username, "mailfetch_lmos_$i");
+                $mailfetch_login_[$i]  = getPref($data_dir, $username, "mailfetch_login_$i");
+                $mailfetch_fref_[$i]   = getPref($data_dir, $username, "mailfetch_fref_$i");
+                $mailfetch_uidl_[$i]   = getPref($data_dir, $username, "mailfetch_uidl_$i");
+                if( $mailfetch_cypher   == 'on' ) $mailfetch_pass_[$i] =    decrypt( $mailfetch_pass_[$i] );
+            }
+        }
+    }
+
+    function mail_fetch_save_pref() {
+        global $username,$data_dir;
+        global $mf_server, $mf_user, $mf_pass, $mf_lmos, $mf_alias;
+        global $mf_cypher;
+        global $mf_uidl;
+        global $mf_login, $mf_fref, $submit_mailfetch;
+        global $mf_action, $mf_sn, $mf_subfolder;
+
+        if (isset($submit_mailfetch))   {
+            if ($mf_action=="add") {
+                //add new server
+                if ($mf_sn<1) $mf_sn=0;
+                if (!isset($mf_server)) return;
+                setPref($data_dir,$username,"mailfetch_server_$mf_sn", (isset($mf_server)?$mf_server:""));
+                setPref($data_dir,$username,"mailfetch_alias_$mf_sn", (isset($mf_alias)?$mf_alias:""));
+                setPref($data_dir,$username,"mailfetch_user_$mf_sn",(isset($mf_user)?$mf_user:""));
+                setPref($data_dir,$username,"mailfetch_pass_$mf_sn",(isset($mf_pass)?encrypt( $mf_pass )    :""));
+                if( $mf_cypher <> 'on' ) SetPref($data_dir,$username,"mailfetch_cypher",    'on');
+                setPref($data_dir,$username,"mailfetch_lmos_$mf_sn",(isset($mf_lmos)?$mf_lmos:""));
+                setPref($data_dir,$username,"mailfetch_login_$mf_sn",(isset($mf_login)?$mf_login:""));
+                setPref($data_dir,$username,"mailfetch_fref_$mf_sn",(isset($mf_fref)?$mf_fref:""));
+                setPref($data_dir,$username,"mailfetch_subfolder_$mf_sn",(isset($mf_subfolder)?$mf_subfolder:""));
+                $mf_sn++;
+                setPref($data_dir,$username,"mailfetch_server_number", $mf_sn);
+            } elseif ($mf_action=="confirm_modify") {
+                //modify    a server
+                if (!isset($mf_server)) return;
+                setPref($data_dir,$username,"mailfetch_server_$mf_sn", (isset($mf_server)?$mf_server:""));
+                setPref($data_dir,$username,"mailfetch_alias_$mf_sn", (isset($mf_alias)?$mf_alias:""));
+                setPref($data_dir,$username,"mailfetch_user_$mf_sn",(isset($mf_user)?$mf_user:""));
+                setPref($data_dir,$username,"mailfetch_pass_$mf_sn",(isset($mf_pass)?encrypt( $mf_pass )    :""));
+                if( $mf_cypher <> 'on' ) setPref($data_dir,$username,"mailfetch_cypher", 'on');
+                setPref($data_dir,$username,"mailfetch_lmos_$mf_sn",(isset($mf_lmos)?$mf_lmos:""));
+                setPref($data_dir,$username,"mailfetch_login_$mf_sn",(isset($mf_login)?$mf_login:""));
+                setPref($data_dir,$username,"mailfetch_fref_$mf_sn",(isset($mf_fref)?$mf_fref:""));
+                setPref($data_dir,$username,"mailfetch_subfolder_$mf_sn",(isset($mf_subfolder)?$mf_subfolder:""));
+            } elseif ($mf_action=="confirm_delete") {
+                //delete    a server
+                $mailfetch_server_number    = getPref($data_dir, $username, "mailfetch_server_number");
+                if ($mf_sn+1==$mailfetch_server_number) {
+                    //is the last server, whe can only decrase $mailfetch_server_number
+                    $mailfetch_server_number--;
+                    setPref($data_dir,$username,"mailfetch_server_number", $mailfetch_server_number);
+                } else {
+                    //if not the last, all the sequel server come up one step
+                    //then whe decrase $mailfetch_server_number
+                    $mailfetch_server_number--;
+                    for ($i=$mf_sn;$i<$mailfetch_server_number;$i++) {
+                        $tmp=$i+1;
+                        setPref($data_dir,$username,"mailfetch_server_$mf_sn", getPref($data_dir, $username, "mailfetch_server_$tmp"));
+                        setPref($data_dir,$username,"mailfetch_alias_$mf_sn", getPref($data_dir, $username, "mailfetch_alias_$tmp"));
+                        setPref($data_dir,$username,"mailfetch_user_$mf_sn", getPref($data_dir, $username, "mailfetch_user_$tmp"));
+                        setPref($data_dir,$username,"mailfetch_pass_$mf_sn",(isset($mf_pass)?encrypt( $mf_pass ) :""));
+                        // if( $mf_cypher <> 'on' ) setPref($data_dir,$username,"mailfetch_cypher", 'on');
+                        setPref($data_dir,$username,"mailfetch_lmos_$mf_sn", getPref($data_dir, $username, "mailfetch_lmos_$tmp"));
+                        setPref($data_dir,$username,"mailfetch_login_$mf_sn", getPref($data_dir, $username, "mailfetch_login_$tmp"));
+                        setPref($data_dir,$username,"mailfetch_fref_$mf_sn", getPref($data_dir, $username, "mailfetch_fref_$tmp"));
+                        setPref($data_dir,$username,"mailfetch_subfolder_$mf_sn", getPref($data_dir, $username, "mailfetch_subfolder_$tmp"));
+                    }
+                    setPref($data_dir,$username,"mailfetch_server_number", $mailfetch_server_number);
+                }
+            }
+        }
+    }
+
+    function mail_fetch_login() {
+
+        require_once ('../src/validate.php');
+        require_once ('../functions/imap.php');
+        require_once ('../plugins/mail_fetch/class.POP3.php');
+        require_once ('../plugins/mail_fetch/functions.php');
+        require_once('../functions/i18n.php');
+
+        global $username, $data_dir, $key,$imapServerAddress,$imapPort;
+
+        $mailfetch_newlog = getPref($data_dir, $username, 'mailfetch_newlog');
+
+        $outMsg = '';
+
+        $mailfetch_server_number = getPref($data_dir, $username, "mailfetch_server_number");
+        if (!isset($mailfetch_server_number)) $mailfetch_server_number=0;
+        $mailfetch_cypher = getPref($data_dir, $username, "mailfetch_cypher");
+        if ($mailfetch_server_number<1) $mailfetch_server_number=0;
+
+        for ($i_loop=0;$i_loop<$mailfetch_server_number;$i_loop++) {
+
+            $mailfetch_login_[$i_loop] = getPref($data_dir, $username, "mailfetch_login_$i_loop");
+            $mailfetch_fref_[$i_loop] = getPref($data_dir, $username, "mailfetch_fref_$i_loop");
+            $mailfetch_pass_[$i_loop] = getPref($data_dir, $username, "mailfetch_pass_$i_loop");
+            if( $mailfetch_cypher == 'on' )
+                $mailfetch_pass_[$i_loop] = decrypt( $mailfetch_pass_[$i_loop] );
+
+            if( $mailfetch_pass_[$i_loop] <> '' &&          // Empty passwords no allowed
+                ( ( $mailfetch_login_[$i_loop] == 'on' &&  $mailfetch_newlog == 'on' ) || $mailfetch_fref_[$i_loop] == 'on' ) ) {
+
+                $mailfetch_server_[$i_loop] = getPref($data_dir, $username, "mailfetch_server_$i_loop");
+                $mailfetch_alias_[$i_loop] = getPref($data_dir, $username, "mailfetch_alias_$i_loop");
+                $mailfetch_user_[$i_loop] = getPref($data_dir, $username, "mailfetch_user_$i_loop");
+                $mailfetch_lmos_[$i_loop] = getPref($data_dir, $username, "mailfetch_lmos_$i_loop");
+                $mailfetch_uidl_[$i_loop] = getPref($data_dir, $username, "mailfetch_uidl_$i_loop");
+                $mailfetch_subfolder_[$i_loop] = getPref($data_dir, $username, "mailfetch_subfolder_$i_loop");
+
+                $mailfetch_server=$mailfetch_server_[$i_loop];
+                $mailfetch_user=$mailfetch_user_[$i_loop];
+                $mailfetch_alias=$mailfetch_alias_[$i_loop];
+                $mailfetch_pass=$mailfetch_pass_[$i_loop];
+                $mailfetch_lmos=$mailfetch_lmos_[$i_loop];
+                $mailfetch_login=$mailfetch_login_[$i_loop];
+                $mailfetch_uidl=$mailfetch_uidl_[$i_loop];
+                $mailfetch_subfolder=$mailfetch_subfolder_[$i_loop];
+
+                // $outMsg .= "$mailfetch_alias checked<br>";
+
+                // $outMsg .= "$mailfetch_alias_[$i_loop]<br>";
+
+                $pop3 = new POP3($mailfetch_server, 60);
+
+                if (!$pop3->connect($mailfetch_server)) {
+                    $outMsg .= _("Warning, ") . $pop3->ERROR;
+                    continue;
+                }
+
+                $imap_stream = sqimap_login($username, $key, $imapServerAddress, $imapPort, 10);
+
+                $Count = $pop3->login($mailfetch_user, $mailfetch_pass);
+                if (($Count == false || $Count == -1) && $pop3->ERROR != '') {
+                    $outMsg .= _("Login Failed:") . $pop3->ERROR;
+                    continue;
+                }
+
+                //   register_shutdown_function($pop3->quit());
+
+                $msglist = $pop3->uidl();
+
+                $i = 1;
+                for ($j = 1; $j < sizeof($msglist); $j++) {
+                if ($msglist["$j"] == $mailfetch_uidl) {
+                        $i = $j+1;
+                        break;
+                }
+                }
+
+                if ($Count < $i) {
+                    $pop3->quit();
+                    continue;
+                }
+                if ($Count == 0) {
+                    $pop3->quit();
+                    continue;
+                } else {
+                    $newmsgcount = $Count - $i + 1;
+                }
+
+                // Faster to get them all at once
+                $mailfetch_uidl = $pop3->uidl();
+
+                if (! is_array($mailfetch_uidl) && $mailfetch_lmos == 'on')
+                    $outMsg .= _("Server does not support UIDL.");
+
+                for (; $i <= $Count; $i++) {
+                    set_time_limit(20); // 20 seconds per message max
+                    $Message = "";
+                    $MessArray = $pop3->get($i);
+
+                    if ( (!$MessArray) or (gettype($MessArray) != "array")) {
+                        $outMsg .= _("Warning, ") . $pop3->ERROR;
+                        continue 2;
+                    }
+
+                    while (list($lineNum, $line) = each ($MessArray)) {
+                        $Message .= $line;
+                    }
+
+                    if ($mailfetch_subfolder=="") {
+                        fputs($imap_stream, "A3$i APPEND INBOX {" . (strlen($Message) - 1) . "}\r\n");
+                    } else {
+                        fputs($imap_stream, "A3$i APPEND $mailfetch_subfolder {" . (strlen($Message) - 1) . "}\r\n");
+                    }
+                    $Line = fgets($imap_stream, 1024);
+                    if (substr($Line, 0, 1) == '+') {
+                        fputs($imap_stream, $Message);
+                        sqimap_read_data($imap_stream, "A3$i", false, $response, $message);
+
+                        if ($mailfetch_lmos != 'on') {
+                        $pop3->delete($i);
+                        }
+                    } else {
+                        echo "$Line";
+                        $outMsg .= _("Error Appending Message!");
+                    }
+                }
+
+                $pop3->quit();
+                sqimap_logout($imap_stream);
+                if (is_array($mailfetch_uidl)) {
+                    setPref($data_dir,$username,"mailfetch_uidl_$i_loop", array_pop($mailfetch_uidl));
+                }
+        }
+        }
+
+        if( trim( $outMsg ) <> '' )
+            echo '<br><font size=1>' . _("Mail Fetch Result:") . "<br>$outMsg</font>";
+
+        if( $mailfetch_newlog == 'on' )
+            setPref($data_dir,$username,"mailfetch_newlog", 'off');
+
+    }
+
+    function mail_fetch_setnew()    {
+
+        global $data_dir,$username;
+        // require_once ('../src/load_prefs.php');
+        // require_once ('../src/validate.php');
+        require_once('../functions/prefs.php');
+
+        if( $username <> '' ) {
+            // Creates the pref file if it does not exist.
+        checkForPrefs( $data_dir, $username );
+            setPref( $data_dir, $username, 'mailfetch_newlog', 'on' );
+        }
+
+    }
+
+    function mailfetch_optpage_register_block() {
+      global $optpage_blocks;
+
+      $optpage_blocks[] = array(
+         'name' => _("Simple POP3 Fetch Mail"),
+         'url'  => '../plugins/mail_fetch/options.php',
+         'desc' => _("This configures settings for downloading email from a pop3 mailbox to your account on this server."),
+         'js'   => false
+      );
+   }
+
+?>
\ No newline at end of file