about summary refs log tree commit homepage
path: root/lib/PublicInbox/NetReader.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/NetReader.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/NetReader.pm')
-rw-r--r--lib/PublicInbox/NetReader.pm9
1 files changed, 7 insertions, 2 deletions
diff --git a/lib/PublicInbox/NetReader.pm b/lib/PublicInbox/NetReader.pm
index 73b8b1cd..76d2fe62 100644
--- a/lib/PublicInbox/NetReader.pm
+++ b/lib/PublicInbox/NetReader.pm
@@ -469,7 +469,10 @@ E: $orig_uri UIDVALIDITY mismatch (got $r_uidval)
 EOF
 
         my $uri = $orig_uri->clone;
+        my $single_uid = $uri->uid;
         my ($itrk, $l_uid, $l_uidval) = itrk_last($self, $uri, $r_uidval, $mic);
+        $itrk = $l_uid = undef if defined($single_uid);
+
         return <<EOF if $l_uidval != $r_uidval;
 E: $uri UIDVALIDITY mismatch
 E: local=$l_uidval != remote=$r_uidval
@@ -499,7 +502,9 @@ EOF
                 # I wish "UID FETCH $START:*" could work, but:
                 # 1) servers do not need to return results in any order
                 # 2) Mail::IMAPClient doesn't offer a streaming API
-                unless ($uids = $mic->search("UID $l_uid:*")) {
+                if (defined $single_uid) {
+                        $uids = [ $single_uid ];
+                } elsif (!($uids = $mic->search("UID $l_uid:*"))) {
                         return if $!{EINTR} && $self->{quit};
                         return "E: $uri UID SEARCH $l_uid:* error: $!";
                 }
@@ -541,7 +546,7 @@ EOF
                 }
                 run_commit_cb($self);
                 $itrk->update_last($r_uidval, $last_uid) if $itrk;
-        } until ($err || $self->{quit});
+        } until ($err || $self->{quit} || defined($single_uid));
         $err;
 }