diff options
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/mailing-list-member-retirement/main.go | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/scripts/mailing-list-member-retirement/main.go b/scripts/mailing-list-member-retirement/main.go index 7388cd6..06990e9 100644 --- a/scripts/mailing-list-member-retirement/main.go +++ b/scripts/mailing-list-member-retirement/main.go @@ -7,6 +7,7 @@ import ( "io" "log" "os" + "time" "github.com/emersion/go-mbox" "github.com/emersion/go-message/mail" _ "github.com/emersion/go-message/charset" @@ -15,12 +16,18 @@ import ( // Prints the email addresses (one per line) of all senders by parsing an MBOX. func main() { - mboxNamePtr := flag.String("mbox", "test.mbox", "MBOX to read") + mboxNamePtr := flag.String("mbox", "test.mbox", "The mailbox (in the mbox file format) to read") + sincePtr := flag.String("since", "1970-01-01", "Consider only messages since the given date (YYYY-MM-DD)") flag.Parse() - PrintAllMboxSenders(*mboxNamePtr) + const isoFormat = "2006-01-02" + since, err := time.Parse(isoFormat, *sincePtr) + if err != nil { + log.Fatalf("Date \"%v\" couldn't be parsed", *sincePtr) + } + PrintAllMboxSenders(*mboxNamePtr, since) } -func PrintAllMboxSenders(fileName string) { +func PrintAllMboxSenders(fileName string, since time.Time) { f, err := os.Open(fileName) if err != nil { log.Fatal(err) @@ -39,16 +46,24 @@ func PrintAllMboxSenders(fileName string) { } else if err != nil { log.Fatal(err) } - PrintMessageSender(r) + PrintMessageSender(r, since) } } -func PrintMessageSender(r io.Reader) { +func PrintMessageSender(r io.Reader, since time.Time) { mr, err := mail.CreateReader(r) if err != nil { IgnoreMail(err, mr) } + date, err := mr.Header.Date() + if err != nil { + IgnoreMail(err, mr) + return + } else if date.Before(since) { + return // Ignore this mail (too old) + } + addr, err := mr.Header.AddressList("From") if err != nil { IgnoreMail(err, mr) |