Author: Adam <git@apiote.xyz>
add empty function for forwarding messages in mímir
config_example.dirty | 4 ++++ imap.go | 8 +++++++- main.go | 4 ++++ mímir.go | 5 ++++-
diff --git a/config_example.dirty b/config_example.dirty index 67061ae3dc80044e505f90d773624f1c6722dc58..46c016fc3d578cd7fc21edf14fa1d1c3d3209072 100644 --- a/config_example.dirty +++ b/config_example.dirty @@ -36,6 +36,10 @@ ('imapPassword' '') ('imapInbox' 'Inbox') ('recipientTemplate' '[:]@exmaple.com') ('categories' ('cars', 'music')) + ('forwardAddress' 'user+[:]@exmaple.com') + ('personalAddress' 'user@example.com') + ('smtpAddress' '') + ('smtpSender' '') ) ) ) diff --git a/imap.go b/imap.go index 558b05ce07e2589fb9f311a943df90c6e15c1a87..a0471ff6392bb59c4d770b78d28b9aa8ff053d90 100644 --- a/imap.go +++ b/imap.go @@ -19,7 +19,7 @@ func moveMultiple(c *client.Client, seqSet *imap.SeqSet, dest string) error { moveClient := move.NewClient(c) if !seqSet.Empty() { - log.Println("moving multiple to "+dest) + log.Println("moving multiple to " + dest) err := moveClient.UidMoveWithFallback(seqSet, dest) return err } @@ -66,3 +66,9 @@ func sendQuarantine(address *imap.Address) { // todo log.Printf("sending quarantine to %s\n", address.Address()) } + +func forwardMessage(config Config, category string, replyTo []string, messageID, inReplyTo, subject string, body []byte) { + //todo set recipient as config.Mímir.PersonalAddress with [:] replaced with category + //todo login to smtp with smtpAddress, imapUsername, imapPassword + //todo send mail with subject, messageID, inReplyTo, body; to recipient; from smtpSender +} diff --git a/main.go b/main.go index 58b6335bd39d3655bce3b408ae09efba32d0144a..9088a9409b5a561b0c04f06af8afb341a79dfcfa 100644 --- a/main.go +++ b/main.go @@ -39,6 +39,10 @@ ImapPassword string ImapInbox string RecipientTemplate string Categories []string + ForwardAddress string + PersonalAddress string + SmtpAddress string + SmtpSender string } type Config struct { diff --git a/mímir.go b/mímir.go index aba05f8985932247021fc3fa91f51c631e853013..93e716a624aa2af12a68576576b14f7699930328 100644 --- a/mímir.go +++ b/mímir.go @@ -23,7 +23,7 @@ categories := config.Mímir.Categories if len(categories) == 0 { return "", nil } - parts := strings.SplitN(config.Mímir.RecipientTemplate, "[:]", 2) + parts := strings.SplitN(config.Mímir.RecipientTemplate, "[:]", 2) // todo if [:] not found r, err := regexp.Compile(parts[0] + "(.*)" + parts[1]) if err != nil { return "", err @@ -136,6 +136,9 @@ return err } addArchiveEntry(db, messageID, category, subject, body, date, inReplyTo, dkimStatus, sender, recipients) + if sender.Address() != config.Mímir.PersonalAddress { // todo if forwarding is on + forwardMessage(config, category, []string{sender.Address(), strings.Replace(config.Mímir.RecipientTemplate, "[:]", category, 1)}, messageID, inReplyTo, subject, body) + } } if err := <-done; err != nil {