0
0
mirror of https://github.com/thunderbird/thunderbird-android.git synced 2024-09-20 12:12:15 +02:00

anchor pgp inline message matching to beginning of message

This commit is contained in:
Vincent Breitmoser 2016-02-10 15:24:12 +01:00
parent da49dd47a2
commit 6465cbe8be
2 changed files with 9 additions and 5 deletions

View File

@ -91,7 +91,7 @@ public class MessageDecryptVerifier {
if (TextUtils.isEmpty(text)) {
continue;
}
switch (OpenPgpUtils.parseMessage(text)) {
switch (OpenPgpUtils.parseMessage(text, true)) {
case OpenPgpUtils.PARSE_RESULT_MESSAGE:
case OpenPgpUtils.PARSE_RESULT_SIGNED_MESSAGE:
inlineParts.add(part);

View File

@ -29,11 +29,11 @@ import android.text.TextUtils;
public class OpenPgpUtils {
public static final Pattern PGP_MESSAGE = Pattern.compile(
".*?(-----BEGIN PGP MESSAGE-----.*?-----END PGP MESSAGE-----).*",
"(-----BEGIN PGP MESSAGE-----.*?-----END PGP MESSAGE-----).*",
Pattern.DOTALL);
public static final Pattern PGP_SIGNED_MESSAGE = Pattern.compile(
".*?(-----BEGIN PGP SIGNED MESSAGE-----.*?-----BEGIN PGP SIGNATURE-----.*?-----END PGP SIGNATURE-----).*",
"(-----BEGIN PGP SIGNED MESSAGE-----.*?-----BEGIN PGP SIGNATURE-----.*?-----END PGP SIGNATURE-----).*",
Pattern.DOTALL);
public static final int PARSE_RESULT_NO_PGP = -1;
@ -41,12 +41,16 @@ public class OpenPgpUtils {
public static final int PARSE_RESULT_SIGNED_MESSAGE = 1;
public static int parseMessage(String message) {
return parseMessage(message, false);
}
public static int parseMessage(String message, boolean anchorToStart) {
Matcher matcherSigned = PGP_SIGNED_MESSAGE.matcher(message);
Matcher matcherMessage = PGP_MESSAGE.matcher(message);
if (matcherMessage.matches()) {
if (anchorToStart ? matcherMessage.matches() : matcherMessage.find()) {
return PARSE_RESULT_MESSAGE;
} else if (matcherSigned.matches()) {
} else if (anchorToStart ? matcherSigned.matches() : matcherSigned.find()) {
return PARSE_RESULT_SIGNED_MESSAGE;
} else {
return PARSE_RESULT_NO_PGP;