Subject: Re: bug#67359: 29.1; 29.1: MH-E limited display malfunctions if nothing is matched

From: Eli Zaretskii <[email-masked]>
Date: Wed, 22 Nov 2023 16:43:09 +0200

> Cc: [email-masked]
> From: Chris Siebenmann <[email-masked]>
> Date: Tue, 21 Nov 2023 19:28:45 -0500
> 
> The summary is that if you use one of the MH-E limit commands, normally
> bound under / in MH-E folder mode, and you attempt to limit (narrow) to
> something that isn't present, MH-E doesn't handle the situation properly
> and winds up with a narrowed list of folder contents displaying nothing
> useful instead of reporting that no messages matched.
> 
> To reproduce this, you will need NMH and MH-E configured. Then:
> 
> * Enter MH-E, for example with 'M-x mh-rmail'.
> * widen the display to cover your entire inbox, '/ w'.
> * search for something that is not present: 'C-u / s', and change the
>   subject to search for to, for example, 'nosuchsubjectstring'.
> 
> When you do this, MH-E will first show an error message in a buffer
> below the folder window and then narrow the main folder window to a
> single line showing 'scan: no messages match specification'. ('/ w' will
> then fix the situation.)
> 
> When this happens, my *MH-E Log* buffer shows (without the leading
> indent):
> 	Errors when executing: mark +inbox -add -sequence header 0 0
> 	mark: no messages match specification
> 
> The NMH commands MH-E has run (for me) are:
> 	/usr/bin/mh/pick +inbox 1-382 -list -subject nosuchsubjectstring
> 	/usr/bin/mh/mark +inbox -add -sequence header 0 0
> 
> The output from this pick command if run by hand *without standard
> output being a tty* are:
> 	$ pick +inbox 1-382 -list -subject nosuchsubjectstring | cat
> 	pick: no messages match specification
> 	0
> 
> The potentially surprising '0' is documented in the current NMH pick
> manual page in "Output when no messages are matched". In brief, with
> -list and standard output not being a tty, pick deliberately outputs as
> '0' to standard output to signal error.
> 
> I believe the code problem is in mh-narrow-to-header-field in
> mh-limit.el, where it processes pick output using 'string-to-number' on
> each line and then pushes the nominal resulting number on to the
> msg-list list with:
> 	(when num (push num msg-list))
> 
> I think that there are two problems with this code. The first is that
> string-to-number doesn't return nil on non-numbers, it returns 0. The
> second is that sometimes a real '0' is present, but should not be pushed
> into the message list either. The two together explain why mark was
> invoked with the odd '0 0'; one is from the pick error line and one is
> from the actual '0' it output.
> 
> I am using the version of NMH packaged with Ubuntu 22.04, which is
> listed as NMH 1.7.1. My Emacs is a locally compiled 29.1.
> 
> NOTE: This reproduces in 'emacs -Q', but this report is submitted from
> inside my regular Emacs environment because life is too short. You can
> ignore the list of third party packages, load-path shadows, and other
> things.

Adding Bill.

I'm not sure if it is better to report MH-E-related bugs here or
submit the reports to https://sourceforge.net/p/mh-e/bugs/.