Merge pull request #1081 from k9mail/pgp-inline-anchor-to-beginning
anchor pgp inline message matching to beginning of message
This commit is contained in:
commit
06e1777bb1
2 changed files with 9 additions and 5 deletions
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue