Eric Wong [Sun, 5 Apr 2020 01:28:49 +0000 (01:28 +0000)]
wwwstatic: set "Vary: Accept-Encoding" in static gzip response
We don't want to confuse intermediate caches into serving
gzipped content to any clients which can't handle it. It
probably doesn't matter in practice, though, since every HTTP
client seems to handle "Content-Encoding: gzip" regardless of
whether it was requested or not, though I could expect some
nc/socat/telnet/s_client users being annoyed.
This also matches the behavior of Plack::Middleware::Deflater
and other deflater implementations.
Eric Wong [Sat, 4 Apr 2020 08:03:18 +0000 (08:03 +0000)]
viewdiff: reduce sub parameter count
We're slowly moving towards doing all of our output buffering
into a single buffer, so passing that around on the stack as
a dedicated parameter is confusing.
Eric Wong [Sat, 4 Apr 2020 08:03:17 +0000 (08:03 +0000)]
view: dedupe_subject: allow "0" as a valid Subject
While rare in practice (even by spammers), A single "0" could
theoretically be the entire contents of a Subject line. So
use the Perl 5.10+ defined-or operator to improve correctness
of subject deduplication.
These seem mostly harmless since Perl will just truncate the
match and start a new one on a newline boundary in our case.
The only downside is we'd end up with redundant <span> tags in
HTML.
Limiting the number of line matched ourselves with `{1,$NUM}'
doesn't seem prudent since lines vary in length, so we continue
to defer the job of limiting matches to the Perl regexp engine.
I've noticed this warning in practice on 100K+ line patches to
locale data.
Eric Wong [Wed, 1 Apr 2020 06:16:20 +0000 (06:16 +0000)]
mid: add $MID_EXTRACT regexp for export
This allows us to consistently enforce the same Message-ID
extraction rules everywhere and makes it easier for us to
make changes in the future.
Update scripts/ssoma-replay, as well, but don't rely on
PublicInbox::* modules in that since it's legacy and
public-inbox was never a dependency of ssoma.
Eric Wong [Wed, 1 Apr 2020 06:16:18 +0000 (06:16 +0000)]
smsg: inline _extract_mid functionality
No need to keep an extra sub which isn't called anywhere else,
and the mid_clean call is redundant since mid_mime already
plucks the msgid out of the angle brackets.
Eric Wong [Tue, 31 Mar 2020 08:49:36 +0000 (08:49 +0000)]
v2writable: index Message-IDs w/ spaces properly
Message-IDs can apparently contain spaces and other weird
characters. Ensure we pass those properly to shard subprocesses
when importing messages in parallel mode.
Our NNTP request parser does not deal with spaces in the
Message-ID, yet, and I don't expect most NNTP clients to,
either. Nor does the Net::NNTP client handle them in responses.
Eric Wong [Mon, 30 Mar 2020 19:42:54 +0000 (19:42 +0000)]
t/multi-mid: allow test to run w/o Xapian
While the v1 inbox in this test is created without Xapian,
the v2 inbox in this test defaults to having Xapian enabled
regardless of whether it's installed or not.
Fixes: c7acdfe78bda5bf3 ("v2: SDBM-based multi Message-ID queue")
git-cat-file(1) may return less than the $BIN_DETECT value for
some blobs, so ensure we repopulate the values in $ctx for
retries in that case, otherwise we'll lose `$ctx->{-res}' and
die when attempting to use `undef' as an array ref.
Eric Wong [Mon, 30 Mar 2020 05:18:42 +0000 (00:18 -0500)]
wwwstream::oneshot => html_oneshot
And use Exporter to make our life easier, since WwwAltId was
using a non-existent PublicInbox::WwwResponse namespace in error
paths which doesn't get noticed by `perl -c' or exercised by
tests on normal systems.
Fixes: 6512b1245ebc6fe3 ("www: add endpoint to retrieve altid dumps")
Eric Wong [Sat, 28 Mar 2020 00:56:04 +0000 (00:56 +0000)]
index: support --compact / -c on command-line
It's more convenient to specify `-c' / `--compact' on the
command-line when reindexing than it is to invoke
public-inbox-compact(1) separately.
This is especially convenient in low-space situations when
public-inbox-index is operating on multiple inboxes
sequentially, as compaction can happen immediately after
indexing each inbox, instead of waiting until all inboxes are
indexed.
Eric Wong [Sat, 28 Mar 2020 00:56:03 +0000 (00:56 +0000)]
searchidxshard: ensure we set indexlevel on shard[0]
For sharded v2 repositories with few-enough messages, it is
possible for shard[0] to go unused and never trigger the
->commit_txn_lazy to set the indexlevel field in Xapian
metadata.
So set it immediately at initialization and avoid this case.
While we're at it, avoid triggering needless pwrite syscalls
from ->set_metadata by checking with ->get_metadata, first.
Eric Wong [Thu, 26 Mar 2020 08:21:29 +0000 (08:21 +0000)]
wwwaltid: inform users to use POST instead of GET
Seeing the example config linkified, some users may inevitably
try to following it in a browser with a GET request. Provide
a helpful message to inform users to use POST instead of
attempting to treat /$INBOX/$ALTID.sql.gz as a Message-Id.
Eric Wong [Sat, 21 Mar 2020 02:03:54 +0000 (02:03 +0000)]
www: add endpoint to retrieve altid dumps
This ensures all our indexed data, including data from altid
searches (e.g. "gmane:$ARTNUM") is retrievable.
It uses a "POST" request to avoid wasting cycles when invoked by
crawlers, since it could potentially be several megabytes of
data not indexable by search engines.
Eric Wong [Sat, 21 Mar 2020 02:03:53 +0000 (02:03 +0000)]
altid: warn about non-word prefixes
We only support searching on prefixes matching /\A\w+\z/ because
Xapian requires ':' to delimit the prefix and splits on spaces
without quotes.
I've also verified Xapian supports multibyte UTF-8 characters,
underscores, and bare numbers as search prefixes, so there's
no need to restrict it beyond what Perl's UTF-8 aware \w
character class offers.
Eric Wong [Sat, 21 Mar 2020 02:03:52 +0000 (02:03 +0000)]
wwwtext: show thread endpoint w/ indexlevel=basic
And show contact info when there's no indexing, at all.
Installations where Xapian is too expensive can still support
threading since it only depends on SQLite, so we need to inform
users of what's available.
Eric Wong [Sat, 21 Mar 2020 02:03:51 +0000 (02:03 +0000)]
search: clobber -user_pfx on query parser initialization
While we don't currently reinitialize the query parser for
the lifetime of a PublicInbox::Search object and have no plans
to, it's incorrect to be appending to an existing array in
case we reininitialize the query parser in the future.
Eric Wong [Sat, 21 Mar 2020 02:03:49 +0000 (02:03 +0000)]
mbox: need_gzip uses WwwStream::oneshot
This makes the error page more consistent.
Not that it really matters since Compress::Raw::Zlib and
IO::Compress packages have been distributed with Perl since
5.10.x. Of course, zlib itself is also a dependency of git.
Eric Wong [Sat, 21 Mar 2020 02:03:46 +0000 (02:03 +0000)]
wwwstream: introduce oneshot API to avoid ->getline
The ->getline API is only useful for limiting memory use when
streaming responses containing multiple emails or log messages.
However it's unnecessary complexity and overhead for callers
(PublicInbox::HTTP) when there's only a single message.
Eric Wong [Sat, 21 Mar 2020 02:03:45 +0000 (02:03 +0000)]
gzipfilter: lazy allocate the deflate context
zlib contexts are memory-intensive, particularly when used for
compression. Since the gzip filter may be sitting in a limiter
queue for a long period, delay the allocation we actually have
data to translate, and not a moment sooner.
Eric Wong [Sat, 21 Mar 2020 02:03:44 +0000 (02:03 +0000)]
qspawn: reinstate filter support, add gzip filter
We'll be supporting gzipped from sqlite3(1) dumps
for altid files in future commits.
In the future (and if we survive), we may replace
Plack::Middleware::Deflater with our own GzipFilter to work
better with asynchronous responses without relying on
memory-intensive anonymous subs.
Eric Wong [Fri, 20 Mar 2020 08:18:21 +0000 (08:18 +0000)]
v2: SDBM-based multi Message-ID queue
This lets us store author and committer times for deferred
indexing messages with ambiguous Message-IDs. This allows
us to reproducibly reindex messages with the git commit
and author times when a rare message lacks Received and/or
Date headers while having ambiguous Message-IDs.
Eric Wong [Fri, 20 Mar 2020 08:18:18 +0000 (08:18 +0000)]
*idx: pass $smsg in more places instead of many args
We can pass blessed PublicInbox::Smsg objects to internal
indexing APIs instead of having long parameter lists in some
places. The end goal is to avoid parsing redundant information
each step of the way and hopefully make things more
understandable.
Eric Wong [Fri, 20 Mar 2020 08:18:17 +0000 (08:18 +0000)]
overidx: parse_references: less error-prone args
Favor `$smsg->{mid}' instead of `$mid0' to reduce parameters
down-the-line, but favor passing the Email::MIME::Header object
around instead of relying on the bloat-prone `$smsg->{mime}'
and calling ->header_obj on it.
Since the introduction of over.sqlite3, SearchMsg is not tied to
our search functionality in any way, so stop confusing ourselves
and future hackers by just calling it "PublicInbox::Smsg".
Eric Wong [Fri, 20 Mar 2020 08:18:14 +0000 (08:18 +0000)]
v2writable: preserve timestamps from import
While v2 indexing is triggered immediately after writing the
commit to the git repository, there may be a gap between when
PublicInbox::Import generates a timestamp and when
PublicInbox::SearchIdx sees the message. So follow the mirror
indexing behavior and take the to-be-indexed (time|date)stamps
directly from the git commit.
Eric Wong [Fri, 20 Mar 2020 08:18:13 +0000 (08:18 +0000)]
index: use git commit times on missing Date/Received
When indexing messages without Date: and/or Received: headers,
fall back to using timestamps originally recorded by git in the
commit object. This allows git mirrors to preserve the import
datestamp and timestamp of a message according to what was fed
into git, instead of blindly falling back to the current time.
Eric Wong [Sat, 21 Mar 2020 05:24:32 +0000 (05:24 +0000)]
t/www_listing: avoid 'once' warnings
We reach into the WwwListing package directly to retrieve
that JSON encoder/decoder object, and we can't rely on `use'
since WwwListing loading may fail if Plack is missing.
Eric Wong [Thu, 19 Mar 2020 08:32:56 +0000 (03:32 -0500)]
viewdiff: favor `qr' to precompile regexps
We can also avoid `o' regexp modifier, since it isn't
recommended by Perl upstream, anymore (although we don't
have any bugs or unintended behavior because of it).
Eric Wong [Thu, 19 Mar 2020 08:32:55 +0000 (03:32 -0500)]
daemon: do more immortal allocations up front
Doing immortal allocations late can cause those allocations
to end up in places where it fragments the heap. So do more
things up front for long-lived daemons.
Eric Wong [Thu, 19 Mar 2020 08:32:53 +0000 (03:32 -0500)]
wwwlisting: avoid lazy loading JSON module
We already lazy-load WwwListing for the CGI script, and
hiding another layer of lazy-loading makes things difficult
to do WWW->preload.
We want long-lived processes to do all long-lived allocations up
front to avoid fragmentation in the allocator, but we'll still
support short-lived processes by lazy-loading individual modules
in the PublicInbox::* namespace.
Mixing up allocation lifetimes (e.g. doing immortal allocations
while a large amount of space is taken by short-lived objects)
will cause fragmentation in any allocator which favors large
contiguous regions for performance reasons. This includes any
malloc implementation which relies on sbrk() for the primary
heap, including glibc malloc.
Eric Wong [Thu, 19 Mar 2020 08:32:51 +0000 (03:32 -0500)]
www: update ->preload for newer modules
We'll also avoid explicitly loading standard library modules
like POSIX and Digest::SHA, here; instead we load our own
modules and let those load whatever non-PublicInbox:: modules
they need.
Eric Wong [Thu, 19 Mar 2020 07:51:53 +0000 (07:51 +0000)]
doc: standards: add references to RFC 5322 (and RFC 822)
RFC 5322 is the latest one in this line, but much documentation
and even command-line options in other programs (e.g. git) refer
to RFC 2822 or even RFC 822.
Eric Wong [Tue, 17 Mar 2020 06:52:17 +0000 (06:52 +0000)]
http: fix RFC conformance w.r.t. message length
We need to favor "Transfer-Encoding: chunked" over the value of
the Content-Length header. We should also reject bogus,
duplicate and/or unreasonable values for both these, since they
can trigger unexpected behavior when combined with other HTTP
parsers in proxies such as varnish, nginx, haproxy, etc...
Eric Wong [Tue, 3 Mar 2020 05:03:11 +0000 (05:03 +0000)]
INSTALL: refer to the proper Debian version
Debian 10.0 was released July 2019, so update our documentation
to reflect that. While we're at it, fixup a broken footnote
reference for Inline::C, too.
Eric Wong [Sat, 7 Mar 2020 12:15:23 +0000 (12:15 +0000)]
daemon: remove unused $parent_pipe variable
We can just create a ParentPipe and let PublicInbox::DS
manage its life cycle. While we're at it, favor `\&coderef'
over `*coderef' so we're explicit about it being a code ref
and not some other ref type.
Eric Wong [Tue, 25 Feb 2020 09:23:03 +0000 (09:23 +0000)]
msgtime: assume +0000 if TZ missing when using Date::Parse
Some old emails don't have timezone offsets, since our
Date::Parse code path takes a liberal interpretation of dates,
fallback to using "+0000" as the timezone offset since it's
closer to the actual date of the message than whatever the
current date is.
Eric Wong [Wed, 26 Feb 2020 10:21:12 +0000 (10:21 +0000)]
import: drop '<' and '>' characters in addresses
Some strange "From:" lines will cause Email::Address::XS to
leave '<' (and presumably '>') in the address which
git-fast-import won't accept even if quoted. Workaround this
problem by deleting '<' and '>' the same way we delete them for
the ident name.
Eric Wong [Wed, 26 Feb 2020 00:44:05 +0000 (00:44 +0000)]
searchview: improve naming and simplify hash override
`%over' could be confused for the overview SQLite DB
instance, so call it `%override', instead. There's
also no need to write a loop to override a hash when
the language can do it for us.
Eric Wong [Mon, 24 Feb 2020 08:08:22 +0000 (08:08 +0000)]
v2writable: lookup_content => content_exists
It only needs to return a boolean, since none of the current
callers care about the return value. Thus avoid a hash table
assignment and use of `$smsg->{mime}', here.
Eric Wong [Mon, 24 Feb 2020 07:33:27 +0000 (07:33 +0000)]
viewdiff: remove optional CR handling
The only caller of `flush_diff' is `add_text_body', and that
already did CRLF conversion on the text part. The regexps in
SolverGit still need to preserve CR, however, since that
actually applies patches (instead of rendering them), and we
need to preserve CRLF patches for CRLF files.
Eric Wong [Mon, 24 Feb 2020 07:33:26 +0000 (07:33 +0000)]
hval: ascii_html: drop CRLF => LF conversion
Instead, we add CRLF conversion to the only remaining place
which needs it, ViewVCS. This save many redundant ops in in
many places.
The only other place where this mattered was in
View::add_text_body, but we already started doing CRLF
conversions when we added diff parsing and link generation for
ViewVCS. Otherwise, all other places we used this was for
header viewing and Email::MIME doesn't preserve CRLF in headers.
Eric Wong [Sun, 23 Feb 2020 22:47:15 +0000 (22:47 +0000)]
searchview: set obfuscation inbox properly
We never lookup `$ctx->{-obfuscate}' anywhere, as the
correct key is `$ctx->{-obfs_ibx}' since some of the
address obfuscation stuff is inbox-specific.
Note: some of the obfuscation stuff still needs tests,
but it's low-priority at the moment since I don't think
it's a good feature after all.
Eric Wong [Mon, 17 Feb 2020 11:00:48 +0000 (05:00 -0600)]
view: shorten life of MIME object for permalink
We don't need to hold onto the Email::MIME object across
multiple WwwResponse->getline calls, instead we can stuff
the rendered HTML of the first (and hopefully only) message
of the buffer into ctx->{-html_tip}.
Eric Wong [Sun, 16 Feb 2020 10:24:35 +0000 (10:24 +0000)]
doc: design_www: document solver endpoint
The blob regeneration (solving) part has been stable and
performant for over a year with no problems, even with web
crawlers constantly hitting it without needing rate limits.
All the other stuff is open to bikeshedding (as long as
my crappy hardware supports it :P)
Eric Wong [Sat, 15 Feb 2020 09:46:40 +0000 (09:46 +0000)]
view: remove last Hval->new caller
The object-oriented Hval API turned out to be less useful and
more clunky than I envisioned years ago, so get rid of it.
We'll no longer strip trailing whitespace from From: headers in
the HTML display, but I doubt anybody cares.
Eric Wong [Sat, 15 Feb 2020 09:46:39 +0000 (09:46 +0000)]
view: escape ampersand in Message-IDs
We need to escape ampersands (and some other characters for href
attributes), so introduce a `mid_href' sub to do just that.
'<', '>' and '"' were always escaped, so there's no risk of tag
or attribute injection, but creative Message-IDs could cause
confusion for some parsers and generate invalid URLs.
Start getting rid of the bloated, over-engineered OO Hval API
while we're at it, I only noticed this bug because I started
killing off Hval->new* callers.
Eric Wong [Sat, 15 Feb 2020 09:46:37 +0000 (09:46 +0000)]
view,searchview: avoid smsg method calls when using SQLite/Xapian
We already pre-populate the hashref when loading $smsg
(PublicInbox::SearchMsg) objects out of over.sqlite3 or Xapian,
so making expensive method calls isn't necessary in those cases.
We only need to use the method calls when SQLite or Xapian are
not available or are being populated (such as during indexing).
Eric Wong [Sat, 15 Feb 2020 09:46:36 +0000 (09:46 +0000)]
view: cleanup topic accumulation and dumping
Avoid needlessly normalizing the subject when dumping, since
it's pushed into the @$topic array during accumulation in
normalized form.
We can also safely treat $smsg as a hashref and avoid
calling "->ds" as a method since we know we've got that
loaded via Over||Search and won't have to use Email::MIME
header lookup methods.