Skip to content

Package: DispositionNotification

DispositionNotification

nameinstructionbranchcomplexitylinemethod
DispositionNotification()
M: 9 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
DispositionNotification(InputStream)
M: 13 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
getNotifications()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
setNotifications(InternetHeaders)
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
static {...}
M: 11 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
toString()
M: 13 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
writeInternetHeaders(InternetHeaders, LineOutputStream)
M: 13 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
writeTo(OutputStream)
M: 21 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 7 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*
2: * Copyright (c) 1997, 2023 Oracle and/or its affiliates. All rights reserved.
3: *
4: * This program and the accompanying materials are made available under the
5: * terms of the Eclipse Public License v. 2.0, which is available at
6: * http://www.eclipse.org/legal/epl-2.0.
7: *
8: * This Source Code may also be made available under the following Secondary
9: * Licenses when the conditions for such availability set forth in the
10: * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
11: * version 2 with the GNU Classpath Exception, which is available at
12: * https://www.gnu.org/software/classpath/license.html.
13: *
14: * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15: */
16:
17: package org.eclipse.angus.mail.dsn;
18:
19: import java.io.IOException;
20: import java.io.InputStream;
21: import java.io.OutputStream;
22: import java.util.Enumeration;
23:
24: import org.eclipse.angus.mail.util.MailLogger;
25: import org.eclipse.angus.mail.util.PropUtil;
26:
27: import jakarta.mail.MessagingException;
28: import jakarta.mail.internet.InternetHeaders;
29: import jakarta.mail.util.LineOutputStream;
30: import jakarta.mail.util.StreamProvider;
31:
32: /**
33: * A message/disposition-notification message content, as defined in
34: * <A HREF="http://www.ietf.org/rfc/rfc3798.txt" TARGET="_top">RFC 3798</A>.
35: *
36: * @since        JavaMail 1.4.2
37: */
38: public class DispositionNotification extends Report {
39:
40: private static MailLogger logger = new MailLogger(
41:         DeliveryStatus.class,
42:         "DEBUG DSN",
43:         PropUtil.getBooleanSystemProperty("mail.dsn.debug", false),
44:         System.out);
45:
46: /**
47: * The disposition notification content fields.
48: */
49: protected InternetHeaders notifications;
50:
51: /**
52: * Construct a disposition notification with no content.
53: *
54: * @exception        MessagingException for failures
55: */
56: public DispositionNotification() throws MessagingException {
57:         super("disposition-notification");
58:         notifications = new InternetHeaders();
59: }
60:
61: /**
62: * Construct a disposition notification by parsing the
63: * supplied input stream.
64: *
65: * @param        is        the input stream
66: * @exception        IOException for I/O errors reading the stream
67: * @exception        MessagingException for other failures
68: */
69: public DispositionNotification(InputStream is)
70:                                 throws MessagingException, IOException {
71:         super("disposition-notification");
72:         notifications = new InternetHeaders(is);
73:         logger.fine("got MDN notification content");
74: }
75:
76: /**
77: * Return all the disposition notification fields in the
78: * disposition notification.
79: * The fields are defined as:
80: *
81: * <pre>
82: * disposition-notification-content =
83: *                [ reporting-ua-field CRLF ]
84: *                [ mdn-gateway-field CRLF ]
85: *                [ original-recipient-field CRLF ]
86: *                final-recipient-field CRLF
87: *                [ original-message-id-field CRLF ]
88: *                disposition-field CRLF
89: *                *( failure-field CRLF )
90: *                *( error-field CRLF )
91: *                *( warning-field CRLF )
92: *                *( extension-field CRLF )
93: * </pre>
94: *
95: * @return        the DSN fields
96: */
97: // XXX - could parse each of these fields
98: public InternetHeaders getNotifications() {
99:         return notifications;
100: }
101:
102: /**
103: * Set the disposition notification fields in the
104: * disposition notification.
105: *
106: * @param        notifications        the DSN fields
107: */
108: public void setNotifications(InternetHeaders notifications) {
109:         this.notifications = notifications;
110: }
111:
112: public void writeTo(OutputStream os) throws IOException {
113:         // see if we already have a LOS
114:         LineOutputStream los = null;
115:•        if (os instanceof LineOutputStream) {
116:          los = (LineOutputStream) os;
117:         } else {
118:          los = StreamProvider.provider().outputLineStream(os, false);
119:         }
120:
121:         writeInternetHeaders(notifications, los);
122:         los.writeln();
123: }
124:
125: private static void writeInternetHeaders(InternetHeaders h,
126:                                 LineOutputStream los) throws IOException {
127:         Enumeration<String> e = h.getAllHeaderLines();
128:•        while (e.hasMoreElements())
129:          los.writeln(e.nextElement());
130: }
131:
132: public String toString() {
133:         return "DispositionNotification: Reporting-UA=" +
134:          notifications.getHeader("Reporting-UA", null);
135: }
136: }