summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorian Pritz <bluewind@xinu.at>2018-07-17 18:10:14 +0200
committerFlorian Pritz <bluewind@xinu.at>2018-07-17 18:10:14 +0200
commitf05b01c2cd283e7d24fe8fe51977355839617e4f (patch)
treed914dd32c69d2749bf6a8bd0f3074ae2b37bb3da
parentae2545a2e081dbc4daaa615f948a942b93df4368 (diff)
downloadApp-ImapNotify-f05b01c2cd283e7d24fe8fe51977355839617e4f.tar.gz
App-ImapNotify-f05b01c2cd283e7d24fe8fe51977355839617e4f.tar.xz
Use TOML for configuration
Signed-off-by: Florian Pritz <bluewind@xinu.at>
-rwxr-xr-xscript/imap-notify.pl107
1 files changed, 80 insertions, 27 deletions
diff --git a/script/imap-notify.pl b/script/imap-notify.pl
index cea3af1..d540e76 100755
--- a/script/imap-notify.pl
+++ b/script/imap-notify.pl
@@ -1,41 +1,93 @@
#!/usr/bin/env perl
+use v5.24;
+
+use warnings;
+use strict;
+
+use App::ImapNotify;
+use Function::Parameters;
+use Log::Any::Adapter ('Stderr', log_level => "info");
+use MCE::Hobo;
+use Path::Tiny;
+use TOML qw(from_toml);
+
+=head1 NAME
+
+imap-notify.pl - Simple notification script using IMAP NOTIFY
+
+=head1 SYNOPSIS
+
+ imap-notify.pl [options]
+
+ Options:
+ --debug
+
=head1 DESCRIPTION
Simple notification script using IMAP NOTIFY. Note that it is very simple and
implements a custom IMAP client with very limited features. Mostly a proof of
concept and personal script.
-=cut
+=head1 CONFIGURATION
-use v5.24;
+To configure the script create a file called $XDG_CONFIG_HOME/imap-notify/config.toml.
-use warnings;
-use strict;
+You should create an array called "watches" with the following settings:
-use App::ImapNotify;
-use Function::Parameters;
-use MCE::Hobo;
-use Log::Any::Adapter ('Stderr', log_level => "info");
+=over
+
+=item log_id
+
+String to identify a particular connection in the debug log.
+
+=item host
+
+Hostname or IP of the server to connect to.
+
+=item port
+
+Port to connect to.
+
+=item username
+
+Username to use to authenticate.
+
+=item passwordeval
+
+Command that is run by the script and that outputs the password that will be used to authenticate on stdout.
+
+=item mailboxes
+
+Array of mailbox names to watch.
+
+=back
+
+=head2 Example Configuration
+
+ [[watches]]
+ log_id = "first-server"
+ host = "mail.first-server.localdomain"
+ port = 993
+ username = "my-username"
+ passwordeval = "getpw-single my-username-password"
+ mailboxes = ["INBOX", "INBOX.Postmaster", "Other.Mailbox"]
+
+ [[watches]]
+ log_id = "second-server"
+ host = "imap.second.localdomain"
+ port = 993
+ username = "user@second.localdomain"
+ passwordeval = "getpw-single user@second.localdomain"
+ mailboxes = ["INBOX"]
+
+=head1 SEE ALSO
+
+L<App::ImapNotify>
+
+=cut
-my $config = [
- {
- log_id => "server-speed",
- host => 'mail.server-speed.net',
- port => 993,
- username => 'mail-flo',
- password => trim(`getpw-single msmtp3`),
- mailboxes => [qw(INBOX INBOX.Postmaster INBOX.TISS INBOX.tuwel)],
- },
- #{
- #log_id => "luxx",
- #host => 'mail.nano-srv.net',
- #port => 993,
- #username => 'bluewind@luxx-area.de',
- #password => trim(`getpw-single bluewind\@luxx-area.de`),
- #mailboxes => [qw(INBOX)],
- #},
-];
+my $config = from_toml(path(($ENV{XDG_CONFIG_HOME} // $ENV{HOME}."/.config")."/imap-notify/config.toml")->slurp);
if ($ARGV[0] // "" eq "--debug") {
Log::Any::Adapter->set("Stderr", log_level => "trace");
@@ -45,7 +97,8 @@ if ($ARGV[0] // "" eq "--debug") {
my @workers;
-for my $single_conf ($config->@*) {
+for my $single_conf ($config->{watches}->@*) {
+ $single_conf->{password} = `$single_conf->{passwordeval}`;
push @workers, mce_async {
my $app = App::ImapNotify->new($single_conf);
$app->loop();