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"])
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