From 4cd709cbb84e1feb29ca4012109e0ff42dd9acff Mon Sep 17 00:00:00 2001
From: Jonathan Putney <jonathan.putney@me.com>
Date: Thu, 26 Apr 2012 16:02:09 -0300
Subject: [PATCH] Updating include/class.mailfetch.php:  Fixing the 'Move to'
 feature for incoming emails.

---
 include/class.mailfetch.php | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/include/class.mailfetch.php b/include/class.mailfetch.php
index 4ee15ecca..424545c8a 100644
--- a/include/class.mailfetch.php
+++ b/include/class.mailfetch.php
@@ -346,7 +346,7 @@ class MailFetcher {
 
     }
 
-    function fetchTickets($emailid,$max=20,$deletemsgs=false){
+    function fetchTickets($emailid,$max=20,$deletemsgs=false,$archivefolder){
 
         $nummsgs=imap_num_msg($this->mbox);
         //echo "New Emails:  $nummsgs\n";
@@ -356,6 +356,8 @@ class MailFetcher {
                 imap_setflag_full($this->mbox, imap_uid($this->mbox,$i), "\\Seen", ST_UID); //IMAP only??
                 if($deletemsgs)
                     imap_delete($this->mbox,$i);
+                if(!is_null($archivefolder))
+                    imap_mail_move($this->mbox,$i,$archivefolder);  //May need some error checking for bad folder names
                 $msgs++;
                 $errors=0; //We are only interested in consecutive errors.
             }else{
@@ -384,7 +386,7 @@ class MailFetcher {
 
         $MAX_ERRORS=5; //Max errors before we start delayed fetch attempts - hardcoded for now.
 
-        $sql=' SELECT email_id,mail_host,mail_port,mail_protocol,mail_encryption,mail_delete,mail_errors,userid,userpass FROM '.EMAIL_TABLE.
+        $sql=' SELECT email_id,mail_host,mail_port,mail_protocol,mail_encryption,mail_delete,mail_archivefolder,mail_errors,userid,userpass FROM '.EMAIL_TABLE.
              ' WHERE mail_active=1 AND (mail_errors<='.$MAX_ERRORS.' OR (TIME_TO_SEC(TIMEDIFF(NOW(),mail_lasterror))>5*60) )'.
              ' AND (mail_lastfetch IS NULL OR TIME_TO_SEC(TIMEDIFF(NOW(),mail_lastfetch))>mail_fetchfreq*60) ';
         //echo $sql;
@@ -396,7 +398,7 @@ class MailFetcher {
             $fetcher = new MailFetcher($row['userid'],Misc::decrypt($row['userpass'],SECRET_SALT),
                                        $row['mail_host'],$row['mail_port'],$row['mail_protocol'],$row['mail_encryption']);
             if($fetcher->connect()){   
-                $fetcher->fetchTickets($row['email_id'],$row['mail_fetchmax'],$row['mail_delete']?true:false);
+                $fetcher->fetchTickets($row['email_id'],$row['mail_fetchmax'],$row['mail_delete']?true:false,$row['mail_archivefolder']);
                 $fetcher->close();
                 db_query('UPDATE '.EMAIL_TABLE.' SET mail_errors=0, mail_lastfetch=NOW() WHERE email_id='.db_input($row['email_id']));
             }else{
-- 
GitLab