1
0
mirror of https://github.com/jhillyerd/inbucket.git synced 2025-12-18 18:17:03 +00:00

SMTP, logging changes

- smtpd/handler uses ParseEmailAddress() when opening mailbox and
  checking domainNoStore
- Added host info to logging for both SMTP and POP3, closes #16
This commit is contained in:
James Hillyerd
2013-11-05 15:18:19 -08:00
parent 962e995268
commit 6b606ebb9b
2 changed files with 19 additions and 12 deletions

View File

@@ -611,21 +611,21 @@ func (ses *Session) ooSeq(cmd string) {
// Session specific logging methods // Session specific logging methods
func (ses *Session) logTrace(msg string, args ...interface{}) { func (ses *Session) logTrace(msg string, args ...interface{}) {
log.LogTrace("POP3<%v> %v", ses.id, fmt.Sprintf(msg, args...)) log.LogTrace("POP3[%v]<%v> %v", ses.remoteHost, ses.id, fmt.Sprintf(msg, args...))
} }
func (ses *Session) logInfo(msg string, args ...interface{}) { func (ses *Session) logInfo(msg string, args ...interface{}) {
log.LogInfo("POP3<%v> %v", ses.id, fmt.Sprintf(msg, args...)) log.LogInfo("POP3[%v]<%v> %v", ses.remoteHost, ses.id, fmt.Sprintf(msg, args...))
} }
func (ses *Session) logWarn(msg string, args ...interface{}) { func (ses *Session) logWarn(msg string, args ...interface{}) {
// Update metrics // Update metrics
//expWarnsTotal.Add(1) //expWarnsTotal.Add(1)
log.LogWarn("POP3<%v> %v", ses.id, fmt.Sprintf(msg, args...)) log.LogWarn("POP3[%v]<%v> %v", ses.remoteHost, ses.id, fmt.Sprintf(msg, args...))
} }
func (ses *Session) logError(msg string, args ...interface{}) { func (ses *Session) logError(msg string, args ...interface{}) {
// Update metrics // Update metrics
//expErrorsTotal.Add(1) //expErrorsTotal.Add(1)
log.LogError("POP3<%v> %v", ses.id, fmt.Sprintf(msg, args...)) log.LogError("POP3[%v]<%v> %v", ses.remoteHost, ses.id, fmt.Sprintf(msg, args...))
} }

View File

@@ -314,12 +314,19 @@ func (ss *Session) dataHandler() {
i := 0 i := 0
for e := ss.recipients.Front(); e != nil; e = e.Next() { for e := ss.recipients.Front(); e != nil; e = e.Next() {
recip := e.Value.(string) recip := e.Value.(string)
if !strings.HasSuffix(strings.ToLower(recip), "@"+ss.server.domainNoStore) { local, domain, err := ParseEmailAddress(recip)
if err != nil {
ss.logError("Failed to parse address for %q", recip)
ss.send(fmt.Sprintf("451 Failed to open mailbox for %v", recip))
ss.reset()
return
}
if strings.ToLower(domain) != ss.server.domainNoStore {
// Not our "no store" domain, so store the message // Not our "no store" domain, so store the message
mb, err := ss.server.dataStore.MailboxFor(recip) mb, err := ss.server.dataStore.MailboxFor(local)
if err != nil { if err != nil {
ss.logError("Failed to open mailbox for %v", recip) ss.logError("Failed to open mailbox for %q", local)
ss.send(fmt.Sprintf("451 Failed to open mailbox for %v", recip)) ss.send(fmt.Sprintf("451 Failed to open mailbox for %v", local))
ss.reset() ss.reset()
return return
} }
@@ -525,21 +532,21 @@ func (ss *Session) ooSeq(cmd string) {
// Session specific logging methods // Session specific logging methods
func (ss *Session) logTrace(msg string, args ...interface{}) { func (ss *Session) logTrace(msg string, args ...interface{}) {
log.LogTrace("SMTP<%v> %v", ss.id, fmt.Sprintf(msg, args...)) log.LogTrace("SMTP[%v]<%v> %v", ss.remoteHost, ss.id, fmt.Sprintf(msg, args...))
} }
func (ss *Session) logInfo(msg string, args ...interface{}) { func (ss *Session) logInfo(msg string, args ...interface{}) {
log.LogInfo("SMTP<%v> %v", ss.id, fmt.Sprintf(msg, args...)) log.LogInfo("SMTP[%v]<%v> %v", ss.remoteHost, ss.id, fmt.Sprintf(msg, args...))
} }
func (ss *Session) logWarn(msg string, args ...interface{}) { func (ss *Session) logWarn(msg string, args ...interface{}) {
// Update metrics // Update metrics
expWarnsTotal.Add(1) expWarnsTotal.Add(1)
log.LogWarn("SMTP<%v> %v", ss.id, fmt.Sprintf(msg, args...)) log.LogWarn("SMTP[%v]<%v> %v", ss.remoteHost, ss.id, fmt.Sprintf(msg, args...))
} }
func (ss *Session) logError(msg string, args ...interface{}) { func (ss *Session) logError(msg string, args ...interface{}) {
// Update metrics // Update metrics
expErrorsTotal.Add(1) expErrorsTotal.Add(1)
log.LogError("SMTP<%v> %v", ss.id, fmt.Sprintf(msg, args...)) log.LogError("SMTP[%v]<%v> %v", ss.remoteHost, ss.id, fmt.Sprintf(msg, args...))
} }