From b894a2078a7d041d0101da05dad83ad37fcaa2ed Mon Sep 17 00:00:00 2001 From: Colin Patrick McCabe Date: Mon, 12 Sep 2011 21:42:27 -0700 Subject: [PATCH] snarf_mail.rb: add date to email file name Signed-off-by: Colin McCabe --- snarf_mail.rb | 13 +++++++++---- 1 files changed, 9 insertions(+), 4 deletions(-) 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 -- 1.6.6.rc1.39.g9a42