Skip to content

Commit

Permalink
Merge pull request #3 from oposs/src_cleanup
Browse files Browse the repository at this point in the history
forward to multiple destinations
  • Loading branch information
oetiker authored Jan 9, 2023
2 parents c00acfd + 9d8c741 commit 1dbdc08
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
7 changes: 5 additions & 2 deletions cmd/config-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
33 changes: 17 additions & 16 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 1dbdc08

Please sign in to comment.