mirror of
https://github.com/M66B/FairEmail.git
synced 2024-12-22 07:42:52 +00:00
Attach autocrypt public key
This commit is contained in:
parent
429c5002b1
commit
a51c8bd6db
2 changed files with 44 additions and 1 deletions
|
@ -66,6 +66,7 @@ import java.io.File;
|
|||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
@ -97,6 +98,7 @@ import javax.mail.FolderNotFoundException;
|
|||
import javax.mail.Message;
|
||||
import javax.mail.MessageRemovedException;
|
||||
import javax.mail.MessagingException;
|
||||
import javax.mail.Part;
|
||||
import javax.mail.Session;
|
||||
import javax.mail.Store;
|
||||
import javax.mail.UIDFolder;
|
||||
|
@ -2148,6 +2150,31 @@ class Core {
|
|||
Log.i(folder.name + " added id=" + message.id + " uid=" + message.uid);
|
||||
|
||||
int sequence = 1;
|
||||
|
||||
String autocrypt = helper.getAutocrypt();
|
||||
if (autocrypt != null) {
|
||||
EntityAttachment attachment = new EntityAttachment();
|
||||
attachment.message = message.id;
|
||||
attachment.sequence = sequence++;
|
||||
attachment.name = "pubkey.pem";
|
||||
attachment.type = "application/pgp-keys";
|
||||
attachment.disposition = Part.ATTACHMENT;
|
||||
attachment.id = db.attachment().insertAttachment(attachment);
|
||||
|
||||
File file = attachment.getFile(context);
|
||||
try (FileWriter writer = new FileWriter(file)) {
|
||||
writer.write("-----BEGIN PGP PUBLIC KEY BLOCK-----\r\n\r\n");
|
||||
while (autocrypt.length() > 0) {
|
||||
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");
|
||||
}
|
||||
|
||||
db.attachment().setDownloaded(attachment.id, file.length());
|
||||
}
|
||||
|
||||
List<EntityAttachment> attachments = parts.getAttachments();
|
||||
for (EntityAttachment attachment : attachments) {
|
||||
Log.i(folder.name + " attachment seq=" + sequence + " " + attachment);
|
||||
|
|
|
@ -236,9 +236,11 @@ public class MessageHelper {
|
|||
StringBuilder sb = new StringBuilder();
|
||||
try (BufferedReader br = new BufferedReader(new FileReader(file))) {
|
||||
String line;
|
||||
while ((line = br.readLine()) != null)
|
||||
while ((line = br.readLine()) != null) {
|
||||
Log.i(line);
|
||||
if (!line.startsWith("-----") && !line.endsWith("-----"))
|
||||
sb.append(line);
|
||||
}
|
||||
}
|
||||
|
||||
imessage.addHeader("Autocrypt",
|
||||
|
@ -876,6 +878,20 @@ public class MessageHelper {
|
|||
}
|
||||
}
|
||||
|
||||
String getAutocrypt() throws MessagingException {
|
||||
String autocrypt = imessage.getHeader("Autocrypt", null);
|
||||
if (autocrypt == null)
|
||||
return null;
|
||||
|
||||
autocrypt = MimeUtility.unfold(autocrypt);
|
||||
|
||||
int k = autocrypt.indexOf("keydata=");
|
||||
if (k < 0)
|
||||
return null;
|
||||
|
||||
return autocrypt.substring(k + 8);
|
||||
}
|
||||
|
||||
String getSubject() throws MessagingException {
|
||||
String subject = imessage.getHeader("Subject", null);
|
||||
if (subject == null)
|
||||
|
|
Loading…
Reference in a new issue