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

Address matching should only apply to address, not name

This commit is contained in:
James Hillyerd
2017-02-05 15:31:31 -08:00
parent 64e75face8
commit 5e94f7b750

View File

@@ -5,6 +5,7 @@ import (
"encoding/json" "encoding/json"
"flag" "flag"
"fmt" "fmt"
"net/mail"
"os" "os"
"time" "time"
@@ -42,9 +43,9 @@ func (*matchCmd) Usage() string {
func (m *matchCmd) SetFlags(f *flag.FlagSet) { func (m *matchCmd) SetFlags(f *flag.FlagSet) {
f.StringVar(&m.output, "output", "id", "output format: id, json, or mbox") f.StringVar(&m.output, "output", "id", "output format: id, json, or mbox")
f.BoolVar(&m.delete, "delete", false, "delete matched messages after output") f.BoolVar(&m.delete, "delete", false, "delete matched messages after output")
f.Var(&m.from, "from", "From header matching regexp") f.Var(&m.from, "from", "From header matching regexp (address, not name)")
f.Var(&m.subject, "subject", "Subject header matching regexp") f.Var(&m.subject, "subject", "Subject header matching regexp")
f.Var(&m.to, "to", "To header matching regexp (must match one)") f.Var(&m.to, "to", "To header matching regexp (must match 1+ to address)")
f.DurationVar( f.DurationVar(
&m.maxAge, "maxage", 0, &m.maxAge, "maxage", 0,
"Matches must have been received in this time frame (ex: \"10s\", \"5m\")") "Matches must have been received in this time frame (ex: \"10s\", \"5m\")")
@@ -118,13 +119,24 @@ func (m *matchCmd) match(header *client.MessageHeader) bool {
} }
} }
if m.from.Defined() { if m.from.Defined() {
if !m.from.MatchString(header.From) { from := header.From
addr, err := mail.ParseAddress(from)
if err == nil {
// Parsed successfully
from = addr.Address
}
if !m.from.MatchString(from) {
return false return false
} }
} }
if m.to.Defined() { if m.to.Defined() {
match := false match := false
for _, to := range header.To { for _, to := range header.To {
addr, err := mail.ParseAddress(to)
if err == nil {
// Parsed successfully
to = addr.Address
}
if m.to.MatchString(to) { if m.to.MatchString(to) {
match = true match = true
break break