aboutsummaryrefslogtreecommitdiff
path: root/serve_imap.go
blob: 53375701a4a6cea478d306f638266e0665318341 (plain) (blame)
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
package main

import (
	"crypto/tls"

	"github.com/emersion/go-imap/v2"
	"github.com/emersion/go-imap/v2/imapserver"
	"go.lindenii.runxiyu.org/lindenii-common/clog"
)

func serve_imap() {
	var tls_config *tls.Config
	var imap_net, imap_addr string
	config_consistent_run(func() {
		tls_config = config._tls_config
		imap_net = config.IMAP.Net
		imap_addr = config.IMAP.Addr
	})
	listener, err := tls.Listen(imap_net, imap_addr, tls_config)
	if err != nil {
		clog.Fatal(1, "IMAP: Cannot listen TLS: "+err.Error())
	}
	clog.Info("IMAP: Listening via " + imap_net + " on " + imap_addr)

	server := imapserver.New(&imapserver.Options{
		NewSession: func(conn *imapserver.Conn) (imapserver.Session, *imapserver.GreetingData, error) {
			return nil, nil, nil
		},
		Caps: imap.CapSet{
			imap.CapIMAP4rev1: {},
			imap.CapIMAP4rev2: {},
		},
		DebugWriter: nil, // TODO
	})
	err = server.Serve(listener)
	if err != nil {
		clog.Fatal(1, "IMAP: Failed serving: "+err.Error())
	}
}