]> Sergey Matveev's repositories - public-inbox.git/log
public-inbox.git
3 years agoMerge tag 'v1.6.1' into eidx
Eric Wong [Fri, 1 Jan 2021 04:51:46 +0000 (04:51 +0000)]
Merge tag 'v1.6.1' into eidx

public-inbox 1.6.1 - minor bugfix release

* tag 'v1.6.1': (31 commits)
  public-inbox 1.6.1 - minor bugfix release
  import: drop X-Status in addition to Status
  eml: fix undefined vars on <Perl 5.28
  t/config: test --get-urlmatch for git <2.26
  inboxidle: avoid needless syscalls on refresh
  inboxidle: clue users into resolving ENOSPC from inotify
  inbox: name variable for values loop iterator
  public-inbox-v[12]-format.pod: make lexgrog happy
  manifest.js.gz: fix per-inbox /$INBOX/manifest.js.gz
  Fix manpage section of perl module documentation
  t/psgi_v2: ignore warnings on missing P::M::ReverseProxy
  daemon: support --daemonize without Net::Server::Daemonize
  doc: v2-format: drop repeated word
  over: ensure old, merged {tid} is really gone
  wwwattach: prevent deep-linking via Referer match
  t/eml.t: workaround newer Email::MIME* behavior
  nntp: attempt RFC 5536 3.1.5-conformant Path: headers
  nntp: delimit Newsgroup: header with commas
  tls: epollbit: account for miscellaneous OpenSSL errors
  scripts/dupe-finder: restore $dbh variable
  ...

3 years agopublic-inbox 1.6.1 - minor bugfix release v1.6.1
Eric Wong [Thu, 31 Dec 2020 20:15:28 +0000 (20:15 +0000)]
public-inbox 1.6.1 - minor bugfix release

3 years agoimport: drop X-Status in addition to Status
Eric Wong [Thu, 17 Dec 2020 09:14:48 +0000 (09:14 +0000)]
import: drop X-Status in addition to Status

It's actually supported by mutt, dovecot[1], and likely some other
software to augment the Status: header.  While dovecot doesn't
expose X-Status to clients, mutt will write 'A' (answered) and
'F' to X-Status (but not T (draft)).

So we'll drop it like we do Status since it's not suitable for
public mail, but stick it in an @UNWANTED_HEADERS array will
allow us to configure an override if needed.

[1]  https://doc.dovecot.org/configuration_manual/mail_location/mbox/

3 years agods: flatten + reuse @events, epoll_wait style fixes
Eric Wong [Sun, 27 Dec 2020 02:53:07 +0000 (02:53 +0000)]
ds: flatten + reuse @events, epoll_wait style fixes

Consistently returning the equivalent of pollfd.revents in a
portable manner was never worth the effort for us, as we use the
same ->event_step callback regardless of POLLIN/POLLOUT/POLLHUP.

Being a Perl, @events knows it size and we don't have to return
a maximum index for the caller to iterate on.

We can also avoid redundant integer coercion ("+0") since we
ensure everything is an IV in other places.

Finally, vec() is preferable to ("\0" x $size) for resizing
buffers because it only needs to write the extended portion
and not overwrite the entire buffer.

3 years agods: simplify EventLoop implementation
Eric Wong [Sun, 27 Dec 2020 02:53:06 +0000 (02:53 +0000)]
ds: simplify EventLoop implementation

More importantly, make it easier-to-find the sub by avoiding
runtime manipulation of subroutine names.  There's no point in
avoiding a potential call to _InitPoller in EventLoop since
entering EventLoop is rare.

On the contrary, PublicInbox::DS->new is called often and this
change to avoid entering _InitPoller there may have more
benefits (which may still be unmeasurable).

3 years agocheck defined return value for localized slurp errors
Eric Wong [Sun, 27 Dec 2020 02:53:05 +0000 (02:53 +0000)]
check defined return value for localized slurp errors

Reading from regular files (even on STDIN) can fail
when dealing with flakey storage.

3 years agoimport: check for git->qx errors, clearer return values
Eric Wong [Sun, 27 Dec 2020 02:53:04 +0000 (02:53 +0000)]
import: check for git->qx errors, clearer return values

Those git commands can fail and git->qx will set $? when it
fails.  There's no need for the extra indirection of the @ret
array, either.

Improve git->qx coverage to check for $? while we're at it.

3 years agogit: qx: avoid extra "local" for scalar context case
Eric Wong [Sun, 27 Dec 2020 02:53:03 +0000 (02:53 +0000)]
git: qx: avoid extra "local" for scalar context case

We can use the ternary operator to avoid an early return, here

3 years agosearch: remove {mset} option for ->mset method
Eric Wong [Sun, 27 Dec 2020 19:38:29 +0000 (19:38 +0000)]
search: remove {mset} option for ->mset method

The ->mset method always returns a Xapian mset nowadays, so
naming a parameter {mset} is too confusing.  As it does with
MiscSearch, setting the {relevance} parameter to -1 now sorts by
ascending docid order.  -2 is now supported for descending
docid order, too, since it may be useful for lei users.

3 years agosearch: remove pointless {relevance} setting
Eric Wong [Sun, 27 Dec 2020 19:38:28 +0000 (19:38 +0000)]
search: remove pointless {relevance} setting

SearchView will set it to `undef', others will set the 'mset'
option (for the ->mset method :P) to 2 which causes {relevance}
to be ignored.

And the 'mset' option is poorly named now that the message
is named ->mset...

3 years agomiscsearch: take reopen from Search and use it
Eric Wong [Sun, 27 Dec 2020 11:01:42 +0000 (11:01 +0000)]
miscsearch: take reopen from Search and use it

As with ExtSearch, MiscSearch lacks a janky cleanup timer of
PublicInbox::Inbox objects, leading to info about
inboxes/newsgroups going stale.  Fortunately, we don't use
MiscSearch very heavily, yet.

In the future, we may be able to detect new inboxes without
having to SIGHUP or restart daemons using MiscSearch.

3 years agoextsearch: unconditionally reopen on access
Eric Wong [Sun, 27 Dec 2020 11:01:41 +0000 (11:01 +0000)]
extsearch: unconditionally reopen on access

Since ExtSearch lacks the janky cleanup timer of
PublicInbox::Inbox objects, its search results get stale.

Reopen the Xapian DB on every ->search call for now, as
reducing reopen calls doesn't seem worth the complexity.

The Xapian::Database::reopen operation itself takes only ~50us
on my old workstation with 3 shards totaling <200GB.  Other
parts of Xapian dominates the search time, so the reopen seems
inconsequential with single-digit shard counts.

3 years agoextindex: allow using --all without EXTINDEX_DIR
Eric Wong [Sat, 26 Dec 2020 10:16:24 +0000 (10:16 +0000)]
extindex: allow using --all without EXTINDEX_DIR

If "--all" is specified to index all inboxes, implicitly choose
the configured [extindex "all"] external index since "--all" is
incompatible with specifying inbox directories on the
command-line.

3 years agoextindex: add undocumented --no-scan switch
Eric Wong [Sat, 26 Dec 2020 10:16:23 +0000 (10:16 +0000)]
extindex: add undocumented --no-scan switch

This makes diagnosing --watch problems easier when there's
50K inboxes by avoiding the lengthy scan (which is the reason
--watch exists in the first place).

3 years agoextindex: enable autoflush on STDOUT/STDERR
Eric Wong [Sat, 26 Dec 2020 10:16:22 +0000 (10:16 +0000)]
extindex: enable autoflush on STDOUT/STDERR

With --watch, the output may be redirected to a pipe or socket
which Perl may decide to buffer.  Ensure Perl doesn't buffer
these outputs since they can provide real-time status updates
in response to signals or FS activity.

3 years agoextindex: various --watch signal handling fixes
Eric Wong [Sat, 26 Dec 2020 10:16:21 +0000 (10:16 +0000)]
extindex: various --watch signal handling fixes

We need to clobber the SIGUSR1 resync queue on SIGHUP to
invalidate old inbox objects.  Furthermore, the lengthy
initial scan needs to ignore signals intended for the
event loop to avoid unexpected behavior.  Finally, add
some progress output to inform users on the terminal
to inform users' of progress.

3 years agoextindex: --watch for inotify-based updates
Eric Wong [Sat, 26 Dec 2020 01:44:37 +0000 (01:44 +0000)]
extindex: --watch for inotify-based updates

This reuses existing InboxIdle infrastructure to update external
indices based on per-inbox updates.  This is an alternative to
auto-updating external indices via the -index command and also
works with existing uses of -mda and public-inbox-watch.

Using inotify (or EVFILT_VNODE) allows watching thousands of
inboxes without having to scan every single one at every
invocation.

This is especially beneficial in cases where an external index
is not writable to the users writing to per-inbox indices.

3 years agoeml: fix undefined vars on <Perl 5.28
Eric Wong [Sat, 26 Dec 2020 12:25:42 +0000 (12:25 +0000)]
eml: fix undefined vars on <Perl 5.28

Encode::MIME::Header::_decode_octets did not correctly default
to Encode::FB_DEFAULT until Encode 2.93 (perl5.git commit
0c541dc5633a341cf44b818014b58e7f8be532e9).  Provide the default
again to work with older Perls.

Reported-by: Ali Alnubani <alialnu@nvidia.com>
Link: https://public-inbox.org/meta/DM6PR12MB49106F8E3BD697B63B943A22DADB0@DM6PR12MB4910.namprd12.prod.outlook.com/
Tested-by: Ali Alnubani <alialnu@nvidia.com>
(cherry picked from commit 46bd595f57cc3d425754b0d0770c125616e74448)

3 years agot/config: test --get-urlmatch for git <2.26
Eric Wong [Sat, 26 Dec 2020 12:30:35 +0000 (12:30 +0000)]
t/config: test --get-urlmatch for git <2.26

While git 1.8.5 learned --get-urlmatch, git did not learn to
match URLs against wildcards until 2.26.  So only depend on
1.8.5 for this test since 2.26 is too new.

Reported-by: Ali Alnubani <alialnu@nvidia.com>
Link: https://public-inbox.org/meta/DM6PR12MB49106F8E3BD697B63B943A22DADB0@DM6PR12MB4910.namprd12.prod.outlook.com/
Tested-by: Ali Alnubani <alialnu@nvidia.com>
(cherry picked from commit 382a2bdd54cfb6c28a935c2b9fe4f1b1c2f469c4)

3 years agoinboxidle: avoid needless syscalls on refresh
Eric Wong [Sat, 26 Dec 2020 09:34:39 +0000 (09:34 +0000)]
inboxidle: avoid needless syscalls on refresh

We don't have to replace a bunch of existing watches
with identical new ones.  On Linux with Linux::Inotify2
installed, this avoids a storm of inotify_add_watch(2)
and inotify_rm_watch(2) syscalls on SIGHUP with -imapd
and "-extindex --watch"

(cherry picked from commit 10bf54305da8422d9ece6b809996092c1c4b1786)

Note: this seems to fix missed wakeups with many watches,
so it's in the stable branch.

Link: https://public-inbox.org/meta/20201226201115.GA30142@dcvr/
3 years agoinboxidle: clue users into resolving ENOSPC from inotify
Eric Wong [Sat, 26 Dec 2020 05:59:22 +0000 (05:59 +0000)]
inboxidle: clue users into resolving ENOSPC from inotify

It may not be obvious to users a ENOSPC error is from hitting
a (tunable) kernel-imposed limit on inotify watches, and not
some storage device running out of space.  Give them a hint
here to reduce our own support burden.

(cherry picked from commit 5e05c2eb58a450849f1826f3d02ed62b814b6617)

3 years agoinbox: name variable for values loop iterator
Eric Wong [Sat, 26 Dec 2020 08:12:52 +0000 (08:12 +0000)]
inbox: name variable for values loop iterator

->on_inbox_unlock callbacks could clobber $_, and this seems to
fix a problem with -extindex --watch failing to index some
inboxes after SIGHUP reload.

(cherry picked from commit b5e960f50289434025f5904c8c1311e4c8a02b82)

3 years agopublic-inbox-v[12]-format.pod: make lexgrog happy
Uwe Kleine-König [Tue, 22 Dec 2020 17:18:10 +0000 (18:18 +0100)]
public-inbox-v[12]-format.pod: make lexgrog happy

The Debian package linter (lintian) emits the following warning:

W: bad-whatis-entry
N:
N:   A manual page should start with a NAME section, which lists the
N:   program name and a brief description. The NAME section is used to
N:   generate a database that can be queried by commands like apropos and
N:   whatis. You are seeing this tag because lexgrog was unable to parse
N:   the NAME section.
N:
N:   Manual pages for multiple programs, functions, or files should list
N:   each separated by a comma and a space, followed by \- and a common
N:   description.
N:
N:   Listed items may not contain any spaces. A manual page for a two-level
N:   command such as fs listacl must look like fs_listacl so the list is
N:   read correctly.
N:
N:   Refer to the lexgrog(1) manual page, the groff_man(7) manual page, and
N:   the groff_mdoc(7) manual page for details.
N:
N:   Severity: warning
N:
N:   Check: documentation/manual
N:
N:   Renamed from: manpage-has-bad-whatis-entry
N:

for public-inbox-v1-format and public-inbox-v2-format.

Adapt the descriptions to make lexgrog and so lintian happy.

(cherry picked from commit 1350f5ab09f72c75ac2cd6c88f6a2b9e198fef55)

3 years agomanifest.js.gz: fix per-inbox /$INBOX/manifest.js.gz
Eric Wong [Mon, 21 Dec 2020 19:41:21 +0000 (19:41 +0000)]
manifest.js.gz: fix per-inbox /$INBOX/manifest.js.gz

/$INBOX/manifest.js.gz should not attempt to match every inbox
in the domain (or every inbox); that is for /manifest.js.gz
(without a /$INBOX prefix).

Fixes: f303b4add8ea1883 ("wwwlisting: avoid hogging event loop")
(cherry picked from commit 3ce4c38119f13d419bb865a0aa9b66feff339308)

3 years agoFix manpage section of perl module documentation
Uwe Kleine-König [Fri, 18 Dec 2020 11:56:14 +0000 (12:56 +0100)]
Fix manpage section of perl module documentation

On Debian (at least) perl documentation is supposed to be installed in
section 3pm. With the build system hardcoding this to 3 instead this
results in a warning by the Debian package linter:

W: public-inbox: wrong-manual-section usr/share/man/man3/PublicInbox::Git.3.gz:74 3 != 3pm
W: public-inbox: wrong-manual-section usr/share/man/man3/PublicInbox::Import.3.gz:74 3 != 3pm
W: public-inbox: wrong-manual-section usr/share/man/man3/PublicInbox::SaPlugin::ListMirror.3.gz:74 3 != 3pm
W: public-inbox: wrong-manual-section ... use --no-tag-display-limit to see all (or pipe to a file/program)

So use "$(MAN3EXT)" instead of "3".

(cherry picked from commit cd12cf22c4d161b7aec819f45628b983f0bd675d)

3 years agot/psgi_v2: ignore warnings on missing P::M::ReverseProxy
Eric Wong [Wed, 16 Dec 2020 04:39:37 +0000 (04:39 +0000)]
t/psgi_v2: ignore warnings on missing P::M::ReverseProxy

Plack::Test::ExternalServer doesn't depend on
Plack::Middleware::ReverseProxy, so we need to account for
some warnings in stderr if P::M::RP is missing.

(cherry picked from commit d26c2837f479b41182946a6540aad95d34b2b594)

3 years agodaemon: support --daemonize without Net::Server::Daemonize
Eric Wong [Tue, 15 Dec 2020 11:47:16 +0000 (11:47 +0000)]
daemon: support --daemonize without Net::Server::Daemonize

We don't actually need Net::Server::Daemonize to support
the --daemonize flag, since the daemonize() sub provided
by N::S::D doesn't exactly do the things we want.

(cherry picked from commit ab11caeb8ae114087636748df4c956d0e625b237)

3 years agodoc: v2-format: drop repeated word
Kyle Meyer [Sat, 12 Dec 2020 18:24:48 +0000 (18:24 +0000)]
doc: v2-format: drop repeated word

(cherry picked from commit 4df1904582c4d7bec64e05d1566cd48c8c2e888e)

3 years agoover: ensure old, merged {tid} is really gone
Eric Wong [Fri, 4 Dec 2020 12:09:29 +0000 (12:09 +0000)]
over: ensure old, merged {tid} is really gone

We must use the result of link_refs() since it can trigger
merge_threads() and invalidate $old_tid.  In case
merge_threads() isn't triggered, link_refs() will return
$old_tid anyways.

When rethreading and allocating new {tid}, we also must update
the row where the now-expired {tid} came from to ensure only the
new {tid} is seen when reindexing subsequent messages in
history.  Otherwise, every subsequently reindexed+rethreaded
message could end up getting a new {tid}.

Reported-by: Kyle Meyer <kyle@kyleam.com>
Link: https://public-inbox.org/meta/87360nlc44.fsf@kyleam.com/
(cherry picked from commit 9356ec0cc5afc95a8fd398ddf898942ef0acdb74)

3 years agowwwattach: prevent deep-linking via Referer match
Eric Wong [Mon, 23 Nov 2020 14:15:35 +0000 (14:15 +0000)]
wwwattach: prevent deep-linking via Referer match

This prevents `<img src=' tags from being used to deep-link
image attachments from HTML outside of the current host and
reduces potential for abuse.

Some browsers (e.g. Firefox) favor content detection and will
display images irrespective of the Content-Type header being
"application/octet-stream", and "Content-Disposition: attachment"
doesn't stop them, either.

Tested with dillo and Firefox.

Reported-by: Leah Neukirchen <leah@vuxu.org>
(cherry picked from commit 46cbc5a7a4ba917bd7154be3b6e6898420ff85d3)

3 years agot/eml.t: workaround newer Email::MIME* behavior
Eric Wong [Sun, 15 Nov 2020 08:56:09 +0000 (08:56 +0000)]
t/eml.t: workaround newer Email::MIME* behavior

Recent (2020) versions of Email::MIME (and/or dependencies)
have different behavior than historical versions which seem
to be less DWIM and perhaps technically more correct.  We'll
retain historical behavior for now, since it doesn't seem to
cause real problems and DWIM-ness is often required to make
sense of historical mail.

Tested on a FreeBSD 11.4 VM with the following packages:

p5-Email-MIME-1.949
p5-Email-MIME-ContentType-1.024_1
p5-Email-MIME-Encodings-1.315_2

(cherry picked from commit 5c4874309c4dd7aa8b9acd6bb97bd512360ab08a)

3 years agonntp: attempt RFC 5536 3.1.5-conformant Path: headers
Eric Wong [Wed, 4 Nov 2020 10:44:48 +0000 (10:44 +0000)]
nntp: attempt RFC 5536 3.1.5-conformant Path: headers

Perhaps some NNTP clients would be unhappy with the old value
"y".  So use a bit more bandwidth+space to use the server-name
and historical "!not-for-mail" tail-entry to better conform to
a published RFC.

Reported-by: Andrey Melnikov <temnota.am@gmail.com>
(cherry picked from commit 47559005ee678592808c351daa1c9f2682beb248)

3 years agonntp: delimit Newsgroup: header with commas
Eric Wong [Tue, 3 Nov 2020 22:55:59 +0000 (22:55 +0000)]
nntp: delimit Newsgroup: header with commas

...instead of spaces.  This is specified in RFC 5536 3.1.4.

Include references to RFC 1036, 5536 and 5537 in our docs while
we're at it.

Reported-by: Andrey Melnikov <temnota.am@gmail.com>
Link: https://public-inbox.org/meta/CA+PODjpUN5Q4gBFQhAzUNuMasVEdmp9f=8Uo0Ej0mFumdSwi4w@mail.gmail.com/
(cherry picked from commit 44227c2624e4f954943d632cd5335396351373be)

3 years agotls: epollbit: account for miscellaneous OpenSSL errors
Eric Wong [Fri, 30 Oct 2020 02:13:58 +0000 (02:13 +0000)]
tls: epollbit: account for miscellaneous OpenSSL errors

Apparently they happen (triggered by my -imapd instance), so
bail out by closing the underlying socket rather than stopping
the event loop and daemon process.

(cherry picked from commit c51c22c349529d9c377160abcc7961a6ca7b7d5c)

3 years agoscripts/dupe-finder: restore $dbh variable
Kyle Meyer [Fri, 16 Oct 2020 02:08:52 +0000 (22:08 -0400)]
scripts/dupe-finder: restore $dbh variable

When dupe-finder was switched from ->search->{over_ro} to ->over, the
database handle was dropped.  Restore it because a spot downstream
uses it.

Fixes: 73e3a6ed6e95adc6 (use more idiomatic internal API for ->over access)
(cherry picked from commit 0438ee2b1a5fbeb587ee62aa3e267ec09d281bd9)

3 years agosearchidx: index lower-case List-Id value
Eric Wong [Mon, 28 Sep 2020 05:15:19 +0000 (05:15 +0000)]
searchidx: index lower-case List-Id value

We don't want a List-Id value being confused with a Xapian
term prefix, here.

Followup-to: 8b06cda3a3af3f0e ("mda: match List-Id insensitively")
(cherry picked from commit 447d049b70c6723a0de8e28aa7db1a4130394c4b)

3 years agods: add missing label for systems w/o EPOLLEXCLUSIVE
Eric Wong [Sun, 27 Sep 2020 21:26:08 +0000 (21:26 +0000)]
ds: add missing label for systems w/o EPOLLEXCLUSIVE

Oops :x
(cherry picked from commit 28dec3a76687617a3a697058964dc0bd1351eb6b)

3 years agoimap: avoid raising exception if client disconnects
Eric Wong [Sat, 26 Sep 2020 08:08:37 +0000 (08:08 +0000)]
imap: avoid raising exception if client disconnects

This ought to save a few cycles if a client disconnects while
in the middle of a (UID) FETCH.  This avoids:

  Can't call method "git" on an undefined value at .../PublicInbox/IMAP.pm

errors in stderr.

(cherry picked from commit 34880bc83077eac5739deca69f66df7685965064)

3 years agoidxstack: fix comment about file_char
Eric Wong [Tue, 22 Sep 2020 18:49:49 +0000 (18:49 +0000)]
idxstack: fix comment about file_char

It's `d' for deletes, not `a'.

(cherry picked from commit 9dd93e4399c67abf74df6832181d442f81e0aa33)

3 years agomda: match List-Id insensitively
Eric Wong [Mon, 21 Sep 2020 20:58:09 +0000 (20:58 +0000)]
mda: match List-Id insensitively

This follows -watch commit b70473ab8296d31ebb600adb4fa8fe0ac5935ca8
to match List-Id headers case-insensitively.

Reported-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
Link: https://public-inbox.org/meta/20200921180152.uyqluod7qxbwqubo@chatter.i7.local/
(cherry picked from commit 8b06cda3a3af3f0e88b599a01f03edb7fec4f2c4)

3 years agomid: drop repeated ';' in mid_escape() regular expression
Kyle Meyer [Sun, 20 Sep 2020 18:13:58 +0000 (14:13 -0400)]
mid: drop repeated ';' in mid_escape() regular expression

(cherry picked from commit dc93c36eb62d36e649b9500b7f190687a3fbcffd)

3 years agodoc: post-1.6 updates, start 1.7
Eric Wong [Sat, 19 Sep 2020 21:42:01 +0000 (21:42 +0000)]
doc: post-1.6 updates, start 1.7

I should've dropped "PENDING" notes before the 1.6 release;
they're dropped now, and a note is added to remind my future
self to drop them before 1.7.

(cherry picked from commit 3b5d3d1910f1db526a488142c01f42db5255ac72)

3 years agoconfig: warn on multiple values for some fields
Eric Wong [Sun, 20 Sep 2020 01:43:15 +0000 (01:43 +0000)]
config: warn on multiple values for some fields

Our code doesn't support multi-values for these, and having
unexpected arrays leads to unexpected results (e.g. showing
stuff like "ARRAY(0xDEADBEEFADD12E55)" in user interfaces).  So
warn and only use the last value (matching git-config(1)
behavior without `--get-all').

(cherry picked from commit c8fe4673056571ed251c3a20cb0bbec586c60bd6)

3 years agodoc: txt2pre: more manpage URLs
Eric Wong [Thu, 17 Sep 2020 21:25:22 +0000 (21:25 +0000)]
doc: txt2pre: more manpage URLs

We host our own -imapd manpage, and we started using a few more
git commands (fast-import for ages).  We'll also need to link to
manpages.debian.org and live with long URLs for a few
non-standard manpages in software we reference.

(cherry picked from commit 31065006a3654968c0c4bbfe2d7399a3b326ce18)

3 years agodoc: flow: include -imapd
Eric Wong [Thu, 17 Sep 2020 21:25:21 +0000 (21:25 +0000)]
doc: flow: include -imapd

It's another read-only daemon, and it may see more usage than
-nntpd as more users have IMAP support than NNTP.

(cherry picked from commit 1fcb5694c2fdd4200820f777f27f9f55cd51b6ae)

3 years agot/indexlevels-mirror: fix improperly skipped test
Eric Wong [Wed, 16 Sep 2020 22:17:08 +0000 (22:17 +0000)]
t/indexlevels-mirror: fix improperly skipped test

Oops :x
(cherry picked from commit a7cd8c6a2bfa1ebfe2edeb0d7a93de17fd334683)

3 years agoeml: fix undefined vars on <Perl 5.28
Eric Wong [Sat, 26 Dec 2020 12:25:42 +0000 (12:25 +0000)]
eml: fix undefined vars on <Perl 5.28

Encode::MIME::Header::_decode_octets did not correctly default
to Encode::FB_DEFAULT until Encode 2.93 (perl5.git commit
0c541dc5633a341cf44b818014b58e7f8be532e9).  Provide the default
again to work with older Perls.

Reported-by: Ali Alnubani <alialnu@nvidia.com>
Link: https://public-inbox.org/meta/DM6PR12MB49106F8E3BD697B63B943A22DADB0@DM6PR12MB4910.namprd12.prod.outlook.com/
Tested-by: Ali Alnubani <alialnu@nvidia.com>
3 years agot/config: test --get-urlmatch for git <2.26
Eric Wong [Sat, 26 Dec 2020 12:30:35 +0000 (12:30 +0000)]
t/config: test --get-urlmatch for git <2.26

While git 1.8.5 learned --get-urlmatch, git did not learn to
match URLs against wildcards until 2.26.  So only depend on
1.8.5 for this test since 2.26 is too new.

Reported-by: Ali Alnubani <alialnu@nvidia.com>
Link: https://public-inbox.org/meta/DM6PR12MB49106F8E3BD697B63B943A22DADB0@DM6PR12MB4910.namprd12.prod.outlook.com/
Tested-by: Ali Alnubani <alialnu@nvidia.com>
3 years agodefault to CORE::warn in $SIG{__WARN__} handlers
Eric Wong [Sat, 26 Dec 2020 01:44:36 +0000 (01:44 +0000)]
default to CORE::warn in $SIG{__WARN__} handlers

As with CORE::die and $SIG{__DIE__}, it turns out CORE::warn is
safe to use inside $SIG{__WARN__} handlers without triggering
infinite recursion.  So fall back to reusing CORE::warn instead
of creating a new sub.

3 years agoinbox: name variable for values loop iterator
Eric Wong [Sat, 26 Dec 2020 08:12:52 +0000 (08:12 +0000)]
inbox: name variable for values loop iterator

->on_inbox_unlock callbacks could clobber $_, and this seems to
fix a problem with -extindex --watch failing to index some
inboxes after SIGHUP reload.

3 years agoinboxidle: avoid needless syscalls on refresh
Eric Wong [Sat, 26 Dec 2020 09:34:39 +0000 (09:34 +0000)]
inboxidle: avoid needless syscalls on refresh

We don't have to replace a bunch of existing watches
with identical new ones.  On Linux with Linux::Inotify2
installed, this avoids a storm of inotify_add_watch(2)
and inotify_rm_watch(2) syscalls on SIGHUP with -imapd
and "-extindex --watch"

3 years agoinboxidle: clue users into resolving ENOSPC from inotify
Eric Wong [Sat, 26 Dec 2020 05:59:22 +0000 (05:59 +0000)]
inboxidle: clue users into resolving ENOSPC from inotify

It may not be obvious to users a ENOSPC error is from hitting
a (tunable) kernel-imposed limit on inotify watches, and not
some storage device running out of space.  Give them a hint
here to reduce our own support burden.

3 years agoindex: filter out indexlevel=basic from extindex
Eric Wong [Fri, 25 Dec 2020 10:21:15 +0000 (10:21 +0000)]
index: filter out indexlevel=basic from extindex

extindex users will likely want to use indexlevel=basic for
per-inbox indices, however extindex itself doesn't support basic
index level (yet?).  Let's ensure we don't trip up extindex
users who specify "-L basic" on the -index command-line.

3 years agov2writable: don't verify tip if reindexing
Eric Wong [Fri, 25 Dec 2020 10:21:14 +0000 (10:21 +0000)]
v2writable: don't verify tip if reindexing

We only rely on git-rev-parse to resolve symbolic names ("HEAD")
to a SHA-* git commit ID.  We'll assume any git commit IDs we
get from SQLite DBs are valid and let "git-log" fail if it
isn't.

3 years agoindex: fix --no-fsync flag propagation to extindex
Eric Wong [Fri, 25 Dec 2020 10:21:13 +0000 (10:21 +0000)]
index: fix --no-fsync flag propagation to extindex

Negation in flag names are confusing, but trying to deviate from
the DB_NO_SYNC name used by Xapian is also confusing.

3 years agoindex: do not attach inbox to extindex unless updated
Eric Wong [Fri, 25 Dec 2020 10:21:12 +0000 (10:21 +0000)]
index: do not attach inbox to extindex unless updated

We'll count the number of log changes (regardless of index or
unindex) and only attach inboxes to ExtSearchIdx objects when
they get new work.  We'll also reduce lock bouncing and only
update external indices after all per-inbox indexing is done.

This also updates existing v2 indexing/unindexing callers
to be more consistent and ensures unindex log entries update
per-inbox last commit information.

3 years agoextsearchidx: close DB handles after use if FD constrained
Eric Wong [Fri, 25 Dec 2020 10:21:11 +0000 (10:21 +0000)]
extsearchidx: close DB handles after use if FD constrained

Most distros ship with low RLIMIT_NOFILE limits and surprises
may lurk for admins who configure many inboxes.  Keep FD usage
under control to avoid EMFILE errors at inopportune times during
reindex.

From what I can tell, this is the only place where extindex can
have unpredictable FD growth when there's thousands of inboxes,
and it's in an extremely rare code path.

3 years agoextsearchidx: delay SQLite availability checks
Eric Wong [Fri, 25 Dec 2020 10:21:10 +0000 (10:21 +0000)]
extsearchidx: delay SQLite availability checks

This will make attach_inbox faster for no-op calls.  It also
helps us avoid races in case msgmap or over.sqlite3 gets
unlinked while -extindex is running.

3 years agoindex: disable --fast-noop on --reindex
Eric Wong [Fri, 25 Dec 2020 10:21:09 +0000 (10:21 +0000)]
index: disable --fast-noop on --reindex

These options make no sense when used together, just inform the
user and move on since it's probably harmless to continue.

3 years agoinit: use the return value of rel2abs_collapsed
Eric Wong [Sat, 26 Dec 2020 01:44:38 +0000 (01:44 +0000)]
init: use the return value of rel2abs_collapsed

:x

Fixes: 9fcce78e40b0a7c6 ("script/public-inbox-*: favor caller-provided pathnames")
3 years agoindex: support --fast-noop / -F switch
Eric Wong [Thu, 24 Dec 2020 10:09:19 +0000 (10:09 +0000)]
index: support --fast-noop / -F switch

Note: I'm not sure if it's worth documenting and supporting this
long-term.

We can can avoid taking locks for invocations of "index --all"
and rely on high-resolution ctime (struct timespec st_ctim)
comparisons of msgmap.sqlite3 and the packed-refs + refs/heads
directory of the newest epoch.

This cuts public-inbox-index invocations with
"--all --no-update-extindex -L basic" down from 0.92s to 0.31s.
The change with "-L medium" or "-L full" and (default) non-zero
jobs is even more drastic, reducing a 12-13s no-op invocation
down to the same 0.31s

3 years agoinboxwritable: delay umask_prepare calls
Eric Wong [Thu, 24 Dec 2020 10:09:18 +0000 (10:09 +0000)]
inboxwritable: delay umask_prepare calls

This simplifies all ->with_umask callers and opens the
door for further optimizations to delay/elide process spawning.

3 years agoindex: update [extindex "all"] by default, support -E
Eric Wong [Wed, 23 Dec 2020 23:02:55 +0000 (23:02 +0000)]
index: update [extindex "all"] by default, support -E

In most cases, this ensures users will only have to opt-in to
using -extindex once and won't have to issue extra commands
to keep external indices up-to-date when using
public-inbox-index.

Since we support arbitrary numbers of external indices for
ease-of-development, we'll support repeating "-E"
("--update-extindex=") in case users want to test changes in
parallel.

3 years agoconfig: config_fh_parse: micro-optimize harder
Eric Wong [Wed, 23 Dec 2020 08:38:53 +0000 (08:38 +0000)]
config: config_fh_parse: micro-optimize harder

Instead of relying on split() and a regexp, we'll drop split()
entirely and rely on index() + two substr() calls to operate on
fixed strings.  This brings PublicInbox::Config->new time down
from 0.98s down to 0.84s.

3 years agoconfig: config_fh_parse: micro-optimize
Eric Wong [Wed, 23 Dec 2020 08:38:52 +0000 (08:38 +0000)]
config: config_fh_parse: micro-optimize

We can avoid a slow regexp capture and instead and rely on
rindex + substr to extract the section from the config file.

Then we use the defined-or-assignment (//=) operator combined
with the documented return value of `push' to ensure @section_order
is unique without repeating a hash lookup.

Finally, we avoid short-lived variables inside the loop and
declare them subroutine-wide to knock a teeny bit of allocation
time.

Combined, these optimizations bring the ~1.22s
PublicInbox::Config->new time down to ~0.98s with 50K inboxes.

3 years agoconfig: git_config_dump: pre-compile RE for split
Eric Wong [Wed, 23 Dec 2020 08:38:51 +0000 (08:38 +0000)]
config: git_config_dump: pre-compile RE for split

It appears the Perl split() operator is not optimized for fixed
strings at all.  With this change, PublicInbox::Config->new (w/o
->fill_all) time is reduced from 1.81s to 1.22s on a config file
with 50K inboxes.

3 years agoconfig: _fill: inbox name extraction optimization
Eric Wong [Wed, 23 Dec 2020 08:38:50 +0000 (08:38 +0000)]
config: _fill: inbox name extraction optimization

Using substr() instead of a string copy + s// substitution here
reduces ->fill_all from 4.00s to 3.88s with 50K inboxes on my
workstation.

3 years agoextsearchidx: close SQLite handles after attaching
Eric Wong [Wed, 23 Dec 2020 08:38:49 +0000 (08:38 +0000)]
extsearchidx: close SQLite handles after attaching

This is needed to prevent us from running out of FDs when
indexing many inboxes.  Perhaps checking these on attach_inbox
is unnecessary and may be removed entirely down the line.

3 years agomiscsearch: index UIDVALIDITY, use as startup cache
Eric Wong [Wed, 23 Dec 2020 08:38:48 +0000 (08:38 +0000)]
miscsearch: index UIDVALIDITY, use as startup cache

This brings -nntpd startup time down from ~35s to ~5s with 50K
inboxes.

Further improvements ought to be possible with deeper changes to
MiscIdx, since -mda having to load every inbox seems unreasonable;
but this general change is fairly unintrusive.

3 years agoinboxwritable: _init_v1: set created_at ASAP
Eric Wong [Wed, 23 Dec 2020 08:38:47 +0000 (08:38 +0000)]
inboxwritable: _init_v1: set created_at ASAP

This ensures we have UIDVALIDITY to index earlier
rather than later for v1 inboxes, matching v2 behavior.

3 years agoinbox: git_epoch: correct false comment
Eric Wong [Wed, 23 Dec 2020 08:38:46 +0000 (08:38 +0000)]
inbox: git_epoch: correct false comment

The original comment hasn't been true since
PublicInbox::Git->modified was changed to use cat_async blob
responses.  In any case, manifest.js.gz generation already
cleans up per-epoch git processes used for ->modified.

3 years agoxt: add create-many-inboxes helper test
Eric Wong [Wed, 23 Dec 2020 08:38:45 +0000 (08:38 +0000)]
xt: add create-many-inboxes helper test

I've been using something like this to mock out thousands
of inboxes for testing.

3 years agomiscsearch: load Xapian at initialization
Eric Wong [Wed, 23 Dec 2020 08:38:44 +0000 (08:38 +0000)]
miscsearch: load Xapian at initialization

We need Xapian bindings loaded before calling
(Search::)Xapian::Database->new

3 years agowwwstream: show relative coderepo URLs correctly
Eric Wong [Tue, 22 Dec 2020 05:04:16 +0000 (05:04 +0000)]
wwwstream: show relative coderepo URLs correctly

Trying to link "foo.git" relative to the current URL usually
does not provide correct results, so prefix it by going
into the parent directory if an absolute (or protocol-relative)
URL is not supplied.

3 years agoadmin: resolve inboxes to absolute paths for index
Eric Wong [Tue, 22 Dec 2020 06:01:44 +0000 (06:01 +0000)]
admin: resolve inboxes to absolute paths for index

Some of my ancient v1-only scripts called public-inbox-index
to operate on GIT_DIR:

GIT_DIR=/path/to/foo.git public-inbox-index

This change ensures they keep working, otherwise "." will be
passed to the --git-dir= switch of git(1) because that's the
default directory if no inboxes are specified on the
command-line.

Fixes: 9fcce78e40b0a7c6 ("script/public-inbox-*: favor caller-provided pathnames")
3 years agopublic-inbox-v[12]-format.pod: make lexgrog happy
Uwe Kleine-König [Tue, 22 Dec 2020 17:18:10 +0000 (18:18 +0100)]
public-inbox-v[12]-format.pod: make lexgrog happy

The Debian package linter (lintian) emits the following warning:

W: bad-whatis-entry
N:
N:   A manual page should start with a NAME section, which lists the
N:   program name and a brief description. The NAME section is used to
N:   generate a database that can be queried by commands like apropos and
N:   whatis. You are seeing this tag because lexgrog was unable to parse
N:   the NAME section.
N:
N:   Manual pages for multiple programs, functions, or files should list
N:   each separated by a comma and a space, followed by \- and a common
N:   description.
N:
N:   Listed items may not contain any spaces. A manual page for a two-level
N:   command such as fs listacl must look like fs_listacl so the list is
N:   read correctly.
N:
N:   Refer to the lexgrog(1) manual page, the groff_man(7) manual page, and
N:   the groff_mdoc(7) manual page for details.
N:
N:   Severity: warning
N:
N:   Check: documentation/manual
N:
N:   Renamed from: manpage-has-bad-whatis-entry
N:

for public-inbox-v1-format and public-inbox-v2-format.

Adapt the descriptions to make lexgrog and so lintian happy.

3 years agosupport multiple CODE_URLs
Eric Wong [Mon, 21 Dec 2020 22:10:55 +0000 (22:10 +0000)]
support multiple CODE_URLs

public-inbox.org will expire in a few years, so ensure Tor .onions
can be known before then.

3 years agoextsearch*: drop unnecessary path canonicalization
Eric Wong [Mon, 21 Dec 2020 07:51:22 +0000 (07:51 +0000)]
extsearch*: drop unnecessary path canonicalization

Unlike inboxdir, the canonical-ness of -extindex paths is not
relevant at the moment, and may never be relevant at all.  So
don't mislead others into thinking these paths being
canonicalized matters.

3 years agosearchidx: rename get_val to int_val and return IV
Eric Wong [Mon, 21 Dec 2020 07:51:21 +0000 (07:51 +0000)]
searchidx: rename get_val to int_val and return IV

Values can be strings in Xapian, although we currently use
integer values exclusively.  Give the wrapper a more appropriate
name in case we start using string columns.

For future-proofing, we'll now return `undef' on missing columns
and coerce the return value to an IV (integer value) to save
memory, as sortable_unserialise returns a PV (pointer value)
scalar despite it existing to support numeric values.

3 years agouse rel2abs_collapsed when loading Inbox objects
Eric Wong [Mon, 21 Dec 2020 07:51:20 +0000 (07:51 +0000)]
use rel2abs_collapsed when loading Inbox objects

We need to canonicalize paths for inboxes which do not have
a newsgroup defined, otherwise ->eidx_key matches can fail
in unexpected ways.

3 years agoisearch: use numeric sort for article numbers
Eric Wong [Mon, 21 Dec 2020 07:51:19 +0000 (07:51 +0000)]
isearch: use numeric sort for article numbers

Perl sort is alphabetical by default and Xapian uses numeric
document IDs, so sort must be told explicitly to use numeric
comparisons even if the scalars are integer values (IV)
internally.

And eliminate extra hash marks ("#") since they're probably too
noisy if there are many IDs.

Note: I haven't seen this warning message in syslog, yet :>

3 years agoinbox: delay ->version detection
Eric Wong [Mon, 21 Dec 2020 07:51:18 +0000 (07:51 +0000)]
inbox: delay ->version detection

Our read-only code won't need to know the version until an inbox
is accessed.  This is a small step towards eliminating many
stat() calls on read-only daemon startup.

3 years agomanifest.js.gz: fix per-inbox /$INBOX/manifest.js.gz
Eric Wong [Mon, 21 Dec 2020 19:41:21 +0000 (19:41 +0000)]
manifest.js.gz: fix per-inbox /$INBOX/manifest.js.gz

/$INBOX/manifest.js.gz should not attempt to match every inbox
in the domain (or every inbox); that is for /manifest.js.gz
(without a /$INBOX prefix).

Fixes: f303b4add8ea1883 ("wwwlisting: avoid hogging event loop")
3 years agoconfig: eliminate unnecessary join call up front
Eric Wong [Sun, 20 Dec 2020 06:30:16 +0000 (06:30 +0000)]
config: eliminate unnecessary join call up front

We can rely on implicit join in string interpolation on die()
iff needed.

And just creating the arrayref up front to avoid an extra
backslash seems nicer at the moment.

3 years agodaemon: kill_workers: eliminate unnecessary loop
Eric Wong [Sun, 20 Dec 2020 06:30:15 +0000 (06:30 +0000)]
daemon: kill_workers: eliminate unnecessary loop

The `kill' perl op takes multiple PIDs, so there's no need to
iterate through the %pids hash.

3 years agodaemon: unconditionally call IO::Handle::blocking(0)
Eric Wong [Sun, 20 Dec 2020 06:30:14 +0000 (06:30 +0000)]
daemon: unconditionally call IO::Handle::blocking(0)

IO::Handle::blocking will always return the initial value from
the F_GETFL op and it won't issue F_SETFL if a socket is already
non-blocking.

3 years agodaemon: lazy load Cwd only for --daemonize users
Eric Wong [Sun, 20 Dec 2020 06:30:13 +0000 (06:30 +0000)]
daemon: lazy load Cwd only for --daemonize users

systemd users won't need it polluting the namespace; though
other things are still likely to load it.

3 years agoinboxidle: remove needless check for {inboxdir}
Eric Wong [Sun, 20 Dec 2020 06:30:12 +0000 (06:30 +0000)]
inboxidle: remove needless check for {inboxdir}

->each_inbox will never attempt to iterate an object
without {inboxdir}, and simplify + short-circuit the
corresponding code

3 years agoscript/public-inbox-*: favor caller-provided pathnames
Eric Wong [Sun, 20 Dec 2020 06:30:11 +0000 (06:30 +0000)]
script/public-inbox-*: favor caller-provided pathnames

We'll try to avoid calling Cwd::abs_path and use
File::Spec->rel2abs instead, since abs_path will resolve
symlinks the user specified on the command-line.

Unfortunately, ->rel2abs still leaves "/.." and "/../"
uncollapsed, so we still need to fall back to Cwd::abs_path in
those cases.

While we are at it, we'll also resolve inboxdir from deep inside
v2 directories instead of misdetecting them as v1 bare git
repos.

In any case, stop matching directories by name and instead rely
on the unique combination of st_dev + st_ino on stat() as we
started doing in the extindex code.

3 years agowwwstream: linkify coderepo URLs
Eric Wong [Fri, 18 Dec 2020 20:53:09 +0000 (20:53 +0000)]
wwwstream: linkify coderepo URLs

It seems like a good idea to get more cgit visibility.

3 years agoextsearchidx: improve missing machine-id fallback
Eric Wong [Thu, 17 Dec 2020 19:40:06 +0000 (19:40 +0000)]
extsearchidx: improve missing machine-id fallback

It's likely most GNU/Linux systems have /etc/machine-id these
days, so anything missing it is likely a *BSD, most of which
support and favor "sysctl -n kern.hostid".  We'll also support
"ghostid" since GNU utils are commonly prefixed with 'g' on
non-GNU platforms.

In any case, we'll suppress stderr from missing commands and
fall back to hard coding an $OSNAME-based identifier as a last
resort and hope the hostname is unique.

3 years agonntpd: skip inboxes w/o {newsgroup}
Eric Wong [Fri, 18 Dec 2020 11:54:37 +0000 (11:54 +0000)]
nntpd: skip inboxes w/o {newsgroup}

So we don't trigger an uninitialized variable warning :x

3 years agoFix manpage section of perl module documentation
Uwe Kleine-König [Fri, 18 Dec 2020 11:56:14 +0000 (12:56 +0100)]
Fix manpage section of perl module documentation

On Debian (at least) perl documentation is supposed to be installed in
section 3pm. With the build system hardcoding this to 3 instead this
results in a warning by the Debian package linter:

W: public-inbox: wrong-manual-section usr/share/man/man3/PublicInbox::Git.3.gz:74 3 != 3pm
W: public-inbox: wrong-manual-section usr/share/man/man3/PublicInbox::Import.3.gz:74 3 != 3pm
W: public-inbox: wrong-manual-section usr/share/man/man3/PublicInbox::SaPlugin::ListMirror.3.gz:74 3 != 3pm
W: public-inbox: wrong-manual-section ... use --no-tag-display-limit to see all (or pipe to a file/program)

So use "$(MAN3EXT)" instead of "3".

3 years agoimport: drop X-Status in addition to Status
Eric Wong [Thu, 17 Dec 2020 09:14:48 +0000 (09:14 +0000)]
import: drop X-Status in addition to Status

It's actually supported by mutt, dovecot[1], and likely some other
software to augment the Status: header.  While dovecot doesn't
expose X-Status to clients, mutt will write 'A' (answered) and
'F' to X-Status (but not T (draft)).

So we'll drop it like we do Status since it's not suitable for
public mail, but stick it in an @UNWANTED_HEADERS array will
allow us to configure an override if needed.

[1]  https://doc.dovecot.org/configuration_manual/mail_location/mbox/

3 years agoextsearchidx: no need to make InboxWritable
Eric Wong [Wed, 16 Dec 2020 23:19:06 +0000 (23:19 +0000)]
extsearchidx: no need to make InboxWritable

extindex treats v1/v2 public inboxes as read-only, so there's
no need to scare people by using the InboxWritable package
now that ->git_dir_n is gone and we can use ->max_git_epoch
instead of ->git_dir_latest.

3 years agoinboxwritable: drop git_dir_n sub
Eric Wong [Wed, 16 Dec 2020 23:19:05 +0000 (23:19 +0000)]
inboxwritable: drop git_dir_n sub

There's only one caller, unlikely to be any more, and
should be harmless to open code.

3 years agoinbox: simplify v2 epoch counting
Eric Wong [Wed, 16 Dec 2020 23:19:04 +0000 (23:19 +0000)]
inbox: simplify v2 epoch counting

Perl readdir detects list context and can return an array
suitable for the grep op.  From there, we can rely on
substr to remove the ".git" suffix and integerize the value
to save a few bytes before letting List::Util::max return
the value.

This is how we detect Xapian shards nowadays, too, and
we'll also use defined-or (//) to simplify the return
value there.

We'll also simplify InboxWritable->git_dir_latest,
remove some callers, and consider removing it entirely.

3 years agoindex: ignore some warnings, set {current_info} for v1
Eric Wong [Wed, 16 Dec 2020 23:19:03 +0000 (23:19 +0000)]
index: ignore some warnings, set {current_info} for v1

-index runs on data that's already frozen in git, so there's
no point in warning users about it.

While we're at it, set the {current_info} prefix for v1 as
we do in v2 inboxes in case new problems show up.

3 years agoinboxwritable: warn_ignore: "Bad UTF7 data escape"
Eric Wong [Wed, 16 Dec 2020 23:19:02 +0000 (23:19 +0000)]
inboxwritable: warn_ignore: "Bad UTF7 data escape"

As with the other messages in this callback, there's
nothing we can do about invalid messages ending up in
our Maildirs for -watch.

3 years agoextsearchidx: lock eidxq on full --reindex
Eric Wong [Wed, 16 Dec 2020 23:04:53 +0000 (23:04 +0000)]
extsearchidx: lock eidxq on full --reindex

Incremental indexing can use the `eidxq' reindexing queue for
handling deletes and resuming interrupted indexing.  Ensure
those incremental -extindex invocations do not steal (and
prematurely perform) work that an "-extindex --reindex"
invocation is handling.