Simplified vault. hopefully this works

This commit is contained in:
Karl Cordes 2016-11-16 22:42:50 +11:00
parent 9d716c0665
commit e8caee5d2f

View file

@ -34,9 +34,9 @@ class VaultShell extends Shell {
else { //Production
$ripmime_path = '/usr/local/bin/ripmime';
$email_dir = '/var/www/cakephp/app/emails';
$vault_dir = '/var/www/cakephp/app/vaultmsgs';
$processed_dir = '/var/www/cakephp/app/processed_vaultmsgs';
$email_dir = '/var/www/emails';
$vault_dir = '/var/www/vaultmsgs/new';
$processed_dir = '/var/www/vaultmsgs/cur';
$lockfile = '/var/www/CMC-Sales/app/vault.lock';
}
@ -76,9 +76,13 @@ class VaultShell extends Shell {
$userMap = $this->makeMap($users, 'User', 'email');
$jobMap = $this->makeMap($jobs, 'Job', 'title');
$emails = scandir($vault_dir);
$processed = scandir($processed_dir);
$new = array_diff($emails, $processed);
$new = scandir($vault_dir);
//$processed = scandir($processed_dir);
//$new = array_diff($emails, $processed);
//Downloads mail using
//getmail -r vault.gmail
/**
* Loop through the messages.
@ -99,32 +103,13 @@ class VaultShell extends Shell {
continue;
}
if(!$this->isEmlFile($vault_dir, $email_filename)) {
echo "Incorrect file extension. Skipping this file";
continue;
}
/*if(file_exists($processed_dir."/".$email_filename)) {
continue;
}*/
$content = file_get_contents($vault_dir."/".$email_filename);
if(!$content) {
if(!$content) { //does this really happen?
echo "No Content Found. Ignoring this email\n";
if(!$this->makeSymlink($email_filename, $vault_dir, $processed_dir)) {
echo "Unable to make symlink to process this email Critical error: {$email_filename}\n";
if(!unlink($lockfile)) {
die("FATAL ERROR: Unable to remove vault.lock. No further Vault instances can run!");
}
}
else {
$this->move($email_filename, $vault_dir, $processed_dir);
continue;
}
}
$content = str_replace("\r", "", $content);
@ -158,8 +143,7 @@ class VaultShell extends Shell {
if(!isset($headers->subject)) { //Emails without a subject are not welcome. Skip it.
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}");
$this->move($email_filename, $vault_dir, $processed_dir);
}
else {
continue;
@ -257,7 +241,7 @@ class VaultShell extends Shell {
else {
print_r($recipientsIDs);
echo "Email has no From Recipient ID. Ignoring this email\n";
$this->makeSymlink($email_filename, $vault_dir, $processed_dir);
$this->move($email_filename, $vault_dir, $processed_dir);
continue;
}
//die("Email has no from Recipient!! Critical Failure"); //Change this to logging for deployment.
@ -378,7 +362,7 @@ class VaultShell extends Shell {
echo "email will not be saved. Subject: ".$subjDecoded[0]->text."\n";
}
if($this->makeSymlink($email_filename, $vault_dir, $processed_dir)) {
if($this->move($email_filename, $vault_dir, $processed_dir)) {
echo "Created Symlink Sucessfully. Email has been processed\n";
}
else {
@ -387,16 +371,14 @@ class VaultShell extends Shell {
}
if(!unlink($lockfile)) {
die("FATAL ERROR: Unable to remove vault.lock. No further Vault instances can run!");
}
}
function isEmlFile($vault_dir, $filename) {
$info = pathinfo($vault_dir."/".$filename);
@ -410,8 +392,11 @@ class VaultShell extends Shell {
}
function makeSymlink($email_filename, $vault_dir, $processed_dir) {
if(symlink($vault_dir."/".$email_filename, $processed_dir."/".$email_filename)) {
function move($email_filename, $vault_dir, $processed_dir) {
$old = $vault_dir."/".$email_filename;
$new = $processed_dir."/".$email_filename.":S";
if(rename($old, $new)) {
return true;
}
else {
@ -693,35 +678,4 @@ class VaultShell extends Shell {
}
/**
* The attachments have been decoded and written to disk by ripmime.
*
* 1. Generate a uuid for this email
* 2. Is there a month-year folder this this current month? If not, make one.
* 3. Move the attachments to the correct month-year Folder. Prefix their new names with uuid.
* 4.
*
* @param <type> $attachments
function moveAttachments($attachments, $email_dir, $unix_time) {
$month_year = date('m-Y');
$uuid = String::uuid();
foreach($attachments as $attachment) {
echo $email_dir.'/'.$attachment['name']."\n";
}
die();
}*/
}
?>