File Coverage

blib/lib/Sietima/Role/Debounce.pm
Criterion Covered Total %
statement 9 9 100.0
branch n/a
condition n/a
subroutine 3 3 100.0
pod n/a
total 12 12 100.0


line stmt bran cond sub pod time code
1             package Sietima::Role::Debounce;
2 2     2   1172 use Moo::Role;
  2         6  
  2         15  
3 2     2   789 use Sietima::Policy;
  2         7  
  2         22  
4 2     2   15 use namespace::clean;
  2         10  
  2         19  
5              
6             our $VERSION = '1.0.3'; # VERSION
7             # ABSTRACT: avoid mail loops
8              
9              
10             my $been_there = 'X-Been-There';
11              
12             around munge_mail => sub ($orig,$self,$incoming_mail) {
13             my $return_path = $self->return_path->address;
14             if (my $there = $incoming_mail->header_str($been_there)) {
15             return if $there =~ m{\b\Q$return_path\E\b};
16             }
17              
18             $incoming_mail->header_str_set(
19             $been_there => $return_path,
20             );
21              
22             return $self->$orig($incoming_mail);
23             };
24              
25             1;
26              
27             __END__
28              
29             =pod
30              
31             =encoding UTF-8
32              
33             =head1 NAME
34              
35             Sietima::Role::Debounce - avoid mail loops
36              
37             =head1 VERSION
38              
39             version 1.0.3
40              
41             =head1 SYNOPSIS
42              
43             my $sietima = Sietima->with_traits('Debounce')->new(\%args);
44              
45             =head1 DESCRIPTION
46              
47             A L<< C<Sietima> >> list with this role applied will mark each message
48             with a C<X-Been-There:> header, and will not handle any messages that
49             have that same header. This prevents messages bounced by other
50             services from being looped between the mailing list and those other
51             services.
52              
53             =head1 MODIFIED METHODS
54              
55             =head2 C<munge_mail>
56              
57             If the incoming email contains our C<X-Been-There:> header, this
58             method will return an empty list (essentially dropping the message).
59              
60             Otherwise, the header is added, and the email is processed normally.
61              
62             =head1 AUTHOR
63              
64             Gianni Ceccarelli <dakkar@thenautilus.net>
65              
66             =head1 COPYRIGHT AND LICENSE
67              
68             This software is copyright (c) 2017 by Gianni Ceccarelli <dakkar@thenautilus.net>.
69              
70             This is free software; you can redistribute it and/or modify it under
71             the same terms as the Perl 5 programming language system itself.
72              
73             =cut