Skip to content
Snippets Groups Projects
Commit 5ef74f03 authored by Oliver Wiese's avatar Oliver Wiese
Browse files

parse keys from mail

parent a40eef33
No related branches found
No related tags found
No related merge requests found
...@@ -564,6 +564,7 @@ class MailHandler { ...@@ -564,6 +564,7 @@ class MailHandler {
} }
} }
} }
newKeyIds.append(contentsOf: findKeyString(content: body))
if let header = header, let from = header.from, let date = header.date { if let header = header, let from = header.from, let date = header.date {
let mail = DataHandler.handler.createMail(uid, sender: from, receivers: rec, cc: cc, time: date, received: true, subject: header.subject ?? "", body: body, flags: flags, record: record, autocrypt: autocrypt, decryptedData: dec, folderPath: folderPath, secretKey: secretKey, references: references, mailagent: userAgent, messageID: msgID) let mail = DataHandler.handler.createMail(uid, sender: from, receivers: rec, cc: cc, time: date, received: true, subject: header.subject ?? "", body: body, flags: flags, record: record, autocrypt: autocrypt, decryptedData: dec, folderPath: folderPath, secretKey: secretKey, references: references, mailagent: userAgent, messageID: msgID)
if let m = mail { if let m = mail {
...@@ -620,12 +621,16 @@ class MailHandler { ...@@ -620,12 +621,16 @@ class MailHandler {
return nil return nil
} }
private func parsePublicKeys(attachment: MCOAttachment) -> [String] {
private func findKeyString(content: String) -> [String] {
var newKey = [String]() var newKey = [String]()
if let content = attachment.decodedString() {
if content.contains("-----BEGIN PGP PUBLIC KEY BLOCK-----") { if content.contains("-----BEGIN PGP PUBLIC KEY BLOCK-----") {
if let start = content.range(of: "-----BEGIN PGP PUBLIC KEY BLOCK-----") { if let start = content.range(of: "-----BEGIN PGP PUBLIC KEY BLOCK-----") {
if let end = content.range(of: "-----END PGP PUBLIC KEY BLOCK-----\n") { var end = content.range(of: "-----END PGP PUBLIC KEY BLOCK-----\n")
if end == nil {
end = content.range(of: "-----END PGP PUBLIC KEY BLOCK-----")
}
if let end = end {
let s = start.lowerBound let s = start.lowerBound
let e = end.upperBound let e = end.upperBound
let pk = content[s..<e] let pk = content[s..<e]
...@@ -636,6 +641,13 @@ class MailHandler { ...@@ -636,6 +641,13 @@ class MailHandler {
} }
} }
} }
return newKey
}
private func parsePublicKeys(attachment: MCOAttachment) -> [String] {
var newKey = [String]()
if let content = attachment.decodedString() {
newKey.append(contentsOf: findKeyString(content: content))
} else if attachment.mimeType == "application/octet-stream", let content = String(data: attachment.data, encoding: String.Encoding.utf8), content.hasPrefix("-----BEGIN PGP PUBLIC KEY BLOCK-----") && (content.hasSuffix("-----END PGP PUBLIC KEY BLOCK-----") || content.hasSuffix("-----END PGP PUBLIC KEY BLOCK-----\n")) { } else if attachment.mimeType == "application/octet-stream", let content = String(data: attachment.data, encoding: String.Encoding.utf8), content.hasPrefix("-----BEGIN PGP PUBLIC KEY BLOCK-----") && (content.hasSuffix("-----END PGP PUBLIC KEY BLOCK-----") || content.hasSuffix("-----END PGP PUBLIC KEY BLOCK-----\n")) {
let pgp = SwiftPGP() let pgp = SwiftPGP()
if let keyId = try? pgp.importKeys(key: content, pw: nil, isSecretKey: false, autocrypt: false) { if let keyId = try? pgp.importKeys(key: content, pw: nil, isSecretKey: false, autocrypt: false) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment