1
0
mirror of https://blitiri.com.ar/repos/chasquid synced 2026-01-04 17:27:02 +00:00

aliases: Implement aliases hooks

This patch implements two new hooks: alias-resolve and alias-exists.

They are called during the aliases resolution process, to allow for more
complex integration with other systems, such as storing the aliases in a
database.

See the included documentation for more details.
This commit is contained in:
Alberto Bertogli
2019-10-22 22:05:09 +01:00
parent dea6f73164
commit f399fe3e84
8 changed files with 253 additions and 36 deletions

View File

@@ -7,6 +7,7 @@ import (
"net"
"net/http"
"net/textproto"
"path"
"time"
"blitiri.com.ar/go/chasquid/internal/aliases"
@@ -67,8 +68,8 @@ type Server struct {
// Queue where we put incoming mail.
queue *queue.Queue
// Path to the Post-DATA hook.
PostDataHook string
// Path to the hooks.
HookPath string
}
// NewServer returns a new empty Server.
@@ -130,6 +131,8 @@ func (s *Server) SetAuthFallback(be auth.Backend) {
func (s *Server) SetAliasesConfig(suffixSep, dropChars string) {
s.aliasesR.SuffixSep = suffixSep
s.aliasesR.DropChars = dropChars
s.aliasesR.ResolveHook = path.Join(s.HookPath, "alias-resolve")
s.aliasesR.ExistsHook = path.Join(s.HookPath, "alias-exists")
}
// InitDomainInfo initializes the domain info database.
@@ -231,6 +234,8 @@ func (s *Server) serve(l net.Listener, mode SocketMode) {
l = tls.NewListener(l, s.tlsConfig)
}
pdhook := path.Join(s.HookPath, "post-data")
for {
conn, err := l.Accept()
if err != nil {
@@ -240,7 +245,7 @@ func (s *Server) serve(l net.Listener, mode SocketMode) {
sc := &Conn{
hostname: s.Hostname,
maxDataSize: s.MaxDataSize,
postDataHook: s.PostDataHook,
postDataHook: pdhook,
conn: conn,
tc: textproto.NewConn(conn),
mode: mode,