From e8caee5d2faeb578cc1fc4d9a193cc2ea9f9637b Mon Sep 17 00:00:00 2001 From: Karl Cordes Date: Wed, 16 Nov 2016 22:42:50 +1100 Subject: [PATCH] Simplified vault. hopefully this works --- app/vendors/shells/vault.php | 90 +++++++++--------------------------- 1 file changed, 22 insertions(+), 68 deletions(-) diff --git a/app/vendors/shells/vault.php b/app/vendors/shells/vault.php index d211885c..d837da1b 100755 --- a/app/vendors/shells/vault.php +++ b/app/vendors/shells/vault.php @@ -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,31 +103,12 @@ 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 { - continue; - } + $this->move($email_filename, $vault_dir, $processed_dir); + continue; } @@ -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,14 +371,12 @@ 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) { @@ -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 $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(); - -}*/ - - -} - - -?>