Skip to content
Snippets Groups Projects
Commit fc3f4ebb authored by Prasad's avatar Prasad
Browse files

Fixes #774: Eliminated friction when download attachment has same name (but different content)

parent 5dfd95f4
No related branches found
No related tags found
1 merge request!311Language italian translation
......@@ -119,13 +119,14 @@
{assign var=ATTACHNAME value=$ATTACHVALUE['filename']}
{if $INLINE_ATT[$ATTACHNAME] eq null}
{assign var=DOWNLOAD_LINK value=$ATTACHNAME|@escape:'url'}
{assign var=ATTACHID value=$ATTACHVALUE['attachid']}
<span>
<i class="fa {$MAIL->getAttachmentIcon($ATTACHVALUE['path'])}"></i>&nbsp;&nbsp;
<a href="index.php?module={$MODULE}&view=Index&_operation=mail&_operationarg=attachment_dld&_muid={$MAIL->muid()}&_atname={$DOWNLOAD_LINK|@escape:'htmlall':'UTF-8'}">
<a href="index.php?module={$MODULE}&view=Index&_operation=mail&_operationarg=attachment_dld&_muid={$MAIL->muid()}&_atid={$ATTACHID}&_atname={$DOWNLOAD_LINK|@escape:'htmlall':'UTF-8'}">
{$ATTACHNAME}
</a>
<span>&nbsp;&nbsp;({$ATTACHVALUE['size']})</span>
<a href="index.php?module={$MODULE}&view=Index&_operation=mail&_operationarg=attachment_dld&_muid={$MAIL->muid()}&_atname={$DOWNLOAD_LINK|@escape:'htmlall':'UTF-8'}">
<a href="index.php?module={$MODULE}&view=Index&_operation=mail&_operationarg=attachment_dld&_muid={$MAIL->muid()}&_atid={$ATTACHID}&_atname={$DOWNLOAD_LINK|@escape:'htmlall':'UTF-8'}">
&nbsp;&nbsp;<i class="fa fa-download"></i>
</a>
</span>
......@@ -135,4 +136,4 @@
</div>
{/if}
</div>
{/strip}
\ No newline at end of file
{/strip}
......@@ -247,8 +247,9 @@ class MailManager_Message_Model extends Vtiger_MailRecord {
* @global Array $upload_badext - List of bad extensions
* @param Boolean $withContent - Used to load the Attachments with/withoud content
* @param String $aName - Attachment Name
* @param Integer $aId - Attachment Id (to eliminate friction with same Attachment Name)
*/
protected function loadAttachmentsFromDB($withContent, $aName=false) {
protected function loadAttachmentsFromDB($withContent, $aName=false, $aId=false) {
$db = PearDatabase::getInstance();
$currentUserModel = Users_Record_Model::getCurrentUserModel();
......@@ -260,7 +261,8 @@ class MailManager_Message_Model extends Vtiger_MailRecord {
$filteredColumns = "aname, attachid, path, cid";
$whereClause = "";
if ($aName) { $whereClause = " AND aname=?"; $params[] = $aName; }
if ($aName) { $whereClause .= " AND aname=?"; $params[] = $aName; }
if ($aId) { $whereClause .= " AND aid=?"; $params[] = $aId; }
$atResult = $db->pquery("SELECT {$filteredColumns} FROM vtiger_mailmanager_mailattachments
WHERE userid=? AND muid=? $whereClause", $params);
......@@ -279,7 +281,7 @@ class MailManager_Message_Model extends Vtiger_MailRecord {
$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);
$this->_attachments[] = array('filename'=>$atResultRow['aname'], 'data' => $data, 'size' => $fileSize, 'path' => $filePath, 'attachid' => $atResultRow['attachid']);
unset($fileContent); // Clear immediately
}
......@@ -404,10 +406,11 @@ class MailManager_Message_Model extends Vtiger_MailRecord {
* Gets the Mail Attachments
* @param Boolean $withContent
* @param String $aName
* @param Integer $aId
* @return List of Attachments
*/
public function attachments($withContent=true, $aName=false) {
$this->loadAttachmentsFromDB($withContent, $aName);
public function attachments($withContent=true, $aName=false, $aId=false) {
$this->loadAttachmentsFromDB($withContent, $aName, $aId);
return $this->_attachments;
}
......@@ -700,4 +703,4 @@ class MailManager_Message_Model extends Vtiger_MailRecord {
return $icon;
}
}
?>
\ No newline at end of file
?>
......@@ -245,6 +245,7 @@ class MailManager_Mail_View extends MailManager_Abstract_View {
} else if ('attachment_dld' == $this->getOperationArg($request)) {
$attachmentName = $request->getRaw('_atname');
$attachmentName= str_replace(' ', '_', $attachmentName);
$attachmentId = $request->get('_atid');
if (MailManager_Utils_Helper::allowedFileExtension($attachmentName)) {
// This is to handle larger uploads
......@@ -253,7 +254,7 @@ class MailManager_Mail_View extends MailManager_Abstract_View {
$mail = new MailManager_Message_Model(false, false);
$mail->readFromDB($request->get('_muid'));
$attachment = $mail->attachments(true, $attachmentName);
$attachment = $mail->attachments(true, $attachmentName, $attachmentId);
//As we are sending attachment name, it will return only that attachment details
if($attachment[0]['data']) {
header("Content-type: application/octet-stream");
......@@ -361,4 +362,4 @@ class MailManager_Mail_View extends MailManager_Abstract_View {
return $request->validateReadAccess();
}
}
?>
\ No newline at end of file
?>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment