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.
68 lines
1.3 KiB
68 lines
1.3 KiB
package smtpd
|
|
|
|
import (
|
|
"fmt"
|
|
"net"
|
|
"regexp"
|
|
"time"
|
|
|
|
"git.watsonserve.com/maild/base"
|
|
)
|
|
|
|
const (
|
|
mod_COMMAND = 1
|
|
mod_HEAD = 2
|
|
mod_BODY = 4
|
|
)
|
|
|
|
type smtp_context_t struct {
|
|
sock net.Conn
|
|
Address string
|
|
handlers SmtpServerConfigure
|
|
conf *base.ServerConfig
|
|
Module int
|
|
Login bool
|
|
re *regexp.Regexp
|
|
Email *base.Mail
|
|
// 其他
|
|
Msg string
|
|
User string
|
|
}
|
|
|
|
func initSmtpContext(sock net.Conn, config SmtpServerConfigure) *smtp_context_t {
|
|
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{},
|
|
}
|
|
|
|
return scxt
|
|
}
|
|
|
|
// 发送
|
|
func (scxt *smtp_context_t) Send(content string) {
|
|
fmt.Fprint(scxt.sock, content)
|
|
}
|
|
|
|
// 发送并关闭
|
|
func (scxt *smtp_context_t) End(content string) {
|
|
fmt.Fprint(scxt.sock, content)
|
|
scxt.sock.Close()
|
|
}
|
|
|
|
// 问候语
|
|
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(),
|
|
))
|
|
}
|
|
|
|
func (scxt *smtp_context_t) takeOff() {
|
|
scxt.handlers.TakeOff(scxt.Email)
|
|
}
|
|
|