[Commits] [SCM] claws branch, master, updated. 3.17.0-108-g1be4e8b

mones at claws-mail.org mones at claws-mail.org
Mon Oct 8 15:51:46 CEST 2018


The branch, master has been updated
       via  1be4e8b27b6cd7977df039ff5e34fd80fceb580a (commit)
       via  788d627c282bd3e8829383fe3dcbe47b0f285671 (commit)
      from  595de51b0f44e283734b08ed785c75ba879983da (commit)

Summary of changes:
 tools/README         |   90 ++++++++++++++++++++++++++++++------
 tools/cm-break.pl    |  124 ++++++++++++++++++++++++++++++++++++++++++++++++++
 tools/cm-reparent.pl |   53 ++++++++++++++-------
 tools/textviewer.pl  |  103 ++++++++++++++++++++++++++++-------------
 4 files changed, 309 insertions(+), 61 deletions(-)
 create mode 100644 tools/cm-break.pl


- Log -----------------------------------------------------------------
commit 1be4e8b27b6cd7977df039ff5e34fd80fceb580a
Author: Ricardo Mones <ricardo at mones.org>
Date:   Mon Oct 8 15:51:15 2018 +0200

    Update textviewer.pl
    
    Patch by H.Merijn Brand

diff --git a/tools/README b/tools/README
index d562f46..5383def 100644
--- a/tools/README
+++ b/tools/README
@@ -707,18 +707,25 @@ Other tools
   WHAT IT DOES
 	This script tries to recognise an attachment by using the 'file'
 	command and/or the file extension and then uses the available
-	utilities to make an effort to display it as text. For example
-		.doc			antiword -w 72
-		.txt, .diff, .c, .h,
-  		  .ic. .ec, .cc, .sh,
-  		  .sed, .awk		cat
-		.html			txt2htm	or text2html
-		.xls, .sxc, .csv	xlscat -L
-		.rtf			rtf2text
-		.pdf			pdf2text %f -
-		.odt			ooo2txt
-		.pl, .pm		perltidy -st -se or  cat
-		.bz2			bzip2 -d < %f | strings
+	utilities to make an effort to display it as text.
+
+	$ textview.pl --list
+
+	will show available conversion, the top:
+
+	  .awk          cat
+	  .bin          strings
+	  .bz2          bzip2 -d < %f | strings
+	  .c            cat
+	  .cc           cat
+	  .csv          xlscat -L
+
+	If there are multiple alternatives available, they are listed in
+	the ordder they are tried, like for .xls:
+
+	  .xls          xlscat -L
+	  .xls          catdoc -x -dutf-8
+	  .xls          wvText
 
   HOW TO USE IT
   	Go to /Configuration/Message View/External Programs and enter the
@@ -726,7 +733,10 @@ Other tools
 	Now when you right-click an attachment and choose 'Display as text'
 	this script will be invoked.
 
-	
+	xlscat comes with the perl module Spreadsheet::Read, which is a
+	wrapper module over several parsers and supports ods, sxc, csv, xls,
+	xlsx, and sq.  See https://metacpan.org/release/Spreadsheet-Read
+
   Contact: H.Merijn Brand <h.m.brand at xs4all.nl>
 
 
diff --git a/tools/textviewer.pl b/tools/textviewer.pl
index 6851196..e9f04ae 100755
--- a/tools/textviewer.pl
+++ b/tools/textviewer.pl
@@ -1,44 +1,42 @@
 #!/usr/bin/perl
 
 # COPYRIGHT AND LICENSE
-#        Copyright (C) 2005-2006 H.Merijn Brand
+#        Copyright (C) 2005-2018 H.Merijn Brand
 #
 #        This script is free software; you can redistribute it and/or modify it
 #        under the same terms as Perl and/or Claws Mail itself. (GPL)
 
-use strict;
+use 5.14.1;
 use warnings;
 
-sub usage ($;$)
-{
+our $VERSION = "1.01 - 2018-10-08";
+our $CMD = $0 =~ s{.*/}{}r;
+
+sub usage {
     my ($err, $str) = (@_, "");
     $err and select STDERR;
-    print
-	"usage: $0 [--html] [--type=<type>] file\n",
+    say "usage: $CMD [--html] [--type=<type>] file\n",
 	"       --html    Generate HTML (if supported)\n",
-	"       --type=X  X as mimetype (msword => doc)\n";
-    $str and print "$str\n";
+	"       --type=X  X as mimetype (msword => doc)\n",
+	"  $CMD --list will show all implemented conversions";
+    $str and say $str;
     exit $err;
     } # usage
 
- at ARGV == 1 and $ARGV[0] eq "-?" || $ARGV[0] =~ m/^-+help$/ and usage (0);
-
 use Getopt::Long qw(:config bundling nopermute);
 my $opt_v = 0;
-my $opt_t;
 my $opt_h = "text";
 GetOptions (
+    "help|?"		=> sub { usage (0); },
+    "V|version"		=> sub { say "$CMD [$VERSION]"; exit 0; },
+
     "v|verbose:1"	=> \$opt_v,
-    "t|type|mimetype=s"	=> \$opt_t,
+    "t|type|mimetype=s"	=> \my $opt_t,
     "h|html"		=> sub { $opt_h = "html" },
+    "l|list!"		=> \my $opt_l,
     ) or usage (1);
 
-$opt_v and print "$0 @ARGV\n";
-
-my $file = shift or usage (1, "File argument is missing");
--f $file         or usage (1, "File argument is not a plain file");
--r $file         or usage (1, "File argument is not a readable file");
--s $file         or usage (1, "File argument is an empty file");
+$opt_v and say "$0 @ARGV";
 
 # anon-list contains all possible commands to show content
 # plain text is a reference to same type (alias)
@@ -49,40 +47,65 @@ my %fh = (
 
 	txt	=> [ "cat"		], # Plain text
 
-	html	=> [ "txt2htm",
-		     "text2html"	], # HTML
+	html	=> [ "htm2txt",
+		     "html2text"	], # HTML
 
 	msword	=> "doc",
-	doc	=> [ "antiword -w 72"	], # M$ Word
+	doc	=> [ "catdoc -x -dutf-8",
+		     "wvText",
+		     "antiword -w 72"	], # M$ Word
 	"vnd.ms-excel" => "xls",
 	"ms-excel"     => "xls",
-	xls	=> [ "xlscat -L"	], # M$ Excel
+	docx	=> [ "unoconv -f text --stdout"	], # MS Word
+	xlsx	=> "xls",
+	xls	=> [ "xlscat -L",
+		     "catdoc -x -dutf-8",
+		     "wvText"		], # M$ Excel
 #	ppt	=> [ "ppthtml"		], # M$ PowerPoint
 #			ppthtml "$1" | html2text
+	csv	=> "xls",		   # Comma Separated Values
+
+	ics	=> [ "ics2txt"		], # ICS calendar request
 
 	rtf	=> [ "rtf2text",
 		     "unrtf -t text"	], # RTF
 	pdf	=> [ "pdftotext %f -"	], # Adobe PDF
 
+	ods	=> "xls",		   # OpenOffice spreadsheet
 	sxc	=> "xls",		   # OpenOffice spreadsheet
-	odt	=> [ "ooo2txt"		], # OpenOffice writer
-
-	csv	=> "xls",		   # Comma Separated Values
+	odt	=> [ "oo2pod %f | pod2text",
+		     "ooo2txt"		], # OpenOffice writer
+	rtf	=> [ "rtf2text"		], # RTF
 
 	pl	=> [ "perltidy -st -se",
 		     "cat"		], # Perl
 	pm	=> "pl",
 
+	jsn	=> [ "json_pp"		], # JSON
+	json	=> "jsn",
+
+	xml	=> [ "xml_pp"		], # XML
+
 	( map { $_ => "txt" } qw(
-	    diff
+	    patch diff
 	    c h ic ec cc
 	    sh sed awk
 	    plain
+	    yml yaml
 	    )),
 
 	bz2	=> [ "bzip2 -d < %f | strings" ],
 
+	zip	=> [ "unzip -l %f"	], # ZIP
+
 	test	=> [ \&test		], # Internal
+
+	tgz	=> [ "tar tvf"		], # Tar     uncompressed
+	tgz	=> [ "tar tzvf"		], # Tar GZ    compressed
+	tbz	=> [ "tar tjvf"		], # Tar BZip2 compressed
+	txz	=> [ "tar tJvf"		], # Tar XZ    compressed
+
+	rar	=> [ "unrar l"		], # RAR
 	},
 
     html => {
@@ -90,6 +113,21 @@ my %fh = (
 	},
     );
 
+if ($opt_l) {
+    my %tc = %{$fh{text}};
+    foreach my $ext (sort keys %tc) {
+	my $exe = $tc{$ext};
+	ref $exe or $exe = $tc{$exe};
+	printf "  .%-12s %s\n", $ext, $_ for @$exe;
+	}
+    exit 0;
+    }
+
+my $file = shift or usage (1, "File argument is missing");
+-f $file         or usage (1, "File argument is not a plain file");
+-r $file         or usage (1, "File argument is not a readable file");
+-s $file         or usage (1, "File argument is an empty file");
+
 my $ext = $file =~ m/\.(\w+)$/ ? lc $1 : "";
 $opt_t && exists $fh{text}{lc $opt_t} and $ext = lc$opt_t;
 unless (exists $fh{text}{$ext}) {
@@ -111,10 +149,9 @@ exists $fh{$opt_h}{$ext} or $ext   = "txt";
 my          $ref = $fh{$opt_h}{$ext};
 ref $ref or $ref = $fh{$opt_h}{$ref};
 
-$opt_v and print STDERR "[ @$ref ] $file\n";
+$opt_v and warn "[ @$ref ] $file\n";
 
-sub which ($)
-{
+sub which {
     (my $cmd = shift) =~ s/\s.*//; # Only the command. Discard arguments here
     foreach my $path (split m/:+/, $ENV{PATH}) {
 	-x "$path/$cmd" and return "$path/$cmd";
@@ -134,6 +171,8 @@ foreach my $c (@$ref) {
     last;
     }
 
-$cmd =~ s/%f\b/$file/g or $cmd .= " $file";
-$opt_v and print "$cmd\n";
-exec $cmd;
+my @cmd = split m/ +/ => $cmd;
+grep { s/%f\b/$file/ } @cmd or push @cmd, $file;
+#$cmd =~ s/%f\b/$file/g or $cmd .= " $file";
+$opt_v and say "@cmd";
+exec @cmd;

commit 788d627c282bd3e8829383fe3dcbe47b0f285671
Author: Ricardo Mones <ricardo at mones.org>
Date:   Mon Oct 8 15:49:29 2018 +0200

    Update thread tools
    
    Patch by H.Merijn Brand

diff --git a/tools/README b/tools/README
index 9d81d64..d562f46 100644
--- a/tools/README
+++ b/tools/README
@@ -5,6 +5,7 @@ Contents of the tools directory:
 
 Action scripts:
   cm-reparent.pl                Fix thread parenting for two or more messages
+  cm-break.pl                   Remove thread parenting for one or more messages
   freshmeat_search.pl           Search freshmeat.net for selected text
   google_msgid.pl               Search groups.google.com for selected message-id
   google_search.pl              Search google.com for selected text
@@ -65,6 +66,11 @@ Action scripts
   COMMAND: cm-reparent.pl %F
   Thread the selected messages based on date, old to new
 
+* cm-break.pl
+  WORKS ON: selected messages (one or more)
+  COMMAND: cm-break.pl %F
+  Break thread references for the selected messages
+
 * google_msgid.pl
   WORKS ON: selection
   COMMAND: |google_msgid.pl
@@ -825,3 +831,51 @@ Extra tools
 This file is Copyright 1999-2014 by the Claws Mail team.
 See accompanying COPYING file for license details.
 See each included script for copyright and license details.
+
+* cm-reparent.pl
+
+  WHAT IT DOES
+	This script tries to fix thread parenting for two or more messages
+
+  HOW TO USE IT
+	Define an action as
+
+	  Menu name:  Reparent (fix threading)
+	  Command:    cm-reparent.pl %F
+
+	Then select from the message list all files that should be re-parented
+
+	Then invoke the action
+
+  MORE INFORMATION
+	$ perldoc cm-reparent.pl
+
+  REQUIREMENTS
+	Date::Parse
+	Getopt::Long
+
+  Contact: H.Merijn Brand <h.m.brand at xs4all.nl>
+
+* cm-break.pl
+
+  WHAT IT DOES
+	This script tries to break thread parenting for one or more messages
+
+  HOW TO USE IT
+	Define an action as
+
+	  Menu name:  Unthread (break threading)
+	  Command:    cm-break.pl %F
+
+	Then select from the message list all files that should be un-threaded
+
+	Then invoke the action
+
+  MORE INFORMATION
+	$ perldoc cm-break.pl
+
+  REQUIREMENTS
+	Date::Parse
+	Getopt::Long
+
+  Contact: H.Merijn Brand <h.m.brand at xs4all.nl>
diff --git a/tools/cm-break.pl b/tools/cm-break.pl
new file mode 100644
index 0000000..7553b17
--- /dev/null
+++ b/tools/cm-break.pl
@@ -0,0 +1,124 @@
+#!/usr/bin/perl
+
+use 5.14.1;
+use warnings;
+
+our $VERSION = "1.05 - 2018-10-08";
+our $cmd = $0 =~ s{.*/}{}r;
+
+sub usage {
+    my $err = shift and select STDERR;
+    say "usage: $cmd file ...";
+    exit $err;
+    } # usage
+
+use Date::Parse;
+use Getopt::Long;
+GetOptions (
+    "help|?"	=> sub { usage (0); },
+    "V|version"	=> sub { say "$cmd [$VERSION]"; exit 0; },
+    ) or usage (1);
+
+my %f;
+foreach my $fn (@ARGV) {
+
+    open my $fh, "<", $fn or die "$fn: $!\n";
+    my ($hdr, $body) = split m/(?<=\n)(?=\r?\n)/ => do { local $/; <$fh> }, 2;
+    close $fh;
+
+    $hdr && $hdr =~ m/\b(?:In-Reply-To|References)\b/i or next;
+
+    my ($mid) = $hdr =~ m{^Message-Id:  (?:[\x20\t]*\n)?[\x20\t]+ (\S.*)}xmi;
+    my ($dte) = $hdr =~ m{^Date:        (?:[\x20\t]*\n)?[\x20\t]+ (\S.*)}xmi;
+    my ($irt) = $hdr =~ m{^In-Reply-To: (?:[\x20\t]*\n)?[\x20\t]+ (\S.*)}xmi;
+    my ($ref) = $hdr =~ m{^References:  (?:[\x20\t]*\n)?[\x20\t]+ (\S.*)}xmi;
+
+    my $stamp = str2time ($dte) or die $dte;
+    my $date = $stamp ? do {
+	my @d = localtime $stamp;
+	sprintf "%4d-%02d-%02d %02d:%02d:%02d", $d[5] + 1900, ++$d[4], @d[3,2,1,0];
+	} : "-";
+    #printf "%12s %-20s %s\n", $stamp // "-", $date, $rcv;
+
+    $f{$fn} = {
+	msg_id	=> $mid,
+	refs	=> $ref,
+	irt	=> $irt,
+	date	=> $dte,
+	stamp	=> $stamp,
+	sdate	=> $date,
+
+	hdr	=> $hdr,
+	body	=> $body,
+	};
+    }
+
+foreach my $fn (sort keys %f) {
+
+    my $c = 0;
+
+    my $f = $f{$fn};
+    if ($f->{refs}) {
+	$c++;
+	$f->{hdr} =~ s{\nReferences:.*(?:\n\s+.*)*+}{}ig;
+	}
+    if ($f->{irt}) {
+	$c++;
+	$f->{hdr} =~ s{\nIn-Reply-To:.*(?:\n\s+.*)*+}{}ig;
+	}
+
+    $c or next;	# No changes required
+
+    say "$f->{msg_id} => -";
+
+    my @t = stat $fn;
+    open my $fh, ">", $fn or die "$fn: $!\n";
+    print   $fh $f->{hdr}, $f->{body};
+    close   $fh or die "$fn: $!\n";
+    utime $t[8], $t[9], $fn;
+    }
+
+__END__
+
+=head1 NAME
+
+cm-break.pl - remove mail from thread
+
+=head1 SYNOPSIS
+
+ cm-break.pl ~/Mail/inbox/23 ~/Mail/inbox/45 ...
+
+=head1 DESCRIPTION
+
+This script should be called from within Claws-Mail as an action
+
+Define an action as
+
+  Menu name:  Unthread (break threading)
+  Command:    cm-break.pl %F
+
+Then select from the message list all files that should be un-threaded
+
+Then invoke the action
+
+All of those mails will be modified (if needed): their C<In-Reply-To:>
+and C<References:> header tags are removed from the header.
+
+=head1 SEE ALSO
+
+L<Date::Parse>, L<Claws Mail|http://www.claws-mail.org>
+cm-reparent.pl
+
+=head1 AUTHOR
+
+H.Merijn Brand <h.m.brand at xs4all.nl>
+
+=head1 COPYRIGHT AND LICENSE
+
+ Copyright (C) 2018-2018 H.Merijn Brand.  All rights reserved.
+
+This library is free software;  you can redistribute and/or modify it under
+the same terms as Perl itself.
+See the L<Artistic license|http://dev.perl.org/licenses/artistic.html>.
+
+=cut
diff --git a/tools/cm-reparent.pl b/tools/cm-reparent.pl
index 9a16da2..30eb7fd 100755
--- a/tools/cm-reparent.pl
+++ b/tools/cm-reparent.pl
@@ -3,11 +3,12 @@
 use 5.14.1;
 use warnings;
 
-our $VERSION = "1.02 - 2016-06-07";
+our $VERSION = "1.05 - 2018-10-08";
+our $cmd = $0 =~ s{.*/}{}r;
 
 sub usage {
     my $err = shift and select STDERR;
-    say "usage: $0 file ...";
+    say "usage: $cmd file ...";
     exit $err;
     } # usage
 
@@ -15,7 +16,7 @@ use Date::Parse;
 use Getopt::Long;
 GetOptions (
     "help|?"	=> sub { usage (0); },
-    "V|version"	=> sub { say $0 =~ s{.*/}{}r, " [$VERSION]"; exit 0; },
+    "V|version"	=> sub { say "$cmd [$VERSION]"; exit 0; },
     ) or usage (1);
 
 my $p;
@@ -26,35 +27,47 @@ foreach my $fn (@ARGV) {
     my ($hdr, $body) = split m/(?<=\n)(?=\r?\n)/ => do { local $/; <$fh> }, 2;
     close $fh;
 
-    $hdr or next;
-
-    my ($mid) = $hdr =~ m{^Message-Id: (.*)}mi;
-    my ($dte) = $hdr =~ m{^Date: (.*)}mi;
-    my ($irt) = $hdr =~ m{^In-Reply-To: (.*)}mi;
-    my ($ref) = $hdr =~ m{^References: (.*)}mi;
-
-    my $stamp = str2time ($dte) or next;
+    $hdr && $hdr =~ m/\b(?:Date|Received)\b/ or next;
+
+    my ($mid) = $hdr =~ m{^Message-Id:  (?:[\x20\t]*\n)?[\x20\t]+ (\S.*)}xmi;
+    my ($dte) = $hdr =~ m{^Date:        (?:[\x20\t]*\n)?[\x20\t]+ (\S.*)}xmi;
+    my ($rcv) = $hdr =~ m{\nReceived:   (?:[\x20\t]*\n)?[\x20\t]+ (\S.*(?:\n\s+.*)*+)}xi;
+    my ($irt) = $hdr =~ m{^In-Reply-To: (?:[\x20\t]*\n)?[\x20\t]+ (\S.*)}xmi;
+    my ($ref) = $hdr =~ m{^References:  (?:[\x20\t]*\n)?[\x20\t]+ (\S.*)}xmi;
+
+    $rcv ||= $dte;
+    $rcv =~ s/[\s\r\n]+/ /g;
+    $rcv =~ s/\s+$//;
+    $rcv =~ s/.*;\s*//;
+    $rcv =~ s/.* id \S+\s+//i;
+    my $stamp = str2time ($rcv) or die $rcv;
+    my $date = $stamp ? do {
+	my @d = localtime $stamp;
+	sprintf "%4d-%02d-%02d %02d:%02d:%02d", $d[5] + 1900, ++$d[4], @d[3,2,1,0];
+	} : "-";
+    #printf "%12s %-20s %s\n", $stamp // "-", $date, $rcv;
 
     $f{$fn} = {
 	msg_id	=> $mid,
 	refs	=> $ref,
 	irt	=> $irt,
 	date	=> $dte,
+	rcvd	=> $rcv,
 	stamp	=> $stamp,
+	sdate	=> $date,
 
 	hdr	=> $hdr,
 	body	=> $body,
 	};
 
     $p //= $fn;
-
     $stamp < $f{$p}{stamp} and $p = $fn;
     }
 
 # All but the oldest will refer to the oldest as parent
 
 $p or exit 0;
-my $pid = $f{$p}{msg_id};
+my $pid = $f{$p}{msg_id} or die "Parent file $p has no Message-Id\n";
 
 foreach my $fn (sort keys %f) {
 
@@ -86,11 +99,18 @@ foreach my $fn (sort keys %f) {
 
     $c or next;	# No changes required
 
+    unless ($f->{msg_id}) {
+	warn "Child message $fn has no Message-Id, skipped\n";
+	next;
+	}
+
     say "$f->{msg_id} => $pid";
 
+    my @t = stat $fn;
     open my $fh, ">", $fn or die "$fn: $!\n";
-    print $fh $f->{hdr}, $f->{body};
-    close $fh or die "$fn: $!\n";
+    print   $fh $f->{hdr}, $f->{body};
+    close   $fh or die "$fn: $!\n";
+    utime $t[8], $t[9], $fn;
     }
 
 __END__
@@ -149,6 +169,7 @@ C<X-In-Reply-To:> respectively.
 =head1 SEE ALSO
 
 L<Date::Parse>, L<Claws Mail|http://www.claws-mail.org>
+cm-break.pl
 
 =head1 AUTHOR
 
@@ -156,7 +177,7 @@ H.Merijn Brand <h.m.brand at xs4all.nl>
 
 =head1 COPYRIGHT AND LICENSE
 
- Copyright (C) 2016-2016 H.Merijn Brand.  All rights reserved.
+ Copyright (C) 2016-2018 H.Merijn Brand.  All rights reserved.
 
 This library is free software;  you can redistribute and/or modify it under
 the same terms as Perl itself.

-----------------------------------------------------------------------


hooks/post-receive
-- 
Claws Mail


More information about the Commits mailing list