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,28 +2148,29 @@ class Core {
int sequence = 1; int sequence = 1;
String autocrypt = helper.getAutocrypt(); String autocrypt = helper.getAutocrypt();
if (autocrypt != null) { if (autocrypt != null)
EntityAttachment attachment = new EntityAttachment(); try {
attachment.message = message.id; EntityAttachment attachment = new EntityAttachment();
attachment.sequence = sequence++; attachment.message = message.id;
attachment.name = "pubkey.pem"; attachment.sequence = sequence++;
attachment.type = "application/pgp-keys"; attachment.name = "pubkey.pem";
attachment.disposition = Part.ATTACHMENT; attachment.type = "application/pgp-keys";
attachment.id = db.attachment().insertAttachment(attachment); attachment.disposition = Part.ATTACHMENT;
attachment.id = db.attachment().insertAttachment(attachment);
File file = attachment.getFile(context);
try (FileWriter writer = new FileWriter(file)) { byte[] b = Base64.decode(autocrypt, Base64.DEFAULT);
writer.write("-----BEGIN PGP PUBLIC KEY BLOCK-----\r\n\r\n");
while (autocrypt.length() > 0) { File file = attachment.getFile(context);
int i = Math.min(64, autocrypt.length()); try (FileWriter writer = new FileWriter(file)) {
writer.write(autocrypt.substring(0, i) + "\r\n"); writer.write("-----BEGIN PGP PUBLIC KEY BLOCK-----\r\n\r\n");
autocrypt = autocrypt.substring(i); writer.write(Base64.encodeToString(b, Base64.CRLF));
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();
for (EntityAttachment attachment : attachments) { for (EntityAttachment attachment : attachments) {

Loading…
Cancel
Save