Fix mbox dates prior to importing into Mail.app

Mar 09, '04 09:49:00AM

Contributed by: SuperCheese

Apple's Mail program won't import an mbox file (such as one exported from another mail program) if the date is not in a valid format. It will actually import the entire mbox file as one email message, without a warning. Apparently, many mail programs don't use the right date format, even though the format is clearly spelled out in the mbox spec.

I found a Perl script online that converts the date to the correct format. (It's probably a good idea to run this on a copy of your mbox file in case it doesn't work.)

#! /usr/bin/perl -ni.bak

use Date::Parse ;
use Date::Format ;
$template = "%a %b %d %R:%S %Y" ;

if (/(^From )([^        ]*) (.*)/) {
    $time = str2time($3) ;
    $date = time2str($template, $time) ;
    print "$1$2  $date\n" ;
} else {
    print ;
} ;
[robg adds: I haven't tested this one...]

Comments (2)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20040227141127521