aboutsummaryrefslogtreecommitdiff
path: root/serve_imap.go
diff options
context:
space:
mode:
Diffstat (limited to 'serve_imap.go')
-rw-r--r--serve_imap.go27
1 files changed, 23 insertions, 4 deletions
diff --git a/serve_imap.go b/serve_imap.go
index 8b2c859..c55ed3e 100644
--- a/serve_imap.go
+++ b/serve_imap.go
@@ -3,9 +3,9 @@ package main
import (
"bufio"
"context"
- "fmt"
"crypto/tls"
"encoding/base64"
+ "fmt"
"io"
"net"
"strings"
@@ -62,7 +62,7 @@ func (session *imap_recv_session) handle(ctx context.Context) error {
break switch_cmd
}
argument := make([]byte, base64.StdEncoding.DecodedLen(len(argument_base64)))
- _, err := base64.StdEncoding.Decode(argument, []byte(argument_base64));
+ _, err := base64.StdEncoding.Decode(argument, []byte(argument_base64))
if err != nil {
_, _ = session.buf_conn.WriteString(tag + " TODO cannot decode base64\r\n")
_ = session.buf_conn.Flush()
@@ -86,12 +86,31 @@ func imap_new_session(ctx context.Context, net_conn net.Conn) error {
}
func serve_imap() {
- var imap_net, imap_addr string
+ var imap_net, imap_addr, imap_trans string
+ var tls_config *tls.Config
config_consistent_run(func() {
imap_net = config.IMAP.Net
imap_addr = config.IMAP.Addr
+ imap_trans = config.IMAP.Trans
+ tls_config = config._tls_config
})
- listener, err := net.Listen(imap_net, imap_addr)
+ var listener net.Listener
+ var err error
+ switch imap_trans {
+ case "tls", "":
+ listener, err = tls.Listen(imap_net, imap_addr, tls_config)
+ if err != nil {
+ clog.Fatal(1, "IMAP: Cannot listen TLS: "+err.Error())
+ }
+ case "plain":
+ listener, err = net.Listen(imap_net, imap_addr)
+ if err != nil {
+ clog.Fatal(1, "IMAP: Cannot listen plain: "+err.Error())
+ }
+ default:
+ clog.Fatal(1, "IMAP: Invalid transport for listening")
+ }
+
if err != nil {
clog.Fatal(1, "IMAP: Cannot listen: "+err.Error())
}