forked from thunderbird/thunderbird-ios
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEmail.swift
More file actions
50 lines (44 loc) · 1.38 KB
/
Email.swift
File metadata and controls
50 lines (44 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import EmailAddress
import Foundation
import MIME
/// ``SMTPClient`` sends `Email`.
public struct Email: Identifiable, Sendable {
public let sender: EmailAddress
public let recipients: [EmailAddress]
public let copied: [EmailAddress]
public let blindCopied: [EmailAddress]
public let subject: String
public let date: Date
public let body: Body
public var contentType: MIME.ContentType { body.contentType }
public var messageID: String {
// Format: https://www.jwz.org/doc/mid.html
let local: String = "\(Int(date.timeIntervalSince1970)).\(id.uuidString(1))"
guard let host: String = sender.host else {
return "<\(local)>"
}
return "<\(local)@\(host)>"
}
public init(
sender: EmailAddress,
recipients: [EmailAddress] = [],
copied: [EmailAddress] = [],
blindCopied: [EmailAddress] = [],
subject: String = "",
date: Date = Date(),
body: Body = .empty,
id: UUID = UUID()
) {
self.sender = sender
self.recipients = recipients
self.copied = copied
self.blindCopied = blindCopied
self.subject = subject
self.date = date
self.body = body
self.id = id
}
var allRecipients: [EmailAddress] { recipients + copied + blindCopied }
// MARK: Identifiable
public let id: UUID
}