6 our $VERSION = "1.05 - 2018-10-08";
7 our $cmd = $0 =~ s{.*/}{}r;
10 my $err = shift and select STDERR
;
11 say "usage: $cmd file ...";
18 "help|?" => sub { usage
(0); },
19 "V|version" => sub { say "$cmd [$VERSION]"; exit 0; },
23 foreach my $fn (@ARGV) {
25 open my $fh, "<", $fn or die "$fn: $!\n";
26 my ($hdr, $body) = split m/(?<=\n)(?=\r?\n)/ => do { local $/; <$fh> }, 2;
29 $hdr && $hdr =~ m/\b(?:In-Reply-To|References)\b/i or next;
31 my ($mid) = $hdr =~ m{^Message-Id: (?:[\x20\t]*\n)?[\x20\t]+ (\S.*)}xmi;
32 my ($dte) = $hdr =~ m{^Date: (?:[\x20\t]*\n)?[\x20\t]+ (\S.*)}xmi;
33 my ($irt) = $hdr =~ m{^In-Reply-To: (?:[\x20\t]*\n)?[\x20\t]+ (\S.*)}xmi;
34 my ($ref) = $hdr =~ m{^References: (?:[\x20\t]*\n)?[\x20\t]+ (\S.*)}xmi;
36 my $stamp = str2time
($dte) or die $dte;
37 my $date = $stamp ?
do {
38 my @d = localtime $stamp;
39 sprintf "%4d-%02d-%02d %02d:%02d:%02d", $d[5] + 1900, ++$d[4], @d[3,2,1,0];
41 #printf "%12s %-20s %s\n", $stamp // "-", $date, $rcv;
56 foreach my $fn (sort keys %f) {
63 $f->{hdr
} =~ s{\nReferences:.*(?:\n\s+.*)*+}{}ig;
67 $f->{hdr
} =~ s{\nIn-Reply-To:.*(?:\n\s+.*)*+}{}ig;
70 $c or next; # No changes required
72 say "$f->{msg_id} => -";
75 open my $fh, ">", $fn or die "$fn: $!\n";
76 print $fh $f->{hdr
}, $f->{body
};
77 close $fh or die "$fn: $!\n";
78 utime $t[8], $t[9], $fn;
85 cm-break.pl - remove mail from thread
89 cm-break.pl ~/Mail/inbox/23 ~/Mail/inbox/45 ...
93 This script should be called from within Claws-Mail as an action
97 Menu name: Unthread (break threading)
98 Command: cm-break.pl %F
100 Then select from the message list all files that should be un-threaded
102 Then invoke the action
104 All of those mails will be modified (if needed): their C<In-Reply-To:>
105 and C<References:> header tags are removed from the header.
109 L<Date::Parse>, L<Claws Mail|http://www.claws-mail.org>
114 H.Merijn Brand <h.m.brand@xs4all.nl>
116 =head1 COPYRIGHT AND LICENSE
118 Copyright (C) 2018-2018 H.Merijn Brand. All rights reserved.
120 This library is free software; you can redistribute and/or modify it under
121 the same terms as Perl itself.
122 See the L<Artistic license|http://dev.perl.org/licenses/artistic.html>.