]> Sergey Matveev's repositories - public-inbox.git/log
public-inbox.git
3 years agoeml: pure-Perl replacement for Email::MIME
Eric Wong [Thu, 7 May 2020 21:05:48 +0000 (21:05 +0000)]
eml: pure-Perl replacement for Email::MIME

Email::MIME eats memory, wastes time parsing out all the
headers, and some problems can't be fixed without breaking
compatibility for other projects which depend on it.

Informal benchmarks show a ~2x improvement in general
stats gathering scripts and ~10% improvement in HTML
view rendering.

We also don't need the ability to create MIME messages, just
parse them and maybe drop an attachment.

While this isn't the zero-copy or streaming MIME parser of my
dreams; it's still an improvement in that it doesn't keep a
scalar copy of the raw body around along with subparts.  It also
doesn't parse subparts up front, so it can also replace our uses
of Email::Simple.

3 years agosmsg: use capitalization for header retrieval
Eric Wong [Thu, 7 May 2020 21:05:47 +0000 (21:05 +0000)]
smsg: use capitalization for header retrieval

PublicInbox::Eml will have case-sensitive memoization to
avoid the need to call `lc' to retrieve common headers,
so ensure we call $mime->header() with the common
capitalization.

Unfortunately, we need to continue using lowercase for field
names for smsg, since NNTP requires case-insensitivity when
matching headers and method dispatch is expensive.

3 years agofilter/rubylang: avoid recursing subparts to strip trailers
Eric Wong [Thu, 7 May 2020 21:05:46 +0000 (21:05 +0000)]
filter/rubylang: avoid recursing subparts to strip trailers

Mailman only seems to add trailers (or signatures) as
attachments at the top-level of MIME messages.  So don't bother
recursing with ->walk_parts since ->walk_parts is non-trivial to
recreate in the Email::MIME replacement I'm working on.

3 years agomsg_iter: pass $idx as a scalar, not array
Eric Wong [Thu, 7 May 2020 21:05:45 +0000 (21:05 +0000)]
msg_iter: pass $idx as a scalar, not array

This doesn't make any difference for most multipart
messages (or any single part messages).  However,
this starts having space savings when parts start
nesting.

It also slightly simplifies callers.

3 years agomsg_iter: make ->each_part method for PublicInbox::MIME
Eric Wong [Thu, 7 May 2020 21:05:44 +0000 (21:05 +0000)]
msg_iter: make ->each_part method for PublicInbox::MIME

The reliance on Email::MIME->subparts is a tad inefficient with
a work-in-progress module to replace Email::MIME.  So move
towards using ->each_part as a class-specific iterator which can
take advantage of more class-specific optimizations in the
yet-to-be-revealed PublicInbox::Eml and PublicInbox::Gmime
classes.

The msg_iter() sub remains for compatibility with existing
3rd-party scripts/modules which use our small public Perl API
and Email::MIME.

3 years agowww: preload: load all encodings at startup
Eric Wong [Fri, 8 May 2020 01:59:01 +0000 (01:59 +0000)]
www: preload: load all encodings at startup

Encode lazy-loads encodings on an as-needed basis.  This is
great for short-lived programs, but leads to fragmentation in
long-lived daemons where immortal allocations can get
interleaved with short-lived, per-request allocations.

Since we have no idea which encodings will be needed when
there's a constant flow of incoming mail, just preload
everything available at startup.

3 years agosearch: support searching on List-Id
Eric Wong [Thu, 7 May 2020 03:00:09 +0000 (03:00 +0000)]
search: support searching on List-Id

We'll support both probabilistic matches via `l:' and boolean
matches via `lid:' for exact matches, similar to how both `m:'
and `mid:' are supported.  Only text inside angle braces (`<'
and `>') are supported, since I'm not sure if there's value in
searching on the optional phrases (which would require decoding
with ->header_str instead of ->header_raw).

3 years agoviewdiff: stricter highlighting and linkification check
Eric Wong [Wed, 6 May 2020 10:40:54 +0000 (10:40 +0000)]
viewdiff: stricter highlighting and linkification check

Sometimes senders draw ASCII tables and such which we
get fooled into attempting highlighting and diffstat
anchoring.

We now require 3 consecutive diff header lines:

/^--- /, /^\Q+++\E /, and /^@@ /

to enable diff highlighting (whether generated with git or not).
The presence of a line matching /^diff / is not sufficient or
even useful to us for highlighting diffs, since that could just
be part of a line-wrapped sentence.

However, we'll now check for the presence of a line matching
/^diff --git / before enabling diffstat anchors.  Otherwise
cover letters for a patch series may fool us into creating
anchors for diffstats.

3 years agoviewdiff: assume diffstat and diff order are identical
Eric Wong [Wed, 6 May 2020 10:40:53 +0000 (10:40 +0000)]
viewdiff: assume diffstat and diff order are identical

For non-malicious messages, we can assume the diffstat and actual
diff appear in the same order.  Thus we can store {-long_paths} as
an arrayref and only compare the first element when we encounter
a truncated path.

This should make HTML rendering stable when there's basename
conflicts in message such as
https://lore.kernel.org/backports/1393202754-12919-13-git-send-email-hauke@hauke-m.de/

This diffstat anchor linkification can still be defeated by
users who make actual path names beginning with "...", but we
won't waste CPU cycles on it, either.

3 years agogit: warn on ->cat_async callback errors
Eric Wong [Wed, 6 May 2020 00:40:45 +0000 (00:40 +0000)]
git: warn on ->cat_async callback errors

This will help us track down bugs in our own code when
it comes to missing error checking.

3 years agoscripts/slrnspool2maildir: don't sort glob()
Eric Wong [Sat, 2 May 2020 21:22:10 +0000 (21:22 +0000)]
scripts/slrnspool2maildir: don't sort glob()

glob() sorts alphabetically by default, which doesn't have
a useful meaning with many articles.  Stop wasting CPU cycles
and memory.

3 years agot/convert-compact: avoid warning on `scalar(split(...))'
Eric Wong [Fri, 1 May 2020 18:04:45 +0000 (18:04 +0000)]
t/convert-compact: avoid warning on `scalar(split(...))'

Perl 5.10.1 would warn about implicit assignment to @_ by
split().  So favor the documented method of using `tr'
to count lines.

Fixes: b5ddcb3352ef31ae ("index: support --compact / -c on command-line")
3 years agot/httpd-corner.t: fix uninitialized warning
Eric Wong [Fri, 1 May 2020 18:04:44 +0000 (18:04 +0000)]
t/httpd-corner.t: fix uninitialized warning

Current versions of Perl don't warn when vec() is given `undef'
as its first arg, but Perl 5.10.1 does, at least.

Fixes: c7b4cbdadf3116a0 ("t/httpd-corner: improve reliability and diagnostics")
3 years agofeed: remove PublicInbox::MIME module load
Eric Wong [Thu, 30 Apr 2020 10:38:29 +0000 (10:38 +0000)]
feed: remove PublicInbox::MIME module load

We don't call any Email::MIME or any PublicInbox::MIME-specific
functions in here.

3 years agot/precheck: remove Email::Simple->create from tests
Eric Wong [Wed, 29 Apr 2020 11:14:43 +0000 (11:14 +0000)]
t/precheck: remove Email::Simple->create from tests

It's likely we'll replace Email::Simple using our Email::MIME
alternative/replacement, as well.  So reduce the API surface we
interact with and make it easier to swap implementations.

3 years agomid: capitalize "ID" in "Message-ID"
Eric Wong [Wed, 29 Apr 2020 10:43:34 +0000 (10:43 +0000)]
mid: capitalize "ID" in "Message-ID"

Prefer the "ID" capitalization since it seems to to be the
preferred capitalization in RFC 5322.

In theory, this allows the interpreter to deduplicate the string
internally (I haven't checked if it does).

Unfortunately, there's too many instances of "Message-Id" in the
tests to be worth changing at this point.

3 years agogit: various minor speedups
Eric Wong [Tue, 28 Apr 2020 08:48:58 +0000 (08:48 +0000)]
git: various minor speedups

While testing performance improvements elsewhere, I noticed some
micro-optimizations could give a small ~2-3% speedup in my test
using the git async API to parse a large inbox.

The `read' perlfunc already has read-in-full behavior (unless
git is killed unexpectedly), so there's no point in using a
loop.  SearchIdxShard in the parallel v2 indexing code path
never looped on `read', either.

Furthermore, we can avoid method dispatch overhead on ->getline
and ->print by using `readline' and `print' as ops which can be
resolved during the Perl compilation phase.

Finally, avoid passing the IO handle around as a parameter,
since avoiding hash lookups with a local variable has its own
costs in stack and refcount bumping.

Best off all, there's less code :>

4 years agodoc: add clients.txt
Eric Wong [Mon, 27 Apr 2020 20:40:22 +0000 (20:40 +0000)]
doc: add clients.txt

Since some client tools exist for dealing with public-inbox
specifically, it seems like a good idea to list some of them.

Cc: Danh Doan <congdanhqx@gmail.com>
Acked-by: Daniel Borkmann <daniel@iogearbox.net>
Cc: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
Cc: Leah Neukirchen <leah@vuxu.org>
4 years agotestcommon: mime_load: drop extra $cb arg
Eric Wong [Sun, 26 Apr 2020 07:32:45 +0000 (07:32 +0000)]
testcommon: mime_load: drop extra $cb arg

We don't need the callback arg, anymore.

4 years agotests: replace mime_from_path with mime_load
Eric Wong [Sat, 25 Apr 2020 05:52:23 +0000 (05:52 +0000)]
tests: replace mime_from_path with mime_load

mime_from_path is designed to fail gracefully in busy Maildirs
whereas mime_load was made for loading files from a work tree.

4 years agotests: remove Email::MIME->create use entirely
Eric Wong [Sat, 25 Apr 2020 05:52:22 +0000 (05:52 +0000)]
tests: remove Email::MIME->create use entirely

Replace them with .eml files generated with the help of
Email::MIME, but without some extraneous and unnecessary
headers, and strip mime_load down to just loading files.

This will give us more freedom to experiment with other mail
libraries which may be more correct, better maintained, use
less memory and/or be faster than Email::MIME.

4 years agotestcommon: introduce mime_load sub
Eric Wong [Sat, 25 Apr 2020 05:52:21 +0000 (05:52 +0000)]
testcommon: introduce mime_load sub

We'll use this to create, memoize, and reuse .eml files.  This
will be used to reduce (and eventually eliminate) our dependency
on Email::MIME in tests.

4 years agofeed: drop needless version check
Eric Wong [Thu, 23 Apr 2020 01:54:52 +0000 (01:54 +0000)]
feed: drop needless version check

We don't need to be checking inbox versions in parts of the WWW
code.  Checking the presence of $ibx->over is enough, everywhere.

4 years agodoc: note some changes for 1.5
Eric Wong [Tue, 21 Apr 2020 20:30:06 +0000 (20:30 +0000)]
doc: note some changes for 1.5

As an established project (:P), it's important to document when
new features appear in manpages.   Users may be reading new
documentation online which doesn't reflect an older version they
have installed.

4 years agowatchmaildir: match List-ID case-insensitively
Eric Wong [Thu, 23 Apr 2020 08:34:19 +0000 (08:34 +0000)]
watchmaildir: match List-ID case-insensitively

RFC 2919 section 6 states the following:

  There is only one operation defined for list identifiers,
  that of case insensitive equality.

So no arguing with that.  Now, the other headers are
open to interpretation, so put a note about them.

4 years agowatchmaildir: scan all matching headers
Eric Wong [Thu, 23 Apr 2020 08:34:18 +0000 (08:34 +0000)]
watchmaildir: scan all matching headers

Some headers may appear more than once in a message, so it's
probably best to ensure we attempt matches on all of them.

This ought to allow matching on Received: or similar because a
list lacks List-IDs :P

4 years agot/mda.t: avoid needless use of Email::Simple
Eric Wong [Tue, 21 Apr 2020 21:16:14 +0000 (21:16 +0000)]
t/mda.t: avoid needless use of Email::Simple

Totally pointless to create an object only to convert
it back to a raw string for -mda input.

4 years agot/*.t: reduce dependency on Email::MIME APIs
Eric Wong [Tue, 21 Apr 2020 21:16:13 +0000 (21:16 +0000)]
t/*.t: reduce dependency on Email::MIME APIs

Instead, favor PublicInbox::MIME->new for non-attachment emails.
We may support alternatives to Email::MIME down the line.

We'll still keep Email::MIME->create to deal with attachments,
for now, but there's also a fair amount of test duplication
we should eliminate, later.

4 years agot/*.t: use Email::MIME->create over PublicInbox::MIME->create
Eric Wong [Tue, 21 Apr 2020 21:16:12 +0000 (21:16 +0000)]
t/*.t: use Email::MIME->create over PublicInbox::MIME->create

PublicInbox::MIME only supports ->new, and is only different
from Email::MIME for old versions of Email::MIME.  In the
future, PublicInbox::MIME may not be a subclass of Email::MIME
at all.

4 years agot/feed: remove useless $ENV{GIT_DIR} assignment
Eric Wong [Tue, 21 Apr 2020 21:16:11 +0000 (21:16 +0000)]
t/feed: remove useless $ENV{GIT_DIR} assignment

I don't think this has been useful since we stopped
supporting ssoma in this test.

4 years agomake zlib-related modules a hard dependency
Eric Wong [Tue, 21 Apr 2020 06:57:34 +0000 (06:57 +0000)]
make zlib-related modules a hard dependency

This allows us to simplify some of our existing code and make
future changes easier.

I doubt anybody goes through the trouble to have a Perl
installation without zlib support.  The zlib source code is even
bundled with Perl since 5.9.3 for systems without existing zlib
development headers and libraries.

Of course, zlib is also a requirement of git, too; and we're not
going to stop using git :)

[squashed: "wwwaltid: use gzipfilter up front"]

4 years agoview: actually omit subject text when dumping topics
Kyle Meyer [Wed, 22 Apr 2020 01:33:59 +0000 (21:33 -0400)]
view: actually omit subject text when dumping topics

Despite dump_topics() calling dedupe_subject() on the subject, the
index shows partly duplicated subjects, for example

  ` [PATCH 2/2] t/www_listing: avoid 'once' warnings
    ` [PATCH v2] t/www_listing: avoid 'once' warnings "

In the second line, the omission character " is appended, but the
entire subject is shown.  To display the subject with duplicated parts
omitted, regenerate it from the array that is modified by
dedupe_subject().

4 years agoview: strip omission character from current message in thread view
Kyle Meyer [Wed, 22 Apr 2020 01:33:58 +0000 (21:33 -0400)]
view: strip omission character from current message in thread view

In the thread view shown at the top of a message, the subject for the
current message is dropped, leaving just the sender's name.  However,
if skel_dump() omitted part of the subject because it was duplicated,
the omission character is still displayed:

  * [PATCH v2] t/www_listing: avoid 'once' warnings
    2020-03-21  1:10 ` [PATCH 2/2] t/www_listing: avoid 'once' warnings Eric Wong
  @ 2020-03-21  5:24   ` " Eric Wong

Note the " on the last line.

Adjust the regular expression in _th_index_lite() to account for the
omission character.

[ew: avoid capturing $1, keep under 80 cols]

4 years agoMerge branch '1.4.0-tag-merge'
Eric Wong [Wed, 22 Apr 2020 06:44:20 +0000 (06:44 +0000)]
Merge branch '1.4.0-tag-merge'

* 1.4.0-tag-merge:
  public-inbox 1.4.0

4 years agoMerge tag 'v1.4.0' into 1.4.0-tag-merge
Eric Wong [Wed, 22 Apr 2020 06:41:54 +0000 (06:41 +0000)]
Merge tag 'v1.4.0' into 1.4.0-tag-merge

Oops, it looks like I tagged, amended, and pushed
1.4.0 with the wrong tag and Message-ID

* tag 'v1.4.0':
  public-inbox 1.4.0

Link: https://public-inbox.org/meta/87r1wgqkff.fsf@kyleam.com/
4 years agot/nntpd: die if we can't open stderr output
Eric Wong [Tue, 21 Apr 2020 03:22:52 +0000 (03:22 +0000)]
t/nntpd: die if we can't open stderr output

We need to detect FS errors and bail out on the test
if we can't open a file -nntpd was just writing to.

4 years agot/nntpd: reduce dependencies on internal API
Eric Wong [Tue, 21 Apr 2020 03:22:51 +0000 (03:22 +0000)]
t/nntpd: reduce dependencies on internal API

Since the advent of run_script(), we can rely on it to simplify
our test code.  Changes like this will let us evolve the
internal API more easily while preserving stable CLI interfaces,
especially since we test the v2 path by default, now.

4 years agot/nntpd: fix lsof check w/ TEST_RUN_MODE=0
Eric Wong [Tue, 21 Apr 2020 03:22:50 +0000 (03:22 +0000)]
t/nntpd: fix lsof check w/ TEST_RUN_MODE=0

The `xqx' sub requires an absolute path for optional
commands.

Fixes: 6e07def560b211d9 ("testcommon: spawn-aware system() and qx[] workalikes")
4 years agoindex: support --max-size / publicinbox.indexMaxSize
Eric Wong [Mon, 20 Apr 2020 22:55:37 +0000 (22:55 +0000)]
index: support --max-size / publicinbox.indexMaxSize

In normal mail paths, we can rely on MTAs being configured with
reasonable limits in the -watch and -mda mail injection paths.

However, the MTA is bypassed in a git-only delivery path, a BOFH
could inject a large message and DoS users attempting to mirror
a public-inbox.

This doesn't protect unindexed WWW interfaces from Email::MIME
memory explosions on v1 inboxes.  Probably nobody cares about
unindexed WWW interfaces anymore, especially now that Xapian is
optional for indexing.

4 years agoqspawn: remove Perl 5.16.x leak workaround
Eric Wong [Fri, 17 Apr 2020 09:33:31 +0000 (09:33 +0000)]
qspawn: remove Perl 5.16.x leak workaround

It seems no longer necessary to workaround this Perl 5.16.3 bug
after the removal of anonymous subs from all of our internal
code in
https://public-inbox.org/meta/20191225075104.22184-1-e@80x24.org/

Tested with repeated clones (both aborted and completed)
in a CentOS 7.x VM which was once able to reproduce leaks
before the workaround appeared in 2fc42236f72ad16a
("qspawn: workaround Perl 5.16.3 leak, re-enable Deflater")

Cc: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
4 years agov2writable: drop SQLite-based multi_mid_q_new
Eric Wong [Mon, 20 Apr 2020 09:59:21 +0000 (09:59 +0000)]
v2writable: drop SQLite-based multi_mid_q_new

We switched to the SDBM-based queue to store author/committer
info last month.

Fixes: c7acdfe78bda5bf3 ("v2: SDBM-based multi Message-ID queue")
4 years agodrop needless `eval {}' around Config->new
Eric Wong [Mon, 20 Apr 2020 09:33:38 +0000 (09:33 +0000)]
drop needless `eval {}' around Config->new

It hasn't been needed since commit 089cca37fa036411
("config: ignore missing config files").  And we
actually want to propagate errors when we can't
start new processes or if git(1) is missing.

4 years agodoc: txt2pre: fix URL of git-filter-repo(1)
Eric Wong [Mon, 20 Apr 2020 07:07:07 +0000 (07:07 +0000)]
doc: txt2pre: fix URL of git-filter-repo(1)

Probably a typo when doing concatenation.

4 years agodoc: HACKING: add a bit about faster testing
Eric Wong [Mon, 20 Apr 2020 07:05:30 +0000 (07:05 +0000)]
doc: HACKING: add a bit about faster testing

`make test' is annoyingly slow, and `make check-run' works
wonders for improving the edit && test cycle.

4 years agotestcommon: spawn-aware system() and qx[] workalikes
Eric Wong [Sun, 19 Apr 2020 23:19:37 +0000 (23:19 +0000)]
testcommon: spawn-aware system() and qx[] workalikes

Barely noticeable on Linux, but this gives a 1-2% speedup
on a FreeBSD 11.3 VM and lets us use built-in redirects
rather than relying on /bin/sh.

4 years agot/ds-leak: use BSD::Resource
Eric Wong [Sun, 19 Apr 2020 23:19:36 +0000 (23:19 +0000)]
t/ds-leak: use BSD::Resource

We use BSD::Resource in other places, so there's no sense
in avoiding it, here.

4 years agoimport: init_bare: use pure Perl
Eric Wong [Sun, 19 Apr 2020 23:19:35 +0000 (23:19 +0000)]
import: init_bare: use pure Perl

Even on systems with Inline::C spawn(), this cuts a primed
"make check-run" time by 2-3% on Linux, and roughly 5-7% on
FreeBSD when using vfork-enabled spawn.

I doubt anybody cares: this omits the sample hooks and some
empty and useless-for-us or obsolete directories created by
git-init(1).

4 years agoimport: init_bare: allow use as method, use in tests
Eric Wong [Sun, 19 Apr 2020 23:19:34 +0000 (23:19 +0000)]
import: init_bare: allow use as method, use in tests

Allowing ->init_bare to be used as a method saves some
keystrokes, and we can save a little bit of time on systems with
our vfork(2)-enabled spawn().

This also sets us up for future improvements where we can
avoid spawning a process at all.

4 years agowatchmaildir: support multiple watchheader values
Kyle Meyer [Mon, 20 Apr 2020 00:13:32 +0000 (20:13 -0400)]
watchmaildir: support multiple watchheader values

The watchheader key supports only a single value.  Supporting multiple
watchheader values was mentioned in discussion [1] of 8d3e3bd8 (doc:
explain publicinbox.<name>.watchheader, 2019-10-09), and it wasn't
clear if there was a need.

One scenario in which matching multiple headers would be convenient is
when someone wants to set up public-inbox archives for some small
projects but does _not_ want to run mailing lists for them, instead
allowing others to follow the project by any of the pull mechanisms.
Using a common underlying address, an address alias for each project
is configured via a third-party email provider, with messages for each
alias being exposed as a separate public-inbox archive.  In this
setup, messages for an inbox cannot be selected by a List-ID header
but can be identified by the inbox's address in either the To or Cc
header.

To support such a use case, update the watchheader handling to
consider multiple values, accepting a message if it matches any value.
While selecting a message based on matching _any_ rather than _all_
values is motivated by the above scenario, it's worth noting that the
"any" behavior is consistent with how multiple listid config values
are handled.

[1] https://public-inbox.org/meta/20191010085118.r3amey4cayazfycb@dcvr/

4 years agot/v*-add-remove-add: fix typo in description of 'removed' check
Kyle Meyer [Sun, 19 Apr 2020 19:27:08 +0000 (15:27 -0400)]
t/v*-add-remove-add: fix typo in description of 'removed' check

4 years agodoc: start writeup on semi-automatic memory management
Eric Wong [Fri, 17 Apr 2020 10:24:45 +0000 (10:24 +0000)]
doc: start writeup on semi-automatic memory management

I don't consider Perl's memory management "automatic".  Instead,
having an extra bit of control as a hacker is nice and there's
no need to burden ordinary users with GC tuning knobs.

4 years agoreduce scope of mbox From_ line removal
Eric Wong [Sat, 18 Apr 2020 03:38:53 +0000 (03:38 +0000)]
reduce scope of mbox From_ line removal

It's unnecessary overhead for anything which does Email::MIME
parsing.  It was never done for v2 indexing, even though v1->v2
conversions did NOT remove those From_ lines.  There was never a
need to remote From_ lines the v1 SearchIdx paths, either.

Hitting a /$INBOX_URL/$MSGID/T/ endpoint with an 18 message
thread reveals a ~0.5% speed improvement.  This will become
more apparent when we have a faster MIME parser.

4 years agombox: use per-message line-ending for From_ line
Eric Wong [Sat, 18 Apr 2020 03:38:52 +0000 (03:38 +0000)]
mbox: use per-message line-ending for From_ line

Email::Simple preserves the message line ending in headers, so
make the From_ line consistent with the rest of the headers.

4 years agowwwatomstream: move {emit_header} field to $self
Eric Wong [Sat, 18 Apr 2020 03:38:51 +0000 (03:38 +0000)]
wwwatomstream: move {emit_header} field to $self

There's no need to pollute the cross-package $ctx with it.

4 years agofavor `do {}' over `eval {}' for localized slurp
Eric Wong [Sat, 18 Apr 2020 03:38:50 +0000 (03:38 +0000)]
favor `do {}' over `eval {}' for localized slurp

I did not know to use the return value of `do' back in the day.
There's probably no practical difference in these cases, but
`eval' is overkill for these uses and may hide actual errors.

We can get rid of a few redundant `scalar' ops and pass scalar
refs to Email::MIME->new to avoid copies in a few more places,
too.

4 years agoinbox: replace `eval {}' with `do {}' where appropriate
Eric Wong [Sat, 18 Apr 2020 03:38:49 +0000 (03:38 +0000)]
inbox: replace `eval {}' with `do {}' where appropriate

-Git->new and -Limiter->new will never fail unless there's
an OOM, so using `eval' is incorrect.

4 years agoinbox: don't memoize missing description|cloneurl
Eric Wong [Sat, 18 Apr 2020 03:38:48 +0000 (03:38 +0000)]
inbox: don't memoize missing description|cloneurl

It's probably common to have inboxes initially setup without
these files properly configured, so don't memoize at that stage.

4 years agosearchidx: die on cat-file failures
Eric Wong [Sat, 18 Apr 2020 03:38:47 +0000 (03:38 +0000)]
searchidx: die on cat-file failures

We always use the object ID from "git <log|rev-list>" for
retrieving blobs, so fail loudly if the git repository is
corrupt instead of silently continuing.

4 years agoinboxwritable: mime_from_path: reuse in more places
Eric Wong [Sat, 18 Apr 2020 03:38:46 +0000 (03:38 +0000)]
inboxwritable: mime_from_path: reuse in more places

There's nothing Maildir-specific about the function, so
`maildir_path_load' was a bad name.  So give it a more
appropriate name and use it in our tests.

This save ourselves some code and inconsistency by reusing an
existing internal library routine in more places.  We can drop
the "From_" line in some of our (formerly) mbox sample files.

4 years agosearchthread: reduce indirection by removing container
Eric Wong [Fri, 17 Apr 2020 09:28:49 +0000 (09:28 +0000)]
searchthread: reduce indirection by removing container

We can rid ourselves of a layer of indirection by subclassing
PublicInbox::Smsg instead of using a container object to hold
each $smsg.  Furthermore, the `{id}' vs. `{mid}' field name
confusion is eliminated.

This reduces the size of the $rootset passed to walk_thread by
around 15%, that is over 50K memory when rendering a /$INBOX/
landing page.

4 years agodoc: update 1.4.0 relnotes with date, start 1.5.0
Eric Wong [Fri, 17 Apr 2020 08:51:52 +0000 (08:51 +0000)]
doc: update 1.4.0 relnotes with date, start 1.5.0

4 years agopublic-inbox 1.4.0
Eric Wong [Fri, 17 Apr 2020 08:41:23 +0000 (08:41 +0000)]
public-inbox 1.4.0

4 years agopublic-inbox 1.4.0 v1.4.0
Eric Wong [Fri, 17 Apr 2020 08:41:23 +0000 (08:41 +0000)]
public-inbox 1.4.0

4 years agot/httpd-unix: skip some tests w/o signalfd|EVFILT_SIGNAL
Eric Wong [Fri, 17 Apr 2020 05:22:54 +0000 (05:22 +0000)]
t/httpd-unix: skip some tests w/o signalfd|EVFILT_SIGNAL

Some of these tests just don't seem reliable enough with the
way we or Perl do portable signal handling.

4 years agot/httpd-corner: improve reliability and diagnostics
Eric Wong [Thu, 16 Apr 2020 00:29:38 +0000 (00:29 +0000)]
t/httpd-corner: improve reliability and diagnostics

The graceful-shutdown-on-PUT test is unreliable because we can't
rely on a FIFO as we do with the GET tests.  So increase the
delay to 100ms since that seems enough on my system even with
CONFIG_HZ=100.

Add a timeout and backtrace to the $check_self sub to help with
further diagnostics while we're at it, too.

It would be nice if there were a portable syscall tracing
mechanism we could attach to the -httpd process to make the test
more determistic...

4 years agot/httpd-corner.t: relax read-after-failed-write handling
Eric Wong [Sat, 11 Apr 2020 10:53:30 +0000 (10:53 +0000)]
t/httpd-corner.t: relax read-after-failed-write handling

I've observed FreeBSD 11.2 read(2) having one of three
behaviors after a failed write(2) on a socket:

1) returning number of bytes read
2) failing with ECONNRESET
3) returning with EOF

1) is the most common, and I've only seen 1) on Linux.  It may
be possible to use SO_LINGER or shutdown(2) to ensure 1) always
happens, but SO_LINGER behavior seems inconsistent across OSes,
especially with non-blocking sockets.

Since these tests are corner-cases where we're dealing with
broken/malicious clients, lets continue spending the least
amount of syscalls protecting ourselves in the daemon and
instead make the client-side test code tolerate more socket
implementations.

4 years agot/*.t: localize $SIG{__WARN__} changes
Eric Wong [Sat, 11 Apr 2020 10:53:29 +0000 (10:53 +0000)]
t/*.t: localize $SIG{__WARN__} changes

We don't want to propagate %SIG changes to other tests when
running multiple tests within the same process via t/run.perl.

4 years agodskqxs: ignore EV_SET errors on EVFILT_WRITE
Eric Wong [Sat, 11 Apr 2020 10:53:28 +0000 (10:53 +0000)]
dskqxs: ignore EV_SET errors on EVFILT_WRITE

Just like the EPOLL_CTL_ADD emulation path, the EPOLL_CTL_MOD
and EPOLL_CTL_DEL emulation paths can fail if attempting to
install an EVFILT_WRITE for a read-only pipe.

I've only observed this on the EPOLL_CTL_DEL emulation path, but
I suspect it could happen on the EPOLL_CTL_MOD path as well.

Increasing the amount of read-only pipes we rely on with altid
exports via sqlite3 made this old bug more apparent and
reproducible while looping the test suite.

This may be adjusted in the future to deal with write-only
pipes, but we currently don't have any of those watched by
kqueue.

4 years agotestcommon: DESTROY: wait for killed daemon
Eric Wong [Sat, 11 Apr 2020 10:53:27 +0000 (10:53 +0000)]
testcommon: DESTROY: wait for killed daemon

Otherwise, the waitpid(-1, 0) call in Xapcmd::process_queue()
may reap it in a subsequent test when using t/run.perl to reuse
processes for testing.

While we're at it, make Xapcmd::process_queue warn about unknown
PIDs in case other PIDs leak through to us in the future.

4 years agoMANIFEST update
Eric Wong [Wed, 15 Apr 2020 10:15:56 +0000 (10:15 +0000)]
MANIFEST update

4 years agodoc: add technical/whyperl
Eric Wong [Tue, 7 Apr 2020 09:35:14 +0000 (04:35 -0500)]
doc: add technical/whyperl

Some people don't like Perl; but it exists, there's no
avoiding it with everything that depends on it.  And
nearly all code still works unmodified after 20 years.

4 years agodoc: start reproducibility document
Eric Wong [Tue, 7 Apr 2020 08:01:36 +0000 (08:01 +0000)]
doc: start reproducibility document

Not new ideas, just gathering thoughts.

4 years agodoc: escape internal ">" in listid code snippet
Kyle Meyer [Sat, 11 Apr 2020 21:05:01 +0000 (17:05 -0400)]
doc: escape internal ">" in listid code snippet

A code snippet in the listid description is incorrectly rendered as

    "publicinbox.$NAME.watchheader=List-Id:<foo.example.com">

Escape the closing bracket around the List-Id value to avoid this.
Also escape the opening bracket for symmetry/readability.

4 years agot/httpd-unix: improve test reliability
Eric Wong [Tue, 7 Apr 2020 21:02:30 +0000 (21:02 +0000)]
t/httpd-unix: improve test reliability

Net::Server::Daemonize::create_pid_file does not
write the PID file atomically, so we need to barf
if it's incomplete.

4 years agotriewyde: ficks soem speling errrors
Eric Wong [Tue, 7 Apr 2020 21:55:54 +0000 (21:55 +0000)]
triewyde: ficks soem speling errrors

Dikshunarees R gude!

4 years agotests: document run_mode=1 as not implemented
Eric Wong [Tue, 7 Apr 2020 21:55:53 +0000 (21:55 +0000)]
tests: document run_mode=1 as not implemented

It was implemented at some point, but it was more things to
support and the worst of both worlds: both unrealistic compared
to real-world use and slower than run_mode=2.

Noticed while looking for speling erorrs.

4 years agoview: do not redundantly obfuscate addresses
Eric Wong [Mon, 6 Apr 2020 08:32:52 +0000 (08:32 +0000)]
view: do not redundantly obfuscate addresses

We shouldn't rerun the address obfuscator on data we've
already run through.  Instead, run through the unescaped
text part and substitute the UTF-8 "\x{2022}" substitution
before it hits HTML escaping

Fixes: 9bdd81dc16ba6511 ("view: msg_iter calls add_body_text directly")
4 years agoportability: constants for NetBSD
Eric Wong [Mon, 6 Apr 2020 20:23:01 +0000 (20:23 +0000)]
portability: constants for NetBSD

NetBSD implements O_CLOEXEC, so let us use it to avoid
inadvertant FD sharing.  It also has the same value for SIGWINCH
as Linux and the other BSDs we support.

4 years agoxt/perf-msgview: update to use git->cat_async
Eric Wong [Mon, 6 Apr 2020 23:16:27 +0000 (23:16 +0000)]
xt/perf-msgview: update to use git->cat_async

It's about 5-10% faster on an SMP machine with an SSD,
even on a hot Linux page cache.

4 years agoexamples/grok-pull.post_update_hook: move url_base to the top
Eric Wong [Mon, 6 Apr 2020 09:56:21 +0000 (09:56 +0000)]
examples/grok-pull.post_update_hook: move url_base to the top

Users are encouraged to edit this script, anyways, so make it
easy for them to swap out and use whatever URL they need.

4 years agoexamples/grok-pull.post_update_hook: capture infourl
Eric Wong [Mon, 6 Apr 2020 09:56:20 +0000 (09:56 +0000)]
examples/grok-pull.post_update_hook: capture infourl

The value of infourl parameters are shared in the config, so
include them in the mirror.

4 years agoexamples/grok-pull.post_update_hook: fetch mirror description
Eric Wong [Mon, 6 Apr 2020 09:56:19 +0000 (09:56 +0000)]
examples/grok-pull.post_update_hook: fetch mirror description

The $INBOX_URL/description endpoint is available since v1.3.0,
so use it in mirrors.

4 years agogit: reduce stat buffer storage overhead
Eric Wong [Sun, 5 Apr 2020 07:53:49 +0000 (07:53 +0000)]
git: reduce stat buffer storage overhead

The stat() array is a whopping 480 bytes (on x86-64, Perl 5.28),
while the new packed representation of two 64-bit doubles as a
scalar is "only" 56 bytes.  This can add up when there's many
inboxes.  Just use a string comparison on the packed
representation.

Some 32-bit Perl builds (IIRC OpenBSD) lack quad support, so
doubles were chosen for pack() portability.

4 years agombox: halve ->getline "context switches"
Eric Wong [Sun, 5 Apr 2020 07:53:48 +0000 (07:53 +0000)]
mbox: halve ->getline "context switches"

We don't need to take extra trips through the event loop for a
single message (in the common case of Message-IDs being unique).
In fact, holding the body reference left behind by Email::Simple
could be harmful to memory usage, though in practice it's not a
big problem since code paths which use Email::MIME take far more.

4 years agorelease large (non ref) scalars using `undef $sv'
Eric Wong [Sun, 5 Apr 2020 07:53:47 +0000 (07:53 +0000)]
release large (non ref) scalars using `undef $sv'

Using `undef EXPR' like a function call actually frees the heap
memory associated with the scalar, whereas `$sv = undef' or
`$sv = ""' will hold the buffer around until $sv goes out
of scope.

The `sv_set_undef' documentation in the perlapi(1) manpage
explicitly states this:

  The perl equivalent is "$sv = undef;". Note that it doesn't
  free any string buffer, unlike "undef $sv".

And I've confirmed by reading Dump() output from Devel::Peek.

We'll also inline the old index_body sub in SearchIdx.pm to make
the scope of the scalar more obvious.

This change saves several hundred kB RSS on both -index and
-httpd when hitting large emails with thousands of lines.

4 years agoxt/msgtime_cmp: fix false positives from msgtime change
Eric Wong [Sat, 4 Apr 2020 23:51:41 +0000 (23:51 +0000)]
xt/msgtime_cmp: fix false positives from msgtime change

commit d857e7dc0d816b635a7ead09c3273f8c2d2434be
("msgtime: assume +0000 if TZ missing when using Date::Parse")
introduced a behavior change which was causes false positives
when compared to the old code.

Update the "old" implementation to match this overdue behavior
change.

4 years agowwwstatic: set "Vary: Accept-Encoding" in static gzip response
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.

4 years agoview: inline flush_quote sub
Eric Wong [Sat, 4 Apr 2020 08:03:19 +0000 (08:03 +0000)]
view: inline flush_quote sub

No point in having an extra sub for a short, commonly
called function in the same file.

4 years agoviewdiff: reduce sub parameter count
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.

4 years agoview: dedupe_subject: allow "0" as a valid Subject
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.

4 years agoview: use defined-or operator to simplify checks
Eric Wong [Sat, 4 Apr 2020 08:03:16 +0000 (08:03 +0000)]
view: use defined-or operator to simplify checks

We depend on Perl 5.10 features in other places.  Shorten the
lifetime of the `$desc' scalar while we're at it.

4 years agoview: note we assume UTF-8 on unknown encodings
Eric Wong [Sat, 4 Apr 2020 08:03:15 +0000 (08:03 +0000)]
view: note we assume UTF-8 on unknown encodings

Clarify that we're assuming the text is UTF-8, since users
may have no idea how it's mangled.

4 years agoinboxwritable: fix From_ line unescaping
Eric Wong [Sat, 4 Apr 2020 06:17:29 +0000 (06:17 +0000)]
inboxwritable: fix From_ line unescaping

We can't rely on Email::MIME noticing the change to our
scalar ref after calling `PublicInbox::MIME->new'.

This is because Email::MIME::body_set (unlike
Email::Simple::body_set) will copy the contents of the body into
`->{body_raw}' as a new scalar.

Furthermore, we need to escape multiple From lines in the body,
not just the first one, using the `g' modifier to `s//'.

Reported-by: Kyle Meyer <kyle@kyleam.com>
4 years agoquiet "Complex regular subexpression recursion limit" warnings
Eric Wong [Fri, 3 Apr 2020 21:06:20 +0000 (21:06 +0000)]
quiet "Complex regular subexpression recursion limit" warnings

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.

4 years agoview: handle the topic-free case properly
Eric Wong [Fri, 3 Apr 2020 05:06:59 +0000 (05:06 +0000)]
view: handle the topic-free case properly

There may be no topics for a given timestamp range,
so don't attempt to treat `undef' as an arrayref.

4 years agonntp: allow multiple spaces or tabs to delimit args
Eric Wong [Thu, 2 Apr 2020 00:17:13 +0000 (00:17 +0000)]
nntp: allow multiple spaces or tabs to delimit args

While this is not a known problem in practice,
RFC 3977 section 3.1 states:

Keywords and arguments MUST each be separated by one
or more space or TAB characters.

4 years agomid: add $MID_EXTRACT regexp for export
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.

4 years agosearchidx: v1: skip mid_clean on mid_mime results
Eric Wong [Wed, 1 Apr 2020 06:16:19 +0000 (06:16 +0000)]
searchidx: v1: skip mid_clean on mid_mime results

We do not need run mid_clean() since mid_mime() uses mids()
to extract the msgid from inside the angle brackets.

4 years agosmsg: inline _extract_mid functionality
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.

4 years agoREADME: add a missing "be"
Kyle Meyer [Thu, 2 Apr 2020 00:26:14 +0000 (00:26 +0000)]
README: add a missing "be"