[Vtigercrm-developers] Displaying inline images in E-Mails

nicolas GASNIER nicolas.gasnier at holdisgroup.fr
Fri Aug 24 07:28:09 PDT 2012


Hi everyone,

I've been trying recently to improve the Emails module. The inline images are not displayed in Vtiger because it doesn't translate the images URLs to internal attachments references.
To display properly the images, image links in the form <img src="cid:afilename.jpg at SOMEPARTIDORSOMETHINGLIKETHAT"> should be translated to the form <img src=" index.php?module=uploads&action=downloadfile&return_module=Emails&fileid=ATTACHMENTID&entityid=EMAILID\">.
This is not an easy task because VTiger doesn't store the attachment in a form that can be easily resolved using the cid link. The Outlook plugin will save the image using a renamed filename in the form "SOMERANDOMNUMBER_afilename.jpg".

Knowing that, I tried to make some search-and-replace code in modules\Emails\DetailView.php to handle the replacement of images.
I first get the list of attachments and map their filename to database ID, removing the random part of the name. Then I use some basic regexp search to replace the cid form of the image URL to the vTiger form in the email content.

Here's what the code looks like, added around the line 138 (version 5.4.0) :

$pjs = $adb->pquery("SELECT vtiger_attachments.* "
    ."FROM vtiger_seattachmentsrel INNER JOIN vtiger_attachments ON vtiger_seattachmentsrel.attachmentsid = vtiger_attachments.attachmentsid "
    ."WHERE vtiger_seattachmentsrel.crmid=".$_REQUEST['record'], array());
$nb = $adb->num_rows($pjs);
$pjs_id = array();
for ($i=0;$i<$nb;$i++)
{
    $pj = $adb->fetchByAssoc($pjs, $i);
    $pos = strpos($pj["name"], "_");
    if ($pos!==FALSE)
    {
        $pj["name"] = substr($pj["name"], $pos+1);
    }
    $pjs_id[$pj["name"]] = $pj["attachmentsid"];
}

$nb = preg_match_all("/[\"\']cid:([^\"\']+)(@[^\"\']+)[\"\']/", $entries[$mod_strings['LBL_EMAIL_INFORMATION']][7][$mod_strings['Description']]['value'], $matches);
for ($i=0;$i<$nb;$i++)
{
    $lien_image = "\"index.php?module=uploads&action=downloadfile&return_module=Emails&fileid=".$pjs_id[$matches[1][$i]]."&entityid=".$_REQUEST["record"]."\"";
    $entries[$mod_strings['LBL_EMAIL_INFORMATION']][7][$mod_strings['Description']]['value'] =
        str_replace($matches[0][$i], $lien_image, $entries[$mod_strings['LBL_EMAIL_INFORMATION']][7][$mod_strings['Description']]['value']);
}

This does the trick, and works well as a quick-fix for me. This solution has the advantage to work without needing any modification in the way e-mails are stored and handled by the various vtiger components (including the outlook plugin).
But I don't know if it will handle all the cases properly.

Do you think I should submit a patch in the bug tracker ?  Does someone have suggestions or better solution to handle this (like modifications to the outlook plugin or saving code...) ?
How can we do to include this improvement in the standard VTiger for future version ?

Thank you for your attention. Have a good week end.

Regards

Nicolas GASNIER
Développeur
HOLDIS AGRIDIS
1 rue des MORELLES
ZA Euro Val de Loire
41330 FOSSE
Tél : 02 54 81 48 44


________________________________
Ce message et toutes les pièces jointes (ci-après le "message") sont établis à l'intention exclusive de ses destinataires et sont confidentiels. Si vous recevez ce message par erreur, merci de le détruire et d'en avertir immédiatement l'expéditeur. Toute utilisation de ce message non conforme à sa destination, toute diffusion ou toute publication, totale ou partielle, est interdite, sauf autorisation expresse. L'internet ne permettant pas d'assurer l'intégrité de ce message, notre société décline par ailleurs toute responsabilité dans l'hypothèse où il aurait été modifié.

This message and any attached files (the "message") are intended solely for the addressees and are confidential. If you receive this message in error, please delete it and immediately notify the sender. Any use not in accord with its purpose, any dissemination or disclosure, either whole or partial, is prohibited except if there is formal approval. The Internet cannot guarantee the integrity of this message, our company shall not therefore be liable for the message if modified.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.vtigercrm.com/pipermail/vtigercrm-developers/attachments/20120824/f24239d1/attachment.html 


More information about the vtigercrm-developers mailing list