Cannot resend to undisclosed-recipients

pull/194/merge
M66B 3 years ago
parent 7263a603f3
commit 668f7951ea

@ -3419,6 +3419,7 @@ The resend menu item will be shown grayed (dimmed) if the message headers are no
Remarks: Remarks:
* Messages to, CC or BCC *undisclosed-recipients:* cannot be resend
* The original subject is sent as-is, unless it is being changed * The original subject is sent as-is, unless it is being changed
* The original message text will be sent as-is, unless text is being entered * The original message text will be sent as-is, unless text is being entered
* The original attachments are sent as they are, unless attachments are being added or removed * The original attachments are sent as they are, unless attachments are being added or removed

@ -238,6 +238,7 @@ import javax.mail.MessageRemovedException;
import javax.mail.MessagingException; import javax.mail.MessagingException;
import javax.mail.Part; import javax.mail.Part;
import javax.mail.Session; import javax.mail.Session;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress; import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage; import javax.mail.internet.MimeMessage;
@ -2790,6 +2791,15 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
} }
} }
boolean canResend = true;
for (Address r : recipients) {
String email = ((InternetAddress) r).getAddress();
if ("undisclosed-recipients:".equals(email)) {
canResend = false;
break;
}
}
PopupMenuLifecycle popupMenu = new PopupMenuLifecycle(context, getViewLifecycleOwner(), anchor); PopupMenuLifecycle popupMenu = new PopupMenuLifecycle(context, getViewLifecycleOwner(), anchor);
popupMenu.inflate(R.menu.popup_reply); popupMenu.inflate(R.menu.popup_reply);
popupMenu.getMenu().findItem(R.id.menu_reply_to_all).setVisible(recipients.length > 0); popupMenu.getMenu().findItem(R.id.menu_reply_to_all).setVisible(recipients.length > 0);
@ -2799,6 +2809,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
popupMenu.getMenu().findItem(R.id.menu_reply_hard_bounce).setEnabled(canBounce); popupMenu.getMenu().findItem(R.id.menu_reply_hard_bounce).setEnabled(canBounce);
popupMenu.getMenu().findItem(R.id.menu_new_message).setVisible(to != null && to.length > 0); popupMenu.getMenu().findItem(R.id.menu_new_message).setVisible(to != null && to.length > 0);
popupMenu.getMenu().findItem(R.id.menu_resend).setVisible(experiments); popupMenu.getMenu().findItem(R.id.menu_resend).setVisible(experiments);
popupMenu.getMenu().findItem(R.id.menu_resend).setEnabled(canResend);
popupMenu.getMenu().findItem(R.id.menu_reply_answer).setVisible(answers != 0 || !ActivityBilling.isPro(context)); popupMenu.getMenu().findItem(R.id.menu_reply_answer).setVisible(answers != 0 || !ActivityBilling.isPro(context));
popupMenu.getMenu().findItem(R.id.menu_reply_to_sender).setEnabled(message.content); popupMenu.getMenu().findItem(R.id.menu_reply_to_sender).setEnabled(message.content);

@ -318,46 +318,49 @@ public class MessageHelper {
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(); try {
String value = header.getValue(); String name = header.getName();
if (name == null || TextUtils.isEmpty(value)) String value = header.getValue();
continue; if (name == null || TextUtils.isEmpty(value))
continue;
switch (name.toLowerCase(Locale.ROOT)) { switch (name.toLowerCase(Locale.ROOT)) {
case "date": case "date":
imessage.setHeader("Date", value); imessage.setHeader("Date", value);
break; break;
case "from": case "from":
imessage.setFrom(value); imessage.setFrom(value);
break; break;
case "to": case "to":
imessage.setRecipients(Message.RecipientType.TO, InternetAddress.parse(value)); imessage.setRecipients(Message.RecipientType.TO, InternetAddress.parse(value));
break; break;
case "cc": case "cc":
imessage.setRecipients(Message.RecipientType.CC, InternetAddress.parse(value)); imessage.setRecipients(Message.RecipientType.CC, InternetAddress.parse(value));
break; break;
case "bcc": case "bcc":
imessage.setRecipients(Message.RecipientType.BCC, InternetAddress.parse(value)); imessage.setRecipients(Message.RecipientType.BCC, InternetAddress.parse(value));
break; break;
case "reply-to": case "reply-to":
imessage.setReplyTo(InternetAddress.parse(value)); imessage.setReplyTo(InternetAddress.parse(value));
break; break;
case "message-id": case "message-id":
if (send) { if (send) {
imessage.setHeader("Resent-Message-ID", message.msgid); imessage.setHeader("Resent-Message-ID", message.msgid);
imessage.updateMessageID(value); imessage.updateMessageID(value);
} }
break; break;
case "references": case "references":
imessage.setHeader("References", value); imessage.setHeader("References", value);
break; break;
case "in-reply-to": case "in-reply-to":
imessage.setHeader("In-Reply-To", value); imessage.setHeader("In-Reply-To", value);
break; break;
// Resent-Sender (=on behalf of) // Resent-Sender (=on behalf of)
}
} catch (Throwable ex) {
Log.e(ex);
} }
}
// The "Resent-Date:" indicates the date and time at which the resent // The "Resent-Date:" indicates the date and time at which the resent
// message is dispatched by the resender of the message. // message is dispatched by the resender of the message.

Loading…
Cancel
Save