mirror of https://github.com/M66B/FairEmail.git
Decode double encoded addresses
This commit is contained in:
parent
7076fda7a1
commit
7b5b300e98
|
@ -468,51 +468,57 @@ public class MessageHelper {
|
||||||
if (address == null || address.length == 0)
|
if (address == null || address.length == 0)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
address[0].setPersonal(decodeMime(address[0].getPersonal()));
|
||||||
|
address[0].setAddress(decodeMime(address[0].getAddress()));
|
||||||
|
} catch (UnsupportedEncodingException ex) {
|
||||||
|
Log.w(ex);
|
||||||
|
}
|
||||||
|
|
||||||
return address[0];
|
return address[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
Address[] getFrom() throws MessagingException {
|
Address[] getFrom() throws MessagingException {
|
||||||
return imessage.getFrom();
|
return fix(imessage.getFrom());
|
||||||
}
|
}
|
||||||
|
|
||||||
Address[] getTo() throws MessagingException {
|
Address[] getTo() throws MessagingException {
|
||||||
return imessage.getRecipients(Message.RecipientType.TO);
|
return fix(imessage.getRecipients(Message.RecipientType.TO));
|
||||||
}
|
}
|
||||||
|
|
||||||
Address[] getCc() throws MessagingException {
|
Address[] getCc() throws MessagingException {
|
||||||
return imessage.getRecipients(Message.RecipientType.CC);
|
return fix(imessage.getRecipients(Message.RecipientType.CC));
|
||||||
}
|
}
|
||||||
|
|
||||||
Address[] getBcc() throws MessagingException {
|
Address[] getBcc() throws MessagingException {
|
||||||
return imessage.getRecipients(Message.RecipientType.BCC);
|
return fix(imessage.getRecipients(Message.RecipientType.BCC));
|
||||||
}
|
}
|
||||||
|
|
||||||
Address[] getReply() throws MessagingException {
|
Address[] getReply() throws MessagingException {
|
||||||
String[] headers = imessage.getHeader("Reply-To");
|
String[] headers = imessage.getHeader("Reply-To");
|
||||||
if (headers != null && headers.length > 0)
|
if (headers != null && headers.length > 0)
|
||||||
return imessage.getReplyTo();
|
return fix(imessage.getReplyTo());
|
||||||
else
|
else
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
String getSubject() throws MessagingException, UnsupportedEncodingException {
|
private static Address[] fix(Address[] addresses) {
|
||||||
|
if (addresses != null)
|
||||||
|
for (int i = 0; i < addresses.length; i++)
|
||||||
|
try {
|
||||||
|
((InternetAddress) addresses[i]).setPersonal(
|
||||||
|
decodeMime(((InternetAddress) addresses[i]).getPersonal()));
|
||||||
|
((InternetAddress) addresses[i]).setAddress(
|
||||||
|
decodeMime(((InternetAddress) addresses[i]).getAddress()));
|
||||||
|
} catch (UnsupportedEncodingException ex) {
|
||||||
|
Log.w(ex);
|
||||||
|
}
|
||||||
|
return addresses;
|
||||||
|
}
|
||||||
|
|
||||||
|
String getSubject() throws MessagingException {
|
||||||
String subject = imessage.getSubject();
|
String subject = imessage.getSubject();
|
||||||
if (subject == null)
|
return decodeMime(subject);
|
||||||
return subject;
|
|
||||||
|
|
||||||
int i = 0;
|
|
||||||
int s = subject.indexOf("=?", i);
|
|
||||||
int e = subject.indexOf("?=", i);
|
|
||||||
while (s >= 0 && e >= 0 && i < subject.length()) {
|
|
||||||
String decode = subject.substring(s, e + 2);
|
|
||||||
String decoded = MimeUtility.decodeText(decode);
|
|
||||||
subject = subject.substring(0, i) + decoded + subject.substring(e + 2);
|
|
||||||
i += decoded.length();
|
|
||||||
s = subject.indexOf("=?", i);
|
|
||||||
e = subject.indexOf("?=", i);
|
|
||||||
}
|
|
||||||
|
|
||||||
return subject;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Long getSize() throws MessagingException {
|
Long getSize() throws MessagingException {
|
||||||
|
@ -566,7 +572,7 @@ public class MessageHelper {
|
||||||
InternetAddress a = (InternetAddress) address;
|
InternetAddress a = (InternetAddress) address;
|
||||||
String personal = a.getPersonal();
|
String personal = a.getPersonal();
|
||||||
if (TextUtils.isEmpty(personal))
|
if (TextUtils.isEmpty(personal))
|
||||||
formatted.add(address.toString());
|
formatted.add(a.getAddress());
|
||||||
else {
|
else {
|
||||||
if (compose) {
|
if (compose) {
|
||||||
boolean quote = false;
|
boolean quote = false;
|
||||||
|
@ -589,6 +595,29 @@ public class MessageHelper {
|
||||||
return TextUtils.join(", ", formatted);
|
return TextUtils.join(", ", formatted);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static String decodeMime(String text) {
|
||||||
|
if (text == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
|
int s = text.indexOf("=?", i);
|
||||||
|
int e = text.indexOf("?=", i);
|
||||||
|
while (s >= 0 && e >= 0 && i < text.length()) {
|
||||||
|
String decode = text.substring(s, e + 2);
|
||||||
|
try {
|
||||||
|
String decoded = MimeUtility.decodeText(decode);
|
||||||
|
text = text.substring(0, i) + decoded + text.substring(e + 2);
|
||||||
|
i += decoded.length();
|
||||||
|
} catch (UnsupportedEncodingException ex) {
|
||||||
|
Log.w(ex);
|
||||||
|
i += decode.length();
|
||||||
|
}
|
||||||
|
s = text.indexOf("=?", i);
|
||||||
|
e = text.indexOf("?=", i);
|
||||||
|
}
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
|
||||||
static String getSortKey(Address[] addresses) {
|
static String getSortKey(Address[] addresses) {
|
||||||
if (addresses == null || addresses.length == 0)
|
if (addresses == null || addresses.length == 0)
|
||||||
return null;
|
return null;
|
||||||
|
|
Loading…
Reference in New Issue