From 422583d0f4fc9e98a5255df65c1d0cf9bd35e45e Mon Sep 17 00:00:00 2001 From: kirkH Date: Thu, 6 Jun 2024 10:52:11 -0600 Subject: [PATCH] feat: contentID for email attachments --- Sources/Smtp/Models/Attachment.swift | 4 +++- Sources/Smtp/Models/Email.swift | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Sources/Smtp/Models/Attachment.swift b/Sources/Smtp/Models/Attachment.swift index 01af71b..cfcaa07 100644 --- a/Sources/Smtp/Models/Attachment.swift +++ b/Sources/Smtp/Models/Attachment.swift @@ -10,10 +10,12 @@ public struct Attachment { public let name: String public let contentType: String public let data: Data + public let contentID: String? - public init(name: String, contentType: String, data: Data) { + public init(name: String, contentType: String, data: Data, contentID: String? = nil) { self.name = name self.contentType = contentType self.data = data + self.contentID = contentID } } diff --git a/Sources/Smtp/Models/Email.swift b/Sources/Smtp/Models/Email.swift index 0200af2..f77314e 100644 --- a/Sources/Smtp/Models/Email.swift +++ b/Sources/Smtp/Models/Email.swift @@ -122,6 +122,9 @@ extension Email { for (index, attachment) in self.attachments.enumerated() { out.writeString("Content-type: \(attachment.contentType)\r\n") out.writeString("Content-Transfer-Encoding: base64\r\n") + if let contentID = attachment.contentID { + out.writeString("Content-ID: \(contentID)\r\n") + } out.writeString("Content-Disposition: attachment; filename=\"\(attachment.name)\"\r\n\r\n") out.writeString("\(attachment.data.base64EncodedString())\r\n")