Author: bago
Date: Fri Aug 12 00:46:09 2005
New Revision: 232226
URL: http://svn.apache.org/viewcvs?rev=232226&view=rev
Log:
The delivery-status created by DSNBounce was not rfc1894 compliant (it ab-used
rfc822 container) (JAMES-378).
Changed it to text-plain (it is not fully compliant but most compliant than
before).
Added support for only headers original message attachment (heads) and removed
inner DSNStatus (the same class was already in the util.dsn package)
Modified:
james/server/trunk/src/java/org/apache/james/transport/mailets/AbstractRedirect.java
james/server/trunk/src/java/org/apache/james/transport/mailets/DSNBounce.java
Modified:
james/server/trunk/src/java/org/apache/james/transport/mailets/AbstractRedirect.java
URL:
http://svn.apache.org/viewcvs/james/server/trunk/src/java/org/apache/james/transport/mailets/AbstractRedirect.java?rev=232226&r1=232225&r2=232226&view=diff
==============================================================================
---
james/server/trunk/src/java/org/apache/james/transport/mailets/AbstractRedirect.java
(original)
+++
james/server/trunk/src/java/org/apache/james/transport/mailets/AbstractRedirect.java
Fri Aug 12 00:46:09 2005
@@ -37,7 +37,6 @@
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;
-import javax.mail.internet.AddressException;
import org.apache.mailet.RFC2822Headers;
import org.apache.mailet.dates.RFC822DateFormat;
@@ -1219,7 +1218,7 @@
* Utility method for obtaining a string representation of a
* Message's headers
*/
- private String getMessageHeaders(MimeMessage message) throws
MessagingException {
+ protected String getMessageHeaders(MimeMessage message) throws
MessagingException {
Enumeration heads = message.getAllHeaderLines();
StringBuffer headBuffer = new StringBuffer(1024);
while(heads.hasMoreElements()) {
Modified:
james/server/trunk/src/java/org/apache/james/transport/mailets/DSNBounce.java
URL:
http://svn.apache.org/viewcvs/james/server/trunk/src/java/org/apache/james/transport/mailets/DSNBounce.java?rev=232226&r1=232225&r2=232226&view=diff
==============================================================================
---
james/server/trunk/src/java/org/apache/james/transport/mailets/DSNBounce.java
(original)
+++
james/server/trunk/src/java/org/apache/james/transport/mailets/DSNBounce.java
Fri Aug 12 00:46:09 2005
@@ -35,9 +35,6 @@
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
-import javax.activation.CommandMap;
-import javax.activation.MailcapCommandMap;
-
import org.apache.james.core.MailImpl;
import org.apache.mailet.Mail;
import org.apache.mailet.MailAddress;
@@ -45,6 +42,7 @@
import org.apache.mailet.dates.RFC822DateFormat;
import org.apache.james.Constants;
import org.apache.james.util.mail.MimeMultipartReport;
+import org.apache.james.util.mail.dsn.DSNStatus;
import org.apache.oro.text.regex.MalformedPatternException;
import org.apache.oro.text.regex.Pattern;
@@ -75,7 +73,7 @@
default=postmaster</I></sender>
* <prefix><I>optional subject prefix prepended to the original
message</I></prefix>
- * <attachment><I>message or none,
default=message</I></attachment>
+ * <attachment><I>message, heads or none,
default=message</I></attachment>
* <messageString><I>the message sent in the bounce, the first
occurrence of the pattern [machine] is replaced with the name of the executing
machine, default=Hi. This is the James mail server at [machine] ...
</I></messageString>
* <passThrough><I>true or false, default=true</I></passThrough>
* <debug><I>true or false, default=false</I></debug>
@@ -90,334 +88,6 @@
public class DSNBounce extends AbstractNotify {
- /**
- * Constants and getters for RFC 3463 Enhanced Mail System Status Codes
- *
- * I suggest do extract this inner class for future use in the smtp-handler
- *
- */
- public static class DSNStatus {
- // status code classes
- /**
- * Success
- */
- public static final int SUCCESS = 2;
-
- /**
- * Persistent Transient Failure
- */
- public static final int TRANSIENT = 4;
-
- /**
- * Permanent Failure
- */
- public static final int PERMANENT = 5;
-
- // subjects and details
-
- /**
- * Other or Undefined Status
- */
- public static final int UNDEFINED = 0;
-
- /**
- * Other undefined status
- */
- public static final String UNDEFINED_STATUS = "0.0";
-
- /**
- * Addressing Status
- */
- public static final int ADDRESS = 1;
-
- /**
- * Other address status
- */
- public static final String ADDRESS_OTHER = "1.0";
-
- /**
- * Bad destination mailbox address
- */
- public static final String ADDRESS_MAILBOX = "1.1";
-
- /**
- * Bad destination system address
- */
- public static final String ADDRESS_SYSTEM = "1.2";
-
- /**
- * Bad destination mailbox address syntax
- */
- public static final String ADDRESS_SYNTAX = "1.3";
-
- /**
- * Destination mailbox address ambiguous
- */
- public static final String ADDRESS_AMBIGUOUS = "1.4";
-
- /**
- * Destination Address valid
- */
- public static final String ADDRESS_VALID = "1.5";
-
- /**
- * Destimation mailbox has moved, no forwarding address
- */
- public static final String ADDRESS_MOVED = "1.6";
-
- /**
- * Bad sender's mailbox address syntax
- */
- public static final String ADDRESS_SYNTAX_SENDER = "1.7";
-
- /**
- * Bad sender's system address
- */
- public static final String ADDRESS_SYSTEM_SENDER = "1.8";
-
-
- /**
- * Mailbox Status
- */
- public static final int MAILBOX = 2;
-
- /**
- * Other or Undefined Mailbox Status
- */
- public static final String MAILBOX_OTHER = "2.0";
-
- /**
- * Mailbox disabled, not accepting messages
- */
- public static final String MAILBOX_DISABLED = "2.1";
-
- /**
- * Mailbox full
- */
- public static final String MAILBOX_FULL = "2.2";
-
- /**
- * Message length exceeds administrative limit
- */
- public static final String MAILBOX_MSG_TOO_BIG = "2.3";
-
- /**
- * Mailing list expansion problem
- */
- public static final String MAILBOX_LIST_EXPANSION = "2.4";
-
-
- /**
- * Mail System Status
- */
- public static final int SYSTEM = 3;
-
- /**
- * Other or undefined mail system status
- */
- public static final String SYSTEM_OTHER = "3.0";
-
- /**
- * Mail system full
- */
- public static final String SYSTEM_FULL = "3.1";
-
- /**
- * System not accepting messages
- */
- public static final String SYSTEM_NOT_ACCEPTING = "3.2";
-
- /**
- * System not capable of selected features
- */
- public static final String SYSTEM_NOT_CAPABLE = "3.3";
-
- /**
- * Message too big for system
- */
- public static final String SYSTEM_MSG_TOO_BIG = "3.4";
-
- /**
- * System incorrectly configured
- */
- public static final String SYSTEM_CFG_ERROR = "3.5";
-
-
- /**
- * Network and Routing Status
- */
- public static final int NETWORK = 4;
-
- /**
- * Other or undefined network or routing status
- */
- public static final String NETWORK_OTHER = "4.0";
-
- /**
- * No answer form host
- */
- public static final String NETWORK_NO_ANSWER = "4.1";
-
- /**
- * Bad Connection
- */
- public static final String NETWORK_CONNECTION = "4.2";
-
- /**
- * Directory server failure
- */
- public static final String NETWORK_DIR_SERVER = "4.3";
-
- /**
- * Unable to route
- */
- public static final String NETWORK_ROUTE = "4.4";
-
- /**
- * Mail system congestion
- */
- public static final String NETWORK_CONGESTION = "4.5";
-
- /**
- * Routing loop detected
- */
- public static final String NETWORK_LOOP = "4.6";
-
- /**
- * Delivery time expired
- */
- public static final String NETWORK_EXPIRED = "4.7";
-
-
- /**
- * Mail Delivery Protocol Status
- */
- public static final int DELIVERY = 5;
-
- /**
- * Other or undefined (SMTP) protocol status
- */
- public static final String DELIVERY_OTHER = "5.0";
-
- /**
- * Invalid command
- */
- public static final String DELIVERY_INVALID_CMD = "5.1";
-
- /**
- * Syntax error
- */
- public static final String DELIVERY_SYNTAX = "5.2";
-
- /**
- * Too many recipients
- */
- public static final String DELIVERY_TOO_MANY_REC = "5.3";
-
- /**
- * Invalid command arguments
- */
- public static final String DELIVERY_INVALID_ARG = "5.4";
-
- /**
- * Wrong protocol version
- */
- public static final String DELIVERY_VERSION = "5.5";
-
-
- /**
- * Message Content or Media Status
- */
- public static final int CONTENT = 6;
-
- /**
- * Other or undefined media error
- */
- public static final String CONTENT_OTHER = "6.0";
-
- /**
- * Media not supported
- */
- public static final String CONTENT_UNSUPPORTED = "6.1";
-
- /**
- * Conversion required and prohibited
- */
- public static final String CONTENT_CONVERSION_NOT_ALLOWED = "6.2";
-
- /**
- * Conversion required, but not supported
- */
- public static final String CONTENT_CONVERSION_NOT_SUPPORTED = "6.3";
-
- /**
- * Conversion with loss performed
- */
- public static final String CONTENT_CONVERSION_LOSS = "6.4";
-
- /**
- * Conversion failed
- */
- public static final String CONTENT_CONVERSION_FAILED = "6.5";
-
-
- /**
- * Security or Policy Status
- */
- public static final int SECURITY = 7;
-
- /**
- * Other or undefined security status
- */
- public static final String SECURITY_OTHER = "7.0";
-
- /**
- * Delivery not authorized, message refused
- */
- public static final String SECURITY_AUTH = "7.1";
-
- /**
- * Mailing list expansion prohibited
- */
- public static final String SECURITY_LIST_EXP = "7.2";
-
- /**
- * Security conversion required, but not possible
- */
- public static final String SECURITY_CONVERSION = "7.3";
-
- /**
- * Security features not supported
- */
- public static final String SECURITY_UNSUPPORTED = "7.4";
-
- /**
- * Cryptographic failure
- */
- public static final String SECURITY_CRYPT_FAIL = "7.5";
-
- /**
- * Cryptographic algorithm not supported
- */
- public static final String SECURITY_CRYPT_ALGO = "7.6";
-
- /**
- * Message integrity failure
- */
- public static final String SECURITY_INTEGRITY = "7.7";
-
-
- // get methods
-
- public static String getStatus(int type, String detail) {
- return type + "." + detail;
- }
-
- public static String getStatus(int type, int subject, int detail) {
- return type + "." + subject + "." + detail;
- }
- }
-
private static final RFC822DateFormat rfc822DateFormat = new
RFC822DateFormat();
// Used to generate new mail names
@@ -466,12 +136,6 @@
if (getInitParameter("messageString") != null) {
messageString = getInitParameter("messageString");
}
-
- MailcapCommandMap mail_cap =
- (MailcapCommandMap) CommandMap.getDefaultCommandMap();
-
- mail_cap.addMailcap ("message/delivery-status;;
x-java-content-handler=com.sun.mail.handlers.message_rfc822");
- CommandMap.setDefaultCommandMap (mail_cap);
}
/**
@@ -547,7 +211,7 @@
// part 3: original mail (optional)
if (getAttachmentType() != NONE) {
- MimeBodyPart part3 = createAttachedOriginal(originalMail);
+ MimeBodyPart part3 =
createAttachedOriginal(originalMail,getAttachmentType());
multipart.addBodyPart(part3);
}
@@ -630,8 +294,6 @@
*/
protected MimeBodyPart createDSN(Mail originalMail) throws
MessagingException {
MimeBodyPart dsn = new MimeBodyPart();
- MimeMessage dsnMessage =
- new MimeMessage(Session.getDefaultInstance(System.getProperties(),
null));
StringWriter sout = new StringWriter();
PrintWriter out = new PrintWriter(sout, true);
String nameType = null;
@@ -737,14 +399,14 @@
}
- // setting content
- dsnMessage.setText(sout.toString());
- dsnMessage.saveChanges();
-
-
- //dsn.setContent(sout.toString(), "text/plain");
-
- dsn.setContent(dsnMessage, "message/delivery-status");
+ // Changed this from rfc822 handling to text/plain
+ // It should be handled correctly as delivery-status but it
+ // is better text/plain than rfc822 (rfc822 add message headers not
+ // allowed in the delivery-status.
+ // text/plain does not support rfc822 header encoding that we
+ // should support here.
+ dsn.setContent(sout.toString(), "text/plain");
+ dsn.setHeader("Content-Type","message/delivery-status");
dsn.setDescription("Delivery Status Notification");
dsn.setFileName("status.dat");
return dsn;
@@ -757,11 +419,18 @@
* @return MimeBodyPart
* @throws MessagingException
*/
- protected MimeBodyPart createAttachedOriginal(Mail originalMail)
+ protected MimeBodyPart createAttachedOriginal(Mail originalMail, int
attachmentType)
throws MessagingException {
MimeBodyPart part = new MimeBodyPart();
MimeMessage originalMessage = originalMail.getMessage();
- part.setContent(originalMessage, "message/rfc822");
+
+ if (attachmentType == HEADS) {
+ part.setContent(getMessageHeaders(originalMessage), "text/plain");
+ part.setHeader("Content-Type","text/rfc822-headers");
+ } else {
+ part.setContent(originalMessage, "message/rfc822");
+ }
+
if ((originalMessage.getSubject() != null) &&
(originalMessage.getSubject().trim().length() > 0)) {
part.setFileName(originalMessage.getSubject().trim());
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]