From 083bc60531ea04f7053f0e0132b65ac0e71a940f Mon Sep 17 00:00:00 2001 From: Jason Morley Date: Sat, 22 Feb 2025 08:09:49 -1000 Subject: [PATCH 1/2] fix: Support multiple named addressees This also supports naming email addresses. --- Sources/ReporterCore/Configuration.swift | 16 ++++++++++-- Sources/ReporterCore/Extensions/User.swift | 29 ++++++++++++++++++++++ Sources/ReporterCore/Reporter.swift | 4 +-- 3 files changed, 45 insertions(+), 4 deletions(-) create mode 100644 Sources/ReporterCore/Extensions/User.swift diff --git a/Sources/ReporterCore/Configuration.swift b/Sources/ReporterCore/Configuration.swift index cf514e7..26d619c 100644 --- a/Sources/ReporterCore/Configuration.swift +++ b/Sources/ReporterCore/Configuration.swift @@ -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] } @@ -42,6 +53,7 @@ struct Configuration: Codable { } let mailServer: Server + let email: Email let folders: [String: Policy] init(contentsOf url: URL) throws { diff --git a/Sources/ReporterCore/Extensions/User.swift b/Sources/ReporterCore/Extensions/User.swift new file mode 100644 index 0000000..6afa81c --- /dev/null +++ b/Sources/ReporterCore/Extensions/User.swift @@ -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) + } + +} diff --git a/Sources/ReporterCore/Reporter.swift b/Sources/ReporterCore/Reporter.swift index a97d892..f2f528b 100644 --- a/Sources/ReporterCore/Reporter.swift +++ b/Sources/ReporterCore/Reporter.swift @@ -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)] From 5f32eb331d6abb1eff0a12d6285606a395d43c22 Mon Sep 17 00:00:00 2001 From: Jason Morley Date: Sat, 22 Feb 2025 08:14:37 -1000 Subject: [PATCH 2/2] Update the config example in the readme --- README.md | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index da42a78..39b984e 100644 --- a/README.md +++ b/README.md @@ -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": {},