Batch handling of moving messages should speed up production thing

This commit is contained in:
Karl Cordes 2010-05-06 14:42:12 +10:00
parent daa4abf828
commit 08cba65fd6

View file

@ -11,7 +11,7 @@ class VaultShell extends Shell {
function main() { function main() {
/****************************************************** /******************************************************
* Config Variables * Config Variables
* *****************************************************/ * *****************************************************/
$testing = 0; //Whether to actually move the emails. 1=test, 0=production $testing = 0; //Whether to actually move the emails. 1=test, 0=production
@ -57,6 +57,8 @@ class VaultShell extends Shell {
$enquiryList[$enqNumber] = $id; $enquiryList[$enqNumber] = $id;
} }
$storedArray = array();
$discardArray = array();
@ -154,9 +156,9 @@ class VaultShell extends Shell {
} }
echo "Email stored in the DB under enquiry ID".$enqID." Will be moved to the stored folder\n"; echo "Email stored in the DB under enquiry ID".$enqID." Will be moved to the stored folder\n";
if($testing == 0) { $storedArray[] = $i;
imap_mail_move($mbox, $i, 'INBOX/Stored');
}
} }
else { else {
echo 'Unable to save the Email\n'; echo 'Unable to save the Email\n';
@ -165,19 +167,37 @@ class VaultShell extends Shell {
echo "Unable to find either HTML or Plaintext body to this email. Ignoring it"; echo "Unable to find either HTML or Plaintext body to this email. Ignoring it";
} }
} else { } else {
/* Can't find a valid-looking CMC Enquiry Number. Move the message to the discarded folder /* Can't find a valid-looking CMC Enquiry Number. Move the message to the discarded folder
* I may change this to simply delete the emails. This will do for now, but it's doubling up on the storage for useless files. * I may change this to simply delete the emails. This will do for now, but it's doubling up on the storage for useless files.
* */ * */
if($testing == 0 ) { $discardArray[] = $i;
imap_mail_move($mbox, $i, 'INBOX/Discarded');
}
} }
} }
/* Finished working with the IMAP server. Make the changes and close the connection */ /* Finished working with the IMAP server. Make the changes and close the connection */
if($testing == 0) {
reset($discardArray);
reset($storedArray);
$storeSet = implode(",", $storedArray);
$discardSet = implode(",",$discardArray);
echo "Tidying up now. Moving messages to Stored or Discarded\n";
imap_mail_move($mbox, $storeSet, 'INBOX/Stored');
imap_mail_move($mbox, $discardSet, 'INBOX/Discarded');
}
imap_expunge($mbox); imap_expunge($mbox);
imap_close($mbox); imap_close($mbox);
} }
@ -233,8 +253,8 @@ class VaultShell extends Shell {
$subject = $headers->subject; $subject = $headers->subject;
//$subject = iconv_mime_decode($subject, 0, "ISO-8859-1//IGNORE"); //$subject = iconv_mime_decode($subject, 0, "ISO-8859-1//IGNORE");
// $subject = mb_convert_encoding($subject, "ISO-8859-1"); // $subject = mb_convert_encoding($subject, "ISO-8859-1");
// $subject = mb_convert_encoding($subject, "UTF-8"); // $subject = mb_convert_encoding($subject, "UTF-8");
$subject = mb_decode_mimeheader($subject); $subject = mb_decode_mimeheader($subject);
$date = $headers->date; $date = $headers->date;