1
0
Fork 0
mirror of https://github.com/M66B/FairEmail.git synced 2024-12-26 09:47:13 +00:00

Use correct resent headers

This commit is contained in:
M66B 2021-12-12 10:12:45 +01:00
parent 33859b0be8
commit 682a7ffca1
2 changed files with 63 additions and 73 deletions

View file

@ -4597,7 +4597,9 @@ public class FragmentCompose extends FragmentBase {
ref.language, ref.language,
alt_fwd ? R.string.title_subject_forward_alt : R.string.title_subject_forward, alt_fwd ? R.string.title_subject_forward_alt : R.string.title_subject_forward,
subject); subject);
} else if ("resend".equals(action) || "editasnew".equals(action)) { } else if ("resend".equals(action)) {
data.draft.subject = ref.subject;
} else if ("editasnew".equals(action)) {
if (ref.from != null && ref.from.length == 1) { if (ref.from != null && ref.from.length == 1) {
String from = ((InternetAddress) ref.from[0]).getAddress(); String from = ((InternetAddress) ref.from[0]).getAddress();
for (EntityIdentity identity : data.identities) for (EntityIdentity identity : data.identities)
@ -4606,11 +4608,13 @@ public class FragmentCompose extends FragmentBase {
break; break;
} }
} }
data.draft.to = ref.to; data.draft.to = ref.to;
data.draft.cc = ref.cc; data.draft.cc = ref.cc;
data.draft.bcc = ref.bcc; data.draft.bcc = ref.bcc;
data.draft.subject = ref.subject; data.draft.subject = ref.subject;
if (ref.content && "editasnew".equals(action))
if (ref.content)
document = JsoupEx.parse(ref.getFile(context)); document = JsoupEx.parse(ref.getFile(context));
} else if ("list".equals(action)) { } else if ("list".equals(action)) {
data.draft.subject = ref.subject; data.draft.subject = ref.subject;

View file

@ -278,95 +278,77 @@ public class MessageHelper {
imessage.addHeader("In-Reply-To", message.inreplyto); imessage.addHeader("In-Reply-To", message.inreplyto);
imessage.addHeader(HEADER_CORRELATION_ID, message.msgid); imessage.addHeader(HEADER_CORRELATION_ID, message.msgid);
// Addresses MailDateFormat mdf = new MailDateFormat();
if (message.headers == null) { mdf.setTimeZone(hide_timezone ? TimeZone.getTimeZone("UTC") : TimeZone.getDefault());
if (message.from != null && message.from.length > 0) String date = mdf.format(new Date(message.sent == null ? message.received : message.sent));
imessage.setFrom(getFrom(message, identity)); imessage.setHeader("Date", date);
if (message.to != null && message.to.length > 0) Address us = null;
imessage.setRecipients(Message.RecipientType.TO, convertAddress(message.to, identity)); if (message.from != null && message.from.length > 0) {
us = getFrom(message, identity);
imessage.setFrom(us);
}
if (message.cc != null && message.cc.length > 0) // Resend
imessage.setRecipients(Message.RecipientType.CC, convertAddress(message.cc, identity)); if (message.headers != null) {
if (message.bcc != null && message.bcc.length > 0)
imessage.setRecipients(Message.RecipientType.BCC, convertAddress(message.bcc, identity));
if (identity != null && identity.replyto != null)
imessage.setReplyTo(convertAddress(InternetAddress.parse(identity.replyto), identity));
MailDateFormat mdf = new MailDateFormat();
mdf.setTimeZone(hide_timezone ? TimeZone.getTimeZone("UTC") : TimeZone.getDefault());
if (message.sent != null)
imessage.setHeader("Date", mdf.format(new Date(message.sent)));
else
imessage.setHeader("Date", mdf.format(new Date(message.received)));
} else {
// https://datatracker.ietf.org/doc/html/rfc2822#section-3.6.6 // 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);
ByteArrayInputStream bis = new ByteArrayInputStream(message.headers.getBytes()); ByteArrayInputStream bis = new ByteArrayInputStream(message.headers.getBytes());
Enumeration<Header> headers = new InternetHeaders(bis).getAllHeaders(); List<Header> headers = Collections.list(new InternetHeaders(bis).getAllHeaders());
while (headers.hasMoreElements()) { for (Header header : headers) {
Header header = headers.nextElement();
String name = header.getName(); String name = header.getName();
String value = header.getValue(); String value = header.getValue();
if (name == null || value == null) if (name == null || value == null)
continue; continue;
switch (name) { switch (name.toLowerCase(Locale.ROOT)) {
case "From": case "from":
// Override default header
imessage.setFrom(value); imessage.setFrom(value);
break; break;
case "To": case "date":
imessage.setRecipients(Message.RecipientType.TO, value); // Override default header
break;
case "Cc":
imessage.setRecipients(Message.RecipientType.CC, value);
break;
case "Bcc":
imessage.setRecipients(Message.RecipientType.BCC, value);
break;
case "Reply-To":
imessage.setReplyTo(InternetAddress.parse(value));
break;
case "Date":
imessage.setHeader("Date", value); imessage.setHeader("Date", value);
break; break;
default:
if (name.startsWith("Resent-")) case "to":
imessage.addHeader(name, value); imessage.addHeader("Resent-To", value);
break;
case "cc":
imessage.addHeader("Resent-Cc", value);
break;
case "bcc":
imessage.addHeader("Resent-Bcc", value);
break;
// Resent-Sender
// Resent-Message-ID
} }
} }
if (message.from != null && message.from.length > 0) for (Header header : headers) {
imessage.addHeader("Resent-From", getFrom(message, identity).toString()); String name = header.getName();
String value = header.getValue();
if (message.to != null && message.to.length > 0) if (name == null || value == null)
for (Address a : convertAddress(message.to, identity)) continue;
imessage.addHeader("Resent-To", a.toString()); if (name.toLowerCase(Locale.ROOT).startsWith("resent-"))
imessage.addHeader(name, value);
if (message.cc != null && message.cc.length > 0) }
for (Address a : convertAddress(message.cc, identity))
imessage.addHeader("Resent-Cc", a.toString());
if (message.bcc != null && message.bcc.length > 0)
for (Address a : convertAddress(message.bcc, identity))
imessage.addHeader("Resent-Bcc", a.toString());
if (identity != null && identity.replyto != null)
for (Address a : convertAddress(InternetAddress.parse(identity.replyto), identity))
imessage.addHeader("Resent-Reply-To", a.toString());
MailDateFormat mdf = new MailDateFormat();
mdf.setTimeZone(hide_timezone ? TimeZone.getTimeZone("UTC") : TimeZone.getDefault());
if (message.sent != null)
imessage.addHeader("Resent-Date", mdf.format(new Date(message.sent)));
else
imessage.addHeader("Resent-Date", mdf.format(new Date(message.received)));
// Resent-Sender
// Resent-Message-ID
} }
// 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)
@ -376,6 +358,10 @@ public class MessageHelper {
// Send message // Send message
if (identity != null) { if (identity != null) {
// Add reply to
if (message.headers == null && identity.replyto != null)
imessage.setReplyTo(convertAddress(InternetAddress.parse(identity.replyto), identity));
// Add extra cc // Add extra cc
if (identity.cc != null) if (identity.cc != null)
addAddress(identity.cc, Message.RecipientType.CC, imessage, identity); addAddress(identity.cc, Message.RecipientType.CC, imessage, identity);