Skip to content

Commit

Permalink
fix: Support multiple named addressees (#40)
Browse files Browse the repository at this point in the history
This also supports naming email addresses.
  • Loading branch information
jbmorley authored Feb 22, 2025
1 parent d51f966 commit 861882a
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 6 deletions.
18 changes: 16 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,24 @@ Settings are stored in `~/.config/reporter/config.json`. Mine looks something li
"domain": "server.example.org",
"timeout": 30,

"from": "server@example.org",
"to": "admin@example.org",
},

"email": {

"from": {
"address": "server@example.org",
"name": "My Server"
},

"to": [
{
"address": "admin@example.org",
"name": "Example.org Admin"
}
]

}

"folders": {
"/mnt/usb0/Storage/Audiobooks": {},
"/mnt/usb0/Storage/Books": {},
Expand Down
16 changes: 14 additions & 2 deletions Sources/ReporterCore/Configuration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,19 @@ struct Configuration: Codable {
let domain: String
let timeout: UInt?

let from: String
let to: String
}

struct User: Codable {

let address: String
let name: String?

}

struct Email: Codable {

let from: User
let to: [User]

}

Expand All @@ -42,6 +53,7 @@ struct Configuration: Codable {
}

let mailServer: Server
let email: Email
let folders: [String: Policy]

init(contentsOf url: URL) throws {
Expand Down
29 changes: 29 additions & 0 deletions Sources/ReporterCore/Extensions/User.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright (c) 2024-2025 Jason Morley
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

import SwiftSMTP

extension Mail.User {

init(_ user: Configuration.User) {
self.init(name: user.name, email: user.address)
}

}
4 changes: 2 additions & 2 deletions Sources/ReporterCore/Reporter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -295,8 +295,8 @@ public class Reporter {
)

let mail = Mail(
from: .init(email: configuration.mailServer.from),
to: [.init(email: configuration.mailServer.to)],
from: .init(configuration.email.from),
to: configuration.email.to.map({ Mail.User($0) }),
subject: "Change Report",
text: summary,
attachments: [.init(htmlContent: htmlSummary)]
Expand Down

0 comments on commit 861882a

Please sign in to comment.