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
3 changed files with 35 additions and 9 deletions
|
@ -17,6 +17,7 @@ import com.android.email.Utility;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import org.apache.james.mime4j.codec.EncoderUtil;
|
||||||
|
|
||||||
public class Address {
|
public class Address {
|
||||||
String mAddress;
|
String mAddress;
|
||||||
|
@ -120,6 +121,7 @@ public class Address {
|
||||||
return super.equals(o);
|
return super.equals(o);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
if (mPersonal != null) {
|
if (mPersonal != null) {
|
||||||
// if (mPersonal.matches(".*[\\(\\)<>@,;:\\\\\".\\[\\]].*")) {
|
// if (mPersonal.matches(".*[\\(\\)<>@,;:\\\\\".\\[\\]].*")) {
|
||||||
|
@ -145,6 +147,30 @@ public class Address {
|
||||||
}
|
}
|
||||||
return sb.toString();
|
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
|
* 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");
|
removeHeader("To");
|
||||||
this.mTo = null;
|
this.mTo = null;
|
||||||
} else {
|
} else {
|
||||||
setHeader("To", Address.toString(addresses));
|
setHeader("To", Address.toEncodedString(addresses));
|
||||||
this.mTo = addresses;
|
this.mTo = addresses;
|
||||||
}
|
}
|
||||||
} else if (type == RecipientType.CC) {
|
} else if (type == RecipientType.CC) {
|
||||||
|
@ -183,7 +183,7 @@ public class MimeMessage extends Message {
|
||||||
removeHeader("CC");
|
removeHeader("CC");
|
||||||
this.mCc = null;
|
this.mCc = null;
|
||||||
} else {
|
} else {
|
||||||
setHeader("CC", Address.toString(addresses));
|
setHeader("CC", Address.toEncodedString(addresses));
|
||||||
this.mCc = addresses;
|
this.mCc = addresses;
|
||||||
}
|
}
|
||||||
} else if (type == RecipientType.BCC) {
|
} else if (type == RecipientType.BCC) {
|
||||||
|
@ -191,7 +191,7 @@ public class MimeMessage extends Message {
|
||||||
removeHeader("BCC");
|
removeHeader("BCC");
|
||||||
this.mBcc = null;
|
this.mBcc = null;
|
||||||
} else {
|
} else {
|
||||||
setHeader("BCC", Address.toString(addresses));
|
setHeader("BCC", Address.toEncodedString(addresses));
|
||||||
this.mBcc = addresses;
|
this.mBcc = addresses;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -223,7 +223,7 @@ public class MimeMessage extends Message {
|
||||||
|
|
||||||
public void setFrom(Address from) throws MessagingException {
|
public void setFrom(Address from) throws MessagingException {
|
||||||
if (from != null) {
|
if (from != null) {
|
||||||
setHeader("From", from.toString());
|
setHeader("From", from.toEncodedString());
|
||||||
this.mFrom = new Address[] {
|
this.mFrom = new Address[] {
|
||||||
from
|
from
|
||||||
};
|
};
|
||||||
|
@ -244,7 +244,7 @@ public class MimeMessage extends Message {
|
||||||
removeHeader("Reply-to");
|
removeHeader("Reply-to");
|
||||||
mReplyTo = null;
|
mReplyTo = null;
|
||||||
} else {
|
} else {
|
||||||
setHeader("Reply-to", Address.toString(replyTo));
|
setHeader("Reply-to", Address.toEncodedString(replyTo));
|
||||||
mReplyTo = replyTo;
|
mReplyTo = replyTo;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1657,7 +1657,7 @@ public class LocalStore extends Store implements Serializable {
|
||||||
|
|
||||||
public void setFrom(Address from) throws MessagingException {
|
public void setFrom(Address from) throws MessagingException {
|
||||||
if (from != null) {
|
if (from != null) {
|
||||||
addHeader("From", from.toString());
|
addHeader("From", from.toEncodedString());
|
||||||
this.mFrom = new Address[] {
|
this.mFrom = new Address[] {
|
||||||
from
|
from
|
||||||
};
|
};
|
||||||
|
@ -1677,7 +1677,7 @@ public class LocalStore extends Store implements Serializable {
|
||||||
removeHeader("To");
|
removeHeader("To");
|
||||||
this.mTo = null;
|
this.mTo = null;
|
||||||
} else {
|
} else {
|
||||||
addHeader("To", Address.toString(addresses));
|
addHeader("To", Address.toEncodedString(addresses));
|
||||||
this.mTo = addresses;
|
this.mTo = addresses;
|
||||||
}
|
}
|
||||||
} else if (type == RecipientType.CC) {
|
} else if (type == RecipientType.CC) {
|
||||||
|
@ -1685,7 +1685,7 @@ public class LocalStore extends Store implements Serializable {
|
||||||
removeHeader("CC");
|
removeHeader("CC");
|
||||||
this.mCc = null;
|
this.mCc = null;
|
||||||
} else {
|
} else {
|
||||||
addHeader("CC", Address.toString(addresses));
|
addHeader("CC", Address.toEncodedString(addresses));
|
||||||
this.mCc = addresses;
|
this.mCc = addresses;
|
||||||
}
|
}
|
||||||
} else if (type == RecipientType.BCC) {
|
} else if (type == RecipientType.BCC) {
|
||||||
|
@ -1693,7 +1693,7 @@ public class LocalStore extends Store implements Serializable {
|
||||||
removeHeader("BCC");
|
removeHeader("BCC");
|
||||||
this.mBcc = null;
|
this.mBcc = null;
|
||||||
} else {
|
} else {
|
||||||
addHeader("BCC", Address.toString(addresses));
|
addHeader("BCC", Address.toEncodedString(addresses));
|
||||||
this.mBcc = addresses;
|
this.mBcc = addresses;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue