Revert "Fixed avatar caching for very long email addresses"

This reverts commit 9c88ccc0f0.
pull/210/head
M66B 2 years ago
parent ac66b564f2
commit 796fd4d7d3

@ -256,16 +256,6 @@ public class ContactInfo {
ContactInfo info = new ContactInfo(); ContactInfo info = new ContactInfo();
info.email = address.getAddress(); info.email = address.getAddress();
// 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);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean avatars = prefs.getBoolean("avatars", true); boolean avatars = prefs.getBoolean("avatars", true);
boolean prefer_contact = prefs.getBoolean("prefer_contact", false); boolean prefer_contact = prefs.getBoolean("prefer_contact", false);
@ -341,6 +331,7 @@ public class ContactInfo {
} }
final String domain = d.toLowerCase(Locale.ROOT); final String domain = d.toLowerCase(Locale.ROOT);
final String email = info.email.toLowerCase(Locale.ROOT);
File dir = Helper.ensureExists(new File(context.getFilesDir(), "favicons")); File dir = Helper.ensureExists(new File(context.getFilesDir(), "favicons"));
@ -348,12 +339,12 @@ public class ContactInfo {
// check cache // check cache
File[] files = null; File[] files = null;
if (gravatars) { if (gravatars) {
File f = new File(dir, ekey + ".gravatar"); File f = new File(dir, email + ".gravatar");
if (f.exists()) if (f.exists())
files = new File[]{f}; files = new File[]{f};
} }
if (files == null && libravatars) { if (files == null && libravatars) {
File f = new File(dir, ekey + ".libravatar"); File f = new File(dir, email + ".libravatar");
if (f.exists()) if (f.exists())
files = new File[]{f}; files = new File[]{f};
} }
@ -393,13 +384,10 @@ public class ContactInfo {
} }
})); }));
String email = info.email.toLowerCase(Locale.ROOT);
if (gravatars) if (gravatars)
futures.add(Helper.getDownloadTaskExecutor() futures.add(Helper.getDownloadTaskExecutor().submit(Avatar.getGravatar(email, scaleToPixels, context)));
.submit(Avatar.getGravatar(email, scaleToPixels, context)));
if (libravatars) if (libravatars)
futures.add(Helper.getDownloadTaskExecutor() futures.add(Helper.getDownloadTaskExecutor().submit(Avatar.getLibravatar(email, scaleToPixels, context)));
.submit(Avatar.getLibravatar(email, scaleToPixels, context)));
if (favicons) { if (favicons) {
String host = domain; String host = domain;
@ -478,7 +466,7 @@ public class ContactInfo {
// Add to cache // Add to cache
File output = new File(dir, File output = new File(dir,
(info.isEmailBased() ? ekey : domain) + (info.isEmailBased() ? email : domain) +
"." + info.type + "." + info.type +
(info.verified ? "_verified" : "")); (info.verified ? "_verified" : ""));
try (OutputStream os = new BufferedOutputStream(new FileOutputStream(output))) { try (OutputStream os = new BufferedOutputStream(new FileOutputStream(output))) {
@ -519,12 +507,11 @@ public class ContactInfo {
File[] files = dir.listFiles(new FilenameFilter() { File[] files = dir.listFiles(new FilenameFilter() {
@Override @Override
public boolean accept(File file, String name) { public boolean accept(File file, String name) {
return name.startsWith(ekey); return name.startsWith(info.email);
} }
}); });
if (files != null && files.length == 1) { if (files != null && files.length == 1) {
Log.i("Generated from cache=" + files[0].getName()); Log.i("Generated from cache=" + files[0].getName());
files[0].setLastModified(new Date().getTime());
info.bitmap = BitmapFactory.decodeFile(files[0].getAbsolutePath()); info.bitmap = BitmapFactory.decodeFile(files[0].getAbsolutePath());
info.type = Helper.getExtension(files[0].getName()); info.type = Helper.getExtension(files[0].getName());
} else { } else {
@ -541,7 +528,7 @@ public class ContactInfo {
} }
// Add to cache // Add to cache
File output = new File(dir, ekey + "." + info.type); File output = new File(dir, info.email + "." + info.type);
try (OutputStream os = new BufferedOutputStream(new FileOutputStream(output))) { try (OutputStream os = new BufferedOutputStream(new FileOutputStream(output))) {
info.bitmap.compress(Bitmap.CompressFormat.PNG, 90, os); info.bitmap.compress(Bitmap.CompressFormat.PNG, 90, os);
} catch (IOException ex) { } catch (IOException ex) {

Loading…
Cancel
Save