1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245
|
package gluon
import (
"crypto/tls"
"io"
"time"
"github.com/ProtonMail/gluon/async"
"github.com/ProtonMail/gluon/db"
"github.com/ProtonMail/gluon/imap"
limits2 "github.com/ProtonMail/gluon/limits"
"github.com/ProtonMail/gluon/profiling"
"github.com/ProtonMail/gluon/reporter"
"github.com/ProtonMail/gluon/store"
"github.com/ProtonMail/gluon/version"
)
// Option represents a type that can be used to configure the server.
type Option interface {
config(*serverBuilder)
}
// WithDelimiter instructs the server to use the given path delimiter instead of the default ('/').
func WithDelimiter(delimiter string) Option {
return &withDelimiter{
delimiter: delimiter,
}
}
type withDelimiter struct {
delimiter string
}
func (opt withDelimiter) config(builder *serverBuilder) {
builder.delim = opt.delimiter
}
// WithLoginJailTime instructs the server to use the given login jail time.
func WithLoginJailTime(loginJailTime time.Duration) Option {
return &withLoginJailTime{
loginJailTime: loginJailTime,
}
}
func (opt withLoginJailTime) config(builder *serverBuilder) {
builder.loginJailTime = opt.loginJailTime
}
type withLoginJailTime struct {
loginJailTime time.Duration
}
// WithTLS instructs the server to use the given TLS config.
func WithTLS(cfg *tls.Config) Option {
return &withTLS{
cfg: cfg,
}
}
type withTLS struct {
cfg *tls.Config
}
func (opt withTLS) config(builder *serverBuilder) {
builder.tlsConfig = opt.cfg
}
// WithIdleBulkTime instructs the server to use the given IDLE bulk time.
func WithIdleBulkTime(idleBulkTime time.Duration) Option {
return &withIdleBulkTime{
idleBulkTime: idleBulkTime,
}
}
type withIdleBulkTime struct {
idleBulkTime time.Duration
}
func (opt withIdleBulkTime) config(builder *serverBuilder) {
builder.idleBulkTime = opt.idleBulkTime
}
// WithLogger instructs the server to write incoming and outgoing IMAP communication to the given io.Writers.
func WithLogger(in, out io.Writer) Option {
return &withLogger{
in: in,
out: out,
}
}
type withLogger struct {
in, out io.Writer
}
func (opt withLogger) config(builder *serverBuilder) {
builder.inLogger = opt.in
builder.outLogger = opt.out
}
type withVersionInfo struct {
versionInfo version.Info
}
func (vi *withVersionInfo) config(builder *serverBuilder) {
builder.versionInfo = vi.versionInfo
}
func WithVersionInfo(
vmajor, vminor, vpatch int,
name, vendor, supportURL string,
) Option {
return &withVersionInfo{
versionInfo: version.Info{
Name: name,
Version: version.Version{
Major: vmajor,
Minor: vminor,
Patch: vpatch,
},
Vendor: vendor,
SupportURL: supportURL,
},
}
}
type withCmdExecProfiler struct {
builder profiling.CmdProfilerBuilder
}
func (c *withCmdExecProfiler) config(builder *serverBuilder) {
builder.cmdExecProfBuilder = c.builder
}
// WithCmdProfiler allows a specific CmdProfilerBuilder to be set for the server's execution.
func WithCmdProfiler(builder profiling.CmdProfilerBuilder) Option {
return &withCmdExecProfiler{builder: builder}
}
type withStoreBuilder struct {
builder store.Builder
}
func (w *withStoreBuilder) config(builder *serverBuilder) {
builder.storeBuilder = w.builder
}
func WithStoreBuilder(builder store.Builder) Option {
return &withStoreBuilder{builder: builder}
}
type withDataDir struct {
path string
}
func (w *withDataDir) config(builder *serverBuilder) {
builder.dataDir = w.path
}
func WithDataDir(path string) Option {
return &withDataDir{path: path}
}
type withDatabaseDir struct {
path string
}
func (w *withDatabaseDir) config(builder *serverBuilder) {
builder.databaseDir = w.path
}
func WithDatabaseDir(path string) Option {
return &withDatabaseDir{path: path}
}
type withReporter struct {
reporter reporter.Reporter
}
func (w *withReporter) config(builder *serverBuilder) {
builder.reporter = w.reporter
}
func WithReporter(reporter reporter.Reporter) Option {
return &withReporter{reporter: reporter}
}
type withDisableParallelism struct{}
func (withDisableParallelism) config(builder *serverBuilder) {
builder.disableParallelism = true
}
func WithDisableParallelism() Option {
return &withDisableParallelism{}
}
type withPanicHandler struct {
panicHandler async.PanicHandler
}
func (opt *withPanicHandler) config(builder *serverBuilder) {
builder.panicHandler = opt.panicHandler
}
func WithPanicHandler(panicHandler async.PanicHandler) Option {
return &withPanicHandler{panicHandler}
}
type withIMAPLimits struct {
limits limits2.IMAP
}
func (w withIMAPLimits) config(builder *serverBuilder) {
builder.imapLimits = w.limits
}
func WithIMAPLimits(limits limits2.IMAP) Option {
return &withIMAPLimits{
limits: limits,
}
}
type withUIDValidityGenerator struct {
generator imap.UIDValidityGenerator
}
func (w withUIDValidityGenerator) config(builder *serverBuilder) {
builder.uidValidityGenerator = w.generator
}
func WithUIDValidityGenerator(generator imap.UIDValidityGenerator) Option {
return &withUIDValidityGenerator{generator: generator}
}
type withDBClient struct {
ci db.ClientInterface
}
func (w withDBClient) config(builder *serverBuilder) {
builder.dbCI = w.ci
}
func WithDBClient(ci db.ClientInterface) Option {
return &withDBClient{ci: ci}
}
|