You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

69 lines
1.3 KiB

4 years ago
package smtpd
import (
7 months ago
"fmt"
"net"
"regexp"
"time"
7 months ago
"git.watsonserve.com/maild/base"
4 years ago
)
const (
7 months ago
mod_COMMAND = 1
mod_HEAD = 2
mod_BODY = 4
4 years ago
)
type smtp_context_t struct {
7 months ago
sock net.Conn
Address string
handlers SmtpServerConfigure
conf *base.ServerConfig
7 months ago
Module int
Login bool
4 years ago
re *regexp.Regexp
Email *base.Mail
7 months ago
// 其他
Msg string
User string
4 years ago
}
func initSmtpContext(sock net.Conn, config SmtpServerConfigure) *smtp_context_t {
7 months ago
scxt := &smtp_context_t{
sock: sock,
Address: sock.RemoteAddr().String(),
handlers: config,
conf: config.GetConfig(),
Module: mod_COMMAND,
Login: false,
re: regexp.MustCompile("<(.+)>"),
Email: &base.Mail{},
7 months ago
}
4 years ago
7 months ago
return scxt
4 years ago
}
// 发送
7 months ago
func (scxt *smtp_context_t) Send(content string) {
fmt.Fprint(scxt.sock, content)
4 years ago
}
// 发送并关闭
7 months ago
func (scxt *smtp_context_t) End(content string) {
fmt.Fprint(scxt.sock, content)
scxt.sock.Close()
4 years ago
}
// 问候语
7 months ago
func (scxt *smtp_context_t) hola() {
config := scxt.conf
scxt.Send(fmt.Sprintf("220 %s %s Server (%s %s Server %s) ready %d\r\n",
config.Domain, config.Type, config.Name, config.Type, config.Version, time.Now().Unix(),
4 years ago
))
}
7 months ago
func (scxt *smtp_context_t) takeOff() {
scxt.handlers.TakeOff(scxt.Email)
4 years ago
}