Sietima

 view release on metacpan or  search on metacpan

example/sietima  view on Meta::CPAN

        owner => 'dakkar@thenautilus.net',
        mail_store => {
            class => 'Sietima::MailStore::FS',
            root => '/tmp/sietima-store',
        },
        return_path => 'dakkar-sietima@thenautilus.net',
        subject_tag => 'Test',
        subscribers => [
            'dakkar-a@thenautilus.net',
            { primary => 'dakkar-b@thenautilus.net', aliases => [ 'dakkar-bis@thenautilus.net' ] },
            { primary => 'dakkar-c@thenautilus.net', prefs => { wants_mail => 0 } },
        ],
    },
})->run;

lib/Sietima.pm  view on Meta::CPAN

An array-ref of L<< C<Sietima::Subscriber> >> objects, defaults to the
empty array.

Each item can be coerced from a string or a L<< C<Email::Address> >>
instance, or a hashref of the form

  { primary => $string, %other_attributes }

The base Sietima class only uses the address of subscribers, but some
roles use the other attributes (L<< C<NoMail>|Sietima::Role::NoMail
>>, for example, uses the C<prefs> attribute, and L<<
C<SubscriberOnly> >> uses C<aliases> via L<<
C<match>|Sietima::Subscriber/match >>)

=head2 C<transport>

A L<< C<Email::Sender::Transport> >> instance, which will be used to
send messages. If not passed in, Sietima uses L<<
C<Email::Sender::Simple> >>'s L<<
C<default_transport>|Email::Sender::Simple/default_transport >>.

lib/Sietima/Role/NoMail.pm  view on Meta::CPAN

use Moo::Role;
use Sietima::Policy;
use namespace::clean;

our $VERSION = '1.1.5'; # VERSION
# ABSTRACT: don't send mail to those who don't want it


around subscribers_to_send_to => sub ($orig,$self,$mail) {
    return [
        grep { $_->prefs->{wants_mail} // 1 }
            $self->$orig($mail)->@*,
    ];
};

1;

__END__

=pod

lib/Sietima/Role/NoMail.pm  view on Meta::CPAN


=head1 VERSION

version 1.1.5

=head1 SYNOPSIS

  my $sietima = Sietima->with_traits('NoMail')->new({
   %args,
   subscribers => [
    { primary => 'write-only@example.com', prefs => { wants_mail => 0 } },
    @other_subscribers,
   ],
  });

=head1 DESCRIPTION

A L<< C<Sietima> >> list with this role applied will not send messages
to subscribers that have the C<wants_mail> preference set to a false
value.

lib/Sietima/Role/ReplyTo.pm  view on Meta::CPAN

    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->@*)) {
            # nothing to do
            push @ret,$m;
        }
        elsif (not ($leave and $leave->@*)) {

lib/Sietima/Role/ReplyTo.pm  view on Meta::CPAN

version 1.1.5

=head1 SYNOPSIS

  my $sietima = Sietima->with_traits('ReplyTo')->new({
    %args,
    return_path => 'list-bounce@example.com',
    munge_reply_to => 1,
    post_address => 'list@example.com',
    subscribers => [
      { primary => 'special@example.com', prefs => { munge_reply_to => 0 } },
      @other_subscribers,
    ],
  });

=head1 DESCRIPTION

A L<< C<Sietima> >> list with this role applied will, on request, set
the C<Reply-To:> header to the value of the L<<
C<post_address>|Sietima::Role::WithPostAddress >> attribute.

lib/Sietima/Subscriber.pm  view on Meta::CPAN

    )
];
has aliases => (
    isa => $address_array,
    is => 'lazy',
    coerce => $address_array->coercion,
);
sub _build_aliases { +[] }


has prefs => (
    isa => HashRef,
    is => 'ro',
    default => sub { +{} },
);


signature_for match => (
    method => Object,
    positional => [ Address->plus_coercions(AddressFromStr) ],
);

lib/Sietima/Subscriber.pm  view on Meta::CPAN

=head2 C<aliases>

Arrayref of L<< C<Email::Address> >> objects, each coercible from a
string. Defaults to an empty arrayref.

These are secondary addresses that the subscriber may write
from. Subscriber-only mailing lists should accept messages from any of
these addresses as if they were from the primary. The L<< /C<match> >>
simplifies that task.

=head2 C<prefs>

A hashref. Various preferences that may be interpreted by Sietima
roles. Defaults to an empty hashref.

=head1 METHODS

=head2 C<match>

  if ($subscriber->match($address)) { ... }

t/tests/sietima/role/nomail.t  view on Meta::CPAN

#!perl
use lib 't/lib';
use Test::Sietima;

subtest 'disabled' => sub {
    my $s = make_sietima(
        with_traits => ['NoMail'],
        subscribers => [
            {
                primary => 'one@users.example.com',
                prefs => { wants_mail => 0 },
            },
            'two@users.example.com',
        ],
    );

    test_sending(
        sietima => $s,
        to => ['two@users.example.com'],
    );
};

subtest 'enabled' => sub {
    my $s = make_sietima(
        with_traits => ['NoMail'],
        subscribers => [
            {
                primary => 'one@users.example.com',
                prefs => { wants_mail => 1 },
            },
            'two@users.example.com',
        ],
    );

    test_sending(
        sietima => $s,
        to => ['one@users.example.com','two@users.example.com'],
    );
};

t/tests/sietima/role/replyto.t  view on Meta::CPAN

    );
};

subtest 'enabled for some' => sub {
    my $s = make_sietima(
        with_traits => ['ReplyTo'],
        munge_reply_to => 0,
        subscribers => [
            {
                primary => 'one@users.example.com',
                prefs => { munge_reply_to => 1 },
            },
            'two@users.example.com',
        ],
    );

    test_sending(
        sietima => $s,
        mails => [
            {
                o => object {

t/tests/sietima/role/replyto.t  view on Meta::CPAN

};


subtest 'disabled for some' => sub {
    my $s = make_sietima(
        with_traits => ['ReplyTo'],
        munge_reply_to => 1,
        subscribers => [
            {
                primary => 'one@users.example.com',
                prefs => { munge_reply_to => 0 },
            },
            'two@users.example.com',
        ],
    );

    test_sending(
        sietima => $s,
        mails => [
            {
                o => object {

t/tests/sietima/subscriber.t  view on Meta::CPAN

    my $s = Sietima::Subscriber->new(
        primary => 'Gino (pino) <gino@pino.example.com>',
    );

    is(
        $s,
        object {
            call address => 'gino@pino.example.com';
            call name => 'Gino';
            call original => 'Gino (pino) <gino@pino.example.com>';
            call prefs => {};
        },
        'construction and delegation should work',
    );
};

subtest 'aliases' => sub {
    my $s = Sietima::Subscriber->new(
        primary => 'Gino (pino) <gino@pino.example.com>',
        aliases => [qw(also-gino@pino.example.com maybe-gino@rino.example.com)],
    );



( run in 0.980 second using v1.01-cache-2.11-cpan-8f98c5d2c55 )