Source:
private void fillContactDataFromCursor(Cursor cursor, List<Recipient> recipients, Map<String, Recipient> recipientMap, @Nullable String prefilledName) { while (cursor.moveToNext()) { String name = prefilledName != null ? prefilledName : cursor.getString(INDEX_NAME); String email = cursor.getString(INDEX_EMAIL); long contactId = cursor.getLong(INDEX_CONTACT_ID); String lookupKey = cursor.getString(INDEX_LOOKUP_KEY); if (recipientMap.containsKey(email)) { continue; } int addressType = cursor.getInt(INDEX_EMAIL_TYPE); String addressLabel = null; switch (addressType) { case ContactsContract.CommonDataKinds.Email.TYPE_HOME: { addressLabel = getContext().getString(R.string.address_type_home); break; } case ContactsContract.CommonDataKinds.Email.TYPE_WORK: { addressLabel = getContext().getString(R.string.address_type_work); break; } case ContactsContract.CommonDataKinds.Email.TYPE_OTHER: { addressLabel = getContext().getString(R.string.address_type_other); break; } case ContactsContract.CommonDataKinds.Email.TYPE_MOBILE: { addressLabel = getContext().getString(R.string.address_type_mobile); break; } case ContactsContract.CommonDataKinds.Email.TYPE_CUSTOM: { addressLabel = cursor.getString(INDEX_EMAIL_CUSTOM_LABEL); break; } } if (email != null) { Recipient recipient = new Recipient(name, email, addressLabel, contactId, lookupKey); if (recipient.isValidEmailAddress()) { Uri photoUri = cursor.isNull(INDEX_PHOTO_URI) ? null : Uri.parse(cursor.getString(INDEX_PHOTO_URI)); recipient.photoThumbnailUri = photoUri; recipientMap.put(email, recipient); recipients.add(recipient); } } } cursor.close(); }

Target:
private void fillContactDataFromCursor(Cursor cursor, List<Recipient> recipients, Map<String, Recipient> recipientMap, @Nullable String prefilledName) { while (cursor.moveToNext()) { String name = prefilledName != null ? prefilledName : cursor.getString(INDEX_NAME); String email = cursor.getString(INDEX_EMAIL); long contactId = cursor.getLong(INDEX_CONTACT_ID); String lookupKey = cursor.getString(INDEX_LOOKUP_KEY); if (email == null || recipientMap.containsKey(email)) { continue; } int addressType = cursor.getInt(INDEX_EMAIL_TYPE); String addressLabel = null; switch (addressType) { case ContactsContract.CommonDataKinds.Email.TYPE_HOME: { addressLabel = getContext().getString(R.string.address_type_home); break; } case ContactsContract.CommonDataKinds.Email.TYPE_WORK: { addressLabel = getContext().getString(R.string.address_type_work); break; } case ContactsContract.CommonDataKinds.Email.TYPE_OTHER: { addressLabel = getContext().getString(R.string.address_type_other); break; } case ContactsContract.CommonDataKinds.Email.TYPE_MOBILE: { addressLabel = getContext().getString(R.string.address_type_mobile); break; } case ContactsContract.CommonDataKinds.Email.TYPE_CUSTOM: { addressLabel = cursor.getString(INDEX_EMAIL_CUSTOM_LABEL); break; } } Recipient recipient = new Recipient(name, email, addressLabel, contactId, lookupKey); if (recipient.isValidEmailAddress()) { Uri photoUri = cursor.isNull(INDEX_PHOTO_URI) ? null : Uri.parse(cursor.getString(INDEX_PHOTO_URI)); recipient.photoThumbnailUri = photoUri; recipientMap.put(email, recipient); recipients.add(recipient); } } cursor.close(); }