Refactoring

pull/212/head
M66B 3 years ago
parent 3d6876d51f
commit cb9102b9ed

@ -2013,6 +2013,20 @@ public class MessageHelper {
return signers;
for (String header : headers) {
String signer = verifySignatureHeader(context, header, DKIM_SIGNATURE, amessage);
if (signer != null && !signers.contains(signer))
signers.add(signer);
}
Log.i("DKIM signers=" + TextUtils.join(",", signers));
} catch (Throwable ex) {
Log.e("DKIM", ex);
}
return signers;
}
private String verifySignatureHeader(Context context, String header, String name, MimeMessage amessage) {
Map<String, String> kv = getKeyValues(MimeUtility.unfold(header));
String a = kv.get("a");
@ -2027,7 +2041,7 @@ public class MessageHelper {
} else {
// TODO: Ed25519
Log.i("DKIM a=" + a);
continue;
return null;
}
try {
@ -2036,7 +2050,7 @@ public class MessageHelper {
Log.i("DKIM lookup " + dns);
DnsHelper.DnsRecord[] records = DnsHelper.lookup(context, dns, "txt");
if (records.length == 0)
continue;
return null;
Log.i("DKIM got " + records[0].name);
Map<String, String> dk = getKeyValues(records[0].name);
@ -2062,7 +2076,7 @@ public class MessageHelper {
if (!from)
throw new IllegalArgumentException("from missing: " + hs);
keys.add(DKIM_SIGNATURE);
keys.add(name);
Map<String, Integer> index = new Hashtable<>();
for (String key : keys) {
@ -2072,7 +2086,7 @@ public class MessageHelper {
idx = (idx == null ? 1 : idx + 1);
index.put(_key, idx);
String[] values = (DKIM_SIGNATURE.equals(key)
String[] values = (name.equals(key)
? new String[]{header}
: amessage.getHeader(key));
if (values == null || idx > values.length) {
@ -2083,7 +2097,7 @@ public class MessageHelper {
}
String value = values[values.length - idx];
if (DKIM_SIGNATURE.equals(key)) {
if (name.equals(key)) {
int b = value.lastIndexOf("b=");
int s = value.indexOf(";", b + 2);
value = value.substring(0, b + 2) + (s < 0 ? "" : value.substring(s));
@ -2091,7 +2105,7 @@ public class MessageHelper {
Log.i("DKIM " + key + "=" + value.replaceAll("\\r?\\n", "|"));
if ("simple".equals(c[0])) {
if (DKIM_SIGNATURE.equals(key))
if (name.equals(key))
head.append(key).append(": ").append(value);
else {
// Find original header/name (case sensitive)
@ -2115,7 +2129,7 @@ public class MessageHelper {
} else
throw new IllegalArgumentException(c[0]);
if (!DKIM_SIGNATURE.equals(key))
if (!name.equals(key))
head.append("\r\n");
}
Log.i("DKIM head=" + head.toString().replace("\r\n", "|"));
@ -2162,7 +2176,7 @@ public class MessageHelper {
String pubkey = dk.get("p");
if (pubkey == null)
continue;
return null;
String p = pubkey.replaceAll("\\s+", "");
Log.i("DKIM pubkey=" + p);
@ -2174,7 +2188,7 @@ public class MessageHelper {
String hash = kv.get("b");
if (hash == null)
continue;
return null;
String s = hash.replaceAll("\\s+", "");
Log.i("DKIM signature=" + s);
@ -2188,20 +2202,13 @@ public class MessageHelper {
" dns=" + dns +
" from=" + formatAddresses(getFrom()));
if (verified &&
!signers.contains(signer))
signers.add(signer);
} catch (Throwable ex) {
Log.e("DKIM", ex);
}
}
Log.i("DKIM signers=" + TextUtils.join(",", signers));
if (verified)
return signer;
} catch (Throwable ex) {
Log.e("DKIM", ex);
}
return signers;
return null;
}
Address[] getMailFrom(String[] headers) {

Loading…
Cancel
Save