user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
* [PATCH] inbox: ->mailboxid accessor
@ 2021-03-02  9:13 Eric Wong
  0 siblings, 0 replies; only message in thread
From: Eric Wong @ 2021-03-02  9:13 UTC (permalink / raw)
  To: meta

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.
---
 lib/PublicInbox/Inbox.pm | 12 ++++++++++++
 t/inbox.t                |  7 +++++++
 2 files changed, 19 insertions(+)

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;
diff --git a/t/inbox.t b/t/inbox.t
index bc8fae9a..b7239e6d 100644
--- a/t/inbox.t
+++ b/t/inbox.t
@@ -32,4 +32,11 @@ is(unlink(glob("$x->{inboxdir}/*")), 2, 'unlinked cloneurl & description');
 is_deeply($x->cloneurl, ['https://example.com/inbox'], 'cloneurls memoized');
 is($x->description, "\x{100}blah", 'description memoized');
 
+$x->{name} = "2\x{100}wide";
+$x->{newsgroup} = '2.wide';
+like($x->mailboxid, qr/\AM32c48077696465-[0-9a-f]+\z/,
+	'->mailboxid w/o slice (JMAP)');
+like($x->mailboxid(78), qr/\AM322e77696465-4e-[0-9a-f]+\z/,
+	'->mailboxid w/ slice (IMAP)');
+
 done_testing();

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-03-02  9:13 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-02  9:13 [PATCH] inbox: ->mailboxid accessor Eric Wong

user/dev discussion of public-inbox itself

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://public-inbox.org/meta
	git clone --mirror http://czquwvybam4bgbro.onion/meta
	git clone --mirror http://hjrcffqmbrq6wope.onion/meta
	git clone --mirror http://ou63pmih66umazou.onion/meta

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V1 meta meta/ https://public-inbox.org/meta \
		meta@public-inbox.org
	public-inbox-index meta

Example config snippet for mirrors.
Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.mail.public-inbox.meta
	nntp://7fh6tueqddpjyxjmgtdiueylzoqt6pt7hec3pukyptlmohoowvhde4yd.onion/inbox.comp.mail.public-inbox.meta
	nntp://ie5yzdi7fg72h7s4sdcztq5evakq23rdt33mfyfcddc5u3ndnw24ogqd.onion/inbox.comp.mail.public-inbox.meta
	nntp://4uok3hntl7oi7b4uf4rtfwefqeexfzil2w6kgk2jn5z2f764irre7byd.onion/inbox.comp.mail.public-inbox.meta
	nntp://news.gmane.io/gmane.mail.public-inbox.general
 note: .onion URLs require Tor: https://www.torproject.org/

code repositories for project(s) associated with this inbox:

	https://80x24.org/public-inbox.git

AGPL code for this site: git clone https://public-inbox.org/public-inbox.git