Vault now processes the array_dir of the vaultmsgs and processed_vaultmsgs directories. Should be fairly quick
This commit is contained in:
parent
d12825247a
commit
d53f29a15e
78
vendors/shells/vault.php
vendored
78
vendors/shells/vault.php
vendored
|
|
@ -6,9 +6,11 @@
|
|||
* Major re-working of the vault idea.
|
||||
*
|
||||
*
|
||||
* No more IMAP connections. These were way too slow. R
|
||||
* No more IMAP connections. These were way too slow.
|
||||
*
|
||||
* Reading these files from the local file system.
|
||||
*
|
||||
*
|
||||
* Reading these files from the local file system (or maybe NFS).
|
||||
*
|
||||
*
|
||||
*
|
||||
|
|
@ -16,18 +18,16 @@
|
|||
*/
|
||||
App::import('Sanitize');
|
||||
class VaultShell extends Shell {
|
||||
|
||||
|
||||
|
||||
var $uses = array('Enquiry', 'Contact', 'Invoice', 'PurchaseOrder', 'User', 'Email', 'EmailRecipient', 'Job');
|
||||
|
||||
// var $email_dir = '/var/www/cakephp/app/emails';
|
||||
|
||||
function main() {
|
||||
|
||||
/******************************************************
|
||||
* Config Variables
|
||||
* *****************************************************/
|
||||
$testing = 0; //Whether to actually move the emails. 1=test, 0=production
|
||||
$testing = 1; //Whether to actually move the emails. 1=test, 0=production
|
||||
|
||||
|
||||
if($testing == 1) {
|
||||
|
|
@ -45,6 +45,10 @@ class VaultShell extends Shell {
|
|||
}
|
||||
|
||||
$emails = scandir($vault_dir);
|
||||
$processed = scandir($processed_dir);
|
||||
$new = array_diff($emails, $processed);
|
||||
|
||||
|
||||
|
||||
/* Find the strings we want to look for in the subjects. Build arrays
|
||||
* using the string as the keys, IDs as the value
|
||||
|
|
@ -86,7 +90,7 @@ class VaultShell extends Shell {
|
|||
* Check the subject for patterns that match Identifiers.
|
||||
*
|
||||
*/
|
||||
foreach($emails as $email_filename) {
|
||||
foreach($new as $email_filename) {
|
||||
echo "Handling $email_filename\n";
|
||||
if( ($email_filename == '.') || ($email_filename == '..') ) {
|
||||
continue;
|
||||
|
|
@ -100,7 +104,13 @@ class VaultShell extends Shell {
|
|||
$content = file_get_contents($vault_dir."/".$email_filename);
|
||||
|
||||
if(!$content) {
|
||||
die("Unable to read ".$vault_dir."/".$email_filename);
|
||||
echo "No Content Found. Ignoring this email\n";
|
||||
if(!$this->makeSymlink($email_filename, $vault_dir, $processed_dir)) {
|
||||
die("Unable to make symlink to process this email Critical error: {$email_filename}");
|
||||
}
|
||||
else {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -139,8 +149,14 @@ class VaultShell extends Shell {
|
|||
|
||||
|
||||
if(!isset($headers->subject)) { //Emails without a subject are not welcome. Skip it.
|
||||
$discard[] = $this_uid;
|
||||
continue;
|
||||
echo "No Subject Found. Ignoring this email\n";
|
||||
if(!$this->makeSymlink($email_filename, $vault_dir, $processed_dir)) {
|
||||
die("Unable to make symlink to process this email Critical error: {$email_filename}");
|
||||
}
|
||||
else {
|
||||
continue;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$subjDecoded = imap_mime_header_decode($headers->subject);
|
||||
|
|
@ -163,12 +179,7 @@ class VaultShell extends Shell {
|
|||
|
||||
$found_jobs = $this->checkValidIdentifier($sub->text, $jobMap, 'job');
|
||||
$foundIdent = $this->foundIdentifier($found_jobs);
|
||||
|
||||
echo $sub->text;
|
||||
}
|
||||
print_r($recipients);
|
||||
|
||||
|
||||
|
||||
//We're going to save this Email.
|
||||
//Lets grab the attachments (if any) then create the appropiate Objects.
|
||||
|
|
@ -214,7 +225,7 @@ class VaultShell extends Shell {
|
|||
$userMap[$recEmailLC] = $newID;
|
||||
}
|
||||
else {
|
||||
echo "Fatal Error: Unable to create user for email '{$recEmailLC}'\n";
|
||||
echo "Serious Error: Unable to create user for email '{$recEmailLC}'\n";
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
@ -237,9 +248,9 @@ class VaultShell extends Shell {
|
|||
}
|
||||
else {
|
||||
print_r($recipientsIDs);
|
||||
echo "Email has no From Recipient ID. Ignoring this.\n";
|
||||
echo "Email has no From Recipient ID. Ignoring this email\n";
|
||||
$this->makeSymlink($email_filename, $vault_dir, $processed_dir);
|
||||
continue;
|
||||
|
||||
}
|
||||
//die("Email has no from Recipient!! Critical Failure"); //Change this to logging for deployment.
|
||||
|
||||
|
|
@ -248,9 +259,9 @@ class VaultShell extends Shell {
|
|||
$newEmail['Email']['udate'] = $unix_time;
|
||||
|
||||
$allowedChars = array('@', ';', ':', '.', '$', '%', '*','#','!',',','[', ']',' ','{','}','|', '(', ')');
|
||||
$newEmail['Email']['subject'] = Sanitize::paranoid($subjDecoded[0]->text, $allowedChars); //Hacky. Will probably fix this quickly.
|
||||
$newEmail['Email']['subject'] = Sanitize::paranoid($subjDecoded[0]->text, $allowedChars);
|
||||
$newEmail['Email']['filename'] = $email_filename;
|
||||
|
||||
|
||||
$recipientCount = 0;
|
||||
foreach($recipientsIDs as $type => $typeEmails) {
|
||||
foreach($typeEmails as $userID) {
|
||||
|
|
@ -359,17 +370,30 @@ class VaultShell extends Shell {
|
|||
echo "email will not be saved. Subject: ".$subjDecoded[0]->text."\n";
|
||||
}
|
||||
|
||||
if(symlink($vault_dir."/".$email_filename, $processed_dir."/".$email_filename)) {
|
||||
echo "Created Symlink sucessfully. Email processed\n";
|
||||
if($this->makeSymlink($email_filename, $vault_dir, $processed_dir)) {
|
||||
echo "Created Symlink Sucessfully. Email has been processed\n";
|
||||
}
|
||||
else {
|
||||
die("Could not create symlink to record processing of this email. Critical failure");
|
||||
echo "Unable to create Symlink for {$email_filename}. Critical Error! \n";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
function makeSymlink($email_filename, $vault_dir, $processed_dir) {
|
||||
if(symlink($vault_dir."/".$email_filename, $processed_dir."/".$email_filename)) {
|
||||
echo "Created Symlink sucessfully. Email processed\n";
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
die("Unable to create symlink for {$email_filename}");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -534,8 +558,8 @@ class VaultShell extends Shell {
|
|||
exec($command, $output, $status);
|
||||
|
||||
|
||||
echo $email_file ."\n";
|
||||
echo $command ."\n";
|
||||
// echo $email_file ."\n";
|
||||
// echo $command ."\n";
|
||||
|
||||
|
||||
/* Check the $output array and find the filenames of the attachments */
|
||||
|
|
@ -584,7 +608,7 @@ class VaultShell extends Shell {
|
|||
$attachments[$j]['filename'] = $name[1];
|
||||
$attachments[$j]['size'] = $size;
|
||||
$attachments[$j]['is_message_body'] = 0;
|
||||
echo "found attachment ".$attachments[$j]['name'].' '.$attachments[$j]['type']."\n";
|
||||
//echo "found attachment ".$attachments[$j]['name'].' '.$attachments[$j]['type']."\n";
|
||||
|
||||
|
||||
/** Record the array ID and size of the largest HTML & plain attachments **/
|
||||
|
|
|
|||
2
vendors/shells/vault_two.php
vendored
2
vendors/shells/vault_two.php
vendored
|
|
@ -624,7 +624,7 @@ class VaultTwoShell extends Shell {
|
|||
$attachments[$j]['filename'] = $name[1];
|
||||
$attachments[$j]['size'] = $size;
|
||||
$attachments[$j]['is_message_body'] = 0;
|
||||
echo "in message number $msg_number: found attachment ".$attachments[$j]['name'].' '.$attachments[$j]['type']."\n";
|
||||
//echo "in message number $msg_number: found attachment ".$attachments[$j]['name'].' '.$attachments[$j]['type']."\n";
|
||||
|
||||
|
||||
/** Record the array ID and size of the largest HTML & plain attachments **/
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@
|
|||
<li><?php echo $html->link('Customers', '/customers/index'); ?>
|
||||
<ul>
|
||||
<li><?php echo $html->link('Customer Index', '/customers/index'); ?></li>
|
||||
<li><?php echo $html->link('Find Customer', '/customers/find'); ?></li>
|
||||
<li><?php echo $html->link('Find Customer', '#', array('id'=>'searchLink')); ?></li>
|
||||
<li><?php echo $html->link('Add Customer', '/customers/add'); ?></li>
|
||||
<li class="last"><?php echo $html->link('Industries', '/industries/index'); ?></li>
|
||||
</ul>
|
||||
|
|
|
|||
Loading…
Reference in a new issue