Skip to content

Commit

Permalink
executors/imap: return an error when one of the Headers cannot be dec…
Browse files Browse the repository at this point in the history
…oded. (#178)
  • Loading branch information
wI2L authored and yesnault committed Nov 30, 2018
1 parent 2e4c692 commit b231ad5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
12 changes: 4 additions & 8 deletions executors/imap/decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"mime/quotedprintable"
"net/mail"

log "github.com/sirupsen/logrus"
"github.com/yesnault/go-imap/imap"

"github.com/ovh/venom"
Expand All @@ -22,7 +21,7 @@ func decodeHeader(msg *mail.Message, headerName string) (string, error) {
dec := new(mime.WordDecoder)
s, err := dec.DecodeHeader(msg.Header.Get(headerName))
if err != nil {
return msg.Header.Get(headerName), fmt.Errorf("Error while decode header %s:%s", headerName, msg.Header.Get(headerName))
return msg.Header.Get(headerName), err
}
return s, nil
}
Expand All @@ -46,18 +45,15 @@ func extract(rsp imap.Response, l venom.Logger) (*Mail, error) {
}
tm.Subject, err = decodeHeader(mmsg, "Subject")
if err != nil {
log.Warnf("Cannot decode Subject header: %s", err)
return nil, nil
return nil, fmt.Errorf("Cannot decode Subject header: %s", err)
}
tm.From, err = decodeHeader(mmsg, "From")
if err != nil {
log.Warnf("Cannot decode From header: %s", err)
return nil, nil
return nil, fmt.Errorf("Cannot decode From header: %s", err)
}
tm.To, err = decodeHeader(mmsg, "To")
if err != nil {
log.Warnf("Cannot decode To header: %s", err)
return nil, nil
return nil, fmt.Errorf("Cannot decode To header: %s", err)
}

encoding := mmsg.Header.Get("Content-Transfer-Encoding")
Expand Down
3 changes: 2 additions & 1 deletion executors/imap/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ func (e *Executor) getMail(l venom.Logger) (*Mail, error) {
for _, msg := range messages {
m, erre := extract(msg, l)
if erre != nil {
return nil, erre
l.Warnf("Cannot extract the content of the mail: %s", erre)
continue
}

found, errs := e.isSearched(m)
Expand Down

0 comments on commit b231ad5

Please sign in to comment.