aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authordakkar <dakkar@thenautilus.net>2016-12-27 15:27:23 +0000
committerdakkar <dakkar@thenautilus.net>2016-12-27 15:30:09 +0000
commit2362fc13b8e79618e285d9cd1817819381d7d0a4 (patch)
tree9b70332a18ecb111905529d9e07f397c2256d0f2 /lib
parentupdate dependencies (diff)
downloadSietima-2362fc13b8e79618e285d9cd1817819381d7d0a4.tar.gz
Sietima-2362fc13b8e79618e285d9cd1817819381d7d0a4.tar.bz2
Sietima-2362fc13b8e79618e285d9cd1817819381d7d0a4.zip
command line handling
Diffstat (limited to 'lib')
-rw-r--r--lib/Sietima.pm28
-rw-r--r--lib/Sietima/CmdLine.pm25
-rw-r--r--lib/Sietima/Role/SubscriberOnly/Moderate.pm36
-rw-r--r--lib/Sietima/Runner.pm15
4 files changed, 104 insertions, 0 deletions
diff --git a/lib/Sietima.pm b/lib/Sietima.pm
index df5de4e..81821e4 100644
--- a/lib/Sietima.pm
+++ b/lib/Sietima.pm
@@ -49,6 +49,12 @@ has transport => (
);
sub _build_transport { Email::Sender::Simple->default_transport }
+sub handle_mail_from_stdin($self) {
+ my $mail_text = do { local $/; <> };
+ my $incoming_mail = Email::MIME->new(\$mail_text);
+ return $self->handle_mail($incoming_mail);
+}
+
sub handle_mail($self,$incoming_mail) {
state $check = compile(Object,EmailMIME); $check->(@_);
@@ -91,4 +97,26 @@ sub send_message($self,$outgoing_message) {
sub _trait_namespace { 'Sietima::Role' }
+sub command_line_spec($self) {
+ return {
+ name => 'sietima',
+ title => 'a simple mailing list manager',
+ options => [
+ {
+ name => 'verbose',
+ summary => 'more chatty',
+ type => 'flag',
+ multiple => 1,
+ aliases => ['v'],
+ },
+ ],
+ subcommands => {
+ send => {
+ op => 'handle_mail_from_stdin',
+ summary => 'send email from STDIN',
+ },
+ },
+ };
+}
+
1;
diff --git a/lib/Sietima/CmdLine.pm b/lib/Sietima/CmdLine.pm
new file mode 100644
index 0000000..57d796f
--- /dev/null
+++ b/lib/Sietima/CmdLine.pm
@@ -0,0 +1,25 @@
+package Sietima::CmdLine;
+use Moo;
+use Sietima::Policy;
+use App::Spec;
+use Sietima::Runner;
+
+has sietima => (
+ is => 'ro',
+ required => 1,
+);
+
+sub run($self) {
+ my $spec_data = $self->sietima->command_line_spec();
+
+ my $app_spec = App::Spec->read($spec_data);
+
+ my $runner = Sietima::Runner->new({
+ spec => $app_spec,
+ cmd => $self->sietima,
+ });
+
+ $runner->run;
+}
+
+1;
diff --git a/lib/Sietima/Role/SubscriberOnly/Moderate.pm b/lib/Sietima/Role/SubscriberOnly/Moderate.pm
index 0d9fd58..8f49bed 100644
--- a/lib/Sietima/Role/SubscriberOnly/Moderate.pm
+++ b/lib/Sietima/Role/SubscriberOnly/Moderate.pm
@@ -31,4 +31,40 @@ sub resume ($self,$mail_id) {
$self->mail_store->remove($mail_id);
}
+sub drop ($self,$mail_id) {
+ $self->mail_store->remove($mail_id);
+}
+
+around command_line_spec => sub ($orig,$self) {
+ my $spec = $self->$orig();
+ $spec->{subcommands}{'resume-held'} = {
+ op => sub ($self,$runner,$args) {
+ $self->resume($runner->parameters->{'mail-id'});
+ },
+ summary => 'resume the given mail, currently held for moderation',
+ parameters => [
+ {
+ name => 'mail-id',
+ required => 1,
+ summary => 'id of the mail to resume',
+ },
+ ],
+ };
+ $spec->{subcommands}{'drop-held'} = {
+ op => sub ($self,$runner,$args) {
+ $self->drop($runner->parameters->{'mail-id'});
+ },
+ summary => 'drop the given mail, currently held for moderation',
+ parameters => [
+ {
+ name => 'mail-id',
+ required => 1,
+ summary => 'id of the mail to drop',
+ },
+ ],
+ };
+
+ return $spec;
+};
+
1;
diff --git a/lib/Sietima/Runner.pm b/lib/Sietima/Runner.pm
new file mode 100644
index 0000000..7d0ad7d
--- /dev/null
+++ b/lib/Sietima/Runner.pm
@@ -0,0 +1,15 @@
+package Sietima::Runner;
+use Moo;
+use Sietima::Policy;
+extends 'App::Spec::Run';
+
+sub run_op($self,$op,$args=[]) {
+ if ($op =~ /^cmd_/) {
+ $self->$op($args);
+ }
+ else {
+ $self->cmd->$op($self,$args);
+ }
+}
+
+1;