Joerg Jaspert: Splitting huge mbox files
As I just had the need to split up two huge mbox files by date and did not find a tool that does that easily, I thought I share what I used.
Careful, it isn’t very clever, so if you use it: It comes with NO WARRANTY at all. If it eats your mail, you lost. Not my fault, you have been warned.
The task it should solve reads
- split files of size 1.8Gb and 3.2Gb, all together nearly a million mails in them,
- do not use lots of memory for this,
- no need to interactively do anything,
- split based on Date: header.
unset confirmcreate set delete=yes set folder=/dev/nulland then a lot of lines looking similar to the following, just replacing the dates;
folder-hook . 'push "T~d01/03/2008-31/03/2008\n;s2008-03.mbox\n$%q"'If you then start mutt using mutt -F theabovemuttrc -f themboxfiletosplit it will go and split it into the YEAR-MONTH based files. I got this way from Gerfried Fuchs, as I am no mutt user and wouldn’t have found the way to do it with mutt myself. Drawback: Mutt needs exact date entries in the push lines. Means you have to write 29/02 if you mean “last day of Februar”, a plain stupid 31/02 will be converted to 02/03. And I was way too lazy to list all the dates for the timeframe those mboxes cover. So, other solution. Ruby to the rescue! The following code does split the mbox into the files I want, based on the date header:
#!/usr/bin/ruby -w
# Split a mbox file into $year-$month files
# Copyright (C) 2008 Joerg Jaspert
# BSD style license, on Debian see /usr/share/common-licenses/BSD
require 'pathname'
require 'rmail'
count = 0
File.open(Pathname.new(ARGV[0]), 'r') do mbox
RMail::Mailbox.parse_mbox(mbox) do raw
count += 1
print "# count mails\n"
begin
File.open(RMail::Parser.read(raw).header.date.strftime("split/mail-%y%m"), 'a') do out
out.print(raw)
end
rescue NoMethodError
print "Couldn't parse date header, ignoring broken spam mail\n"
end
end
end
This will go through the whole mbox and store them in split/mail-$year$ month files. It has a few things you should keep in mind, if you really want to use it:
- Spam mails often have a very broken Date header. Sometimes broken enough that it can’t be parsed. I discard the “can’t be parsed” ones, as I havent seen a valid mail with that. You might want to store it in a different file, so change the part within rescue.
- Again, Spam mails often have a very broken Date header. So you will get files for years way in the past or future. In my case I could simply delete all of them, as all of those had been spam, and I knew in which timeframe the good mails got into the mbox.
I really don't think I have anything to add to
Boston offers slim pickings for vegetarian fine-dining options in the financial district. Most nice places have some sort of pasta dish and not much else. I have forgotten several times, but now write this blog entry to permanently remember, that
Excuse the quality; this is a low-light low-resolution image taken by cell phone. It was called “Butter Cake” but went well beyond the humble title. Those specks around the outside are dried grapefruit.
Technorati Tags:
With Hans Reiser
I installed Debian upon a new desktop machine yesterday, via a PXE network boot.
It was painless.
Getting xen up and running, with a 32-bit guest and a 64-bit guest each running XDMCP & VNC was also pretty straightforward.
There is a minor outstanding problem with the 32-bit xen guest though; connecting to it from dom0, via XDMCP, I see only a blank window - no login manager running.
GDM appears painlessly when I connect via VNC.
The relevent configuration file looks like this:




I've got most of the build system / packaging stuff done for estron now. There's a basic Yelp manual pending completion of the Estron GNOME application, there are some refreshed screenshots, updated the website CSS and added an icon, updated Glade files using Gtk stock items for the buttons.
Since I didn't find a similar tool for Linux, I've hacked together a tiny tool
to do BPM counting. The usual stuff: tap any key with the music to get a BPM
estimation. There is no music analysis done.
To achieve better results, my tool uses an exponentially weighted average. It
also computes a confidence interval. So if the song changes tempo (and quite
some jazz songs do) or doesn't keep the tempo constantly (live music with human
drummers often shows some tempo drift. It's just the drum computers that keep
their speed very well...) - the tool can handle that quite well, while also
not being overly sensitive to tapping errors (as you can see in the image).I figure there might be even better estimation tricks (e.g. doing some error
detection and removing them), but this one was just very simple to implement.
And by looking at the graph and the error interval it's quite easy to check
that you didn't any recent mistakes and the result is okay.The Python code is about 158 lines SLOC, and a small UI description generated
with Glade. It's built with PyGTK and uses Cairo for the plots, so it should be
very platform independant and even run on Windows.Download will be available sometime when I get around to clean it up a little.
There is for example still the code in there to compute plain averages, which
can't handle songs with multiple tempos at all.[Update: it now also has a tiny 'flasher' icon that will show you the current
tempo estimation. This is great for checking the quality of the result - if it
keeps on flashing in sync with the music after you've stopped tapping, it's
good. I was also pointed to
Debian wants to release in september. This target is already becoming difficult to reach, though the Release Team would like to try to do an extra effort to reach it.
History has shown that as long as testing migration is not frozen, many maintainers don't care much. Even during the freeze 'small' bug fixes are uploaded that sometimes break a lot and can delay the release quite a bit.
Currently build-essential packages are frozen, though 13 of these have new uploads in unstable...
We do want to finish 2 major transitions: python 2.4 -> 2.5 and perl 5.8 -> 5.10 before also freezing the non essential toolchain. The first one is reaching an end, though some build failures on arm and a flaky alpha buildd are not helpful in that regard.
Note that during a freeze fixes for release critical bugs, release goal bugs, documentation issues as well as translation bugs should still be fine if they have a low impact. Please do send unblock requests for those to the Release Team.
Considering all the above I do hope that maintainers start to realise that requesting freeze exceptions (exceptions to the above guidelines) should not be done lightly and start preparing for a release.