Java Code Examples for android.text.util.Rfc822Tokenizer

The following are top voted examples for showing how to use android.text.util.Rfc822Tokenizer. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: q-mail   File: Address.java   Source Code and License 6 votes vote down vote up
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 (!TextUtils.isEmpty(name)) {
                /*
                 * Don't use the "personal" argument if "address" is of the form:
                 * James Bond <[email protected]>
                 *
                 * See issue 2920
                 */
                mPersonal = name;
            } else {
                mPersonal = (personal == null) ? null : personal.trim();
            }
        } else {
            // This should be an error
        }
    } else {
        mAddress = address;
        mPersonal = personal;
    }
}
 
Example 2
Project: talk-android   File: RecipientEditTextView.java   Source Code and License 6 votes vote down vote up
String createAddressText(RecipientEntry entry) {
    String display = entry.getDisplayName();
    String address = entry.getDestination();
    if (TextUtils.isEmpty(display) || TextUtils.equals(display, address)) {
        display = null;
    }
    String trimmedDisplayText;
    if (isPhoneQuery() && isPhoneNumber(address)) {
        trimmedDisplayText = address.trim();
    } else {
        if (address != null) {
            // Tokenize out the address in case the address already
            // contained the username as well.
            Rfc822Token[] tokenized = Rfc822Tokenizer.tokenize(address);
            if (tokenized != null && tokenized.length > 0) {
                address = tokenized[0].getAddress();
            }
        }
        Rfc822Token token = new Rfc822Token(display, address, null);
        trimmedDisplayText = token.toString().trim();
    }
    int index = trimmedDisplayText.indexOf(",");
    return mTokenizer != null && !TextUtils.isEmpty(trimmedDisplayText)
            && index < trimmedDisplayText.length() - 1 ? (String) mTokenizer
            .terminateToken(trimmedDisplayText) : trimmedDisplayText;
}
 
Example 3
Project: talk-android   File: TextChipsEditView.java   Source Code and License 6 votes vote down vote up
String createAddressText(RecipientEntry entry) {
    String display = entry.getDisplayName();
    String address = entry.getDestination();
    if (TextUtils.isEmpty(display) || TextUtils.equals(display, address)) {
        display = null;
    }
    String trimmedDisplayText;
    if (isPhoneQuery() && isPhoneNumber(address)) {
        trimmedDisplayText = address.trim();
    } else {
        if (address != null) {
            // Tokenize out the address in case the address already
            // contained the username as well.
            Rfc822Token[] tokenized = Rfc822Tokenizer.tokenize(address);
            if (tokenized != null && tokenized.length > 0) {
                address = tokenized[0].getAddress();
            }
        }
        Rfc822Token token = new Rfc822Token(display, address, null);
        trimmedDisplayText = token.toString().trim();
    }
    int index = trimmedDisplayText.indexOf(",");
    return mTokenizer != null && !TextUtils.isEmpty(trimmedDisplayText)
            && index < trimmedDisplayText.length() - 1 ? (String) mTokenizer
            .terminateToken(trimmedDisplayText) : trimmedDisplayText;
}
 
Example 4
Project: K9-MailClient   File: Address.java   Source Code and License 6 votes vote down vote up
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 (!TextUtils.isEmpty(name)) {
                /*
                 * Don't use the "personal" argument if "address" is of the form:
                 * James Bond <[email protected]>
                 *
                 * See issue 2920
                 */
                mPersonal = name;
            } else {
                mPersonal = (personal == null) ? null : personal.trim();
            }
        } else {
            // This should be an error
        }
    } else {
        mAddress = address;
        mPersonal = personal;
    }
}
 
Example 5
Project: FMTech   File: ckm.java   Source Code and License 6 votes vote down vote up
private final String l()
{
  if (TextUtils.isEmpty(this.o)) {}
  String str;
  do
  {
    Rfc822Token[] arrayOfRfc822Token;
    do
    {
      return null;
      arrayOfRfc822Token = Rfc822Tokenizer.tokenize(this.o);
    } while ((arrayOfRfc822Token == null) || (arrayOfRfc822Token.length <= 0));
    str = arrayOfRfc822Token[0].getAddress();
  } while ((TextUtils.isEmpty(str)) || (!E.matcher(str).matches()));
  return str;
}
 
Example 6
Project: FMTech   File: cdo.java   Source Code and License 6 votes vote down vote up
public final void b(String paramString)
{
  Rfc822Token[] arrayOfRfc822Token = null;
  if (paramString != null) {
    arrayOfRfc822Token = Rfc822Tokenizer.tokenize(paramString);
  }
  if ((arrayOfRfc822Token == null) || (arrayOfRfc822Token.length == 0)) {
    return;
  }
  Rfc822Token localRfc822Token = arrayOfRfc822Token[0];
  if ((TextUtils.isEmpty(localRfc822Token.getName())) && (!TextUtils.isEmpty(this.b.Z))) {
    localRfc822Token.setName(this.b.Z);
  }
  String str1 = String.valueOf(Uri.encode(localRfc822Token.toString()));
  if (str1.length() != 0) {}
  for (String str2 = "mailto:".concat(str1);; str2 = new String("mailto:"))
  {
    f(new Intent("android.intent.action.SENDTO", Uri.parse(str2)));
    return;
  }
}
 
Example 7
Project: daxSmail   File: Address.java   Source Code and License 6 votes vote down vote up
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 (!StringUtils.isNullOrEmpty(name)) {
                /*
                 * Don't use the "personal" argument if "address" is of the form:
                 * James Bond <[email protected]>
                 *
                 * See issue 2920
                 */
                mPersonal = name;
            } else {
                mPersonal = (personal == null) ? null : personal.trim();
            }
        } else {
            // This should be an error
        }
    } else {
        mAddress = address;
        mPersonal = personal;
    }
}
 
Example 8
Project: sms_DualCard   File: RecipientsEditor.java   Source Code and License 6 votes vote down vote up
private static String getNumberAt(Spanned sp, int start, int end, Context context) {
    String number = getFieldAt("number", sp, start, end, context);
    number = PhoneNumberUtils.replaceUnicodeDigits(number);
    if (!TextUtils.isEmpty(number)) {
        int pos = number.indexOf('<');
        if (pos >= 0 && pos < number.indexOf('>')) {
            // The number looks like an Rfc882 address, i.e. <fred flinstone> 891-7823
            Rfc822Token[] tokens = Rfc822Tokenizer.tokenize(number);
            if (tokens.length == 0) {
                return number;
            }
            return tokens[0].getAddress();
        }
    }
    return number;
}
 
Example 9
Project: sms_DualCard   File: RecipientEditTextView.java   Source Code and License 6 votes vote down vote up
String createAddressText(RecipientEntry entry) {
    String display = entry.getDisplayName();
    String address = entry.getDestination();
    if (TextUtils.isEmpty(display) || TextUtils.equals(display, address)) {
        display = null;
    }
    String trimmedDisplayText;
    if (isPhoneQuery() && isPhoneNumber(address)) {
        trimmedDisplayText = address.trim();
    } else {
        if (address != null) {
            // Tokenize out the address in case the address already
            // contained the username as well.
            Rfc822Token[] tokenized = Rfc822Tokenizer.tokenize(address);
            if (tokenized != null && tokenized.length > 0) {
                address = tokenized[0].getAddress();
            }
        }
        Rfc822Token token = new Rfc822Token(display, address, null);
        trimmedDisplayText = token.toString().trim();
    }
    int index = trimmedDisplayText.indexOf(",");
    return mTokenizer != null && !TextUtils.isEmpty(trimmedDisplayText)
            && index < trimmedDisplayText.length() - 1 ? (String) mTokenizer
            .terminateToken(trimmedDisplayText) : trimmedDisplayText;
}
 
Example 10
Project: sms_DualCard   File: RecipientEditTextView.java   Source Code and License 6 votes vote down vote up
String createChipDisplayText(RecipientEntry entry) {
    String display = entry.getDisplayName();
    String address = entry.getDestination();
    if (TextUtils.isEmpty(display) || TextUtils.equals(display, address)) {
        display = null;
    }
    if (address != null && !(isPhoneQuery() && isPhoneNumber(address))) {
        // Tokenize out the address in case the address already
        // contained the username as well.
        Rfc822Token[] tokenized = Rfc822Tokenizer.tokenize(address);
        if (tokenized != null && tokenized.length > 0) {
            address = tokenized[0].getAddress();
        }
    }
    if (!TextUtils.isEmpty(display)) {
        return display;
    } else if (!TextUtils.isEmpty(address)){
        return address;
    } else {
        return new Rfc822Token(display, address, null).toString();
    }
}
 
Example 11
Project: k-9   File: Address.java   Source Code and License 6 votes vote down vote up
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 (!StringUtils.isNullOrEmpty(name)) {
                /*
                 * Don't use the "personal" argument if "address" is of the form:
                 * James Bond <[email protected]>
                 *
                 * See issue 2920
                 */
                mPersonal = name;
            } else {
                mPersonal = (personal == null) ? null : personal.trim();
            }
        } else {
            // This should be an error
        }
    } else {
        mAddress = address;
        mPersonal = personal;
    }
}
 
Example 12
Project: ChipsLibrary   File: RecipientEditTextView.java   Source Code and License 6 votes vote down vote up
String createAddressText(final RecipientEntry entry)
{
String display=entry.getDisplayName();
String address=entry.getDestination();
if(TextUtils.isEmpty(display)||TextUtils.equals(display,address))
  display=null;
String trimmedDisplayText;
if(isPhoneQuery()&&isPhoneNumber(address))
  trimmedDisplayText=address.trim();
else
  {
  if(address!=null)
    {
    // Tokenize out the address in case the address already
    // contained the username as well.
    final Rfc822Token[] tokenized=Rfc822Tokenizer.tokenize(address);
    if(tokenized!=null&&tokenized.length>0)
      address=tokenized[0].getAddress();
    }
  final Rfc822Token token=new Rfc822Token(display,address,null);
  trimmedDisplayText=token.toString().trim();
  }
final int index=trimmedDisplayText.indexOf(",");
return mTokenizer!=null&&!TextUtils.isEmpty(trimmedDisplayText)&&index<trimmedDisplayText.length()-1 ? (String)mTokenizer.terminateToken(trimmedDisplayText) : trimmedDisplayText;
}
 
Example 13
Project: Calendar_lunar   File: EditEventHelper.java   Source Code and License 6 votes vote down vote up
public static LinkedHashSet<Rfc822Token> getAddressesFromList(String list,
        Rfc822Validator validator) {
    LinkedHashSet<Rfc822Token> addresses = new LinkedHashSet<Rfc822Token>();
    Rfc822Tokenizer.tokenize(list, addresses);
    if (validator == null) {
        return addresses;
    }

    // validate the emails, out of paranoia. they should already be
    // validated on input, but drop any invalid emails just to be safe.
    Iterator<Rfc822Token> addressIterator = addresses.iterator();
    while (addressIterator.hasNext()) {
        Rfc822Token address = addressIterator.next();
        if (!validator.isValid(address.getAddress())) {
            Log.v(TAG, "Dropping invalid attendee email address: " + address.getAddress());
            addressIterator.remove();
        }
    }
    return addresses;
}
 
Example 14
Project: Calendar_lunar   File: EditEventView.java   Source Code and License 6 votes vote down vote up
private MultiAutoCompleteTextView initMultiAutoCompleteTextView(RecipientEditTextView list) {
    if (ChipsUtil.supportsChipsUi()) {
        mAddressAdapter = new RecipientAdapter(mActivity);
        list.setAdapter((BaseRecipientAdapter) mAddressAdapter);
        list.setOnFocusListShrinkRecipients(false);
    } else {
        mAddressAdapter = new EmailAddressAdapter(mActivity);
        list.setAdapter((EmailAddressAdapter)mAddressAdapter);
    }
    list.setTokenizer(new Rfc822Tokenizer());
    list.setValidator(mEmailValidator);

    // NOTE: assumes no other filters are set
    list.setFilters(sRecipientFilters);

    return list;
}
 
Example 15
Project: Calendar_lunar   File: RecipientEditTextView.java   Source Code and License 6 votes vote down vote up
String createAddressText(RecipientEntry entry) {
    String display = entry.getDisplayName();
    String address = entry.getDestination();
    if (TextUtils.isEmpty(display) || TextUtils.equals(display, address)) {
        display = null;
    }
    String trimmedDisplayText;
    if (isPhoneQuery() && isPhoneNumber(address)) {
        trimmedDisplayText = address.trim();
    } else {
        if (address != null) {
            // Tokenize out the address in case the address already
            // contained the username as well.
            Rfc822Token[] tokenized = Rfc822Tokenizer.tokenize(address);
            if (tokenized != null && tokenized.length > 0) {
                address = tokenized[0].getAddress();
            }
        }
        Rfc822Token token = new Rfc822Token(display, address, null);
        trimmedDisplayText = token.toString().trim();
    }
    int index = trimmedDisplayText.indexOf(",");
    return mTokenizer != null && !TextUtils.isEmpty(trimmedDisplayText)
            && index < trimmedDisplayText.length() - 1 ? (String) mTokenizer
            .terminateToken(trimmedDisplayText) : trimmedDisplayText;
}
 
Example 16
Project: Calendar_lunar   File: RecipientEditTextView.java   Source Code and License 6 votes vote down vote up
String createChipDisplayText(RecipientEntry entry) {
    String display = entry.getDisplayName();
    String address = entry.getDestination();
    if (TextUtils.isEmpty(display) || TextUtils.equals(display, address)) {
        display = null;
    }
    if (address != null && !(isPhoneQuery() && isPhoneNumber(address))) {
        // Tokenize out the address in case the address already
        // contained the username as well.
        Rfc822Token[] tokenized = Rfc822Tokenizer.tokenize(address);
        if (tokenized != null && tokenized.length > 0) {
            address = tokenized[0].getAddress();
        }
    }
    if (!TextUtils.isEmpty(display)) {
        return display;
    } else if (!TextUtils.isEmpty(address)){
        return address;
    } else {
        return new Rfc822Token(display, address, null).toString();
    }
}
 
Example 17
Project: k-9-master   File: Address.java   Source Code and License 6 votes vote down vote up
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 (!StringUtils.isNullOrEmpty(name)) {
                /*
                 * Don't use the "personal" argument if "address" is of the form:
                 * James Bond <[email protected]>
                 *
                 * See issue 2920
                 */
                mPersonal = name;
            } else {
                mPersonal = (personal == null) ? null : personal.trim();
            }
        } else {
            // This should be an error
        }
    } else {
        mAddress = address;
        mPersonal = personal;
    }
}
 
Example 18
Project: android-aosp-mms   File: RecipientsEditor.java   Source Code and License 6 votes vote down vote up
private static String getNumberAt(Spanned sp, int start, int end, Context context) {
    String number = getFieldAt("number", sp, start, end, context);
    number = PhoneNumberUtils.replaceUnicodeDigits(number);
    if (!TextUtils.isEmpty(number)) {
        int pos = number.indexOf('<');
        if (pos >= 0 && pos < number.indexOf('>')) {
            // The number looks like an Rfc882 address, i.e. <fred flinstone> 891-7823
            Rfc822Token[] tokens = Rfc822Tokenizer.tokenize(number);
            if (tokens.length == 0) {
                return number;
            }
            return tokens[0].getAddress();
        }
    }
    return number;
}
 
Example 19
Project: q-mail   File: Address.java   Source Code and License 5 votes vote down vote up
/**
 * 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) {
    List<Address> addresses = new ArrayList<Address>();
    if (!TextUtils.isEmpty(addressList)) {
        Rfc822Token[] tokens = Rfc822Tokenizer.tokenize(addressList);
        for (Rfc822Token token : tokens) {
            String address = token.getAddress();
            if (!TextUtils.isEmpty(address)) {
                addresses.add(new Address(token.getAddress(), token.getName(), false));
            }
        }
    }
    return addresses.toArray(EMPTY_ADDRESS_ARRAY);
}
 
Example 20
Project: talk-android   File: RecipientEditTextView.java   Source Code and License 5 votes vote down vote up
private static String tokenizeAddress(String destination) {
    Rfc822Token[] tokens = Rfc822Tokenizer.tokenize(destination);
    if (tokens != null && tokens.length > 0) {
        return tokens[0].getAddress();
    }
    return destination;
}
 
Example 21
Project: talk-android   File: TextChipsEditView.java   Source Code and License 5 votes vote down vote up
private static String tokenizeAddress(String destination) {
    Rfc822Token[] tokens = Rfc822Tokenizer.tokenize(destination);
    if (tokens != null && tokens.length > 0) {
        return tokens[0].getAddress();
    }
    return destination;
}
 
Example 22
Project: talk-android   File: RecipientEntry.java   Source Code and License 5 votes vote down vote up
/**
 * Construct a RecipientEntry from just an address that has been entered.
 * This address has not been resolved to a contact and therefore does not
 * have a contact id or photo.
 */
public static RecipientEntry constructFakeEntry(final String address, final boolean isValid) {
    final Rfc822Token[] tokens = Rfc822Tokenizer.tokenize(address);
    final String tokenizedAddress = tokens.length > 0 ? tokens[0].getAddress() : address;

    return new RecipientEntry(ENTRY_TYPE_PERSON, tokenizedAddress, tokenizedAddress,
            INVALID_DESTINATION_TYPE, null, INVALID_CONTACT, null /* directoryId */,
            INVALID_CONTACT, null, true, isValid, null /* lookupKey */);
}
 
Example 23
Project: K9-MailClient   File: Address.java   Source Code and License 5 votes vote down vote up
/**
 * 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) {
    List<Address> addresses = new ArrayList<Address>();
    if (!TextUtils.isEmpty(addressList)) {
        Rfc822Token[] tokens = Rfc822Tokenizer.tokenize(addressList);
        for (Rfc822Token token : tokens) {
            String address = token.getAddress();
            if (!TextUtils.isEmpty(address)) {
                addresses.add(new Address(token.getAddress(), token.getName(), false));
            }
        }
    }
    return addresses.toArray(EMPTY_ADDRESS_ARRAY);
}
 
Example 24
Project: FMTech   File: brn.java   Source Code and License 5 votes vote down vote up
private static String c(String paramString)
{
  Rfc822Token[] arrayOfRfc822Token = Rfc822Tokenizer.tokenize(paramString);
  if (arrayOfRfc822Token.length == 0) {}
  String str;
  do
  {
    return null;
    str = arrayOfRfc822Token[0].getAddress();
  } while (TextUtils.isEmpty(str));
  return str.toLowerCase();
}
 
Example 25
Project: daxSmail   File: Address.java   Source Code and License 5 votes vote down vote up
/**
 * 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) {
    List<Address> addresses = new ArrayList<Address>();
    if (!StringUtils.isNullOrEmpty(addressList)) {
        Rfc822Token[] tokens = Rfc822Tokenizer.tokenize(addressList);
        for (Rfc822Token token : tokens) {
            String address = token.getAddress();
            if (!StringUtils.isNullOrEmpty(address)) {
                addresses.add(new Address(token.getAddress(), token.getName(), false));
            }
        }
    }
    return addresses.toArray(EMPTY_ADDRESS_ARRAY);
}
 
Example 26
Project: j2objc   File: TextUtilsTest.java   Source Code and License 5 votes vote down vote up
@SmallTest
public void testRfc822TokenizerFullAddress() {
    Rfc822Token[] tokens = Rfc822Tokenizer.tokenize("Foo Bar (something) <[email protected]>");
    assertNotNull(tokens);
    assertEquals(1, tokens.length);
    assertEquals("[email protected]", tokens[0].getAddress());
    assertEquals("Foo Bar", tokens[0].getName());
    assertEquals("something",tokens[0].getComment());
}
 
Example 27
Project: j2objc   File: TextUtilsTest.java   Source Code and License 5 votes vote down vote up
@SmallTest
public void testRfc822TokenizeItemWithError() {
    Rfc822Token[] tokens = Rfc822Tokenizer.tokenize("\"Foo Bar\\");
    assertNotNull(tokens);
    assertEquals(1, tokens.length);
    assertEquals("Foo Bar", tokens[0].getAddress());
}
 
Example 28
Project: j2objc   File: TextUtilsTest.java   Source Code and License 5 votes vote down vote up
@SmallTest
public void testRfc822FindToken() {
    Rfc822Tokenizer tokenizer = new Rfc822Tokenizer();
    //                0           1         2           3         4
    //                0 1234 56789012345678901234 5678 90123456789012345
    String address = "\"Foo\" <[email protected]>, \"Bar\" <[email protected]>";
    assertEquals(0, tokenizer.findTokenStart(address, 21));
    assertEquals(22, tokenizer.findTokenEnd(address, 21));
    assertEquals(24, tokenizer.findTokenStart(address, 25));
    assertEquals(46, tokenizer.findTokenEnd(address, 25));
}
 
Example 29
Project: Zom-Android   File: AddContactActivity.java   Source Code and License 5 votes vote down vote up
void inviteBuddies() {
    Rfc822Token[] recipients = Rfc822Tokenizer.tokenize(mNewAddress.getText());

    Pattern pattern = Pattern.compile(EMAIL_PATTERN);

    boolean foundOne = false;

    for (Rfc822Token recipient : recipients) {

        String address = recipient.getAddress();
        if (pattern.matcher(address).matches()) {
            new AddContactAsyncTask(mApp.getDefaultProviderId(), mApp.getDefaultAccountId(), mApp).execute(address, null, null);
            foundOne = true;
        }
    }

    if (foundOne) {
        Intent intent = new Intent();
        intent.putExtra(ContactsPickerActivity.EXTRA_RESULT_USERNAME, recipients[0].getAddress());
        intent.putExtra(ContactsPickerActivity.EXTRA_RESULT_PROVIDER, mApp.getDefaultProviderId());
        setResult(RESULT_OK, intent);
        finish();
    }



}
 
Example 30
Project: sms_DualCard   File: RecipientEditTextView.java   Source Code and License 5 votes vote down vote up
private String tokenizeAddress(String destination) {
    Rfc822Token[] tokens = Rfc822Tokenizer.tokenize(destination);
    if (tokens != null && tokens.length > 0) {
        return tokens[0].getAddress();
    }
    return destination;
}
 
Example 31
Project: sms_DualCard   File: SingleRecipientArrayAdapter.java   Source Code and License 5 votes vote down vote up
private void bindView(View view, Context context, RecipientEntry entry) {
    TextView display = (TextView) view.findViewById(android.R.id.title);
    ImageView imageView = (ImageView) view.findViewById(android.R.id.icon);
    display.setText(entry.getDisplayName());
    display.setVisibility(View.VISIBLE);
    imageView.setVisibility(View.VISIBLE);
    TextView destination = (TextView) view.findViewById(android.R.id.text1);
    destination.setText(Rfc822Tokenizer.tokenize(entry.getDestination())[0].getAddress());
}
 
Example 32
Project: k-9   File: Address.java   Source Code and License 5 votes vote down vote up
/**
 * 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) {
    List<Address> addresses = new ArrayList<Address>();
    if (!StringUtils.isNullOrEmpty(addressList)) {
        Rfc822Token[] tokens = Rfc822Tokenizer.tokenize(addressList);
        for (Rfc822Token token : tokens) {
            String address = token.getAddress();
            if (!StringUtils.isNullOrEmpty(address)) {
                addresses.add(new Address(token.getAddress(), token.getName(), false));
            }
        }
    }
    return addresses.toArray(EMPTY_ADDRESS_ARRAY);
}
 
Example 33
Project: ChipsLibrary   File: RecipientEditTextView.java   Source Code and License 5 votes vote down vote up
private static String tokenizeAddress(final String destination)
{
final Rfc822Token[] tokens=Rfc822Tokenizer.tokenize(destination);
if(tokens!=null&&tokens.length>0)
  return tokens[0].getAddress();
return destination;
}
 
Example 34
Project: ChipsLibrary   File: SingleRecipientArrayAdapter.java   Source Code and License 5 votes vote down vote up
private static void bindView(View view,RecipientEntry entry)
{
TextView display=(TextView)view.findViewById(android.R.id.title);
ImageView imageView=(ImageView)view.findViewById(android.R.id.icon);
display.setText(entry.getDisplayName());
display.setVisibility(View.VISIBLE);
imageView.setVisibility(View.VISIBLE);
TextView destination=(TextView)view.findViewById(android.R.id.text1);
destination.setText(Rfc822Tokenizer.tokenize(entry.getDestination())[0].getAddress());
}
 
Example 35
Project: ChipsLibrary   File: RecipientEntry.java   Source Code and License 5 votes vote down vote up
/**
 * Construct a RecipientEntry from just an address that has been entered. This address has not been resolved to a
 * contact and therefore does not have a contact id or photo.
 */
public static RecipientEntry constructFakeEntry(final String address,final boolean isValid)
  {
  final Rfc822Token[] tokens=Rfc822Tokenizer.tokenize(address);
  final String tokenizedAddress=tokens.length>0 ? tokens[0].getAddress() : address;
  return new RecipientEntry(ENTRY_TYPE_PERSON,tokenizedAddress,tokenizedAddress,INVALID_DESTINATION_TYPE,null,INVALID_CONTACT,INVALID_CONTACT,null,true,isValid,false /* isGalContact */);
  }
 
Example 36
Project: silent-contacts-android   File: ScContactsDatabaseHelper.java   Source Code and License 5 votes vote down vote up
public String extractHandleFromEmailAddress(String email) {
    Rfc822Token[] tokens = Rfc822Tokenizer.tokenize(email);
    if (tokens.length == 0) {
        return null;
    }

    String address = tokens[0].getAddress();
    int at = address.indexOf('@');
    if (at != -1) {
        return address.substring(0, at);
    }
    return null;
}
 
Example 37
Project: silent-contacts-android   File: ScContactsDatabaseHelper.java   Source Code and License 5 votes vote down vote up
public String extractAddressFromEmailAddress(String email) {
    Rfc822Token[] tokens = Rfc822Tokenizer.tokenize(email);
    if (tokens.length == 0) {
        return null;
    }
    return tokens[0].getAddress().trim();
}
 
Example 38
Project: EmailPopup   File: Address.java   Source Code and License 5 votes vote down vote up
public static Address[] parseUnencoded(String addressList) {
    List<Address> addresses = new ArrayList<Address>();
    if (addressList!=null
        && !"".equals(addressList)) {
        Rfc822Token[] tokens = Rfc822Tokenizer.tokenize(addressList);
        for (Rfc822Token token : tokens) {
            String address = token.getAddress();
            if (address!=null
                && !"".equals(address)) {
                addresses.add(new Address(token.getAddress(), token.getName()));
            }
        }
    }
    return addresses.toArray(new Address[0]);
}
 
Example 39
Project: prive-android   File: AddContactActivity.java   Source Code and License 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    mApp = (ImApp)getApplication();
    mHandler = new SimpleAlertHandler(this);
    resolveIntent(getIntent());

    setContentView(R.layout.add_contact_activity);

    BrandingResources brandingRes = mApp.getBrandingResource(mProviderId);
    setTitle(brandingRes.getString(BrandingResourceIDs.STRING_ADD_CONTACT_TITLE));

    TextView label = (TextView) findViewById(R.id.input_contact_label);
    label.setText(brandingRes.getString(BrandingResourceIDs.STRING_LABEL_INPUT_CONTACT));

    mAddressList = (MultiAutoCompleteTextView) findViewById(R.id.email);
    mAddressList.setAdapter(new EmailAddressAdapter(this));
    mAddressList.setTokenizer(new Rfc822Tokenizer());
    mAddressList.addTextChangedListener(mTextWatcher);

    mListSpinner = (Spinner) findViewById(R.id.choose_list);

    Cursor c = queryContactLists();
    int initSelection = searchInitListPos(c,
            getIntent().getStringExtra(ImServiceConstants.EXTRA_INTENT_LIST_NAME));
    SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,
            android.R.layout.simple_spinner_item, c, new String[] { Imps.ContactList.NAME },
            new int[] { android.R.id.text1 });
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    mListSpinner.setAdapter(adapter);
    mListSpinner.setSelection(initSelection);
    
    mInviteButton = (Button) findViewById(R.id.invite);
    mInviteButton.setText(brandingRes.getString(BrandingResourceIDs.STRING_BUTTON_ADD_CONTACT));
    mInviteButton.setOnClickListener(mButtonHandler);
    mInviteButton.setEnabled(false);
}
 
Example 40
Project: prive-android   File: AddContactActivity.java   Source Code and License 5 votes vote down vote up
void inviteBuddies() {
    Rfc822Token[] recipients = Rfc822Tokenizer.tokenize(mAddressList.getText());
    try {
        IImConnection conn = mApp.getConnection(mProviderId);
        IContactList list = getContactList(conn);
        if (list == null) {
            Log.e(ImApp.LOG_TAG, "<AddContactActivity> can't find given contact list:"
                                 + getSelectedListName());
            finish();
        } else {
            boolean fail = false;
            for (Rfc822Token recipient : recipients) {
                String username = recipient.getAddress();
                if (mDefaultDomain != null && username.indexOf('@') == -1) {
                    username = username + "@" + mDefaultDomain;
                }
                if (Log.isLoggable(ImApp.LOG_TAG, Log.DEBUG)) {
                    log("addContact:" + username);
                }
                int res = list.addContact(username);
                if (res != ImErrorInfo.NO_ERROR) {
                    fail = true;
                    mHandler.showAlert(R.string.error,
                            ErrorResUtils.getErrorRes(getResources(), res, username));
                }
            }
            // close the screen if there's no error.
            if (!fail) {
                finish();
            }
        }
    } catch (RemoteException ex) {
        Log.e(ImApp.LOG_TAG, "<AddContactActivity> inviteBuddies: caught " + ex);
    }
}
 
Example 41
Project: Calendar_lunar   File: RecipientEditTextView.java   Source Code and License 5 votes vote down vote up
private String tokenizeAddress(String destination) {
    Rfc822Token[] tokens = Rfc822Tokenizer.tokenize(destination);
    if (tokens != null && tokens.length > 0) {
        return tokens[0].getAddress();
    }
    return destination;
}
 
Example 42
Project: Calendar_lunar   File: SingleRecipientArrayAdapter.java   Source Code and License 5 votes vote down vote up
private void bindView(View view, Context context, RecipientEntry entry) {
    TextView display = (TextView) view.findViewById(android.R.id.title);
    ImageView imageView = (ImageView) view.findViewById(android.R.id.icon);
    display.setText(entry.getDisplayName());
    display.setVisibility(View.VISIBLE);
    imageView.setVisibility(View.VISIBLE);
    TextView destination = (TextView) view.findViewById(android.R.id.text1);
    destination.setText(Rfc822Tokenizer.tokenize(entry.getDestination())[0].getAddress());
}
 
Example 43
Project: Calendar_lunar   File: Rfc822Validator.java   Source Code and License 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public boolean isValid(CharSequence text) {
    Rfc822Token[] tokens = Rfc822Tokenizer.tokenize(text);

    return tokens.length == 1 &&
           EMAIL_ADDRESS_PATTERN.
               matcher(tokens[0].getAddress()).matches();
}
 
Example 44
Project: k-9-master   File: Address.java   Source Code and License 5 votes vote down vote up
/**
 * 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) {
    List<Address> addresses = new ArrayList<Address>();
    if (!StringUtils.isNullOrEmpty(addressList)) {
        Rfc822Token[] tokens = Rfc822Tokenizer.tokenize(addressList);
        for (Rfc822Token token : tokens) {
            String address = token.getAddress();
            if (!StringUtils.isNullOrEmpty(address)) {
                addresses.add(new Address(token.getAddress(), token.getName(), false));
            }
        }
    }
    return addresses.toArray(EMPTY_ADDRESS_ARRAY);
}
 
Example 45
Project: q-mail   File: EmailAddressValidator.java   Source Code and License 4 votes vote down vote up
public boolean isValid(CharSequence text) {
    return Rfc822Tokenizer.tokenize(text).length > 0;
}
 
Example 46
Project: talk-android   File: RecipientEditTextView.java   Source Code and License 4 votes vote down vote up
RecipientEntry createTokenizedEntry(final String token) {
    if (TextUtils.isEmpty(token)) {
        return null;
    }
    if (isPhoneQuery() && isPhoneNumber(token)) {
        return RecipientEntry.constructFakePhoneEntry(token, true);
    }
    Rfc822Token[] tokens = Rfc822Tokenizer.tokenize(token);
    String display = null;
    boolean isValid = isValid(token);
    if (isValid && tokens != null && tokens.length > 0) {
        // If we can get a name from tokenizing, then generate an entry from
        // this.
        display = tokens[0].getName();
        if (!TextUtils.isEmpty(display)) {
            return RecipientEntry.constructGeneratedEntry(display, tokens[0].getAddress(),
                    isValid);
        } else {
            display = tokens[0].getAddress();
            if (!TextUtils.isEmpty(display)) {
                return RecipientEntry.constructFakeEntry(display, isValid);
            }
        }
    }
    // Unable to validate the token or to create a valid token from it.
    // Just create a chip the user can edit.
    String validatedToken = null;
    if (mValidator != null && !isValid) {
        // Try fixing up the entry using the validator.
        validatedToken = mValidator.fixText(token).toString();
        if (!TextUtils.isEmpty(validatedToken)) {
            if (validatedToken.contains(token)) {
                // protect against the case of a validator with a null
                // domain,
                // which doesn't add a domain to the token
                Rfc822Token[] tokenized = Rfc822Tokenizer.tokenize(validatedToken);
                if (tokenized.length > 0) {
                    validatedToken = tokenized[0].getAddress();
                    isValid = true;
                }
            } else {
                // We ran into a case where the token was invalid and
                // removed
                // by the validator. In this case, just use the original
                // token
                // and let the user sort out the error chip.
                validatedToken = null;
                isValid = false;
            }
        }
    }
    // Otherwise, fallback to just creating an editable email address chip.
    return RecipientEntry.constructFakeEntry(
            !TextUtils.isEmpty(validatedToken) ? validatedToken : token, isValid);
}
 
Example 47
Project: talk-android   File: TextChipsEditView.java   Source Code and License 4 votes vote down vote up
RecipientEntry createTokenizedEntry(final String token) {
    if (TextUtils.isEmpty(token)) {
        return null;
    }
    if (isPhoneQuery() && isPhoneNumber(token)) {
        return RecipientEntry.constructFakePhoneEntry(token, true);
    }
    Rfc822Token[] tokens = Rfc822Tokenizer.tokenize(token);
    String display = null;
    boolean isValid = isValid(token);
    if (isValid && tokens != null && tokens.length > 0) {
        // If we can get a name from tokenizing, then generate an entry from
        // this.
        display = tokens[0].getName();
        if (!TextUtils.isEmpty(display)) {
            return RecipientEntry.constructGeneratedEntry(display, tokens[0].getAddress(),
                    isValid);
        } else {
            display = tokens[0].getAddress();
            if (!TextUtils.isEmpty(display)) {
                return RecipientEntry.constructFakeEntry(display, isValid);
            }
        }
    }
    // Unable to validate the token or to create a valid token from it.
    // Just create a chip the user can edit.
    String validatedToken = null;
    if (mValidator != null && !isValid) {
        // Try fixing up the entry using the validator.
        validatedToken = mValidator.fixText(token).toString();
        if (!TextUtils.isEmpty(validatedToken)) {
            if (validatedToken.contains(token)) {
                // protect against the case of a validator with a null
                // domain,
                // which doesn't add a domain to the token
                Rfc822Token[] tokenized = Rfc822Tokenizer.tokenize(validatedToken);
                if (tokenized.length > 0) {
                    validatedToken = tokenized[0].getAddress();
                    isValid = true;
                }
            } else {
                // We ran into a case where the token was invalid and
                // removed
                // by the validator. In this case, just use the original
                // token
                // and let the user sort out the error chip.
                validatedToken = null;
                isValid = false;
            }
        }
    }
    // Otherwise, fallback to just creating an editable email address chip.
    return RecipientEntry.constructFakeEntry(
            !TextUtils.isEmpty(validatedToken) ? validatedToken : token, isValid);
}
 
Example 48
Project: talk-android   File: DropdownChipLayouter.java   Source Code and License 4 votes vote down vote up
/**
 * Layouts and binds recipient information to the view. If convertView is null, inflates a new
 * view with getItemLaytout().
 *
 * @param convertView The view to bind information to.
 * @param parent The parent to bind the view to if we inflate a new view.
 * @param entry The recipient entry to get information from.
 * @param position The position in the list.
 * @param type The adapter type that is requesting the bind.
 * @param constraint The constraint typed in the auto complete view.
 *
 * @return A view ready to be shown in the drop down list.
 */
public View bindView(View convertView, ViewGroup parent, RecipientEntry entry, int position,
    AdapterType type, String constraint) {
    // Default to show all the information
    String displayName = entry.getDisplayName();
    String destination = entry.getDestination();
    boolean showImage = true;
    CharSequence destinationType = getDestinationType(entry);

    final View itemView = reuseOrInflateView(convertView, parent, type);

    final ViewHolder viewHolder = new ViewHolder(itemView);

    // Hide some information depending on the entry type and adapter type
    switch (type) {
        case BASE_RECIPIENT:
            if (TextUtils.isEmpty(displayName) || TextUtils.equals(displayName, destination)) {
                displayName = destination;

                // We only show the destination for secondary entries, so clear it only for the
                // first level.
                if (entry.isFirstLevel()) {
                    destination = null;
                }
            }

            if (!entry.isFirstLevel()) {
                displayName = null;
                showImage = false;
            }
            break;
        case RECIPIENT_ALTERNATES:
            if (position != 0) {
                displayName = null;
                showImage = false;
            }
            break;
        case SINGLE_RECIPIENT:
            destination = Rfc822Tokenizer.tokenize(entry.getDestination())[0].getAddress();
            destinationType = null;
    }

    if (displayName == null && !showImage) {
        viewHolder.destinationView.setPadding(mContext.getResources().getDimensionPixelSize(R.dimen.padding_no_picture), 0, 0, 0);
    } else {
        viewHolder.destinationView.setPadding(0, 0, 0, 0);
    }

    // Bind the information to the view
    bindTextToView(displayName, viewHolder.displayNameView);
    bindTextToView(destination, viewHolder.destinationView);
    bindTextToView("(" + destinationType + ")", viewHolder.destinationTypeView);
    bindIconToView(showImage, entry, viewHolder.imageView, type);

    return itemView;
}
 
Example 49
Project: K9-MailClient   File: EmailAddressValidator.java   Source Code and License 4 votes vote down vote up
public boolean isValid(CharSequence text) {
    return Rfc822Tokenizer.tokenize(text).length > 0;
}
 
Example 50
Project: daxSmail   File: EmailAddressValidator.java   Source Code and License 4 votes vote down vote up
public boolean isValid(CharSequence text) {
    return Rfc822Tokenizer.tokenize(text).length > 0;
}
 
Example 51
Project: j2objc   File: TextUtilsTest.java   Source Code and License 4 votes vote down vote up
@SmallTest
public void testRfc822FindTokenWithError() {
    assertEquals(9, new Rfc822Tokenizer().findTokenEnd("\"Foo Bar\\", 0));
}
 
Example 52
Project: sms_DualCard   File: RecipientEditTextView.java   Source Code and License 4 votes vote down vote up
private RecipientEntry createTokenizedEntry(String token) {
    if (TextUtils.isEmpty(token)) {
        return null;
    }
    Rfc822Token[] tokens = Rfc822Tokenizer.tokenize(token);
    String display = null;
    if (isPhoneQuery()) {
        // The number often arrives as "(800) 123-1231, ".
        // Trim the space and trailing comma if necessary.
        token = token.trim();
        char charAt = token.charAt(token.length() - 1);
        if (charAt == COMMIT_CHAR_COMMA || charAt == COMMIT_CHAR_SEMICOLON) {
            token = token.substring(0, token.length() - 1);
        }

        // look for something that looks like a phone number. At this point, the original
        // token might have looked like this: "Fred Flinstone <(800) 425-2323>"
        if (!isPhoneNumber(token) && isValid(token) && tokens != null && tokens.length > 0) {
            for (int i = 0; i < tokens.length; i++) {
                // If we can get a phone number from tokenizing, then generate an entry from
                // this.
                display = tokens[i].getName();
                if (!TextUtils.isEmpty(display) && isPhoneNumber(display)) {
                    return RecipientEntry.constructGeneratedEntry(display, display);
                } else {
                    display = tokens[i].getAddress();
                    if (!TextUtils.isEmpty(display) && isPhoneNumber(display)) {
                        return RecipientEntry.constructFakeEntry(display);
                    }
                }
            }
        }
        // If the original token is a phone number to start with or as a last resort, use the
        // original token.
        return RecipientEntry.constructFakeEntry(token);
    }
    if (isValid(token) && tokens != null && tokens.length > 0) {
        // If we can get a name from tokenizing, then generate an entry from
        // this.
        display = tokens[0].getName();
        if (!TextUtils.isEmpty(display)) {
            return RecipientEntry.constructGeneratedEntry(display, token);
        } else {
            display = tokens[0].getAddress();
            if (!TextUtils.isEmpty(display)) {
                return RecipientEntry.constructFakeEntry(display);
            }
        }
    }
    // Unable to validate the token or to create a valid token from it.
    // Just create a chip the user can edit.
    String validatedToken = null;
    if (mValidator != null && !mValidator.isValid(token)) {
        // Try fixing up the entry using the validator.
        validatedToken = mValidator.fixText(token).toString();
        if (!TextUtils.isEmpty(validatedToken)) {
            if (validatedToken.contains(token)) {
                // protect against the case of a validator with a null domain,
                // which doesn't add a domain to the token
                Rfc822Token[] tokenized = Rfc822Tokenizer.tokenize(validatedToken);
                if (tokenized.length > 0) {
                    validatedToken = tokenized[0].getAddress();
                }
            } else {
                // We ran into a case where the token was invalid and removed
                // by the validator. In this case, just use the original token
                // and let the user sort out the error chip.
                validatedToken = null;
            }
        }
    }
    // Otherwise, fallback to just creating an editable email address chip.
    return RecipientEntry
            .constructFakeEntry(!TextUtils.isEmpty(validatedToken) ? validatedToken : token);
}
 
Example 53
Project: sms_DualCard   File: RecipientAlternatesAdapter.java   Source Code and License 4 votes vote down vote up
/**
 * Get a HashMap of address to RecipientEntry that contains all contact
 * information for a contact with the provided address, if one exists. This
 * may block the UI, so run it in an async task.
 *
 * @param context Context.
 * @param inAddresses Array of addresses on which to perform the lookup.
 * @return HashMap<String,RecipientEntry>
 */
public static HashMap<String, RecipientEntry> getMatchingRecipients(Context context,
        ArrayList<String> inAddresses, int addressType) {
    Queries.Query query;
    if (addressType == QUERY_TYPE_EMAIL) {
        query = Queries.EMAIL;
    } else {
        query = Queries.PHONE;
    }
    int addressesSize = Math.min(MAX_LOOKUPS, inAddresses.size());
    String[] addresses = new String[addressesSize];
    StringBuilder bindString = new StringBuilder();
    // Create the "?" string and set up arguments.
    for (int i = 0; i < addressesSize; i++) {
        Rfc822Token[] tokens = Rfc822Tokenizer.tokenize(inAddresses.get(i).toLowerCase());
        addresses[i] = (tokens.length > 0 ? tokens[0].getAddress() : inAddresses.get(i));
        bindString.append("?");
        if (i < addressesSize - 1) {
            bindString.append(",");
        }
    }

    if (Log.isLoggable(TAG, Log.DEBUG)) {
        Log.d(TAG, "Doing reverse lookup for " + addresses.toString());
    }

    HashMap<String, RecipientEntry> recipientEntries = new HashMap<String, RecipientEntry>();
    Cursor c = context.getContentResolver().query(
            query.getContentUri(),
            query.getProjection(),
            query.getProjection()[Queries.Query.DESTINATION] + " IN (" + bindString.toString()
                    + ")", addresses, null);

    if (c != null) {
        try {
            if (c.moveToFirst()) {
                do {
                    String address = c.getString(Queries.Query.DESTINATION);
                    recipientEntries.put(address, RecipientEntry.constructTopLevelEntry(
                            c.getString(Queries.Query.NAME),
                            c.getInt(Queries.Query.DISPLAY_NAME_SOURCE),
                            c.getString(Queries.Query.DESTINATION),
                            c.getInt(Queries.Query.DESTINATION_TYPE),
                            c.getString(Queries.Query.DESTINATION_LABEL),
                            c.getLong(Queries.Query.CONTACT_ID),
                            c.getLong(Queries.Query.DATA_ID),
                            c.getString(Queries.Query.PHOTO_THUMBNAIL_URI)));
                    if (Log.isLoggable(TAG, Log.DEBUG)) {
                        Log.d(TAG, "Received reverse look up information for " + address
                                + " RESULTS: "
                                + " NAME : " + c.getString(Queries.Query.NAME)
                                + " CONTACT ID : " + c.getLong(Queries.Query.CONTACT_ID)
                                + " ADDRESS :" + c.getString(Queries.Query.DESTINATION));
                    }
                } while (c.moveToNext());
            }
        } finally {
            c.close();
        }
    }
    return recipientEntries;
}
 
Example 54
Project: k-9   File: EmailAddressValidator.java   Source Code and License 4 votes vote down vote up
public boolean isValid(CharSequence text) {
    return Rfc822Tokenizer.tokenize(text).length > 0;
}
 
Example 55
Project: ChipsLibrary   File: RecipientEditTextView.java   Source Code and License 4 votes vote down vote up
RecipientEntry createTokenizedEntry(final String token)
{
if(TextUtils.isEmpty(token))
  return null;
if(isPhoneQuery()&&isPhoneNumber(token))
  return RecipientEntry.constructFakePhoneEntry(token,true);
final Rfc822Token[] tokens=Rfc822Tokenizer.tokenize(token);
String display=null;
boolean isValid=isValid(token);
if(isValid&&tokens!=null&&tokens.length>0)
  {
  // If we can get a name from tokenizing, then generate an entry from
  // this.
  display=tokens[0].getName();
  if(!TextUtils.isEmpty(display))
    return RecipientEntry.constructGeneratedEntry(display,tokens[0].getAddress(),isValid);
  else
    {
    display=tokens[0].getAddress();
    if(!TextUtils.isEmpty(display))
      return RecipientEntry.constructFakeEntry(display,isValid);
    }
  }
// Unable to validate the token or to create a valid token from it.
// Just create a chip the user can edit.
String validatedToken=null;
if(mValidator!=null&&!isValid)
  {
  // Try fixing up the entry using the validator.
  validatedToken=mValidator.fixText(token).toString();
  if(!TextUtils.isEmpty(validatedToken))
    if(validatedToken.contains(token))
      {
      // protect against the case of a validator with a null
      // domain,
      // which doesn't add a domain to the token
      final Rfc822Token[] tokenized=Rfc822Tokenizer.tokenize(validatedToken);
      if(tokenized.length>0)
        {
        validatedToken=tokenized[0].getAddress();
        isValid=true;
        }
      }
    else
      {
      // We ran into a case where the token was invalid and
      // removed
      // by the validator. In this case, just use the original
      // token
      // and let the user sort out the error chip.
      validatedToken=null;
      isValid=false;
      }
  }
// Otherwise, fallback to just creating an editable email address chip.
return RecipientEntry.constructFakeEntry(!TextUtils.isEmpty(validatedToken) ? validatedToken : token,isValid);
}
 
Example 56
Project: Calendar_lunar   File: RecipientEditTextView.java   Source Code and License 4 votes vote down vote up
private RecipientEntry createTokenizedEntry(String token) {
    if (TextUtils.isEmpty(token)) {
        return null;
    }
    Rfc822Token[] tokens = Rfc822Tokenizer.tokenize(token);
    String display = null;
    if (isPhoneQuery()) {
        // The number often arrives as "(800) 123-1231, ".
        // Trim the space and trailing comma if necessary.
        token = token.trim();
        char charAt = token.charAt(token.length() - 1);
        if (charAt == COMMIT_CHAR_COMMA || charAt == COMMIT_CHAR_SEMICOLON) {
            token = token.substring(0, token.length() - 1);
        }

        // look for something that looks like a phone number. At this point, the original
        // token might have looked like this: "Fred Flinstone <(800) 425-2323>"
        if (!isPhoneNumber(token) && isValid(token) && tokens != null && tokens.length > 0) {
            for (int i = 0; i < tokens.length; i++) {
                // If we can get a phone number from tokenizing, then generate an entry from
                // this.
                display = tokens[i].getName();
                if (!TextUtils.isEmpty(display) && isPhoneNumber(display)) {
                    return RecipientEntry.constructGeneratedEntry(display, display);
                } else {
                    display = tokens[i].getAddress();
                    if (!TextUtils.isEmpty(display) && isPhoneNumber(display)) {
                        return RecipientEntry.constructFakeEntry(display);
                    }
                }
            }
        }
        // If the original token is a phone number to start with or as a last resort, use the
        // original token.
        return RecipientEntry.constructFakeEntry(token);
    }
    if (isValid(token) && tokens != null && tokens.length > 0) {
        // If we can get a name from tokenizing, then generate an entry from
        // this.
        display = tokens[0].getName();
        if (!TextUtils.isEmpty(display)) {
            return RecipientEntry.constructGeneratedEntry(display, token);
        } else {
            display = tokens[0].getAddress();
            if (!TextUtils.isEmpty(display)) {
                return RecipientEntry.constructFakeEntry(display);
            }
        }
    }
    // Unable to validate the token or to create a valid token from it.
    // Just create a chip the user can edit.
    String validatedToken = null;
    if (mValidator != null && !mValidator.isValid(token)) {
        // Try fixing up the entry using the validator.
        validatedToken = mValidator.fixText(token).toString();
        if (!TextUtils.isEmpty(validatedToken)) {
            if (validatedToken.contains(token)) {
                // protect against the case of a validator with a null domain,
                // which doesn't add a domain to the token
                Rfc822Token[] tokenized = Rfc822Tokenizer.tokenize(validatedToken);
                if (tokenized.length > 0) {
                    validatedToken = tokenized[0].getAddress();
                }
            } else {
                // We ran into a case where the token was invalid and removed
                // by the validator. In this case, just use the original token
                // and let the user sort out the error chip.
                validatedToken = null;
            }
        }
    }
    // Otherwise, fallback to just creating an editable email address chip.
    return RecipientEntry
            .constructFakeEntry(!TextUtils.isEmpty(validatedToken) ? validatedToken : token);
}
 
Example 57
Project: Calendar_lunar   File: RecipientAlternatesAdapter.java   Source Code and License 4 votes vote down vote up
/**
 * Get a HashMap of address to RecipientEntry that contains all contact
 * information for a contact with the provided address, if one exists. This
 * may block the UI, so run it in an async task.
 *
 * @param context Context.
 * @param inAddresses Array of addresses on which to perform the lookup.
 * @return HashMap<String,RecipientEntry>
 */
public static HashMap<String, RecipientEntry> getMatchingRecipients(Context context,
        ArrayList<String> inAddresses, int addressType) {
    Queries.Query query;
    if (addressType == QUERY_TYPE_EMAIL) {
        query = Queries.EMAIL;
    } else {
        query = Queries.PHONE;
    }
    int addressesSize = Math.min(MAX_LOOKUPS, inAddresses.size());
    String[] addresses = new String[addressesSize];
    StringBuilder bindString = new StringBuilder();
    // Create the "?" string and set up arguments.
    for (int i = 0; i < addressesSize; i++) {
        Rfc822Token[] tokens = Rfc822Tokenizer.tokenize(inAddresses.get(i).toLowerCase());
        addresses[i] = (tokens.length > 0 ? tokens[0].getAddress() : inAddresses.get(i));
        bindString.append("?");
        if (i < addressesSize - 1) {
            bindString.append(",");
        }
    }

    if (Log.isLoggable(TAG, Log.DEBUG)) {
        Log.d(TAG, "Doing reverse lookup for " + addresses.toString());
    }

    HashMap<String, RecipientEntry> recipientEntries = new HashMap<String, RecipientEntry>();
    Cursor c = context.getContentResolver().query(
            query.getContentUri(),
            query.getProjection(),
            query.getProjection()[Queries.Query.DESTINATION] + " IN (" + bindString.toString()
                    + ")", addresses, null);

    if (c != null) {
        try {
            if (c.moveToFirst()) {
                do {
                    String address = c.getString(Queries.Query.DESTINATION);
                    recipientEntries.put(address, RecipientEntry.constructTopLevelEntry(
                            c.getString(Queries.Query.NAME),
                            c.getInt(Queries.Query.DISPLAY_NAME_SOURCE),
                            c.getString(Queries.Query.DESTINATION),
                            c.getInt(Queries.Query.DESTINATION_TYPE),
                            c.getString(Queries.Query.DESTINATION_LABEL),
                            c.getLong(Queries.Query.CONTACT_ID),
                            c.getLong(Queries.Query.DATA_ID),
                            c.getString(Queries.Query.PHOTO_THUMBNAIL_URI)));
                    if (Log.isLoggable(TAG, Log.DEBUG)) {
                        Log.d(TAG, "Received reverse look up information for " + address
                                + " RESULTS: "
                                + " NAME : " + c.getString(Queries.Query.NAME)
                                + " CONTACT ID : " + c.getLong(Queries.Query.CONTACT_ID)
                                + " ADDRESS :" + c.getString(Queries.Query.DESTINATION));
                    }
                } while (c.moveToNext());
            }
        } finally {
            c.close();
        }
    }
    return recipientEntries;
}
 
Example 58
Project: Calendar_lunar   File: Rfc822Validator.java   Source Code and License 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
public CharSequence fixText(CharSequence cs) {
    // Return an empty string if the email address only contains spaces, \n or \t
    if (TextUtils.getTrimmedLength(cs) == 0) return "";

    Rfc822Token[] tokens = Rfc822Tokenizer.tokenize(cs);
    StringBuilder sb = new StringBuilder();

    for (int i = 0; i < tokens.length; i++) {
        String text = tokens[i].getAddress();

        if (mRemoveInvalid && !isValid(text)) {
            continue;
        }
        int index = text.indexOf('@');
        if (index < 0) {
            // append the domain of the account if it exists
            if (mDomain != null) {
                tokens[i].setAddress(removeIllegalCharacters(text) + "@" + mDomain);
            }
        } else {
            // Otherwise, remove the illegal characters on both sides of the '@'
            String fix = removeIllegalCharacters(text.substring(0, index));
            if (TextUtils.isEmpty(fix)) {
                // if the address is empty after removing invalid chars
                // don't use it
                continue;
            }
            String domain = removeIllegalCharacters(text.substring(index + 1));
            boolean emptyDomain = domain.length() == 0;
            if (!emptyDomain || mDomain != null) {
                tokens[i].setAddress(fix + "@" + (!emptyDomain ? domain : mDomain));
            }
        }

        sb.append(tokens[i].toString());
        if (i + 1 < tokens.length) {
            sb.append(", ");
        }
    }

    return sb;
}
 
Example 59
Project: k-9-master   File: EmailAddressValidator.java   Source Code and License 4 votes vote down vote up
public boolean isValid(CharSequence text) {
    return Rfc822Tokenizer.tokenize(text).length > 0;
}