mirror of
https://github.com/moparisthebest/k-9
synced 2024-11-30 13:12:25 -05:00
Correctly parse email addresses (from contacts). Could be of the form "User name <user@example.com>".
Fixes issue 2920
This commit is contained in:
parent
920d8b2ca3
commit
a213ca2fb7
@ -47,21 +47,49 @@ public class Address
|
|||||||
|
|
||||||
public Address(String address, String personal)
|
public Address(String address, String personal)
|
||||||
{
|
{
|
||||||
this.mAddress = address;
|
this(address, personal, true);
|
||||||
if ("".equals(personal))
|
|
||||||
{
|
|
||||||
personal = null;
|
|
||||||
}
|
|
||||||
if (personal!=null)
|
|
||||||
{
|
|
||||||
personal = personal.trim();
|
|
||||||
}
|
|
||||||
this.mPersonal = personal;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Address(String address)
|
public Address(String address)
|
||||||
{
|
{
|
||||||
this.mAddress = address;
|
this(address, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Address(String address, String personal, boolean parse)
|
||||||
|
{
|
||||||
|
if (parse)
|
||||||
|
{
|
||||||
|
Rfc822Token[] tokens = Rfc822Tokenizer.tokenize(address);
|
||||||
|
if (tokens.length > 0)
|
||||||
|
{
|
||||||
|
Rfc822Token token = tokens[0];
|
||||||
|
mAddress = token.getAddress();
|
||||||
|
String name = token.getName();
|
||||||
|
if ((name != null) && !("".equals(name)))
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* Don't use the "personal" argument if "address" is of the form:
|
||||||
|
* James Bond <james.bond@mi6.uk>
|
||||||
|
*
|
||||||
|
* See issue 2920
|
||||||
|
*/
|
||||||
|
mPersonal = name;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mPersonal = (personal == null) ? null : personal.trim();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// This should be an error
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mAddress = address;
|
||||||
|
mPersonal = personal;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getAddress()
|
public String getAddress()
|
||||||
@ -85,7 +113,7 @@ public class Address
|
|||||||
{
|
{
|
||||||
personal = null;
|
personal = null;
|
||||||
}
|
}
|
||||||
if (personal!=null)
|
if (personal != null)
|
||||||
{
|
{
|
||||||
personal = personal.trim();
|
personal = personal.trim();
|
||||||
}
|
}
|
||||||
@ -102,17 +130,15 @@ public class Address
|
|||||||
public static Address[] parseUnencoded(String addressList)
|
public static Address[] parseUnencoded(String addressList)
|
||||||
{
|
{
|
||||||
List<Address> addresses = new ArrayList<Address>();
|
List<Address> addresses = new ArrayList<Address>();
|
||||||
if (addressList!=null
|
if ((addressList != null) && !("".equals(addressList)))
|
||||||
&& !"".equals(addressList))
|
|
||||||
{
|
{
|
||||||
Rfc822Token[] tokens = Rfc822Tokenizer.tokenize(addressList);
|
Rfc822Token[] tokens = Rfc822Tokenizer.tokenize(addressList);
|
||||||
for (Rfc822Token token : tokens)
|
for (Rfc822Token token : tokens)
|
||||||
{
|
{
|
||||||
String address = token.getAddress();
|
String address = token.getAddress();
|
||||||
if (address!=null
|
if ((address != null) && !("".equals(address)))
|
||||||
&& !"".equals(address))
|
|
||||||
{
|
{
|
||||||
addresses.add(new Address(token.getAddress(), token.getName()));
|
addresses.add(new Address(token.getAddress(), token.getName(), false));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -129,7 +155,7 @@ public class Address
|
|||||||
public static Address[] parse(String addressList)
|
public static Address[] parse(String addressList)
|
||||||
{
|
{
|
||||||
ArrayList<Address> addresses = new ArrayList<Address>();
|
ArrayList<Address> addresses = new ArrayList<Address>();
|
||||||
if (addressList == null && !"".equals(addressList))
|
if ((addressList == null) && !("".equals(addressList)))
|
||||||
{
|
{
|
||||||
return EMPTY_ADDRESS_ARRAY;
|
return EMPTY_ADDRESS_ARRAY;
|
||||||
}
|
}
|
||||||
@ -142,25 +168,18 @@ public class Address
|
|||||||
if (address instanceof Mailbox)
|
if (address instanceof Mailbox)
|
||||||
{
|
{
|
||||||
Mailbox mailbox = (Mailbox)address;
|
Mailbox mailbox = (Mailbox)address;
|
||||||
if (mailbox.getName() != null )
|
addresses.add(new Address(mailbox.getLocalPart() + "@" + mailbox.getDomain(), mailbox.getName(), false));
|
||||||
{
|
|
||||||
addresses.add(new Address(mailbox.getLocalPart() + "@" + mailbox.getDomain(), mailbox.getName()));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
addresses.add(new Address(mailbox.getLocalPart() + "@" + mailbox.getDomain()));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Log.e(K9.LOG_TAG, "Unknown address type from Mime4J: "
|
Log.e(K9.LOG_TAG, "Unknown address type from Mime4J: "
|
||||||
+ address.getClass().toString());
|
+ address.getClass().toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (MimeException pe)
|
catch (MimeException pe)
|
||||||
{
|
{
|
||||||
|
Log.e(K9.LOG_TAG, "MimeException in Address.parse()", pe);
|
||||||
}
|
}
|
||||||
return addresses.toArray(EMPTY_ADDRESS_ARRAY);
|
return addresses.toArray(EMPTY_ADDRESS_ARRAY);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user