From bd274a20b46202f3a7d53a51a117cfd4110c3a67 Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Sat, 23 Jan 2021 17:18:10 -0700 Subject: new script: gmi2email Signed-off-by: Sean Whitton --- gmi2email.1.pod | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 gmi2email.1.pod (limited to 'gmi2email.1.pod') diff --git a/gmi2email.1.pod b/gmi2email.1.pod new file mode 100644 index 0000000..5fa6d20 --- /dev/null +++ b/gmi2email.1.pod @@ -0,0 +1,81 @@ +=head1 NAME + +gmi2email - subscribe to gemlogs and read individual Gemini pages by e-mail + +=head1 SYNOPSIS + +B [I] [I] ... + +=head1 DESCRIPTION + +B fetches pages served using the Gemini protocol, converts them to +e-mail messages, and then sends those messages. It is mainly useful for +subscribing to Gemini logs ("gemlogs") by e-mail, like rss2email(1). +B fetches, converts and sends all URIs and files containing +text/gemini content specified on the command line. + +=head1 OPTIONS + +=over 4 + +=item B<--subscriptions> + +In addition to mailing any URIs/files specified on the command line, check +subscribed gemlogs for new posts and send those too. Useful in a crontab. + +Currently we only support the subscription mechanism described at +. + +B looks for a file with a list of gemini:// URIs to check for new +posts, one per line, in +B<$XDG_CONFIG_HOME/mailscripts/gmi2email.subscriptions>, or if XDG_CONFIG_HOME +is not set, it falls back to trying to read +B<~/.config/mailscripts/gmi2email.subscriptions>. + +=item B<--inline-images> + +Download and inline any images included in the post. + +=item B<--from=>I
+ +Set the From: address, overriding the configuration file. + +=item B<--to=>I
+ +Set the To: address, overriding the configuration file. + +=back + +=head1 CONFIGURATION + +B tries to read configuration from the file +B<$XDG_CONFIG_HOME/mailscripts/gmi2email.config>, or if XDG_CONFIG_HOME is not +set, it falls back to trying to read +B<~/.config/mailscripts/gmi2email.config>. + +The format is I, one per line. The following +configuration keys are supported: + +=over 4 + +=item B + +Set the From: address. + +=item B + +Set the To: address. + +=item inline_images + +Set to 1 to implicitly pass B<--inline-images>. + +=back + +=head1 SEE ALSO + + + +=head1 AUTHOR + +B was written by Sean Whitton . -- cgit v1.2.3 From b8694107731a779b2e2ebd307577c8f1f6dc7c91 Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Sat, 23 Jan 2021 18:29:14 -0700 Subject: gmi2email: add --no-send Signed-off-by: Sean Whitton --- gmi2email | 9 +++++---- gmi2email.1.pod | 6 ++++++ 2 files changed, 11 insertions(+), 4 deletions(-) (limited to 'gmi2email.1.pod') diff --git a/gmi2email b/gmi2email index 75816e6..67f9562 100755 --- a/gmi2email +++ b/gmi2email @@ -33,12 +33,13 @@ use Email::Date::Format "email_date"; use Time::Local; use Mail::Field::AddrList; -my ($from, $to, $do_subs, $inline_images); +my ($from, $to, $do_subs, $inline_images, $no_mail); GetOptions "from=s" => \$from, "to=s" => \$to, "subscriptions!" => \$do_subs, - "inline-images!" => \$inline_images; + "inline-images!" => \$inline_images, + "no-send!" => \$no_mail; my $conf_r = $ENV{XDG_CONFIG_HOME} || catfile $ENV{HOME}, ".config"; my $conf_f = catfile $conf_r, "mailscripts", "gmi2email.config"; @@ -74,7 +75,7 @@ for (@ARGV) { ($type, $data) = gemini_fetch($_, abs_links => 1); $type =~ m{^text/gemini} or die "$_ is not gemtext"; } - gemtext_to_mail($data, %to_mail_opts)->send; + $no_mail or gemtext_to_mail($data, %to_mail_opts)->send; } exit unless $do_subs; @@ -133,7 +134,7 @@ foreach my $sub (<$subs_fh>) { }; #>>> $dbh->do("INSERT INTO seen VALUES (\"$uri\")"); - $mail or next; + $mail and !$no_mail or next; if ($type =~ m{^text/gemini}) { gemtext_to_mail( $data, %to_mail_opts, diff --git a/gmi2email.1.pod b/gmi2email.1.pod index 5fa6d20..d4e656c 100644 --- a/gmi2email.1.pod +++ b/gmi2email.1.pod @@ -36,6 +36,12 @@ B<~/.config/mailscripts/gmi2email.subscriptions>. Download and inline any images included in the post. +=item B<--no-send> + +Don't actually send any mail. Intended when you just added some new +subscriptions and want to avoid receiving all the old posts you've already +read. + =item B<--from=>I
Set the From: address, overriding the configuration file. -- cgit v1.2.3 From d41a20368ed7c7458495cfbe2a13eab50f9c5c28 Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Sun, 24 Jan 2021 11:36:27 -0700 Subject: gmi2email: support for Atom feeds Signed-off-by: Sean Whitton --- debian/changelog | 4 ++-- debian/control | 1 + gmi2email | 25 +++++++++++++++++-------- gmi2email.1.pod | 5 +++-- 4 files changed, 23 insertions(+), 12 deletions(-) (limited to 'gmi2email.1.pod') diff --git a/debian/changelog b/debian/changelog index bbb3bf5..5373cf1 100644 --- a/debian/changelog +++ b/debian/changelog @@ -2,8 +2,8 @@ mailscripts (0.23-1) UNRELEASED; urgency=medium * New script: gmi2email - add libdbd-sqlite3-perl, libio-socket-ssl-perl, libmime-lite-perl, - libemail-date-format-perl, libtry-tiny-perl and libmailtools-perl to - Recommends. + libemail-date-format-perl, libtry-tiny-perl, libmailtools-perl and + libxml-feed-perl to Recommends. -- Sean Whitton Sat, 23 Jan 2021 16:36:25 -0700 diff --git a/debian/control b/debian/control index a47be4c..552da66 100644 --- a/debian/control +++ b/debian/control @@ -57,6 +57,7 @@ Recommends: libemail-date-format-perl, libtry-tiny-perl, libmailtools-perl, + libxml-feed-perl, notmuch, python3-argcomplete, python3-gssapi, diff --git a/gmi2email b/gmi2email index 714e58a..dd9edba 100755 --- a/gmi2email +++ b/gmi2email @@ -32,6 +32,7 @@ use Getopt::Long; use Email::Date::Format "email_date"; use Time::Local; use Mail::Field::AddrList; +use XML::Feed; my ($from, $to, $do_subs, $inline_images, $no_mail); GetOptions @@ -108,15 +109,23 @@ foreach my $sub (<$subs_fh>) { } }; #>>> - $type =~ m{^text/gemini} or die "$sub is not gemtext"; - for (@$data) { - if (/^#\s*/ and not $gemlog) { - chomp($gemlog = $'); - } elsif (my ($uri, $y, $m, $d, $title) - = /^=>\s*(\S+)\s+([0-9]{4})-([0-9]{2})-([0-9]{2})[\s-]*(.*)/) { - send_subscribed_gemtext($uri, $gemlog // "unknown gemlog", - $title, timelocal 0, 0, 12, $d, $m - 1, $y); + if ($type =~ m{^text/gemini}) { + for (@$data) { + if (/^#\s*/ and not $gemlog) { + chomp($gemlog = $'); + } elsif (my ($uri, $y, $m, $d, $title) + = /^=>\s*(\S+)\s+([0-9]{4})-([0-9]{2})-([0-9]{2})[\s-]*(.*)/) { + send_subscribed_gemtext($uri, $gemlog // "unknown gemlog", + $title, timelocal 0, 0, 12, $d, $m - 1, $y); + } } + } elsif ($type =~ m{^text/xml}) { + my $feed = XML::Feed->parse(\$data); + send_subscribed_gemtext($_->link, $feed->title, $_->title, + ($_->issued // $_->modified)->epoch) + for $feed->entries; + } else { + die "$sub is not gemtext"; } } diff --git a/gmi2email.1.pod b/gmi2email.1.pod index d4e656c..d5004d5 100644 --- a/gmi2email.1.pod +++ b/gmi2email.1.pod @@ -23,8 +23,9 @@ text/gemini content specified on the command line. In addition to mailing any URIs/files specified on the command line, check subscribed gemlogs for new posts and send those too. Useful in a crontab. -Currently we only support the subscription mechanism described at -. +We support the subscription mechanism described at + as well as +Atom feeds. B looks for a file with a list of gemini:// URIs to check for new posts, one per line, in -- cgit v1.2.3 From e29e329b58b8e4a92c0d535a5e67f147e8a3d026 Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Sun, 24 Jan 2021 11:51:43 -0700 Subject: gmi2email(1): add "TYPICAL USAGE" Signed-off-by: Sean Whitton --- gmi2email.1.pod | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'gmi2email.1.pod') diff --git a/gmi2email.1.pod b/gmi2email.1.pod index d5004d5..6f12b84 100644 --- a/gmi2email.1.pod +++ b/gmi2email.1.pod @@ -14,6 +14,47 @@ subscribing to Gemini logs ("gemlogs") by e-mail, like rss2email(1). B fetches, converts and sends all URIs and files containing text/gemini content specified on the command line. +=head2 TYPICAL USAGE + +1. Ensure you have a working MTA: B will use the sendmail(1) +command to send mail. + +2. Create B<~/.config/mailscripts/gmi2email.config> with content like this: + +=over 4 + + from = rss@example.com + to = your_email@example.com + inline_images = 1 + +=back + +3. Create B<~/.config/mailscripts/gmi2email.subscriptions> with some feed +URIs, e.g. + +=over 4 + + gemini://example.com/my_cool_gemlog/ + gemini://example.com/other_cool_gemlog/feed.xml + +=back + +4. Just once, execute + +=over 4 + + % gmi2email --subscriptions --no-send + +=back + +5. Periodically, execute + +=over 4 + + % gmi2email --subscriptions + +=back + =head1 OPTIONS =over 4 -- cgit v1.2.3 From 1f07bf968d154664cfec5d2414b8a960f82e38ec Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Wed, 27 Jan 2021 16:27:14 -0700 Subject: gmi2email: enable specifying a list of subscriptions Signed-off-by: Sean Whitton --- gmi2email | 24 ++++++++++++------------ gmi2email.1.pod | 4 ++-- 2 files changed, 14 insertions(+), 14 deletions(-) (limited to 'gmi2email.1.pod') diff --git a/gmi2email b/gmi2email index 4c567e9..54a3459 100755 --- a/gmi2email +++ b/gmi2email @@ -42,13 +42,13 @@ use Time::Local; use Mail::Field::AddrList; use XML::Feed; -my ($from, $to, $do_subs, $inline_images, $no_mail); +my ($from, $to, $subs, $inline_images, $no_mail); GetOptions - "from=s" => \$from, - "to=s" => \$to, - "subscriptions!" => \$do_subs, - "inline-images!" => \$inline_images, - "no-send!" => \$no_mail; + "from=s" => \$from, + "to=s" => \$to, + "subscriptions:s" => \$subs, + "inline-images!" => \$inline_images, + "no-send!" => \$no_mail; my $conf_r = $ENV{XDG_CONFIG_HOME} || catfile $ENV{HOME}, ".config"; my $conf_f = catfile $conf_r, "mailscripts", "gmi2email.config"; @@ -57,6 +57,8 @@ my $conf_f = catfile $conf_r, "mailscripts", "gmi2email.config"; or die "no config file nor sufficient command line options: don't know who to mail"; my $conf = Config::Tiny->new->read($conf_f); +$subs ||= catfile $conf_r, "mailscripts", "gmi2email.subscriptions" + if defined $subs; my %to_mail_opts = ( from => ( @@ -72,7 +74,7 @@ my %to_mail_opts = ( inline_images => $inline_images // $conf->{_}->{inline_images} // 0 ); -@ARGV or $do_subs or die "nothing to do\n"; +@ARGV or $subs or die "nothing to do\n"; for (@ARGV) { my $data; @@ -87,11 +89,9 @@ for (@ARGV) { $no_mail or gemtext_to_mail($data, %to_mail_opts)->send; } -exit unless $do_subs; - -my $subs_f = catfile $conf_r, "mailscripts", "gmi2email.subscriptions"; --e $subs_f or die "no list of subscriptions"; -open my $subs_fh, "<", $subs_f; +exit unless $subs; +-r $subs or die "file $subs not readable"; +open my $subs_fh, "<", $subs; my $db_r = $ENV{XDG_CACHE_HOME} || catfile $ENV{HOME}, ".cache"; my $db_d = catfile $db_r, "mailscripts"; diff --git a/gmi2email.1.pod b/gmi2email.1.pod index 6f12b84..b7e9108 100644 --- a/gmi2email.1.pod +++ b/gmi2email.1.pod @@ -59,7 +59,7 @@ URIs, e.g. =over 4 -=item B<--subscriptions> +=item B<--subscriptions>[=I] In addition to mailing any URIs/files specified on the command line, check subscribed gemlogs for new posts and send those too. Useful in a crontab. @@ -69,7 +69,7 @@ We support the subscription mechanism described at Atom feeds. B looks for a file with a list of gemini:// URIs to check for new -posts, one per line, in +posts, one per line, in I, or if that is not set, in B<$XDG_CONFIG_HOME/mailscripts/gmi2email.subscriptions>, or if XDG_CONFIG_HOME is not set, it falls back to trying to read B<~/.config/mailscripts/gmi2email.subscriptions>. -- cgit v1.2.3