Skip to content

Package: DeliveryStatus

DeliveryStatus

nameinstructionbranchcomplexitylinemethod
DeliveryStatus()
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%
DeliveryStatus(InputStream)
M: 63 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 17 C: 0
0%
M: 1 C: 0
0%
addRecipientDSN(InternetHeaders)
M: 29 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%
getMessageDSN()
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%
getRecipientDSN(int)
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getRecipientDSNCount()
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
setMessageDSN(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: 19 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: 38 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 10 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.EOFException;
20: import java.io.IOException;
21: import java.io.InputStream;
22: import java.io.OutputStream;
23: import java.util.Enumeration;
24: import java.util.Vector;
25: import java.util.logging.Level;
26:
27: import org.eclipse.angus.mail.util.MailLogger;
28: import org.eclipse.angus.mail.util.PropUtil;
29:
30: import jakarta.mail.MessagingException;
31: import jakarta.mail.internet.InternetHeaders;
32: import jakarta.mail.util.LineOutputStream;
33: import jakarta.mail.util.StreamProvider;
34:
35: /**
36: * A message/delivery-status message content, as defined in
37: * <A HREF="http://www.ietf.org/rfc/rfc3464.txt" TARGET="_top">RFC 3464</A>.
38: *
39: * @since        JavaMail 1.4
40: */
41: public class DeliveryStatus extends Report {
42:
43: private static MailLogger logger = new MailLogger(
44:         DeliveryStatus.class,
45:         "DEBUG DSN",
46:         PropUtil.getBooleanSystemProperty("mail.dsn.debug", false),
47:         System.out);
48:
49: /**
50: * The DSN fields for the message.
51: */
52: protected InternetHeaders messageDSN;
53:
54: /**
55: * The DSN fields for each recipient.
56: */
57: protected InternetHeaders[] recipientDSN;
58:
59: /**
60: * Construct a delivery status notification with no content.
61: *
62: * @exception        MessagingException for failures
63: */
64: public DeliveryStatus() throws MessagingException {
65:         super("delivery-status");
66:         messageDSN = new InternetHeaders();
67:         recipientDSN = new InternetHeaders[0];
68: }
69:
70: /**
71: * Construct a delivery status notification by parsing the
72: * supplied input stream.
73: *
74: * @param        is        the input stream
75: * @exception        IOException for I/O errors reading the stream
76: * @exception        MessagingException for other failures
77: */
78: public DeliveryStatus(InputStream is)
79:                                 throws MessagingException, IOException {
80:         super("delivery-status");
81:         messageDSN = new InternetHeaders(is);
82:         logger.fine("got messageDSN");
83:         Vector<InternetHeaders> v = new Vector<>();
84:         try {
85:•         while (is.available() > 0) {
86:                 InternetHeaders h = new InternetHeaders(is);
87:                 logger.fine("got recipientDSN");
88:                 v.addElement(h);
89:          }
90:         } catch (EOFException ex) {
91:          logger.log(Level.FINE, "got EOFException", ex);
92:         }
93:•        if (logger.isLoggable(Level.FINE))
94:          logger.fine("recipientDSN size " + v.size());
95:         recipientDSN = new InternetHeaders[v.size()];
96:         v.copyInto(recipientDSN);
97: }
98:
99: /**
100: * Return all the per-message fields in the delivery status notification.
101: * The fields are defined as:
102: *
103: * <pre>
104: * per-message-fields =
105: * [ original-envelope-id-field CRLF ]
106: * reporting-mta-field CRLF
107: * [ dsn-gateway-field CRLF ]
108: * [ received-from-mta-field CRLF ]
109: * [ arrival-date-field CRLF ]
110: * *( extension-field CRLF )
111: * </pre>
112: *
113: * @return        the per-message DSN fields
114: */
115: // XXX - could parse each of these fields
116: public InternetHeaders getMessageDSN() {
117:         return messageDSN;
118: }
119:
120: /**
121: * Set the per-message fields in the delivery status notification.
122: *
123: * @param        messageDSN        the per-message DSN fields
124: */
125: public void setMessageDSN(InternetHeaders messageDSN) {
126:         this.messageDSN = messageDSN;
127: }
128:
129: /**
130: * Return the number of recipients for which we have
131: * per-recipient delivery status notification information.
132: *
133: * @return        the number of recipients
134: */
135: public int getRecipientDSNCount() {
136:         return recipientDSN.length;
137: }
138:
139: /**
140: * Return the delivery status notification information for
141: * the specified recipient.
142: *
143: * @param        n        the recipient number
144: * @return        the DSN fields for the recipient
145: */
146: public InternetHeaders getRecipientDSN(int n) {
147:         return recipientDSN[n];
148: }
149:
150: /**
151: * Add deliver status notification information for another
152: * recipient.
153: *
154: * @param        h        the DSN fields for the recipient
155: */
156: public void addRecipientDSN(InternetHeaders h) {
157:         InternetHeaders[] rh = new InternetHeaders[recipientDSN.length + 1];
158:         System.arraycopy(recipientDSN, 0, rh, 0, recipientDSN.length);
159:         recipientDSN = rh;
160:         recipientDSN[recipientDSN.length - 1] = h;
161: }
162:
163: public void writeTo(OutputStream os) throws IOException {
164:         // see if we already have a LOS
165:         LineOutputStream los = null;
166:•        if (os instanceof LineOutputStream) {
167:          los = (LineOutputStream) os;
168:         } else {
169:          los = StreamProvider.provider().outputLineStream(os, false);
170:         }
171:
172:         writeInternetHeaders(messageDSN, los);
173:         los.writeln();
174:•        for (int i = 0; i < recipientDSN.length; i++) {
175:          writeInternetHeaders(recipientDSN[i], los);
176:          los.writeln();
177:         }
178: }
179:
180: private static void writeInternetHeaders(InternetHeaders h,
181:                                 LineOutputStream los) throws IOException {
182:         Enumeration<String> e = h.getAllHeaderLines();
183:•        while (e.hasMoreElements())
184:          los.writeln(e.nextElement());
185: }
186:
187: @Override
188: public String toString() {
189:         return "DeliveryStatus: Reporting-MTA=" +
190:          messageDSN.getHeader("Reporting-MTA", null) + ", #Recipients=" +
191:          recipientDSN.length;
192: }
193: }