Christopher X. Candreva wrote:
On Fri, 21 Mar 2008, Mark Heer wrote:
reproduced the file just as I had concatenated it. Is there a way to merge
2 same list mboxes into 1 properly sequenced mbox?
If this is a one-time thing for the transition, you could load them into a
mail program, move all the messages to a single folder, sort the folder
by date, then save all to another folder again. I've done this with Pine.
I hacked a crude script to do the merge. It needs more work to become a
really useful tool such as a switch to choose between the UnixMailbox
(more strict From_ recognition) and PortableUnixMailbox (loose From_
recognition) classes and a switch to choose whether Date: or
X-List-Received-Date: is the preferred merge key, but I have attached it
in case it may be useful.
--
Mark Sapiro <[EMAIL PROTECTED]> The highway is for gamblers,
San Francisco Bay Area, California better use your sense - B. Dylan
#! /bin/env python
""" Merge two mailboxes by the Date: header value.
Fall back to X-List-Received-Date: if Date: not usable.
Should X-List-Received-Date: be first?
This is not well tested, and it assumes all messages in
both mbox files are parseable by email.message_from_file().
Usage: mbmerge path/to/mbox1 path/to/mbox2 > result
"""
import sys
import email
import mailbox
lasttime = 0
BIGTIME = 100. * 365.25 * 24. * 3600.
def main():
if len(sys.argv) <> 3:
print >> sys.stderr, \
'Usage: ', sys.argv[0], ' mbox1 mbox2 > result'
sys.exit(1)
fp1 = open(sys.argv[1])
mb1 = mailbox.UnixMailbox(fp1, email.message_from_file)
fp2 = open(sys.argv[2])
mb2 = mailbox.UnixMailbox(fp2, email.message_from_file)
gen = email.Generator.Generator(sys.stdout)
m1, t1 = get_next(mb1)
m2, t2 = get_next(mb2)
while m1 or m2:
if t1 < t2:
gen.flatten(m1, unixfrom=True)
m1, t1 = get_next(mb1)
else:
gen.flatten(m2, unixfrom=True)
m2, t2 = get_next(mb2)
def get_next(mb):
global lasttime
msg = mb.next()
if msg is None:
datime = BIGTIME
else:
datime = email.Utils.parsedate_tz(msg['date'])
if datime:
datime = email.Utils.mktime_tz(datime)
lasttime = datime
else:
datime = email.Utils.parsedate_tz(msg['x-list-received-date'])
if datime:
datime = email.Utils.mktime_tz(datime)
lasttime = datime
else:
datime = lasttime
return msg, datime
if __name__ == '__main__':
main()
------------------------------------------------------
Mailman-Users mailing list
[email protected]
http://mail.python.org/mailman/listinfo/mailman-users
Mailman FAQ: http://www.python.org/cgi-bin/faqw-mm.py
Searchable Archives: http://www.mail-archive.com/mailman-users%40python.org/
Unsubscribe:
http://mail.python.org/mailman/options/mailman-users/archive%40jab.org
Security Policy:
http://www.python.org/cgi-bin/faqw-mm.py?req=show&file=faq01.027.htp