#! /usr/bin/perl # convert_to_maildir converts mboxes to maildir, and is released # under the terms of the GPL version 2, or any later version, at your # option. See the file README and COPYING for more information. # Copyright 2011 by Don Armstrong . # $Id: perl_script 1825 2011-01-02 01:53:43Z don $ use warnings; use strict; use Getopt::Long; use Pod::Usage; =head1 NAME convert_to_maildir mailbox maildir - convert a mailbox to a maildir =head1 SYNOPSIS convert_to_maildir [options] mailbox maildir convert_to_maildir -m maildir mailbox [mailbox2..] Options: --maildir,-m maildir destination --debug, -d debugging level (Default 0) --help, -h display this help --man, -m display manual =head1 OPTIONS =over =item B<--maildir,-m> Maildir destination; useful if converting multiple mailboxes =item B<--debug, -d> Debug verbosity. (Default 0) =item B<--help, -h> Display brief usage information. =item B<--man, -m> Display this manual. =back =head1 EXAMPLES =cut use vars qw($DEBUG); use Date::Parse; use IO::Handle; use Fcntl; my %options = (debug => 0, help => 0, man => 0, ); GetOptions(\%options, 'maildir|m=s', 'debug|d+','help|h|?','man|m'); pod2usage() if $options{help}; pod2usage({verbose=>2}) if $options{man}; $DEBUG = $options{debug}; my @USAGE_ERRORS; if (@ARGV != 2 and not defined $options{maildir}) { push @USAGE_ERRORS,"You must either give one mailbox and one maildir, or use the -m option"; } pod2usage(join("\n",@USAGE_ERRORS)) if @USAGE_ERRORS; if (not defined $options{maildir}) { $options{maildir} = pop @ARGV; } for my $mailbox (@ARGV) { convert($mailbox,$options{maildir}); } # The idea to do this came from # http://blog.sandipb.net/2009/01/07/one-liner-to-convert-maildir-to-mbox-using-mutt/ # and talking with Mako. Lets just call mutt, it'll know what to do! sub convert { my ($mailbox,$maildir) = @_; system('mutt','-m','maildir','-F/etc/Muttrc', '-n','-R','-f', $mailbox,'-e', 'set confirmcreate=no; set delete=no; set confirmappend=no; set quit=yes; push T.*\;C'. $maildir.';'); }