about summary refs log tree commit homepage
path: root/lib/PublicInbox/LeiLcat.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2021-05-28 00:07:56 +0000
committerEric Wong <e@80x24.org>2021-05-28 09:19:58 +0000
commit9b3cd5e254fafa08c774a24f85c2b2eac12a9de5 (patch)
treef7d9ba7947272754348b2d587075d43c59f06bea /lib/PublicInbox/LeiLcat.pm
parent578520277aaf723b174a2567aff90c10e29abbcb (diff)
downloadpublic-inbox-9b3cd5e254fafa08c774a24f85c2b2eac12a9de5.tar.gz
"lei import" can now import a single IMAP message via
<imaps://example.com/MAILBOX/;UID=$UID>

Likewise, "lei inspect" can show the blob information for UID
URLs and "lei lcat" can display the blob without network access
if imported.

"lei lcat" also gets rid of some unused code and supports
"blob:$OIDHEX" syntax as described in the comments (and used by
our "text" output format).

v2: enforce UID in URL, fail without
v3: fix error reporting (s/fail/child_error/)
Diffstat (limited to 'lib/PublicInbox/LeiLcat.pm')
-rw-r--r--lib/PublicInbox/LeiLcat.pm33
1 files changed, 20 insertions, 13 deletions
diff --git a/lib/PublicInbox/LeiLcat.pm b/lib/PublicInbox/LeiLcat.pm
index 87729acf..0f585ff5 100644
--- a/lib/PublicInbox/LeiLcat.pm
+++ b/lib/PublicInbox/LeiLcat.pm
@@ -9,27 +9,31 @@ use strict;
 use v5.10.1;
 use PublicInbox::LeiViewText;
 use URI::Escape qw(uri_unescape);
-use URI;
 use PublicInbox::MID qw($MID_EXTRACT);
 
-sub lcat_redispatch {
-        my ($lei, $out, $op_p) = @_;
-        my $l = bless { %$lei }, ref($lei);
-        delete $l->{sock};
-        $l->{''} = $op_p; # daemon only
-        eval {
-                $l->qerr("# updating $out");
-                up1($l, $out);
-                $l->qerr("# $out done");
-        };
-        $l->err($@) if $@;
+sub lcat_imap_uid_uri ($$) {
+        my ($lei, $uid_uri) = @_;
+        my $lms = $lei->{lse}->lms or return;
+        my $oidhex = $lms->imap_oid($lei, $uid_uri);
+        if (ref(my $err = $oidhex)) { # art2folder error
+                $lei->qerr(@{$err->{qerr}}) if $err->{qerr};
+        }
+        push @{$lei->{lcat_blob}}, $oidhex; # cf. LeiToMail->wq_atexit_child
 }
 
 sub extract_1 ($$) {
         my ($lei, $x) = @_;
-        if ($x =~ m!\b([a-z]+?://\S+)!i) {
+        if ($x =~ m!\b(imaps?://[^>]+)!i) {
+                my $u = $1;
+                require PublicInbox::URIimap;
+                $u = PublicInbox::URIimap->new($u);
+                defined($u->uid) ? lcat_imap_uid_uri($lei, $u) :
+                                $lei->child_error(1 << 8, "# no UID= in $u");
+                '""'; # blank query, using {lcat_blob}
+        } elsif ($x =~ m!\b([a-z]+?://\S+)!i) {
                 my $u = $1;
                 $u =~ s/[\>\]\)\,\.\;]+\z//;
+                require URI;
                 $u = URI->new($u);
                 my $p = $u->path;
                 my $term;
@@ -57,6 +61,9 @@ sub extract_1 ($$) {
                 $1;
         } elsif ($x =~ /\bid:(\S+)/) { # notmuch convention
                 "mid:$1";
+        } elsif ($x =~ /\bblob:([0-9a-f]{7,})\b/) {
+                push @{$lei->{lcat_blob}}, $1; # cf. LeiToMail->wq_atexit_child
+                '""'; # blank query
         } else {
                 undef;
         }