1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-11-30 13:12:25 -05:00

Fix for Issue 328 and 332

Contributed by: Ludovic LANGE / ludovic.lange.android
This commit is contained in:
Jesse Vincent 2009-06-01 01:55:39 +00:00
parent 7d47328b2e
commit a7d316ecdd
3 changed files with 35 additions and 2 deletions

View File

@ -13,6 +13,6 @@ public class EmailAddressValidator implements Validator {
} }
public boolean isValid(CharSequence text) { public boolean isValid(CharSequence text) {
return Address.parse(text.toString()).length > 0; return Address.parseUnencoded(text.toString()).length > 0;
} }
} }

View File

@ -566,7 +566,7 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
} }
private Address[] getAddresses(MultiAutoCompleteTextView view) { private Address[] getAddresses(MultiAutoCompleteTextView view) {
Address[] addresses = Address.parse(view.getText().toString().trim()); Address[] addresses = Address.parseUnencoded(view.getText().toString().trim());
return addresses; return addresses;
} }

View File

@ -12,6 +12,7 @@ import org.apache.james.mime4j.field.address.Mailbox;
import org.apache.james.mime4j.field.address.MailboxList; import org.apache.james.mime4j.field.address.MailboxList;
import org.apache.james.mime4j.field.address.NamedMailbox; import org.apache.james.mime4j.field.address.NamedMailbox;
import org.apache.james.mime4j.field.address.parser.ParseException; import org.apache.james.mime4j.field.address.parser.ParseException;
import org.apache.james.mime4j.codec.EncoderUtil;
import android.util.Config; import android.util.Config;
import android.util.Log; import android.util.Log;
@ -50,6 +51,38 @@ public class Address {
this.mPersonal = personal; this.mPersonal = personal;
} }
/**
* Parse a comma separated list of email addresses in human readable format and return an
* array of Address objects, RFC-822 encoded.
*
* @param addressList
* @return An array of 0 or more Addresses.
*/
public static Address[] parseUnencoded(String addressList) {
if (addressList != null) {
String[] addresses = addressList.split(",");
StringBuilder newAddressList = new StringBuilder();
String tmp = null;
String before = null;
String after = null;
int pos = -1;
for( int i = 0, count = addresses.length; i < count; i++ ) {
tmp = addresses[i];
pos = tmp.indexOf("<");
if( pos > 1 ) {
before = tmp.substring( 0, pos );
after = tmp.substring( pos );
tmp = EncoderUtil.encodeAddressDisplayName( before ) + after;
}
if( i > 0 ) {
newAddressList.append( "," );
}
newAddressList.append( tmp );
}
addressList = newAddressList.toString();
}
return Address.parse( addressList );
}
/** /**
* Parse a comma separated list of addresses in RFC-822 format and return an * Parse a comma separated list of addresses in RFC-822 format and return an
* array of Address objects. * array of Address objects.