3 # * Copyright © 2003 Paul Mangan <claws@thewildbeast.co.uk>
5 # * This file is free software; you can redistribute it and/or modify it
6 # * under the terms of the GNU General Public License as published by
7 # * the Free Software Foundation; either version 2 of the License, or
8 # * (at your option) any later version.
10 # * This program is distributed in the hope that it will be useful, but
11 # * WITHOUT ANY WARRANTY; without even the implied warranty of
12 # * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # * General Public License for more details.
15 # * You should have received a copy of the GNU General Public License
16 # * along with this program; if not, write to the Free Software
17 # * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 ## script name : maildir2sylpheed.pl
21 ## script purpose : convert a Kmail mailbox into a Sylpheed mailbox
23 ## USAGE: maildir2sylpheed.pl --kmaildir=Mail
25 ## tested with Kmail 1.5.2
33 $sylpheed_tmpdir = "sylpheed_tmp";
34 $kmail_olddir = "kmail_junk";
36 GetOptions("kmaildir=s" => \$kmaildir,
37 "help" => \$iNeedHelp);
39 if ($kmaildir eq "" || $iNeedHelp) {
41 print "No directory name given\n";
43 print "Use the following format:\n";
44 print "\tmaildir2sylpheed.pl --kmaildir=mail_folder_name\n\n";
45 print "For example: 'Mail'\n";
51 $MAIL_dir = "$ENV{HOME}/$kmaildir";
53 mkdir("$sylpheed_tmpdir", 0755);
55 my %files = Recurse(["$MAIL_dir"], {});
57 foreach (keys %files) {
60 foreach (@{ $files{$_} }) {
61 push(@files, "$dir/$_");
65 foreach $direc (@dirs) {
66 if ($direc !~ m/^drafts$/
67 && $direc !~ m/^outbox$/
68 && $direc !~ m/^trash$/
69 && $direc !~ m/^inbox$/) {
71 $tmpdir =~ s/^$MAIL_dir//;
72 $tmpdir =~ s/sent-mail/sent/;
73 $tmpdir =~ s/\/cur$//;
74 $tmpdir =~ s/\/new$//;
76 $tmpdir =~ s/\.directory//g;
78 mkdir("$sylpheed_tmpdir/$tmpdir");
79 opendir(DIR, "$direc")
80 || die("Can't open directory");
81 push(@subdirs,(readdir(DIR)));
85 foreach $subdir (@subdirs) {
86 if ($subdir !~ m/\.directory$/
88 && $subdir !~ m/cur\/$/
89 && $subdir !~ m/new\/$/
90 && $subdir !~ m/tmp\/$/) {
91 $sub_dir =~ s/\.directory//;
92 unless (-e "$sylpheed_tmpdir/$tmpdir/$sub_dir") {
93 mkdir("$sylpheed_tmpdir/$tmpdir/$sub_dir");
100 foreach $file (@files) {
102 if ($tmpfile =~ m/\/cur\//
103 || $tmpfile =~ m/\/new\//) {
104 $tmpfile =~ s/\/new//;
105 $tmpfile =~ s/\/cur//;
106 @spl_str = split("/", $tmpfile);
108 push(@spl_str, "$count");
109 foreach $spl_str (@spl_str) {
111 $spl_str =~ s/\.directory$//;
112 $spl_str =~ s/sent-mail/sent/;
114 $nfile = join("/", @spl_str);
115 $nfile =~ s/\/$kmaildir\//\/$sylpheed_tmpdir\//;
118 if (-e "$file" && $nfile ne "") {
119 system("cp \"$file\" \"$nfile\"");
124 system("mv $kmaildir $kmail_olddir");
125 system("mv $sylpheed_tmpdir $ENV{HOME}/Mail");
127 print "Sucessfully converted mailbox \"$MAIL_dir\"\n";
128 print "Start Sylpheed and right-click \"Mailbox (MH)\" and ";
129 print "select \"Rebuild folder tree\"\n";
130 print "You may also need to run \"/File/Folder/Check for "
131 print "new messages in all folders\"\n\n";
132 print "Your kmail directories have been backed-up to\n";
133 print "$ENV{HOME}/$kmail_olddir\n\n";