If an e-mail including attachment is moved to a another email folder
MailManager module: When received an Email with 1 attachment:
- It's displayed with 1 attachment in Inbox folder
- imagine that there is a Test1 folder with another email with 2 attachments
- Move Email from Inbox to Test1 folder. After click to display details, you will see 3 attachments.
- the reason is that message open does handle get attachments with userid and muid params only.
Possible solution, alter query with join to mailrecord table by mfolder value to get correct entries.
I don't know how to merge .zip files for packages in Vtiger, so this is the solution
modules/MailManager/models/Message.php
from:
protected function loadAttachmentsFromDB($withContent, $aName=false, $aId=false) { $db = PearDatabase::getInstance(); $currentUserModel = Users_Record_Model::getCurrentUserModel();
if (empty($this->_attachments)) {
$this->_attachments = array();
$params = array($currentUserModel->getId(), $this->muid());
$filteredColumns = "aname, attachid, path, cid";
$whereClause = "";
if ($aName) { $whereClause .= " AND aname=?"; $params[] = $aName; }
if ($aId) { $whereClause .= " AND attachid=?"; $params[] = $aId; }
$atResult = $db->pquery("SELECT {$filteredColumns} FROM vtiger_mailmanager_mailattachments
WHERE userid=? AND muid=? $whereClause", $params);
if ($db->num_rows($atResult)) {
for($atIndex = 0; $atIndex < $db->num_rows($atResult); ++$atIndex) {
$atResultRow = $db->raw_query_result_rowdata($atResult, $atIndex);
if($withContent) {
$binFile = sanitizeUploadFileName($atResultRow['aname'], vglobal('upload_badext'));
$saved_filename = $atResultRow['path'] . $atResultRow['attachid']. '_' .$binFile;
if(file_exists($saved_filename)) $fileContent = @fread(fopen($saved_filename, "r"), filesize($saved_filename));
}
if(!empty($atResultRow['cid'])) {
$this->_inline_attachments[] = array('filename'=>$atResultRow['aname'], 'cid'=>$atResultRow['cid']);
}
$filePath = $atResultRow['path'].$atResultRow['attachid'].'_'.sanitizeUploadFileName($atResultRow['aname'], vglobal('upload_badext'));
$fileSize = $this->convertFileSize(filesize($filePath));
$data = ($withContent? $fileContent: false);
$this->_attachments[] = array('filename'=>$atResultRow['aname'], 'data' => $data, 'size' => $fileSize, 'path' => $filePath, 'attachid' => $atResultRow['attachid']);
unset($fileContent); // Clear immediately
}
$atResult->free();
unset($atResult); // Indicate cleanup
}
}
}
to:
protected function loadAttachmentsFromDB($withContent, $aName=false, $aId=false) { $db = PearDatabase::getInstance(); $currentUserModel = Users_Record_Model::getCurrentUserModel(); request = new Vtiger_Request(_REQUEST, $_REQUEST);
if (empty($this->_attachments)) {
$this->_attachments = array();
$params = array($currentUserModel->getId(), $this->muid());
$filteredColumns = "aname, attachid, path, cid";
$whereClause = "";
if ($aName) { $whereClause .= " AND aname=?"; $params[] = $aName; }
if ($aId) { $whereClause .= " AND attachid=?"; $params[] = $aId; }
if ($request->has('_folder')) { $whereClause .= " AND vtiger_mailmanager_mailrecord.mfolder=?"; $params[] = decode_html($request->get('_folder')); }
$atResult = $db->pquery("SELECT {$filteredColumns} FROM vtiger_mailmanager_mailattachments
INNER JOIN vtiger_mailmanager_mailrecord ON vtiger_mailmanager_mailrecord.muid = vtiger_mailmanager_mailattachments.muid AND vtiger_mailmanager_mailrecord.lastsavedtime = vtiger_mailmanager_mailattachments.lastsavedtime
WHERE vtiger_mailmanager_mailattachments.userid=?
AND vtiger_mailmanager_mailattachments.muid=? $whereClause", $params);
if ($db->num_rows($atResult)) {
for($atIndex = 0; $atIndex < $db->num_rows($atResult); ++$atIndex) {
$atResultRow = $db->raw_query_result_rowdata($atResult, $atIndex);
if($withContent) {
$binFile = sanitizeUploadFileName($atResultRow['aname'], vglobal('upload_badext'));
$saved_filename = $atResultRow['path'] . $atResultRow['attachid']. '_' .$binFile;
if(file_exists($saved_filename)) $fileContent = @fread(fopen($saved_filename, "r"), filesize($saved_filename));
}
if(!empty($atResultRow['cid'])) {
$this->_inline_attachments[] = array('filename'=>$atResultRow['aname'], 'cid'=>$atResultRow['cid']);
}
$filePath = $atResultRow['path'].$atResultRow['attachid'].'_'.sanitizeUploadFileName($atResultRow['aname'], vglobal('upload_badext'));
$fileSize = $this->convertFileSize(filesize($filePath));
$data = ($withContent? $fileContent: false);
$this->_attachments[] = array('filename'=>$atResultRow['aname'], 'data' => $data, 'size' => $fileSize, 'path' => $filePath, 'attachid' => $atResultRow['attachid']);
unset($fileContent); // Clear immediately
}
$atResult->free();
unset($atResult); // Indicate cleanup
}
}
}