talons

Fork of Claws Mail https://www.claws-mail
Log | Files | Refs | README | LICENSE

commit a0623d9247ff1c3ecbf5b81b554071889125fc64
parent a1e39ff5b7455e40cb882cded91655499d72bc8d
Author: Ricardo Mones <mones@claws-mail.org>
Date:   Sun, 20 Sep 2009 12:57:21 +0000

2009-09-20 [mones]	3.7.2cvs35

	* tools/convert_mbox.pl
		Add -R flag to support recursive conversions
		of arbitrary Evolution mail folders, based on
		bash script by Daniel Dickinson (fixes debian
		bug #461435)
	* tools/popfile-link.sh
		Set required shell for script (fixes debian
		bug #530057)

Diffstat:
MChangeLog | 11+++++++++++
MPATCHSETS | 1+
Mconfigure.ac | 2+-
Mtools/convert_mbox.pl | 182++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----------------
Mtools/popfile-link.sh | 2+-
5 files changed, 157 insertions(+), 41 deletions(-)

diff --git a/ChangeLog b/ChangeLog @@ -1,3 +1,14 @@ +2009-09-20 [mones] 3.7.2cvs35 + + * tools/convert_mbox.pl + Add -R flag to support recursive conversions + of arbitrary Evolution mail folders, based on + bash script by Daniel Dickinson (fixes debian + bug #461435) + * tools/popfile-link.sh + Set required shell for script (fixes debian + bug #530057) + 2009-09-16 [colin] 3.7.2cvs34 * src/main.c diff --git a/PATCHSETS b/PATCHSETS @@ -3859,3 +3859,4 @@ ( cvs diff -u -r 1.75.2.65 -r 1.75.2.66 src/matcher.c; cvs diff -u -r 1.39.2.17 -r 1.39.2.18 src/matcher.h; cvs diff -u -r 1.25.2.33 -r 1.25.2.34 src/matcher_parser_parse.y; cvs diff -u -r 1.43.2.81 -r 1.43.2.82 src/prefs_matcher.c; ) > 3.7.2cvs32.patchset ( cvs diff -u -r 1.49.2.130 -r 1.49.2.131 src/procmime.c; ) > 3.7.2cvs33.patchset ( cvs diff -u -r 1.115.2.222 -r 1.115.2.223 src/main.c; ) > 3.7.2cvs34.patchset +( cvs diff -u -r 1.3.2.2 -r 1.3.2.3 tools/convert_mbox.pl; cvs diff -u -r 1.1.2.3 -r 1.1.2.4 tools/popfile-link.sh; ) > 3.7.2cvs35.patchset diff --git a/configure.ac b/configure.ac @@ -12,7 +12,7 @@ MINOR_VERSION=7 MICRO_VERSION=2 INTERFACE_AGE=0 BINARY_AGE=0 -EXTRA_VERSION=34 +EXTRA_VERSION=35 EXTRA_RELEASE= EXTRA_GTK2_VERSION= diff --git a/tools/convert_mbox.pl b/tools/convert_mbox.pl @@ -16,7 +16,9 @@ # Making these changes requires further changes in the script # that results in much longer run-times. # -# Copyright © 2003 Fred Marton +# Copyright (c) 2003 Fred Marton +# Copyright (c) 2009 Ricardo Mones, based on the bash script +# by Daniel Dickinson [1] # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License @@ -32,53 +34,155 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA # 02111-1307, USA. +# +# [1] http://bugs.debian.org/cgi-bin/bugreport.cgi?msg=15;filename=convert_mbox.sh;att=1;bug=461435 + +use File::Path; +use File::Basename; -# check for both arguments +# check for arguments &usage if ($#ARGV < 1); -$mbox = $ARGV[0]; -$mh = $ARGV[1]; -# check to make sure there isn't something named MH already -if (-e $mh) { - die (" The directory \"$mh\" already exists. Exiting.\n"); +if ($ARGV[0] eq "-R") { + # recursive, need more args + &usage if ($#ARGV < 2); + &usage unless (-d $ARGV[1]); + &usage unless (-d $ARGV[2]); + &convert_all ($ARGV[1], $ARGV[2]); } else { - mkdir $mh; + # default behaviour + &convert_mbox ($ARGV[0], $$ARGV[1]); +} + +sub strip_sbd { + # raw translation of bash, probably doable in real Perl better + $dirname = shift; + $nosbddir = ""; + $dirleft = $dirname; + while ($dirleft ne "." and $dirleft ne "") { + $enddir = &basename ($dirleft, ['.sbd']); + if ($nosbddir ne "") { + $nosbddir = "$enddir/$nosbddir"; + } + else { + $nosbddir = $enddir; + } + $dirleft = &dirname ($dirleft); + } + print "$nosbddir\n"; +} + +sub convert_all { + ($mboxdir, $targetdir) = @_; + $tmpbase = '/tmp/frommbox'; + $tmplist = '/tmp/.convert_mbox.filelist'; + $curdir = qx/pwd/; + chdir ($mboxdir); + qx/find * -type -d -a ! -name '*.*'i | sort > $tmplist/; + open (FLH, "<$tmplist") or die "cannot open $tmplist: $!\n"; + while (<FLH>) { + chomp; + &convert_one ($_, $targetdir, $tmpbase); + } + close (FLH); + unlink ($tmplist); + chdir ($curdir); } -# start numbering -$i = 0; -# open the mbox file -open (IN, $mbox); -while ($line = <IN>) { -# check for the beginning of an e-mail - @word = split(/ +/m,$line); -# some lines might start with "From ", so check -# to see if the [second-to-]last word is a year - @word2 = split(/:/,$line); - chomp($word2[$#word2]); - @word3 = split(/ /,$word2[2]); - $year = @word3[1]; -# ignore the MAILER-DAEMON message from pine - if (@word[1] ne "MAILER-DAEMON") { -# start a new file, assuming $year is > 1970 + +sub convert_one { + # targetdir isn't used in the original bash script, maybe a bug? + ($file, $targetdir, $tmpbase) = @_; + $dirname = &dirname ($file); + $filename = &basename ($file); + if ($dirname eq $filename) { + $dirname = ""; + } + $dirname = &strip_sbd ($dirname); + if ($dirname ne "") { + $dirname = "/$dirname"; + } + &mkpath ($tmpbase . $dirname); + $basefile = &basename ($file); + $base1 = &basename ($file, ['.cmeta']); + $base2 = &basename ($base1, ['.ibex.index']); + $base3 = &basename ($base2, ['.ibex.index.data']); + $base5 = &basename ($base3, ['.ev-summary']); + $base4 = &basename ($base5, ['.ev-summary-meta']); + $subdir = &basename ($dirname); + $basedir = "/" . &dirname ($dirname); + if ( $basedir eq '/.' or $basedir eq '/' ) { + $basedir = $dirname; + $subdir = ""; + } + $basedir = $tmpbase . $basedir; + &mkpath ($basedir); + $dirisfile = 0; + if ( -f "$basedir/$subdir" ) { + $dirisfile = 1; + qx/mv \"$basedir\/$subdir\" \"$basedir\/$subdir.tmp\"/; + &mkpath ("$basedir/$subdir"); + } + if ( ! -d "$basedir/$subdir/$base4" ) { + print "$basedir/$subdir/$base4\n"; + &convert_mbox ($file, "$basedir/$subdir/$base4", 'quiet'); + if ($dirisfile == 1) { + qx/mv \"$basedir\/$subdir.tmp\/*\" \"$basedir\/$subdir\/\"/; + } + } +} + + +sub convert_mbox { + ($mbox, $mh, $quiet) = @_; + # check to make sure there isn't something named MH already + if (-e $mh) { + die (" The directory \"$mh\" already exists. Exiting.\n"); + } + else { + mkdir $mh; + } + # start numbering + $i = 0; + # open the mbox file + open (IN, $mbox); + while ($line = <IN>) { + # check for the beginning of an e-mail + @word = split(/ +/m,$line); + # some lines might start with "From ", so check + # to see if the [second-to-]last word is a year + @word2 = split(/:/,$line); + chomp($word2[$#word2]); + @word3 = split(/ /,$word2[2]); + $year = @word3[1]; + # ignore the MAILER-DAEMON message from pine + if (@word[1] ne "MAILER-DAEMON") { + # start a new file, assuming $year is > 1970 if (@word[0] eq "From" && $year > 1970) { - $i++; - close (OUT); - open (OUT, ">$mh/$i"); - print OUT $line; + $i++; + close (OUT); + open (OUT, ">$mh/$i"); + print OUT $line; } else { -# continue the file - print OUT $line; + # continue the file + print OUT $line; } - } + } + } + close (OUT); + close (IN); + # and we're done + if (! defined($quiet)) { + print "\n If it isn't there already, please move the directory \"$mh\"\n" + . " into your MH directory and rebuild your folder tree.\n\n"; + } } -close (OUT); -close (IN); -# and we're done -print "\n If it isn't there already, please move the directory \"$mh\"\n" - . " into your MH directory and rebuild your folder tree.\n\n"; -sub usage -{ - die ( " usage: convert_mbox.pl MBOX MH_DIR\n"); +sub usage { + die ("Usage: convert_mbox.pl MBOX MH_DIR\n" + . " convert_mbox.pl -R MBOXDIR MH_DIR\n" + . "Where: \n" + . " -R Converts recursively a directory of mboxes\n"); } + + diff --git a/tools/popfile-link.sh b/tools/popfile-link.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash # * Copyright 2007 Tristan Chabredier <wwp@claws-mail.org> # *