From 89703e618c93344e6dfc38ca672e4595c756860c Mon Sep 17 00:00:00 2001 From: Karl Cordes Date: Fri, 10 Dec 2010 16:55:59 +1100 Subject: [PATCH] Vault work --- config/acl.ini.php | 10 +- vendors/shells/firstpass.php | 9 +- vendors/shells/vault_two.php | 211 +++++++++++++++++++++++++++++++++++ 3 files changed, 221 insertions(+), 9 deletions(-) create mode 100644 vendors/shells/vault_two.php diff --git a/config/acl.ini.php b/config/acl.ini.php index 6f21fc0a..89ca6974 100755 --- a/config/acl.ini.php +++ b/config/acl.ini.php @@ -63,14 +63,14 @@ ;------------------------------------- [username-goes-here] -groups = group1, group2 -deny = aco1, aco2 -allow = aco3, aco4 +;groups = group1, group2 +;deny = aco1, aco2 +;allow = aco3, aco4 ;------------------------------------- ;Groups ;------------------------------------- [groupname-goes-here] -deny = aco5, aco6 -allow = aco7, aco8 \ No newline at end of file +;deny = aco5, aco6 +;allow = aco7, aco8 \ No newline at end of file diff --git a/vendors/shells/firstpass.php b/vendors/shells/firstpass.php index af7db743..5569b838 100644 --- a/vendors/shells/firstpass.php +++ b/vendors/shells/firstpass.php @@ -22,6 +22,7 @@ class FirstpassShell extends Shell { $username = 'vault'; $password = 'xjdYOsmJWc37'; /* The password for the account to be checked */ + $hostname = 'mail.cmctechnologies.com.au'; $testing = 0; @@ -30,7 +31,7 @@ class FirstpassShell extends Shell { $mbox = imap_open("{192.168.0.8:143}INBOX", $username, $password) or die("can't connect: " . imap_last_error()); } else { - $mbox = imap_open("{192.168.0.8:143/novalidate-cert}INBOX", $username, $password) or die("can't connect: " . imap_last_error()); + $mbox = imap_open("{mail.cmctechnologies.com.au:143/novalidate-cert}INBOX", $username, $password) or die("can't connect: " . imap_last_error()); } @@ -61,18 +62,18 @@ class FirstpassShell extends Shell { // for($i=1; $i <= $number_of_messages; $i++) { - for($i=1; $i <= 500; $i++) { + for($i=$number_of_messages; $i > 0; $i--) { $this_header = imap_headerinfo($mbox, $i); $message = $this->getMessage($mbox, $i, $this_header); - //echo "Checking msg number: $i\tSubject: ".$message['subject']."\n"; + echo "Checking msg number: $i\tSubject: ".$message['subject']."\n"; //echo "Checking msg number: $i\n"; $enqID = $this->checkIfValidEnquiry($message['subject'], $enquiryList); if($enqID == false) { echo "Deleting msg number: $i\tSubject: ".$message['subject']."\n"; - imap_delete($mbox, $i); + // imap_delete($mbox, $i); //$discardArray[] = $i; } diff --git a/vendors/shells/vault_two.php b/vendors/shells/vault_two.php new file mode 100644 index 00000000..1cf7b5a5 --- /dev/null +++ b/vendors/shells/vault_two.php @@ -0,0 +1,211 @@ +Nmsgs; + + echo $username."\n"; + echo "Number of messages to Process ".$number_of_messages."\n"; + + if($number_of_messages == 0) { + exit(0); + } + + $enquiries = $this->Enquiry->find('all', array('recursive'=>0,'fields' => array('Enquiry.title', 'Enquiry.id'))); + $contacts = $this->Contact->find('all', array('recursive'=>0, 'fields'=>array('Contact.id', 'Contact.email'))); + + + foreach ($enquiries as $enq) { + $enqNumber = $enq['Enquiry']['title']; + $id = $enq['Enquiry']['id']; + $enquiryList[$enqNumber] = $id; + } + + foreach($contacts as $contact) { + $email = strtolower($contact['Contact']['email']); + $id = $contact['Contact']['id']; + $emailList[$email] = $id; + + //echo $email."\n"; + } + + for($i=$number_of_messages; $i > 0; $i--) { + $this_header = imap_headerinfo($mbox, $i); + $message = $this->getMessage($mbox, $i, $this_header); + + // echo "Checking msg number: $i\tSubject: ".$message['subject']."\n"; + //echo "Checking msg number: $i\n"; + + $enqID = $this->checkIfValidEnquiry($message['subject'], $enquiryList); + $contactID = $this->checkIfFromContact($message['from'], $emailList); + + if($enqID == false && $contactID == false) { + $uid = imap_uid($mbox, $i); + echo "Deleting msg number: $i\tSubject: ".$message['subject']."[{$uid}]"."\n"; + imap_delete($mbox, $uid, 1); + //$discardArray[] = $i; + + } + else { + $message['subject']." from ".$message['from']." will be saved"; + } + + } + + + + imap_close($mbox); + } + + + + function checkIfValidEnquiry($subject, &$enqList) { + $subject = iconv_mime_decode($subject, 0, "ISO-8859-1"); + + $output = array(); +// $decoded_subject = iconv_mime_decode($subject, 2, "ISO-8859-1"); + + preg_match("/CMC\d+([NVQWSOT]|ACT|NT)E\d+-\d+/", $subject, $output); + + + if(isset($output[0])) { //Found a valid-looking Enquiry Number + $fetched_enquirynumber = $output[0]; + + echo "'$fetched_enquirynumber'\n"; + + if(array_key_exists($fetched_enquirynumber, $enqList)) { //check if it actually exists. + $enqid = $enqList[$fetched_enquirynumber]; + + return $enqid; + } + else { + return false; + } + } + else { + return false; + } + + } + + function checkIfFromContact($sender, &$emailList) { + if(array_key_exists($sender, $emailList)) { + echo "'".$sender."'\n"; + return $emailList[$sender]; + } + else { + return false; + } + } + + + + function getMessage($mbox, $msgnumber, $headers) { + + $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_decode_mimeheader($subject); + + $date = $headers->date; + $recipients = $this->getRecipients($headers); + $message['subject'] = $subject; + $message['date'] = $date; + $message['to'] = strtolower($recipients['to']); + $message['from'] = strtolower($recipients['from']); + $message['cc'] = strtolower($recipients['cc']); + return $message; + + } + + /* get Recipients from the headers of an email */ + function getRecipients($headers) { + + $recipients = array(); + $recipients['to'] = ""; + $recipients['from'] = ""; + $recipients['cc'] = ""; + + if(isset($headers->to)) { + $to = $headers->to; + if(count($to) > 0) { + foreach ($to as $id => $object) { + $recipients['to'] .= "$object->mailbox@$object->host "; + } + } + } + if(isset($headers->cc)) { + $cc = $headers->cc; + if(count($cc) > 0) { + foreach ($cc as $id => $object) { + $recipients['cc'] .= "$object->mailbox@$object->host "; + } + + } + } + + if(isset($headers->from)) { + $from = $headers->from; + if(count($from) > 0) { + foreach ($from as $id => $object) { + $recipients['from'] .= "$object->mailbox@$object->host"; + } + } + } + + return $recipients; + } + +} + + +?> \ No newline at end of file