]> git.donarmstrong.com Git - bin.git/blob - convert_to_maildir
add reset usb bus command
[bin.git] / convert_to_maildir
1 #! /usr/bin/perl
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 $
7
8
9 use warnings;
10 use strict;
11
12 use Getopt::Long;
13 use Pod::Usage;
14
15 =head1 NAME
16
17 convert_to_maildir mailbox maildir - convert a mailbox to a maildir
18
19 =head1 SYNOPSIS
20
21 convert_to_maildir [options] mailbox maildir
22 convert_to_maildir -m maildir mailbox [mailbox2..]
23
24
25  Options:
26   --maildir,-m maildir destination
27   --debug, -d debugging level (Default 0)
28   --help, -h display this help
29   --man, -m display manual
30
31 =head1 OPTIONS
32
33 =over
34
35 =item B<--maildir,-m>
36
37 Maildir destination; useful if converting multiple mailboxes
38
39 =item B<--debug, -d>
40
41 Debug verbosity. (Default 0)
42
43 =item B<--help, -h>
44
45 Display brief usage information.
46
47 =item B<--man, -m>
48
49 Display this manual.
50
51 =back
52
53 =head1 EXAMPLES
54
55
56 =cut
57
58
59 use vars qw($DEBUG);
60 use Date::Parse;
61 use IO::Handle;
62 use Fcntl;
63
64
65 my %options = (debug           => 0,
66                help            => 0,
67                man             => 0,
68                );
69
70 GetOptions(\%options,
71            'maildir|m=s',
72            'debug|d+','help|h|?','man|m');
73
74 pod2usage() if $options{help};
75 pod2usage({verbose=>2}) if $options{man};
76
77 $DEBUG = $options{debug};
78
79 my @USAGE_ERRORS;
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";
82 }
83
84 pod2usage(join("\n",@USAGE_ERRORS)) if @USAGE_ERRORS;
85
86 if (not defined $options{maildir}) {
87     $options{maildir} = pop @ARGV;
88 }
89
90 for my $mailbox (@ARGV) {
91     convert($mailbox,$options{maildir});
92 }
93
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!
97 sub convert {
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>;');
103 }