Vault work

This commit is contained in:
Karl Cordes 2010-12-10 16:55:59 +11:00
parent 204c0d6e6e
commit 89703e618c
3 changed files with 221 additions and 9 deletions

View file

@ -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
;deny = aco5, aco6
;allow = aco7, aco8

View file

@ -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;
}

211
vendors/shells/vault_two.php vendored Normal file
View file

@ -0,0 +1,211 @@
<?php
/**
* file: vault_two.php
*
* Major re-working of the vault idea.
*/
class VaultTwoShell extends Shell {
var $uses = array('Enquiry', 'Contact');
function main() {
/******************************************************
* Config Variables
* *****************************************************/
$testing = 1; //Whether to actually move the emails. 1=test, 0=production
/* Setup Connection to the IMAP server */
$username = 'vault';
$password = 'xjdYOsmJWc37'; /* The password for the account to be checked */
$email_dir = '/var/www/cakephp/app/emails';
$ripmime_path = '/usr/local/bin/ripmime';
if($testing == 1) {
//$username = 'karl';
//$password = '72seng89';
$email_dir = '/Users/karlcordes/Sites/quotenik/app/emails';
$ripmime_path = '/opt/local/bin/ripmime';
$mbox = imap_open("{mail.cmctechnologies.com.au: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());
}
$MC = imap_check($mbox);
$number_of_messages = $MC->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;
}
}
?>