aboutsummaryrefslogblamecommitdiff
path: root/main.go
blob: bf503f44a2c13cca7ba26a26487a6d69fa48b594 (plain) (tree)
1
2
3
4
5
6
7
8
9
10

            
        
                 
                
              
            
             

                                                      




                                       
                                                                                                      

                    
                                        
                       
                                                                              

         
                                                                  
                       
                                                                

                              
                                                                                 



                                              
                                                                                
                 
                                                                                       

                           


                                                                               
                                                                  


                                                                                                                                          


                         
 
package main

import (
	"context"
	"errors"
	"flag"
	"io"
	"net"

	"go.lindenii.runxiyu.org/lindenii-common/clog"
)

const VERSION = "lindenii-maild v0.0.0"

func main() {
	config_path := flag.String("config", "/etc/lindenii/maild.scfg", "path to configuration file")
	flag.Parse()

	err := load_config(*config_path)
	if err != nil {
		clog.Fatal(1, "Configuration file not found at "+*config_path)
	}

	listener, err := net.Listen(config.MX.Net, config.MX.Addr)
	if err != nil {
		clog.Fatal(1, "MX: Cannot listen: "+err.Error())
	}
	defer listener.Close()
	clog.Info("MX: Listening via " + config.MX.Net + " on " + config.MX.Addr)

	for {
		conn, err := listener.Accept()
		if err != nil {
			clog.Error("MX: Cannot accept connection: "+err.Error())
		}
		clog.Info("MX: Accepted connection from " + conn.RemoteAddr().String())

		go func() {
			ctx, cancel := context.WithCancel(context.Background())
			defer cancel()
			err := handle_mx_recv_conn(ctx, conn)
			if err != nil && !errors.Is(err, io.EOF) {
				clog.Error("MX: Connection handler for " + conn.RemoteAddr().String() + " returned error: " + err.Error())
			} else {
				clog.Error("MX: Connection handler for " + conn.RemoteAddr().String() + " returned error: " + err.Error())
			}
		}()
	}
}