|
|
@ -281,75 +281,96 @@ public class MessageHelper {
|
|
|
|
|
|
|
|
|
|
|
|
MailDateFormat mdf = new MailDateFormat();
|
|
|
|
MailDateFormat mdf = new MailDateFormat();
|
|
|
|
mdf.setTimeZone(hide_timezone ? TimeZone.getTimeZone("UTC") : TimeZone.getDefault());
|
|
|
|
mdf.setTimeZone(hide_timezone ? TimeZone.getTimeZone("UTC") : TimeZone.getDefault());
|
|
|
|
String date = mdf.format(new Date(message.sent == null ? message.received : message.sent));
|
|
|
|
String ourDate = mdf.format(new Date(message.sent == null ? message.received : message.sent));
|
|
|
|
imessage.setHeader("Date", date);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Address us = null;
|
|
|
|
Address ourFrom = null;
|
|
|
|
if (message.from != null && message.from.length > 0) {
|
|
|
|
if (message.from != null && message.from.length > 0)
|
|
|
|
us = getFrom(message, identity);
|
|
|
|
ourFrom = getFrom(message, identity);
|
|
|
|
imessage.setFrom(us);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Resend
|
|
|
|
if (message.headers == null) {
|
|
|
|
if (message.headers != null) {
|
|
|
|
imessage.setHeader("Date", ourDate);
|
|
|
|
// https://datatracker.ietf.org/doc/html/rfc2822#section-3.6.6
|
|
|
|
|
|
|
|
if (us != null)
|
|
|
|
|
|
|
|
imessage.addHeader("Resent-From", us.toString());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
imessage.addHeader("Resent-Date", date);
|
|
|
|
// Addresses
|
|
|
|
|
|
|
|
if (ourFrom != null)
|
|
|
|
|
|
|
|
imessage.setFrom(ourFrom);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (message.to != null && message.to.length > 0)
|
|
|
|
|
|
|
|
imessage.setRecipients(Message.RecipientType.TO, convertAddress(message.to, identity));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (message.cc != null && message.cc.length > 0)
|
|
|
|
|
|
|
|
imessage.setRecipients(Message.RecipientType.CC, convertAddress(message.cc, identity));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (message.bcc != null && message.bcc.length > 0)
|
|
|
|
|
|
|
|
imessage.setRecipients(Message.RecipientType.BCC, convertAddress(message.bcc, identity));
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// https://datatracker.ietf.org/doc/html/rfc2822#section-3.6.6
|
|
|
|
ByteArrayInputStream bis = new ByteArrayInputStream(message.headers.getBytes());
|
|
|
|
ByteArrayInputStream bis = new ByteArrayInputStream(message.headers.getBytes());
|
|
|
|
List<Header> headers = Collections.list(new InternetHeaders(bis).getAllHeaders());
|
|
|
|
List<Header> headers = Collections.list(new InternetHeaders(bis).getAllHeaders());
|
|
|
|
|
|
|
|
|
|
|
|
for (Header header : headers) {
|
|
|
|
for (Header header : headers) {
|
|
|
|
String name = header.getName();
|
|
|
|
String name = header.getName();
|
|
|
|
String value = header.getValue();
|
|
|
|
String value = header.getValue();
|
|
|
|
if (name == null || value == null)
|
|
|
|
if (name == null || TextUtils.isEmpty(value))
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
|
|
switch (name.toLowerCase(Locale.ROOT)) {
|
|
|
|
switch (name.toLowerCase(Locale.ROOT)) {
|
|
|
|
case "from":
|
|
|
|
|
|
|
|
// Override default header
|
|
|
|
|
|
|
|
imessage.setFrom(value);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "date":
|
|
|
|
case "date":
|
|
|
|
// Override default header
|
|
|
|
|
|
|
|
imessage.setHeader("Date", value);
|
|
|
|
imessage.setHeader("Date", value);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "from":
|
|
|
|
|
|
|
|
imessage.setFrom(value);
|
|
|
|
|
|
|
|
break;
|
|
|
|
case "to":
|
|
|
|
case "to":
|
|
|
|
imessage.addHeader("Resent-To", value);
|
|
|
|
imessage.setRecipients(Message.RecipientType.TO, InternetAddress.parse(value));
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case "cc":
|
|
|
|
case "cc":
|
|
|
|
imessage.addHeader("Resent-Cc", value);
|
|
|
|
imessage.setRecipients(Message.RecipientType.CC, InternetAddress.parse(value));
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case "bcc":
|
|
|
|
case "bcc":
|
|
|
|
imessage.addHeader("Resent-Bcc", value);
|
|
|
|
imessage.setRecipients(Message.RecipientType.BCC, InternetAddress.parse(value));
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "reply-to":
|
|
|
|
|
|
|
|
imessage.setReplyTo(InternetAddress.parse(value));
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
// Resent-Sender
|
|
|
|
// Resent-Sender
|
|
|
|
// Resent-Message-ID
|
|
|
|
// Resent-Message-ID
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// The "Resent-Date:" indicates the date and time at which the resent
|
|
|
|
|
|
|
|
// message is dispatched by the resender of the message.
|
|
|
|
|
|
|
|
imessage.addHeader("Resent-Date", ourDate);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// a simple "Resent-From:" form which
|
|
|
|
|
|
|
|
// contains the mailbox of the individual doing the resending
|
|
|
|
|
|
|
|
if (ourFrom != null)
|
|
|
|
|
|
|
|
imessage.addHeader("Resent-From", ourFrom.toString());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// The "Resent-To:", "Resent-Cc:", and "Resent-Bcc:" fields function
|
|
|
|
|
|
|
|
// identically to the "To:", "Cc:", and "Bcc:" fields respectively,
|
|
|
|
|
|
|
|
// except that they indicate the recipients of the resent message, not
|
|
|
|
|
|
|
|
// the recipients of the original message.
|
|
|
|
|
|
|
|
if (message.to != null && message.to.length > 0)
|
|
|
|
|
|
|
|
imessage.addHeader("Resent-To", InternetAddress.toString(message.to));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (message.cc != null && message.cc.length > 0)
|
|
|
|
|
|
|
|
imessage.addHeader("Resent-Cc", InternetAddress.toString(message.cc));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (message.bcc != null && message.bcc.length > 0)
|
|
|
|
|
|
|
|
imessage.addHeader("Resent-Bcc", InternetAddress.toString(message.bcc));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Each new set of resent fields is prepended to the message;
|
|
|
|
|
|
|
|
// that is, the most recent set of resent fields appear earlier in the message.
|
|
|
|
for (Header header : headers) {
|
|
|
|
for (Header header : headers) {
|
|
|
|
String name = header.getName();
|
|
|
|
String name = header.getName();
|
|
|
|
String value = header.getValue();
|
|
|
|
String value = header.getValue();
|
|
|
|
if (name == null || value == null)
|
|
|
|
if (name == null || TextUtils.isEmpty(value))
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
if (name.toLowerCase(Locale.ROOT).startsWith("resent-"))
|
|
|
|
if (name.toLowerCase(Locale.ROOT).startsWith("resent-"))
|
|
|
|
imessage.addHeader(name, value);
|
|
|
|
imessage.addHeader(name, value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Addresses
|
|
|
|
|
|
|
|
if (message.to != null && message.to.length > 0)
|
|
|
|
|
|
|
|
imessage.setRecipients(Message.RecipientType.TO, convertAddress(message.to, identity));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (message.cc != null && message.cc.length > 0)
|
|
|
|
|
|
|
|
imessage.setRecipients(Message.RecipientType.CC, convertAddress(message.cc, identity));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (message.bcc != null && message.bcc.length > 0)
|
|
|
|
|
|
|
|
imessage.setRecipients(Message.RecipientType.BCC, convertAddress(message.bcc, identity));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (message.subject != null) {
|
|
|
|
if (message.subject != null) {
|
|
|
|
int maxlen = MAX_HEADER_LENGTH - "Subject: ".length();
|
|
|
|
int maxlen = MAX_HEADER_LENGTH - "Subject: ".length();
|
|
|
|
if (message.subject.length() > maxlen)
|
|
|
|
if (message.subject.length() > maxlen)
|
|
|
@ -359,17 +380,19 @@ public class MessageHelper {
|
|
|
|
|
|
|
|
|
|
|
|
// Send message
|
|
|
|
// Send message
|
|
|
|
if (identity != null) {
|
|
|
|
if (identity != null) {
|
|
|
|
// Add reply to
|
|
|
|
if (message.headers == null) {
|
|
|
|
if (message.headers == null && identity.replyto != null)
|
|
|
|
// Add reply to
|
|
|
|
imessage.setReplyTo(convertAddress(InternetAddress.parse(identity.replyto), identity));
|
|
|
|
if (identity.replyto != null)
|
|
|
|
|
|
|
|
imessage.setReplyTo(convertAddress(InternetAddress.parse(identity.replyto), identity));
|
|
|
|
// Add extra cc
|
|
|
|
|
|
|
|
if (identity.cc != null)
|
|
|
|
// Add extra cc
|
|
|
|
addAddress(identity.cc, Message.RecipientType.CC, imessage, identity);
|
|
|
|
if (identity.cc != null)
|
|
|
|
|
|
|
|
addAddress(identity.cc, Message.RecipientType.CC, imessage, identity);
|
|
|
|
// Add extra bcc
|
|
|
|
|
|
|
|
if (identity.bcc != null)
|
|
|
|
// Add extra bcc
|
|
|
|
addAddress(identity.bcc, Message.RecipientType.BCC, imessage, identity);
|
|
|
|
if (identity.bcc != null)
|
|
|
|
|
|
|
|
addAddress(identity.bcc, Message.RecipientType.BCC, imessage, identity);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Delivery/read request
|
|
|
|
// Delivery/read request
|
|
|
|
if (message.receipt_request != null && message.receipt_request) {
|
|
|
|
if (message.receipt_request != null && message.receipt_request) {
|
|
|
|