3 # * This file is free software; you can redistribute it and/or modify it
4 # * under the terms of the GNU General Public License as published by
5 # * the Free Software Foundation; either version 2 of the License, or
6 # * (at your option) any later version.
8 # * This program is distributed in the hope that it will be useful, but
9 # * WITHOUT ANY WARRANTY; without even the implied warranty of
10 # * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 # * General Public License for more details.
13 # * You should have received a copy of the GNU General Public License
14 # * along with this program; if not, write to the Free Software
15 # * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 # * Copyright © 2003 Paul Mangan <claws@thewildbeast.co.uk>
19 # * 2003-10-01: add --debug and --dry-run options
20 # * 2003-09-30: updated/improved by Matthias Förste <itsjustme@users.sourceforge.net>
21 # * 2003-05-27: version one
23 ## script name : maildir2sylpheed.pl
25 ## script purpose : convert a Kmail mailbox into a Sylpheed mailbox
27 ## USAGE: maildir2sylpheed.pl --kmaildir=Mail
29 ## tested with Kmail version 1.5.2
38 # dont actually change anything if set(useful in conjunction with debug)
40 # print debug info if set
43 my $sylpheed_tmpdir = "$ENV{HOME}/sylpheed_tmp";
44 my $kmail_olddir = "$ENV{HOME}/kmail_junk";
46 GetOptions("kmaildir=s" => \$kmaildir,
47 "help" => \$iNeedHelp,
48 "dry-run" => \$PRETEND,
51 if ($kmaildir eq "" || $iNeedHelp) {
53 print "No directory name given\n";
55 print "Use the following format:\n";
56 print "\tmaildir2sylpheed.pl --kmaildir=mail_folder_name\n\n";
57 print "For example: 'Mail'\n";
61 $kmaildir = "$ENV{PWD}/$kmaildir" unless '/' eq substr($kmaildir,0,1);
64 my $MAIL_dir = "$kmaildir";
66 my $find_opts = { wanted => \&process };
69 find($find_opts , ($MAIL_dir));
71 print "\n$MAIL_dir is not a directory !\n";
76 mkdir("$sylpheed_tmpdir", 0755);
77 system("mv $kmaildir $kmail_olddir");
78 system("mv $sylpheed_tmpdir $ENV{HOME}/Mail");
80 print "\n\nSucessfully converted mailbox \"$MAIL_dir\"\n";
81 print "Start Sylpheed and right-click \"Mailbox (MH)\" and ";
82 print "select \"Rebuild folder tree\"\n";
83 print "You may also need to run \"/File/Folder/Check for ";
84 print "new messages in all folders\"\n\n";
85 print "Your kmail directories have been backed-up to\n";
86 print "$kmail_olddir\n\n";
94 process_dir($File::Find::dir);
96 process_file($File::Find::name);
102 $DEBUG && print "\nDIR $direc";
104 if ($direc !~ m/^drafts$/ &&
105 $direc !~ m/^outbox$/ &&
106 $direc !~ m/^trash$/ &&
107 $direc !~ m/^inbox$/) {
109 $tmpdir =~ s/^$MAIL_dir//;
110 $tmpdir =~ s/sent-mail/sent/;
111 $tmpdir =~ s/\/cur$//;
112 $tmpdir =~ s/\/new$//;
114 $tmpdir =~ s/\.directory//g;
117 my $newdir = "$sylpheed_tmpdir/$tmpdir";
118 $DEBUG && print qq{\n>>> -e "$newdir" || mkdir("$newdir")};
119 $PRETEND || -e "$newdir" || mkdir("$newdir");
126 $DEBUG && print "\nFILE $file";
131 if ($tmpfile =~ m/\/cur\// ||
132 $tmpfile =~ m/\/new\//) {
134 $tmpfile =~ s/\/new//;
135 $tmpfile =~ s/\/cur//;
137 my @spl_str = split("/", $tmpfile);
139 push(@spl_str, "$count");
141 foreach my $spl_str (@spl_str) {
143 $spl_str =~ s/\.directory$//;
144 $spl_str =~ s/sent-mail/sent/;
147 $nfile = join("/", @spl_str);
148 $nfile =~ s|$kmaildir|$sylpheed_tmpdir/|;
151 if (-e "$file" && $nfile ne "") {
152 $DEBUG && print qq{\n+++ cp "$file" "$nfile"};
153 $PRETEND || system("cp \"$file\" \"$nfile\"");