smtpd

package
v0.0.0-...-44b4573 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 31, 2024 License: MPL-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
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
)
View Source
const (
	// DNSBlackListQueryTimeoutSec is the number of seconds to be used as timeout when querying a DNS-based blacklist lookup server.
	DNSBlackListQueryTimeoutSec = 3
)
View Source
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

View Source
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

func GetBlacklistLookupName(suspectIP, blLookupDomain string) (string, error)

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

func GetFromAddressWithDmarcWorkaround(fromAddr string, randNum int) string

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

func GetMailAddressComponents(addr string) (name, domain string)

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

func IsDmarcPolicyEnforcing(domain string) bool

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

func IsIPBlacklistIndication(ip net.IP) bool

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

func IsSuspectIPBlacklisted(suspectIP string) string

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

func WithHeaderFromAddr(mail []byte, newFromAddr string) []byte

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

func (daemon *Daemon) GetTCPStatsCollector() *misc.Stats

GetTCPStatsCollector returns the stats collector that counts and times client connections for the TCP application.

func (*Daemon) HandleTCPConnection

func (daemon *Daemon) HandleTCPConnection(logger *lalog.Logger, ip string, client *net.TCPConn)

HandleTCPConnection converses with the SMTP client. The client connection is closed by server upon returning from the implementation.

func (*Daemon) Initialise

func (daemon *Daemon) Initialise() error

Check configuration and initialise internal states.

func (*Daemon) ProcessMail

func (daemon *Daemon) ProcessMail(clientIP, fromAddr, mailBody string)

Unconditionally forward the mail to forward addresses, then process feature commands if they are found.

func (*Daemon) StartAndBlock

func (daemon *Daemon) StartAndBlock() (err error)

You may call this function only after having called Initialise()! Start SMTP daemon and block until daemon is told to stop.

func (*Daemon) Stop

func (daemon *Daemon) Stop()

If SMTP daemon has started (i.e. listener is set), close the listener so that its connection loop will terminate.

Directories

Path Synopsis
smtp package implements a rather forgiving TCP server that carries on and decodes an SMTP conversation.
smtp package implements a rather forgiving TCP server that carries on and decodes an SMTP conversation.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL