Simplified vault. hopefully this works
This commit is contained in:
parent
9d716c0665
commit
e8caee5d2f
90
app/vendors/shells/vault.php
vendored
90
app/vendors/shells/vault.php
vendored
|
|
@ -34,9 +34,9 @@ class VaultShell extends Shell {
|
||||||
else { //Production
|
else { //Production
|
||||||
|
|
||||||
$ripmime_path = '/usr/local/bin/ripmime';
|
$ripmime_path = '/usr/local/bin/ripmime';
|
||||||
$email_dir = '/var/www/cakephp/app/emails';
|
$email_dir = '/var/www/emails';
|
||||||
$vault_dir = '/var/www/cakephp/app/vaultmsgs';
|
$vault_dir = '/var/www/vaultmsgs/new';
|
||||||
$processed_dir = '/var/www/cakephp/app/processed_vaultmsgs';
|
$processed_dir = '/var/www/vaultmsgs/cur';
|
||||||
$lockfile = '/var/www/CMC-Sales/app/vault.lock';
|
$lockfile = '/var/www/CMC-Sales/app/vault.lock';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -76,9 +76,13 @@ class VaultShell extends Shell {
|
||||||
$userMap = $this->makeMap($users, 'User', 'email');
|
$userMap = $this->makeMap($users, 'User', 'email');
|
||||||
$jobMap = $this->makeMap($jobs, 'Job', 'title');
|
$jobMap = $this->makeMap($jobs, 'Job', 'title');
|
||||||
|
|
||||||
$emails = scandir($vault_dir);
|
$new = scandir($vault_dir);
|
||||||
$processed = scandir($processed_dir);
|
//$processed = scandir($processed_dir);
|
||||||
$new = array_diff($emails, $processed);
|
//$new = array_diff($emails, $processed);
|
||||||
|
|
||||||
|
|
||||||
|
//Downloads mail using
|
||||||
|
//getmail -r vault.gmail
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loop through the messages.
|
* Loop through the messages.
|
||||||
|
|
@ -99,31 +103,12 @@ class VaultShell extends Shell {
|
||||||
continue;
|
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);
|
$content = file_get_contents($vault_dir."/".$email_filename);
|
||||||
|
|
||||||
if(!$content) {
|
if(!$content) { //does this really happen?
|
||||||
echo "No Content Found. Ignoring this email\n";
|
echo "No Content Found. Ignoring this email\n";
|
||||||
if(!$this->makeSymlink($email_filename, $vault_dir, $processed_dir)) {
|
$this->move($email_filename, $vault_dir, $processed_dir);
|
||||||
echo "Unable to make symlink to process this email Critical error: {$email_filename}\n";
|
continue;
|
||||||
|
|
||||||
if(!unlink($lockfile)) {
|
|
||||||
die("FATAL ERROR: Unable to remove vault.lock. No further Vault instances can run!");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -158,8 +143,7 @@ class VaultShell extends Shell {
|
||||||
|
|
||||||
if(!isset($headers->subject)) { //Emails without a subject are not welcome. Skip it.
|
if(!isset($headers->subject)) { //Emails without a subject are not welcome. Skip it.
|
||||||
echo "No Subject Found. Ignoring this email\n";
|
echo "No Subject Found. Ignoring this email\n";
|
||||||
if(!$this->makeSymlink($email_filename, $vault_dir, $processed_dir)) {
|
$this->move($email_filename, $vault_dir, $processed_dir);
|
||||||
die("Unable to make symlink to process this email Critical error: {$email_filename}");
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
continue;
|
continue;
|
||||||
|
|
@ -257,7 +241,7 @@ class VaultShell extends Shell {
|
||||||
else {
|
else {
|
||||||
print_r($recipientsIDs);
|
print_r($recipientsIDs);
|
||||||
echo "Email has no From Recipient ID. Ignoring this email\n";
|
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;
|
continue;
|
||||||
}
|
}
|
||||||
//die("Email has no from Recipient!! Critical Failure"); //Change this to logging for deployment.
|
//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";
|
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";
|
echo "Created Symlink Sucessfully. Email has been processed\n";
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
@ -387,14 +371,12 @@ class VaultShell extends Shell {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!unlink($lockfile)) {
|
if(!unlink($lockfile)) {
|
||||||
die("FATAL ERROR: Unable to remove vault.lock. No further Vault instances can run!");
|
die("FATAL ERROR: Unable to remove vault.lock. No further Vault instances can run!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function isEmlFile($vault_dir, $filename) {
|
function isEmlFile($vault_dir, $filename) {
|
||||||
|
|
@ -410,8 +392,11 @@ class VaultShell extends Shell {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function makeSymlink($email_filename, $vault_dir, $processed_dir) {
|
function move($email_filename, $vault_dir, $processed_dir) {
|
||||||
if(symlink($vault_dir."/".$email_filename, $processed_dir."/".$email_filename)) {
|
$old = $vault_dir."/".$email_filename;
|
||||||
|
$new = $processed_dir."/".$email_filename.":S";
|
||||||
|
|
||||||
|
if(rename($old, $new)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else {
|
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();
|
|
||||||
|
|
||||||
}*/
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
?>
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue