Simplification

pull/170/head
M66B 6 years ago
parent e1755c5fe0
commit 88952aed2c

@ -32,6 +32,7 @@ import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.os.SystemClock; import android.os.SystemClock;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Base64;
import android.util.Pair; import android.util.Pair;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
@ -2147,7 +2148,8 @@ class Core {
int sequence = 1; int sequence = 1;
String autocrypt = helper.getAutocrypt(); String autocrypt = helper.getAutocrypt();
if (autocrypt != null) { if (autocrypt != null)
try {
EntityAttachment attachment = new EntityAttachment(); EntityAttachment attachment = new EntityAttachment();
attachment.message = message.id; attachment.message = message.id;
attachment.sequence = sequence++; attachment.sequence = sequence++;
@ -2156,18 +2158,18 @@ class Core {
attachment.disposition = Part.ATTACHMENT; attachment.disposition = Part.ATTACHMENT;
attachment.id = db.attachment().insertAttachment(attachment); attachment.id = db.attachment().insertAttachment(attachment);
byte[] b = Base64.decode(autocrypt, Base64.DEFAULT);
File file = attachment.getFile(context); File file = attachment.getFile(context);
try (FileWriter writer = new FileWriter(file)) { try (FileWriter writer = new FileWriter(file)) {
writer.write("-----BEGIN PGP PUBLIC KEY BLOCK-----\r\n\r\n"); writer.write("-----BEGIN PGP PUBLIC KEY BLOCK-----\r\n\r\n");
while (autocrypt.length() > 0) { writer.write(Base64.encodeToString(b, Base64.CRLF));
int i = Math.min(64, autocrypt.length());
writer.write(autocrypt.substring(0, i) + "\r\n");
autocrypt = autocrypt.substring(i);
}
writer.write("-----END PGP PUBLIC KEY BLOCK-----\r\n"); writer.write("-----END PGP PUBLIC KEY BLOCK-----\r\n");
} }
db.attachment().setDownloaded(attachment.id, file.length()); db.attachment().setDownloaded(attachment.id, file.length());
} catch (IllegalArgumentException ex) {
Log.w(ex);
} }
List<EntityAttachment> attachments = parts.getAttachments(); List<EntityAttachment> attachments = parts.getAttachments();

Loading…
Cancel
Save