Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mox IMAP4rev2 service endpoint instance on returned bidirectional stream #120

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions imapserver/internals.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package imapserver

import (
"crypto/tls"
"net"
)

// internalsStruct exports some private top-level identifiers
type internalsStruct struct {
// LimitersInit configures mox’ connection rate limiting and max connections
LimitersInit func()
// Serve launches the mox imap server with storage using provided connection
Serve func(listenerName string, cid int64, tlsConfig *tls.Config, nc net.Conn, xtls bool, noRequireSTARTTLS bool)
}

// internalsValue exports some private top-level identifiers
var internalsValue = internalsStruct{
LimitersInit: limitersInit,
Serve: serve,
}

// Internals exports some private top-level identifiers
func Internals() (internals internalsStruct) { return internalsValue }
44 changes: 44 additions & 0 deletions imaptemp/close-oncer.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
Written 2024 by Harald Rudell <[email protected]> (https://haraldrudell.github.io/haraldrudell/)
*/

package imaptemp

import (
"net"
"sync/atomic"
)

// closeOncer ensures a net.Conn to have thread-safe idempotent observable Close
type closeOncer struct {
net.Conn
CloseWait chan struct{}
IsClosed atomic.Bool
}

// newCloseOncer returns a wrapper making the net.Conn to have thread-safe idempotent observable Close
func newCloseOncer(conn net.Conn) (c net.Conn) {
return &closeOncer{
Conn: conn,
CloseWait: make(chan struct{}),
}
}

// Close is thread-safe idempotent observable
// - only the winner thread actually closing receives a possible error
// - no thread returns prior to the connection being closed
// - Close can be awaited by <-c.CloseWait
// - Close is observable by c.IsClosed.Load()
func (c *closeOncer) Close() (err error) {
if !c.IsClosed.CompareAndSwap(false, true) {
// loser thread gets to wait
<-c.CloseWait
return
}
defer close(c.CloseWait)

// winner thread does close
err = c.Conn.Close()

return
}
21 changes: 21 additions & 0 deletions imaptemp/domains.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Domains:
mox.example:
LocalpartCaseSensitive: false
Accounts:
mjl:
Domain: mox.example
Destinations:
[email protected]: nil
""@mox.example: nil
JunkFilter:
Threshold: 0.95
Params:
Twograms: true
MaxPower: 0.1
TopWords: 10
IgnoreWords: 0.1
limit:
Domain: mox.example
Destinations:
[email protected]: nil
QuotaMessageSize: 1
Loading