From: Colin Patrick McCabe Date: Tue, 13 Sep 2011 04:42:27 +0000 (-0700) Subject: snarf_mail.rb: add date to email file name X-Git-Url: http://club.cc.cmu.edu/~cmccabe/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b894a2078a7d041d0101da05dad83ad37fcaa2ed;p=cmccabe-bin snarf_mail.rb: add date to email file name Signed-off-by: Colin McCabe --- diff --git a/snarf_mail.rb b/snarf_mail.rb index fc51b57..76c831c 100755 --- a/snarf_mail.rb +++ b/snarf_mail.rb @@ -90,16 +90,20 @@ def format_uid(uid) return sprintf("%006d", uid) end -def get_sanitized_email_name(mailbox, uid) +def format_date(date) + date.gsub!(' ', '_') +end + +def get_sanitized_email_name(mailbox, arr) msn = mailbox.dup msn.gsub!(' ', '_') msn.gsub!('/', '.') - return "#{msn}#{format_uid(uid)}" + return "#{msn}_#{format_date(arr["INTERNALDATE"])}_#{format_uid(arr["UID"])}" end def write_email_to_disk(mailbox, data) arr = data[0].attr - filename = get_sanitized_email_name(mailbox, arr["UID"]) + filename = get_sanitized_email_name(mailbox, arr) fp = File.open(filename, 'w') fp.write(arr["RFC822.HEADER"]) fp.write(arr["RFC822.TEXT"]) @@ -135,7 +139,8 @@ def snarf_mailbox(imap, mailbox) STDOUT.flush() first_time = false end - data = imap.fetch(message_id, [ "UID", "RFC822.HEADER", "RFC822.TEXT" ]) + data = imap.fetch(message_id, + [ "INTERNALDATE", "UID", "RFC822.HEADER", "RFC822.TEXT" ]) write_email_to_disk(mailbox, data) count = count + 1 full_count = full_count + 1