From 1b5a23b3c082c32c23789bde62562905e2895c45 Mon Sep 17 00:00:00 2001 From: Karl Cordes Date: Mon, 24 Nov 2025 21:59:54 +1100 Subject: [PATCH] Fix vault attachment directory --- go/cmd/vault/README.md | 2 ++ .../email_attachments_controller.php | 32 +++++++++++++++---- scripts/cron/vault-cron-prod.sh | 2 +- 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/go/cmd/vault/README.md b/go/cmd/vault/README.md index e7125816..86c4d14d 100644 --- a/go/cmd/vault/README.md +++ b/go/cmd/vault/README.md @@ -27,6 +27,8 @@ Processes emails from local filesystem directories. --dbname=cmc ``` +**Note:** The `emaildir` should be set to `/var/www/emails` to match the legacy directory structure expected by the CakePHP application. + ### 2. Gmail Index Mode Indexes Gmail emails without downloading content. Creates database references only. diff --git a/php/app/controllers/email_attachments_controller.php b/php/app/controllers/email_attachments_controller.php index 9e5a7608..2974f15d 100755 --- a/php/app/controllers/email_attachments_controller.php +++ b/php/app/controllers/email_attachments_controller.php @@ -12,11 +12,20 @@ class EmailAttachmentsController extends AppController { // GET vault.cmctechnologies.com.au/filename // HTTP basic auth, or some sort of preshared key // service hits S3 if required. Cached on disk for $sometime - + $file = $this->EmailAttachment->findById($id); - $file_path = Configure::read('attachments_directory'); - if(file_exists($file_path."/".$file['EmailAttachment']['name'])) { + // Try legacy emails directory first (where vault saves files) + $file_path = '/var/www/emails'; + $full_path = $file_path."/".$file['EmailAttachment']['name']; + + // Fallback to attachments directory if not found in emails + if(!file_exists($full_path)) { + $file_path = Configure::read('attachments_directory'); + $full_path = $file_path."/".$file['EmailAttachment']['name']; + } + + if(file_exists($full_path)) { @@ -33,12 +42,13 @@ class EmailAttachmentsController extends AppController { header('Content-length: ' . $file['EmailAttachment']['size']); header('Content-Disposition: attachment; filename='.$filename); - readfile($file_path."/".$file['EmailAttachment']['name']); + readfile($full_path); exit(); } else { - echo "ERROR!! : File Not Found"; + echo "ERROR: File Not Found"; + echo '\n'; echo $file['EmailAttachment']['filename']; die(); } @@ -55,9 +65,17 @@ class EmailAttachmentsController extends AppController { $file = $this->EmailAttachment->find('first', array('conditions'=>array('EmailAttachment.id'=>$id))); //$this->set('attachment', $file); - $file_path = Configure::read('attachments_directory'); + // Try legacy emails directory first (where vault saves files) + $file_path = '/var/www/emails'; + $full_path = $file_path."/".$file['EmailAttachment']['name']; - $contents = file_get_contents($file_path."/".$file['EmailAttachment']['name']); + // Fallback to attachments directory if not found in emails + if(!file_exists($full_path)) { + $file_path = Configure::read('attachments_directory'); + $full_path = $file_path."/".$file['EmailAttachment']['name']; + } + + $contents = file_get_contents($full_path); if($file['EmailAttachment']['type'] == 'text/plain') { diff --git a/scripts/cron/vault-cron-prod.sh b/scripts/cron/vault-cron-prod.sh index 39923859..5d4e1e79 100755 --- a/scripts/cron/vault-cron-prod.sh +++ b/scripts/cron/vault-cron-prod.sh @@ -20,7 +20,7 @@ echo "$(date): Starting vault processing..." >> "$LOG_FILE" docker exec -t "$CONTAINER_NAME" ./vault --mode=local \ --vaultdir=/var/www/vaultmsgs/new \ --processeddir=/var/www/vaultmsgs/cur \ - --emaildir=/var/www/attachments_files \ + --emaildir=/var/www/emails \ --dbhost=cmc-prod-db \ --dbuser=cmc \ --dbpass="xVRQI&cA?7AU=hqJ!%au" \