FairEmail/app/src/main/java/eu/faircode/email/ContactInfo.java

1065 lines
43 KiB
Java
Raw Normal View History

2019-01-19 13:21:21 +00:00
package eu.faircode.email;
2019-05-04 20:49:22 +00:00
/*
This file is part of FairEmail.
FairEmail is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
FairEmail is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FairEmail. If not, see <http://www.gnu.org/licenses/>.
2022-01-01 08:46:36 +00:00
Copyright 2018-2022 by Marcel Bokhorst (M66B)
2019-05-04 20:49:22 +00:00
*/
2019-01-19 13:21:21 +00:00
import android.Manifest;
import android.content.ContentResolver;
import android.content.Context;
2019-01-26 09:58:37 +00:00
import android.content.SharedPreferences;
2019-05-06 17:19:37 +00:00
import android.database.ContentObserver;
2019-01-19 13:21:21 +00:00
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
2020-07-28 15:18:13 +00:00
import android.graphics.Canvas;
import android.graphics.Color;
2020-07-01 09:05:18 +00:00
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
2019-01-19 13:21:21 +00:00
import android.net.Uri;
import android.provider.ContactsContract;
2020-05-06 20:30:47 +00:00
import android.text.TextUtils;
2021-07-16 06:14:05 +00:00
import android.util.Pair;
2019-01-19 13:21:21 +00:00
2020-02-09 11:14:11 +00:00
import androidx.annotation.NonNull;
import androidx.preference.PreferenceManager;
2021-06-27 10:02:05 +00:00
import org.json.JSONArray;
import org.json.JSONObject;
2020-06-30 09:19:17 +00:00
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
2020-12-11 08:21:01 +00:00
import org.jsoup.select.Elements;
2020-06-30 09:19:17 +00:00
import java.io.BufferedOutputStream;
2022-04-24 07:32:55 +00:00
import java.io.EOFException;
2020-06-30 09:19:17 +00:00
import java.io.File;
2020-06-30 12:04:50 +00:00
import java.io.FileNotFoundException;
2020-06-30 09:19:17 +00:00
import java.io.FileOutputStream;
2021-07-16 13:05:54 +00:00
import java.io.FilenameFilter;
2020-01-17 15:59:29 +00:00
import java.io.IOException;
2019-01-19 13:21:21 +00:00
import java.io.InputStream;
2020-06-30 09:19:17 +00:00
import java.io.OutputStream;
2020-05-06 20:30:47 +00:00
import java.io.UnsupportedEncodingException;
2020-06-30 12:04:50 +00:00
import java.net.ConnectException;
2020-01-17 15:59:29 +00:00
import java.net.HttpURLConnection;
2020-07-01 09:05:18 +00:00
import java.net.SocketTimeoutException;
2020-01-17 15:59:29 +00:00
import java.net.URL;
2020-06-30 12:04:50 +00:00
import java.net.UnknownHostException;
2020-05-06 20:30:47 +00:00
import java.nio.charset.StandardCharsets;
2020-07-01 12:28:13 +00:00
import java.security.cert.CertPathValidatorException;
2020-06-30 12:04:50 +00:00
import java.security.cert.CertificateException;
2020-07-01 08:49:09 +00:00
import java.util.ArrayList;
2021-04-25 09:27:34 +00:00
import java.util.Arrays;
2020-12-11 09:06:48 +00:00
import java.util.Collections;
import java.util.Comparator;
2019-01-25 13:13:58 +00:00
import java.util.Date;
import java.util.HashMap;
2020-07-01 08:49:09 +00:00
import java.util.List;
2020-02-15 14:53:11 +00:00
import java.util.Locale;
2019-01-25 13:13:58 +00:00
import java.util.Map;
2020-07-01 08:49:09 +00:00
import java.util.concurrent.Callable;
2019-05-06 17:19:37 +00:00
import java.util.concurrent.ConcurrentHashMap;
2020-07-01 08:49:09 +00:00
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
2019-01-19 13:21:21 +00:00
import javax.mail.Address;
import javax.mail.internet.InternetAddress;
2020-06-30 09:19:17 +00:00
import javax.net.ssl.HttpsURLConnection;
2020-06-30 12:04:50 +00:00
import javax.net.ssl.SSLException;
import javax.net.ssl.SSLHandshakeException;
import javax.net.ssl.SSLPeerUnverifiedException;
import javax.net.ssl.SSLProtocolException;
2019-01-19 13:21:21 +00:00
public class ContactInfo {
2019-01-26 09:58:37 +00:00
private String email;
private Bitmap bitmap;
2022-04-26 08:48:16 +00:00
private String type; // contact, vmc, favicon, identicon, letter, unknown
2021-07-13 08:37:02 +00:00
private boolean verified;
2019-01-19 13:21:21 +00:00
private String displayName;
private Uri lookupUri;
2019-10-02 11:36:07 +00:00
private boolean known;
2019-01-25 13:13:58 +00:00
private long time;
2022-04-27 13:01:16 +00:00
static final int FAVICON_READ_BYTES = 50 * 1024;
2020-05-06 20:30:47 +00:00
private static Map<String, Lookup> emailLookup = new ConcurrentHashMap<>();
2019-10-02 11:36:07 +00:00
private static final Map<String, ContactInfo> emailContactInfo = new HashMap<>();
2020-06-30 09:19:17 +00:00
2022-04-09 17:55:43 +00:00
private static final int GENERATED_ICON_SIZE = 48; // dp
2020-12-11 09:06:48 +00:00
private static final int FAVICON_ICON_SIZE = 64; // dp
2020-06-30 12:04:50 +00:00
private static final int FAVICON_CONNECT_TIMEOUT = 5 * 1000; // milliseconds
private static final int FAVICON_READ_TIMEOUT = 10 * 1000; // milliseconds
2020-01-21 10:12:28 +00:00
private static final long CACHE_CONTACT_DURATION = 2 * 60 * 1000L; // milliseconds
2020-10-19 10:47:51 +00:00
private static final long CACHE_FAVICON_DURATION = 2 * 7 * 24 * 60 * 60 * 1000L; // milliseconds
2022-02-18 12:40:32 +00:00
private static final float MIN_FAVICON_LUMINANCE = 0.2f;
2019-01-19 13:21:21 +00:00
2022-08-12 15:48:20 +00:00
// https://realfavicongenerator.net/faq
private static final String[] FIXED_FAVICONS = new String[]{
"apple-touch-icon.png", // 57x57
"apple-touch-icon-precomposed.png", // 57x57
"favicon.ico"
};
2021-05-24 06:35:09 +00:00
// https://css-tricks.com/prefetching-preloading-prebrowsing/
// https://developer.mozilla.org/en-US/docs/Web/Performance/dns-prefetch
2021-05-24 05:45:57 +00:00
private static final List<String> REL_EXCLUDE = Collections.unmodifiableList(Arrays.asList(
2021-06-16 18:23:16 +00:00
"dns-prefetch", "preconnect", "prefetch", "preload", "prerender", "subresource",
"respond-redirect"
2021-05-24 05:45:57 +00:00
));
2019-01-26 09:58:37 +00:00
private ContactInfo() {
2019-01-19 13:21:21 +00:00
}
2021-07-16 13:05:54 +00:00
String getType() {
return type;
}
boolean isEmailBased() {
return ("gravatar".equals(type) || "libravatar".equals(type));
}
2021-07-13 08:37:02 +00:00
boolean isVerified() {
return (bitmap != null && verified);
}
2019-01-26 09:58:37 +00:00
boolean hasPhoto() {
return (bitmap != null);
2019-01-19 13:21:21 +00:00
}
Bitmap getPhotoBitmap() {
2019-01-26 09:58:37 +00:00
return bitmap;
2019-01-19 13:21:21 +00:00
}
String getEmailAddress() {
return email;
}
2019-12-19 20:37:09 +00:00
String getDisplayName() {
return displayName;
}
2019-01-26 09:58:37 +00:00
boolean hasLookupUri() {
return (lookupUri != null);
2019-01-19 13:21:21 +00:00
}
Uri getLookupUri() {
return lookupUri;
}
2019-10-02 11:36:07 +00:00
boolean isKnown() {
return known;
}
2019-01-25 13:13:58 +00:00
private boolean isExpired() {
2019-03-31 07:09:32 +00:00
return (new Date().getTime() - time > CACHE_CONTACT_DURATION);
2019-01-25 13:13:58 +00:00
}
2020-10-19 10:47:51 +00:00
static void cleanup(Context context) {
long now = new Date().getTime();
// Favicons
2022-08-18 05:42:15 +00:00
Log.i("Cleanup avatars");
for (String type : new String[]{"favicons", "generated"}) {
File[] favicons = new File(context.getFilesDir(), type).listFiles();
if (favicons != null)
for (File file : favicons)
if (file.lastModified() + CACHE_FAVICON_DURATION < now) {
Log.i("Deleting " + file);
if (!file.delete())
Log.w("Error deleting " + file);
}
}
2020-10-19 10:47:51 +00:00
}
2020-06-30 10:51:16 +00:00
static void clearCache(Context context) {
2020-09-27 08:42:12 +00:00
clearCache(context, true);
}
static void clearCache(Context context, boolean files) {
2019-01-26 09:58:37 +00:00
synchronized (emailContactInfo) {
emailContactInfo.clear();
}
2020-06-30 10:51:16 +00:00
2020-09-27 08:42:12 +00:00
if (!files)
return;
2020-06-30 10:51:16 +00:00
2022-08-18 05:42:15 +00:00
for (String type : new String[]{"favicons", "generated"}) {
final File dir = new File(context.getFilesDir(), type);
2022-12-13 09:52:39 +00:00
Helper.getParallelExecutor().submit(new Runnable() {
2022-08-18 05:42:15 +00:00
@Override
public void run() {
try {
File[] favicons = dir.listFiles();
if (favicons != null)
for (File favicon : favicons)
favicon.delete();
} catch (Throwable ex) {
Log.w(ex);
}
2020-06-30 10:51:16 +00:00
}
2022-08-18 05:42:15 +00:00
});
}
2019-01-26 09:58:37 +00:00
}
2019-01-19 13:21:21 +00:00
2020-02-09 11:14:11 +00:00
@NonNull
2021-07-16 18:03:27 +00:00
static ContactInfo[] get(Context context, long account, String folderType, String selector, Address[] addresses) {
return get(context, account, folderType, selector, addresses, false);
2020-02-09 11:14:11 +00:00
}
2021-07-16 18:03:27 +00:00
static ContactInfo[] getCached(Context context, long account, String folderType, String selector, Address[] addresses) {
return get(context, account, folderType, selector, addresses, true);
2020-02-09 11:14:11 +00:00
}
2021-07-16 18:03:27 +00:00
private static ContactInfo[] get(Context context, long account, String folderType, String selector, Address[] addresses, boolean cacheOnly) {
2019-01-26 09:58:37 +00:00
if (addresses == null || addresses.length == 0)
2020-02-09 11:14:11 +00:00
return new ContactInfo[]{new ContactInfo()};
ContactInfo[] result = new ContactInfo[addresses.length];
for (int i = 0; i < addresses.length; i++) {
2021-07-16 18:03:27 +00:00
result[i] = _get(context, account, folderType, selector, (InternetAddress) addresses[i], cacheOnly);
2020-02-09 11:14:11 +00:00
if (result[i] == null)
return null;
}
return result;
}
2019-01-25 13:13:58 +00:00
2021-07-16 18:03:27 +00:00
private static ContactInfo _get(
Context context,
long account, String folderType,
String selector, InternetAddress address, boolean cacheOnly) {
2019-10-14 10:22:07 +00:00
String key = MessageHelper.formatAddresses(new Address[]{address});
2019-01-25 13:13:58 +00:00
synchronized (emailContactInfo) {
2019-01-30 08:06:10 +00:00
ContactInfo info = emailContactInfo.get(key);
2019-01-25 13:13:58 +00:00
if (info != null && !info.isExpired())
return info;
}
2019-01-26 09:58:37 +00:00
if (cacheOnly)
2019-01-25 13:13:58 +00:00
return null;
2019-01-26 09:58:37 +00:00
ContactInfo info = new ContactInfo();
2019-01-30 08:06:10 +00:00
info.email = address.getAddress();
2019-01-26 09:58:37 +00:00
// Maximum file name length: 255
// Maximum email address length: 320 (<local part = 64> @ <domain part = 255>)
final String ekey;
if (TextUtils.isEmpty(info.email))
ekey = null;
else
ekey = (info.email.length() > 255
? info.email.substring(0, 255)
: info.email).toLowerCase(Locale.ROOT);
2019-01-26 09:58:37 +00:00
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
2020-03-23 06:42:31 +00:00
boolean avatars = prefs.getBoolean("avatars", true);
2022-07-31 05:36:20 +00:00
boolean prefer_contact = prefs.getBoolean("prefer_contact", false);
boolean distinguish_contacts = prefs.getBoolean("distinguish_contacts", false);
2022-12-30 09:30:30 +00:00
boolean bimi = (prefs.getBoolean("bimi", false) && !BuildConfig.PLAY_STORE_RELEASE);
boolean gravatars = (prefs.getBoolean("gravatars", false) && !BuildConfig.PLAY_STORE_RELEASE);
boolean libravatars = (prefs.getBoolean("libravatars", false) && !BuildConfig.PLAY_STORE_RELEASE);
boolean favicons = prefs.getBoolean("favicons", false);
2020-03-23 06:42:31 +00:00
boolean generated = prefs.getBoolean("generated_icons", true);
boolean identicons = prefs.getBoolean("identicons", false);
boolean circular = prefs.getBoolean("circular", true);
2019-01-26 09:58:37 +00:00
2020-06-30 09:19:17 +00:00
// Contact photo
2020-06-25 12:32:04 +00:00
if (!TextUtils.isEmpty(info.email) &&
2022-07-31 05:36:20 +00:00
(avatars || prefer_contact || distinguish_contacts) &&
2020-06-25 12:32:04 +00:00
Helper.hasPermission(context, Manifest.permission.READ_CONTACTS)) {
2019-07-23 16:51:03 +00:00
ContentResolver resolver = context.getContentResolver();
2019-10-23 07:35:55 +00:00
Uri uri = Uri.withAppendedPath(
ContactsContract.CommonDataKinds.Email.CONTENT_LOOKUP_URI,
2020-06-25 12:32:04 +00:00
Uri.encode(info.email.toLowerCase(Locale.ROOT)));
2019-10-23 07:35:55 +00:00
try (Cursor cursor = resolver.query(uri,
2019-07-23 16:51:03 +00:00
new String[]{
ContactsContract.CommonDataKinds.Photo.CONTACT_ID,
ContactsContract.Contacts.LOOKUP_KEY,
ContactsContract.Contacts.DISPLAY_NAME
},
2019-10-23 07:35:55 +00:00
null, null, null)) {
2019-07-23 16:51:03 +00:00
if (cursor != null && cursor.moveToNext()) {
int colContactId = cursor.getColumnIndex(ContactsContract.CommonDataKinds.Photo.CONTACT_ID);
int colLookupKey = cursor.getColumnIndex(ContactsContract.Contacts.LOOKUP_KEY);
int colDisplayName = cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME);
long contactId = cursor.getLong(colContactId);
String lookupKey = cursor.getString(colLookupKey);
Uri lookupUri = ContactsContract.Contacts.getLookupUri(contactId, lookupKey);
2020-04-15 16:01:45 +00:00
if (avatars)
try (InputStream is = ContactsContract.Contacts.openContactPhotoInputStream(
resolver, lookupUri, false)) {
info.bitmap = BitmapFactory.decodeStream(is);
2021-07-16 13:05:54 +00:00
info.type = "contact";
2020-04-15 16:01:45 +00:00
} catch (Throwable ex) {
Log.e(ex);
}
2019-07-23 16:51:03 +00:00
info.displayName = cursor.getString(colDisplayName);
info.lookupUri = lookupUri;
2019-10-02 11:36:07 +00:00
info.known = true;
2019-01-19 13:21:21 +00:00
}
2019-01-26 09:58:37 +00:00
} catch (Throwable ex) {
Log.e(ex);
}
2019-07-23 16:51:03 +00:00
}
2019-01-26 09:58:37 +00:00
2020-06-30 09:19:17 +00:00
// Favicon
2021-07-16 13:05:54 +00:00
if (info.bitmap == null &&
2022-07-31 05:36:20 +00:00
(bimi || gravatars || libravatars || favicons) &&
!EntityFolder.JUNK.equals(folderType)) {
2021-07-16 13:05:54 +00:00
String d = UriHelper.getEmailDomain(info.email);
if (d != null) {
2021-07-13 19:23:05 +00:00
// Prevent using Doodles
2021-07-16 13:05:54 +00:00
if ("google.com".equals(d) ||
"gmail.com".equals(d) ||
"googlemail.com".equals(d))
d = "support.google.com";
2020-06-30 10:35:38 +00:00
2022-03-14 06:55:51 +00:00
// https://yahoo.fr/co.uk redirects unsafely to http://fr.yahoo.com/favicon.ico
for (String yahoo : d.split("\\."))
if ("yahoo".equals(yahoo)) {
d = "yahoo.com";
break;
}
2021-07-16 13:05:54 +00:00
final String domain = d.toLowerCase(Locale.ROOT);
2021-07-13 19:23:05 +00:00
2022-10-06 12:43:44 +00:00
File dir = Helper.ensureExists(new File(context.getFilesDir(), "favicons"));
2020-06-30 10:51:16 +00:00
2020-06-30 09:19:17 +00:00
try {
2020-06-30 10:28:31 +00:00
// check cache
2021-07-16 13:05:54 +00:00
File[] files = null;
if (gravatars) {
File f = new File(dir, ekey + ".gravatar");
if (f.exists())
files = new File[]{f};
}
if (files == null && libravatars) {
File f = new File(dir, ekey + ".libravatar");
2022-04-27 12:56:42 +00:00
if (f.exists())
files = new File[]{f};
}
2021-07-16 13:05:54 +00:00
if (files == null)
files = dir.listFiles(new FilenameFilter() {
@Override
public boolean accept(File file, String name) {
return name.startsWith(domain);
}
});
if (files != null && files.length == 1) {
2022-12-28 12:43:02 +00:00
files[0].setLastModified(new Date().getTime());
2021-07-16 13:05:54 +00:00
if (files[0].length() == 0)
Log.i("Avatar blacklisted cache" + files[0].getName());
2021-07-13 08:37:02 +00:00
else {
2021-07-16 13:05:54 +00:00
Log.i("Avatar from cache=" + files[0].getName());
String ext = Helper.getExtension(files[0].getName());
String[] data = (ext == null ? null : ext.split("_"));
info.bitmap = BitmapFactory.decodeFile(files[0].getAbsolutePath());
if (data != null) {
info.type = (data.length > 0 ? data[0] : "unknown");
info.verified = (data.length > 1 && "verified".equals(data[1]));
}
2021-07-13 08:37:02 +00:00
}
2021-07-16 13:05:54 +00:00
} else {
2020-12-11 09:06:48 +00:00
final int scaleToPixels = Helper.dp2pixels(context, FAVICON_ICON_SIZE);
2020-07-01 07:59:48 +00:00
2021-07-13 08:37:02 +00:00
List<Future<Favicon>> futures = new ArrayList<>();
2020-12-10 19:56:47 +00:00
2021-07-16 13:05:54 +00:00
if (bimi)
2022-12-28 09:32:41 +00:00
futures.add(Helper.getDownloadTaskExecutor().submit(new Callable<Favicon>() {
2020-12-10 19:56:47 +00:00
@Override
2021-07-13 08:37:02 +00:00
public Favicon call() throws Exception {
2021-07-16 06:14:05 +00:00
Pair<Bitmap, Boolean> bimi =
2021-07-16 18:03:27 +00:00
Bimi.get(context, domain, selector, scaleToPixels);
2021-07-16 13:05:54 +00:00
return (bimi == null ? null : new Favicon(bimi.first, "vmc", bimi.second));
}
}));
String email = info.email.toLowerCase(Locale.ROOT);
if (gravatars)
futures.add(Helper.getDownloadTaskExecutor()
.submit(Avatar.getGravatar(email, scaleToPixels, context)));
if (libravatars)
futures.add(Helper.getDownloadTaskExecutor()
.submit(Avatar.getLibravatar(email, scaleToPixels, context)));
2022-04-27 12:56:42 +00:00
2021-07-13 08:37:02 +00:00
if (favicons) {
String host = domain;
2022-08-12 15:48:20 +00:00
if (!host.startsWith("www."))
host = "www." + host;
2021-07-13 08:37:02 +00:00
while (host.indexOf('.') > 0) {
final URL base = new URL("https://" + host);
2022-12-28 09:32:41 +00:00
futures.add(Helper.getDownloadTaskExecutor().submit(new Callable<Favicon>() {
2021-07-13 08:37:02 +00:00
@Override
public Favicon call() throws Exception {
return parseFavicon(base, scaleToPixels, context);
}
}));
2022-04-18 10:12:40 +00:00
int dot = host.indexOf('.');
host = host.substring(dot + 1);
}
host = domain;
2022-08-12 15:48:20 +00:00
if (!host.startsWith("www."))
host = "www." + host;
2022-04-18 10:12:40 +00:00
while (host.indexOf('.') > 0) {
final URL base = new URL("https://" + host);
2021-07-13 08:37:02 +00:00
2022-08-12 15:48:20 +00:00
for (String name : FIXED_FAVICONS)
2022-12-28 09:32:41 +00:00
futures.add(Helper.getDownloadTaskExecutor().submit(new Callable<Favicon>() {
2022-08-12 15:48:20 +00:00
@Override
public Favicon call() throws Exception {
return getFavicon(new URL(base, name), null, scaleToPixels, context);
}
}));
2021-07-13 08:37:02 +00:00
int dot = host.indexOf('.');
host = host.substring(dot + 1);
}
2020-12-10 19:56:47 +00:00
}
2020-07-01 08:49:09 +00:00
Throwable ex = null;
2021-07-13 08:37:02 +00:00
for (Future<Favicon> future : futures)
2020-07-01 07:59:48 +00:00
try {
2021-07-13 08:37:02 +00:00
Favicon favicon = future.get();
2022-04-18 10:12:40 +00:00
Log.i("Using favicon source=" + (favicon == null ? null : favicon.source));
if (favicon == null)
continue;
float lum = 0; // ImageHelper.getLuminance(favicon.bitmap);
if (lum < MIN_FAVICON_LUMINANCE) {
Bitmap bitmap = Bitmap.createBitmap(
favicon.bitmap.getWidth(),
favicon.bitmap.getHeight(),
favicon.bitmap.getConfig());
bitmap.eraseColor(Color.WHITE);
Canvas canvas = new Canvas(bitmap);
canvas.drawBitmap(favicon.bitmap, 0, 0, null);
favicon.bitmap.recycle();
favicon.bitmap = bitmap;
2021-07-13 08:37:02 +00:00
}
2022-04-18 10:12:40 +00:00
info.bitmap = favicon.bitmap;
info.type = favicon.type;
info.verified = favicon.verified;
break;
2020-07-01 08:49:09 +00:00
} catch (ExecutionException exex) {
ex = exex.getCause();
} catch (Throwable exex) {
ex = exex;
2020-07-01 07:59:48 +00:00
}
2020-06-30 09:19:17 +00:00
2020-06-30 12:29:50 +00:00
if (info.bitmap == null)
2021-08-04 21:04:22 +00:00
if (ex == null)
throw new FileNotFoundException();
else
throw ex;
2020-07-01 08:49:09 +00:00
// Add to cache
2021-07-16 13:05:54 +00:00
File output = new File(dir,
(info.isEmailBased() ? ekey : domain) +
2021-07-16 13:05:54 +00:00
"." + info.type +
(info.verified ? "_verified" : ""));
2021-07-15 05:48:17 +00:00
try (OutputStream os = new BufferedOutputStream(new FileOutputStream(output))) {
2020-07-01 08:49:09 +00:00
info.bitmap.compress(Bitmap.CompressFormat.PNG, 90, os);
}
2021-07-16 13:05:54 +00:00
Log.i("Avatar to cache=" + output.getName());
2020-06-30 09:19:17 +00:00
}
} catch (Throwable ex) {
2020-07-06 15:39:21 +00:00
if (isRecoverable(ex, context))
Log.i(ex);
else {
2021-03-13 20:25:27 +00:00
if (ex instanceof FileNotFoundException ||
2021-08-24 06:28:25 +00:00
ex instanceof CertificateException ||
2021-08-03 06:08:38 +00:00
ex instanceof CertPathValidatorException ||
2021-08-24 06:28:25 +00:00
ex.getCause() instanceof CertPathValidatorException ||
2021-10-12 13:37:46 +00:00
ex.getCause() instanceof CertificateException ||
(ex instanceof SSLException &&
2022-05-11 12:36:29 +00:00
"Unable to parse TLS packet header".equals(ex.getMessage())) ||
(ex instanceof IOException &&
"Resetting to invalid mark".equals(ex.getMessage())))
2021-03-13 20:25:27 +00:00
Log.i(ex);
else
Log.e(ex);
2020-06-30 10:51:16 +00:00
try {
2021-07-15 05:48:17 +00:00
new File(dir, domain).createNewFile();
2020-06-30 12:04:50 +00:00
} catch (IOException ex1) {
Log.e(ex1);
2020-06-30 09:19:17 +00:00
}
2020-07-06 15:39:21 +00:00
}
2020-06-30 09:19:17 +00:00
}
}
}
// Generated
2019-09-30 18:27:36 +00:00
boolean identicon = false;
2022-08-18 05:42:15 +00:00
if (info.bitmap == null && generated && !TextUtils.isEmpty(info.email)) {
2022-10-06 12:43:44 +00:00
File dir = Helper.ensureExists(new File(context.getFilesDir(), "generated"));
2022-08-18 05:42:15 +00:00
File[] files = dir.listFiles(new FilenameFilter() {
@Override
public boolean accept(File file, String name) {
return name.startsWith(ekey);
2022-08-18 05:42:15 +00:00
}
});
if (files != null && files.length == 1) {
Log.i("Generated from cache=" + files[0].getName());
files[0].setLastModified(new Date().getTime());
2022-08-18 05:42:15 +00:00
info.bitmap = BitmapFactory.decodeFile(files[0].getAbsolutePath());
info.type = Helper.getExtension(files[0].getName());
} else {
int dp = Helper.dp2pixels(context, GENERATED_ICON_SIZE);
2019-09-30 18:27:36 +00:00
if (identicons) {
identicon = true;
2019-10-13 11:54:18 +00:00
info.bitmap = ImageHelper.generateIdenticon(
2020-06-25 12:32:04 +00:00
info.email, dp, 5, context);
2021-07-16 13:05:54 +00:00
info.type = "identicon";
} else {
2019-10-13 11:54:18 +00:00
info.bitmap = ImageHelper.generateLetterIcon(
2020-06-25 12:32:04 +00:00
info.email, address.getPersonal(), dp, context);
2021-07-16 15:02:19 +00:00
info.type = "letter";
2021-07-16 13:05:54 +00:00
}
2022-08-18 05:42:15 +00:00
// Add to cache
File output = new File(dir, ekey + "." + info.type);
2022-08-18 05:42:15 +00:00
try (OutputStream os = new BufferedOutputStream(new FileOutputStream(output))) {
info.bitmap.compress(Bitmap.CompressFormat.PNG, 90, os);
} catch (IOException ex) {
Log.e(ex);
}
Log.i("Generated to cache=" + output.getName());
}
2019-01-19 13:21:21 +00:00
}
info.bitmap = ImageHelper.makeCircular(info.bitmap,
circular && !identicon ? null : Helper.dp2pixels(context, 3));
2019-04-25 19:20:20 +00:00
2019-01-26 09:58:37 +00:00
if (info.displayName == null)
info.displayName = address.getPersonal();
2021-10-26 05:56:37 +00:00
if (!info.known && !TextUtils.isEmpty(info.email))
try {
DB db = DB.getInstance(context);
EntityContact contact = db.contact().getContact(account, EntityContact.TYPE_TO, info.email);
info.known = (contact != null);
} catch (Throwable ex) {
Log.e(ex);
}
2019-10-02 11:36:07 +00:00
2019-01-26 09:58:37 +00:00
synchronized (emailContactInfo) {
2019-01-30 08:06:10 +00:00
emailContactInfo.put(key, info);
2019-01-26 09:58:37 +00:00
}
info.time = new Date().getTime();
return info;
2019-01-19 13:21:21 +00:00
}
2019-02-04 11:45:38 +00:00
2021-07-13 08:37:02 +00:00
private static Favicon parseFavicon(URL base, int scaleToPixels, Context context) throws IOException {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean favicons_partial = prefs.getBoolean("favicons_partial", true);
Log.i("PARSE favicon " + base);
HttpURLConnection connection = ConnectionHelper
.openConnectionUnsafe(context, base, FAVICON_CONNECT_TIMEOUT, FAVICON_READ_TIMEOUT);
2020-06-30 10:28:31 +00:00
Document doc;
2020-06-30 12:04:50 +00:00
try {
Log.i("Favicon partial=" + favicons_partial);
if (favicons_partial) {
byte[] buffer = new byte[FAVICON_READ_BYTES];
int len = 0;
while (len < buffer.length) {
int read = connection.getInputStream().read(buffer, len, buffer.length - len);
if (read < 0)
break;
else
len += read;
}
if (len < 0)
throw new IOException("length");
doc = JsoupEx.parse(new String(buffer, 0, len, StandardCharsets.UTF_8.name()));
} else
doc = JsoupEx.parse(connection.getInputStream(), StandardCharsets.UTF_8.name(), base.toString());
2020-06-30 12:04:50 +00:00
} finally {
connection.disconnect();
}
2020-06-30 10:28:31 +00:00
2020-12-11 08:21:01 +00:00
// Use canonical address
2020-12-10 21:10:18 +00:00
Element canonical = doc.head().select("link[rel=canonical]").first();
if (canonical != null) {
String href = canonical.attr("href");
if (!TextUtils.isEmpty(href))
base = new URL(href);
}
2020-12-11 08:21:01 +00:00
// https://en.wikipedia.org/wiki/Favicon
Elements imgs = new Elements();
2020-12-11 13:54:15 +00:00
imgs.addAll(doc.head().select("link[href~=.+\\.(ico|png|gif|svg)]"));
imgs.addAll(doc.head().select("meta[itemprop=image]"));
2020-12-11 08:21:01 +00:00
2021-06-27 10:02:05 +00:00
// https://developer.mozilla.org/en-US/docs/Web/Manifest/icons
if (imgs.size() == 0 || BuildConfig.DEBUG)
for (Element manifest : doc.head().select("link[rel=manifest]"))
try {
String href = manifest.attr("href");
if (TextUtils.isEmpty(href))
continue;
URL url = new URL(base, href);
2022-03-07 09:32:05 +00:00
if (!"https".equals(url.getProtocol()))
throw new FileNotFoundException(url.toString());
2021-06-27 10:02:05 +00:00
Log.i("GET favicon manifest " + url);
HttpsURLConnection m = (HttpsURLConnection) url.openConnection();
m.setRequestMethod("GET");
m.setReadTimeout(FAVICON_READ_TIMEOUT);
m.setConnectTimeout(FAVICON_CONNECT_TIMEOUT);
m.setInstanceFollowRedirects(true);
ConnectionHelper.setUserAgent(context, m);
2021-06-27 10:02:05 +00:00
m.connect();
try {
String json = Helper.readStream(m.getInputStream());
JSONObject jroot = new JSONObject(json);
2021-07-08 07:19:56 +00:00
if (jroot.has("icons")) {
JSONArray jicons = jroot.getJSONArray("icons");
for (int i = 0; i < jicons.length(); i++) {
JSONObject jicon = jicons.getJSONObject(i);
String src = jicon.optString("src");
String sizes = jicon.optString("sizes", "");
String type = jicon.optString("type", "");
if (!TextUtils.isEmpty(src)) {
Element img = doc.createElement("link")
2022-03-12 10:45:44 +00:00
.attr("rel", "manifest")
2021-07-08 07:19:56 +00:00
.attr("href", src)
.attr("sizes", sizes)
.attr("type", type);
imgs.add(img);
}
2021-06-27 10:02:05 +00:00
}
}
} finally {
m.disconnect();
}
} catch (Throwable ex) {
Log.w(ex);
}
2022-05-12 18:57:08 +00:00
// https://docs.microsoft.com/en-us/previous-versions/windows/internet-explorer/ie-developer/platform-apis/dn320426(v=vs.85)
2022-05-18 07:58:18 +00:00
/*
2022-05-12 18:57:08 +00:00
if (imgs.size() == 0 || BuildConfig.DEBUG) {
String cfg = "/browserconfig.xml";
Element meta = doc.head().select("meta[name=msapplication-config]").first();
if (meta != null) {
String content = meta.attr("content");
if (!TextUtils.isEmpty(content))
cfg = content;
}
try {
URL url = new URL(base, cfg);
if (!"https".equals(url.getProtocol()))
throw new FileNotFoundException(url.toString());
Log.i("GET browserconfig " + url);
HttpsURLConnection m = (HttpsURLConnection) url.openConnection();
m.setRequestMethod("GET");
m.setReadTimeout(FAVICON_READ_TIMEOUT);
m.setConnectTimeout(FAVICON_CONNECT_TIMEOUT);
m.setInstanceFollowRedirects(true);
m.setRequestProperty("User-Agent", WebViewEx.getUserAgent(context));
m.connect();
try {
XmlPullParser xml = Xml.newPullParser();
xml.setInput(m.getInputStream(), null);
int eventType = xml.getEventType();
while (eventType != XmlPullParser.END_DOCUMENT) {
if (eventType == XmlPullParser.START_TAG) {
String name = xml.getName();
if ("square70x70logo".equals(name) ||
"square150x150logo".equals(name) ||
"square310x310logo".equals(name)) {
String src = xml.getAttributeValue(null, "src");
if (!TextUtils.isEmpty(src)) {
Element img = doc.createElement("link")
.attr("rel", "browserconfig")
.attr("href", new URL(base, src).toString())
.attr("sizes", name
.replace("square", "")
.replace("logo", ""));
Log.i("GOT browserconfig " + img);
imgs.add(img);
}
}
}
eventType = xml.next();
}
} finally {
m.disconnect();
}
} catch (Throwable ex) {
Log.w(ex);
}
}
2022-05-18 07:58:18 +00:00
*/
2022-05-12 18:57:08 +00:00
2022-03-12 15:02:09 +00:00
String host = base.getHost();
2020-12-11 09:06:48 +00:00
Collections.sort(imgs, new Comparator<Element>() {
@Override
public int compare(Element img1, Element img2) {
2022-03-12 15:02:09 +00:00
int t1 = getOrder(host, img1);
int t2 = getOrder(host, img2);
2021-06-22 09:45:43 +00:00
int t = Integer.compare(t1, t2);
if (t != 0)
2022-03-12 10:45:44 +00:00
return -t;
2021-06-22 09:45:43 +00:00
2021-06-27 10:20:28 +00:00
int s1 = getSize(img1.attr("sizes"));
int s2 = getSize(img2.attr("sizes"));
2020-12-11 09:06:48 +00:00
return Integer.compare(
2021-06-27 10:20:28 +00:00
Math.abs(s1 - scaleToPixels),
Math.abs(s2 - scaleToPixels));
2020-12-11 09:06:48 +00:00
}
});
Log.i("Favicons " + base + "=" + imgs.size());
2020-12-11 13:54:15 +00:00
for (int i = 0; i < imgs.size(); i++)
2022-03-12 15:02:09 +00:00
Log.i("Favicon #" + getOrder(host, imgs.get(i)) + " " + i + "=" + imgs.get(i) + " @" + base);
2020-12-11 13:54:15 +00:00
2020-12-11 08:21:01 +00:00
for (Element img : imgs) {
2021-05-24 05:45:57 +00:00
String rel = img.attr("rel").trim().toLowerCase(Locale.ROOT);
if (REL_EXCLUDE.contains(rel)) // dns-prefetch: gmx.net
2021-05-23 05:47:23 +00:00
continue;
2020-12-11 08:21:01 +00:00
String favicon = ("link".equals(img.tagName())
? img.attr("href")
: img.attr("content"));
2020-12-10 21:09:36 +00:00
if (TextUtils.isEmpty(favicon))
continue;
try {
2022-12-28 09:32:41 +00:00
URL url = new URL(base, favicon);
Favicon f = getFavicon(url, img.attr("type"), scaleToPixels, context);
Log.i("Using favicon=" + url);
return f;
2020-12-10 21:09:36 +00:00
} catch (Throwable ex) {
2021-03-13 20:25:27 +00:00
if (ex.getCause() instanceof FileNotFoundException ||
ex.getCause() instanceof CertPathValidatorException)
2021-03-13 20:04:49 +00:00
Log.i(ex);
else
Log.e(ex);
2020-12-10 21:09:36 +00:00
}
2022-12-28 09:32:41 +00:00
}
2020-06-30 12:04:50 +00:00
return null;
2020-06-30 09:19:17 +00:00
}
2022-03-12 15:02:09 +00:00
private static int getOrder(String host, Element img) {
2022-03-12 10:45:44 +00:00
// https://en.wikipedia.org/wiki/Favicon#How_to_use
String href = img.attr("href")
.toLowerCase(Locale.ROOT)
.trim();
String rel = img.attr("rel")
.toLowerCase(Locale.ROOT)
.replace("shortcut", "") // "shortcut icon"
.trim();
String type = img.attr("type")
.trim();
int order = 0;
if ("link".equals(img.tagName()))
order += 100;
2022-03-12 15:02:09 +00:00
boolean isIco = (href.endsWith(".ico") || "image/x-icon".equals(type));
boolean isSvg = (href.endsWith(".svg") || "image/svg+xml".equals(type));
2022-03-14 07:06:36 +00:00
boolean isMask = ("mask-icon".equals(rel) || img.hasAttr("mask"));
2022-03-12 15:02:09 +00:00
2022-03-14 07:06:36 +00:00
if (isMask)
order = -10; // Safari: "mask-icon"
else if ("icon".equals(rel) && !isIco)
2022-03-12 10:45:44 +00:00
order += 20;
2022-03-12 15:02:09 +00:00
else if ("apple-touch-icon".equals(rel) ||
"apple-touch-icon-precomposed".equals(rel)) {
2022-03-14 07:06:36 +00:00
// "apple-touch-startup-image"
2022-03-12 15:02:09 +00:00
if ("mailbox.org".equals(host))
order += 30;
else
order += 10;
}
2022-03-12 10:45:44 +00:00
2022-03-12 15:02:09 +00:00
if (isIco)
order += 1;
else if (isSvg)
order += 2;
else
order += 5;
2021-07-13 18:31:31 +00:00
return order;
}
2021-06-27 10:20:28 +00:00
private static int getSize(String sizes) {
int max = 0;
for (String size : sizes.split(" ")) {
int min = Integer.MAX_VALUE;
2022-02-11 19:31:13 +00:00
for (String p : size.trim().split("[×|x|X]")) {
2021-08-24 07:29:06 +00:00
if (TextUtils.isEmpty(p) || "any".equalsIgnoreCase(p))
2021-06-27 11:24:18 +00:00
continue;
2021-08-24 07:29:06 +00:00
2021-06-27 10:20:28 +00:00
try {
int x = Integer.parseInt(p);
if (x < min)
min = x;
} catch (NumberFormatException ex) {
Log.w(ex);
}
2021-06-27 11:24:18 +00:00
}
2021-06-27 10:20:28 +00:00
if (min != Integer.MAX_VALUE && min > max)
max = min;
}
return max;
}
2020-07-01 08:49:09 +00:00
@NonNull
2021-07-18 10:15:25 +00:00
private static Favicon getFavicon(URL url, String mimeType, int scaleToPixels, Context context) throws IOException {
2020-06-30 10:28:31 +00:00
Log.i("GET favicon " + url);
2020-07-04 07:08:32 +00:00
if (!"https".equals(url.getProtocol()))
2022-03-07 09:32:05 +00:00
throw new FileNotFoundException(url.toString());
2020-07-04 07:08:32 +00:00
HttpURLConnection connection = ConnectionHelper
.openConnectionUnsafe(context, url, FAVICON_CONNECT_TIMEOUT, FAVICON_READ_TIMEOUT);
2020-06-30 10:28:31 +00:00
try {
2021-05-19 15:20:42 +00:00
int status = connection.getResponseCode();
if (status != HttpURLConnection.HTTP_OK)
2021-07-15 06:36:55 +00:00
throw new FileNotFoundException("Error " + status + ": " + connection.getResponseMessage());
2021-05-19 15:20:42 +00:00
2021-07-18 10:15:25 +00:00
Bitmap bitmap = ImageHelper.getScaledBitmap(connection.getInputStream(), url.toString(), mimeType, scaleToPixels);
2020-07-01 08:49:09 +00:00
if (bitmap == null)
throw new FileNotFoundException("decodeStream");
2022-04-18 10:12:40 +00:00
return new Favicon(bitmap, url.toString());
2020-06-30 10:28:31 +00:00
} finally {
connection.disconnect();
}
}
2020-07-01 09:05:18 +00:00
private static boolean isRecoverable(Throwable ex, Context context) {
if (ex instanceof SocketTimeoutException) {
2022-04-13 20:27:33 +00:00
ConnectivityManager cm = Helper.getSystemService(context, ConnectivityManager.class);
2020-07-01 09:05:18 +00:00
NetworkInfo ni = (cm == null ? null : cm.getActiveNetworkInfo());
return (ni == null || !ni.isConnected());
}
2020-06-30 12:29:50 +00:00
return !(ex instanceof ConnectException ||
(ex instanceof UnknownHostException &&
ex.getMessage() != null &&
ex.getMessage().contains("No address associated with hostname")) ||
2022-04-24 07:32:55 +00:00
ex instanceof EOFException ||
2020-06-30 12:04:50 +00:00
ex instanceof FileNotFoundException ||
ex instanceof SSLPeerUnverifiedException ||
(ex instanceof SSLException &&
"Unable to parse TLS packet header".equals(ex.getMessage())) ||
(ex instanceof SSLHandshakeException &&
2020-07-01 12:28:13 +00:00
("connection closed".equals(ex.getMessage())) ||
"Connection closed by peer".equals(ex.getMessage())) ||
2020-07-01 17:44:01 +00:00
(ex instanceof SSLHandshakeException &&
ex.getMessage() != null &&
2020-07-19 06:01:14 +00:00
(ex.getMessage().contains("usually a protocol error") ||
ex.getMessage().contains("Unacceptable certificate"))) ||
2020-06-30 12:04:50 +00:00
(ex instanceof SSLHandshakeException &&
2020-07-01 12:28:13 +00:00
(ex.getCause() instanceof SSLProtocolException ||
ex.getCause() instanceof CertificateException ||
ex.getCause() instanceof CertPathValidatorException)));
2020-06-30 12:04:50 +00:00
}
2019-07-24 06:52:38 +00:00
static void init(final Context context) {
if (Helper.hasPermission(context, Manifest.permission.READ_CONTACTS)) {
2020-08-23 15:34:14 +00:00
ContentObserver observer = new ContentObserver(ApplicationEx.getMainHandler()) {
2019-07-24 06:52:38 +00:00
@Override
public void onChange(boolean selfChange, Uri uri) {
Log.i("Contact changed uri=" + uri);
2022-12-13 09:52:39 +00:00
Helper.getSerialExecutor().submit(new Runnable() {
2019-07-24 06:52:38 +00:00
@Override
public void run() {
try {
emailLookup = getEmailLookup(context);
} catch (Throwable ex) {
Log.e(ex);
}
2019-07-23 16:51:03 +00:00
}
2019-07-24 06:52:38 +00:00
});
}
};
2022-12-13 09:52:39 +00:00
Helper.getSerialExecutor().submit(new Runnable() {
2019-07-24 06:52:38 +00:00
@Override
public void run() {
try {
emailLookup = getEmailLookup(context);
} catch (Throwable ex) {
Log.e(ex);
2019-07-16 10:01:57 +00:00
}
2019-07-24 06:52:38 +00:00
}
});
2019-07-23 16:51:03 +00:00
2020-06-28 07:50:49 +00:00
try {
Uri uri = ContactsContract.CommonDataKinds.Email.CONTENT_URI;
Log.i("Observing uri=" + uri);
context.getContentResolver().registerContentObserver(uri, true, observer);
} catch (SecurityException ex) {
Log.w(ex);
/*
Should never happen, but:
Caused by: android.os.RemoteException:
at com.android.server.content.ContentService.registerContentObserver (ContentService.java:340)
at android.content.IContentService$Stub.onTransact (IContentService.java:76)
at com.android.server.content.ContentService.onTransact (ContentService.java:262)
at android.os.Binder.execTransact (Binder.java:731)
*/
}
2019-07-24 06:52:38 +00:00
}
2019-05-06 17:19:37 +00:00
}
2022-03-03 14:44:42 +00:00
static Uri getLookupUri(List<Address> addresses) {
return getLookupUri(addresses.toArray(new Address[0]));
}
2020-05-06 20:30:47 +00:00
static Uri getLookupUri(Address[] addresses) {
2019-05-06 17:19:37 +00:00
if (addresses == null)
2019-02-04 11:45:38 +00:00
return null;
2019-05-06 17:19:37 +00:00
for (Address from : addresses) {
String email = ((InternetAddress) from).getAddress();
2022-03-03 14:44:42 +00:00
if (TextUtils.isEmpty(email))
continue;
Lookup lookup = emailLookup.get(email.toLowerCase(Locale.ROOT));
if (lookup != null)
return lookup.uri;
2019-04-05 06:33:43 +00:00
}
2019-02-04 11:45:38 +00:00
2019-05-06 17:19:37 +00:00
return null;
}
2022-03-03 14:44:42 +00:00
static Uri getLookupUri(String email) {
if (TextUtils.isEmpty(email))
return null;
Lookup lookup = emailLookup.get(email.toLowerCase(Locale.ROOT));
return (lookup == null ? null : lookup.uri);
}
2021-02-28 16:37:06 +00:00
static Address[] fillIn(Address[] addresses, boolean prefer_contact, boolean only_contact) {
2020-05-06 20:30:47 +00:00
if (addresses == null)
return null;
Address[] modified = new Address[addresses.length];
for (int i = 0; i < addresses.length; i++) {
InternetAddress address = (InternetAddress) addresses[i];
String email = address.getAddress();
2021-02-28 16:37:06 +00:00
String personal = (only_contact ? null : address.getPersonal());
2020-06-25 12:32:04 +00:00
if (!TextUtils.isEmpty(email)) {
Lookup lookup = emailLookup.get(email.toLowerCase(Locale.ROOT));
if (lookup != null &&
(TextUtils.isEmpty(personal) || prefer_contact))
2020-05-06 20:30:47 +00:00
personal = lookup.displayName;
}
try {
modified[i] = new InternetAddress(email, personal, StandardCharsets.UTF_8.name());
} catch (UnsupportedEncodingException ex) {
Log.e(ex);
modified[i] = address;
}
}
return modified;
}
private static Map<String, Lookup> getEmailLookup(Context context) {
Map<String, Lookup> all = new ConcurrentHashMap<>();
2019-05-06 17:19:37 +00:00
if (Helper.hasPermission(context, Manifest.permission.READ_CONTACTS)) {
2019-07-24 06:52:38 +00:00
Log.i("Reading email/uri");
2019-02-22 15:59:23 +00:00
ContentResolver resolver = context.getContentResolver();
2019-07-21 08:31:34 +00:00
2019-02-22 15:59:23 +00:00
try (Cursor cursor = resolver.query(ContactsContract.CommonDataKinds.Email.CONTENT_URI,
new String[]{
ContactsContract.CommonDataKinds.Photo.CONTACT_ID,
2019-05-06 17:19:37 +00:00
ContactsContract.Contacts.LOOKUP_KEY,
2020-05-06 20:30:47 +00:00
ContactsContract.CommonDataKinds.Email.ADDRESS,
ContactsContract.Contacts.DISPLAY_NAME
2019-02-22 15:59:23 +00:00
},
2019-05-06 17:19:37 +00:00
ContactsContract.CommonDataKinds.Email.ADDRESS + " <> ''",
null, null)) {
while (cursor != null && cursor.moveToNext()) {
long contactId = cursor.getLong(0);
String lookupKey = cursor.getString(1);
String email = cursor.getString(2);
2020-05-06 20:30:47 +00:00
String displayName = cursor.getString(3);
2019-05-06 17:19:37 +00:00
2020-05-06 20:30:47 +00:00
Lookup lookup = new Lookup();
lookup.uri = ContactsContract.Contacts.getLookupUri(contactId, lookupKey);
lookup.displayName = displayName;
2020-06-25 12:32:04 +00:00
all.put(email.toLowerCase(Locale.ROOT), lookup);
2019-03-31 07:09:32 +00:00
}
2019-07-23 16:51:03 +00:00
} catch (Throwable ex) {
Log.e(ex);
2019-02-04 11:45:38 +00:00
}
}
2019-03-31 07:09:32 +00:00
2019-05-06 17:19:37 +00:00
Log.i("Read email/uri=" + all.size());
return all;
2019-03-31 07:09:32 +00:00
}
2020-01-23 15:47:10 +00:00
2022-04-12 06:42:03 +00:00
static int[] getStats() {
synchronized (emailContactInfo) {
return new int[]{emailLookup.size(), emailContactInfo.size()};
}
}
2020-05-06 20:30:47 +00:00
private static class Lookup {
Uri uri;
String displayName;
}
2022-04-27 12:56:42 +00:00
static class Favicon {
2021-07-13 08:37:02 +00:00
private Bitmap bitmap;
2021-07-16 13:05:54 +00:00
private String type;
2021-07-13 08:37:02 +00:00
private boolean verified;
2022-04-18 10:12:40 +00:00
private String source;
2021-07-13 08:37:02 +00:00
2022-04-18 10:12:40 +00:00
private Favicon(@NonNull Bitmap bitmap, String source) {
2021-07-16 13:05:54 +00:00
this(bitmap, "favicon", false);
2022-04-18 10:12:40 +00:00
this.source = source;
2021-07-13 08:37:02 +00:00
}
2022-04-27 12:56:42 +00:00
Favicon(@NonNull Bitmap bitmap, String type, boolean verified) {
2021-07-13 08:37:02 +00:00
this.bitmap = bitmap;
2021-07-16 13:05:54 +00:00
this.type = type;
2021-07-13 08:37:02 +00:00
this.verified = verified;
2022-04-18 10:12:40 +00:00
this.source = type;
2021-07-13 08:37:02 +00:00
}
}
2021-04-25 09:27:34 +00:00
}