mirror of
https://github.com/moparisthebest/k-9
synced 2024-11-27 19:52:17 -05:00
Fixed issue 261:Commas within diplay names were considered as delimiters
--> Using built in Rfc822Tokenizer
This commit is contained in:
parent
97e603362d
commit
c11c484718
@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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) {
|
||||||
if (addressList != null) {
|
List<Address> addresses = new ArrayList<Address>();
|
||||||
String[] addresses = addressList.split(",");
|
if (addressList!=null) {
|
||||||
StringBuilder newAddressList = new StringBuilder();
|
Rfc822Token[] tokens = Rfc822Tokenizer.tokenize(addressList);
|
||||||
String tmp = null;
|
for (Rfc822Token token : tokens) {
|
||||||
String before = null;
|
addresses.add(new Address(token.getAddress(), token.getName()));
|
||||||
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 );
|
return addresses.toArray(new Address[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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.
|
||||||
|
Loading…
Reference in New Issue
Block a user