User Tools

Site Tools


split_an_mbox_file_on_the_from_line

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

split_an_mbox_file_on_the_from_line [2007/09/11 16:36]
adam
split_an_mbox_file_on_the_from_line [2016/11/25 22:38]
Line 1: Line 1:
-===== Split an Mbox file on the From Line ===== 
  
-I've had to do this when you are using an mbox mail spool and you get an enormous mail (in my case usually some automated data import) which is too large to transfer in a reasonable period causing you to not be able to download any mail because there is a huge one in the way. 
- 
-What you want to do is split the mbox file into individual files per email and then reassemble them without the large one. You might want to stop your mail server while you do this so your mbox file won't get added to by incoming mail, or you might want to do something more clever if you can't do that. Also turn off your mail client so it won't try to download mail. 
- 
-So first you need to split the mbox file up: 
- 
-  csplit -n 4 filename /^From/ {*} 
- 
-Look at the csplit man page to understand the options. 
- 
-This gives me a file per email, named xx followed by a 4 digit number, so I rename the problem email according to it's size: 
- 
-  mv xx0123 bigmail 
- 
-Move my existing mbox to something else in case anything goes wrong: 
- 
-  mv adam adam.old 
- 
-Create a new mbox: 
- 
-  touch adam 
- 
-Give it the right file ownerships for your mail server, for me this is: 
- 
-  chown adam:mail adam 
- 
-Then put all of the new files together again in your mbox: 
- 
-  cat xx* >> adam 
- 
-And remove the split files: 
- 
-  rm -f xx* 
- 
--f option stops Red Hat/Fedora asking me if I want to remove each file. You might want to omit this option. 
- 
-You can now restart your mail server and download your mail. 
split_an_mbox_file_on_the_from_line.txt ยท Last modified: 2016/11/25 22:38 (external edit)