How to merge two mbox files using python

400 views Asked by At

I have two mbox files that I need to combine, merge or concat into one mbox file.

I've tried a for loop that pulls the messages into one master list but not sure if this is the best way since I now have two lists that can be combined but need a final mbox file(I suppose). I plan on again breaking down the combined mbox file into a data frame, which I've done for one mbox file already.

Here's what I have thus far:

inbox_1 = mailbox.mbox('Inbox1.mbox')
inbox_2 = mailbox.mbox('Inbox2.mbox')

all_msgs = []
for message in inbox_1:
    all_msgs.append(message)

for message in inbox_2:
    all_msgs.append(message)
#convert back to .mbox format

Any help would be appreciated. Thanks in advance!

0

There are 0 answers