예제 #1
0
func main() {
	log.SetSeverities(log.INFO | log.WARN)
	log.Info("Severity: will print info.")
	log.Warn("Severity: will print warn.")
	log.Debug("Severity: won't print debug.")

	log.SetMinMaxSeverity(log.TRACE, log.INFO)
	log.Trace("Severity: will print trace.")
	log.Debug("Severity: will print debug.")
	log.Info("Severity: will print info.")
	log.Warn("Severity: won't print warn.")
}
예제 #2
0
파일: server.go 프로젝트: nickvanw/anonmail
func StartServer(config *Config) {
	err := initDB(config)
	if err != nil {
		log.Critical(err)
		panic(err)
	}
	queue = make(chan int, runtime.NumCPU())
	listen, err := net.Listen("tcp", config.Listen)
	if err != nil {
		log.Critical(err)
		panic(err)
	}
	greeting = fmt.Sprintf("220 %s SMTP ANONMAIL\r\n", config.Name)
	saveMailChannel := make(chan *ServerMessage, 10)
	go SaveMail(saveMailChannel)
	for {
		con, err := listen.Accept()
		if err != nil {
			log.Critical("Error accepting connection", err)
		}
		log.Debug("New Connection: ", con.RemoteAddr().String())
		NewClient := &Client{
			server:  config.Name,
			conn:    con,
			address: con.RemoteAddr().String(),
			time:    time.Now().Unix(),
			reader:  bufio.NewReader(con),
			writer:  bufio.NewWriter(con),
			message: &ServerMessage{},
		}
		queue <- 0
		go NewClient.HandleMessage(saveMailChannel)
	}
}
예제 #3
0
파일: server.go 프로젝트: nickvanw/anonmail
func (c *Client) HandleMessage(save chan *ServerMessage) {
	defer c.closeClient()
	c.Write(greeting)
	for {
		data, err := c.readMessage()
		if err != nil {
			//This means the client has quit, or there's an error.
			break
		}
		log.Debug("Recieved: ", data)
		line := command(string(data))
		if !line.IsValid() {
			c.Write("500 Invalid Data\r\n")
		}
		switch line.Action() {
		case "HELO":
			c.HandleHelo(line)
		case "EHLO":
			c.HandleEhlo(line)
		case "RSET":
			c.message = &ServerMessage{}
			c.Write("250 2.0.0 OK\r\n")
		case "MAIL":
			c.HandleMailFrom(line)
		case "RCPT":
			c.HandleRCPT(line)
		case "DATA":
			c.HandleMail(line)
		case "NOOP":
			c.Write("250 2.0.0 OK\r\n")
		case "QUIT":
			c.Write("221 2.0.0 Bye\r\n")
		default:
			c.Write("502 5.5.2 Error: Command Not Recognized\r\n")
		}
		if c.message.IsValid() {
			save <- c.message
		}
	}
}
예제 #4
0
파일: server.go 프로젝트: nickvanw/anonmail
func (c *Client) Write(line string) {
	log.Debug("Writing ", line)
	c.writer.WriteString(line)
	c.writer.Flush()
}