MCPcopy Create free account
hub / github.com/M66B/FairEmail / _get

Method _get

app/src/main/java/eu/faircode/email/ContactInfo.java:260–661  ·  view source on GitHub ↗
(
            Context context,
            long account, String folderType,
            String selector, boolean dmarc, InternetAddress address, boolean cacheOnly)

Source from the content-addressed store, hash-verified

258 }
259
260 private static ContactInfo _get(
261 Context context,
262 long account, String folderType,
263 String selector, boolean dmarc, InternetAddress address, boolean cacheOnly) {
264 String key = MessageHelper.formatAddresses(new Address[]{address});
265 synchronized (emailContactInfo) {
266 ContactInfo info = emailContactInfo.get(key);
267 if (info != null && !info.isExpired())
268 return info;
269 }
270
271 if (cacheOnly)
272 return null;
273
274 boolean cached = false;
275 ContactInfo info = new ContactInfo();
276 info.email = address.getAddress();
277
278 final String ekey = (TextUtils.isEmpty(info.email) ? null : getKey(info.email));
279
280 SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
281 boolean favicons_dmarc = prefs.getBoolean("favicons_dmarc", false);
282 boolean avatars = prefs.getBoolean("avatars", true);
283 boolean prefer_contact = prefs.getBoolean("prefer_contact", false);
284 boolean distinguish_contacts = prefs.getBoolean("distinguish_contacts", false);
285 boolean bimi = (prefs.getBoolean("bimi", false) && (!favicons_dmarc || dmarc) && !BuildConfig.PLAY_STORE_RELEASE);
286 boolean gravatars = (prefs.getBoolean("gravatars", false) && (!favicons_dmarc || dmarc) && !BuildConfig.PLAY_STORE_RELEASE);
287 boolean libravatars = (prefs.getBoolean("libravatars", false) && (!favicons_dmarc || dmarc) && !BuildConfig.PLAY_STORE_RELEASE);
288 boolean favicons = (prefs.getBoolean("favicons", false) && (!favicons_dmarc || dmarc));
289 boolean ddg_icons = (prefs.getBoolean("ddg_icons", false) && (!favicons_dmarc || dmarc) && !BuildConfig.PLAY_STORE_RELEASE);
290 String favicon_uri = prefs.getString("favicon_uri", null);
291 boolean generated = prefs.getBoolean("generated_icons", true);
292 boolean identicons = prefs.getBoolean("identicons", false);
293 boolean circular = prefs.getBoolean("circular", true);
294
295 // Contact photo
296 if (!TextUtils.isEmpty(info.email) &&
297 (avatars || prefer_contact || distinguish_contacts) &&
298 Helper.hasPermission(context, Manifest.permission.READ_CONTACTS)) {
299 File dir = Helper.ensureExists(context, "notcontact");
300 File file = new File(dir, ekey);
301 if (file.exists()) {
302 file.setLastModified(new Date().getTime());
303 Log.i("Contact negative cache key=" + ekey);
304 } else {
305 ContentResolver resolver = context.getContentResolver();
306 Uri uri = Uri.withAppendedPath(
307 ContactsContract.CommonDataKinds.Email.CONTENT_LOOKUP_URI,
308 Uri.encode(info.email.toLowerCase(Locale.ROOT)));
309 try (Cursor cursor = resolver.query(uri,
310 new String[]{
311 ContactsContract.CommonDataKinds.Photo.CONTACT_ID,
312 ContactsContract.Contacts.LOOKUP_KEY,
313 ContactsContract.Contacts.DISPLAY_NAME
314 },
315 null, null, ContactsContract.Contacts.DISPLAY_NAME)) {
316
317 if (cursor != null && cursor.moveToNext()) {

Callers 1

getMethod · 0.95

Calls 15

formatAddressesMethod · 0.95
isExpiredMethod · 0.95
getKeyMethod · 0.95
hasPermissionMethod · 0.95
ensureExistsMethod · 0.95
iMethod · 0.95
dp2pixelsMethod · 0.95
getScaledBitmapMethod · 0.95
eMethod · 0.95
getEmailDomainMethod · 0.95
getExtensionMethod · 0.95

Tested by

no test coverage detected