package Sietima::Role::ReplyTo;
use Moo::Role;
use Sietima::Policy;
use Types::Standard qw(Bool);
use List::AllUtils qw(part);
use namespace::clean;
our $VERSION = '1.1.1';
with 'Sietima::Role::WithPostAddress';
has munge_reply_to => (
is => 'ro',
isa => Bool,
default => 0,
);
around munge_mail => sub ($orig,$self,$mail) {
my @messages = $self->$orig($mail);
my @ret;
for my $m (@messages) {
my ($leave,$munge) = part {
my $m = $_->prefs->{munge_reply_to};
defined $m ? (
$m ? 1 : 0
) : ( $self->munge_reply_to ? 1 : 0 )
} $m->to->@*;
if (not ($munge and $munge->@*)) {
push @ret,$m;
}
elsif (not ($leave and $leave->@*)) {
$m->mail->header_str_set('Reply-To',$self->post_address->address);
push @ret,$m;
}
else {
my $leave_message = Sietima::Message->new({
mail => $m->mail,
from => $m->from,
to => $leave,
});
my $munged_mail = Email::MIME->new($m->mail->as_string);
$munged_mail->header_str_set('Reply-To',$self->post_address->address);
my $munged_message = Sietima::Message->new({
mail => $munged_mail,
from => $m->from,
to => $munge,
});
push @ret,$leave_message,$munged_message;
}
}
return @ret;
};
1;
__END__