1

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!

Swift Dev Journal
  • 19,282
  • 4
  • 56
  • 66
  • 1
    If they're true mbox files, and you're not sorting them, you could just 'cat' them together (potentially needing to insert a blank line). Python may be overkill! – Max Jun 03 '21 at 21:00
  • Related: [Python concatenate text files](https://stackoverflow.com/q/13613336/9997212) – enzo Jun 03 '21 at 21:31

0 Answers0