12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- package backends
- import (
- "github.com/flashmob/go-guerrilla/mail"
- "strings"
- )
- // ----------------------------------------------------------------------------------
- // Processor Name: debugger
- // ----------------------------------------------------------------------------------
- // Description : Log received emails
- // ----------------------------------------------------------------------------------
- // Config Options: log_received_mails bool - log if true
- // --------------:-------------------------------------------------------------------
- // Input : e.MailFrom, e.RcptTo, e.Header
- // ----------------------------------------------------------------------------------
- // Output : none (only output to the log if enabled)
- // ----------------------------------------------------------------------------------
- func init() {
- processors[strings.ToLower(defaultProcessor)] = func() Decorator {
- return Debugger()
- }
- }
- type debuggerConfig struct {
- LogReceivedMails bool `json:"log_received_mails"`
- }
- func Debugger() Decorator {
- var config *debuggerConfig
- initFunc := InitializeWith(func(backendConfig BackendConfig) error {
- configType := BaseConfig(&debuggerConfig{})
- bcfg, err := Svc.ExtractConfig(backendConfig, configType)
- if err != nil {
- return err
- }
- config = bcfg.(*debuggerConfig)
- return nil
- })
- Svc.AddInitializer(initFunc)
- return func(p Processor) Processor {
- return ProcessWith(func(e *mail.Envelope, task SelectTask) (Result, error) {
- if task == TaskSaveMail {
- if config.LogReceivedMails {
- Log().Infof("Mail from: %s / to: %v", e.MailFrom.String(), e.RcptTo)
- Log().Info("Headers are:", e.Header)
- }
- // continue to the next Processor in the decorator stack
- return p.Process(e, task)
- } else {
- return p.Process(e, task)
- }
- })
- }
- }
|