1 # Copyright (C) 2016-2020 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
4 # Used for giving serial numbers to messages. This can be tied to
5 # the msgmap for live updates to living lists (see
6 # PublicInbox::Filters::RubyLang), or kept separate for imports
7 # of defunct NNTP groups (e.g. scripts/xhdr-num2mid)
9 # Introducing NEW uses of serial numbers is discouraged because of
10 # it leads to reliance on centralization. However, being able
11 # to use existing serial numbers is beneficial.
12 package PublicInbox::AltId;
15 use URI::Escape qw(uri_unescape);
16 use PublicInbox::Msgmap;
18 # spec: TYPE:PREFIX:param1=value1¶m2=value2&...
19 # The PREFIX will be a searchable boolean prefix in Xapian
20 # Example: serial:gmane:file=/path/to/altmsgmap.sqlite3
22 my ($class, $ibx, $spec, $writable) = @_;
23 my ($type, $prefix, $query) = split(/:/, $spec, 3);
24 $type eq 'serial' or die "non-serial not supported, yet\n";
25 $prefix =~ /\A\w+\z/ or warn "non-word prefix not searchable\n";
27 my ($k, $v) = split(/=/, uri_unescape($_), 2);
28 $v = '' unless defined $v;
30 } split(/[&;]/, $query);
31 my $f = $params{file} or die "file: required for $type spec $spec\n";
32 unless (index($f, '/') == 0) {
33 if ($ibx->version == 1) {
34 $f = "$ibx->{inboxdir}/public-inbox/$f";
36 $f = "$ibx->{inboxdir}/$f";
41 writable => $writable,
43 xprefix => 'X'.uc($prefix),
49 $self->{mm_alt} ||= eval {
50 my $f = $self->{filename};
51 my $writable = $self->{writable};
52 PublicInbox::Msgmap->new_file($f, $writable);
57 my ($self, $mid) = @_;
58 $self->mm_alt->num_for($mid);