Vault fixed

This commit is contained in:
Karl Cordes 2009-02-11 11:03:50 +11:00
parent 8f7d1a1022
commit 33318da076

View file

@ -11,6 +11,8 @@ class VaultShell extends Shell {
function main() {
$testing = 1; //Whether to actually move the emails.
/* Setup Connection to the IMAP server */
$username = 'vault';
$password = 'xjdYOsmJWc37'; /* The password for the account to be checked */
@ -34,7 +36,9 @@ class VaultShell extends Shell {
$enquiry = $this->Enquiry->findByTitle($fetched_enquirynumber);
if($enquiry['Enquiry']['id'] == NULL) { //It passes the Regex - but we don't find an Enquiry for it in the MER.
imap_mail_move($mbox, $i, 'INBOX/Discarded'); //Discard it.
if($testing == 0) { //testing mode.
imap_mail_move($mbox, $i, 'INBOX/Discarded'); //Discard it.
}
}
else { //Process it and store the message and its attachments.
@ -71,7 +75,10 @@ class VaultShell extends Shell {
}
echo "Email stored in the DB under enquiry ".$enquiry['Enquiry']['title']." Will be moved to the stored folder\n";
imap_mail_move($mbox, $i, 'INBOX/Stored'); //Move it to the stored folder.
if($testing == 0) { //Testing Mode. Don't actually move these emails unless we're in production.
imap_mail_move($mbox, $i, 'INBOX/Stored'); //Move it to the stored folder.
}
$this->clearEmailAttachmentDirs($email_dir, $temp_filename, $attachment_dir, $attachment_files);
}
else {
@ -84,12 +91,15 @@ class VaultShell extends Shell {
/* 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(imap_mail_move($mbox, $i, 'INBOX/Discarded')) {
echo "Message Number $i contains no valid Enquiry number. Has been discarded\n";
}
else {
echo "Message Number $i contains no valid Enquiry number. But could not be discarded\n";
}
if($testing == 0) {
if(imap_mail_move($mbox, $i, 'INBOX/Discarded')) {
echo "Message Number $i contains no valid Enquiry number. Has been discarded\n";
}
else {
echo "Message Number $i contains no valid Enquiry number. But could not be discarded\n";
}
}
}
}
@ -221,12 +231,41 @@ function getBody($mbox, $msgnumber) {
}
function getParts($parts, $mbox, $msgnumber) {
for ($i = 0, $j = count($parts); $i < $j; $i++) {
$part = $parts[$i];
$bodystruct = imap_bodystruct($mbox, $msgnumber, $i+1);
if ($part->subtype == 'HTML') { /* Find the HTML component of the body */
$body = imap_fetchbody($mbox, $msgnumber, $i+1);
if($bodystruct->subtype != 'HTML') {
continue;
}
if($bodystruct->subtype == 'HTML') {
break; //Found HTML (preferred) So end the loop.
}
}
elseif($part->subtype == 'PLAIN') {
$body = imap_fetchbody($mbox, $msgnumber, $i+1);
break;
}
elseif(isset($part->parts)) {
$body = getParts($part->parts, $mbox, $msgnumber); /* Handle these goddamn Outlook messages */
}
}
return $body;
}
/*
function getParts($parts, $mbox, $msgnumber) {
for ($i = 0, $j = count($parts); $i < $j; $i++) {
$part = $parts[$i];
if ($part->subtype == 'HTML') { /* Find the HTML component of the body */
if ($part->subtype == 'HTML') { /* Find the HTML component of the body
$body = imap_fetchbody($mbox, $msgnumber, $i+1);
break; //Found HTML (preferred) So end the loop.
}
@ -235,14 +274,14 @@ function getParts($parts, $mbox, $msgnumber) {
}
elseif(isset($part->parts)) {
$body = $this->getParts($part->parts, $mbox, $msgnumber); /* Handle these goddamn Outlook messages */
$body = $this->getParts($part->parts, $mbox, $msgnumber); /* Handle these goddamn Outlook messages
}
}
return $body;
}
*/
}