001: /****************************************************************
002: * Licensed to the Apache Software Foundation (ASF) under one *
003: * or more contributor license agreements. See the NOTICE file *
004: * distributed with this work for additional information *
005: * regarding copyright ownership. The ASF licenses this file *
006: * to you under the Apache License, Version 2.0 (the *
007: * "License"); you may not use this file except in compliance *
008: * with the License. You may obtain a copy of the License at *
009: * *
010: * http://www.apache.org/licenses/LICENSE-2.0 *
011: * *
012: * Unless required by applicable law or agreed to in writing, *
013: * software distributed under the License is distributed on an *
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
015: * KIND, either express or implied. See the License for the *
016: * specific language governing permissions and limitations *
017: * under the License. *
018: ****************************************************************/package org.apache.james.util.mail.mdn;
019:
020: import javax.mail.MessagingException;
021: import javax.mail.internet.MimeBodyPart;
022:
023: import org.apache.james.util.mail.MimeMultipartReport;
024:
025: /**
026: * Class <code>MDNFactory</code> creates MimeMultipartReports containing
027: * Message Delivery Notifications as specified by RFC 2298.
028: */
029: public class MDNFactory {
030:
031: /**
032: * Default Constructor
033: */
034: private MDNFactory() {
035: super ();
036: }
037:
038: /**
039: * Answers a MimeMultipartReport containing a
040: * Message Delivery Notification as specified by RFC 2298.
041: *
042: * @param humanText
043: * @param reporting_UA_name
044: * @param reporting_UA_product
045: * @param original_recipient
046: * @param final_recipient
047: * @param original_message_id
048: * @param disposition
049: * @return MimeMultipartReport
050: * @throws MessagingException
051: */
052: static public MimeMultipartReport create(String humanText,
053: String reporting_UA_name, String reporting_UA_product,
054: String original_recipient, String final_recipient,
055: String original_message_id, Disposition disposition)
056: throws MessagingException {
057: // Create the message parts. According to RFC 2298, there are two
058: // compulsory parts and one optional part...
059: MimeMultipartReport multiPart = new MimeMultipartReport();
060: multiPart.setReportType("disposition-notification");
061:
062: // Part 1: The 'human-readable' part
063: MimeBodyPart humanPart = new MimeBodyPart();
064: humanPart.setText(humanText);
065: multiPart.addBodyPart(humanPart);
066:
067: // Part 2: MDN Report Part
068: // 1) reporting-ua-field
069: StringBuffer mdnReport = new StringBuffer(128);
070: mdnReport.append("Reporting-UA: ");
071: mdnReport.append((reporting_UA_name == null ? ""
072: : reporting_UA_name));
073: mdnReport.append("; ");
074: mdnReport.append((reporting_UA_product == null ? ""
075: : reporting_UA_product));
076: mdnReport.append("\r\n");
077: // 2) original-recipient-field
078: if (null != original_recipient) {
079: mdnReport.append("Original-Recipient: ");
080: mdnReport.append("rfc822; ");
081: mdnReport.append(original_recipient);
082: mdnReport.append("\r\n");
083: }
084: // 3) final-recipient-field
085: mdnReport.append("Final-Recepient: ");
086: mdnReport.append("rfc822; ");
087: mdnReport.append((final_recipient == null ? ""
088: : final_recipient));
089: mdnReport.append("\r\n");
090: // 4) original-message-id-field
091: mdnReport.append("Original-Message-ID: ");
092: mdnReport.append((original_message_id == null ? ""
093: : original_message_id));
094: mdnReport.append("\r\n");
095: // 5) disposition-field
096: mdnReport.append(disposition.toString());
097: mdnReport.append("\r\n");
098: MimeBodyPart mdnPart = new MimeBodyPart();
099: mdnPart.setContent(mdnReport.toString(),
100: "message/disposition-notification");
101: multiPart.addBodyPart(mdnPart);
102:
103: // Part 3: The optional third part, the original message is omitted.
104: // We don't want to propogate over-sized, virus infected or
105: // other undesirable mail!
106: // There is the option of adding a Text/RFC822-Headers part, which
107: // includes only the RFC 822 headers of the failed message. This is
108: // described in RFC 1892. It would be a useful addition!
109: return multiPart;
110: }
111:
112: }
|