| 1 | package Mail::Clean; | ||
| 2 | use strict; | ||
| 3 | use Exporter 'import'; | ||
| 4 | use vars qw($VERSION); | ||
| 5 | $VERSION = '0.06'; | ||
| 6 | |||
| 7 | use vars qw(@EXPORT_OK); | ||
| 8 | @EXPORT_OK = qw( clean_subject ); | ||
| 9 | |||
| 10 | =head1 NAME | ||
| 11 | |||
| 12 | Mail::Clean - clean up mail parts | ||
| 13 | |||
| 14 | =cut | ||
| 15 | |||
| 16 | use vars qw(%subject_prefixes); | ||
| 17 | |||
| 18 | # https://en.wikipedia.org/wiki/List_of_email_subject_abbreviations | ||
| 19 | %subject_prefixes = ( | ||
| 20 | 'Re:' => 1, | ||
| 21 | 'Aw:' => 1, | ||
| 22 | 'Antw.:' => 1, | ||
| 23 | 'Antwort:' => 1, | ||
| 24 | 'Fwd:' => 1, | ||
| 25 | 'Sv:' => 1, | ||
| 26 | 'Vs:' => 1, | ||
| 27 | ); | ||
| 28 | |||
| 29 | =head2 C<< clean_subject( $subject ) >> | ||
| 30 | |||
| 31 | Removes the forwarding and in-reply-to prefixes | ||
| 32 | from mail titles, leaving only what whas hopefully | ||
| 33 | the original mail title. | ||
| 34 | |||
| 35 | =cut | ||
| 36 | |||
| 37 | sub clean_subject { | ||
| 38 | my( $subject ) = @_; | ||
| 39 | # This should be cached for perfomance reasons | ||
| 40 | my $cleaner = join "|", | ||
| 41 | map { quotemeta($_) } | ||
| 42 | sort { length $b <=> length $a || $a cmp $b } | ||
| 43 | keys %subject_prefixes; | ||
| 44 | $subject =~ s/^(?:(?:$cleaner)\s*)+//i; | ||
| 45 | $subject | ||
| 46 | }; | ||
| 47 | |||
| 48 | 1; |