Package opensmtpd implements OpenSMTPD-extras in Go https://godoc.org/pkg/maze.io/x/opensmtpd
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

smtpd.go 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. package opensmtpd
  2. import (
  3. "fmt"
  4. "os"
  5. "strings"
  6. )
  7. const (
  8. // FilterVersion is the supported filter API version
  9. FilterVersion = 52
  10. // QueueVersion is the supported queue API version
  11. QueueVersion = 2
  12. // TableVersion is the supported table API version
  13. TableVersion = 2
  14. )
  15. var (
  16. // Debug flag
  17. Debug bool
  18. prog = os.Args[0]
  19. )
  20. // Services
  21. const (
  22. ServiceNone = 0x000
  23. ServiceAlias = 0x001
  24. ServiceDomain = 0x002
  25. ServiceCredentials = 0x004
  26. ServiceNetaddr = 0x008
  27. ServiceUserinfo = 0x010
  28. ServiceSource = 0x020
  29. ServiceMailaddr = 0x040
  30. ServiceAddrname = 0x080
  31. ServiceMailaddrMap = 0x100
  32. ServiceRelayHost = 0x200
  33. ServiceString = 0x400
  34. ServiceAny = 0xfff
  35. )
  36. var serviceTypeName = map[int]string{
  37. ServiceAlias: "alias",
  38. ServiceDomain: "domain",
  39. ServiceCredentials: "credentials",
  40. ServiceNetaddr: "netaddr",
  41. ServiceUserinfo: "userinfo",
  42. ServiceSource: "source",
  43. ServiceMailaddr: "mailaddr",
  44. ServiceAddrname: "addrname",
  45. ServiceMailaddrMap: "maddrmap",
  46. ServiceRelayHost: "relayhost",
  47. ServiceString: "string",
  48. }
  49. func serviceName(service int) string {
  50. var s []string
  51. for i := 1; i <= service; i <<= 1 {
  52. if k := service & i; k != 0 {
  53. s = append(s, serviceTypeName[k])
  54. }
  55. }
  56. return strings.Join(s, ",")
  57. }
  58. func debugf(format string, v ...interface{}) {
  59. if !Debug {
  60. return
  61. }
  62. line := strings.TrimSuffix(fmt.Sprintf(format, v...), "\n")
  63. fmt.Fprintln(os.Stderr, prog+": debug: "+line)
  64. }
  65. func fatal(v ...interface{}) {
  66. line := strings.TrimSuffix(fmt.Sprint(v...), "\n")
  67. fmt.Fprintln(os.Stderr, prog+": "+line)
  68. os.Exit(1)
  69. }
  70. func fatalf(format string, v ...interface{}) {
  71. line := strings.TrimSuffix(fmt.Sprintf(format, v...), "\n")
  72. fmt.Fprintln(os.Stderr, prog+": "+line)
  73. os.Exit(1)
  74. }
  75. const (
  76. maxLineSize = 2048
  77. )
  78. // Dict is a key-value mapping
  79. type Dict map[string]interface{}