Documentation
¶
Index ¶
- Constants
- Variables
- func GetBlacklistLookupName(suspectIP, blLookupDomain string) (string, error)
- func GetFromAddressWithDmarcWorkaround(fromAddr string, randNum int) string
- func GetMailAddressComponents(addr string) (name, domain string)
- func IsDmarcPolicyEnforcing(domain string) bool
- func IsIPBlacklistIndication(ip net.IP) bool
- func IsSuspectIPBlacklisted(suspectIP string) string
- func TestSMTPD(smtpd *Daemon, t testingstub.T)
- func WithHeaderFromAddr(mail []byte, newFromAddr string) []byte
- type Daemon
- func (daemon *Daemon) GetTCPStatsCollector() *misc.Stats
- func (daemon *Daemon) HandleTCPConnection(logger *lalog.Logger, ip string, client *net.TCPConn)
- func (daemon *Daemon) Initialise() error
- func (daemon *Daemon) ProcessMail(clientIP, fromAddr, mailBody string)
- func (daemon *Daemon) StartAndBlock() (err error)
- func (daemon *Daemon) Stop()
Constants ¶
const ( IOTimeoutSec = 60 // IO timeout for both read and write operations MaxConversationLength = 256 // Only converse up to this number of exchanges in an SMTP connection MaxNumRecipients = 100 // MaxNumRecipients is the maximum number of recipients an SMTP conversation will accept )
const (
// DNSBlackListQueryTimeoutSec is the number of seconds to be used as timeout when querying a DNS-based blacklist lookup server.
DNSBlackListQueryTimeoutSec = 3
)
const DmarcWorkaroundDomainLabel = "laitos-nodmarc"
DmarcWorkaroundDomainLabel is a short string added to mail's From domain name when the domain has strong DMARC verification requirement. By adding the label to the domain name, the recipient's MTA will not perform a DMARC verification that would otherwise fail for the genuine domain name and lead to rejected delivery, hence improving the chance of mail delivery at the expense of sacrificing message authenticity.
Variables ¶
var ( // SpamBlacklistLookupServers is a list of domain names that provide email spam reporting and blacklist look-up services. // Each of the domain name offers a DNS-based blacklist look-up service. By appending the reversed IPv4 address to any of // the domain names (e.g. resolve 4.3.2.1.domain.net to check blacklist status of 1.2.3.4), the success of DNS resolution // will indictate that the IP address has been blacklisted for spamming. SpamBlacklistLookupServers = []string{ "b.barracudacentral.org", "cbl.abuseat.org", "dnsbl-1.uceprotect.net", "dnsbl-2.uceprotect.net", "dnsbl-3.uceprotect.net", "spam.dnsbl.sorbs.net", "ix.dnsbl.manitu.net", "truncate.gbudb.net", "zen.spamhaus.org", "noptr.spamrats.com", "spam.spamrats.com", "spam.dnsbl.anonmails.de", "psbl.surriel.com", "z.mailspike.net", "bl.mailspike.net", "dnsbl.kempt.net", } )
Functions ¶
func GetBlacklistLookupName ¶
GetBlacklistLookupName returns a DNS name constructed from a combination of the suspect IP and blacklist lookup domain name. For example, in order to look-up a suspect IP 1.2.3.4 using blacklist look-up domain bl.spamcop.net, the function will return "4.3.2.1.bl.spamcop.net". The caller should then attempt to resolve the A record of the returned name. If the resolution is successful, then the suspect IP has been blacklisted by the look-up domain.
func GetFromAddressWithDmarcWorkaround ¶
GetFromAddressWithDmarcWorkaround returns an altered mail From address that comes with extra string and random number in its domain name portion. The modification is only appled when the original domain name enforces DMARC verification. The modified domain name prevents the recipient of this mail from performing DMARC verification, which means, laitos has a better chance at delivering this mail to the recipient, at the expense of sacrificing message authenticity. If the domain name does not enforce DMARC verification, the function will return the verbatim address.
func GetMailAddressComponents ¶
GetMailAddressComponents returns the mail address (e.g. "name@example.com") broken down into its name and domain name components. If a component is not present in the input address, the function will return an empty string for that component.
func IsDmarcPolicyEnforcing ¶
IsDmarcPolicyEnforcing returns true only if the domain name demands quarantine or rejection from failed DMARC verification. If DMARC policy cannot be determined, the function will return false.
func IsIPBlacklistIndication ¶
IsIPBlacklistIndication inspects the IP address resolved from blacklist and returns true only if the IP address is a positive indication of blacklisting, that is, the IP is in the range of 127.0.0.0/16.
func IsSuspectIPBlacklisted ¶
IsSuspectIPBlacklisted looks up the suspect IP from all sources of spam blacklists. If the suspect IP is blacklisted by any of the spam blacklists, then the function will return the domain name of the DNSBL. If the suspect IP is not blacklisted or due to network error the blacklist status cannot be determined, then the function will return an empty string.
func TestSMTPD ¶
func TestSMTPD(smtpd *Daemon, t testingstub.T)
Run unit tests on Daemon. See TestSMTPD_StartAndBlock for daemon setup.
func WithHeaderFromAddr ¶
WithHeaderFromAddr changes the "From:" header value into the input string and returns the new message.
Types ¶
type Daemon ¶
type Daemon struct { Address string `json:"Address"` // Address is the TCP address listen to, e.g. 0.0.0.0 for all network interfaces. Port int `json:"Port"` // Port number to listen on. TLSCertPath string `json:"TLSCertPath"` // TLSCertPath is the path to server's TLS certificate for StartTLS operation. This is optional. TLSKeyPath string `json:"TLSKeyPath"` // TLSCertPath is the path to server's TLS certificate key for StartTLS operation. This is optional. PerIPLimit int `json:"PerIPLimit"` // PerIPLimit is the maximum number of approximately how many concurrent users are expected to be using the server from same IP address // MyDomains is an array of domain names that this SMTP server receives mails for. Mails addressed to domain names other than these will be rejected. MyDomains []string `json:"MyDomains"` // ForwardTo are the recipients (email addresses) to receive emails that are delivered to this SMTP server. ForwardTo []string `json:"ForwardTo"` CommandRunner *mailcmd.CommandRunner `json:"-"` // Process feature commands from incoming mails ForwardMailClient inet.MailClient `json:"-"` // ForwardMailClient is used to forward arriving emails. // contains filtered or unexported fields }
Daemon implements an SMTP server that receives mails addressed to configured set of domain names, and optionally forward the received mails to other addresses.
func (*Daemon) GetTCPStatsCollector ¶
GetTCPStatsCollector returns the stats collector that counts and times client connections for the TCP application.
func (*Daemon) HandleTCPConnection ¶
HandleTCPConnection converses with the SMTP client. The client connection is closed by server upon returning from the implementation.
func (*Daemon) Initialise ¶
Check configuration and initialise internal states.
func (*Daemon) ProcessMail ¶
Unconditionally forward the mail to forward addresses, then process feature commands if they are found.
func (*Daemon) StartAndBlock ¶
You may call this function only after having called Initialise()! Start SMTP daemon and block until daemon is told to stop.