add kmail to sylpheed mailbox conversion script
authorPaul Mangan <paul@claws-mail.org>
Tue, 27 May 2003 22:23:13 +0000 (22:23 +0000)
committerPaul Mangan <paul@claws-mail.org>
Tue, 27 May 2003 22:23:13 +0000 (22:23 +0000)
ChangeLog.claws
configure.ac
tools/Makefile.am
tools/maildir2sylpheed.pl [new file with mode: 0644]

index 0a7938d..97cae6b 100644 (file)
@@ -1,3 +1,9 @@
+2003-05-27 [paul]      0.9.0claws4
+
+       * tools/Makefile.am
+         tools/maildir2sylpheed.pl     ** NEW FILE **
+               add kmail to sylpheed mailbox conversion script
+
 2003-05-27 [paul]      0.9.0claws3
 
        * sync with 0.9.0cvs10
index 1a025a5..50a4e60 100644 (file)
@@ -11,7 +11,7 @@ MINOR_VERSION=9
 MICRO_VERSION=0
 INTERFACE_AGE=0
 BINARY_AGE=0
-EXTRA_VERSION=claws3
+EXTRA_VERSION=claws4
 VERSION=$MAJOR_VERSION.$MINOR_VERSION.$MICRO_VERSION$EXTRA_VERSION
 
 dnl set $target
index e0798b1..2e578b4 100644 (file)
@@ -12,6 +12,7 @@ EXTRA_TOOLS = \
        kmail2sylpheed.pl \
        kmail2sylpheed_v2.pl \
        launch_phoenix \
+       maildir2sylpheed.pl \
        multiwebsearch.pl \
        newscache_clean.pl \
        outlook2sylpheed.pl \
diff --git a/tools/maildir2sylpheed.pl b/tools/maildir2sylpheed.pl
new file mode 100644 (file)
index 0000000..d2ffcad
--- /dev/null
@@ -0,0 +1,135 @@
+#!/usr/bin/perl
+
+#  * Copyright © 2003 Paul Mangan <claws@thewildbeast.co.uk>
+#  *
+#  * This file is free software; you can redistribute it and/or modify it
+#  * under the terms of the GNU General Public License as published by
+#  * the Free Software Foundation; either version 2 of the License, or
+#  * (at your option) any later version.
+#  *
+#  * This program is distributed in the hope that it will be useful, but
+#  * WITHOUT ANY WARRANTY; without even the implied warranty of
+#  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+#  * General Public License for more details.
+#  *
+#  * You should have received a copy of the GNU General Public License
+#  * along with this program; if not, write to the Free Software
+#  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+## script name : maildir2sylpheed.pl
+
+## script purpose : convert a Kmail mailbox into a Sylpheed mailbox
+
+## USAGE: maildir2sylpheed.pl --kmaildir=Mail
+
+## tested with Kmail 1.5.2
+
+use Getopt::Long;
+use File::Recurse;
+
+$kmaildir  = '';
+$iNeedHelp = '';
+
+$sylpheed_tmpdir = "sylpheed_tmp";
+$kmail_olddir    = "kmail_junk";
+
+GetOptions("kmaildir=s" => \$kmaildir,
+          "help"        => \$iNeedHelp);
+
+if ($kmaildir eq "" || $iNeedHelp) {
+       if (!$iNeedHelp) {
+               print "No directory name given\n";
+       }
+       print "Use the following format:\n";
+       print "\tmaildir2sylpheed.pl --kmaildir=mail_folder_name\n\n";
+       print "For example: 'Mail'\n";
+       exit;
+}
+
+chdir($ENV{HOME});
+
+$MAIL_dir = "$ENV{HOME}/$kmaildir";
+
+mkdir("$sylpheed_tmpdir", 0755);
+
+my %files = Recurse(["$MAIL_dir"], {});
+
+foreach (keys %files) { 
+       $dir = $_;
+       push(@dirs, "$_");
+       foreach (@{ $files{$_} }) { 
+               push(@files, "$dir/$_");
+       }
+}
+
+foreach $direc (@dirs) {
+       if ($direc !~ m/^drafts$/
+           && $direc !~ m/^outbox$/
+           && $direc !~ m/^trash$/
+           && $direc !~ m/^inbox$/) {
+               $tmpdir = $direc;
+               $tmpdir =~ s/^$MAIL_dir//;
+               $tmpdir =~ s/sent-mail/sent/;
+               $tmpdir =~ s/\/cur$//;
+               $tmpdir =~ s/\/new$//;
+               $tmpdir =~ s/^\///;
+               $tmpdir =~ s/\.directory//g;
+               $tmpdir =~ s/\.//g;
+               mkdir("$sylpheed_tmpdir/$tmpdir");
+               opendir(DIR, "$direc")
+                       || die("Can't open directory");
+               push(@subdirs,(readdir(DIR)));
+               closedir DIR;
+       }
+
+       foreach $subdir (@subdirs) {
+               if ($subdir !~ m/\.directory$/
+                   && $subdir!~ m/^\.*$/
+                   && $subdir !~ m/cur\/$/
+                   && $subdir !~ m/new\/$/
+                   && $subdir !~ m/tmp\/$/) {
+                       $sub_dir =~ s/\.directory//;
+                       unless (-e "$sylpheed_tmpdir/$tmpdir/$sub_dir") {
+                               mkdir("$sylpheed_tmpdir/$tmpdir/$sub_dir");
+                       }
+               }               
+       }
+}
+
+$count = 1;
+foreach $file (@files) {
+       $tmpfile = $file;
+       if ($tmpfile =~ m/\/cur\//
+           || $tmpfile =~ m/\/new\//) {
+               $tmpfile =~ s/\/new//;
+               $tmpfile =~ s/\/cur//;
+               @spl_str = split("/", $tmpfile);
+               pop(@spl_str);
+               push(@spl_str, "$count");
+               foreach $spl_str (@spl_str) {
+                       $spl_str =~ s/^\.//;
+                       $spl_str =~ s/\.directory$//;
+                       $spl_str =~ s/sent-mail/sent/;
+               }
+               $nfile = join("/", @spl_str);
+               $nfile =~ s/\/$kmaildir\//\/$sylpheed_tmpdir\//;
+       }
+
+       if (-e "$file" && $nfile ne "") {
+               system("cp \"$file\" \"$nfile\"");
+               $count++;
+       }       
+}
+
+system("mv $kmaildir $kmail_olddir");
+system("mv $sylpheed_tmpdir $ENV{HOME}/Mail");
+
+print "Sucessfully converted mailbox \"$MAIL_dir\"\n";
+print "Start Sylpheed and right-click \"Mailbox (MH)\" and ";
+print "select \"Rebuild folder tree\"\n";
+print "You may also need to run \"/File/Folder/Check for "
+print "new messages in all folders\"\n\n";
+print "Your kmail directories have been backed-up to\n";
+print "$ENV{HOME}/$kmail_olddir\n\n";
+
+exit;