dummy.go 819 B

12345678910111213141516171819202122232425262728293031323334353637
  1. package backends
  2. import (
  3. "fmt"
  4. log "github.com/Sirupsen/logrus"
  5. guerrilla "github.com/flashmob/go-guerrilla"
  6. )
  7. func init() {
  8. backends["dummy"] = &DummyBackend{}
  9. }
  10. type DummyBackend struct {
  11. config dummyConfig
  12. }
  13. type dummyConfig struct {
  14. LogReceivedMails bool `json:"log_received_mails"`
  15. }
  16. func (b *DummyBackend) Initialize(backendConfig guerrilla.BackendConfig) error {
  17. var converted bool
  18. b.config.LogReceivedMails, converted = backendConfig["log_received_mails"].(bool)
  19. if !converted {
  20. return fmt.Errorf("failed to load backend config (%v)", backendConfig)
  21. }
  22. return nil
  23. }
  24. func (b *DummyBackend) Process(client *guerrilla.Client, user, host string) string {
  25. if b.config.LogReceivedMails {
  26. log.Infof("Mail from: %s@%s", user, host)
  27. }
  28. return fmt.Sprintf("250 OK : queued as %s", client.Hash)
  29. }