diff options
-rwxr-xr-x | script/imap-notify.pl | 107 |
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(); |