]> Sergey Matveev's repositories - public-inbox.git/log
public-inbox.git
3 years agoimap: use git-cat-file asynchronously
Eric Wong [Wed, 10 Jun 2020 07:04:22 +0000 (07:04 +0000)]
imap: use git-cat-file asynchronously

This ought to improve overall performance with multiple clients.
Single client performance suffers a tiny bit due to extra
syscall overhead from epoll.

This also makes the existing async interface easier-to-use,
since calling cat_async_begin is no longer required.

3 years agogit: do our own read buffering for cat-file
Eric Wong [Wed, 10 Jun 2020 07:04:21 +0000 (07:04 +0000)]
git: do our own read buffering for cat-file

To work with our event loop, we must perform read buffering
ourselves or risk starvation, as there doesn't appear to be
a way to check the amount of data buffered in userspace by
by the PerlIO layers without resorting to C or XS.

This lets us perform fewer syscalls at the expense of more Perl
ops.  As it stands, there seems to be a tiny performance
improvement, but more will be possible in the future.

3 years agogit: async: flatten the inflight array
Eric Wong [Wed, 10 Jun 2020 07:04:20 +0000 (07:04 +0000)]
git: async: flatten the inflight array

Small array refs have considerable overhead in Perl, so reduce
AV/SV overhead and instead allow the inflight array to grow
twice as large.

3 years agoimap: speed up HEADER.FIELDS[.NOT] range fetches
Eric Wong [Wed, 10 Jun 2020 07:04:19 +0000 (07:04 +0000)]
imap: speed up HEADER.FIELDS[.NOT] range fetches

While we can't memoize the regexp forever like we do with other
Eml users, we can still benefit from caching regexp compilation
on a per-request basis.

A FETCH request from mutt on a 4K message inbox is around 8%
faster after this.  Since regexp compilation via qr// isn't
unbearably slow, a shared cache probably isn't worth the
trouble of implementing.  A per-request cache seems enough.

3 years agoimap: support the CLOSE command
Eric Wong [Wed, 10 Jun 2020 07:04:18 +0000 (07:04 +0000)]
imap: support the CLOSE command

It seems worthless to support CLOSE for read-only inboxes, but
mutt sends it, so don't return a BAD error with proper use.

3 years agoimap: do not include ".PEEK" in responses
Eric Wong [Wed, 10 Jun 2020 07:04:17 +0000 (07:04 +0000)]
imap: do not include ".PEEK" in responses

They're not specified in RFC 3501 for responses, and at least
mutt fails to handle it.

3 years agoimap: support sequence number FETCH
Eric Wong [Wed, 10 Jun 2020 07:04:16 +0000 (07:04 +0000)]
imap: support sequence number FETCH

We'll return dummy messages for now when sequence numbers go
missing, in case clients can't handle missing messages.

3 years agoimap: simplify partial fetch structure
Eric Wong [Wed, 10 Jun 2020 07:04:15 +0000 (07:04 +0000)]
imap: simplify partial fetch structure

While the contents of normal %want hash keys are bounded in
size, %partial can cause more overhead and lead to repeated sort
calls on multi-message fetches.  So sort it once and use
arrayrefs to make the data structure more compact.

3 years agoimap: fix multi-message partial header fetches
Eric Wong [Wed, 10 Jun 2020 07:04:14 +0000 (07:04 +0000)]
imap: fix multi-message partial header fetches

We must keep the contents of {-partial} around when handling
a request to fetch multiple messages.

3 years agoimap: split out unit tests and benchmarks
Eric Wong [Wed, 10 Jun 2020 07:04:13 +0000 (07:04 +0000)]
imap: split out unit tests and benchmarks

This makes the test code easier-to-manage and allows us to run
faster unit tests which don't involve loading Mail::IMAPClient.

3 years agoimap: always include `resp-text' in responses
Eric Wong [Wed, 10 Jun 2020 07:04:12 +0000 (07:04 +0000)]
imap: always include `resp-text' in responses

Mail::IMAPClient doesn't seem to mind the lack of `resp-text';
but it's required by RFC 3501.  Preliminary tests with
offlineimap(1) indicates the presence of `resp-text' is
necessary, even if it's just the freeform `text'.

And make the `text' more consistent, favoring "done" over
"complete" or "completed"; while we're at it.

3 years agoimap: allow fetch of partial of BODY[...] and headers
Eric Wong [Wed, 10 Jun 2020 07:04:11 +0000 (07:04 +0000)]
imap: allow fetch of partial of BODY[...] and headers

IMAP supports a high level of granularity when it comes to
fetching, but fortunately Perl makes it fairly easy to support.

3 years agoeml: each_part: single part $idx is 1
Eric Wong [Wed, 10 Jun 2020 07:04:10 +0000 (07:04 +0000)]
eml: each_part: single part $idx is 1

Instead of counts starting at 0, we start the single-part
message at 1 like we do with subparts of a multipart message.
This will make it easier to map offsets for "BODY[$SECTION]"
when using IMAP FETCH, since $SECTION must contain non-zero
numbers according to RFC 3501.

This doesn't make any difference for WWW URLs, since single part
messages cannot have downloadable attachments.

3 years agoimap: support fetch for BODYSTRUCTURE and BODY
Eric Wong [Wed, 10 Jun 2020 07:04:09 +0000 (07:04 +0000)]
imap: support fetch for BODYSTRUCTURE and BODY

I'm not sure which clients use these, but it could be useful
down the line.

3 years agot/imapd: support FakeInotify and KQNotify
Eric Wong [Wed, 10 Jun 2020 07:04:08 +0000 (07:04 +0000)]
t/imapd: support FakeInotify and KQNotify

We can fill in some missing pieces from the emulation APIs
to enable IMAP IDLE tests on non-Linux platforms.

3 years agoimap: support LIST command
Eric Wong [Wed, 10 Jun 2020 07:04:07 +0000 (07:04 +0000)]
imap: support LIST command

We'll optimize for the common case of: $TAG LIST "" *
and rely on the grep perlfunc to handle trickier cases.

3 years agoimap: use Text::ParseWords::parse_line to handle quoted words
Eric Wong [Wed, 10 Jun 2020 07:04:06 +0000 (07:04 +0000)]
imap: use Text::ParseWords::parse_line to handle quoted words

IMAP clients may quote args and escape similar to POSIX shell,
so attempt to handle them properly using this standard library
module.

3 years agoimap: implement STATUS command
Eric Wong [Wed, 10 Jun 2020 07:04:05 +0000 (07:04 +0000)]
imap: implement STATUS command

I'm not sure if there's much use for this command, but it's
part of RFC3501 and works read-only.

3 years agoimap: delay InboxIdle start, support refresh
Eric Wong [Wed, 10 Jun 2020 07:04:04 +0000 (07:04 +0000)]
imap: delay InboxIdle start, support refresh

InboxIdle should not be holding onto Inbox objects after the
Config object they came from expires, and Config objects may
expire on SIGHUP.

Old Inbox objects still persist due to IMAP clients holding onto
them, but that's a concern we'll deal with at another time, or
not at all, since all clients expire, eventually.

Regardless, stale inotify watch descriptors should not be left
hanging after SIGHUP refreshes.

3 years agomsgmap: split ->max into its own method
Eric Wong [Wed, 10 Jun 2020 07:04:03 +0000 (07:04 +0000)]
msgmap: split ->max into its own method

There's enough places where we only care about the max NNTP
article number to warrant avoiding a call into SQLite.

Using ->num_highwater in read-only packages such as
PublicInbox::IMAP is also incorrect, since that memoizes
and won't pick up changes made by other processes.

3 years agoimap: support IDLE
Eric Wong [Wed, 10 Jun 2020 07:04:02 +0000 (07:04 +0000)]
imap: support IDLE

It seems to be working as far as Mail::IMAPClient is concerned.

3 years agoinboxidle: new class to detect inbox changes
Eric Wong [Wed, 10 Jun 2020 07:04:01 +0000 (07:04 +0000)]
inboxidle: new class to detect inbox changes

This will be used to implement IMAP IDLE, first.

Eventually, it may be used to trigger other things:

* incremental internal updates for manifest.js.gz
* restart `git cat-file' processes on pack index unlink
* IMAP IDLE-like long-polling HTTP endpoint

And maybe more things we haven't thought of, yet.

It uses Linux::Inotify2 or IO::KQueue depending on what packages
are installed and what the kernel supports.  It falls back to
nanosecond-aware Time::HiRes::stat() (available with Perl 5.10.0+)
on systems lacking Linux::Inotify2 and IO::KQueue.

In the future, a pure Perl alternative to Linux::Inotify2 may be
supplied for users of architectures we already support signalfd
and epoll on.

v2 changes:
- avoid O_TRUNC on lock file
- change ctime on Linux systems w/o inotify
- fix naming of comments and fields

3 years agopreliminary imap server implementation
Eric Wong [Wed, 10 Jun 2020 07:04:00 +0000 (07:04 +0000)]
preliminary imap server implementation

It shares a bit of code with NNTP.  It's copy+pasted for now
since this provides new ground to experiment with APIs for
dealing with slow storage and many inboxes.

3 years agonntpd: restrict allowed newsgroup names
Eric Wong [Wed, 10 Jun 2020 07:03:59 +0000 (07:03 +0000)]
nntpd: restrict allowed newsgroup names

We'll be using newsgroup names as mailbox names for IMAP,
too, so ensure we don't send wonky characters in responses.

I doubt this affects any real-world instances, but a BOFH could
choose strange names to cause grief for clients.

3 years agodoc: add some IMAP standards
Eric Wong [Wed, 10 Jun 2020 07:03:58 +0000 (07:03 +0000)]
doc: add some IMAP standards

There's more, but IMAP is big and complex already.

3 years agoindex: v2: parallel by default
Eric Wong [Sun, 7 Jun 2020 20:02:15 +0000 (20:02 +0000)]
index: v2: parallel by default

InboxWritable should only set $v2w->{parallel} if the $parallel
flag is defined to 0 or 1.  We want indexing a new inbox to
utilize SMP, just like --reindex.

-index once again allows -j0/--jobs=0 to force single-process
use, and we'll be ensuring that works in tests to maintain
performance on small systems.

Fixes: 61a2fff5b34a3e32 ("admin: move index_inbox over")
3 years agosearchidx: v1: fix retries when Xapian and Msgmap are out-of-sync
Eric Wong [Fri, 5 Jun 2020 02:01:10 +0000 (02:01 +0000)]
searchidx: v1: fix retries when Xapian and Msgmap are out-of-sync

We forcibly stop git-log here, so erroring out on git-log close
failures is wrong since it sees SIGPIPE.  Noticed while
reindexing a large v1 inbox for IMAP changes.

Fixes: b32b47fb12a3043d ("index: "git log" failures are fatal")
3 years agowwwatomstream: drop smsg->{mid} fallback for non-SQLite
Eric Wong [Mon, 1 Jun 2020 10:06:57 +0000 (10:06 +0000)]
wwwatomstream: drop smsg->{mid} fallback for non-SQLite

It's no longer necessary to populate the smsg->{mid} field now
that ->smsg_eml calls smsg->populate in rare cases where the
smsg did not originate from SQLite.

3 years agosmsg: remove remaining accessor methods
Eric Wong [Mon, 1 Jun 2020 10:06:56 +0000 (10:06 +0000)]
smsg: remove remaining accessor methods

We'll continue to favor simpler data models that can be
used directly rather than wasting time and memory with
accessor APIs.

The ->from, ->to, -cc, ->mid, ->subject, >references methods can
all be trivially replaced by hash lookups since all their values
are stored in doc_data.  Most remaining callers of those methods
were test cases, anyways.

->from_name is only used in the PSGI code, so we can just
use ->psgi_cull to take care of populating the {from_name}
field.

3 years agosmsg: remove ->bytes and ->lines methods
Eric Wong [Mon, 1 Jun 2020 10:06:55 +0000 (10:06 +0000)]
smsg: remove ->bytes and ->lines methods

They're stored directly in Xapian and SQLite document data.
NNTP accesses those fields directly to avoid method invocation
overhead so there's no reason to waste several kilobytes for
each sub.

3 years agosmsg: get rid of remaining {mime} users
Eric Wong [Mon, 1 Jun 2020 10:06:54 +0000 (10:06 +0000)]
smsg: get rid of remaining {mime} users

We'll let $smsg->populate take care of everything all at once
without hanging onto the header object for too long.

3 years agonntp: smsg_range_i: favor ->{$field} lookups when possible
Eric Wong [Mon, 1 Jun 2020 10:06:53 +0000 (10:06 +0000)]
nntp: smsg_range_i: favor ->{$field} lookups when possible

PublicInbox::Smsg::date remains the only exception which
requires any subroutine calls, here, so we'll just have
a branch just for that.

3 years agowww: remove smsg_mime API and adjust callers
Eric Wong [Mon, 1 Jun 2020 10:06:52 +0000 (10:06 +0000)]
www: remove smsg_mime API and adjust callers

To further simplify callers and avoid embarrasing memory
explosions[1], we can finally eliminate this method in
favor of smsg_eml.

[1] commit 7d02b9e64455831d3bda20cd2e64e0c15dc07df5
    ("view: stop storing all MIME objects on large threads")
    fixed a huge memory blowup.

3 years agoinbox: msg_by_*: remove $(size)ref args
Eric Wong [Mon, 1 Jun 2020 10:06:51 +0000 (10:06 +0000)]
inbox: msg_by_*: remove $(size)ref args

None of our current callers care about the size of the blob
we're retrieving, so stop wasting stack space and code for
it.

3 years agosmsg: get rid of ->wrap initializer, too
Eric Wong [Mon, 1 Jun 2020 10:06:50 +0000 (10:06 +0000)]
smsg: get rid of ->wrap initializer, too

We'll just use `bless' like most current PublicInbox::Smsg callers.

3 years agosmsg: introduce ->populate method
Eric Wong [Mon, 1 Jun 2020 10:06:49 +0000 (10:06 +0000)]
smsg: introduce ->populate method

This will eventually replace the __hdr() calling methods and
eradicate {mime} usage from Smsg.  For now, we can eliminate
PublicInbox::Smsg->new since most callers already rely on an
open `bless' to avoid the old {mime} arg.

3 years agoimport: modernize to use Perl 5.10 features
Eric Wong [Mon, 1 Jun 2020 10:06:48 +0000 (10:06 +0000)]
import: modernize to use Perl 5.10 features

First, prefer the leaner "parent" module over the heavy "base"
module to establish ISA relationships, since "base" is only
needed for "fields".

The "//" and "//=" operators allow us simplify our code and fix
minor bugs where a value of "0" was disallowed.  Yes, we'll
allow "0" as an email address, too, since some twisted BOFH
could theoretically use it as a local user name.

Going forward, we'll also be avoiding "use warnings" and
instead rely on `-w' in the shebang.

3 years agov2writable: fix non-sensical interpolation in BUG message
Eric Wong [Mon, 1 Jun 2020 10:06:47 +0000 (10:06 +0000)]
v2writable: fix non-sensical interpolation in BUG message

No point in attempting to print the value of an undefined
variable if there's a bug.  Fortunately, (AFAIK) we've never hit
that bug check :>

3 years agowwwatomstream: convert callers to use smsg_eml
Eric Wong [Mon, 1 Jun 2020 10:06:46 +0000 (10:06 +0000)]
wwwatomstream: convert callers to use smsg_eml

We can simplify WwwAtomStream callbacks by performing ->smsg_eml
calls in the `feed_entry' sub itself.  This simplifies callers,
by reducing the number of places which can load an Eml object
into memory.

3 years agoinbox: introduce smsg_eml method
Eric Wong [Mon, 1 Jun 2020 10:06:45 +0000 (10:06 +0000)]
inbox: introduce smsg_eml method

The goal of this is to eventually remove the $smsg->{mime} field
which is easy-to-misuse and cause memory explosions which
necessitated fixes like commit 7d02b9e64455831d
("view: stop storing all MIME objects on large threads").

3 years agowwwlisting: utf8::decode before undef
Eric Wong [Sun, 31 May 2020 23:09:03 +0000 (23:09 +0000)]
wwwlisting: utf8::decode before undef

Assisted by commit a73957b5b05f2a00f7a85353b1658b6d8cde05ae
("testcommon: speed up wait_for_tail() on GNU/Linux")

Fixes: 846161e3d1207d59 ("treat $INBOX_DIR/description and gitweb.owner as UTF-8")
3 years agotestcommon: speed up wait_for_tail() on GNU/Linux
Eric Wong [Sat, 30 May 2020 08:51:10 +0000 (08:51 +0000)]
testcommon: speed up wait_for_tail() on GNU/Linux

Somewhat recent versions of GNU tail(1) use inotify(7) on Linux;
so don't penalize hackers using TAIL='tail -F' to run their tests
with extra delays.

Ironically, we still need to busy loop on /proc/$TAIL_PID/{fd,fdinfo}
since inotify doesn't seem to support procfs.

3 years agotreat $INBOX_DIR/description and gitweb.owner as UTF-8
Eric Wong [Thu, 28 May 2020 18:37:08 +0000 (18:37 +0000)]
treat $INBOX_DIR/description and gitweb.owner as UTF-8

gitweb does the same with $GIT_DIR/description and gitweb.owner.

Allowing UTF-8 description should not cause problems when used
in responses for to the NNTP "LIST NEWSGROUPS" request, either,
since RFC 3977 section 7.6.6 recommends the description be UTF-8
(but does not require it).

Link: https://public-inbox.org/meta/20200528151216.l7vmnmrs4ojw372g@sourcephile.fr/
3 years agolearn: support --all with `rm'
Eric Wong [Tue, 26 May 2020 09:05:24 +0000 (09:05 +0000)]
learn: support --all with `rm'

I found myself wanting to remove a message from all inboxes
while working on a test case in another branch.  I figure this
could also be useful for globally removing messages which are in
the grey area or too big for spamc.

3 years agolearn: fix buggy typo on List-ID mapping
Eric Wong [Tue, 26 May 2020 09:05:23 +0000 (09:05 +0000)]
learn: fix buggy typo on List-ID mapping

There is obviously a typo here, so fix it and add a test
case to guard against future regressions.

Fixes: 74a3206babe0572a ("mda: support multiple List-ID matches")
3 years agomsgmap: tmp_clone: use in-memory journal
Eric Wong [Mon, 25 May 2020 03:30:20 +0000 (03:30 +0000)]
msgmap: tmp_clone: use in-memory journal

This prevents $TMPDIR from being littered with *-journal files
after running the test suite.

This shouldn't cause excessive memory use since $v2w->{mm_tmp}
doesn't see big transactions.  There's no need to worry about
data loss, here,either, since this is just a temporary clone
we've even disabled fsync on.

Fixes: 78888d36fb80889f ("msgmap: use TRUNCATE for journal_mode, for now")
3 years agoview: do not offer links to 0-byte multipart attachments
Eric Wong [Mon, 25 May 2020 08:21:37 +0000 (08:21 +0000)]
view: do not offer links to 0-byte multipart attachments

Offering links to download 0-byte files is useless.  We could
waste memory by preserving $eml->{bdy} during iteration, but
offering attachments of type "multipart" is not very useful,
as users are usually interested in decoded attachments or
the entire raw message.

Fixes: e60231148eb604a3 ("descend into message/(rfc822|news|global) parts")
3 years agov2writable: only load Xapian when a shard is found
Eric Wong [Sun, 24 May 2020 03:06:37 +0000 (03:06 +0000)]
v2writable: only load Xapian when a shard is found

We don't need to load Xapian until we have a directory
which looks like a shard, otherwise we're wasting cycles
on memory when running short-lived processes.

3 years agot/eml.t: favor ->header over ->header_str
Eric Wong [Wed, 20 May 2020 23:55:22 +0000 (19:55 -0400)]
t/eml.t: favor ->header over ->header_str

This test may still run against ancient versions of Email::MIME
for comparisons.

3 years agospawn: fix compatibility with old Inline::C
Eric Wong [Thu, 21 May 2020 05:12:46 +0000 (05:12 +0000)]
spawn: fix compatibility with old Inline::C

Older versions of Inline (e.g. 0.53 in CentOS 7) did not accept
the `directory' parameter, so use conditional assignment to set
a default value on $ENV{PERL_INLINE_DIRECTORY}, instead.

3 years agoscripts/import_*: remove PublicInbox::MIME usage
Eric Wong [Tue, 19 May 2020 09:06:58 +0000 (09:06 +0000)]
scripts/import_*: remove PublicInbox::MIME usage

These aren't really supported and will probably be replaced with
better tools, but PublicInbox::Eml should be readily available
to anybody who already has our source tree.

3 years agospamcheck/spamc: use localized slurp to read from spamc
Eric Wong [Tue, 19 May 2020 22:45:32 +0000 (22:45 +0000)]
spamcheck/spamc: use localized slurp to read from spamc

The <EXPR> perlop, `readline', and `read' functions will all
retry on EINTR, so there's no need to retry and loop ourselves
with `sysread'.

3 years agot/edit: use eml_load here, too
Eric Wong [Wed, 20 May 2020 04:46:07 +0000 (04:46 +0000)]
t/edit: use eml_load here, too

I missed this instance of file slurping into an Email::MIME-like
object the other week when tearing Email::MIME usage out.

3 years agoconvert: describe the release of fast-import pipes
Eric Wong [Wed, 20 May 2020 07:38:08 +0000 (07:38 +0000)]
convert: describe the release of fast-import pipes

Upon rereading the code, it wasn't immediately obvious to
me why we didn't check for errors with `close($w)' instead
of relying on `undef'.  So add a comment for the benefit of
future readers.

3 years agofavor readline() and print() as functions
Eric Wong [Sun, 17 May 2020 19:48:14 +0000 (19:48 +0000)]
favor readline() and print() as functions

In our inbox-writing code paths, ->getline as an OO method may
be confused with the various definitions of `getline' used by
the PSGI interface.  It's also easier to do: "perldoc -f readline"
than to figure out which class "->getline" belongs to (IO::Handle)
and lookup documentation for that.

->print is less confusing than the "readline" vs "getline"
mismatch, but we can still make it clear we're using a real
file handle and not a mock interface.

Finally, functions are a bit faster than their OO counterparts.

3 years agoindex: add --batch-size=SIZE option
Eric Wong [Sun, 17 May 2020 19:37:21 +0000 (19:37 +0000)]
index: add --batch-size=SIZE option

On powerful systems, having this option is preferable to
XAPIAN_FLUSH_THRESHOLD due to lock granularity and contention
with other processes (-learn, -mda, -watch).

Setting XAPIAN_FLUSH_THRESHOLD can cause -learn, -mda, and
-watch to get stuck until an epoch is completely processed.

3 years agoindex: v2: parallelize if --reindex or --jobs is specified
Eric Wong [Sun, 17 May 2020 00:08:54 +0000 (00:08 +0000)]
index: v2: parallelize if --reindex or --jobs is specified

`--reindex' involves chomping down lots of mail, so it benefits
from parallelization just like the initial indexing.  It's
also a bit surprising to specify `--jobs/-j' without parallel
processes, so ensure we turn on parallelization there, too.

We can simplify initialization here, as well, since neither
`eval' nor `V2Writable->new' should be in this code.

3 years agoconfine Email::MIME use even further
Eric Wong [Sat, 16 May 2020 22:53:53 +0000 (22:53 +0000)]
confine Email::MIME use even further

To avoid confusing future readers and users, recommend
PublicInbox::Eml in our Import POD and refer to PublicInbox::Eml
comments at the top of PublicInbox::MIME.

mime_load() confined to t/eml.t, since we won't be using
it anywhere else in our tests.

3 years agodescend into message/(rfc822|news|global) parts
Eric Wong [Sat, 16 May 2020 10:03:22 +0000 (10:03 +0000)]
descend into message/(rfc822|news|global) parts

Email::MIME never supported this properly, but there's real
instances of forwarded messages as message/rfc822 attachments.
message/news is legacy thing which we'll see in archives, and
message/global appears to be the new thing.

gmime also supports message/rfc2822, so we'll support it anyways
despite lacking other evidence of its existence.

Existing attachments remain downloadable as a whole message,
but individual attachments of subparts are now downloadable
and can be displayed in HTML, too.

Furthermore, ensure Xapian can now search for common headers
inside those messages as well as the message bodies.

3 years agot/psgi_attach: assert message/* parts are downloadable
Eric Wong [Sat, 16 May 2020 10:03:21 +0000 (10:03 +0000)]
t/psgi_attach: assert message/* parts are downloadable

We'll be adding support to descend into message/rfc822 (and
legacy message/news) attachments.  First, we must ensure
existing message/rfc822 attachments can be downloaded and remain
downloadable in future commits.

3 years agoview: drop a newline before first attachment link
Eric Wong [Sat, 16 May 2020 07:35:02 +0000 (07:35 +0000)]
view: drop a newline before first attachment link

However, we'll always have a newline before subsequent
attachments links after the first.

For the initial part of a multipart message, this regression
appeared in 1.5.0, but the display was overly clumped in prior
relases, too.

Fixes: 453dee4881a9c764 ("msg_iter: pass $idx as a scalar, not array")
3 years agoPublicInbox::Inbox.pm: Default unset address to a one element array
Eric W. Biederman [Fri, 15 May 2020 21:11:47 +0000 (16:11 -0500)]
PublicInbox::Inbox.pm: Default unset address to a one element array

PublicInbox::Config.pm::_fill() assumes that address is an array.
Therefore when handling an unset address use an array containing a
single string, instead of a single string.

Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
3 years agomsgmap: use TRUNCATE for journal_mode, for now
Eric Wong [Sun, 10 May 2020 22:37:14 +0000 (22:37 +0000)]
msgmap: use TRUNCATE for journal_mode, for now

It avoids I/O on the directory itself, which could prolong
the lifetime of the storage device.

3 years agooveridx: document the SQLite PRAGMA we use
Eric Wong [Sun, 10 May 2020 22:37:13 +0000 (22:37 +0000)]
overidx: document the SQLite PRAGMA we use

This ought to prevent cargo-culting the cache_size PRAGMA
into smaller SQLite DBs we might use.

3 years agorename "ContentId" to "ContentHash"
Eric Wong [Sun, 10 May 2020 22:37:12 +0000 (22:37 +0000)]
rename "ContentId" to "ContentHash"

The old name may be confused with "Content-ID" as described in
RFC 2392, so use an alternate name to avoid confusing future
readers.

3 years agoxt/eml_check_limits: check limits against an inbox
Eric Wong [Sun, 10 May 2020 22:37:11 +0000 (22:37 +0000)]
xt/eml_check_limits: check limits against an inbox

This allows maintainers to easily check limits against the
contents of existing inboxes.  This script covers most of
the new limits enforced by PublicInbox::Eml.

Usage is similar to most xt/*.t scripts:

  GIANT_INBOX_DIR=/path/to/inbox prove -bvw xt/eml_check_limits.t

Setting `TEST_CLASS=PublicInbox::MIME' allows us to check
performance and memory use against the old subclass of
Email::MIME.

3 years agospawn: use ~/.cache/public-inbox/inline-c if writable
Eric Wong [Mon, 11 May 2020 04:27:36 +0000 (04:27 +0000)]
spawn: use ~/.cache/public-inbox/inline-c if writable

Despite several memory reductions and pure Perl performance
improvements, Inline::C spawn() still gives us a noticeable
performance boost.

More user-oriented command-line programs are likely coming,
setting PERL_INLINE_DIRECTORY is annoying to users, and so is
is poor performance.  So allow users to opt-in to using our
Inline::C code once by creating a `~/.cache/public-inbox/inline-c'
directory.

XDG_CACHE_HOME is respected to override the location of ~/.cache
independent of HOME, according to
https://specifications.freedesktop.org/basedir-spec/0.6/ar01s03.html

v2: use "/nonexistent" if HOME is undefined, since that's
the home of the "nobody" user on both FreeBSD and Debian.

4 years agoemlcontentfoo: drop the {discrete} and {composite} fields
Eric Wong [Sun, 10 May 2020 09:42:02 +0000 (09:42 +0000)]
emlcontentfoo: drop the {discrete} and {composite} fields

We don't have to worry about compatibility with old
installations of Email::MIME::ContentType any longer,
so save some space.

4 years agot/mime: fix test to work w/o Email::MIME
Eric Wong [Sun, 10 May 2020 09:41:52 +0000 (09:41 +0000)]
t/mime: fix test to work w/o Email::MIME

Although the lazy loading changes were correct, the code
was still using PublicInbox::MIME as a fixed class.  Use
the `$cls' variable from the loop.

Favor ->subparts to ->parts, instead, too, since ->parts is
discouraged by the Email::MIME manpage and not implemented for
Eml.

4 years agobuild: check-manifest runs after tests
Eric Wong [Sun, 10 May 2020 19:38:23 +0000 (19:38 +0000)]
build: check-manifest runs after tests

And just treat it as a non-fatal nag when checking the rest of the
codebase.  Calling it "check-manifest" as a `make' target
preserves the old behavior, which causes the check to fail
if a file were added to the worktree without changing the
MANIFEST.

4 years agopublic-inbox 1.5.0 v1.5.0
Eric Wong [Sun, 10 May 2020 07:01:46 +0000 (07:01 +0000)]
public-inbox 1.5.0

4 years agovarious doc updates ahead of 1.5.0
Eric Wong [Sat, 9 May 2020 09:09:00 +0000 (09:09 +0000)]
various doc updates ahead of 1.5.0

4 years agoeml: rename limits to match postfix names
Eric Wong [Sun, 10 May 2020 06:21:05 +0000 (06:21 +0000)]
eml: rename limits to match postfix names

They're still part of our internal API at this point, but
reusing the same names as those used by postfix makes sense for
now to reduce cognitive overheads of learning new things.

There's no "mime_parts_limit", but the name is consistent
with "mime_nesting_limit".

4 years agoeml: enforce a maximum header length
Eric Wong [Sun, 10 May 2020 06:21:04 +0000 (06:21 +0000)]
eml: enforce a maximum header length

While our header processing is more efficient than
Email::*::Header, capping the maximum size for a `m//g' match
still limits memory growth on a header we care for.

Use the same limit as postfix (header_size_limit=102400), since
messages fetched via git/HTTP/NNTP/etc can bypass MTA limits.

4 years agosearch: remove documentation for "lid:"
Eric Wong [Sat, 9 May 2020 08:37:00 +0000 (08:37 +0000)]
search: remove documentation for "lid:"

I'm not sure it's necessary, since "mid:" is similarly
undocumented.  Also, "t:", "c:", "f:" don't offer boolean
analogues for exact matches on To/Cc/From headers, despite
having similar tokens as List-Id inside angle brackets.

4 years agoemlcontentfoo: quiet warning on missing attributes
Eric Wong [Sat, 9 May 2020 08:27:38 +0000 (08:27 +0000)]
emlcontentfoo: quiet warning on missing attributes

This bug was also present in Email::MIME::ContentType:
commit ae081fb576d8507efca4928116ad81efa756c723 (refs/pull/pull/9/head)
in https://github.com/rjbs/Email-MIME-ContentType.git

Our fix is shorter, but dependent on 5.10+ as our codebase
relies on Perl 5.10 features, anyways.

4 years agoeml: speed up common LF-only emails
Eric Wong [Sat, 9 May 2020 08:27:37 +0000 (08:27 +0000)]
eml: speed up common LF-only emails

Emails a *nix MTA are typically LF-only, so we don't need the
complexity of the RE engine when a simple index() works.  We
still need to ensure there's no "\r\n\r\n" before the first
"\n\n", but two calls to index() is still faster than a RE
match.

This gives a 2-5% speedup in some informal tests and saves ~30MB
when scanning a 30MB spam message on newer versions of Perl.
I'll have to diagnose why Perl wastes so much memory doing
RE matches on giant strings, though.

4 years agoeml: reduce RE captures and possible side effects
Eric Wong [Sat, 9 May 2020 08:27:36 +0000 (08:27 +0000)]
eml: reduce RE captures and possible side effects

Since Perl 5.6, the `@-' (aka @LAST_MATCH_START) and `@+' (aka
@LAST_MATCH_END) arrays provides integer offsets for every match
as documented in perlvar(1), regardless of regexp modifiers.

We can avoid relying on $1 in the epilogue scan, entirely.

So use these instead of relying on m//g and pos(), since the `g'
modifier can be affected by m//g matches performed in other
places.

Unrelated, but while we're in the area: remove some unnecessary
use of (?:...), too.

4 years agoviewdiff: don't increment the reported hunk line number
Kyle Meyer [Sat, 9 May 2020 18:57:46 +0000 (18:57 +0000)]
viewdiff: don't increment the reported hunk line number

For a diff hunk starting at line N, diff_hunk() constructs the link
with "#n(N + 1)".  This sends the viewer one line below the first
context line.  Although this is minor and may not even be noticed,
there's not an obvious reason to increment the line number, so switch
to using the reported value as is.

4 years agoeml: drop trailing blank line on missing epilogue
Eric Wong [Thu, 7 May 2020 21:05:56 +0000 (21:05 +0000)]
eml: drop trailing blank line on missing epilogue

This improves Email::MIME compatibility when running
xt/cmp-msgview.t on some GPG-signed messages.

Its usefulness is dubious in the long term and this patch
may be reverted down the line.

4 years agoremove most internal Email::MIME usage
Eric Wong [Thu, 7 May 2020 21:05:55 +0000 (21:05 +0000)]
remove most internal Email::MIME usage

We no longer load or use Email::MIME outside of comparison
tests.

4 years agoxt: eml comparison tests
Eric Wong [Thu, 7 May 2020 21:05:54 +0000 (21:05 +0000)]
xt: eml comparison tests

While our codebase can still work with either MIME
implementation, add comparison tests to ensure we
handle corner cases in existing archives.

4 years agoeml: remove dependency on Email::MIME::Encodings
Eric Wong [Thu, 7 May 2020 21:05:53 +0000 (21:05 +0000)]
eml: remove dependency on Email::MIME::Encodings

Since Email::MIME usage is going away, Email::MIME::Encodings
might as well go away, too.  We can also use fewer branches
and just rely on hash lookups, unlike E::M::E.

4 years agoEmlContentFoo: relax Encode version requirement
Eric Wong [Thu, 7 May 2020 21:05:52 +0000 (21:05 +0000)]
EmlContentFoo: relax Encode version requirement

We want to support Perl v5.10.1 out-of-the-box with minimal
download/installation time.  Installing Encode from CPAN
requires a compiler and lengthy build+install time.

So mimic find_mime_encoding() using what Perl v5.10.1 provides
out-of-the box.

4 years agoEmlContentFoo: Email::MIME::ContentType replacement
Eric Wong [Thu, 7 May 2020 21:05:51 +0000 (21:05 +0000)]
EmlContentFoo: Email::MIME::ContentType replacement

Since we're getting rid of Email::MIME, get rid of
Email::MIME::ContentType, too; since we may introduce
speedups down the line specific to our codebase.

4 years agoreplace most uses of PublicInbox::MIME with Eml
Eric Wong [Thu, 7 May 2020 21:05:50 +0000 (21:05 +0000)]
replace most uses of PublicInbox::MIME with Eml

PublicInbox::Eml has enough functionality to replace the
Email::MIME-based PublicInbox::MIME.

4 years agoswitch read-only Email::Simple users to Eml
Eric Wong [Thu, 7 May 2020 21:05:49 +0000 (21:05 +0000)]
switch read-only Email::Simple users to Eml

Since PublicInbox::Eml doesn't parse MIME subparts
up front, it can replace most uses of Email::Simple
without performance penalty.

This will eventually allow us to lower overall internal
API footprint by not having to keep the MIME vs Simple
distinction.

4 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.

4 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.

4 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.

4 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.

4 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.

4 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.

4 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).

4 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.

4 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.

4 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.

4 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.

4 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")
4 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")