From 9d8c7416b77673561fe67b8ab3e5ad53bc308ae1 Mon Sep 17 00:00:00 2001 From: Tobias Oetiker Date: Mon, 9 Jan 2023 14:55:20 +0100 Subject: [PATCH] forward to multiple destinations --- cmd/config-schema.json | 7 +++++-- cmd/main.go | 33 +++++++++++++++++---------------- 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/cmd/config-schema.json b/cmd/config-schema.json index 5cae0e9..9983a99 100644 --- a/cmd/config-schema.json +++ b/cmd/config-schema.json @@ -109,8 +109,11 @@ "type": "string", "description": "Folder for storing the edited message" }, - "forwardCopyTo": { - "type": "string", + "forwardCopiesTo": { + "type": "array", + "items": { + "type": "string" + }, "description": "Forward the edited message to ..." }, "deleteMessage": { diff --git a/cmd/main.go b/cmd/main.go index be64eb5..81b16c5 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -49,19 +49,19 @@ type SmtpAccount struct { Server string `yaml:"server"` } type Task struct { - ImapAccount string `yaml:"imapAccount"` - SmtpAccount string `yaml:"smtpAccount"` - WatchFolder string `yaml:"watchFolder"` - SelectMessage string `yaml:"selectMessage"` - EditCopy string `yaml:"editCopy"` - StoreCopyIn string `yaml:"storeCopyIn"` - ForwardCopyTo string `yaml:"forwardCopyTo"` - DeleteMessage bool `yaml:"deleteMessage"` - RtTag string `yaml:"rtTag"` - _imapAccount ImapAccount - _smtpAccount SmtpAccount - _name string - _client *client.Client + ImapAccount string `yaml:"imapAccount"` + SmtpAccount string `yaml:"smtpAccount"` + WatchFolder string `yaml:"watchFolder"` + SelectMessage string `yaml:"selectMessage"` + EditCopy string `yaml:"editCopy"` + StoreCopyIn string `yaml:"storeCopyIn"` + ForwardCopiesTo []string `yaml:"forwardCopiesTo"` + DeleteMessage bool `yaml:"deleteMessage"` + RtTag string `yaml:"rtTag"` + _imapAccount ImapAccount + _smtpAccount SmtpAccount + _name string + _client *client.Client } // type FullMessage struct { @@ -480,8 +480,9 @@ func scanMailbox(task Task) chan error { returnPath := mr.Header.Get("Return-Path") mr.Header.Del("Return-Path") rawMessage := makeRawMessage(mr, rBody) - if task.ForwardCopyTo != "" { - sl.Infof("%s: forwarding msg to %s\n", task._name, task.ForwardCopyTo) + + if len(task.ForwardCopiesTo) > 0 { + sl.Infof("%s: forwarding msg to %s\n", task._name, strings.Join(task.ForwardCopiesTo, ", ")) if err := forwardMessage(task, rawMessage, returnPath); err != nil { sl.Infof("%s: SMTP problem: %v", task._name, err) continue @@ -534,7 +535,7 @@ func saveMessage(task Task, rawMessage *bytes.Buffer, oldFlags []string) error { func forwardMessage(task Task, rawMessage *bytes.Buffer, returnPath string) error { - return sendMail(task._smtpAccount.Server, returnPath, []string{task.ForwardCopyTo}, rawMessage.Bytes()) + return sendMail(task._smtpAccount.Server, returnPath, task.ForwardCopiesTo, rawMessage.Bytes()) } func getNextRtKey(task Task) (string, error) {