Subject: bug#50450: 28.0.50; nnmaildir cannot find article file

From: Philip Kaludercic <[email-masked]>
Date: Wed, 15 Sep 2021 09:03:16 +0000

Lars Ingebrigtsen <[email-masked]> writes:

> Philip Kaludercic <[email-masked]> writes:
>
>>>From time to time I get error messages like
>>
>> nnmaildir--article-set-flags: Couldn’t find article file
>> /home/philip/Mail/Pers/Sent/cur/1631002186.M670797P704685Q0.icterid:2,S
>>
>> when trying to send a message.
>
> I don't use nnmaildir myself (and I'm not familiar with how maildir
> works, really).  Can you propose a patch to fix this yourself?  :-)

I found out that the issue is not the UID, but the flags. Specifically,
when I open a message via Gnus, leave it open for a while, perhaps check
the message on my phone or some other device, and then return to Gnus,
it might have happened that the flags (included in the file-name) were
updated by mbsync.

This patch attempts to find a similar file, and renames that file
instead of the one Gnus remembered. It seems to be working for now, but
I'd wait a bit until I had more time to test it before applying it:

>From facb1848952d5c844d76844e35da708fda8307c7 Mon Sep 17 00:00:00 2001
From: Philip Kaludercic <[email-masked]>
Date: Wed, 15 Sep 2021 10:58:50 +0200
Subject: [PATCH] Handle updates flags when setting flags

* nnmaildir.el (nnmaildir--article-set-flags): Handle updated flags
  more gracefully
---
 lisp/gnus/nnmaildir.el | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/lisp/gnus/nnmaildir.el b/lisp/gnus/nnmaildir.el
index 171f0813b3..690761a2d6 100644
--- a/lisp/gnus/nnmaildir.el
+++ b/lisp/gnus/nnmaildir.el
@@ -194,7 +194,15 @@ nnmaildir--article-set-flags
 	 (article-file (concat curdir prefix suffix))
 	 (new-name (concat curdir prefix new-suffix)))
     (unless (file-exists-p article-file)
-      (error "Couldn't find article file %s" article-file))
+      (let ((possible (file-expand-wildcards (concat curdir prefix "*"))))
+	(cond ((length= possible 1)
+	       (unless (string-match-p "\\`\\(.+\\):2,.*?\\'" (car possible))
+		 (error "Couldn't find updated article file %s" article-file))
+	       (setq article-file (car possible)))
+	      ((length> possible 1)
+	       (error "Couldn't determine exact article file %s" article-file))
+	      ((null possible)
+	       (error "Couldn't find article file %s" article-file)))))
     (rename-file article-file new-name 'replace)
     (setf (nnmaildir--art-suffix article) new-suffix)))
 
-- 
2.30.2

One possible issue is that nnmaildir--article-set-flags overwrites
previous flags that might have been updated elsewhere.

-- 
	Philip Kaludercic