2 # convert_to_maildir converts mboxes to maildir, and is released
3 # under the terms of the GPL version 2, or any later version, at your
4 # option. See the file README and COPYING for more information.
5 # Copyright 2011 by Don Armstrong <don@donarmstrong.com>.
6 # $Id: perl_script 1825 2011-01-02 01:53:43Z don $
17 convert_to_maildir mailbox maildir - convert a mailbox to a maildir
21 convert_to_maildir [options] mailbox maildir
22 convert_to_maildir -m maildir mailbox [mailbox2..]
26 --maildir,-m maildir destination
27 --debug, -d debugging level (Default 0)
28 --help, -h display this help
29 --man, -m display manual
37 Maildir destination; useful if converting multiple mailboxes
41 Debug verbosity. (Default 0)
45 Display brief usage information.
65 my %options = (debug => 0,
72 'debug|d+','help|h|?','man|m');
74 pod2usage() if $options{help};
75 pod2usage({verbose=>2}) if $options{man};
77 $DEBUG = $options{debug};
80 if (@ARGV != 2 and not defined $options{maildir}) {
81 push @USAGE_ERRORS,"You must either give one mailbox and one maildir, or use the -m option";
84 pod2usage(join("\n",@USAGE_ERRORS)) if @USAGE_ERRORS;
86 if (not defined $options{maildir}) {
87 $options{maildir} = pop @ARGV;
90 for my $mailbox (@ARGV) {
91 convert($mailbox,$options{maildir});
94 # The idea to do this came from
95 # http://blog.sandipb.net/2009/01/07/one-liner-to-convert-maildir-to-mbox-using-mutt/
96 # and talking with Mako. Lets just call mutt, it'll know what to do!
98 my ($mailbox,$maildir) = @_;
99 system('mutt','-m','maildir','-F/etc/Muttrc',
100 '-n','-R','-f', $mailbox,'-e',
101 'set confirmcreate=no; set delete=no; set confirmappend=no; set quit=yes; push T.*<enter>\;C'.
102 $maildir.'<enter><quit>;');