<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Generator" content="Microsoft Word 12 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:"Calibri","sans-serif";
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:70.85pt 70.85pt 70.85pt 70.85pt;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="FR" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal"><span lang="EN-US">Hi everyone,<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">I&#8217;ve been trying recently to improve the Emails module. The inline images are not displayed in Vtiger because it doesn&#8217;t translate the images URLs to internal attachments references.
<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">To display properly the images, image links in the form &lt;img src=&#8220;cid:afilename.jpg@SOMEPARTIDORSOMETHINGLIKETHAT&#8221;&gt; should be translated to the form &lt;img src=&#8221; index.php?module=uploads&amp;action=downloadfile&amp;return_module=Emails&amp;fileid=ATTACHMENTID&amp;entityid=EMAILID\&#8221;&gt;.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">This is not an easy task because VTiger doesn&#8217;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 &#8220;SOMERANDOMNUMBER_afilename.jpg&#8221;.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">Knowing that, I tried to make some search-and-replace code in modules\Emails\DetailView.php to handle the replacement of images.
<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">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.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">Here&#8217;s what the code looks like, added around the line 138 (version 5.4.0) :<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">$pjs = $adb-&gt;pquery(&quot;SELECT vtiger_attachments.* &quot;<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">&nbsp;&nbsp;&nbsp; .&quot;FROM vtiger_seattachmentsrel INNER JOIN vtiger_attachments ON vtiger_seattachmentsrel.attachmentsid = vtiger_attachments.attachmentsid &quot;<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">&nbsp;&nbsp;&nbsp; .&quot;WHERE vtiger_seattachmentsrel.crmid=&quot;.$_REQUEST['record'], array());<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">$nb = $adb-&gt;num_rows($pjs);<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">$pjs_id = array();<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">for ($i=0;$i&lt;$nb;$i&#43;&#43;)<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">{<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">&nbsp;&nbsp;&nbsp; $pj = $adb-&gt;fetchByAssoc($pjs, $i);<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">&nbsp;&nbsp;&nbsp; $pos = strpos($pj[&quot;name&quot;], &quot;_&quot;);<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">&nbsp;&nbsp;&nbsp; if ($pos!==FALSE)<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">&nbsp;&nbsp;&nbsp; {<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $pj[&quot;name&quot;] = substr($pj[&quot;name&quot;], $pos&#43;1);<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">&nbsp;&nbsp;&nbsp; }<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">&nbsp;&nbsp;&nbsp; $pjs_id[$pj[&quot;name&quot;]] = $pj[&quot;attachmentsid&quot;];<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">}<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">$nb = preg_match_all(&quot;/[\&quot;\']cid:([^\&quot;\']&#43;)(@[^\&quot;\']&#43;)[\&quot;\']/&quot;, $entries[$mod_strings['LBL_EMAIL_INFORMATION']][7][$mod_strings['Description']]['value'], $matches);<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">for ($i=0;$i&lt;$nb;$i&#43;&#43;)<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">{<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">&nbsp;&nbsp;&nbsp; $lien_image = &quot;\&quot;index.php?module=uploads&amp;action=downloadfile&amp;return_module=Emails&amp;fileid=&quot;.$pjs_id[$matches[1][$i]].&quot;&amp;entityid=&quot;.$_REQUEST[&quot;record&quot;].&quot;\&quot;&quot;;<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">&nbsp;&nbsp;&nbsp; $entries[$mod_strings['LBL_EMAIL_INFORMATION']][7][$mod_strings['Description']]['value'] =
<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;str_replace($matches[0][$i], $lien_image, $entries[$mod_strings['LBL_EMAIL_INFORMATION']][7][$mod_strings['Description']]['value']);<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">}<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">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). &nbsp;<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">But I don&#8217;t know if it will handle all the cases properly.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">Do you think I should submit a patch in the bug tracker ?&nbsp; Does someone have suggestions or better solution to handle this (like modifications to the outlook plugin or saving code&#8230;) ?
<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">How can we do to include this improvement in the standard VTiger for future version ?<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">Thank you for your attention. Have a good week end.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">Regards<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">Nicolas GASNIER<o:p></o:p></span></p>
<p class="MsoNormal">Développeur<o:p></o:p></p>
<p class="MsoNormal">HOLDIS AGRIDIS<o:p></o:p></p>
<p class="MsoNormal">1 rue des MORELLES<o:p></o:p></p>
<p class="MsoNormal">ZA Euro Val de Loire<o:p></o:p></p>
<p class="MsoNormal">41330 FOSSE<o:p></o:p></p>
<p class="MsoNormal">Tél : 02 54 81 48 44<o:p></o:p></p>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
</div>
<br>
<hr>
<font face="Arial" color="Navy" size="1">Ce message et toutes les pièces jointes (ci-après le &quot;message&quot;) 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&#8217;hypothèse où il aurait été modifié.<br>
<br>
This message and any attached files (the &quot;message&quot;) 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.<br>
</font>
</body>
</html>