KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > james > util > mail > mdn > MDNFactory


1 /***********************************************************************
2  * Copyright (c) 2003-2004 The Apache Software Foundation. *
3  * All rights reserved. *
4  * ------------------------------------------------------------------- *
5  * Licensed under the Apache License, Version 2.0 (the "License"); you *
6  * may not use this file except in compliance with the License. You *
7  * may obtain a copy of the License at: *
8  * *
9  * http://www.apache.org/licenses/LICENSE-2.0 *
10  * *
11  * Unless required by applicable law or agreed to in writing, software *
12  * distributed under the License is distributed on an "AS IS" BASIS, *
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or *
14  * implied. See the License for the specific language governing *
15  * permissions and limitations under the License. *
16  ***********************************************************************/

17 package org.apache.james.util.mail.mdn;
18
19 import javax.mail.MessagingException JavaDoc;
20 import javax.mail.internet.MimeBodyPart JavaDoc;
21
22 import org.apache.james.util.mail.MimeMultipartReport;
23
24 /**
25  * Class <code>MDNFactory</code> creates MimeMultipartReports containing
26  * Message Delivery Notifications as specified by RFC 2298.
27  */

28 public class MDNFactory
29 {
30
31     /**
32      * Default Constructor
33      */

34     private MDNFactory()
35     {
36         super();
37     }
38     
39     /**
40      * Answers a MimeMultipartReport containing a
41      * Message Delivery Notification as specified by RFC 2298.
42      *
43      * @param humanText
44      * @param reporting_UA_name
45      * @param reporting_UA_product
46      * @param original_recipient
47      * @param final_recipient
48      * @param original_message_id
49      * @param disposition
50      * @return MimeMultipartReport
51      * @throws MessagingException
52      */

53     static public MimeMultipartReport create(String JavaDoc humanText,
54             String JavaDoc reporting_UA_name,
55             String JavaDoc reporting_UA_product,
56             String JavaDoc original_recipient,
57             String JavaDoc final_recipient,
58             String JavaDoc original_message_id,
59             Disposition disposition) throws MessagingException JavaDoc
60     {
61         // Create the message parts. According to RFC 2298, there are two
62
// compulsory parts and one optional part...
63
MimeMultipartReport multiPart = new MimeMultipartReport();
64         multiPart.setReportType("disposition-notification");
65         
66         // Part 1: The 'human-readable' part
67
MimeBodyPart JavaDoc humanPart = new MimeBodyPart JavaDoc();
68         humanPart.setText(humanText);
69         multiPart.addBodyPart(humanPart);
70
71         // Part 2: MDN Report Part
72
// 1) reporting-ua-field
73
StringBuffer JavaDoc mdnReport = new StringBuffer JavaDoc(128);
74         mdnReport.append("Reporting-UA: ");
75         mdnReport.append((reporting_UA_name == null ? "" : reporting_UA_name));
76         mdnReport.append("; ");
77         mdnReport.append((reporting_UA_product == null ? "" : reporting_UA_product));
78         mdnReport.append("\r\n");
79         // 2) original-recipient-field
80
if (null != original_recipient)
81         {
82             mdnReport.append("Original-Recipient: ");
83             mdnReport.append("rfc822; ");
84             mdnReport.append(original_recipient);
85             mdnReport.append("\r\n");
86         }
87         // 3) final-recipient-field
88
mdnReport.append("Final-Recepient: ");
89         mdnReport.append("rfc822; ");
90         mdnReport.append((final_recipient == null ? "" : final_recipient));
91         mdnReport.append("\r\n");
92         // 4) original-message-id-field
93
mdnReport.append("Original-Message-ID: ");
94         mdnReport.append((original_message_id == null ? "" : original_message_id));
95         mdnReport.append("\r\n");
96         // 5) disposition-field
97
mdnReport.append(disposition.toString());
98         mdnReport.append("\r\n");
99         MimeBodyPart JavaDoc mdnPart = new MimeBodyPart JavaDoc();
100         mdnPart.setContent(mdnReport.toString(), "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 }
113
Popular Tags