mirror of
https://github.com/M66B/FairEmail.git
synced 2025-03-01 01:06:11 +00:00
PGP: retry with trim
This commit is contained in:
parent
4f3d58f42c
commit
b72486752f
2 changed files with 57 additions and 5 deletions
|
@ -9015,7 +9015,7 @@ public class FragmentMessages extends FragmentBase
|
|||
Intent data = new Intent();
|
||||
data.setAction(OpenPgpApi.ACTION_DECRYPT_VERIFY);
|
||||
data.putExtra(BuildConfig.APPLICATION_ID, id);
|
||||
onPgp(data, auto);
|
||||
onPgp(data, auto, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -9035,7 +9035,7 @@ public class FragmentMessages extends FragmentBase
|
|||
break;
|
||||
case REQUEST_OPENPGP:
|
||||
if (resultCode == RESULT_OK && data != null)
|
||||
onPgp(data, false);
|
||||
onPgp(data, false, false);
|
||||
break;
|
||||
case REQUEST_MESSAGE_DELETE:
|
||||
if (resultCode == RESULT_OK && data != null)
|
||||
|
@ -9250,16 +9250,18 @@ public class FragmentMessages extends FragmentBase
|
|||
}.execute(this, args, "raw:save");
|
||||
}
|
||||
|
||||
private void onPgp(Intent data, boolean auto) {
|
||||
private void onPgp(Intent data, boolean auto, boolean stripped) {
|
||||
Bundle args = new Bundle();
|
||||
args.putParcelable("data", data);
|
||||
args.putBoolean("auto", auto);
|
||||
args.putBoolean("stripped", stripped);
|
||||
|
||||
new SimpleTask<PendingIntent>() {
|
||||
@Override
|
||||
protected PendingIntent onExecute(Context context, Bundle args) throws Throwable {
|
||||
// Get arguments
|
||||
boolean auto = args.getBoolean("auto");
|
||||
boolean stripped = args.getBoolean("stripped");
|
||||
Intent data = args.getParcelable("data");
|
||||
long id = data.getLongExtra(BuildConfig.APPLICATION_ID, -1);
|
||||
|
||||
|
@ -9348,6 +9350,9 @@ public class FragmentMessages extends FragmentBase
|
|||
else
|
||||
throw new IllegalArgumentException(context.getString(R.string.title_not_encrypted));
|
||||
|
||||
if (stripped)
|
||||
in = new MessageHelper.StripStream((in));
|
||||
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
boolean autocrypt = prefs.getBoolean("autocrypt", true);
|
||||
if (autocrypt &&
|
||||
|
@ -9542,8 +9547,13 @@ public class FragmentMessages extends FragmentBase
|
|||
} else if (sresult == RESULT_KEY_MISSING)
|
||||
args.putString("sigresult", context.getString(R.string.title_signature_key_missing));
|
||||
else {
|
||||
if (stripped) {
|
||||
String text = context.getString(R.string.title_signature_invalid_reason, Integer.toString(sresult));
|
||||
args.putString("sigresult", text);
|
||||
} else {
|
||||
onPgp(data, auto, true);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
|
|
|
@ -88,6 +88,7 @@ import java.io.File;
|
|||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.FileReader;
|
||||
import java.io.FilterInputStream;
|
||||
import java.io.FilterOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
@ -6130,6 +6131,47 @@ public class MessageHelper {
|
|||
}
|
||||
}
|
||||
|
||||
static class StripStream extends FilterInputStream {
|
||||
protected StripStream(InputStream in) {
|
||||
super(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int read() throws IOException {
|
||||
int b = super.read();
|
||||
if (b == ' ') {
|
||||
super.mark(1000);
|
||||
while (true) {
|
||||
b = super.read();
|
||||
if (b != ' ') {
|
||||
if (b == '\r' || b == '\n')
|
||||
return b;
|
||||
else {
|
||||
super.reset();
|
||||
return ' ';
|
||||
}
|
||||
}
|
||||
}
|
||||
} else
|
||||
return b;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int read(byte[] b) throws IOException {
|
||||
for (int i = 0; i < b.length; i++) {
|
||||
b[i] = (byte) read();
|
||||
if (b[i] < 0)
|
||||
return i;
|
||||
}
|
||||
return b.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int read(byte[] b, int off, int len) throws IOException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
||||
static class CanonicalizingStream extends FilterOutputStream {
|
||||
private OutputStream os;
|
||||
private int content;
|
||||
|
|
Loading…
Reference in a new issue