about summary refs log tree commit homepage
path: root/lib/PublicInbox/Inbox.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2021-03-02 09:13:07 +0000
committerEric Wong <e@80x24.org>2021-03-02 21:05:36 +0000
commite01956b6cef0db5e82e2637fe5e565f4560f9fd5 (patch)
tree707f33bbc5539173d2122558103f4e5f4301a374 /lib/PublicInbox/Inbox.pm
parent5b0ff78b53a796a54f8a8d7402bd04bcd2235b14 (diff)
downloadpublic-inbox-e01956b6cef0db5e82e2637fe5e565f4560f9fd5.tar.gz
inbox: ->mailboxid accessor
This will be necessary for "mailboxIds" as described in RFCs 8620 and
8621 (for JMAP).  We may implement "MAILBOXID" in RFC 8474 for IMAP,
as well.
Diffstat (limited to 'lib/PublicInbox/Inbox.pm')
-rw-r--r--lib/PublicInbox/Inbox.pm12
1 files changed, 12 insertions, 0 deletions
diff --git a/lib/PublicInbox/Inbox.pm b/lib/PublicInbox/Inbox.pm
index a1e34797..da7ea75f 100644
--- a/lib/PublicInbox/Inbox.pm
+++ b/lib/PublicInbox/Inbox.pm
@@ -421,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;