Documentation
¶
Index ¶
- Constants
- Variables
- func AddRoute(host, localIp, remoteHost string, remotePort, priority int, ...) error
- func AliasAdd(alias, deliverTo, pipe string, isMiniList bool) error
- func AliasDel(alias string) error
- func AliasExists(alias string) (bool, error)
- func AutoMigrateDB(DB *gorm.DB) error
- func Bootstrap() (err error)
- func DelRoute(id int64) error
- func DkimDisable(domain string) error
- func ErrBadDsn(err error) error
- func GetBasePath() string
- func GetDsnsFromString(dsnsStr string) (dsns []dsn, err error)
- func InitBolt() error
- func InitDB(DB *gorm.DB) error
- func IpCanRelay(ip net.Addr) (bool, error)
- func IsIPV4(ip string) bool
- func IsInRcptHost(hostname string) (bool, error)
- func IsOkDB(DB *gorm.DB) bool
- func IsStringInSlice(str string, s []string) (found bool)
- func IsValidLocalRcpt(rcpt string) (bool, error)
- func LaunchDeliverd()
- func MailboxAdd(mailbox string) error
- func MailboxDel(mailbox string) error
- func MailboxExists(mailbox string) (bool, error)
- func NewClamav() *clamav
- func NewDiskStore() (*diskStore, error)
- func NewUUID() (string, error)
- func QueueAddMessage(rawMess *[]byte, envelope message.Envelope, authUser string) (uuid string, err error)
- func QueueCount() (c uint32, err error)
- func RcpthostAdd(hostname string, isLocal, isAlias bool) error
- func RcpthostDel(hostname string) error
- func RegisterDeliverdPlugin(hook string, plugin DeliverdPlugin)
- func RegisterPlugin(hook string, plugin TmailPlugin)
- func RegisterSMTPdPlugin(hook string, plugin SMTPdPlugin)
- func RelayIpAdd(ip string) error
- func RelayIpDel(ip string) error
- func RemoveBrackets(s string) string
- func StripQuotes(s string) string
- func Unix2dos(ch *[]byte) (err error)
- func UserAdd(login, passwd, mbQuota string, haveMailbox, authRelay, isCatchall bool) error
- func UserChangePassword(login, password string) error
- func UserDel(login string) error
- func UserExists(login string) (bool, error)
- type Alias
- type Config
- func (c *Config) GetBoltFile() string
- func (c *Config) GetClusterModeEnabled() bool
- func (c *Config) GetDbDriver() string
- func (c *Config) GetDbSource() string
- func (c *Config) GetDebugEnabled() bool
- func (c *Config) GetDeliverdConcurrencyLocal() int
- func (c *Config) GetDeliverdConcurrencyRemote() int
- func (c *Config) GetDeliverdDkimSign() bool
- func (c *Config) GetDeliverdQueueBouncesLifetime() int
- func (c *Config) GetDeliverdQueueLifetime() int
- func (c *Config) GetDeliverdRemoteTLSFallback() bool
- func (c *Config) GetDeliverdRemoteTLSSkipVerify() bool
- func (c *Config) GetDeliverdRemoteTimeout() int
- func (c *Config) GetDovecotLda() string
- func (c *Config) GetDovecotSupportEnabled() bool
- func (c *Config) GetHideServerSignature() bool
- func (c *Config) GetLaunchDeliverd() bool
- func (c *Config) GetLaunchSmtpd() bool
- func (c *Config) GetLocalIps() string
- func (c *Config) GetLogPath() string
- func (c *Config) GetMe() string
- func (c *Config) GetMicroservicesUri(hookId string) []string
- func (c *Config) GetNSQLookupdHttpAddresses() (addr []string)
- func (c *Config) GetNSQLookupdTcpAddresses() (addr []string)
- func (c *Config) GetOpenstackEnable() bool
- func (c *Config) GetRestServerIp() string
- func (c *Config) GetRestServerIsTls() bool
- func (c *Config) GetRestServerLaunch() bool
- func (c *Config) GetRestServerLogin() string
- func (c *Config) GetRestServerPasswd() string
- func (c *Config) GetRestServerPort() int
- func (c *Config) GetSmtpdClamavDsns() string
- func (c *Config) GetSmtpdClamavEnabled() bool
- func (c *Config) GetSmtpdConcurrencyIncoming() int
- func (c *Config) GetSmtpdDsns() string
- func (c *Config) GetSmtpdMaxBadRcptTo() int
- func (c *Config) GetSmtpdMaxDataBytes() int
- func (c *Config) GetSmtpdMaxHops() int
- func (c *Config) GetSmtpdMaxRcptTo() int
- func (c *Config) GetSmtpdMaxVrfy() int
- func (c *Config) GetSmtpdServerTimeout() int
- func (c *Config) GetStoreDriver() string
- func (c *Config) GetStoreSource() string
- func (c *Config) GetTempDir() string
- func (c *Config) GetUserMailboxDefaultQuota() string
- func (c *Config) GetUsersHomeBase() string
- func (c *Config) SetRestServerLogin(login string)
- func (c *Config) SetRestServerPasswd(passwd string)
- type DeliverdAuth
- type DeliverdPlugin
- type Delivery
- type DkimConfig
- type FileFormatter
- type Mailbox
- type NSQLogger
- type QMessage
- type RcptHost
- type RelayIpOk
- type Route
- type SMTPServerSession
- func (s *SMTPServerSession) ExitAsap()
- func (s *SMTPServerSession) GetEnvelope() *message.Envelope
- func (s *SMTPServerSession) GetLastClientCmd() []byte
- func (s *SMTPServerSession) Log(msg ...string)
- func (s *SMTPServerSession) LogDebug(msg ...string)
- func (s *SMTPServerSession) LogError(msg ...string)
- func (s *SMTPServerSession) Out(msg string)
- func (s *SMTPServerSession) Reset()
- type SMTPdPlugin
- type ServerInfo
- type Smtpd
- type Storer
- type TmailPlugin
- type User
Constants ¶
const ( // CR is a Carriage Return CR = 13 // LF is a Line Feed LF = 10 )
const ( // Time822 formt time for RFC 822 Time822 = "02 Jan 2006 15:04:05 -0700" // "02 Jan 06 15:04 -0700" )
Variables ¶
var ( // Version is tamil version Version string Cfg *Config DB *gorm.DB Bolt *bolt.DB //Log *Logger Logger *logrus.Logger NsqQueueProducer *nsq.Producer SmtpSessionsCount int ChSmtpSessionsCount chan int DeliverdConcurrencyLocalCount int DeliverdConcurrencyRemoteCount int ChDeliverdConcurrencyRemoteCount chan int Store Storer )
var DeliverdPlugins map[string][]DeliverdPlugin
DeliverdPlugins map of deliverd plugins
var ( // ErrNonAsciiCharDetected when an email body does not contain only 7 bits ascii char ErrNonAsciiCharDetected = errors.New("email must contains only 7-bit ASCII characters") )
var SMTPdPlugins map[string][]SMTPdPlugin
SMTPdPlugins is a map of SMTPd plugins
var TmailPlugins map[string][]TmailPlugin
TmailPlugins is a map of plugin
Functions ¶
func AddRoute ¶
func AddRoute(host, localIp, remoteHost string, remotePort, priority int, user, mailFrom, smtpAuthLogin, smtpAuthPasswd string) error
AddRoute add a new route
func AliasExists ¶
AliasExists checks if an alias exists
func AutoMigrateDB ¶
AutoMigrateDB will keep tables reflecting structs
func Bootstrap ¶
func Bootstrap() (err error)
Bootstrap DB, config,... TODO check validity of each element
func DkimDisable ¶
DkimDisable Disable DKIM for domain domain by removing his DkimConfig entry
func GetDsnsFromString ¶
getDsnsFromString Get dsn string from config and returns slice of dsn struct
func InitDB ¶
InitDB create tables if needed and initialize them TODO: SKIP in CLI TODO: check regularly structure & indexes
func IpCanRelay ¶
remoteIpCanUseSmtp checks if an IP can relay
func IsInRcptHost ¶
IsInRcptHost checks if domain is in the RcptHost list (-> relay authorized)
func IsStringInSlice ¶
Check if a string is in a Slice of string TODO: replace by sort package
func IsValidLocalRcpt ¶
IsValidLocalRcpt checks if rcpt is a valid local destination Mailbox (or wildcard) Alias catchall
func MailboxDel ¶
MailboxDel delete Mailbox TODO: supprimer tout ce qui est associé a cette boite
func MailboxExists ¶
MailboxExists checks if mailbox exist
func NewDiskStore ¶
func NewDiskStore() (*diskStore, error)
NewDiskStore returns a store with local disk as backend
func QueueAddMessage ¶
func QueueAddMessage(rawMess *[]byte, envelope message.Envelope, authUser string) (uuid string, err error)
QueueAddMessage add a new mail in queue
func QueueCount ¶
QueueCount rerurn the number of message in queue
func RcpthostAdd ¶
RcpthostAdd add hostname to rcpthosts
func RcpthostDel ¶
RcpthostDel delete a hostname from rcpthosts list
func RegisterDeliverdPlugin ¶
func RegisterDeliverdPlugin(hook string, plugin DeliverdPlugin)
RegisterDeliverdPlugin registers plugin for deliverd hooks
func RegisterPlugin ¶
func RegisterPlugin(hook string, plugin TmailPlugin)
RegisterPlugin registers a new plugin
func RegisterSMTPdPlugin ¶
func RegisterSMTPdPlugin(hook string, plugin SMTPdPlugin)
RegisterSMTPdPlugin registers a new smtpd plugin
func RemoveBrackets ¶
RemoveBrackets removes trailing and ending brackets (<string> -> string)
func UserChangePassword ¶
UserChangePassword is used to change user password
Types ¶
type Alias ¶
type Alias struct { ID int64 Alias string `sql:"unique"` DeliverTo string `sql:"null"` Pipe string `sql:"null"` IsDomAlias bool `sql:"default:false"` IsMiniList bool `sql:"default:false"` }
Alias represents a tmail alias
type Config ¶
Config represents tmail confiig when default is set to _ that means that the defauly value is (type)null (eg "" for string)
func (*Config) GetClusterModeEnabled ¶
GetClusterModeEnabled return clusterModeEnabled
func (*Config) GetDbDriver ¶
GetDbDriver returns database driver
func (*Config) GetDbSource ¶
GetDbSource return database source
func (*Config) GetDebugEnabled ¶
GetDebugEnabled returns debugEnabled
func (*Config) GetDeliverdConcurrencyLocal ¶
GetDeliverdMaxInFlight returns DeliverdMaxInFlight
func (*Config) GetDeliverdConcurrencyRemote ¶
GetDeliverdConcurrencyRemote returns max concurrency for deliverd remote
func (*Config) GetDeliverdDkimSign ¶
GetDeliverdDkimSign wheras deliverd must sign outgoing (remote) email
func (*Config) GetDeliverdQueueBouncesLifetime ¶
GetDeliverdQueueBouncesLifetime return DeliverdQueueBouncesLifetime
func (*Config) GetDeliverdQueueLifetime ¶
GetDeliverdQueueLifetime return queue lifetime in minutes
func (*Config) GetDeliverdRemoteTLSFallback ¶
GetDeliverdRemoteTLSFallback return DeliverdRemoteTLSFallback
func (*Config) GetDeliverdRemoteTLSSkipVerify ¶
GetDeliverdRemoteTLSSkipVerify return DeliverdRemoteTLSSkipVerify
func (*Config) GetDeliverdRemoteTimeout ¶
GetDeliverdRemoteTimeout return remote timeout in second time to wait for a response from remote server before closing conn
func (*Config) GetDovecotLda ¶
GetDovecotLda returns path to dovecot-lda binary
func (*Config) GetDovecotSupportEnabled ¶
GetDovecotSupportEnabled returns DovecotSupportEnabled
func (*Config) GetHideServerSignature ¶
GetHideServerSignature HideServerSignature
func (*Config) GetLaunchDeliverd ¶
GetLaunchDeliverd returns true if deliverd have to be launched
func (*Config) GetLaunchSmtpd ¶
GetLaunchSmtpd returns true if smtpd have to be launched
func (*Config) GetLocalIps ¶
GetLocalIps returns ordered lits of local IP (net.IP) to use when sending mail
func (*Config) GetMicroservicesUri ¶
GetMicroservicesUri returns defined URI for a hookId
func (*Config) GetNSQLookupdHttpAddresses ¶
GetNSQLookupdHttpAddresses returns lookupd HTTP adresses
func (*Config) GetNSQLookupdTcpAddresses ¶
GetNSQLookupdTcpAddresses returns lookupd tcp adresses
func (*Config) GetOpenstackEnable ¶
GetOpenstackEnable returns if openstack support is enabled
func (*Config) GetRestServerIp ¶
GetRestServerIp return the ip that the REST server should listen on
func (*Config) GetRestServerIsTls ¶
GetRestServerIsTls return RestServerIsTls
func (*Config) GetRestServerLaunch ¶
GetRestServerLaunch return true if REST server must be launched
func (*Config) GetRestServerLogin ¶
GetRestServerLogin return RestServerLogin
func (*Config) GetRestServerPasswd ¶
GetRestServerPasswd return RestServerPasswd
func (*Config) GetRestServerPort ¶
GetRestServerPort return the port that the REST server should listen on
func (*Config) GetSmtpdClamavDsns ¶
GetSmtpdClamavDsns returns clamav dsns
func (*Config) GetSmtpdClamavEnabled ¶
GetSmtpdClamavEnabled returns if clamav scan is enable
func (*Config) GetSmtpdConcurrencyIncoming ¶
GetSmtpdConcurrencyIncoming returns ConcurrencyIncoming
func (*Config) GetSmtpdDsns ¶
GetSmtpdDsns returns smtpd dsns
func (*Config) GetSmtpdMaxBadRcptTo ¶
GetSmtpdMaxBadRcptTo returns the maximum number of bad RCPT TO commands
func (*Config) GetSmtpdMaxDataBytes ¶
GetSmtpdMaxDataBytes returns max size of accepted email
func (*Config) GetSmtpdMaxHops ¶
GetSmtpdMaxHops returns the number of relay a mail can traverser
func (*Config) GetSmtpdMaxRcptTo ¶
GetSmtpdMaxRcptTo returns the maximum number of RCPT TO commands
func (*Config) GetSmtpdMaxVrfy ¶
GetSmtpdMaxVrfy return GetSmtpdMaxVrfy
func (*Config) GetSmtpdServerTimeout ¶
GetSmtpdTransactionTimeout return smtpdTransactionTimeout
func (*Config) GetStoreDriver ¶
GetStoreDriver return source driver disk runabove
func (*Config) GetStoreSource ¶
GetStoreSource return store source
func (*Config) GetUserMailboxDefaultQuota ¶
func GetUserMailboxDefaultQuota return the default mailbox quota
func (*Config) GetUsersHomeBase ¶
GetUsersHomeBase returns users home base
func (*Config) SetRestServerLogin ¶
SetRestServerLogin is used to set REST server login
func (*Config) SetRestServerPasswd ¶
SetRestServerPasswd set RestServerPasswd
type DeliverdAuth ¶
type DeliverdAuth interface { // Start begins an authentication with a server. // It returns the name of the authentication protocol // and optionally data to include in the initial AUTH message // sent to the server. It can return proto == "" to indicate // that the authentication should be skipped. // If it returns a non-nil error, the SMTP client aborts // the authentication attempt and closes the connection. Start(server *ServerInfo) (proto string, toServer []byte, err error) // Next continues the authentication. The server has just sent // the fromServer data. If more is true, the server expects a // response, which Next should return as toServer; otherwise // Next should return toServer == nil. // If Next returns a non-nil error, the SMTP client aborts // the authentication attempt and closes the connection. Next(fromServer []byte, more bool) (toServer []byte, err error) }
Auth is implemented by an SMTP authentication mechanism.
func CRAMMD5Auth ¶
func CRAMMD5Auth(username, secret string) DeliverdAuth
CRAMMD5Auth returns an Auth that implements the CRAM-MD5 authentication mechanism as defined in RFC 2195. The returned Auth uses the given username and secret to authenticate to the server using the challenge-response mechanism.
func PlainAuth ¶
func PlainAuth(identity, username, password, host string) DeliverdAuth
PlainAuth returns an Auth that implements the PLAIN authentication mechanism as defined in RFC 4616. The returned Auth uses the given username and password to authenticate on TLS connections to host and act as identity. Usually identity will be left blank to act as username.
type DeliverdPlugin ¶
DeliverdPlugin type for deliverd plugin
type Delivery ¶
type Delivery struct { ID string NSQMsg *nsq.Message QMsg *QMessage RawData *[]byte QStore Storer StartAt time.Time IsLocal bool LocalAddr string RemoteRoutes []Route RemoteAddr string RemoteSMTPresponseCode int Success bool }
Delivery is a deliver process
type DkimConfig ¶
type DkimConfig struct { Id int64 Domain string PubKey string `sql:"type:text;"` PrivKey string `sql:"type:text;"` Selector string Headers string }
DkimConfig represents DKIM configuration for a domain
func DkimEnable ¶
func DkimEnable(domain string) (dkc *DkimConfig, err error)
DkimEnable enabled DKIM on domain
func DkimGetConfig ¶
func DkimGetConfig(domain string) (dkc *DkimConfig, err error)
DkimGetConfig returns DKIM config for domain domain
type FileFormatter ¶
type FileFormatter struct { // Set to true to bypass checking for a TTY before outputting colors. ForceColors bool // Force disabling colors. DisableColors bool // Disable timestamp logging. useful when output is redirected to logging // system that already adds timestamps. DisableTimestamp bool // Enable logging the full timestamp when a TTY is attached instead of just // the time passed since beginning of execution. FullTimestamp bool // TimestampFormat to use for display when a full timestamp is printed TimestampFormat string // The fields are sorted by default for a consistent output. For applications // that log extremely frequently and don't use the JSON formatter this may not // be desired. DisableSorting bool }
type Mailbox ¶
func MailboxList ¶
MailboxList return all mailboxes
type QMessage ¶
type QMessage struct { sync.Mutex Id int64 Uuid string // Unique ID common to all QMessage, representing the queued ID of the message MailFrom string AuthUser string // Si il y a eu authentification SMTP contient le login/user sert pour le routage RcptTo string MessageId string Host string LastUpdate time.Time AddedAt time.Time NextDeliveryScheduledAt time.Time Status uint32 // 0 delivery in progress, 1 to be discarded, 2 scheduled, 3 to be bounced DeliveryFailedCount uint32 }
QMessage represents a message in queue
func QueueGetExpiredMessages ¶
QueueGetExpiredMessages return expired messages from DB
func QueueGetMessageById ¶
QueueGetMessageById return a message from is key
func QueueListMessages ¶
QueueListMessages return all messages in queue
func (*QMessage) UpdateFromDb ¶
UpdateFromDb update message from DB
type RcptHost ¶
type RcptHost struct { Id int64 Hostname string `sql:"unique"` IsLocal bool `sql:"default:false"` IsAlias bool `sql:"default:false"` }
RcptHost represents a hostname that tmail have to handle mails for (=local domains)
func RcpthostGet ¶
RcpthostGet return a rcpthost
func RcpthostGetAll ¶
RcpthostGetAll return hostnames in rcpthosts
type RelayIpOk ¶
relayOkIp represents an IP that can use SMTP for relaying
func RelayIpGetAll ¶
RelayIpList return all IPs authorized to relay through tmail
type Route ¶
type Route struct { Id int64 Host string `sql:not null` // destination LocalIp sql.NullString RemoteHost string `sql:not null` RemotePort sql.NullInt64 Priority sql.NullInt64 SmtpAuthLogin sql.NullString SmtpAuthPasswd sql.NullString MailFrom sql.NullString User sql.NullString }
Route represents a route in DB
func GetAllRoutes ¶
GetAllRoutes returns all routes (really ?!)
type SMTPServerSession ¶
type SMTPServerSession struct { Conn net.Conn RelayGranted bool Envelope message.Envelope LastRcptTo string BadRcptToCount int SMTPResponseCode uint32 CurrentRawMail []byte // contains filtered or unexported fields }
SMTPServerSession retpresents a SMTP session (server)
func NewSMTPServerSession ¶
func NewSMTPServerSession(conn net.Conn, isTLS bool) (sss *SMTPServerSession, err error)
NewSMTPServerSession returns a new SMTP session
func (*SMTPServerSession) ExitAsap ¶
func (s *SMTPServerSession) ExitAsap()
ExitAsap exist session as soon as possible
func (*SMTPServerSession) GetEnvelope ¶
func (s *SMTPServerSession) GetEnvelope() *message.Envelope
GetEnvelope returns pointer to current envelope mainly used for plugin
func (*SMTPServerSession) GetLastClientCmd ¶
func (s *SMTPServerSession) GetLastClientCmd() []byte
GetLastClientCmd returns lastClientCmd (not splited)
func (*SMTPServerSession) Log ¶
func (s *SMTPServerSession) Log(msg ...string)
Log helper for INFO log
func (*SMTPServerSession) LogDebug ¶
func (s *SMTPServerSession) LogDebug(msg ...string)
LogDebug is a log helper for DEBUG logs
func (*SMTPServerSession) LogError ¶
func (s *SMTPServerSession) LogError(msg ...string)
LogError is a log helper for ERROR logs
type SMTPdPlugin ¶
type SMTPdPlugin func(s *SMTPServerSession) bool
SMTPdPlugin is the type for SMTPd plugins
type ServerInfo ¶
type ServerInfo struct { //Address net.TCPAddr // SMTP adrress Name string // SMTP server name TLS bool // using TLS, with valid certificate for Name Auth []string // advertised authentication mechanisms }
ServerInfo records information about an SMTP server.
type Storer ¶
type Storer interface { //TODO should return perm or temp failure Get(key string) (io.Reader, error) Put(key string, reader io.Reader) error Del(key string) error }
Storer is a interface for stores
type User ¶
type User struct { Id int64 Login string `sql:"unique"` Passwd string `sql:"not null"` DovePasswd string `sql:"null"` // SHA512 passwd workaround (glibc on most linux flavor doesn't have bcrypt support) Active string `sql:"type:char(1);default:'Y'"` //rune `sql:"type:char(1);not null;default:'Y'` AuthRelay bool `sql:"default:false"` // authorization of relaying HaveMailbox bool `sql:"default:false"` IsCatchall bool `sql:"default:false"` MailboxQuota string `sql:"null"` Home string `sql:"null"` // used by dovecot to store mailbox }
User represents a tmail user.
func UserGetByLogin ¶
UserGetByLogin return an user from his login
func UserGetCatchallForDomain ¶
UserGetCatchallForDomain return catchall
func (*User) ChangePasswd ¶
ChangePasswd is used to change user password
Source Files
¶
- alias.go
- clamav.go
- config.go
- database.go
- deliverd.go
- deliverd_auth.go
- deliverd_delivery.go
- deliverd_handler.go
- deliverd_local.go
- deliverd_remote.go
- deliverd_route.go
- dkim.go
- errors.go
- file_formatter.go
- local.go
- logger.go
- mailbox.go
- mailqueue.go
- plugin.go
- rcpthost.go
- scope.go
- smtp_client.go
- smtpd.go
- smtpd_dsn.go
- smtpd_relay_ip.go
- smtpd_session.go
- smtpd_user.go
- smtproutes.go
- store.go
- store_disk.go
- store_openstack.go
- tls.go
- user.go
- utils.go
- uuid.go