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

@ -10,8 +10,8 @@ class VaultShell extends Shell {
var $uses = array('Enquiry', 'Email', 'EmailAttachment');
function main() {
/******************************************************
/******************************************************
* Config Variables
* *****************************************************/
$testing = 0; //Whether to actually move the emails. 1=test, 0=production
@ -32,7 +32,7 @@ class VaultShell extends Shell {
}
else {
$mbox = imap_open("{192.168.0.8:143/novalidate-cert}INBOX", $username, $password) or die("can't connect: " . imap_last_error());
}
@ -57,6 +57,8 @@ class VaultShell extends Shell {
$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";
if($testing == 0) {
imap_mail_move($mbox, $i, 'INBOX/Stored');
}
$storedArray[] = $i;
}
else {
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";
}
} 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.
* */
if($testing == 0 ) {
imap_mail_move($mbox, $i, 'INBOX/Discarded');
}
$discardArray[] = $i;
}
}
/* 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_close($mbox);
}
@ -233,8 +253,8 @@ class VaultShell extends Shell {
$subject = $headers->subject;
//$subject = iconv_mime_decode($subject, 0, "ISO-8859-1//IGNORE");
// $subject = mb_convert_encoding($subject, "ISO-8859-1");
// $subject = mb_convert_encoding($subject, "UTF-8");
// $subject = mb_convert_encoding($subject, "ISO-8859-1");
// $subject = mb_convert_encoding($subject, "UTF-8");
$subject = mb_decode_mimeheader($subject);
$date = $headers->date;