]> Sergey Matveev's repositories - public-inbox.git/log
public-inbox.git
2 years agolei: normalize whitespace in remote queries
Eric Wong [Sat, 11 Sep 2021 00:19:17 +0000 (00:19 +0000)]
lei: normalize whitespace in remote queries

Having redundant "+" in URLs is ugly and can hurt cacheability
of queries.  Even with "quoted phrase searches", Xapian seems
unaffected by redundant spaces, so just normalize the ASCII
white spaces to ' ' (%20) when fed via STDIN or saved-search
config file.

Reported-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
Link: https://public-inbox.org/meta/20210910141157.6u5adehpx7wftkor@meerkat.local/
2 years agolei: pass client stderr to git-config in more places
Eric Wong [Sat, 11 Sep 2021 00:19:16 +0000 (00:19 +0000)]
lei: pass client stderr to git-config in more places

This should improve the users' chances of seeing errors in
various git config files we use.

2 years agolei: fix handling of broken lei.saved-search config files
Eric Wong [Sat, 11 Sep 2021 00:19:15 +0000 (00:19 +0000)]
lei: fix handling of broken lei.saved-search config files

lei shouldn't become unusable if a config file is invalid.
Instead, show the "git config" stderr and attempt to continue
gracefully.

Reported-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
Link: https://public-inbox.org/meta/20210910141157.6u5adehpx7wftkor@meerkat.local/
2 years agoINSTALL: depend on URI rather than URI::Escape
Eric Wong [Fri, 10 Sep 2021 13:10:04 +0000 (13:10 +0000)]
INSTALL: depend on URI rather than URI::Escape

As far as I can tell, URI::Escape has always been a part of the
`URI' package (aka "distribution" on CPAN) and not distributed
separately (unlike URI::Escape::XS).  So avoid confusing users
with `URI::Escape' and just document `URI' instead.

Along the same lines, we depend on the `Plack' package rather
than Plack::Util or Plack::Builder, after all.

2 years agolei up: only delay non-zero "# $NR written to ..."
Eric Wong [Fri, 10 Sep 2021 11:46:53 +0000 (11:46 +0000)]
lei up: only delay non-zero "# $NR written to ..."

"# 0 written to $FOLDER" messages aren't important to the
user, so we can show them in real time and allow them to
be lost in the terminal scroll.  When >0 messages are
written to a folder, we'll show them last so a user
will know which folders to open with their MUA.

2 years agodoc: lei-index manpage
Eric Wong [Fri, 10 Sep 2021 09:08:50 +0000 (09:08 +0000)]
doc: lei-index manpage

It's a pretty incomplete command, so it's important to document
its incompleteness.

2 years agolei: do not read ~/.netrc by default
Eric Wong [Fri, 10 Sep 2021 09:08:49 +0000 (09:08 +0000)]
lei: do not read ~/.netrc by default

Since ~/.netrc isn't widely used by most (if any) NNTP and IMAP
clients, we won't read it by default for lei.  AFAIK, ~/.netrc
is mainly by FTP clients (e.g. ftp(1) and lftp(1)).  wget uses
it by default for HTTP(S) (and FTP), but curl does not.

To avoid breaking stable release use cases, public-inbox-watch
continues to read ~/.netrc by default.

The --netrc switch is supported by all existing lei commands
which may use curl.

2 years agolei: split out @net_opt for curl/torsocks use
Eric Wong [Fri, 10 Sep 2021 09:08:48 +0000 (09:08 +0000)]
lei: split out @net_opt for curl/torsocks use

IMAP and NNTP connections share some curl(1) options for TLS,
IPv4/IPv6, or netrc, etc...

2 years agolei_query: fix comment about %lei2curl commands
Eric Wong [Fri, 10 Sep 2021 09:08:47 +0000 (09:08 +0000)]
lei_query: fix comment about %lei2curl commands

Just a typo.

2 years agolei add-external --mirror: quiet unlink error on ENOENT
Eric Wong [Fri, 10 Sep 2021 09:15:36 +0000 (09:15 +0000)]
lei add-external --mirror: quiet unlink error on ENOENT

If the mirror.done file doesn't exist for unlink, it's because
we already got another error, so don't confuse users by noting
an unlink error since the ENOENT is expected in the face of
other errors.

2 years agolei add-external --mirror: deduce paths for PSGI mount prefixes
Eric Wong [Fri, 10 Sep 2021 05:51:00 +0000 (05:51 +0000)]
lei add-external --mirror: deduce paths for PSGI mount prefixes

The current manifest.js.gz generation in WWW doesn't account for
PSGI mount prefixes (and grokmirror 1.x appears to work fine).

In other words, <https://yhbt.net/lore/lkml/manifest.js.gz>
currently has keys like "/lkml/git/0.git" and not
"/lore/lkml/git/0.git" where "/lore" is the PSGI mount prefix.
This works fine with the prefix accounted for in my grokmirror
(1.x) repos.conf like this:

site = https://yhbt.net/lore/
manifest = https://yhbt.net/lore/manifest.js.gz

Adding the PSGI mount prefix in manifest.js.gz is probably not
desirable since it would force the prefix into the locally
cloned path by grokmirror, and all the cloned directories
would have the remote PSGI mount prefix prepended to the
toplevel.

So, "lei add-external --mirror" needs to account for PSGI
mount prefixes by deducing the prefix based on available keys
in the manifest.js.gz hash table.

2 years agogcf2: die if pkg-config is missing
Eric Wong [Thu, 9 Sep 2021 20:45:41 +0000 (20:45 +0000)]
gcf2: die if pkg-config is missing

We can't link properly to libgit2 without pkg-config telling
us which libraries and headers to use.

2 years agot/git.t: quiet intentional git-rev-parse failure
Eric Wong [Thu, 9 Sep 2021 21:14:36 +0000 (21:14 +0000)]
t/git.t: quiet intentional git-rev-parse failure

It can get confusing, especially when running non-parallel "make test"

Link: https://public-inbox.org/meta/20210909210138.ssiv5tri65mf4l4o@meerkat.local/
2 years agotest_common: print diagnostic for missing dependencies
Eric Wong [Thu, 9 Sep 2021 21:34:36 +0000 (21:34 +0000)]
test_common: print diagnostic for missing dependencies

The "#" prefix should prevent it from being too alarming if
a dependency is expected to be missing, but still useful if a
dependency is misconfigured.

2 years agolei up: print messages before disconnecting
Eric Wong [Thu, 9 Sep 2021 05:34:31 +0000 (05:34 +0000)]
lei up: print messages before disconnecting

Closing the socket for script/lei needs to be done AFTER the
final message(s) are printed.

2 years agonet_reader: support Mail::IMAPClient Ignoresizeerrors
Eric Wong [Thu, 9 Sep 2021 05:25:05 +0000 (05:25 +0000)]
net_reader: support Mail::IMAPClient Ignoresizeerrors

Some proprietary servers may do wacky things and give the
wrong size, so Mail::IMAPClient has a knob for this which
we can expose to users to workaround this.

2 years agonet_reader: improve naming of common args
Eric Wong [Thu, 9 Sep 2021 05:25:04 +0000 (05:25 +0000)]
net_reader: improve naming of common args

IMHO this makes things easier-to-follow than before.

2 years agonet_reader: combine Net::NNTP and IMAPClient args
Eric Wong [Thu, 9 Sep 2021 05:25:03 +0000 (05:25 +0000)]
net_reader: combine Net::NNTP and IMAPClient args

Since these are keyed by IMAP and NNTP URIs which can never
conflict, it simplifies our internals to keep them in one big
hash since we'll add POP3 and JMAP client support.

2 years agonet_reader: imap_opt => cfg_opt
Eric Wong [Thu, 9 Sep 2021 05:25:02 +0000 (05:25 +0000)]
net_reader: imap_opt => cfg_opt

Since this our internal IMAP options are keyed by URI section,
there's no need to have separate hashes for NNTP and IMAP
options since they URI already distinguishes them.

This will make future changes to support POP3 and JMAP and
arg caching with lei/store easier.

2 years agonet_reader: nntp_opt => cfg_opt
Eric Wong [Thu, 9 Sep 2021 05:25:01 +0000 (05:25 +0000)]
net_reader: nntp_opt => cfg_opt

Since this our internal NNTP options are keyed by URI section,
there's no need to have separate hashes for NNTP and IMAP
options since they URI already distinguishes them.

This will make future changes to support POP3 and JMAP and
arg caching with lei/store easier.

2 years agonet_reader: preserve memoized IMAPClient arg for SOCKS
Eric Wong [Thu, 9 Sep 2021 05:25:00 +0000 (05:25 +0000)]
net_reader: preserve memoized IMAPClient arg for SOCKS

Multiple invocations of mic_new may happen in long-lived
processes, so do not let mic_new make irreversible changes
to the cached args when using a SOCKS proxy.

2 years agonet_reader: set IMAPClient Keepalive flag late
Eric Wong [Thu, 9 Sep 2021 05:24:59 +0000 (05:24 +0000)]
net_reader: set IMAPClient Keepalive flag late

Since we always enable SO_KEEPALIVE unconditionally, having it
in {mic_arg} leads to unnecessary IPC overhead and memory use.

2 years agonet_reader: do not set "SSL" fields for non-TLS
Eric Wong [Thu, 9 Sep 2021 05:24:58 +0000 (05:24 +0000)]
net_reader: do not set "SSL" fields for non-TLS

This will save a little bit of memory and IPC I/O for users
connecting to localhost and the majority of Tor .onions.

2 years agolei prune-mail-sync: ignore missing locations
Eric Wong [Wed, 8 Sep 2021 19:04:37 +0000 (19:04 +0000)]
lei prune-mail-sync: ignore missing locations

"lei prune-mail-sync --all" shouldn't abort if a location
isn't available, and maybe it should prune harder...

2 years agolei_input: provide hint for bare "L:" and "kw:"
Eric Wong [Wed, 8 Sep 2021 19:03:59 +0000 (19:03 +0000)]
lei_input: provide hint for bare "L:" and "kw:"

I just made this mistake running "lei import" myself, so
I figure giving a hint makes sense, here.

2 years agolei-rm: add man page, support LeiInput args
Eric Wong [Wed, 8 Sep 2021 18:48:20 +0000 (18:48 +0000)]
lei-rm: add man page, support LeiInput args

-F/--in-format and --lock=TYPE(S) are easily supported by
all classes using LeiInput.

2 years agonews_www: favor ->ALL URL when using ->ALL
Eric Wong [Tue, 7 Sep 2021 22:02:03 +0000 (22:02 +0000)]
news_www: favor ->ALL URL when using ->ALL

This allows us to link to threads spread across multiple inboxes.

Reported-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
Link: https://public-inbox.org/meta/20210907140954.4rlh6pn5fz4ljkxp@meerkat.local/
2 years agodoc: acknowledge the MMDF mailbox format
Eric Wong [Tue, 7 Sep 2021 22:42:08 +0000 (22:42 +0000)]
doc: acknowledge the MMDF mailbox format

While I don't currently see a point in supporting MMDF, we'll
still acknowledge it since mutt actually supports it.  Expand a
bit on MH while we're at it, since MH seems at least relevant.

2 years agolei q|up: fix write counter for v2
Eric Wong [Tue, 7 Sep 2021 22:41:41 +0000 (22:41 +0000)]
lei q|up: fix write counter for v2

It's a bit confusing to see "0 written to ..." when we actually
wrote something.

2 years agonews_www: avoid uninitialized variables
Eric Wong [Tue, 7 Sep 2021 14:05:48 +0000 (14:05 +0000)]
news_www: avoid uninitialized variables

PATH_INFO may not have enough slashes for newsgroup name in the
URL at all, so ensure we don't try to further process requests
which have no chance of having a newsgroup name.

2 years agodoc: lei-*.pod: update to Tor v3 .onion address
Eric Wong [Tue, 7 Sep 2021 11:32:11 +0000 (11:32 +0000)]
doc: lei-*.pod: update to Tor v3 .onion address

We missed a few when new documentation came in, and there's no
going back to v2 onions.

Followup-to: 0b15dfc58ceaecdc ("treewide: update to v3 Tor onions")
2 years agolei up: support --all for IMAP folders
Eric Wong [Tue, 7 Sep 2021 11:32:10 +0000 (11:32 +0000)]
lei up: support --all for IMAP folders

Since "lei up" is expected to be a heavily-used command,
better support for IMAP seems like a reasonable idea.

This is inefficient since we waste an IMAP(S) TCP connection
since it dies when an auth-only LeiUp worker process dies, but
it's better than not working at all, right now.

2 years agolei: dump and clear log at exit
Eric Wong [Tue, 7 Sep 2021 11:32:09 +0000 (11:32 +0000)]
lei: dump and clear log at exit

This may be helpful for diagnosing errors in case we missed any.

2 years agoxt/net_writer_imap: test "lei up" on single IMAP output
Eric Wong [Tue, 7 Sep 2021 11:32:08 +0000 (11:32 +0000)]
xt/net_writer_imap: test "lei up" on single IMAP output

That's the minimum, at least...

2 years agolei_auth: simplify users
Eric Wong [Mon, 6 Sep 2021 12:58:03 +0000 (12:58 +0000)]
lei_auth: simplify users

There's no need to alias net_merge_all in each WQ class
which uses LeiAuth, `$obj->$sub' works even when `$sub'
is a fully-qualified subroutine name with `::' in it.
perlobj(1) documents it under "Method Call Variations".

2 years agolei_auth: remove net_merge_done1 step
Eric Wong [Mon, 6 Sep 2021 12:58:02 +0000 (12:58 +0000)]
lei_auth: remove net_merge_done1 step

It turns out this step is unnecessary, since SOCK_SEQPACKET
ordering is guaranteed and we know wq_broadcast calls will
always be handled sequentially.

2 years agolei_auth: diagram for current behavior
Eric Wong [Mon, 6 Sep 2021 12:58:01 +0000 (12:58 +0000)]
lei_auth: diagram for current behavior

Before making potentially major changes, lets clarify readers'
understanding of how LeiAuth currently works.

2 years agolei_search: xsmsg_vmd: retry_reopen properly
Eric Wong [Mon, 6 Sep 2021 07:20:12 +0000 (07:20 +0000)]
lei_search: xsmsg_vmd: retry_reopen properly

The deeper eval was preventing retry_reopen from retrying
with readers and writers working in parallel:

  FOO=imaps://example.com/INBOX.huge
  lei lcat $FOO -f mboxcl | lei tag -F mboxcl +L:bar -

Fixes: c7bcfe6cd6648ff0 ("lei: diagnostics for /Document \d+ not found/ errors")
2 years agonet_reader: don't approve/reject credentials w/o "fill"
Eric Wong [Mon, 6 Sep 2021 07:11:53 +0000 (07:11 +0000)]
net_reader: don't approve/reject credentials w/o "fill"

Credentials sourced via ~/.netrc should not be written to
git-credential.

2 years agolei_to_mail+mbox_reader: fix handling of empty/bogus emails
Eric Wong [Sat, 4 Sep 2021 21:36:58 +0000 (21:36 +0000)]
lei_to_mail+mbox_reader: fix handling of empty/bogus emails

We may be handling invalid mboxes, so just return no objects in
that case.  While "lei q" on HTTP(S) externals expects a gzipped
mboxrd, there's always a chance something else gzipped can be
sent to us.

There's also changes to lei_to_mail to better handle emails
which lack a body and/or headers (e.g. t/solve/bare.patch)

Link: https://public-inbox.org/meta/20210903151500.h72mzcpqixgtytjs@meerkat.local/
2 years agolei: fix read/write IMAP access
Eric Wong [Fri, 3 Sep 2021 08:54:27 +0000 (08:54 +0000)]
lei: fix read/write IMAP access

xt/net_writer-imap.t was completely broken in recent months and
I completely forgot this test.  net->add_url still only accepts
bare scalars (and not scalar refs), so we must set that up
properly.  Furthermore, our changes to do FLAGS-only
synchronization in lei of old messages was causing us to not
handle FLAGS properly for the test.

2 years agolei_xsearch: avoid false-positives on externals w/ L: and kw:
Eric Wong [Fri, 3 Sep 2021 08:54:26 +0000 (08:54 +0000)]
lei_xsearch: avoid false-positives on externals w/ L: and kw:

We need to use LeiSearch->qparse_new to handle (and filter out)
"L:" and "kw:" search prefixes to avoid hitting false positives
when externals are involved.  Unfortunately, this doesn't work
for remote HTTP(S) externals, but those aren't enabled by
default.

2 years agolei inspect: support reading eml from --stdin
Eric Wong [Fri, 3 Sep 2021 08:54:25 +0000 (08:54 +0000)]
lei inspect: support reading eml from --stdin

This can be useful inside mutt since I was diagnosing why
a label ("L:$FOO") search was giving me a false-positive
search result...

2 years agolei up --all: avoid double-close on shared STDOUT
Eric Wong [Fri, 3 Sep 2021 08:54:24 +0000 (08:54 +0000)]
lei up --all: avoid double-close on shared STDOUT

This is merely to avoid perl setting errors internally which
were not user visible.  The double-close wasn't a problem in
practice since we open a new file hanlde for the mbox or
mbox.gz anyways, so the new t/lei-up.t test case shows no
regressions nor fixes.

2 years agolei: use lei->lms in place of lse->lms in a few places
Eric Wong [Fri, 3 Sep 2021 08:54:23 +0000 (08:54 +0000)]
lei: use lei->lms in place of lse->lms in a few places

We can golf out some code and refcounts this way.

2 years agolei: ->child_error less error-prone
Eric Wong [Fri, 3 Sep 2021 08:54:22 +0000 (08:54 +0000)]
lei: ->child_error less error-prone

I was calling "child_error(1, ...)" in a few places where I meant
to be calling "child_error(1 << 8, ...)" and inadvertantly
triggering SIGHUP in script/lei.  Since giving a zero exit code
to child_error makes no sense, just allow falsy values to
default to 1 << 8.

2 years agolei/store: quiet down link(2) warnings
Eric Wong [Fri, 3 Sep 2021 08:54:21 +0000 (08:54 +0000)]
lei/store: quiet down link(2) warnings

ENOENT can be too common due to timing and concurrent access
from MUAs and "lei export-kw", and other mail synchronization
tools (e.g. mbsync and offlineimap).

2 years agolei: dump errors to syslog, and not to CLI
Eric Wong [Fri, 3 Sep 2021 08:54:20 +0000 (08:54 +0000)]
lei: dump errors to syslog, and not to CLI

Dumping errors from the previous run can often get lost, so just
spew to syslog since it's a standard place to put errors that
don't make it to a client.  Note: we don't rely on $SIG{__WARN__}
since some of the Net:: stuff will write directly to STDERR
(as will external processes).

2 years agowww: handle name-only publicinbox.*.url entries
Eric Wong [Thu, 2 Sep 2021 22:12:59 +0000 (22:12 +0000)]
www: handle name-only publicinbox.*.url entries

Apparently URLs can be configured relatively for HTTP(S) setups,
attempt to support them when linking to cross-posted messages.

This also fixes the top-row (mirror/help/color/Atom feed) links
in /$INBOX_URL/$EXTMSG_MSGID/T/ (and /t/) URLs.

Reported-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
Link: https://public-inbox.org/meta/20210902191239.cmbxlmjqcsmdzmqp@meerkat.local/
2 years agotests: "make check-run" favors reliability over speed
Eric Wong [Thu, 2 Sep 2021 22:36:47 +0000 (22:36 +0000)]
tests: "make check-run" favors reliability over speed

Sharing a single lei-daemon across multiple processes still
exhibits reliability problems, and reliably checking
lei-daemon's inotify internals seems impossible without.

Even without lei-daemon sharing, "make check-run" is a few
seconds faster than "make check" for me.

2 years agot/lei-auto-watch: improve test reliability
Eric Wong [Thu, 2 Sep 2021 22:36:46 +0000 (22:36 +0000)]
t/lei-auto-watch: improve test reliability

On slower systems, even a 100ms delay may not be enough;
so loop and retry in hopes of an early exit for faster
systems.

2 years agolei: propagate keyword changes from lei/store
Eric Wong [Thu, 2 Sep 2021 10:17:58 +0000 (10:17 +0000)]
lei: propagate keyword changes from lei/store

This works with existing inotify/EVFILT_VNODE functionality to
propagate changes made from one Maildir to another Maildir.

I chose the lei/store worker process to handle this since
propagating changes back into lei-daemon on a massive scale
could lead to dead-locking while both processes are attempting
to write to each other.  Eliminating IPC overhead is a nice
side effect, but could hurt performance if Maildirs are slow.

The code for "lei export-kw" is significantly revamped to match
the new code used in the "lei/store" daemon.  It should be more
correct w.r.t. corner-cases and stale entries, but perhaps
better tests need to be written.

squashed:
  t/lei-auto-watch: increase delay for FreeBSD kevent

  My FreeBSD VM seems to need longer for this test than inotify
  under Linux, likely because the kevent support code needs to be
  more complicated.

2 years agolei_input: set and prepare watches early
Eric Wong [Thu, 2 Sep 2021 10:17:57 +0000 (10:17 +0000)]
lei_input: set and prepare watches early

This will be needed as we track changes in real-time, especially
for "lei index" since there's no storage involved.

2 years agolei_mail_sync: do not use transactions
Eric Wong [Thu, 2 Sep 2021 10:17:56 +0000 (10:17 +0000)]
lei_mail_sync: do not use transactions

For lei-index to work in parallel with MUA access and upcoming
inotify-based updates, mail_sync.sqlite3 needs to always be
up-to-date to read-only worker processes (ahead of everything
else).  So rely on the default auto-commit behavior and hope
SQLite WAL can reduce some of the overheads involved with
writes.

2 years agoextindex: --gc removes messages from over, too
Eric Wong [Wed, 1 Sep 2021 00:17:32 +0000 (00:17 +0000)]
extindex: --gc removes messages from over, too

While messages from removed inboxes were removed from Xapian
search, --gc failed to remove messages from over.sqlite3
entirely.  They no longer show up in the topic summary view.

Reported-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
Link: https://public-inbox.org/20210830201723.dehoul4y6gpqf2cp@nitro.local/
2 years agoextindex: document --all and indexlevel=basic interaction
Eric Wong [Tue, 31 Aug 2021 22:23:00 +0000 (22:23 +0000)]
extindex: document --all and indexlevel=basic interaction

Cache is expensive, so help users save on storage by documenting
this behavior.

2 years agolei up: only show finmsg in top-level lei-daemon
Eric Wong [Tue, 31 Aug 2021 19:38:03 +0000 (19:38 +0000)]
lei up: only show finmsg in top-level lei-daemon

->DESTROY can get triggered in child processes, which
unnecessarily duplicates messages queued up for display
when lei spawns extra workers.

2 years agolei/store: correctly delete entries from over
Eric Wong [Tue, 31 Aug 2021 11:21:26 +0000 (11:21 +0000)]
lei/store: correctly delete entries from over

Some of these errors were inadvertantly lost due to delayed
error reporting in the past.

2 years agolei: fix error reporting from lei/store -> lei-daemon
Eric Wong [Tue, 31 Aug 2021 11:21:25 +0000 (11:21 +0000)]
lei: fix error reporting from lei/store -> lei-daemon

We must set autoflush to ensure timely notification of clients;
and lei-daemon must not block when waiting on reads in case of
spurious wakeups.

Finally, if no clients are connected to lei-daemon, write to
syslog to ensure the error is visible.

2 years agolei_mail_sync: set_src uses binary OIDs
Eric Wong [Tue, 31 Aug 2021 11:21:24 +0000 (11:21 +0000)]
lei_mail_sync: set_src uses binary OIDs

Another step towards moving more of our internals to use binary
OIDs to avoid needless conversions before hitting disk.

2 years agolei: refresh watches before MUA spawn for Maildir
Eric Wong [Tue, 31 Aug 2021 11:21:23 +0000 (11:21 +0000)]
lei: refresh watches before MUA spawn for Maildir

If we possibly just wrote or created a Maildir, ensure it's
monitored by the lei watch mechanism.

2 years agolei note-event: always flush changes on daemon exit
Eric Wong [Tue, 31 Aug 2021 11:21:22 +0000 (11:21 +0000)]
lei note-event: always flush changes on daemon exit

Because the timer may not fire in time before daemon shutdown.

2 years agot/lei-watch: avoid race between glob + readlink
Eric Wong [Tue, 31 Aug 2021 11:21:21 +0000 (11:21 +0000)]
t/lei-watch: avoid race between glob + readlink

Open file handles in lei-daemon may be unstable so we need to
account for readlink() returning undef.

2 years agolei_mail_sync: make rename_folder more robust
Eric Wong [Tue, 31 Aug 2021 11:21:20 +0000 (11:21 +0000)]
lei_mail_sync: make rename_folder more robust

We need to account for past canonicalization errors and deal
with cases which violate uniqueness constraints in
mail_sync.sqlite3

2 years agolei_mail_sync: simplify group2folders
Eric Wong [Tue, 31 Aug 2021 11:21:19 +0000 (11:21 +0000)]
lei_mail_sync: simplify group2folders

No need to loop when we can rely on grep.

2 years agolei prune-mail-sync: handle --all (no args)
Eric Wong [Tue, 31 Aug 2021 11:21:18 +0000 (11:21 +0000)]
lei prune-mail-sync: handle --all (no args)

This still needs tests, but I noticed "--all" w/o "local" or
"remote" was not working correctly since split() returned
an empty array.

2 years agolei_mail_sync: forget_folder: simplify code
Eric Wong [Tue, 31 Aug 2021 11:21:17 +0000 (11:21 +0000)]
lei_mail_sync: forget_folder: simplify code

No need to bump refcounts of {dbh} nor declare extra variables
for a rarely-called function.

2 years agowww_listing: add note about mirroring information
Eric Wong [Mon, 30 Aug 2021 23:44:54 +0000 (23:44 +0000)]
www_listing: add note about mirroring information

Perhaps this can be expanded to include grokmirror information
in the future.  For now, just give a hint about the "mirror"
link for each inbox.

2 years agowww_text/mirror: spell out "external index" and "public inbox"
Eric Wong [Mon, 30 Aug 2021 23:44:53 +0000 (23:44 +0000)]
www_text/mirror: spell out "external index" and "public inbox"

"extindex" and "public-inbox" are project-specific terms which
are probably unsuitable for folks who are seeing this for the
first time.

Use "public inbox" when referring to actual public inboxes,
since "public-inbox" is merely the name for this particular
implementation and others have adopted the same concept (IMHO
the concept is more important than any particular
implementation).

2 years agowww_stream: extra link to mirroring information in the footer
Eric Wong [Mon, 30 Aug 2021 23:44:52 +0000 (23:44 +0000)]
www_stream: extra link to mirroring information in the footer

This may be redundant with the "mirror" link at the top right,
but maybe people will miss one.  Properly capitalize the
"Code repositories" text while we're at it.

Link: https://public-inbox.org/20210828175827.rgzwqbn7brl56oej@nitro.local/
Cc: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
2 years agowww_stream: description header links to top $INBOX_URL
Eric Wong [Sat, 28 Aug 2021 11:50:07 +0000 (11:50 +0000)]
www_stream: description header links to top $INBOX_URL

Making the inbox description link back to the most recent
per-inbox topics from text/ and $OID/s/ URLs seems useful,
rather than keeping the description up there.

Followup-to: 6c853f5256f3a324 ("www: improve navigation around contemporary threads")
2 years agowww: move mirror instructions to /text/
Eric Wong [Sat, 28 Aug 2021 11:50:06 +0000 (11:50 +0000)]
www: move mirror instructions to /text/

This makes the mirroring and code retrieval instructions less
obstructive.  Relying on WwwText means we only use our Linkify
module to make hrefs of full URLs; making relative and shortened
hrefs off-limits; hopefully this isn't too much of a problem.

coderepo information remains duplicated on every page since
(IMHO) coderepos are an important feature; but nobody besides me
has ever bothered to configure coderepos, so I suppose it's
fine...

Suggested-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
Link: https://public-inbox.org/meta/20210826132747.6gxuwnhftyf7c6hp@nitro.local/
2 years agowww: avoid potential auto-vivification on ibx->{url}
Eric Wong [Fri, 27 Aug 2021 22:03:02 +0000 (22:03 +0000)]
www: avoid potential auto-vivification on ibx->{url}

This may fix problems with the "all" link disappearing.

Link: https://public-inbox.org/meta/CAMwyc-Tw=v5yT1U1U66GSwwTK8OJXv8_YDu-=oXbZO3tHSnYWw@mail.gmail.com/
2 years agowww_listing: fix odd "locate inbox" cases
Eric Wong [Fri, 27 Aug 2021 12:08:45 +0000 (12:08 +0000)]
www_listing: fix odd "locate inbox" cases

Searching inboxes with an empty query no longer gives 500 errors
due to Xapian.  Also, improve the error message when no inboxes
match, since saying no inboxes exist yet is wrong.

2 years agowww_listing: show ->ALL at top of HTML listing
Eric Wong [Fri, 27 Aug 2021 12:08:44 +0000 (12:08 +0000)]
www_listing: show ->ALL at top of HTML listing

It's a special case and we can show it in the HTML display
without affecting manifest.js.gz generation.

2 years agomove ->ids_after from mm to over
Eric Wong [Thu, 26 Aug 2021 12:33:38 +0000 (12:33 +0000)]
move ->ids_after from mm to over

Since we favor ->over in WWW and IMAP, move this method to
->over to reduce open files in common cases.

This fixes the /$EXTINDEX_NAME/all.mbox.gz endpoint for extindex
entries (which may get expensive...).

2 years agowww_text: add coderepo config support for extindex
Eric Wong [Thu, 26 Aug 2021 12:33:37 +0000 (12:33 +0000)]
www_text: add coderepo config support for extindex

At least manually configured coderepos "just work"
for extindex, though it probably could be automatic
and inherited from the publicinbox configs.

2 years agoconfig: do not parse altid for extindex
Eric Wong [Thu, 26 Aug 2021 12:33:36 +0000 (12:33 +0000)]
config: do not parse altid for extindex

There's currently no support for altid with extindex, and
there's likely no legacy precedent for using altid like there is
with single public-inboxes.

2 years agowww_text: fix example config snippet for extindex
Eric Wong [Thu, 26 Aug 2021 12:33:35 +0000 (12:33 +0000)]
www_text: fix example config snippet for extindex

extindex doesn't use the same config stuff as normal
"publicinbox" entries, so we'll need a separate function
for them.

2 years agowww: avoid incorrect instructions for extindex
Eric Wong [Thu, 26 Aug 2021 12:33:34 +0000 (12:33 +0000)]
www: avoid incorrect instructions for extindex

There's no way to clone an extindex, since there's no git
storage associated with them.  So attempt to link to the
HTML listing of public-inboxes, instead.

2 years agowww_stream: sh-friendly .onion URLs wrapping
Eric Wong [Thu, 26 Aug 2021 12:33:33 +0000 (12:33 +0000)]
www_stream: sh-friendly .onion URLs wrapping

The long v3 .onion URL was causing havoc on small mobile
displays, so extract "hostname" into a variable which can
still used as a Bourne shell snippet.

While we're at it, include "torsocks" in the git command used
for .onion URLs since that's the (near)-universal wrapper for
Tor-ifying things (like git) which are dynamically linked to
libc.

Cc: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
Link: https://public-inbox.org/meta/20210816163654.c6gfzuezhji4l6s7@nitro.local/
2 years agods: use bytes::substr and bytes::length module-wide for now
Eric Wong [Thu, 26 Aug 2021 12:33:32 +0000 (12:33 +0000)]
ds: use bytes::substr and bytes::length module-wide for now

The use of substr within IO::Handle->write may not be correct if
we have wide characters, so handle it ourselves.

bytes.pm usage is probably better fixed in PublicInbox::NNTP,
but the effort required is higher, so we'll just keep bytes in
DS for now.

2 years agoget rid of unnecessary bytes::length usage
Eric Wong [Thu, 26 Aug 2021 12:33:31 +0000 (12:33 +0000)]
get rid of unnecessary bytes::length usage

The only place where we could return wide characters with -httpd
was the raw $INBOX_DIR/description text, which is now converted
to octets.

All daemon (HTTP/NNTP/IMAP) sockets are opened in binary mode,
so length() and bytes::length() are equivalent on reads.  For
socket writes, any non-octet data would warn about wide characters
and we are strict in warnings with test_httpd.

All gzipped buffers are also octets, as is PublicInbox::Eml->body,
and anything from PerlIO objects ("git cat-file --batch" output,
filesystems), so bytes::length was unnecessary in all those places.

2 years agowwwlisting: support global CSS in HTML view
Eric Wong [Wed, 18 Aug 2021 11:41:02 +0000 (11:41 +0000)]
wwwlisting: support global CSS in HTML view

Since CSS can be overridden by a static webserver on a per-inbox
basis, we need a similar pattern to deal with the instance-wide
WwwListing HTML.  "/+/" probably won't conflict with any current
nor future public inbox names.

I don't think it'll cause problems with common linkifiers or URL
extractors, either (and it's unlikely anybody would want to
share URLs of just the CSS in a plain text(-like) format).

2 years agolei_mail_sync: remove warning message from caller
Eric Wong [Wed, 25 Aug 2021 08:40:40 +0000 (08:40 +0000)]
lei_mail_sync: remove warning message from caller

We can afford to be liberal in what messages we accept
internally, since LeiToMail uses a trailing slash internally.

2 years agolei up: improve --all=local stderr output
Eric Wong [Wed, 25 Aug 2021 08:40:39 +0000 (08:40 +0000)]
lei up: improve --all=local stderr output

The "# $NR written to $DEST ($total matches)" messages are
arguably the most useful output of "lei up --all=local",
but they get intermixed with progress messages from various
workers.  Queue up these finalization messages and only spit
them out on ->DESTROY.

2 years agoimap+nntp: die loudly if ->mm or ->over disappear
Eric Wong [Tue, 24 Aug 2021 22:49:24 +0000 (22:49 +0000)]
imap+nntp: die loudly if ->mm or ->over disappear

While the WWW front-end can gracefully handle ->mm and ->over
disappearing (in most cases), IMAP+NNTP front-ends are completely
dependent on these and failed mysteriously when they go missing
after startup.

These will hopefully make issues like what Konstantin
encountered more obvious:

Link: https://public-inbox.org/meta/20210824204855.ejspej4z7r2rpu63@nitro.local/
2 years agolei: non-blocking lei/store->done in lei-daemon
Eric Wong [Tue, 24 Aug 2021 13:06:39 +0000 (13:06 +0000)]
lei: non-blocking lei/store->done in lei-daemon

This allows client sockets to wait for "done" commits to
lei/store while the daemon reacts asynchronously.  The goal
of this change is to keep the script/lei client alive until
lei/store commits changes to the filesystem, but without
blocking the lei-daemon event loop.  It depends on Perl
refcounting to close the socket.

This change also highlighted our over-use of "done" requests to
lei/store processes, which is now corrected so we only issue it
on collective socket EOF rather than upon reaping every single
worker.

This also fixes "lei forget-mail-sync" when it is the initial
command.

This took several iterations and much debugging to arrive at the
current implementation:

1. The initial iteration of this change utilized socket passing
   from lei-daemon to lei/store, which necessitated switching
   from faster pipes to slower Unix sockets.

2. The second iteration switched to registering notification sockets
   independently of "done" requests, but that could lead to early
   wakeups when "done" was requested by other workers.  This
   appeared to work most of the time, but suffered races under
   high load which were difficult to track down.

Finally, this iteration passes the stringified socket GLOB ref
to lei/store which is echoed back to lei-daemon upon completion
of that particular "done" request.

2 years agolei: add missing LeiWatch lazy-load
Eric Wong [Tue, 24 Aug 2021 13:04:06 +0000 (13:04 +0000)]
lei: add missing LeiWatch lazy-load

I'm not sure if this class will actually be needed, but
we need to load it while we're using it.

2 years agolei: implicitly watch all Maildirs it knows about
Eric Wong [Thu, 19 Aug 2021 09:49:34 +0000 (09:49 +0000)]
lei: implicitly watch all Maildirs it knows about

This allows MUA-made flag changes to Maildirs to be instantly
read and acknowledged for future search results.

In the future, it may be used to speed up --augment and
--import-before (the default) with with "lei q".

2 years agolei q: make --save the default
Eric Wong [Thu, 19 Aug 2021 01:36:38 +0000 (01:36 +0000)]
lei q: make --save the default

Since "lei up" is more often useful than not and incurs neglible
overhead; enable --save by default and allow --no-save to work.

This also fixes a long-standing when overwriting --output
destinations with saved searches:  dedupe data from previous
searches are reset and no longer influences the new (changed)
search, so results no longer go missing if two sequential
invocations of "lei q --save" point to the same --output.

2 years agolei forget-mail-sync: rely on lei/store process
Eric Wong [Tue, 17 Aug 2021 08:52:41 +0000 (08:52 +0000)]
lei forget-mail-sync: rely on lei/store process

As implied in commit 6ff03ba2be9247f1
("lei export-kw: do not write directly to mail_sync.sqlite3"),
modifying mail_sync.sqlite3 directly can lead to conflicts
and making everything go through lei/store is easier.

2 years agoipc: remove WQ_MAX_WORKERS
Eric Wong [Tue, 17 Aug 2021 08:52:40 +0000 (08:52 +0000)]
ipc: remove WQ_MAX_WORKERS

We no longer rely on IO::FDPass, so there's no longer a reason
to limit this internally.

2 years agolei: add ->lms shortcut for LeiMailSync
Eric Wong [Tue, 17 Aug 2021 08:52:39 +0000 (08:52 +0000)]
lei: add ->lms shortcut for LeiMailSync

We access this read-only in many places (and will in more),
so provide a shortcut to simplify callers.

2 years agoview: remove mbox.gz and Atom from topic view
Eric Wong [Mon, 16 Aug 2021 23:35:20 +0000 (23:35 +0000)]
view: remove mbox.gz and Atom from topic view

This declutters the topic view since these links seem rarely
used.  Atom and mbox.gz links probably make most sense when
users have read the HTML and decide the topic is worth following
or downloading.

Reported-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
Link: https://public-inbox.org/meta/20210816154444.sj3ks2sikq3x2ywx@nitro.local/
2 years agouser_content: update + wrap lines for CSS change
Eric Wong [Mon, 16 Aug 2021 22:42:45 +0000 (22:42 +0000)]
user_content: update + wrap lines for CSS change

Fixes: 86df4acd140d61ab ("Duplicate base css definitions in stylesheets")
2 years agoDuplicate base css definitions in stylesheets
Konstantin Ryabitsev [Mon, 16 Aug 2021 14:50:15 +0000 (10:50 -0400)]
Duplicate base css definitions in stylesheets

All pages carry the following inlined css declaration:

    <style>pre{white-space:pre-wrap}*{font-size:100%;font-family:monospace}</style>

However, site security policies may deliberately prohibit execution of
inline content such as scripts and stylesheets as an extra layer of
protection against XSS vulnerabilities. For example, with the following
HTTP headers returned by the server, the inline styles above will be
ignored:

    Content-Security-Policy: default-src 'self'

This causes public-inbox content to be rendered poorly on mobile devices
due to the default <pre> behaviour. Duplicating this declaration into
the contrib stylesheets makes sure that these styles are applied even
with the strictest security policies in place.

Signed-off-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
2 years agot/run.perl: fix "make check-run" on FreeBSD 11.x
Eric Wong [Mon, 16 Aug 2021 07:29:17 +0000 (07:29 +0000)]
t/run.perl: fix "make check-run" on FreeBSD 11.x

Persistent lei-daemon still leads to ECONNRESET client errors on
FreeBSD, and maxing out the kern.ipc.soacceptqueue sysctl (as
documented in the FreeBSD listen(2) manpage) doesn't seem to
help.

"make check-run" is still 4-5s faster than "make check" on my
FreeBSD VM even after this change, so it's still a worthwhile
improvement.

2 years agolei_search: avoid unconditional warning when no exception
Eric Wong [Mon, 16 Aug 2021 05:39:33 +0000 (05:39 +0000)]
lei_search: avoid unconditional warning when no exception

Oops, we shouldn't warn on "$@" unless "$@" is truthy.

Fixes: c7bcfe6cd6648ff0 ("lei: diagnostics for /Document \d+ not found/ errors")
2 years agowww: uninitialized vars due to extindex lacking address
Eric Wong [Mon, 16 Aug 2021 05:30:22 +0000 (05:30 +0000)]
www: uninitialized vars due to extindex lacking address

Some messages have From/To/Cc headers munged to be unparseable to
Email::Address::XS, the fallback is to use the default inbox address.
-extindex do not have an address on their own, so just fall back to
using 'unknown@example.com' for now.

An example of such a message:
https://yhbt.net/lore/all/20201002154535.28412-1-fw@strlen.de/