mirror of
https://github.com/moparisthebest/k-9
synced 2025-01-13 06:38:05 -05:00
Fixed issue with encoding of email addresses in the header with non ascii characters. The way were doing it was only compatible with certain email clients (Thunderbird) but not with K-9 itself
This commit is contained in:
parent
736d330e38
commit
a4965f042c
@ -17,6 +17,7 @@ import com.android.email.Utility;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
import org.apache.james.mime4j.codec.EncoderUtil;
|
||||
|
||||
public class Address {
|
||||
String mAddress;
|
||||
@ -120,6 +121,7 @@ public class Address {
|
||||
return super.equals(o);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
if (mPersonal != null) {
|
||||
// if (mPersonal.matches(".*[\\(\\)<>@,;:\\\\\".\\[\\]].*")) {
|
||||
@ -145,6 +147,30 @@ public class Address {
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public String toEncodedString() {
|
||||
if (mPersonal != null) {
|
||||
String s = EncoderUtil.encodeAddressDisplayName(mPersonal) + " <" + mAddress + ">";
|
||||
Log.v(Email.LOG_TAG, s);
|
||||
return s;
|
||||
} else {
|
||||
return mAddress;
|
||||
}
|
||||
}
|
||||
|
||||
public static String toEncodedString(Address[] addresses) {
|
||||
if (addresses == null) {
|
||||
return null;
|
||||
}
|
||||
StringBuffer sb = new StringBuffer();
|
||||
for (int i = 0; i < addresses.length; i++) {
|
||||
sb.append(addresses[i].toEncodedString());
|
||||
if (i < addresses.length - 1) {
|
||||
sb.append(',');
|
||||
}
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns either the personal portion of the Address or the address portion if the personal
|
||||
|
@ -175,7 +175,7 @@ public class MimeMessage extends Message {
|
||||
removeHeader("To");
|
||||
this.mTo = null;
|
||||
} else {
|
||||
setHeader("To", Address.toString(addresses));
|
||||
setHeader("To", Address.toEncodedString(addresses));
|
||||
this.mTo = addresses;
|
||||
}
|
||||
} else if (type == RecipientType.CC) {
|
||||
@ -183,7 +183,7 @@ public class MimeMessage extends Message {
|
||||
removeHeader("CC");
|
||||
this.mCc = null;
|
||||
} else {
|
||||
setHeader("CC", Address.toString(addresses));
|
||||
setHeader("CC", Address.toEncodedString(addresses));
|
||||
this.mCc = addresses;
|
||||
}
|
||||
} else if (type == RecipientType.BCC) {
|
||||
@ -191,7 +191,7 @@ public class MimeMessage extends Message {
|
||||
removeHeader("BCC");
|
||||
this.mBcc = null;
|
||||
} else {
|
||||
setHeader("BCC", Address.toString(addresses));
|
||||
setHeader("BCC", Address.toEncodedString(addresses));
|
||||
this.mBcc = addresses;
|
||||
}
|
||||
} else {
|
||||
@ -223,7 +223,7 @@ public class MimeMessage extends Message {
|
||||
|
||||
public void setFrom(Address from) throws MessagingException {
|
||||
if (from != null) {
|
||||
setHeader("From", from.toString());
|
||||
setHeader("From", from.toEncodedString());
|
||||
this.mFrom = new Address[] {
|
||||
from
|
||||
};
|
||||
@ -244,7 +244,7 @@ public class MimeMessage extends Message {
|
||||
removeHeader("Reply-to");
|
||||
mReplyTo = null;
|
||||
} else {
|
||||
setHeader("Reply-to", Address.toString(replyTo));
|
||||
setHeader("Reply-to", Address.toEncodedString(replyTo));
|
||||
mReplyTo = replyTo;
|
||||
}
|
||||
}
|
||||
|
@ -1657,7 +1657,7 @@ public class LocalStore extends Store implements Serializable {
|
||||
|
||||
public void setFrom(Address from) throws MessagingException {
|
||||
if (from != null) {
|
||||
addHeader("From", from.toString());
|
||||
addHeader("From", from.toEncodedString());
|
||||
this.mFrom = new Address[] {
|
||||
from
|
||||
};
|
||||
@ -1677,7 +1677,7 @@ public class LocalStore extends Store implements Serializable {
|
||||
removeHeader("To");
|
||||
this.mTo = null;
|
||||
} else {
|
||||
addHeader("To", Address.toString(addresses));
|
||||
addHeader("To", Address.toEncodedString(addresses));
|
||||
this.mTo = addresses;
|
||||
}
|
||||
} else if (type == RecipientType.CC) {
|
||||
@ -1685,7 +1685,7 @@ public class LocalStore extends Store implements Serializable {
|
||||
removeHeader("CC");
|
||||
this.mCc = null;
|
||||
} else {
|
||||
addHeader("CC", Address.toString(addresses));
|
||||
addHeader("CC", Address.toEncodedString(addresses));
|
||||
this.mCc = addresses;
|
||||
}
|
||||
} else if (type == RecipientType.BCC) {
|
||||
@ -1693,7 +1693,7 @@ public class LocalStore extends Store implements Serializable {
|
||||
removeHeader("BCC");
|
||||
this.mBcc = null;
|
||||
} else {
|
||||
addHeader("BCC", Address.toString(addresses));
|
||||
addHeader("BCC", Address.toEncodedString(addresses));
|
||||
this.mBcc = addresses;
|
||||
}
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user