You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Dominik Stadler (JIRA)" <ji...@apache.org> on 2010/07/13 06:08:51 UTC
[jira] Issue Comment Edited: (EMAIL-92) Improve support to embed
images in HTML eMails
[ https://issues.apache.org/jira/browse/EMAIL-92?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12887645#action_12887645 ]
Dominik Stadler edited comment on EMAIL-92 at 7/13/10 12:07 AM:
----------------------------------------------------------------
Looks better now. Here another small patch, it seems the regex was corrupted with the last checkin, there is now a "\\" missing in front of "s":
{code}
### Eclipse Workspace Patch 1.0
#P commons-email-trunk
Index: src/java/org/apache/commons/mail/ImageHtmlEmail.java
===================================================================
--- src/java/org/apache/commons/mail/ImageHtmlEmail.java (revision 963592)
+++ src/java/org/apache/commons/mail/ImageHtmlEmail.java (working copy)
@@ -54,11 +55,11 @@
* newlines on any place, HTML is not case sensitive and there can be
* arbitrary text between "IMG" and "SRC" like IDs and other things.
*/
- public static final String REGEX_IMG_SRC = "(<[Ii][Mm][Gg]\\s*[^>]*?\\s+[Ss][Rr][Cc]\\s*=s*[\"'])([^\"']+?)([\"'])";
+ public static final String REGEX_IMG_SRC = "(<[Ii][Mm][Gg]\\s*[^>]*?\\s+[Ss][Rr][Cc]\\s*=\\s*[\"'])([^\"']+?)([\"'])";
public static final String REGEX_SCRIPT_SRC = "(<[Ss][Cc][Rr][Ii][Pp][Tt]\\s*.*?\\s+[Ss][Rr][Cc]\\s*=\\s*[\"'])([^\"']+?)([\"'])";
- // this pattern looks for the HTML imgage tag which indicates embedded images,
+ // this pattern looks for the HTML image tag which indicates embedded images,
// the grouping is necessary to allow to replace the element with the CID
protected static final Pattern pattern = Pattern.compile(REGEX_IMG_SRC);
{code}
was (Author: dominik.stadler@gmx.at):
Looks better now. Here another small patch, it seems the regex was corrupted with the last checkin, there is now a "\\" missing in front of "s":
### Eclipse Workspace Patch 1.0
#P commons-email-trunk
Index: src/java/org/apache/commons/mail/ImageHtmlEmail.java
===================================================================
--- src/java/org/apache/commons/mail/ImageHtmlEmail.java (revision 963592)
+++ src/java/org/apache/commons/mail/ImageHtmlEmail.java (working copy)
@@ -54,11 +55,11 @@
* newlines on any place, HTML is not case sensitive and there can be
* arbitrary text between "IMG" and "SRC" like IDs and other things.
*/
- public static final String REGEX_IMG_SRC = "(<[Ii][Mm][Gg]\\s*[^>]*?\\s+[Ss][Rr][Cc]\\s*=s*[\"'])([^\"']+?)([\"'])";
+ public static final String REGEX_IMG_SRC = "(<[Ii][Mm][Gg]\\s*[^>]*?\\s+[Ss][Rr][Cc]\\s*=\\s*[\"'])([^\"']+?)([\"'])";
public static final String REGEX_SCRIPT_SRC = "(<[Ss][Cc][Rr][Ii][Pp][Tt]\\s*.*?\\s+[Ss][Rr][Cc]\\s*=\\s*[\"'])([^\"']+?)([\"'])";
- // this pattern looks for the HTML imgage tag which indicates embedded images,
+ // this pattern looks for the HTML image tag which indicates embedded images,
// the grouping is necessary to allow to replace the element with the CID
protected static final Pattern pattern = Pattern.compile(REGEX_IMG_SRC);
> Improve support to embed images in HTML eMails
> ----------------------------------------------
>
> Key: EMAIL-92
> URL: https://issues.apache.org/jira/browse/EMAIL-92
> Project: Commons Email
> Issue Type: New Feature
> Reporter: Dominik Stadler
> Assignee: Siegfried Goeschl
> Attachments: EMAIL-92-with-test.patch, ImageHtmlEmail.java, ImageHtmlEmail.java
>
>
> I have created a improvement on top of HtmlEmail class which automatically detects <img src=".."/> tags in the HTML source and which embeds all the URLs correctly in the email so they are sent as attachments as part of the email.
> It is implemented as new class ImageHtmlEmail, no existing code of commons email is touched at all.
> This make sending HTML Mails much easier, now it is as simple as
> ImageHtmlEmail email = new ImageHtmlEmail();
> email.setHostName(SMTP_HOST);
> email.addTo(EMAIL_TO, "DS");
> email.setFrom(EMAIL_FROM, "Me");
> email.setSubject(EMAIL_SUBJECT);
>
> String html = FileUtils.readFileToString(new File("/tmp/test_email.html"));
>
> // set the html message
> email.setHtmlMsg(html, new File("/tmp"));
> // set the alternative message
> email.setTextMsg("Your email client does not support HTML messages");
> // send the email
> email.send();
> as stated in the mail, I am making this availalbe under the Apache License 2.0 so that it can be integrated if it sounds useful.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.