[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

mbox2txt subject sorting patch

I noticed that the subject sorting in the mbox2txt script does not
ignore the leading "Re: " in the subject of replies, which makes the
sort pretty useless.  Here's a quick patch I made to fix it.  Of course,
you still need to uncomment the relevant code to enable sorting by

Index: mbox2txt
--- mbox2txt	(revision 126)
+++ mbox2txt	(working copy)
@@ -55,10 +55,16 @@
     mb = open(filename)
     mbox = mailbox.UnixMailbox(mb, email.message_from_file)
+    def strip_re(subject):
+        if subject[:4] == "Re: ":
+            return subject[4:]
+        else:
+            return subject
     def sort_mails(a, b):
         # Sort by Subject: as well
-        #ret = cmp(a['subject'], b['subject'])
-        #if ret: return ret
+        #ret = cmp(strip_re(a['subject']), strip_re(b['subject']))
+        #if ret: return ret
         a_time = mktime_tz(parsedate_tz(a['date']))
         b_time = mktime_tz(parsedate_tz(b['date']))
You win again, gravity!

Reply to: