]> Sergey Matveev's repositories - public-inbox.git/log
public-inbox.git
2 years agoview: extra check to for redundant messages in HTML view
Eric Wong [Sat, 19 Jun 2021 03:22:28 +0000 (03:22 +0000)]
view: extra check to for redundant messages in HTML view

There appears to be some cases of duplicates appearing due to
-extindex.  I haven't nailed down the cause of it, yet, but
this should make things easier for readers using the PSGI
HTML interface in the meantime.

The raw mboxrd remains undeduplicated for now, and the
correct fix/workaround would be some fsck-like mode for
public-inbox-extindex.

2 years agoscripts: add syscall-list tool for development
Eric Wong [Fri, 18 Jun 2021 21:44:38 +0000 (18:44 -0300)]
scripts: add syscall-list tool for development

We'll be supporting inotify directly as we do with epoll so so
Linux users won't have to deal with XS, extra DSOs or install
Linux::Inotify2 (and common::sense) modules.

2 years agot/sigfd: add diagnostic for occasional FreeBSD failure
Eric Wong [Fri, 18 Jun 2021 19:28:13 +0000 (10:28 -0900)]
t/sigfd: add diagnostic for occasional FreeBSD failure

Not 100% sure what's going on, here...

2 years agolei/store: do not put NULL into over.num column
Eric Wong [Fri, 18 Jun 2021 19:20:31 +0000 (19:20 +0000)]
lei/store: do not put NULL into over.num column

Simplify oid2docid and filter out undefined docids in ->add_eml,
instead.  This avoids SQLite "datatype mismatch" errors in
OverIdx->add_over

Fixes: d1052f03ea85d4af ("lei/store: cull redundant docids based on blob OID")
2 years agolei/store: cull redundant docids based on blob OID
Eric Wong [Thu, 17 Jun 2021 22:00:47 +0000 (22:00 +0000)]
lei/store: cull redundant docids based on blob OID

I'm not sure how this happened (only once for me in March), but
it should not happen...  In any case, we'll operate on the
lowest numbered docid and cull redundant index entries when
lei/store is open for read-write.

This also fixes the normal lei/store removal path to clean up
the xref3 table (since it's not done automatically for
public-facing -eidx due to the multi-list nature of it).

2 years agolei_input: prefix bare Maildir paths w/ "maildir:"
Eric Wong [Thu, 17 Jun 2021 22:00:46 +0000 (22:00 +0000)]
lei_input: prefix bare Maildir paths w/ "maildir:"

This will simplify upcoming code for watches.

2 years agolei inspect: learn "num:" and "docid:" prefixes
Eric Wong [Thu, 17 Jun 2021 22:00:45 +0000 (22:00 +0000)]
lei inspect: learn "num:" and "docid:" prefixes

"num:" is useful for inspecting Inbox-ish directories, while
"docid:" can be used for any Xapian DB (not just stuff managed
by our code).

2 years agolei index+import: reject keywords from R/O IMAP
Eric Wong [Sun, 13 Jun 2021 18:12:06 +0000 (18:12 +0000)]
lei index+import: reject keywords from R/O IMAP

Since users can't set IMAP flags in read-only IMAP folders,
we won't clobber local flags when importing from IMAP.  This
also enables the local_blob fallback used for lei-index to
be used for index deduplication.

2 years agolei_input: allow keywords when importing 1 file from Maildir
Eric Wong [Sun, 13 Jun 2021 18:12:05 +0000 (18:12 +0000)]
lei_input: allow keywords when importing 1 file from Maildir

This will eventually be useful for supporting inotify watches
on Maildir.  It will also allow users to script their own FS
watchers more easily.

2 years agonet_reader: canonicalize URL args on add_url
Eric Wong [Sat, 12 Jun 2021 00:10:45 +0000 (00:10 +0000)]
net_reader: canonicalize URL args on add_url

This fixes cases when users specify an IMAP or NNTP URL
with standard port numbers explicitly.

In other words, this allows users to use
"lei ls-mail-source nntps://public-inbox.org:563/" and
"lei ls-mail-source imaps://public-inbox.org:993/"
without hitting "BUG:" errors.

2 years agolei import: use url_folder_cache for completion
Eric Wong [Sat, 12 Jun 2021 00:10:44 +0000 (00:10 +0000)]
lei import: use url_folder_cache for completion

And fix "lei index" completion while we're at it.

2 years agot/lei-import-http: quiet unnecessary diag message
Eric Wong [Sat, 12 Jun 2021 00:10:43 +0000 (00:10 +0000)]
t/lei-import-http: quiet unnecessary diag message

Leftover while writing the test.

2 years agolei ls-mail-source: write through to URL folder cache
Eric Wong [Sat, 12 Jun 2021 00:10:42 +0000 (00:10 +0000)]
lei ls-mail-source: write through to URL folder cache

We'll be able to use this for shell completion for
lei import, lcat, tag, etc..

This also adds --url support for scripting purposes.

2 years agolei: stop pager early on exit
Eric Wong [Sat, 12 Jun 2021 00:10:41 +0000 (00:10 +0000)]
lei: stop pager early on exit

This is necessary when using "ls-mail-source" on an unreachable
IMAP server.

2 years agolei ls-mail-source: list IMAP folders and NNTP groups
Eric Wong [Fri, 11 Jun 2021 09:42:40 +0000 (09:42 +0000)]
lei ls-mail-source: list IMAP folders and NNTP groups

While other tools can provide the same functionality, having
integration with git-credential is convenient, here.  Caching
and completion will be implemented separately.

2 years agolei tag: less confusing warning about unimported messages
Eric Wong [Wed, 9 Jun 2021 23:27:50 +0000 (20:27 -0300)]
lei tag: less confusing warning about unimported messages

"unimported" is more meaningful than "missing", here.  And
instead of having every worker spew about unimported messages,
we'll accumulate and only print one warning line.  This
necessitated alterating ->DESTROY behavior and persisting
the client socket within the $lei object itself, not just
the PktOp consumer object.

2 years agolei import: support --new-only for IMAP
Eric Wong [Wed, 9 Jun 2021 22:39:24 +0000 (22:39 +0000)]
lei import: support --new-only for IMAP

Taking ~40s to synchronize a ~75K message IMAP folder is
still a lot of time, so support an option to only touch
new messages.

This is similar to "offlineimap -q" (quick) or "mbsync --new"
switches, but lei already accepts "-q" as a shortcut for
--quiet.  "--new" could work, but "--new-only" might be more
descriptive (or "--only-new"?), since the default fetches
also fetches new messages.

v2: warn for non-IMAP sources, I'm not sure it's worth it for
    Maildir or other sources, yet.  It will also make sense
    for MH and JMAP once we support them.

2 years agolei prune-mail-sync: new command to prune invalid sync data
Eric Wong [Wed, 9 Jun 2021 07:47:51 +0000 (07:47 +0000)]
lei prune-mail-sync: new command to prune invalid sync data

This will be invoked automatically by "lei import" eventually,
but it may make sense to expose as a separate command.

2 years agolei_mail_sync: hoist out --all handling from export-kw
Eric Wong [Wed, 9 Jun 2021 07:47:50 +0000 (07:47 +0000)]
lei_mail_sync: hoist out --all handling from export-kw

We'll be reusing it in other commands, too.

2 years agolei tag: parallelize Maildir access
Eric Wong [Wed, 9 Jun 2021 07:47:49 +0000 (07:47 +0000)]
lei tag: parallelize Maildir access

Since Maildir isn't guaranteed to have any sort of order, we
can parallelize inputs, here.  On a 4-core system, this reduced
one of my tag invocations from 5.5 to 1.4s.

2 years agomdir_reader: maildir_each_file: pass flags, skip Trash
Eric Wong [Wed, 9 Jun 2021 07:47:48 +0000 (07:47 +0000)]
mdir_reader: maildir_each_file: pass flags, skip Trash

This is a slight behavior change for "lei q": Trashed
(but not-yet-expunged) messages no longer get unlinked
when --output is used without --augment.

2 years agoinbox_writable: fix import_maildir
Eric Wong [Wed, 9 Jun 2021 07:47:47 +0000 (07:47 +0000)]
inbox_writable: fix import_maildir

I'm not sure if anybody uses this, but it exists.  It'll likely
be dropped in the future.

Fixes: fa3f0cbcd1af5008 ("use MdirReader in -watch and InboxWritable")
2 years agolei/store: do eidx_init before creating R/W lms dbh
Eric Wong [Wed, 9 Jun 2021 10:03:05 +0000 (10:03 +0000)]
lei/store: do eidx_init before creating R/W lms dbh

Sharing lms->{dbh} with eidx shards appears to be the cause of
the "Issuing rollback() due to DESTROY without explicit
disconnect() of DBD::SQLite::db handle" messages I've been
seeing from "lei up".

2 years agolei edit-search: fix and add a (weak) test
Eric Wong [Wed, 9 Jun 2021 00:11:11 +0000 (00:11 +0000)]
lei edit-search: fix and add a (weak) test

This broke recently and lacked an automated test, so rely on
EDITOR=cat to ensure we have some coverage.

Fixes: d2670108f71b1eff ("pkt_op: make pkt_do an OO method")
2 years agolei pmdir: fix nproc for <= 4 CPUs
Eric Wong [Tue, 8 Jun 2021 23:56:13 +0000 (23:56 +0000)]
lei pmdir: fix nproc for <= 4 CPUs

I forgot my FreeBSD VM has 8 cores, actually, and tweaked the
nproc detection on that machine before finalizing commit
10b523eb017162240b1ac3647f8dcbbf2be348a7
("lei import: speed up repeated Maildir imports")

Fixes: 10b523eb01716224 ("lei import: speed up repeated Maildir imports")
2 years agolei import: speed up repeated Maildir imports
Eric Wong [Tue, 8 Jun 2021 09:50:21 +0000 (09:50 +0000)]
lei import: speed up repeated Maildir imports

On a 4-core CPU, this speeds up "lei import" on a largish
Maildir inbox with 75K messages from ~8 minutes down to ~40s.

Parallelizing alone did not bring any improvement and may
even hurt performance slightly, depending on CPU availability.
However, creating the index on the "fid" and "name" columns in
blob2name yields us the same speedup we got.

Parallelizing IMAP makes more sense due to the fact most IMAP
stores are non-local and subject to network latency.

Followup-to: bdecd7ed8e0dcf0b45491b947cd737ba8cfe38a3 ("lei import: speed up kw updates for old IMAP messages")
2 years agolei: generalize auxiliary WQ handling
Eric Wong [Tue, 8 Jun 2021 09:50:20 +0000 (09:50 +0000)]
lei: generalize auxiliary WQ handling

op_wait_event is now more lei-specific since we no longer have
to care about oneshot and use a synchronous loop.

{ikw} (import-keywords) started a trend, but LeiPmdir (parallel
Maildir) is an upcoming WQ class that will follow this idea.

Eventually, {l2m} usage may be updated to follow this, too.

2 years agolei: safety fix for multiple WQ classes
Eric Wong [Tue, 8 Jun 2021 09:50:19 +0000 (09:50 +0000)]
lei: safety fix for multiple WQ classes

For commands utilizing multiple workers, this simple change
generalizes the persistence mechanism and and prevents
lei->dclose from causing script/lei to exit if there are
still in-flight workers.

This ougth to prevent read-after-write consistency problems that
occasionally manifest in scripts (e.g. test cases) but usually
go unnoticed in normal use.

2 years agolei/store: checkpoint commits mail_sync.sqlite3
Eric Wong [Mon, 7 Jun 2021 19:06:30 +0000 (19:06 +0000)]
lei/store: checkpoint commits mail_sync.sqlite3

We mainly rely on ->done with lei/store, but moving to
->checkpoint probably makes sense.  Note: over, msgmap, and
mail_sync all have slightly different transacation behavior;
perhaps they can be unified in the future.

2 years agolei: don't drop WQ workers on normal exit
Eric Wong [Sat, 5 Jun 2021 21:06:06 +0000 (21:06 +0000)]
lei: don't drop WQ workers on normal exit

This is dangerous and causes race conditions on commands
which utilize multiple workqueues.

2 years agoINSTALL: note about lei metadata storage
Eric Wong [Sat, 5 Jun 2021 21:04:50 +0000 (21:04 +0000)]
INSTALL: note about lei metadata storage

Since lei is for personal mailboxes, I don't think lei needs to
keep keyword and label changes in history.  And fix a minor
wording problem ("or" => "nor") while we're at it.

2 years agopkt_op: make pkt_do an OO method
Eric Wong [Thu, 3 Jun 2021 09:52:06 +0000 (09:52 +0000)]
pkt_op: make pkt_do an OO method

This will make it easier to use for internal use such as
managing Maildir and IMAP IDLE watches.

2 years agopkt_op: remove blocking I/O support
Eric Wong [Thu, 3 Jun 2021 09:01:24 +0000 (09:01 +0000)]
pkt_op: remove blocking I/O support

Since lei-daemon is guaranteed to be running, there's no
need to keep blocking I/O support around (and we can
get it back via git if we need it).

Followup-to: 1d6e1f9a6a66a42d ("lei: require Socket::MsgHdr or Inline::C, drop oneshot")
2 years agolei import: speed up kw updates for old IMAP messages
Eric Wong [Thu, 3 Jun 2021 01:05:20 +0000 (01:05 +0000)]
lei import: speed up kw updates for old IMAP messages

On a 4-core CPU, this speeds up "lei import" on a largish IMAP
inbox with 75K messages from ~21 minutes down to 40s.

Parallelizing with the new LeiImportKw WQ worker class gives a
near-linear speedup and brought the runtime down to ~5:40.

The new idx_fid_uid index on the "fid" and "uid" columns of
blob2num in mail_sync.sqlite3 brought us the final speedup.

An additional index on over.sqlite3#xref3(oidbin) did not help,
since idx_nntp already exists and speeds up the new ->oidbin_exists
internal API.

I initially experimented with a separate "lei import-kw" command
but decided against it since it's useless outside of IMAP+JMAP
and would require extra cognitive overhead for both users and
hackers.  So LeiImportKw is just a WQ worker used by "lei import"
and not its own user-visible command.

v2: fix ikw_done_wait arg handling (ugh, confusing API :x)

2 years agolei export-kw: do not write directly to mail_sync.sqlite3
Eric Wong [Wed, 2 Jun 2021 10:03:25 +0000 (10:03 +0000)]
lei export-kw: do not write directly to mail_sync.sqlite3

Only the lei/store process should be writing to files/DBs
in lei/store.

2 years agolei: remove "forget" (old name for "rm")
Eric Wong [Tue, 1 Jun 2021 19:20:16 +0000 (19:20 +0000)]
lei: remove "forget" (old name for "rm")

"rm" is probably the better name for it, since it matches
"public-inbox-learn rm"

2 years agolei_mail_sync: more debug info for uncommitted txn
Eric Wong [Tue, 1 Jun 2021 19:14:28 +0000 (19:14 +0000)]
lei_mail_sync: more debug info for uncommitted txn

I'm not actually sure if I hit an uncommitted transaction just
now, it doesn't seem like it.

2 years agolei import: reduce writes to lei/store on IMAP sync
Eric Wong [Mon, 31 May 2021 10:20:06 +0000 (10:20 +0000)]
lei import: reduce writes to lei/store on IMAP sync

We don't need to write VMD changes to lei/store if local
keywords are unchanged.

2 years agolei import: import IMAP flag changes from old messages
Eric Wong [Sun, 30 May 2021 11:45:44 +0000 (11:45 +0000)]
lei import: import IMAP flag changes from old messages

This makes "lei import" behavior with IMAP folders more
consistent with that with Maildir.

Opening IMAP folders read-write with "SELECT" (instead of
read-only with "EXAMINE") was necessary, since it lets an IMAP
server communicate to us as to whether or not it's worth
refetching IMAP flags of previously imported messages.

Fetching UID+FLAGS only is one of the fastest IMAP operations
with dovecot, our -imapd and presumably other common IMAP servers.
It is issued by common MUAs such as mutt after every SELECT.

Users may now rely on "lei import" exclusively to merge mail and
keywords into lei/store, and "lei export-kw" to propagate
keyword changes back to IMAP servers.

A sticks-and-stones workflow for personal mailboxes is currently:

lei import imaps://$MY_PERSONAL_INBOX
lei q --mua=$MUA -o /tmp/results SEARCH TERMS...
# do stuff from within $MUA to /tmp/results
lei import /tmp/results # read keyword changes from MUA
lei export-kw imaps://$MY_PERSONAL_INBOX
# repeat when new stuff shows up in personal inbox

The next goal is to automate repeated imports + export-kw
commands with with inotify and IMAP IDLE.

2 years agolei: support implicit stdin by default
Eric Wong [Sun, 30 May 2021 06:33:58 +0000 (06:33 +0000)]
lei: support implicit stdin by default

This adds implicit stdin suppport for p2q and lcat,
while rm and rediff no longer need explicit support
for it.

2 years agolei lcat: support maildir: paths, too
Eric Wong [Sun, 30 May 2021 06:33:57 +0000 (06:33 +0000)]
lei lcat: support maildir: paths, too

This could be helpful in case when a Maildir is on a slow
or unmounted filesystem and lei/store is on fast storage.

2 years agolei lcat: allow IMAP folder URLs w/o UIDVALIDITY
Eric Wong [Sun, 30 May 2021 06:33:56 +0000 (06:33 +0000)]
lei lcat: allow IMAP folder URLs w/o UIDVALIDITY

Requiring UIDVALIDITY on the command-line is of course
unreasonable.

2 years agolei lcat+inspect: start wiring up completion
Eric Wong [Sun, 30 May 2021 06:33:55 +0000 (06:33 +0000)]
lei lcat+inspect: start wiring up completion

Colons and other delimiters still cause problems for our bash
completion, but some completion is better than no completion.

2 years agolei q: --sort and --save|v2 are incompatible
Eric Wong [Sat, 29 May 2021 20:20:39 +0000 (20:20 +0000)]
lei q: --sort and --save|v2 are incompatible

Saved searches rely on (reverse) docid ordering for efficient
incremental results, and sorting any other way prevents that.

Update comment description in LeiQuery while we're at it:
"ls-query" and "rm-query" are "ls-search" and "forget-search",
respectively, and "mv-query" is implicit with "edit-search"

2 years agolei import|lcat: improve+fix single message IMAP support
Eric Wong [Sat, 29 May 2021 20:20:38 +0000 (20:20 +0000)]
lei import|lcat: improve+fix single message IMAP support

lcat can now dump the memoized contents of entire IMAP folders,
not just a single UID.  It's now parallelized and pipelined for
multiple lei2mail workers.

Furthemore, various forms of JSON output work consistently
with blob-only output, now.

While working on this, I noticed NetReader was passing UID URLs
to imap_each callbacks, which was causing mail_sync.sqlite3 to
store UIDs in `folders' and clearly wrong so it's now fixed.

2 years agoTODO: add pipelining note
Eric Wong [Sat, 29 May 2021 20:20:37 +0000 (20:20 +0000)]
TODO: add pipelining note

Network latency is painful to deal with.

2 years agolei_to_mail: use abs_path for Maildir in mail_sync.sqlite3
Eric Wong [Sat, 29 May 2021 00:57:19 +0000 (00:57 +0000)]
lei_to_mail: use abs_path for Maildir in mail_sync.sqlite3

lei->rel2abs doesn't resolve symlinks, which could cause
synchronization problems with export-kw or other commands.

2 years agolei q|up: support v2:/path/to/inboxdir destination
Eric Wong [Fri, 28 May 2021 22:37:21 +0000 (22:37 +0000)]
lei q|up: support v2:/path/to/inboxdir destination

This allows "lei-managed pseudo mailing lists" as described
by Konstantin.

Alternates use is optional and can be enables via --shared.

This doesn't manage or edit ~/.public-inbox/config; presumably
there'll need to be some tweaking of search parameters before
finalizing and making the inbox publicly accessible via HTTP/NNTP.

Link: https://public-inbox.org/meta/20210426164454.5zd5kgugfhfwfkpo@nitro.local/T/
2 years agolei: retry_reopen on read-only Xapian access
Eric Wong [Fri, 28 May 2021 19:47:23 +0000 (19:47 +0000)]
lei: retry_reopen on read-only Xapian access

Xapian DBs may be modified by a parallel process while we're
reading it, and Xapian's MVCC model places the burden on readers
to retry operations.

We'll also have retry_reopen croak instead of die on errors,
which ought to help us track down some "Document not found"
errors I've occasionally seen when using "lei <q|up>".

2 years agoscript/lei: drop leftover message about fallback
Eric Wong [Fri, 28 May 2021 09:45:21 +0000 (09:45 +0000)]
script/lei: drop leftover message about fallback

Non-daemon lei isn't implemented, anymore.

2 years agolei: restore working directory in more places
Eric Wong [Fri, 28 May 2021 09:45:20 +0000 (09:45 +0000)]
lei: restore working directory in more places

Every tick of the event loop can change the working directory,
so we need to restore it for every client if they operate
in different directories.

This would be easier if we had openat(2) and friends in Perl;
but Inline::C is practically required for lei, now.

2 years agot/lei-*: better diagnostics for occasional failures
Eric Wong [Fri, 28 May 2021 09:45:19 +0000 (09:45 +0000)]
t/lei-*: better diagnostics for occasional failures

Some of these have been failing occasionally, not sure
how, yet...

2 years agolei: handle a single IMAP message in most places
Eric Wong [Fri, 28 May 2021 00:07:56 +0000 (00:07 +0000)]
lei: handle a single IMAP message in most places

"lei import" can now import a single IMAP message via
<imaps://example.com/MAILBOX/;UID=$UID>

Likewise, "lei inspect" can show the blob information for UID
URLs and "lei lcat" can display the blob without network access
if imported.

"lei lcat" also gets rid of some unused code and supports
"blob:$OIDHEX" syntax as described in the comments (and used by
our "text" output format).

v2: enforce UID in URL, fail without
v3: fix error reporting (s/fail/child_error/)

2 years agolei_mail_sync: debug code for uncommitted txn
Eric Wong [Fri, 28 May 2021 00:07:54 +0000 (00:07 +0000)]
lei_mail_sync: debug code for uncommitted txn

I'm not 100% sure why, but "lei up" seems to cause uncommitted
transaction errors.  LeiToMail calls sto->set_sync_info, but
LeiXSearch should call sto->done and lms_commit, so I'm not
sure where the uncommited transaction is coming from...

2 years agolei: add TODO item for FUSE mount
Eric Wong [Fri, 28 May 2021 00:07:57 +0000 (00:07 +0000)]
lei: add TODO item for FUSE mount

It seems possible and natural to allow browsing lei/store as
a Maildir (as well as read-write JMAP/IMAP store).

2 years agolei: mark reorder-and-rewrite-local-history as a TODO item
Eric Wong [Fri, 28 May 2021 00:07:55 +0000 (00:07 +0000)]
lei: mark reorder-and-rewrite-local-history as a TODO item

This is low priority, for now.

2 years agoviewdiff: escape '{' and '}' for regexp
Eric Wong [Fri, 28 May 2021 00:07:53 +0000 (00:07 +0000)]
viewdiff: escape '{' and '}' for regexp

Perl 5 doesn't warn on this, yet, but it warns on unescaped
'(' and ')' nowadays, so it's conceivable Perl could start
warning on this in the future.  So future-proof our code and
reduce reader confusion.

2 years agoviewdiff: make $UNSAFE a variable
Eric Wong [Fri, 28 May 2021 00:07:52 +0000 (00:07 +0000)]
viewdiff: make $UNSAFE a variable

There's no sense in using a constant here since it
gets copied into the uri_escape_utf8 function anyways.
Furthermore, inlined constants still leave behind a
subroutine and subs cost several KB of memory.

Finally, add a comment as to why it's different than the default
escape, since I just spent a minute wondering that.

2 years agolei rm: new command to remove messages from index
Eric Wong [Wed, 26 May 2021 23:50:07 +0000 (23:50 +0000)]
lei rm: new command to remove messages from index

This is similar to "public-inbox-learn rm", but it's
possible to point an entire Maildir/IMAP/mbox*/newsgroup
at it.

2 years agolei: require Socket::MsgHdr or Inline::C, drop oneshot
Eric Wong [Wed, 26 May 2021 18:08:57 +0000 (18:08 +0000)]
lei: require Socket::MsgHdr or Inline::C, drop oneshot

The cost of supporting separate code paths between oneshot and
daemon isn't worth the trouble; especially if there are more
users to support.  The test suite time nearly doubles with
oneshot, so that's hurting developer productivity.

FD passing is currently required to work efficiently with
remote HTTP(S) queries which return large messages, as seen in
commit 708b182a57373172f5523f3dc297659d58e03b58
("ipc: wq: handle >MAX_ARG_STRLEN && <EMSGSIZE case").

Additionally, upcoming support for IMAP IDLE and inotify-based
monitoring of Maildirs cannot work properly without a background
daemon.

2 years agoipc: wq: handle >MAX_ARG_STRLEN && <EMSGSIZE case
Eric Wong [Tue, 25 May 2021 22:20:01 +0000 (22:20 +0000)]
ipc: wq: handle >MAX_ARG_STRLEN && <EMSGSIZE case

WQWorkers are limited roughly to MAX_ARG_STRLEN (the kernel
limit of argv + environ) to avoid excessive memory growth.
Occasionally, we need to send larger messages via workqueues
that are too small to hit EMSGSIZE on the sender.

This fixes "lei q" when using HTTP(S) externals, since that
code path sends large Eml objects from lei_xsearch workers
directly to lei2mail WQ workers.

2 years agoipc: avoid potential stack-not-refcounted bug
Eric Wong [Tue, 25 May 2021 22:20:00 +0000 (22:20 +0000)]
ipc: avoid potential stack-not-refcounted bug

This fixes a potential problem with Carp::longmess
firing somewhere deeper in the stack.  This is not a known
problem at this time, but something I noticed while chasing
something else.

2 years agolei forget-mail-sync: new command to drop sync information
Eric Wong [Tue, 25 May 2021 11:01:36 +0000 (11:01 +0000)]
lei forget-mail-sync: new command to drop sync information

Sometimes a user stops caring to sync an IMAP or Maildir
folder, or wants to force a resync.  Let them run this
command to have lei forget all the sync information about
the mail folder.

This won't delete any stored messages in git, but will
leave "lei index" users with dangling references.

2 years agolei_mail_sync: args2folder: common folder lookup sub
Eric Wong [Tue, 25 May 2021 11:01:35 +0000 (11:01 +0000)]
lei_mail_sync: args2folder: common folder lookup sub

This lets us have a more consistent UX for mapping
easily-typed command-line arguments to canonical
folder locations.

2 years agolei export-kw: use lei->abs_path instead of rel2abs
Eric Wong [Tue, 25 May 2021 11:01:34 +0000 (11:01 +0000)]
lei export-kw: use lei->abs_path instead of rel2abs

This is to match LeiInput behavior when mail-sync is
enabled, since rel2abs won't resolve symlinks.

2 years agolei export-kw: fix case-insensitivity typo for IMAP URLs
Eric Wong [Mon, 24 May 2021 22:48:55 +0000 (22:48 +0000)]
lei export-kw: fix case-insensitivity typo for IMAP URLs

Fixes: a9bfba8eb31dbb4c ("lei inspect: use LeiMailSync->match_imap_url")
2 years agolei_mail_sync: reject IMAP URLs w/o UIDVALIDITY
Eric Wong [Sun, 23 May 2021 21:36:51 +0000 (21:36 +0000)]
lei_mail_sync: reject IMAP URLs w/o UIDVALIDITY

It's inappropriate to store sync information without
UIDVALIDITY, so add an assertion to prevent it.

2 years agolei inspect: use LeiMailSync->match_imap_url
Eric Wong [Sun, 23 May 2021 21:36:50 +0000 (21:36 +0000)]
lei inspect: use LeiMailSync->match_imap_url

Move match_imap_url into LeiMailSync so it can be used in more
places, such as "lei inspect".  Upcoming commands such as
"lei forget-mail-sync" and {add,forget,pause,resume}-watch will
also support relaxed IMAP matching rules since there's
no reasonable way to expect users use ";UIDVALIDITY=" on the
command-line.

2 years agolei <q|up>: set \Recent on non-empty mbox and Maildir
Eric Wong [Sun, 23 May 2021 08:01:16 +0000 (08:01 +0000)]
lei <q|up>: set \Recent on non-empty mbox and Maildir

Despite JMAP not supporting the equivalent of the IMAP \Recent
flag, it is useful for "lei q --augment", and "lei up" users to
be able to distinguish new results from old-but-unread messages
in an mbox or Maildir.

For mbox family messages, we'll drop the "O" status flag when
appending to mboxes, and we'll write to the "new" subdirectory
of Maildirs.

Behavior when writing to initially empty Maildirs and mboxes
remains unchanged since there's no need to distinguish between
new and old results in the initial case.  Having users wait
for a rename(2) storm or complete mbox rewrite hurts UX.

With IMAP mailboxes, \Recent is already enforced by the IMAP
server and IMAP clients have no way of changing it(*)

(*) mutt uses the "Old" IMAP flag which isn't part of RFC 3501,
    other MUAs may do similar things.

2 years agolei export-kw: relax IMAP URL matching
Eric Wong [Sun, 23 May 2021 01:38:28 +0000 (01:38 +0000)]
lei export-kw: relax IMAP URL matching

It's unreasonable to expect UIDVALIDITY= to be specified in
command-line arguments.  We'll also check for cases without
"$USER@" or ";AUTH=", since we accept those forms on the
command-line.

2 years agolei export-kw: support exporting keywords to IMAP
Eric Wong [Sun, 23 May 2021 01:38:27 +0000 (01:38 +0000)]
lei export-kw: support exporting keywords to IMAP

We support writing to IMAP stores in other places (just like
Maildir), and it's actually less complex for us to write to
IMAP.  Neither usability nor performance is ideal, but usability
will be addressed in the next commit to relax CLI argument
checking.

Performance is poor due to the synchronous Mail::IMAPClient
API and will need to be addressed with pipelining sometime
further in the future.

2 years agonet_reader|net_writer: pass URI refs deeper into callbacks
Eric Wong [Sun, 23 May 2021 01:38:26 +0000 (01:38 +0000)]
net_reader|net_writer: pass URI refs deeper into callbacks

This will give us more flexibility in the future w.r.t.
dealing with UIDVALIDITY and AUTH= info with IMAP.  The LoC
reduction is welcome, too.

2 years agolei import: store IMAP user+auth in mail_sync folder URI
Eric Wong [Fri, 21 May 2021 10:28:32 +0000 (10:28 +0000)]
lei import: store IMAP user+auth in mail_sync folder URI

Just having UIDVALIDITY in the URI isn't enough, since a single
lei user may have multiple IMAP logins on the same server.

This leads to compatibility problems and forces a reimport for
the few users already using this lei functionality, but it's not
stable nor released, yet.

2 years agouri_imap: support uid/auth/user as full accessors
Eric Wong [Fri, 21 May 2021 10:28:31 +0000 (10:28 +0000)]
uri_imap: support uid/auth/user as full accessors

We will need this for mail synchronization

2 years agolei export-kw: new command to export keywords to Maildirs
Eric Wong [Fri, 21 May 2021 10:28:30 +0000 (10:28 +0000)]
lei export-kw: new command to export keywords to Maildirs

IMAP will eventually be supported.

2 years agolei index: support command-line options
Eric Wong [Fri, 21 May 2021 10:28:29 +0000 (10:28 +0000)]
lei index: support command-line options

This mostly takes after "lei import", and at least --quiet needs
to be supported.

2 years agolei_input: fix canonicalization of Maildirs for sync
Eric Wong [Fri, 21 May 2021 10:28:28 +0000 (10:28 +0000)]
lei_input: fix canonicalization of Maildirs for sync

This is needed for the upcoming "lei export-kw"

2 years agolei tag: support tagging index-only messages
Eric Wong [Fri, 21 May 2021 10:28:27 +0000 (10:28 +0000)]
lei tag: support tagging index-only messages

This will make some of our tests faster and allow users to try
more features of lei without high storage requirements.

2 years agolei: drop EOFpipe in favor of PktOp
Eric Wong [Fri, 21 May 2021 10:28:26 +0000 (10:28 +0000)]
lei: drop EOFpipe in favor of PktOp

lei already uses PktOp and SOCK_SEQPACKET throughout; whereas
EOFpipe had one single use in lei.  Since PktOp is a strict
superset of EOFpipe functionality, we may be able to get rid of
EOFpipe entirely.

However, lei is considered a portability canary and I'm not sure
if the stable public-inbox-* code can drop EOFpipe just yet.

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"

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

3 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