1 # Copyright (C) 2016-2019 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);
17 # spec: TYPE:PREFIX:param1=value1¶m2=value2&...
18 # The PREFIX will be a searchable boolean prefix in Xapian
19 # Example: serial:gmane:file=/path/to/altmsgmap.sqlite3
21 my ($class, $ibx, $spec, $writable) = @_;
22 my ($type, $prefix, $query) = split(/:/, $spec, 3);
23 $type eq 'serial' or die "non-serial not supported, yet\n";
25 require PublicInbox::Msgmap;
28 my ($k, $v) = split(/=/, uri_unescape($_), 2);
29 $v = '' unless defined $v;
31 } split(/[&;]/, $query);
32 my $f = $params{file} or die "file: required for $type spec $spec\n";
33 unless (index($f, '/') == 0) {
34 if (($ibx->{version} || 1) == 1) {
35 $f = "$ibx->{mainrepo}/public-inbox/$f";
37 $f = "$ibx->{mainrepo}/$f";
42 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);