Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mail/common/src/main/java/com/fsck/k9/mail/Address.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ private Address(String address, String personal, boolean parse) {
Log.e("Invalid address: %s", address);
}
} else {
mAddress = address;
mAddress = Rfc822Token.withULabelDomain(address);
mPersonal = personal;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.fsck.k9.mail.helper;


import java.net.IDN;
import org.jetbrains.annotations.Nullable;


Expand All @@ -34,7 +35,7 @@ public class Rfc822Token {
*/
public Rfc822Token(@Nullable String name, @Nullable String address, @Nullable String comment) {
mName = name;
mAddress = address;
mAddress = withULabelDomain(address);
mComment = comment;
}

Expand Down Expand Up @@ -73,7 +74,7 @@ public void setName(@Nullable String name) {
* Changes the address to the specified address.
*/
public void setAddress(@Nullable String address) {
mAddress = address;
mAddress = withULabelDomain(address);
}

/**
Expand Down Expand Up @@ -202,4 +203,14 @@ public boolean equals(@Nullable Object o) {
stringEquals(mAddress, other.mAddress) &&
stringEquals(mComment, other.mComment));
}

@Nullable
public static String withULabelDomain(@Nullable final String address) {
if (address == null) return null;
int at = address.lastIndexOf('@');
if (at < 0 || at == address.length()-1)
return address;
return address.substring(0, at+1) +
IDN.toUnicode(address.substring(at+1), IDN.ALLOW_UNASSIGNED);
}
}
18 changes: 18 additions & 0 deletions mail/common/src/test/java/com/fsck/k9/mail/AddressTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public void parse_withUnusualEmails_shouldSetAddress() {
"example@s.solutions",
"user@com",
"user@localserver",
"user@orléans.example",
"user@[IPv6:2001:db8::1]"
};

Expand All @@ -87,14 +88,31 @@ public void parse_withEncodedPersonal_shouldDecode() {

}

@Test
public void construction_withALabel_shouldDecode() {
// Mutt and Exchange do this, and maybe Plesk too. Best fix it
// at the earliest opportinity.
Address a = new Address("grå@xn--gr-zia.org", "Grå katt");

assertEquals("Grå katt", a.getPersonal());
assertEquals("grå@grå.org", a.getAddress());
}

@Test
public void parse_withQuotedEncodedPersonal_shouldDecode() {
Address[] addresses = Address.parse(
"\"=?UTF-8?B?WWFob28h44OA44Kk44Os44Kv44OI44Kq44OV44Kh44O8?= \"<directoffer-master@mail.yahoo.co.jp>");

assertEquals("Yahoo!ダイレクトオファー ", addresses[0].getPersonal());
assertEquals("directoffer-master@mail.yahoo.co.jp", addresses[0].getAddress());
}


@Test
public void parse_withALabel_shouldDecode() {
Address[] addresses = Address.parse("info@xn--gr-zia.org");
assertEquals(1, addresses.length);
assertEquals("info@grå.org", addresses[0].getAddress());
}

/**
Expand Down
Loading