| 1 | package Sietima::Role::SubscriberOnly::Moderate; | ||||||||||||||||||||||||||||||||
| 2 | 2 | ▶ | use Moo::Role; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use Sietima::Policy; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use Email::Stuffer; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use namespace::clean; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||
| 7 | 2 | our $VERSION = '1.1.5'; # VERSION | |||||||||||||||||||||||||||||||
| 8 | # ABSTRACT: moderate messages from non-subscribers | ||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||
| 11 | 2 | with 'Sietima::Role::SubscriberOnly', | |||||||||||||||||||||||||||||||
| 12 | 'Sietima::Role::WithMailStore', | ||||||||||||||||||||||||||||||||
| 13 | 'Sietima::Role::WithOwner'; | ||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||
| 16 | 4 | ▶ | sub munge_mail_from_non_subscriber ($self,$mail) { | ||||||||||||||||||||||||||||||
|
Subroutine
munge_mail_from_non_subscriber: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 17 | 4 | my $id = $self->mail_store->store($mail,'moderation'); | |||||||||||||||||||||||||||||||
| 18 | 4 | my $notice = Email::Stuffer | |||||||||||||||||||||||||||||||
| 19 | ->from($self->return_path->address) | ||||||||||||||||||||||||||||||||
| 20 | ->to($self->owner->address) | ||||||||||||||||||||||||||||||||
| 21 | ->subject("Message held for moderation - ".$mail->header_str('subject')) | ||||||||||||||||||||||||||||||||
| 22 | ->text_body("Use id $id to refer to it") | ||||||||||||||||||||||||||||||||
| 23 | ->attach( | ||||||||||||||||||||||||||||||||
| 24 | $mail->as_string, | ||||||||||||||||||||||||||||||||
| 25 | content_type => 'message/rfc822', | ||||||||||||||||||||||||||||||||
| 26 | # some clients, most notably Claws-Mail, seem to have | ||||||||||||||||||||||||||||||||
| 27 | # problems with encodings other than this | ||||||||||||||||||||||||||||||||
| 28 | encoding => '7bit', | ||||||||||||||||||||||||||||||||
| 29 | ); | ||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||
| 31 | 4 | return Sietima::Message->new({ | |||||||||||||||||||||||||||||||
| 32 | mail => $notice->email, | ||||||||||||||||||||||||||||||||
| 33 | from => $self->return_path, | ||||||||||||||||||||||||||||||||
| 34 | to => [ $self->owner ], | ||||||||||||||||||||||||||||||||
| 35 | }); | ||||||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||
| 39 | 3 | ▶ | sub resume ($self,$mail_id) { | ||||||||||||||||||||||||||||||
|
Subroutine
resume: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 40 | 3 | my $mail = $self->mail_store->retrieve_by_id($mail_id); | |||||||||||||||||||||||||||||||
| 41 | $self->ignoring_subscriberonly( | ||||||||||||||||||||||||||||||||
| 42 | 3 | ▶ | sub($s) { $s->handle_mail($mail) }, | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 43 | 3 | ); | |||||||||||||||||||||||||||||||
| 44 | 3 | $self->mail_store->remove($mail_id); | |||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||
| 48 | 1 | ▶ | sub drop ($self,$mail_id) { | ||||||||||||||||||||||||||||||
|
Subroutine
drop: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 49 | 1 | $self->mail_store->remove($mail_id); | |||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||
| 53 | 1 | ▶ | sub list_mails_in_moderation_queue ($self,$runner,@) { | ||||||||||||||||||||||||||||||
|
Subroutine
list_mails_in_moderation_queue: called CC=5 SCAR=17.4
Pod
documented
| |||||||||||||||||||||||||||||||||
| 54 | 1 | my $mails = $self->mail_store->retrieve_by_tags('moderation'); | |||||||||||||||||||||||||||||||
| 55 | 1 | $runner->out(sprintf 'There are %d messages held for moderation:',scalar($mails->@*)); | |||||||||||||||||||||||||||||||
| 56 | 1 | for my $mail ($mails->@*) { | |||||||||||||||||||||||||||||||
| 57 | $runner->out(sprintf '* %s %s "%s" (%s)', | ||||||||||||||||||||||||||||||||
| 58 | $mail->{id}, | ||||||||||||||||||||||||||||||||
| 59 | $mail->{mail}->header_str('From')//'<no from>', | ||||||||||||||||||||||||||||||||
| 60 | $mail->{mail}->header_str('Subject')//'<no subject>', | ||||||||||||||||||||||||||||||||
| 61 | 1 | ▶ | $mail->{mail}->header_str('Date')//'<no date>', | ||||||||||||||||||||||||||||||
|
Condition50%3/6
$mail->{"mail"}->header_str("From") // "<no from>"
$mail->{"mail"}->header_str("Subject") // "<no subject>"
$mail->{"mail"}->header_str("Date") // "<no date>"
MC/DC0%0/1
$mail->{"mail"}->header_str("From") // "<no from>"
$mail->{"mail"}->header_str("From")
MC/DC0%0/1
$mail->{"mail"}->header_str("Subject") // "<no subject>"
$mail->{"mail"}->header_str("Subject")
MC/DC0%0/1
$mail->{"mail"}->header_str("Date") // "<no date>"
$mail->{"mail"}->header_str("Date")
Truth table50%1/2
A
A= $mail->{"mail"}->header_str("From")
Truth table50%1/2
A
A= $mail->{"mail"}->header_str("Subject")
Truth table50%1/2
A
A= $mail->{"mail"}->header_str("Date")
| |||||||||||||||||||||||||||||||||
| 62 | ); | ||||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||
| 67 | 1 | ▶ | sub show_mail_from_moderation_queue ($self,$runner,@) { | ||||||||||||||||||||||||||||||
|
Subroutine
show_mail_from_moderation_queue: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 68 | 1 | my $id = $runner->parameters->{'mail-id'}; | |||||||||||||||||||||||||||||||
| 69 | 1 | my $mail = $self->mail_store->retrieve_by_id($id); | |||||||||||||||||||||||||||||||
| 70 | 1 | $runner->out("Message $id:"); | |||||||||||||||||||||||||||||||
| 71 | 1 | $runner->out($mail->as_string =~ s{\r\n}{\n}gr); | |||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||
| 75 | 0 | ▶ | sub resume_mail_from_moderation_queue ($self,$runner,@) { | ||||||||||||||||||||||||||||||
|
Subroutine
resume_mail_from_moderation_queue: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 76 | 0 | $self->resume($runner->parameters->{'mail-id'}); | |||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||
| 80 | 0 | ▶ | sub drop_mail_from_moderation_queue ($self,$runner,@) { | ||||||||||||||||||||||||||||||
|
Subroutine
drop_mail_from_moderation_queue: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 81 | 0 | $self->drop($runner->parameters->{'mail-id'}); | |||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||
| 85 | 0 | ▶ | around command_line_spec => sub ($orig,$self) { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 86 | 0 | my $spec = $self->$orig(); | |||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||
| 88 | # this allows us to tab-complete identifiers from the shell! | ||||||||||||||||||||||||||||||||
| 89 | 0 | ▶ | my $list_mail_ids = sub ($self,$runner,$args) { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 90 | 0 | $self->mail_store->retrieve_ids_by_tags('moderation'); | |||||||||||||||||||||||||||||||
| 91 | 0 | }; | |||||||||||||||||||||||||||||||
| 92 | # a little factoring: $etc->($command_name) generates the spec for | ||||||||||||||||||||||||||||||||
| 93 | # sub-commands that require a mail id | ||||||||||||||||||||||||||||||||
| 94 | 0 | ▶ | my $etc = sub($cmd) { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 95 | return ( | ||||||||||||||||||||||||||||||||
| 96 | 0 | summary => "$cmd the given mail, currently held for moderation", | |||||||||||||||||||||||||||||||
| 97 | parameters => [ | ||||||||||||||||||||||||||||||||
| 98 | { | ||||||||||||||||||||||||||||||||
| 99 | name => 'mail-id', | ||||||||||||||||||||||||||||||||
| 100 | required => 1, | ||||||||||||||||||||||||||||||||
| 101 | summary => "id of the mail to $cmd", | ||||||||||||||||||||||||||||||||
| 102 | completion => { op => $list_mail_ids }, | ||||||||||||||||||||||||||||||||
| 103 | }, | ||||||||||||||||||||||||||||||||
| 104 | ], | ||||||||||||||||||||||||||||||||
| 105 | ); | ||||||||||||||||||||||||||||||||
| 106 | 0 | }; | |||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||
| 108 | 0 | $spec->{subcommands}{'list-held'} = { | |||||||||||||||||||||||||||||||
| 109 | op => 'list_mails_in_moderation_queue', | ||||||||||||||||||||||||||||||||
| 110 | summary => 'list all mails currently held for moderation', | ||||||||||||||||||||||||||||||||
| 111 | }; | ||||||||||||||||||||||||||||||||
| 112 | 0 | $spec->{subcommands}{'show-held'} = { | |||||||||||||||||||||||||||||||
| 113 | op => 'show_mail_from_moderation_queue', | ||||||||||||||||||||||||||||||||
| 114 | $etc->('show'), | ||||||||||||||||||||||||||||||||
| 115 | }; | ||||||||||||||||||||||||||||||||
| 116 | 0 | $spec->{subcommands}{'resume-held'} = { | |||||||||||||||||||||||||||||||
| 117 | op => 'resume_mail_from_moderation_queue', | ||||||||||||||||||||||||||||||||
| 118 | $etc->('resume'), | ||||||||||||||||||||||||||||||||
| 119 | }; | ||||||||||||||||||||||||||||||||
| 120 | 0 | $spec->{subcommands}{'drop-held'} = { | |||||||||||||||||||||||||||||||
| 121 | op => 'drop_mail_from_moderation_queue', | ||||||||||||||||||||||||||||||||
| 122 | $etc->('drop'), | ||||||||||||||||||||||||||||||||
| 123 | }; | ||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||
| 125 | 0 | return $spec; | |||||||||||||||||||||||||||||||
| 126 | 2 | }; | |||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||
| 128 | 2 | 1; | |||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||
| 130 | __END__ | ||||||||||||||||||||||||||||||||