]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/Inbox.pm
config: lazy-load coderepos, support extindex
[public-inbox.git] / lib / PublicInbox / Inbox.pm
index 1b9b56ff1a7220e12350b726520bfcf91efa59e2..da7ea75f1a5741c7702aa0a85466ee908b9f019b 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (C) 2016-2020 all contributors <meta@public-inbox.org>
+# Copyright (C) 2016-2021 all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 #
 # Represents a public-inbox (which may have multiple mailing addresses)
@@ -196,7 +196,7 @@ sub isrch { $_[0]->{isrch} // search($_[0]) }
 
 sub over {
        $_[0]->{over} //= eval {
-               my $srch = $_[0]->{search} //= eval {
+               my $srch = $_[0]->{search} //= do {
                        _cleanup_later($_[0]);
                        require PublicInbox::Search;
                        PublicInbox::Search->new($_[0]);
@@ -210,12 +210,9 @@ sub over {
 
 sub try_cat {
        my ($path) = @_;
-       my $rv = '';
-       if (open(my $fh, '<', $path)) {
-               local $/;
-               $rv = <$fh>;
-       }
-       $rv;
+       open(my $fh, '<', $path) or return '';
+       local $/;
+       <$fh> // '';
 }
 
 sub cat_desc ($) {
@@ -424,4 +421,16 @@ sub uidvalidity { $_[0]->{uidvalidity} //= eval { $_[0]->mm->created_at } }
 
 sub eidx_key { $_[0]->{newsgroup} // $_[0]->{inboxdir} }
 
+sub mailboxid { # rfc 8474, 8620, 8621
+       my ($self, $imap_slice) = @_;
+       my $pfx = defined($imap_slice) ? $self->{newsgroup} : $self->{name};
+       utf8::encode($pfx); # to octets
+       # RFC 8620, 1.2 recommends not starting with dash or digits
+       # "A good solution to these issues is to prefix every id with a single
+       #  alphabetical character."
+       'M'.join('', map { sprintf('%02x', ord) } split(//, $pfx)) .
+               (defined($imap_slice) ? sprintf('-%x', $imap_slice) : '') .
+               sprintf('-%x', uidvalidity($self) // 0)
+}
+
 1;