RE: [Exim] Mailbox to Maildir Converter

Page principale
Supprimer ce message
Répondre à ce message
Auteur: Jeffrey Wheat
Date:  
À: Elie Kfoury, exim-users
Sujet: RE: [Exim] Mailbox to Maildir Converter
This is what I used. Someone sent it to me, original author is
unknown.

#! /usr/bin/perl
# put into the public domain by Bruce Guenter <bruceg@???>
# based heavily on code by Russell Nelson <nelson@???>, also in
# the public domain
# NO GUARANTEE AT ALL
#
# Creates a maildir from a mbox file

# Assumes that nothing is trying to modify the mailboxe
# version 0.00 - first release to the public.

require 'stat.pl';

sub error {
    print STDERR join("\n", @_), "\n";
    exit(1);
}


sub usage {
    print STDERR "usage: mbox2maildir <mbox file> <maildir> [ <uid> <gid> ]\n";
    exit(@_);
}


&usage(1) if $#ARGV != 1 && $#ARGV != 3;;

$mbox = $ARGV[0];
$mdir = $ARGV[1];
$uid = $ARGV[2];
$gid = $ARGV[3];

&error("can't open mbox '$mbox'") unless
    open(SPOOL, $mbox);


-d $mdir || mkdir $mdir,0700 ||
    &error("maildir '$mdir' doesn't exist and can't be created.");
chown($uid,$gid,$mdir) if defined($uid) && defined($gid);
chdir($mdir) || &error("fatal: unable to chdir to $mdir.");
-d "tmp" || mkdir("tmp",0700) || &error("unable to make tmp/ subdir");
-d "new" || mkdir("new",0700) || &error("unable to make new/ subdir");
-d "cur" || mkdir("cur",0700) || &error("unable to make cur/ subdir");
chown($uid,$gid,"tmp","new","cur") if defined($uid) && defined($gid);


$stamp = time;
sub open_msg {
    my($flags,$header) = @_;
    if($flags) {
        if($flags =~ /RO/) { $fn = "cur/$stamp.$$.mbox2maildir:2,S"; }
    elsif($flags =~ /O/) { $fn = "cur/$stamp.$$.mbox2maildir"; }
    else { $fn = "new/$stamp.$$.mbox2maildir"; }
    } else {
        $fn = "new/$stamp.$$.mbox2maildir";
    }
    $stamp++;
    close(OUT);
    open(OUT, ">$fn") || &error("unable to create new message");
    chown ($uid,$gid,$fn) if defined($uid) && defined($gid);
    print OUT @$header, "\n";
}


$in_header = 0;
while(<SPOOL>) {
    if(/^From /) {
        open_msg($flags, \@header) if $in_header;
    undef $flags;
    undef @header;
    $in_header = 1;
    push @header, "MBOX-Line: $_";
    } elsif($in_header) {
    if(/^\s+$/o) {
        $in_header = 0;
        open_msg($flags, \@header);
    } else {
            $flags = $1 if /^Status:\s+(\S+)/oi;
        push @header, $_;
        }
    } else {
        s/^>From /From /;
        print OUT || &error("unable to write to new message");
    }
}
close(SPOOL);
open_msg($flags, \@header) if $in_header;
close(OUT);


> -----Original Message-----
> From: Elie Kfoury [mailto:elie@affinity.au.com]
> Sent: Monday, December 02, 2002 5:30 PM
> To: exim-users@???
> Subject: [Exim] Mailbox to Maildir Converter
>
>
> This is a multi-part message in MIME format.
> --
> [ Picked text/plain from multipart/alternative ]
> Hi,
>
> I am looking for a script that will convert al of my EXIM
> mailboxes to maildirs.
>
> Thank you for Help.
> --
>
> --
>
> ## List details at
> http://www.exim.org/mailman/listinfo/exim-> users Exim details
> at http://www.exim.org/ ##
>
>
> ---
> Incoming
> mail is certified Virus Free.
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.422 / Virus Database: 237 - Release Date: 11/20/2002
>
>


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.423 / Virus Database: 238 - Release Date: 11/25/2002