Revert "Fixed avatar caching for very long email addresses"

This reverts commit 9c88ccc0f0.
This commit is contained in:
M66B 2022-12-30 13:15:28 +01:00
parent ac66b564f2
commit 796fd4d7d3
1 changed files with 8 additions and 21 deletions

View File

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