snarf_mail.rb: add date to email file name
authorColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Tue, 13 Sep 2011 04:42:27 +0000 (21:42 -0700)
committerColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Tue, 13 Sep 2011 04:42:27 +0000 (21:42 -0700)
Signed-off-by: Colin McCabe <cmccabe@alumni.cmu.edu>

snarf_mail.rb

index fc51b57..76c831c 100755 (executable)
@@ -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