base.go 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package match
  2. import (
  3. "github.com/Jinnrry/pmail/dto/parsemail"
  4. "github.com/Jinnrry/pmail/utils/context"
  5. )
  6. const (
  7. RuleTypeRegex = "regex"
  8. RuleTypeContains = "contains"
  9. RuleTypeEq = "equal"
  10. )
  11. type Match interface {
  12. Match(ctx *context.Context, email *parsemail.Email) bool
  13. }
  14. func buildUsers(users []*parsemail.User) string {
  15. ret := ""
  16. for i, u := range users {
  17. if i != 0 {
  18. ret += ","
  19. }
  20. ret += u.EmailAddress
  21. }
  22. return ret
  23. }
  24. func getFieldContent(field string, email *parsemail.Email) string {
  25. switch field {
  26. case "ReplyTo":
  27. return buildUsers(email.ReplyTo)
  28. case "From":
  29. return email.From.EmailAddress
  30. case "Subject":
  31. return email.Subject
  32. case "To":
  33. return buildUsers(email.To)
  34. case "Bcc":
  35. return buildUsers(email.Bcc)
  36. case "Cc":
  37. return buildUsers(email.Cc)
  38. case "Text":
  39. return string(email.Text)
  40. case "Html":
  41. return string(email.HTML)
  42. case "Sender":
  43. return email.Sender.EmailAddress
  44. case "Content":
  45. b := string(email.HTML)
  46. b2 := string(email.Text)
  47. return b + b2
  48. }
  49. return ""
  50. }