Re: Possible to display JPG attachment in email
Posted by
Coleen_Astalos on
May 22, 2014; 2:55pm
URL: https://support.nabble.com/Possible-to-display-JPG-attachment-in-email-tp7589178p7590349.html
You provided this customization for us to display a picture of an image file instead of the standard paperclip icon:
Pedro <Nabble> wrote
Please, try this code:
<override_macro name="message_as_html" requires="message">
<n.if.either condition1="[n.is_deleted/]" condition2="[n.is_deactivated/]">
<then>
<b><t>CONTENTS DELETED</t></b>
<div class="weak-color"><t>The author has deleted this message.</t></div>
</then>
<else>
<n.set_var. name="output">
<n.as_html_list.process_message_html />
</n.set_var.>
<n.if.is_imported_mail>
<then>
<n.set_var. name="output">
<n.remove_unsubscription_link.var name="output" />
</n.set_var.>
<n.comment>
PART 1: Copy the attachment links to a variable
</n.comment>
<n.set_var. name="attachments">
<n.regex. text="[n.var name='output'/]" pattern="[n.attachments_regex/]">
<n.if.find>
<then.found/>
</n.if.find>
</n.regex.>
</n.set_var.>
<n.set_var. name="thumb_url">
<n.regex. text="[n.var name='attachments'/]" pattern="[n.href_regex/]">
<n.if.find>
<then>
<n.regex_replace_all text = "[n.found/]" pattern="href=" replacement = ''/>
</then>
</n.if.find>
</n.regex.>
</n.set_var.>
<n.regex. text="[n.var name='thumb_url'/]" pattern="\w+\.(jpg|gif|png)">
<n.if.find>
<then>
<n.set_var. name="thumb_url">
height = '100px' width='100px' src=
<n.regex_replace_all text = "[n.var name='thumb_url'/]" pattern="href=" replacement = ''/>
\>
</n.set_var.>
<n.set_var. name="attachments">
<n.regex_replace_all text = "[n.var name='attachments'/]" pattern="[n.img_regex/]" replacement = "[n.var name='thumb_url'/]"/>
</n.set_var.>
</then>
</n.if.find>
</n.regex.>
<n.comment>
PART 2: Rebuild the "output" variable by placing the attachments at the top.
At the end, we remove the old attachments so that we don't show duplicate links.
</n.comment>
<n.set_var. name="output">
<n.var name='attachments' />
<br/>
<n.regex_replace_all text = "[n.var name='output'/]" pattern="[n.attachments_regex/]" replacement ='' />
</n.set_var.>
</then>
</n.if.is_imported_mail>
<n.var name="output" />
</else>
</n.if.either>
</override_macro>
<macro name="attachments_regex">
<![CDATA[<!--start-attachments-->.*<!--end-attachments-->]]>
</macro>
<macro name="img_regex">
<![CDATA[src=.*?\>]]>
</macro>
<macro name="href_regex">
<![CDATA[href="([^"]*)"]]>
</macro>
This works great 95% of the time when my members only have one image attached to an email. However, when they have more than one image the first image is displayed for all the icons.
This is confusing to many members as they think each attachment is the same. So I'm looking for alternate solutions for the case where there are multiple images attached to an email.
The ideal solution would be that the corresponding image is displayed for each attachment. Is that possible?
If that is not possible I have some alternate ideas we could explore.
Let me know,
Thanks,
Coleen