Prefer links to unsubscribe

This commit is contained in:
M66B 2019-09-23 12:15:25 +02:00
parent 852b2d5579
commit cc15eda190
1 changed files with 11 additions and 3 deletions

View File

@ -592,6 +592,8 @@ public class MessageHelper {
if (list != null && list.startsWith("NO"))
return null;
String link = null;
String mailto = null;
for (String entry : list.split(",")) {
entry = entry.trim();
int lt = entry.indexOf("<");
@ -600,12 +602,18 @@ public class MessageHelper {
String unsubscribe = entry.substring(lt + 1, gt);
Uri uri = Uri.parse(unsubscribe);
String scheme = uri.getScheme();
if ("mailto".equals(scheme) ||
"http".equals(scheme) || "https".equals(scheme))
return unsubscribe;
if (mailto == null && "mailto".equals(scheme))
mailto = unsubscribe;
if (link == null && ("http".equals(scheme) || "https".equals(scheme)))
link = unsubscribe;
}
}
if (link != null)
return link;
if (mailto != null)
return mailto;
Log.w(new IllegalArgumentException("List-Unsubscribe: " + list));
return null;
} catch (AddressException ex) {