about summary refs log tree commit homepage
path: root/lib/PublicInbox/LeiConvert.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2021-02-24 17:31:52 +0600
committerEric Wong <e@80x24.org>2021-02-24 23:26:14 +0000
commit2f9f6c9eca667dfde9e267e946498eaad0b0c8da (patch)
tree86c6807030725d685e6ab5d7b110e602630bf7ab /lib/PublicInbox/LeiConvert.pm
parentc1a92bf7adccea821a905b221972c06fc5579718 (diff)
downloadpublic-inbox-2f9f6c9eca667dfde9e267e946498eaad0b0c8da.tar.gz
lei <import|convert>: support NNTP sources
We can read NNTP in -watch and Net::NNTP is shipped with Perl5,
so lei import and convert have no excuse not to support NNTP
as a client.

Authentication is not tested, yet; but should be close to what
IMAP is like...
Diffstat (limited to 'lib/PublicInbox/LeiConvert.pm')
-rw-r--r--lib/PublicInbox/LeiConvert.pm14
1 files changed, 9 insertions, 5 deletions
diff --git a/lib/PublicInbox/LeiConvert.pm b/lib/PublicInbox/LeiConvert.pm
index 4839dea4..a7e47871 100644
--- a/lib/PublicInbox/LeiConvert.pm
+++ b/lib/PublicInbox/LeiConvert.pm
@@ -18,8 +18,8 @@ sub mbox_cb {
         $self->{wcb}->(undef, { kw => \@kw }, $eml);
 }
 
-sub imap_cb { # ->imap_each
-        my ($url, $uid, $kw, $eml, $self) = @_;
+sub net_cb { # callback for ->imap_each, ->nntp_each
+        my (undef, undef, $kw, $eml, $self) = @_; # @_[0,1]: url + uid ignored
         $self->{wcb}->(undef, { kw => $kw }, $eml);
 }
 
@@ -35,14 +35,18 @@ sub do_convert { # via wq_do
         my $mics;
         if (my $nrd = $lei->{nrd}) { # may prompt user once
                 $nrd->{mics_cached} = $nrd->imap_common_init($lei);
+                $nrd->{nn_cached} = $nrd->nntp_common_init($lei);
         }
         if (my $stdin = delete $self->{0}) {
                 PublicInbox::MboxReader->$in_fmt($stdin, \&mbox_cb, $self);
         }
         for my $input (@{$self->{inputs}}) {
                 my $ifmt = lc($in_fmt // '');
-                if ($input =~ m!\A(?:imap|nntp)s?://!) { # TODO: nntp
-                        $lei->{nrd}->imap_each($input, \&imap_cb, $self);
+                if ($input =~ m!\Aimaps?://!) {
+                        $lei->{nrd}->imap_each($input, \&net_cb, $self);
+                        next;
+                } elsif ($input =~ m!\A(?:nntps?|s?news)://!) {
+                        $lei->{nrd}->nntp_each($input, \&net_cb, $self);
                         next;
                 } elsif ($input =~ s!\A([a-z0-9]+):!!i) {
                         $ifmt = lc $1;
@@ -82,7 +86,7 @@ sub call { # the main "lei convert" method
         # e.g. Maildir:/home/user/Mail/ or imaps://example.com/INBOX
         for my $input (@inputs) {
                 my $input_path = $input;
-                if ($input =~ m!\A(?:imap|nntp)s?://!i) {
+                if ($input =~ m!\A(?:imaps?|nntps?|s?news)://!i) {
                         require PublicInbox::NetReader;
                         $nrd //= PublicInbox::NetReader->new;
                         $nrd->add_url($input);