From 714da2b50f0b027abe4b5b759c5fa3bbd3815089 Mon Sep 17 00:00:00 2001 From: dakkar Date: Tue, 14 Feb 2017 22:22:56 +0000 Subject: new role: ManualSubscription --- lib/Sietima.pm | 2 ++ lib/Sietima/Role/ManualSubscription.pm | 53 +++++++++++++++++++++++++++++++ t/tests/sietima/role/manualsubscription.t | 31 ++++++++++++++++++ 3 files changed, 86 insertions(+) create mode 100644 lib/Sietima/Role/ManualSubscription.pm create mode 100644 t/tests/sietima/role/manualsubscription.t diff --git a/lib/Sietima.pm b/lib/Sietima.pm index e317147..98859ab 100644 --- a/lib/Sietima.pm +++ b/lib/Sietima.pm @@ -51,6 +51,8 @@ prevents the sender from receiving copies of their own messages avoids mail-loops using a C header = L<< C|Sietima::Role::Headers >> adds C headers to all outgoing messages += L<< C|Sietima::Role::ManualSubscription >> +specifies that to (un)subscribe, people should write to the list owner = L<< C|Sietima::Role::NoMail >> avoids sending messages to subscribers who don't want them = L<< C|Sietima::Role::ReplyTo >> diff --git a/lib/Sietima/Role/ManualSubscription.pm b/lib/Sietima/Role/ManualSubscription.pm new file mode 100644 index 0000000..fd75f80 --- /dev/null +++ b/lib/Sietima/Role/ManualSubscription.pm @@ -0,0 +1,53 @@ +package Sietima::Role::ManualSubscription; +use Moo::Role; +use Sietima::Policy; +use URI; +use namespace::clean; + +# VERSION +# ABSTRACT: adds standard list-related headers to messages + +with 'Sietima::Role::WithOwner'; + +=head1 SYNOPSIS + + my $sietima = Sietima->with_traits( + 'Headers', + 'ManualSubscription', + )->new({ + %args, + owner => 'listmaster@example.com', + }); + +=head1 DESCRIPTION + +A L<< C >> list with this role (and L<< +C|Sietima::Role::Headers >>) applied will add, to each +outgoing message, headers specifying that to subscribe and +unsubscribe, people sould email the list owner. + +=modif C + +This method declares two "addresses", C and +C. Both are C URLs for the list +L, with different subjects. + +=cut + +around list_addresses => sub($orig,$self) { + my $list_name = $self->name // 'the list'; + my $mail_owner_uri = URI->new($self->owner,'mailto'); + my $sub_uri = $mail_owner_uri->clone; + $sub_uri->query_form(subject => "Please add me to $list_name"); + my $unsub_uri = $mail_owner_uri->clone; + $unsub_uri->query_form(subject => "Please remove me from $list_name"); + + return +{ + $self->$orig->%*, + subscribe => $sub_uri, + unsubscribe => $unsub_uri, + }; +}; + + +1; diff --git a/t/tests/sietima/role/manualsubscription.t b/t/tests/sietima/role/manualsubscription.t new file mode 100644 index 0000000..f99805d --- /dev/null +++ b/t/tests/sietima/role/manualsubscription.t @@ -0,0 +1,31 @@ +#!perl +use lib 't/lib'; +use Test::Sietima; + +my $s = make_sietima( + with_traits => ['Headers','ManualSubscription'], + name => 'test-list', + owner => 'owner@example.com', + subscribers => [ + 'one@users.example.com', + 'two@users.example.com', + ], +); + +subtest '(un)sub headers should be added' => sub { + test_sending( + sietima => $s, + mails => [ + object { + call sub { +{ shift->header_str_pairs } } => hash { + field 'List-Subscribe' => ''; + field 'List-Unsubscribe' => ''; + + etc; + }; + }, + ], + ); +}; + +done_testing; -- cgit v1.2.3