File Coverage

blib/lib/Sietima/Role/SubjectTag.pm
Criterion Covered Total %
statement 12 12 100.0
branch n/a
condition n/a
subroutine 4 4 100.0
pod n/a
total 16 16 100.0


line stmt bran cond sub pod time code
1             package Sietima::Role::SubjectTag;
2 1     1   489 use Moo::Role;
  1         1  
  1         6  
3 1     1   309 use Sietima::Policy;
  1         2  
  1         17  
4 1     1   6 use Types::Standard qw(Str);
  1         1  
  1         11  
5 1     1   764 use namespace::clean;
  1         2  
  1         6  
6              
7             our $VERSION = '1.0.5'; # VERSION
8             # ABSTRACT: add a tag to messages' subjects
9              
10              
11             has subject_tag => (
12             is => 'ro',
13             isa => Str,
14             required => 1,
15             );
16              
17              
18             around munge_mail => sub ($orig,$self,$mail) {
19             my $tag = '['.$self->subject_tag.']';
20             my $subject = $mail->header_str('Subject');
21             unless ($subject =~ m{\Q$tag\E}) {
22             $mail->header_str_set(
23             Subject => "$tag $subject",
24             );
25             }
26             return $self->$orig($mail);
27             };
28              
29             1;
30              
31             __END__
32              
33             =pod
34              
35             =encoding UTF-8
36              
37             =head1 NAME
38              
39             Sietima::Role::SubjectTag - add a tag to messages' subjects
40              
41             =head1 VERSION
42              
43             version 1.0.5
44              
45             =head1 SYNOPSIS
46              
47             my $sietima = Sietima->with_traits('SubjectTag')->new({
48             %args,
49             subject_tag => 'foo',
50             });
51              
52             =head1 DESCRIPTION
53              
54             A L<< C<Sietima> >> list with this role applied will prepend the given
55             tag to every outgoing message's C<Subject:> header.
56              
57             =head1 ATTRIBUTES
58              
59             =head2 C<subject_tag>
60              
61             Required string. This string, enclosed by square brackets, will be
62             prepended to the C<Subject:> header of outgoing messages. For example,
63             the code in the L</synopsis> would cause an incoming message with
64             subject "new stuff" to be sent out with subject "[foo] new stuff".
65              
66             If the incoming message's C<Subject:> header already contains the tag,
67             the header will not be modified. This prevents getting subjects like
68             "[foo] Re: [foo] Re: [foo] new stuff".
69              
70             =head1 MODIFIED METHODS
71              
72             =head2 C<munge_mail>
73              
74             The subject of the incoming email is modified to add the tag (unless
75             it's already there). The email is then processed normally.
76              
77             =head1 AUTHOR
78              
79             Gianni Ceccarelli <dakkar@thenautilus.net>
80              
81             =head1 COPYRIGHT AND LICENSE
82              
83             This software is copyright (c) 2017 by Gianni Ceccarelli <dakkar@thenautilus.net>.
84              
85             This is free software; you can redistribute it and/or modify it under
86             the same terms as the Perl 5 programming language system itself.
87              
88             =cut