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 3 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 # * Copyright 2003-2007 Paul Mangan <paul@claws-mail.org>
19 # * 2007-02-25: several fixes for kmail 1.9.6
20 # --kmaildir now expects the full path
21 # renamed from maildir2claws-mail.pl to kmail-mailbox2claws-mail.pl
22 # * 2003-10-01: add --debug and --dry-run options
23 # * 2003-09-30: updated/improved by Matthias Förste <itsjustme@users.sourceforge.net>
24 # * 2003-05-27: version one
26 ## script name : kmail-mailbox2claws-mail.pl
28 ## script purpose : convert a Kmail mailbox into a Claws Mail mailbox
30 ## USAGE: kmail-mailbox2claws-mail.pl --kmaildir=/full/path/to/kmail/mailbox
32 ## tested with Kmail version 1.9.6
41 # dont actually change anything if set(useful in conjunction with debug)
43 # print debug info if set
46 my $claws_tmpdir = "$ENV{HOME}/claws_tmp";
48 GetOptions
("kmaildir=s" => \
$kmaildir,
49 "help" => \
$iNeedHelp,
50 "dry-run" => \
$PRETEND,
53 if ($kmaildir eq "" || $iNeedHelp) {
55 print "No directory name given\n";
57 print "Use the following format:\n";
58 print "\tkmail-mailbox2claws-mail.pl --kmaildir=full-path-to-kmail-dir\n\n";
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("$claws_tmpdir", 0755);
77 system("mv $claws_tmpdir $ENV{HOME}/Mail");
79 print "\n\nSucessfully converted mailbox \"$MAIL_dir\"\n";
80 print "Start claws-mail and right-click \"Mailbox (MH)\" and ";
81 print "select \"Rebuild folder tree\"\n";
82 print "You may also need to run \"/File/Folder/Check for ";
83 print "new messages in all folders\"\n\n";
91 process_dir
($File::Find
::dir
);
93 process_file
($File::Find
::name
);
99 $DEBUG && print "\nDIR $direc";
101 if ($direc !~ m/^drafts$/ &&
102 $direc !~ m/^outbox$/ &&
103 $direc !~ m/^trash$/ &&
104 $direc !~ m/^inbox$/) {
106 $tmpdir =~ s/^$MAIL_dir//;
107 $tmpdir =~ s/\/sent-mail$/sent
/;
108 $tmpdir =~ s/\/cur$//;
109 $tmpdir =~ s/\/new$//;
111 $tmpdir =~ s/\.directory//g;
114 my $newdir = "$claws_tmpdir/$tmpdir";
115 $DEBUG && print qq{\n>>> -e
"$newdir" || mkdir("$newdir")};
116 $PRETEND || -e
"$newdir" || mkdir("$newdir");
123 $DEBUG && print "\nFILE $file";
128 $tmpfile =~ s
|^$kmaildir||;
130 if ($tmpfile =~ m/\/cur\
// ||
131 $tmpfile =~ m/\/new\
//) {
133 $tmpfile =~ s/\/new//;
134 $tmpfile =~ s/\/cur//;
136 my @spl_str = split("/", $tmpfile);
138 push(@spl_str, "$count");
140 foreach my $spl_str (@spl_str) {
141 $spl_str =~ s/\.directory$//;
143 $spl_str =~ s/^sent-mail$/sent/;
145 $nfile = join("/", @spl_str);
146 $nfile = $claws_tmpdir.$nfile;
149 if (-e
"$file" && $nfile ne "") {
150 $DEBUG && print qq{\n+++ cp
"$file" "$nfile"};
151 $PRETEND || system("cp \"$file\" \"$nfile\"");