Fix vault attachment directory

This commit is contained in:
Karl Cordes 2025-11-24 21:59:54 +11:00
parent ce5d44ae6b
commit 1b5a23b3c0
3 changed files with 28 additions and 8 deletions

View file

@ -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.

View file

@ -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') {

View file

@ -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" \