You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by an...@apache.org on 2008/07/04 22:08:01 UTC
svn commit: r674111 - in /cocoon/branches/BRANCH_2_1_X:
src/blocks/mail/java/org/apache/cocoon/mail/transformation/SendMailTransformer.java
status.xml
Author: anathaniel
Date: Fri Jul 4 13:08:01 2008
New Revision: 674111
URL: http://svn.apache.org/viewvc?rev=674111&view=rev
Log:
Backport http://svn.apache.org/viewvc?view=rev&revision=314933
Apply patch http://issues.apache.org/jira/browse/COCOON-2213
Modified:
cocoon/branches/BRANCH_2_1_X/src/blocks/mail/java/org/apache/cocoon/mail/transformation/SendMailTransformer.java
cocoon/branches/BRANCH_2_1_X/status.xml
Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/mail/java/org/apache/cocoon/mail/transformation/SendMailTransformer.java
URL: http://svn.apache.org/viewvc/cocoon/branches/BRANCH_2_1_X/src/blocks/mail/java/org/apache/cocoon/mail/transformation/SendMailTransformer.java?rev=674111&r1=674110&r2=674111&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/mail/java/org/apache/cocoon/mail/transformation/SendMailTransformer.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/mail/java/org/apache/cocoon/mail/transformation/SendMailTransformer.java Fri Jul 4 13:08:01 2008
@@ -53,7 +53,7 @@
import org.xml.sax.helpers.AttributesImpl;
/**
- * The SendMailTransformer send mails with optional attachments using a SMTP
+ * The <code>SendMailTransformer</code> send mails with optional attachments using a SMTP
* server and delivers furthermore a status report of each sent mail.
*
* <p>
@@ -198,7 +198,11 @@
* </ul>
* </p>
*
- * @author <a href="mailto:pklassen@s-und-n.de">Peter Klassen</a>
+ * @cocoon.sitemap.component.documentation
+ * The <code>SendMailTransformer</code> send mails with optional attachments using a SMTP
+ * server and delivers furthermore a status report of each sent mail.
+ * @cocoon.sitemap.component.documentation.caching No
+ *
* @version $Id$
*/
public class SendMailTransformer extends AbstractSAXTransformer {
@@ -206,6 +210,7 @@
/*
* constants, related to elements in configuration-file
*/
+
public static final String NAMESPACE = "http://apache.org/cocoon/transformation/sendmail";
public static final String ELEMENT_SENDMAIL = "sendmail";
public static final String ELEMENT_SMTPHOST = "smtphost";
@@ -228,6 +233,7 @@
/*
* mode-constants
*/
+
protected static final int MODE_NONE = 0;
protected static final int MODE_SMTPHOST = 1;
protected static final int MODE_FROM = 2;
@@ -369,9 +375,9 @@
}
Properties outputProperties = new Properties();
- if (this.bodyMimeType.equals("text/plain"))
+ if (this.bodyMimeType.startsWith("text/plain"))
outputProperties.put(OutputKeys.METHOD, "text");
- else if (this.bodyMimeType.equals("text/html"))
+ else if (this.bodyMimeType.startsWith("text/html"))
outputProperties.put(OutputKeys.METHOD, "html");
startSerializedXMLRecording(outputProperties);
this.mode = MODE_BODY;
@@ -579,6 +585,7 @@
// decide, if to take content from source or plain text
// from variable to build mailbody
+ String messageString;
if (this.bodyURI != null) {
Source inSrc = resolver.resolveURI(this.bodyURI);
this.usedSources.add(inSrc);
@@ -586,39 +593,50 @@
byte[] byteArr = new byte[inStr.available()];
inStr.read(byteArr);
- String mailBody = new String(byteArr);
- messageBodyPart.setContent(mailBody, this.bodyMimeType);
+ messageString = new String(byteArr);
+
+ // String mailBody = new String(byteArr);
+ // this.setMessageBody(messageBodyPart, mailBody, this.bodyMimeType);
} else {
- messageBodyPart.setContent(this.body, this.bodyMimeType);
+ messageString = this.body;
+ // this.setMessageBody(messageBodyPart, this.body, this.bodyMimeType);
}
- Multipart multipart = new MimeMultipart();
- multipart.addBodyPart(messageBodyPart);
-
- // process attachments
- Iterator i = this.attachments.iterator();
- while (i.hasNext()) {
- AttachmentDescriptor aD = (AttachmentDescriptor) i.next();
- messageBodyPart = new MimeBodyPart();
-
- if (!aD.isTextContent()) {
- Source inputSource = resolver.resolveURI(aD.isURLSource() ? aD.strAttrSrc : aD.strAttrFile);
- this.usedSources.add(inputSource);
+ // make it a simple plain text message in the case of a set plain/text
+ // mime-type and any attachements
+ if (this.bodyMimeType.startsWith("text/plain") && this.attachments.size() == 0) {
+ sm.setText(messageString);
+ }
+ // add message as message body part
+ else {
+ messageBodyPart.setContent(messageString, this.bodyMimeType);
+ Multipart multipart = new MimeMultipart();
+ multipart.addBodyPart(messageBodyPart);
- DataSource dataSource = new SourceDataSource(inputSource, aD.strAttrMimeType, aD.strAttrName);
- ((SourceDataSource) dataSource).enableLogging(getLogger());
+ // process attachments
+ Iterator i = this.attachments.iterator();
+ while (i.hasNext()) {
+ AttachmentDescriptor aD = (AttachmentDescriptor) i.next();
+ messageBodyPart = new MimeBodyPart();
+
+ if (!aD.isTextContent()) {
+ Source inputSource = resolver.resolveURI(aD.isURLSource() ? aD.strAttrSrc : aD.strAttrFile);
+ this.usedSources.add(inputSource);
+
+ DataSource dataSource = new SourceDataSource(inputSource, aD.strAttrMimeType, aD.strAttrName);
+ ((SourceDataSource) dataSource).enableLogging(getLogger());
+
+ messageBodyPart.setDataHandler(new DataHandler(dataSource));
+ } else {
+ messageBodyPart.setContent(aD.strContent, aD.strAttrMimeType);
+ }
- messageBodyPart.setDataHandler(new DataHandler(dataSource));
- } else {
- messageBodyPart.setContent(aD.strContent, aD.strAttrMimeType);
+ messageBodyPart.setFileName(aD.strAttrName);
+ multipart.addBodyPart(messageBodyPart);
}
-
- messageBodyPart.setFileName(aD.strAttrName);
- multipart.addBodyPart(messageBodyPart);
+ sm.setContent(multipart);
}
- sm.setContent(multipart);
-
//sm.setReturnOption(SMTPMessage.RETURN_FULL);
sm.saveChanges();
Modified: cocoon/branches/BRANCH_2_1_X/status.xml
URL: http://svn.apache.org/viewvc/cocoon/branches/BRANCH_2_1_X/status.xml?rev=674111&r1=674110&r2=674111&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/status.xml (original)
+++ cocoon/branches/BRANCH_2_1_X/status.xml Fri Jul 4 13:08:01 2008
@@ -186,6 +186,15 @@
<action dev="all" type="update">
Starting with 2.1.12 the minimum required Java version will be 1.4.2.
</action>
+ <action dev="AN" type="fix" fixes-bug="COCOON-2213" due-to="Jasha Joachimsthal" due-to-email="j.joachimsthal@onehippo.com">
+ Mail block: Allow mime-type to explicitly set a charset as in mime-type="text/html;charset=UTF-8".
+ </action>
+ <action dev="RP" type="fix">
+ Mail block: Make a difference between plain text mails and mails that have a multi-part body.
+ If the mail-body has set the mime-type="text/plain", then the message body isn't send as
+ body part but as simple content. That avoids getting a plain text-message without attachment
+ being marked as mail with attachment.
+ </action>
<action dev="JH" type="update">
Core: Cocoon's pipeline buffer increases from an initial buffer size of 8192 bytes to the configurable flush
buffer size rather than allocating the complete buffer beforehand.