]> Sergey Matveev's repositories - public-inbox.git/log
public-inbox.git
2 years agotreewide: favor open(..., '+<&=', $fd)
Eric Wong [Fri, 21 May 2021 10:28:25 +0000 (10:28 +0000)]
treewide: favor open(..., '+<&=', $fd)

Cut down on unnecessary imports of IO::Handle and
method lookup + dispatch overhead.

2 years agolei rediff: fix construction of git-diff options
Kyle Meyer [Fri, 21 May 2021 04:38:16 +0000 (00:38 -0400)]
lei rediff: fix construction of git-diff options

When generating git-diff options, lei-rediff extracts the single
character option from the lei option spec.  However, there's no check
that the regular expression actually matches, leading to an
unintentional git-diff option when there isn't a short option (e.g.,
--inter-hunk-context=1 maps to the invalid `git diff --color -w1').

Check for a match before trying to extract the single character
option.

Fixes: cf0c7ce3ce81b5c3 (lei rediff: regenerate diffs from stdin)
2 years agolei: relax rules for "new" in Maildir
Eric Wong [Wed, 19 May 2021 08:54:13 +0000 (08:54 +0000)]
lei: relax rules for "new" in Maildir

mbsync and offlineimap both use ":2," suffixes for filenames in
"new/", however my interpretation of the Maildir spec at
<https://cr.yp.to/proto/maildir.html> is that ":2," is only for
files in "cur/".  My interpretation also matches that of
doveecot, but we'll allow what mbsync and offlineimap do given
their popularity.

2 years agolei lcat: fix handling of multiple MSGID_OR_URL arguments
Kyle Meyer [Mon, 17 May 2021 03:37:00 +0000 (23:37 -0400)]
lei lcat: fix handling of multiple MSGID_OR_URL arguments

`lei lcat' is documented as being able to display multiple messages,
but this works only with --stdin because the positional argument
MSGID_OR_URL is missing a period.

2 years agodoc lei: update manpages with new options
Kyle Meyer [Mon, 17 May 2021 03:35:28 +0000 (23:35 -0400)]
doc lei: update manpages with new options

2 years agodoc lei: add manpages for new commands
Kyle Meyer [Mon, 17 May 2021 03:35:27 +0000 (23:35 -0400)]
doc lei: add manpages for new commands

[ew: MANIFEST: s/lei-cat/lei-lcat/]

2 years agodoc lei: add manpage for convert
Kyle Meyer [Mon, 17 May 2021 03:35:26 +0000 (23:35 -0400)]
doc lei: add manpage for convert

Link: https://public-inbox.org/meta/20210429015738.GA30172@dcvr/
2 years agodoc lei q: add missing value for --lock
Kyle Meyer [Mon, 17 May 2021 03:35:25 +0000 (23:35 -0400)]
doc lei q: add missing value for --lock

2 years agodoc lei q: fix a typo
Kyle Meyer [Mon, 17 May 2021 03:35:24 +0000 (23:35 -0400)]
doc lei q: fix a typo

2 years agodoc lei: resort lei-tag entries
Kyle Meyer [Mon, 17 May 2021 03:35:23 +0000 (23:35 -0400)]
doc lei: resort lei-tag entries

The command was renamed in 54da988cfb049ea2 (lei tag: rename from "lei
mark", 2021-03-30).  Relocate its entries in txt2pre and Makefile.PL
to restore alphabetical sorting.

2 years agodoc lei blob: point to lei-q for shared options
Kyle Meyer [Mon, 17 May 2021 03:35:22 +0000 (23:35 -0400)]
doc lei blob: point to lei-q for shared options

lei-blob shares a good number of options with lei-q.  Refer to lei-q's
manpage rather than repeating the descriptions.

Also, add lei-q to lei-blob's "see also" section.

Link: https://public-inbox.org/meta/YGFImEcWX1mCJJwv@dcvr/
2 years agodoc: split option variants into separate items
Kyle Meyer [Mon, 17 May 2021 03:35:21 +0000 (23:35 -0400)]
doc: split option variants into separate items

e226f18934eb7291 modified the lei-q manpage so that each variant of an
option gets a dedicated =item to make L</--xyz> look nicer and to
follow the Perl core documentation.  Do the same for the other
manpages.

Note that this still leaves the variants of an option grouped in one
scenario: when a list of options without descriptions is presented as
a pointer to another location.  Splitting the variants in that case
would make it harder for the reader to tell what the distinct options
are.

2 years agodoc lei blob: avoid combined description of separate options
Kyle Meyer [Mon, 17 May 2021 03:35:20 +0000 (23:35 -0400)]
doc lei blob: avoid combined description of separate options

The next commit will update the manpages to split each option's
variants into separate items.  This change won't mix well with
--oid-a, --path-a, and --path-b.  These different options all share a
single description, and, if each form is on its own line, the link
between the variants of each option would no longer be clear.

Use a dedicated description for each option to avoid confusion.

2 years agolei rediff: handle stdin like other commands
Kyle Meyer [Sun, 16 May 2021 02:42:42 +0000 (22:42 -0400)]
lei rediff: handle stdin like other commands

`lei rediff' reads from stdin when no argument is specified, but this
is likely unintentional given that other lei commands instead have a
--stdin|- option and that `lei rediff --help' includes --stdin.

Align rediff's handling with the other commands'.

2 years agolei rediff: mark --color-moved value as optional
Kyle Meyer [Sun, 16 May 2021 02:41:02 +0000 (22:41 -0400)]
lei rediff: mark --color-moved value as optional

`git-diff --color-moved' can be called without a mode, in which case
it defaults to "zebra".

2 years agolei_input: drop misplaced word from error message
Kyle Meyer [Sun, 16 May 2021 02:39:33 +0000 (22:39 -0400)]
lei_input: drop misplaced word from error message

2 years agodir_idle: support IN_DELETE_SELF|IN_MOVE_SELF, too
Eric Wong [Fri, 14 May 2021 20:14:47 +0000 (20:14 +0000)]
dir_idle: support IN_DELETE_SELF|IN_MOVE_SELF, too

We'll treat IN_MOVE_SELF as IN_DELETE_SELF since there
doesn't seem to be a reliable way to distinguish them
with FakeInotify, nor know the new name with kevent.

2 years agodir_idle: detect files which are gone
Eric Wong [Fri, 14 May 2021 07:27:57 +0000 (07:27 +0000)]
dir_idle: detect files which are gone

lei now makes use of this to clean up after unlinked sockets
with less delay.  This will also be used to maintain
mail_sync.sqlite3.

2 years agolei_mail_sync: do not disable CoW for this DB
Eric Wong [Thu, 13 May 2021 07:00:05 +0000 (07:00 +0000)]
lei_mail_sync: do not disable CoW for this DB

This is rather critical data for synchronization,
especially when "lei index" is used instead of "lei import"

2 years agogit: fix numerous bugs in git_quote and git_unquote
Eric Wong [Sun, 9 May 2021 11:16:13 +0000 (11:16 +0000)]
git: fix numerous bugs in git_quote and git_unquote

git always quotes with leading zeros to ensure the octal
representation is 3 characters long.  We enforce that to match
low ASCII characters (e.g. [x01-\x06]) that don't need the
range provided by 3 characters.

git_unquote now does a single pass so it won't get fooled by
decoded backslashes into parsing a digit as an octal character.
git_unquote is also capped to "\377" so we don't overflow a
byte.

2 years agot/sigfd: use PublicInbox::DS::block_signals
Eric Wong [Thu, 6 May 2021 17:09:23 +0000 (17:09 +0000)]
t/sigfd: use PublicInbox::DS::block_signals

We already use PublicInbox::DS in this test and I've always
found the terminology of sig* APIs confusing :x

2 years agosyscall: minor yak-shaving updates
Eric Wong [Thu, 6 May 2021 08:38:53 +0000 (08:38 +0000)]
syscall: minor yak-shaving updates

FreeBSD (and other *BSDs) do not have stable syscall numbers, so
drop no-op checks for it and add a note to use Inline::C,
instead.  Drop an implicit return for the syscall.ph loading
while we're at it, too.

On Linux, epoll_create(2) ignores the size arg since Linux
2.6.8, so just hard code it to some non-zero value.

On a side note, we can probably drop epoll_create(2) support
soon and just use epoll_create1(2) which appeared in 2.6.27+
(2008-10-09).  Our userspace (Perl and git) requirements are
already further ahead.

2 years agolei_xsearch: fix accounting bugs in for remote mboxrd
Eric Wong [Thu, 6 May 2021 02:28:19 +0000 (02:28 +0000)]
lei_xsearch: fix accounting bugs in for remote mboxrd

We must not accumulate mset totals for messages which
have already been counted.  Furthermore, the combined
search was being passed an extra arg and causing the
total to go missing.

2 years agolei_mail_sync: Maildir canonicalization omits trailing slash
Eric Wong [Thu, 6 May 2021 02:22:39 +0000 (02:22 +0000)]
lei_mail_sync: Maildir canonicalization omits trailing slash

We use trailing slashes internally, but should not increase
visual noise for users by exposing them in config files or
DB storage (and shell completion/listings).

This fixes a long-standing bug in $lei->rel2abs that prevented
absolute paths from being canonicalized.

2 years agolei_rediff: reduce overhead of tmp store
Eric Wong [Thu, 6 May 2021 01:53:36 +0000 (01:53 +0000)]
lei_rediff: reduce overhead of tmp store

We don't need Xapian positional info when searching
for blob pre/post-images.  Furthermore, rediff will
usually be used for a single email or at most, one
patchset.  So there's little point in parallelizing
or having multiple shards.

2 years agolei rediff: do not automatically store patches/mails
Eric Wong [Wed, 5 May 2021 17:49:44 +0000 (17:49 +0000)]
lei rediff: do not automatically store patches/mails

We can use a temporary lei/store to avoid cluttering up
future search results.  This is especially useful since
we expect "lei rediff" to be useful for non-email diffs
and individual attachments, too.

2 years agolei rediff: capture and regenerate file modes
Eric Wong [Wed, 5 May 2021 17:49:43 +0000 (17:49 +0000)]
lei rediff: capture and regenerate file modes

Don't lose file mode information when regenerating a diff.

2 years agoscript/public-inbox-extindex: chmod +x
Eric Wong [Wed, 5 May 2021 17:49:42 +0000 (17:49 +0000)]
script/public-inbox-extindex: chmod +x

Everything else that's intended to be executable at some
point has the executable bit set.  Remove an inaccurate
comment while we're at it.

2 years agolei blob: support "lei index"-ed mail
Eric Wong [Wed, 5 May 2021 10:46:38 +0000 (10:46 +0000)]
lei blob: support "lei index"-ed mail

Normal git retrieval don't work for Maildir blobs indexed using
"lei index".  Fortunately, this oddness is limited to the
LeiStore class and we can override smsg_eml with a fallback
to read blobs from Maildirs.

2 years agolei rediff: regenerate diffs from stdin
Eric Wong [Wed, 5 May 2021 10:46:37 +0000 (10:46 +0000)]
lei rediff: regenerate diffs from stdin

Sometimes a mailed patch is generated with non-ideal output,
(lacking context, noisy whitespace changes, etc.), or a user
wants to use the same external diff viewer they've configured
git to use.

Since we have SolverGit to regenerate arbitrary blobs from
patches; this new command allows us to regenerate a diff with
different options using the blobs SolverGit gives us.

The amount of git-diff(1) options is mind numbing, so it's
likely I missed some favorites or botched the getopt spec
translation.

This also fixes Inbox::base_url to check psgi.url_scheme
before attempting to generate URLs and avoid uninitialized
variable warnings.  Oddly, the "lei blob" tests did not
trigger these uninitialized warnings.

Note: this will automatically import+index the message(s)
it's regenerating, because solver relies on being able
to lookup pre/postimage OIDs and read blobs.

2 years agolei index: new command to index mail w/o git storage
Eric Wong [Tue, 4 May 2021 09:49:12 +0000 (09:49 +0000)]
lei index: new command to index mail w/o git storage

Since completely purging blobs from git is slow, users may wish
to index messages in Maildirs (and eventually other local
storage) without storing data in git.

Much code from LeiImport and LeiInput is reused, and a new dummy
FakeImport class supplies a non-storing $im->add and minimize
changes to LeiStore.

The tricky part of this command is to support "lei import"
after a message has gone through "lei index".  Relying on
$smsg->{bytes} == 0 (as we do for external-only vmd storage)
does not work here, since it would break searching for "z:"
byte-ranges when not using externals.

This eventually required PublicInbox::Import::add to use a
SharedKV to keep track of imported blobs and prevent
duplication.

2 years agolei: fix mail_sync.sqlite3 folder names for NNTP
Eric Wong [Tue, 4 May 2021 05:24:24 +0000 (05:24 +0000)]
lei: fix mail_sync.sqlite3 folder names for NNTP

We should not have "SCALAR(XXXXXXX)" showing up in SQLite DBs
because we passed a SCALAR ref instead of a non-ref SCALAR.

2 years agolei ls-mail-sync: fix handling of non-wildcard filters
Eric Wong [Tue, 4 May 2021 05:14:19 +0000 (05:14 +0000)]
lei ls-mail-sync: fix handling of non-wildcard filters

If lei_ls_mail_sync() is given a filter without any wildcards
and --globoff is unspecified, glob2re() will return undef,
resulting in the final regular expression being undefined.
Always use a fallback value when there's no RE.

Based-on-patch-by: Kyle Meyer <kyle@kyleam.com>
Link: https://public-inbox.org/meta/20210504044559.12941-5-kyle@kyleam.com/
2 years agolei: add help output for --invert match
Kyle Meyer [Tue, 4 May 2021 04:45:59 +0000 (00:45 -0400)]
lei: add help output for --invert match

ls-external and ls-mail-sync accept an --invert-match option.  Show it
in the --help output.

2 years agolei ls-mail-sync: accept a filter
Kyle Meyer [Tue, 4 May 2021 04:45:57 +0000 (00:45 -0400)]
lei ls-mail-sync: accept a filter

lei_ls_mail_sync() is written to accept a filter, and ls-mail-sync has
related command-line options (--globoff, --invert-match), but a
positional argument isn't actually accepted.  Add it.

2 years agolei ls-mail-sync: drop repeated -z/0 option
Kyle Meyer [Tue, 4 May 2021 04:45:56 +0000 (00:45 -0400)]
lei ls-mail-sync: drop repeated -z/0 option

2 years agolei ls-mail-sync: update reference to ls-sync
Kyle Meyer [Tue, 4 May 2021 04:45:55 +0000 (00:45 -0400)]
lei ls-mail-sync: update reference to ls-sync

ls-sync was renamed to ls-mail-sync in cb0e9d42b799c748.  Update a
stale reference to the old name.

2 years agodoc: ignore onion URLs for 80-column check
Eric Wong [Tue, 4 May 2021 04:15:44 +0000 (04:15 +0000)]
doc: ignore onion URLs for 80-column check

This failure was also passing under FreeBSD make + /bin/sh;
so we also avoid the '&&' chain is avoided and use '>$@' as a
separate line in the Makefile.

2 years agotreewide: update to v3 Tor onions
Eric Wong [Tue, 4 May 2021 01:32:25 +0000 (01:32 +0000)]
treewide: update to v3 Tor onions

v2 onions are insecure, deprecated and going away.  v3 names are
unfortunately longer and more difficult to remember, but should
be more resistant to attack than v2 ones.

2 years agolei up: fix dedupe with remote externals on Maildir + IMAP
Eric Wong [Mon, 3 May 2021 20:57:31 +0000 (20:57 +0000)]
lei up: fix dedupe with remote externals on Maildir + IMAP

LeiToMail Maildir and IMAP write callbacks need to account for
the caller-supplied smsg.  We'll also make better use of the
user-supplied smsg object by ensuring blob deduplication happens
ASAP.

Fixes: e76683309ca4f254 ("lei <q|up>: distinguish between mset and l2m counts")
2 years agolei <q|up>: writes to Maildirs and IMAP use mail-sync
Eric Wong [Sun, 2 May 2021 06:05:42 +0000 (06:05 +0000)]
lei <q|up>: writes to Maildirs and IMAP use mail-sync

This will allow keyword updates from other folders to propagate
to folders where search results may be duplicated.

2 years agonet_writer: use "FLAGS.SILENT" to set keywords
Eric Wong [Sun, 2 May 2021 06:05:41 +0000 (06:05 +0000)]
net_writer: use "FLAGS.SILENT" to set keywords

Instead of "+FLAGS.SILENT" which merely adds to the keywords.
We store all keywords together, so it's unlikely we will rely
on the "+FLAGS.SILENT" or "-FLAGS.SILENT".

2 years agolei: simplify workers_start API
Eric Wong [Sun, 2 May 2021 06:05:40 +0000 (06:05 +0000)]
lei: simplify workers_start API

In most cases, we just name the worker process based
on the command.  The only change is for LeiMirror
vs "lei add-external --mirror", but I doubt it matters.

2 years agolei_input: reject --mail-sync if using HTTP(S) for now
Eric Wong [Sun, 2 May 2021 06:05:39 +0000 (06:05 +0000)]
lei_input: reject --mail-sync if using HTTP(S) for now

I'm not sure how we'll distinguish JMAP vs read-only HTTPS,
yet; but we'll focus on currently-supported stuff, first.

2 years agolei_input: common net_merge_all_done for lei <import|tag>
Eric Wong [Sun, 2 May 2021 06:05:38 +0000 (06:05 +0000)]
lei_input: common net_merge_all_done for lei <import|tag>

I suspect there'll be more lei_input-only things in the future.

2 years agolei <q|up>: combine written/results into one line
Eric Wong [Sun, 2 May 2021 06:05:37 +0000 (06:05 +0000)]
lei <q|up>: combine written/results into one line

Having multiple lines of output mean they can be interleaved in
daemon mode.  Put stats into one line to reduce screen
real-estate size and improve readability.

3 years agolei_auth: s/net_merge_complete/net_merge_all_done/
Eric Wong [Sat, 1 May 2021 06:31:22 +0000 (06:31 +0000)]
lei_auth: s/net_merge_complete/net_merge_all_done/

We use the "done" term elsewhere for similar things, and
my easily-confused mind equates "complete" with shell
completion.

3 years agolei edit-search: support relocating lei.q.output
Eric Wong [Sat, 1 May 2021 06:21:17 +0000 (06:21 +0000)]
lei edit-search: support relocating lei.q.output

The contents of the old lei.q.output will not be removed,
but will be converted into the new one.

3 years agolei import: fix --mail-sync handling in LeiInput
Eric Wong [Sat, 1 May 2021 19:29:05 +0000 (19:29 +0000)]
lei import: fix --mail-sync handling in LeiInput

"lei inspect" also shows "mail-sync" as a field name

3 years agolei: rename ls-sync to ls-mail-sync
Eric Wong [Sat, 1 May 2021 06:21:16 +0000 (06:21 +0000)]
lei: rename ls-sync to ls-mail-sync

This allows tab-completion for "ls-search" to work with fewer
characters ("ls-s<TAB>" instead of "ls-se<TAB>"), and I expect
"ls-search" to be used more frequently than "ls-mail-sync".

This also matches the --mail-sync switch of "lei import"

3 years agolei_saved_search: fix excess indent for first lei.q entry
Eric Wong [Sat, 1 May 2021 06:21:15 +0000 (06:21 +0000)]
lei_saved_search: fix excess indent for first lei.q entry

This was harmless, but ugly and possibly confusing to
users who run "lei edit-search".

3 years agolei <q|up>: distinguish between mset and l2m counts
Eric Wong [Sat, 1 May 2021 06:21:14 +0000 (06:21 +0000)]
lei <q|up>: distinguish between mset and l2m counts

The number of messages we write to --output is usually different
than the mset count due to deduplication from combining multiple
sources.

This change makes the stderr output of "lei up --all=local" way
more useful IMHO.

3 years agoxt/lei-onion-convert: test for NNTP+IMAP onions
Eric Wong [Sat, 1 May 2021 06:21:13 +0000 (06:21 +0000)]
xt/lei-onion-convert: test for NNTP+IMAP onions

These tests require a running Tor instance (defaulting to
127.0.0.1:9050) and Internet connectivity, but otherwise
work pretty well.

3 years agonet_reader: support (imap|nntp).proxy in config file
Eric Wong [Fri, 30 Apr 2021 09:24:38 +0000 (09:24 +0000)]
net_reader: support (imap|nntp).proxy in config file

This allows us to use URL-matching config in git and specify
proxies on a per-host basis.  git 2.26+ users may use wildcards
to enable Tor (on 127.0.0.1:9050) for all NNTP and IMAP .onion
domains.

My ~/.config/lei/config file has the following:

[imap "imap://*.onion"]
proxy = socks5h://127.0.0.1:9050
[nntp "nntp://*.onion"]
proxy = socks5h://127.0.0.1:9050

3 years agonet_reader: Net::NNTP --proxy=socks5h:// support
Eric Wong [Fri, 30 Apr 2021 09:24:37 +0000 (09:24 +0000)]
net_reader: Net::NNTP --proxy=socks5h:// support

Since Net::NNTP doesn't support Socket or RawSocket
options/accessors like Mail::IMAPClient does; we must perform
localized @ISA manipulation and massage Net::NNTP into using
IO::Socket::Socks rather than IO::Socket::IP.

This is a bit fragile, but Net::Cmd and Net::NNTP rarely change;
and I keep an eye on them, anyways.

3 years agolei: IMAP .onion support via --proxy=s switch
Eric Wong [Fri, 30 Apr 2021 09:24:36 +0000 (09:24 +0000)]
lei: IMAP .onion support via --proxy=s switch

Mail::IMAPClient provides the ability to pass a pre-connected
Socket to it.  We can rely on this functionality to use
IO::Socket::Socks in place whatever socket class
Mail::IMAPClient chooses to use.

The --proxy=s is shared with curl(1), though we only support
socks5h:// at the moment.  Is there any need for SOCKS4 or SOCKS5
without name resolution?  Tor .onions require socks5h:// for
name resolution and to prevent data leakage.

3 years agonet_reader: {nn,mic}_for: use prototypes for internal subs
Eric Wong [Fri, 30 Apr 2021 09:24:35 +0000 (09:24 +0000)]
net_reader: {nn,mic}_for: use prototypes for internal subs

We don't use these subs elsewhere, so stick prototypes on them
to give them a little extra checking.

3 years agolei: ensure autoflush(1) is on STDERR
Eric Wong [Fri, 30 Apr 2021 09:24:34 +0000 (09:24 +0000)]
lei: ensure autoflush(1) is on STDERR

This fixes error reporting for oneshot tests in xt/lei-auth-failure.t

3 years agolei: kill old PIDs when dropping
Eric Wong [Fri, 30 Apr 2021 09:24:33 +0000 (09:24 +0000)]
lei: kill old PIDs when dropping

This ensures hitting Ctrl-C on a long-running "lei convert" or
similar will stop the WQ worker, even after we've closed
the WQ socketpair in the daemon.

3 years agolei_curl: improve correctness of LD_PRELOAD check
Eric Wong [Fri, 30 Apr 2021 09:24:32 +0000 (09:24 +0000)]
lei_curl: improve correctness of LD_PRELOAD check

LD_PRELOAD sent by a client can't affect lei-daemon.

3 years agolei sucks: preserve utsname.machine, add "x86" where appropriate
Eric Wong [Fri, 30 Apr 2021 09:24:31 +0000 (09:24 +0000)]
lei sucks: preserve utsname.machine, add "x86" where appropriate

It's helpful for us to distinguish x86 kernels from x86_64
kernels when using an x86 userspace.  OSes are dropping i386
support and only support i486 and newer, so "x86" is a more
appropriate description for that platform than "i386".

3 years agolei_store: fix locking w.r.t epoch creation
Eric Wong [Thu, 29 Apr 2021 19:49:57 +0000 (19:49 +0000)]
lei_store: fix locking w.r.t epoch creation

Prior to this change, it was possible for oneshot lei processes
to race on epoch creation/rollover.  lei-daemon normally
prevents the problem by funnelling all writes to a single
socket, but oneshot lei has no such protection.

3 years agolei import: support shell completion of known folders
Eric Wong [Thu, 29 Apr 2021 09:46:20 +0000 (09:46 +0000)]
lei import: support shell completion of known folders

This also fixes completion of "lei up" for IMAP folders.

3 years agolei import: support UIDVALIDITY in IMAP URL
Eric Wong [Thu, 29 Apr 2021 09:46:19 +0000 (09:46 +0000)]
lei import: support UIDVALIDITY in IMAP URL

Specifying a UIDVALIDITY value allows the user to enforce
a strict match and force failure.  This necessitated changes
to NetReader to allow die() and make error reporting more
suitable for CLI usage rather than daemonized usage of -watch.

3 years agolei import: avoid IMAPTracker, use LeiMailSync more
Eric Wong [Thu, 29 Apr 2021 09:46:18 +0000 (09:46 +0000)]
lei import: avoid IMAPTracker, use LeiMailSync more

IMAPTracker has a UNIQUE constraint on the `url' column,
which may cause compatibility and/or rollback problems
in attempting to deal with UIDVALIDITY changes.

Having multiple sources of truth leads to confusion and bugs,
so relying on LeiMailSync exclusively ought to simplify things.

Furthermore, since LeiMailSync is only written to by LeiStore,
it is safer in that it won't mark a UID or article as imported
until git-fast-import has seen it, and the SQLite commit always
happens after "done\n" is sent to fast-import.

This mostly reverts recent commits to IMAPTracker to support
lei, those are:

1) commit 7632d8f7590daf70c65d4270e750c36552fa9389
   ("net_reader: restart on first UID when UIDVALIDITY changes")
2) commit 311a5d37ad275cd75b1e64d87827c4d13fe4bfab
   ("imap_tracker: prepare for use with lei").

This means public-inbox-watch will not change between 1.6 and
1.7: -watch stops synching a folder when UIDVALIDITY changes.

3 years agocontent_hash: git_sha: allow unblessed SCALAR refs
Eric Wong [Thu, 29 Apr 2021 09:46:17 +0000 (09:46 +0000)]
content_hash: git_sha: allow unblessed SCALAR refs

This will be convenient to avoid the overhead of
PublicInbox::Eml for verifying synchronization in lei.

3 years agolei: avoid close(STD{IN,OUT,ERR}) in oneshot mode
Eric Wong [Wed, 28 Apr 2021 19:37:29 +0000 (19:37 +0000)]
lei: avoid close(STD{IN,OUT,ERR}) in oneshot mode

This seems to fix the occasional "make check-run" failures I've
been chasing.

Some parts of our code assumes we can close($lei->{1})
and similar, which causes IO::Handle::autoflush to behave
badly when STDOUT is the "select"-ed FH of the Perl process.
Since oneshot mode is (hopefully) the uncommon case, we'll
just accept the cost of extra FDs and minimize differences
between lei in oneshot vs daemon mode.

3 years agot/run: support TEST_RUN_LOG to diagnose process death
Eric Wong [Wed, 28 Apr 2021 19:37:28 +0000 (19:37 +0000)]
t/run: support TEST_RUN_LOG to diagnose process death

Knowing which process ran what before dying unexpectedly
helps with debugging.

3 years agolei (lcat|q): support --no-color and --color
Eric Wong [Wed, 28 Apr 2021 07:52:05 +0000 (07:52 +0000)]
lei (lcat|q): support --no-color and --color

This should be familiar to git users who wish to force color
when writing to pipes or disable color.

3 years agolei_view_text: translate background colors from git
Eric Wong [Wed, 28 Apr 2021 07:52:04 +0000 (07:52 +0000)]
lei_view_text: translate background colors from git

This seems to work with or without attributes.  We'll deal with
256-color terminal colors when/if somebody cares for it, but the
usual 16 ought to be more than enough.

3 years agolei_view_text: improve attachment display
Eric Wong [Wed, 28 Apr 2021 07:52:03 +0000 (07:52 +0000)]
lei_view_text: improve attachment display

Support setting a color to distinguish from user-supplied text.
We'll also put the $BLOB:$IDX identifier on a separate line and
just put the entire corresponding lei command in the form of:
"[-- lei blob $BLOB:$IDX --]" to teach users how to access it.

3 years agolei: simple WQ workers use {wq1} field
Eric Wong [Wed, 28 Apr 2021 07:52:02 +0000 (07:52 +0000)]
lei: simple WQ workers use {wq1} field

This lets us share more code and reduces cognitive overhead when
it comes to picking names (because {lsss} was ridiculous).

We'll need to ensure the first error set in lei is the actual
error we exit with, otherwise things can get confusing and
errors may get lost.

3 years agolei: quiet down Eml-related warnings consistently
Eric Wong [Wed, 28 Apr 2021 07:52:01 +0000 (07:52 +0000)]
lei: quiet down Eml-related warnings consistently

"lei import" is probably the only place where it users
might care about warnings.

3 years agot/run.perl: add (GNU) tail and strace support
Eric Wong [Wed, 28 Apr 2021 07:52:00 +0000 (07:52 +0000)]
t/run.perl: add (GNU) tail and strace support

This may help track down some "make check-run" failures
that don't seem to manifest under "make check".

3 years agolei-daemon: note FD count mismatch to client
Eric Wong [Wed, 28 Apr 2021 07:51:59 +0000 (07:51 +0000)]
lei-daemon: note FD count mismatch to client

This should help in some error diagnostics

3 years agolei_p2q: add _lei_wq_eof callback
Eric Wong [Wed, 28 Apr 2021 07:51:58 +0000 (07:51 +0000)]
lei_p2q: add _lei_wq_eof callback

This may help with some error diagnostics.

3 years agoview_diff: minor coding style fixes
Eric Wong [Wed, 28 Apr 2021 07:51:57 +0000 (07:51 +0000)]
view_diff: minor coding style fixes

Prefer "use v5.10", s/base/parent/, rely on "perl -w" for warnings.
We also pass a regexp to the split perlop rather than literal
SV, since split() will compile a new RE every time.

3 years agotests: restore CWD with "lei -C" and run_script
Eric Wong [Wed, 28 Apr 2021 07:51:56 +0000 (07:51 +0000)]
tests: restore CWD with "lei -C" and run_script

This simplifies test_lei users in t/*.t

3 years agot/lei-p2q: add diagnostics
Eric Wong [Wed, 28 Apr 2021 07:51:55 +0000 (07:51 +0000)]
t/lei-p2q: add diagnostics

Maybe this helps fix occasional problems in daemon mode,
but I haven't seen anything on failure, yet...

3 years agodoc: lei q: split --output and --format, note "text"
Eric Wong [Wed, 28 Apr 2021 04:51:07 +0000 (04:51 +0000)]
doc: lei q: split --output and --format, note "text"

I guess --format makes sense for stdout, after all;
and I'm enjoying "-f text" quite a bit, so far.

3 years agodoc: lei q: split =item aliases onto separate lines
Eric Wong [Wed, 28 Apr 2021 04:51:06 +0000 (04:51 +0000)]
doc: lei q: split =item aliases onto separate lines

It makes L</--augment> look nicer without resorting to
L<--augment|/-a, --augment> and similarly verbose nastiness.

Having each option as a separate =item (with a blank line in
between each =item) seems to be the preferred style used within
Perl core documentation (I used perlrun.pod as an example),
so we'll follow Perl core style, here.

This needs to be done for other manpages, at some point...

3 years agodoc: lei: use /tmp for search results pathnames
Eric Wong [Wed, 28 Apr 2021 04:51:05 +0000 (04:51 +0000)]
doc: lei: use /tmp for search results pathnames

This drives the point home about results being volatile
and discardable.

3 years agoview: add [thread overview] anchor next to Date:
Eric Wong [Wed, 28 Apr 2021 06:55:22 +0000 (06:55 +0000)]
view: add [thread overview] anchor next to Date:

The existing Subject: anchor to #r may not be 100% obvious,
and we can't stick the phrase "[thread overview]" into the
same line as the Subject without introducing ambiguity.

Fortunately, we have the Date: header directly under it.
Adding "[thread overview]" after the Date: is unambiguous
and won't make the line too long for valid emails.

This hopefully improves navigation ever-so-slightly thanks
to comments by Son Luong Ngoc.

Reported-by: Son Luong Ngoc <sluongng@gmail.com>
Link: https://public-inbox.org/git/YHhfsqfTJ9NzRwS1@C02YX140LVDN.corpad.adbkng.com/
3 years agolei q + lcat: support --format=text output
Eric Wong [Tue, 27 Apr 2021 11:07:53 +0000 (11:07 +0000)]
lei q + lcat: support --format=text output

This is mainly for "lei lcat" where it's the default,
but I find it useful anyways compared to the JSON view.

Colors are loaded from ~/.config/lei/config, and fall back
to using diff colors from a normal git config
(e.g. ~/.gitconfig).

3 years agolei lcat: extract Message-IDs from URLs and show them
Eric Wong [Tue, 27 Apr 2021 11:07:52 +0000 (11:07 +0000)]
lei lcat: extract Message-IDs from URLs and show them

It's a wrapper around "lei q" which extracts Message-IDs
from URLs, "<$MSGID>", "id:$MSGID" and attempts to display the
local version of the message.

Its main purpose is to extract Message-IDs out of
commonly-understood URLs to save users bandwidth and time
by displaying the message locally.  When reading from stdin,
it will discard things it doesn't understand, so you can just
pipe an entire "Link: $URL" line to it and it'll attempt to
pluck the Message-ID out of the URL.

3 years agolei: standardize on _lei_wq_eof callback for workers
Eric Wong [Tue, 27 Apr 2021 11:07:51 +0000 (11:07 +0000)]
lei: standardize on _lei_wq_eof callback for workers

Simplify our internals a little bit.

3 years agolei blob: support retrieving attachments via $OID:$IDX
Eric Wong [Tue, 27 Apr 2021 11:07:50 +0000 (11:07 +0000)]
lei blob: support retrieving attachments via $OID:$IDX

We'll be supporting some sort of text view for pager or
piping to an $EDITOR buffer.

3 years agolei: add "ls-sync" command for listing sync folders
Eric Wong [Tue, 27 Apr 2021 11:07:49 +0000 (11:07 +0000)]
lei: add "ls-sync" command for listing sync folders

This will be useful, later.

3 years agoURIimap: canonicalize uppercases UIDVALIDITY parameter
Eric Wong [Mon, 26 Apr 2021 11:44:25 +0000 (11:44 +0000)]
URIimap: canonicalize uppercases UIDVALIDITY parameter

And the UID one, too, as well.  This simplifies future
comparison and matching code once case is no longer
taken into account.

3 years agolei p2q: exit with failure if format-patch fails
Eric Wong [Mon, 26 Apr 2021 08:43:23 +0000 (08:43 +0000)]
lei p2q: exit with failure if format-patch fails

Merely redirecting the failure message from git to our stderr is
insufficient.

3 years agolei_input: support PublicInbox::WWW mboxrd URLs
Eric Wong [Mon, 26 Apr 2021 08:30:52 +0000 (08:30 +0000)]
lei_input: support PublicInbox::WWW mboxrd URLs

This gives "lei import", "lei tag", and similar commands
the ability to use URLs recognized by our PSGI frontend
directly.

This is more convenient than an equivalent shell pipeline
since "set -o pipefail" is not portable and errors may be
lost.

3 years agowww: missing /$INBOX/$MSGID/raw returns 404
Eric Wong [Mon, 26 Apr 2021 08:02:16 +0000 (08:02 +0000)]
www: missing /$INBOX/$MSGID/raw returns 404

Don't attempt to return HTTP 300 via Extmsg on it,
since whoever uses /raw is likely piping it to some
other command.

3 years agolei_xsearch: show --output location with match count
Eric Wong [Sat, 24 Apr 2021 23:15:26 +0000 (19:15 -0400)]
lei_xsearch: show --output location with match count

This makes "lei up --all=local" output easier-to-understand
when it's updating multiple saved searches.

3 years agolei_saved_search: avoid reentrancy in ->is_dup
Eric Wong [Sat, 24 Apr 2021 22:42:59 +0000 (22:42 +0000)]
lei_saved_search: avoid reentrancy in ->is_dup

Use a separate git process when calling xoids_for to prevent
reentrancy in ->is_dup.  Reentrancy happens since LeiToMail will
call ->is_dup when inside callbacks when writing mail.

This fixes --dedupe=mid test failures in t/lei-q-save.t

I could only reproduce this consistently on a uniprocessor VM.
"schedtool -a 0x1 -e ..." could not reproduce the problem on
2 and 4-core systems.

3 years agotest_common: don't attempt to seek on pipes and terminals
Eric Wong [Sat, 24 Apr 2021 20:09:36 +0000 (20:09 +0000)]
test_common: don't attempt to seek on pipes and terminals

This allows proper error reporting on daemon failure
when using "check-run".

3 years agoextindex: --gc: use escape pathnames for SQL LIKE properly
Eric Wong [Sat, 24 Apr 2021 10:23:30 +0000 (10:23 +0000)]
extindex: --gc: use escape pathnames for SQL LIKE properly

This allows us to handle odd inboxes w/o a newsgroup configured
if they also make the strange choice of having backslashes in
their path name.  Also, ensure we use case-sensitive LIKE, since
case-insensitive FSes are not worth supporting.

3 years agolei import: keep sync info for Maildir and IMAP folders
Eric Wong [Sat, 24 Apr 2021 09:28:46 +0000 (09:28 +0000)]
lei import: keep sync info for Maildir and IMAP folders

We aren't using it, yet, but the plan is to be able to use
this information to propagate keyword changes back to IMAP
and Maildir folders using some to-be-implemented command.

"lei inspect" is a half-baked new command to make testing this
change easier.  It will be updated to support more SQLite+Xapian
introspection duties in the future, including public-inbox
things independent of lei.

3 years agolei_mail_sync: for bidirectional keyword sync
Eric Wong [Sat, 24 Apr 2021 09:28:45 +0000 (09:28 +0000)]
lei_mail_sync: for bidirectional keyword sync

We'll be using the new class to efficiently propagate keyword
changes from lei/store back to Maildir or IMAP folders.

3 years agodoc: lei_design_notes: add a bit on WAL usage
Eric Wong [Sat, 24 Apr 2021 09:28:44 +0000 (09:28 +0000)]
doc: lei_design_notes: add a bit on WAL usage

3 years agonet_reader: imap_each: add UIDVALIDITY to URL arg
Eric Wong [Sat, 24 Apr 2021 09:28:43 +0000 (09:28 +0000)]
net_reader: imap_each: add UIDVALIDITY to URL arg

This will allow the callback to reliably maintain OID <=> UID
mappings between lei/store and the IMAP folder.