You are viewing a plain text version of this content. The canonical link for it is here.
Posted to taglibs-dev@jakarta.apache.org by bu...@apache.org on 2004/10/23 04:41:51 UTC
DO NOT REPLY [Bug 31859] New: -
Add filename based Content-ID to attachments and url based message bodies.
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=31859>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND
INSERTED IN THE BUG DATABASE.
http://issues.apache.org/bugzilla/show_bug.cgi?id=31859
Add filename based Content-ID to attachments and url based message bodies.
Summary: Add filename based Content-ID to attachments and url
based message bodies.
Product: Taglibs
Version: 1.1.0
Platform: All
URL: http://home.insightbb.com/~robertmurphy/mailer.html
OS/Version: All
Status: NEW
Severity: Enhancement
Priority: Other
Component: Mailer Taglib
AssignedTo: taglibs-dev@jakarta.apache.org
ReportedBy: robertmurphy@insightbb.com
The two diffs add the folowing:
<mt:message url="http://www.domain.net"/>
<mt:message url="">
http://www.domain.net
</mt:message>
And, when attaching a file, each attachment will have a Content-ID based on the
filename.
Index: AttachTag.java
===================================================================
--- AttachTag.java (revision 1)
+++ AttachTag.java (working copy)
@@ -97,8 +97,13 @@
}
mbp = new MimeBodyPart(); // create the bodypart for this attachment
body = null;
- if (type != null || (file != null && file.length() == 0) ||
- (url != null && url.length() == 0) ) {
+ if (
+ type != null
+ ||
+ (file != null && file.length() == 0)
+ ||
+ (url != null && url.length() == 0)
+ ) {
return EVAL_BODY_TAG;
}
return SKIP_BODY;
@@ -233,10 +238,13 @@
try {
URL url = new URL(value);
mbp.setDataHandler(new DataHandler(url));
- if(url.getFile() != null)
+ if(url.getFile() != null) {
mbp.setFileName(url.getFile());
- else
+ mbp.setContentID(url.getFile());
+ } else {
mbp.setFileName(value);
+ mbp.setContentID(value);
+ }
} catch(MalformedURLException e) {
throw new JspException("The URL entered as an attachment was " +
@@ -268,6 +276,7 @@
DataSource attachment = new FileDataSource(file);
mbp.setDataHandler(new DataHandler(attachment));
mbp.setFileName(file.getName());
+ mbp.setContentID(file.getName());
} else {
// if the file does not exist it is probably an error in the way
// the page author is adding the path throw an exception so this
Index: MessageTag.java
===================================================================
--- MessageTag.java (revision 1)
+++ MessageTag.java (working copy)
@@ -19,6 +19,11 @@
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.BodyContent;
import javax.servlet.jsp.tagext.BodyTagSupport;
+import java.net.URL;
+import javax.mail.internet.MimeBodyPart;
+import javax.activation.DataHandler;
+import java.net.MalformedURLException;
+import javax.mail.MessagingException;
/**
* MessageTag - JSP tag <b>Message</b> is used to set the message in an e-mail.
@@ -55,11 +60,27 @@
private String type = "text";
/**
+ * holds the value of body if the url is to be retrieved from the body of
+ * tag
+ */
+ private String url = null;
+
+ /**
* character set to be used (default is unspecified)
*/
private String charset = null;
/**
+ * object in which the attachment is stored within the e-mail message
+ */
+ private MimeBodyPart mbp = null;
+
+ /**
+ * pointer to the parent tag
+ */
+ private MailTag myparent = null;
+
+ /**
* implementation of the method from the tag interface that tells the JSP
* page what to do after the body of this tag
*
@@ -71,26 +92,81 @@
*
*/
public int doAfterBody() throws JspException {
+ BodyContent body = getBodyContent();
+ mbp = new MimeBodyPart(); // create the bodypart for this attachment
+ myparent = (MailTag)findAncestorWithClass(this, MailTag.class);
+ if (url == null) {
+ // parent tag must be a MailTag, gives access to methods in parent
+ if (myparent == null) {
+ throw new JspException("message tag not nested within mail tag");
+ }
+
+ String message = body.getString();
+ // Clear the body since we only used it as input for the email address
+ body.clearBody();
+ if (message == null) {
+ throw new JspException("The message tag is empty");
+ }
+ myparent.setMessage(message); // set message in the parent tag
+ myparent.setType(type); // set the mime type of the message
+ myparent.setCharset(charset); // set the character set of the message
+
+ } else if (url.length() == 0 && body != null) {
+ String s_body = body.getString();
+ if(s_body != null)
+ s_body = s_body.trim();
+ // the url is supposed to come from the body of the tag
+ if (s_body.length() > 0) {
+ // prepare the file or url resource to be an attachment
+ setUrlBodyPart(s_body);
+ } else {
+ // body is empty throw error
+ throw new JspException(
+ "The url must be givenin the body of this tag.");
+ }
+ } else
+ // create the attachment with the url in the url attribute
+ setUrlBodyPart(url);
+ return SKIP_BODY;
+ }
- // parent tag must be a MailTag, gives access to methods in parent
- MailTag myparent = (MailTag)findAncestorWithClass(this, MailTag.class);
- if (myparent == null) {
- throw new JspException("message tag not nested within mail tag");
- }
+ /**
+ * wrap the url named attachment in the approiate datahandler and create a
+ * mimebodypart to be added to the list of attachments
+ *
+ * @param value string that represents a URL
+ *
+ */
+ protected void setUrlBodyPart(String value) throws JspException {
- BodyContent body = getBodyContent();
- String message = body.getString();
- // Clear the body since we only used it as input for the email address
- body.clearBody();
- if (message == null) {
- throw new JspException("The message tag is empty");
+// Added by Jayson Falkner - 5/8/2001
+
+ try {
+ URL url = new URL(value);
+ mbp.setDataHandler(new DataHandler(url));
+ if(url.getFile() != null) {
+ mbp.setFileName(url.getFile());
+ mbp.setContentID(url.getFile());
+ } else {
+ mbp.setFileName(value);
+ mbp.setContentID(value);
+ }
+ myparent.setMessage((String)mbp.getContent()); // set message in
the parent tag
+ myparent.setType(type); // set the mime type of the message
+ myparent.setCharset(charset); // set the character set of the message
+ } catch(MalformedURLException e) {
+ throw new JspException("The URL entered as an attachment was " +
+ "incorrectly formatted please check it and try again.");
+ } catch(MessagingException e) {
+ throw new JspException("The Resource named by " + url + " could not"
+ + " be used as the message body.");
+ } catch(java.io.IOException ioe) {
+ throw new JspException("The Resource named by " + url + " could not"
+ + " be cast to a String.");
}
- myparent.setMessage(message); // set message in the parent tag
- myparent.setType(type); // set the mime type of the message
- myparent.setCharset(charset); // set the character set of the message
- return SKIP_BODY;
+// End of added
}
-
+
/**
* set the mime type for this email text or html
*
@@ -110,4 +186,15 @@
public void setCharset(String value) {
charset = value;
}
+
+ /**
+ * set the resource named by URL into a mimebodypart so that it can be added
+ * to the list of attachments for this e-mail
+ *
+ * @param value full url including http://, to the resource to be added as
+ * an attachment
+ */
+ public void setUrl(String value) {
+ url = value;
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: taglibs-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: taglibs-dev-help@jakarta.apache.org