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

Fixed issue 261:Commas within diplay names were considered as delimiters

--> Using built in Rfc822Tokenizer
This commit is contained in:
Bao-Long Nguyen-Trong 2009-09-08 07:31:02 +00:00
parent 97e603362d
commit c11c484718
2 changed files with 14 additions and 33 deletions

View File

@ -1,10 +1,8 @@
package com.android.email; package com.android.email;
import com.android.email.mail.Address; import android.text.util.Rfc822Tokenizer;
import android.util.Config;
import android.util.Log;
import android.widget.AutoCompleteTextView.Validator; import android.widget.AutoCompleteTextView.Validator;
public class EmailAddressValidator implements Validator { public class EmailAddressValidator implements Validator {
@ -13,6 +11,6 @@ public class EmailAddressValidator implements Validator {
} }
public boolean isValid(CharSequence text) { public boolean isValid(CharSequence text) {
return Address.parseUnencoded(text.toString()).length > 0; return Rfc822Tokenizer.tokenize(text).length > 0;
} }
} }

View File

@ -1,25 +1,22 @@
package com.android.email.mail; package com.android.email.mail;
import java.io.UnsupportedEncodingException; import android.text.util.Rfc822Token;
import java.net.URLEncoder; import android.text.util.Rfc822Tokenizer;
import java.util.ArrayList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.james.mime4j.field.address.AddressList; import org.apache.james.mime4j.field.address.AddressList;
import org.apache.james.mime4j.field.address.Mailbox; 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.Log; import android.util.Log;
import com.android.email.Email; import com.android.email.Email;
import com.android.email.Utility; import com.android.email.Utility;
import com.android.email.mail.internet.MimeUtility;
import java.util.List;
import java.util.ArrayList;
public class Address { public class Address {
String mAddress; String mAddress;
@ -71,30 +68,16 @@ public class Address {
* @return An array of 0 or more Addresses. * @return An array of 0 or more Addresses.
*/ */
public static Address[] parseUnencoded(String addressList) { public static Address[] parseUnencoded(String addressList) {
List<Address> addresses = new ArrayList<Address>();
if (addressList!=null) { if (addressList!=null) {
String[] addresses = addressList.split(","); Rfc822Token[] tokens = Rfc822Tokenizer.tokenize(addressList);
StringBuilder newAddressList = new StringBuilder(); for (Rfc822Token token : tokens) {
String tmp = null; addresses.add(new Address(token.getAddress(), token.getName()));
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 ); return addresses.toArray(new Address[0]);
}
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.