diff options
author | dakkar <dakkar@thenautilus.net> | 2017-01-02 17:35:52 +0000 |
---|---|---|
committer | dakkar <dakkar@thenautilus.net> | 2017-01-02 17:35:52 +0000 |
commit | 66061a7ca7849ae147b12bf0aca72bbc70821099 (patch) | |
tree | 0eebf9fb02899fa1f8a96e770e507420c8a29afc | |
parent | clean all the namespaces (diff) | |
download | Sietima-66061a7ca7849ae147b12bf0aca72bbc70821099.tar.gz Sietima-66061a7ca7849ae147b12bf0aca72bbc70821099.tar.bz2 Sietima-66061a7ca7849ae147b12bf0aca72bbc70821099.zip |
ReplyTo can set a post address != return path
-rw-r--r-- | lib/Sietima/Role/ReplyTo.pm | 19 | ||||
-rw-r--r-- | t/tests/sietima/role/replyto.t | 33 |
2 files changed, 50 insertions, 2 deletions
diff --git a/lib/Sietima/Role/ReplyTo.pm b/lib/Sietima/Role/ReplyTo.pm index 56a8ed9..583b1de 100644 --- a/lib/Sietima/Role/ReplyTo.pm +++ b/lib/Sietima/Role/ReplyTo.pm @@ -2,6 +2,7 @@ package Sietima::Role::ReplyTo; use Moo::Role; use Sietima::Policy; use Types::Standard qw(Bool); +use Sietima::Types qw(Address AddressFromStr); use List::AllUtils qw(part); use namespace::clean; @@ -11,6 +12,13 @@ has munge_reply_to => ( default => 0, ); +has post_address => ( + is => 'lazy', + isa => Address, + coerce => AddressFromStr, +); +sub _build_post_address($self) { $self->return_path } + around munge_mail => sub ($orig,$self,$mail) { my @messages = $self->$orig($mail); my @ret; @@ -28,7 +36,7 @@ around munge_mail => sub ($orig,$self,$mail) { } elsif (not ($leave and $leave->@*)) { # all these recipients want munging - $m->mail->header_str_set('Reply-To',$self->return_path->address); + $m->mail->header_str_set('Reply-To',$self->post_address->address); push @ret,$m; } else { @@ -40,7 +48,7 @@ around munge_mail => sub ($orig,$self,$mail) { }); my $munged_mail = Email::MIME->new($m->mail->as_string); - $munged_mail->header_str_set('Reply-To',$self->return_path->address); + $munged_mail->header_str_set('Reply-To',$self->post_address->address); my $munged_message = Sietima::Message->new({ mail => $munged_mail, @@ -54,4 +62,11 @@ around munge_mail => sub ($orig,$self,$mail) { return @ret; }; +around list_addresses => sub ($orig,$self) { + return +{ + $self->$orig->%*, + post => $self->post_address, + }; +}; + 1; diff --git a/t/tests/sietima/role/replyto.t b/t/tests/sietima/role/replyto.t index c502391..bae1bdf 100644 --- a/t/tests/sietima/role/replyto.t +++ b/t/tests/sietima/role/replyto.t @@ -42,6 +42,39 @@ subtest 'enabled' => sub { ); }; +subtest 'enabled, custom post address' => sub { + my $post_address = 'the-list@example.com'; + my $s = make_sietima( + with_traits => ['ReplyTo'], + munge_reply_to => 1, + subscribers => [ + 'one@users.example.com', + 'two@users.example.com', + ], + post_address => $post_address, + ); + + is( + $s->list_addresses, + hash { + field return_path => $s->return_path; + field post => object { + call address => $post_address; + }; + }, + 'the custom post address should be set for the headers', + ); + + test_sending( + sietima => $s, + mails => [ + object { + call [ header_str => 'reply-to' ] => $post_address; + }, + ], + ); +}; + subtest 'enabled for some' => sub { my $s = make_sietima( with_traits => ['ReplyTo'], |