Improved list-unsubscribe parser

pull/194/merge
M66B 3 years ago
parent b6402467e2
commit 05785a1ecb

@ -1786,26 +1786,39 @@ public class MessageHelper {
list = MimeUtility.unfold(list); list = MimeUtility.unfold(list);
list = decodeMime(list); list = decodeMime(list);
if (list != null && list.startsWith("NO")) if (list == null || list.startsWith("NO"))
return null; return null;
String link = null; String link = null;
String mailto = null; String mailto = null;
for (String entry : list.split(",")) { int s = list.indexOf('<');
entry = entry.trim(); int e = list.indexOf('>', s + 1);
int lt = entry.indexOf("<"); while (s >= 0 && e > s) {
int gt = entry.lastIndexOf(">"); String unsubscribe = list.substring(s + 1, e);
if (lt >= 0 && gt > lt) { if (TextUtils.isEmpty(unsubscribe))
String unsubscribe = entry.substring(lt + 1, gt); ; // Empty address
Uri uri = Uri.parse(unsubscribe); h else if (unsubscribe.toLowerCase(Locale.ROOT).startsWith("mailto:")) {
String scheme = uri.getScheme(); if (mailto == null) {
if (scheme != null) try {
scheme = scheme.toLowerCase(Locale.ROOT); MailTo.parse(unsubscribe);
if (mailto == null && "mailto".equals(scheme)) mailto = unsubscribe;
mailto = unsubscribe; } catch (Throwable ex) {
if (link == null && ("http".equals(scheme) || "https".equals(scheme))) Log.w(new Throwable(unsubscribe, ex));
link = unsubscribe; }
}
} else {
if (link == null) {
Uri uri = Uri.parse(unsubscribe);
String scheme = uri.getScheme();
if ("http".equalsIgnoreCase(scheme) || "https".equalsIgnoreCase(scheme))
link = unsubscribe;
else
Log.w(new Throwable(unsubscribe));
}
} }
s = list.indexOf('<', e + 1);
e = list.indexOf('>', s + 1);
} }
if (link != null) if (link != null)
@ -1815,8 +1828,8 @@ public class MessageHelper {
Log.i(new IllegalArgumentException("List-Unsubscribe: " + list)); Log.i(new IllegalArgumentException("List-Unsubscribe: " + list));
return null; return null;
} catch (AddressException ex) { } catch (Throwable ex) {
Log.w(ex); Log.e(ex);
return null; return null;
} }
} }

Loading…
Cancel
Save