Article View: linux.debian.bugs.dist
Article #3616Bug#1153304: neomutt: Maildir sync overwrites flags changed by another program while a local change is pending
From: Benj. Mako Hill
Date: Sat, 07 Nov 2026 02:10
Date: Sat, 07 Nov 2026 02:10
378 lines
15279 bytes
15279 bytes
--yfmbydepypqzkrhw
Content-Type: multipart/mixed; protected-headers=v1;
boundary="4wij4jyfwzsogyo3"
Content-Disposition: inline
Subject: neomutt: Maildir sync overwrites flags changed by another program
while a local change is pending
MIME-Version: 1.0
--4wij4jyfwzsogyo3
Content-Type: text/plain; charset=utf-8
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
Package: neomutt
Version: 20250510+dfsg-2
Severity: important
Tags: upstream patch
Forwarded: https://github.com/neomutt/neomutt/pull/5075
When a Maildir message has an unsynced local change (which $mark_old,
on by default, causes for most messages at open), neomutt's mailbox
check ignores the flags in the file's current name, and the next sync
renames the file to the whole in-memory flag set. Every flag another
program=E2=80=94offlineimap, mbsync, notmuch with maildir.synchronize_flags=
, a
second neomutt=E2=80=94changed in the meantime is lost, and since the synci=
ng
program then pushes the flags back to the server, the loss is
permanent. Typical result: a message read elsewhere while a reply was
pending here becomes unread again; a flag set in one instance is wiped
by a sync in the other.
This is related to #1153301 (same investigation, same code path) but
loses flags, not messages (hence severity=3Dimportant rather than
grave).
A reproduction script is attached (two neomutt instances in tmux on a
temporary Maildir, synthetic messages only). With 20250510+dfsg-2 all
four cases fail (the file ends up :2,S / :2,F / :2,F / :2,FS instead
of :2,FS / :2,FS / :2,FS / :2,RS). The code is unchanged in
20260616+dfsg-1 and upstream main.
I have sent a fix upstream: https://github.com/neomutt/neomutt/pull/5075
It records, per message, the flags last seen on disk and, on a check,
takes each flag that changed on disk and that this instance did not
change; a flag changed in both places keeps the local value.
The patch is attached and applies to the Debian source with minor
offsets. As with #1153301, the patch was developed with generative AI
(Claude Fable 5.1) in a human-assistance sense. I'm also not super
familiar with neomutt so I'd appreciate extra eyes.
-- System Information:
Debian Release: 13.7
APT prefers stable-updates
APT policy: (990, 'stable-updates'), (990, 'stable-security'), (990, 'sta=
ble'), (500, 'unstable'), (100, 'unstable'), (100, 'testing'), (1, 'experim=
ental')
Architecture: amd64 (x86_64)
Foreign Architectures: i386
Kernel: Linux 6.12.113+deb13-amd64 (SMP w/20 CPU threads; PREEMPT)
Kernel taint flags: TAINT_USER, TAINT_WARN, TAINT_OOT_MODULE, TAINT_UNSIGNE=
D_MODULE
Locale: LANG=3Den_US.UTF-8, LC_CTYPE=3Den_US.UTF-8 (charmap=3DUTF-8) (ignor=
ed: LC_ALL set to en_US.UTF-8), LANGUAGE not set
Shell: /bin/sh linked to /usr/bin/dash
Init: systemd (via /run/systemd/system)
LSM: AppArmor: enabled
Versions of packages neomutt depends on:
ii libc6 2.41-12+deb13u4
ii libgnutls30t64 3.8.9-3+deb13u4
ii libgpgme11t64 1.24.2-3
ii libgsasl18 2.2.2-1.1+deb13u2
ii libgssapi-krb5-2 1.21.3-5+deb13u1
ii libidn2-0 2.3.8-2
ii liblmdb0 0.9.31-1+b2
ii liblua5.4-0 5.4.7-1+b2
ii liblz4-1 1.10.0-4
ii libncursesw6 6.5+20250216-2
ii libnotmuch5t64 0.39-1
ii libpcre2-8-0 10.46-1~deb13u3
ii libsqlite3-0 3.46.1-7+deb13u2
ii libtinfo6 6.5+20250216-2
ii libzstd1 1.5.7+dfsg-1
ii sensible-utils 0.0.25
ii zlib1g 1:1.3.dfsg+really1.3.1-1+b1
Versions of packages neomutt recommends:
ii locales 2.41-12+deb13u4
ii mailcap 3.74
Versions of packages neomutt suggests:
ii aspell 0.60.8.1-4
ii ca-certificates 20250419+deb13u1
ii gnupg 2.4.7-21+deb13u1
ii ispell 3.4.06-1
ii openssl 3.5.7-1~deb13u3
ii postfix [mail-transport-agent] 3.10.13-0+deb13u1
ii python3 3.13.5-1
pn urlview <none>
Versions of packages neomutt is related to:
ii neomutt 20260616+dfsg-1+mako1
-- no debconf information
--=20
Benjamin Mako Hill
https://mako.cc/
--4wij4jyfwzsogyo3
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment; filename="maildir-merge-flags.patch"
Content-Transfer-Encoding: quoted-printable
=46rom 7fa5a3dbe4921c6fba626bdc77acb70e418724a5 Mon Sep 17 00:00:00 2001
=46rom: Benjamin Mako Hill <mako@atdot.cc>
Date: Fri, 6 Nov 2026 17:57:24 -0800
Subject: [PATCH] maildir: merge external flag changes instead of overwriting
them on sync
When an Email has unsynced local changes, maildir_check() ignores the
flags in the file's current name, and the next sync renames the file
to carry the whole in-memory flag set. Any flag another program
changed in the meantime (offlineimap/mbsync syncing from the server,
notmuch with maildir.synchronize_flags, a second NeoMutt) is lost: a
message read elsewhere while a reply was pending here becomes unread
again; a flag set in one instance is wiped by a sync in the other.
Record, per Email, the flags as last seen on disk (at parse, after a
check, after a sync). When a check finds the file renamed under a
locally modified Email, take each flag that changed on disk and that
we did not change ourselves; a flag changed in both places keeps the
local value. Custom flags, which NeoMutt never sets, always follow
the file. The sync then writes our changes as a delta over theirs.
Note: I used an AI coding agent (Fable 5.1) as part of my workflow to
help prepare and review this change. That said, this code is (at most)
"AI assisted" and fully reflects my own work and judgement.
---
maildir/edata.c | 17 ++++++++++++++++
maildir/edata.h | 7 +++++++
maildir/mailbox.c | 18 ++++++++++++++++-
maildir/message.c | 5 +++++
maildir/shared.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++
maildir/shared.h | 1 +
6 files changed, 96 insertions(+), 1 deletion(-)
diff --git a/maildir/edata.c b/maildir/edata.c
index 3e3acf825..ebf337299 100644
--- a/maildir/edata.c
+++ b/maildir/edata.c
@@ -66,3 +66,20 @@ struct MaildirEmailData *maildir_edata_get(struct Email =
*e)
return NULL;
return e->edata;
}
+
+/**
+ * maildir_edata_set_disk_flags - Record the flags currently in the file's=
name
+ * @param e Email to update
+ * @param e_disk Email whose flags match the file on disk (may be e itself)
+ */
+void maildir_edata_set_disk_flags(struct Email *e, const struct Email *e_d=
isk)
+{
+ struct MaildirEmailData *edata =3D maildir_edata_get(e);
+ if (!edata || !e_disk)
+ return;
+
+ edata->disk_flagged =3D e_disk->flagged;
+ edata->disk_replied =3D e_disk->replied;
+ edata->disk_read =3D e_disk->read;
+ edata->disk_old =3D e_disk->old;
+}
diff --git a/maildir/edata.h b/maildir/edata.h
index 674b19ffa..3fd0efbd9 100644
--- a/maildir/edata.h
+++ b/maildir/edata.h
@@ -31,10 +31,17 @@ struct Email;
struct MaildirEmailData
{
char *custom_flags; ///< Custom Maildir flags (e.g Dovecot labe=
ls)
+
+ // Flags as last seen in the filename on disk, see maildir_merge_flags()
+ bool disk_flagged : 1; ///< 'F' flag was set on disk
+ bool disk_replied : 1; ///< 'R' flag was set on disk
+ bool disk_read : 1; ///< 'S' flag was set on disk
+ bool disk_old : 1; ///< File was in the 'cur' directory
};
=20
void maildir_edata_free(void **ptr);
struct MaildirEmailData *maildir_edata_get(struct Email *e);
struct MaildirEmailData *maildir_edata_new(void);
+void maildir_edata_set_disk_flags(struct Email *e, con=
st struct Email *e_disk);
=20
#endif /* MUTT_MAILDIR_EDATA_H */
diff --git a/maildir/mailbox.c b/maildir/mailbox.c
index 29814b831..f0961b722 100644
--- a/maildir/mailbox.c
+++ b/maildir/mailbox.c
@@ -143,6 +143,8 @@ void maildir_parse_flags(struct Email *e, const char *p=
ath)
FREE(&edata->custom_flags);
else if (q)
*q =3D '\0';
+
+ maildir_edata_set_disk_flags(e, e);
}
=20
/**
@@ -647,10 +649,24 @@ static enum MxStatus maildir_check(struct Mailbox *m)
mutt_str_replace(&e->path, md->email->path);
=20
/* if the user hasn't modified the flags on this message, update
- * the flags we just detected. */
+ * the flags we just detected. Otherwise take only the flags that
+ * changed on disk since we last saw the file. */
if (!e->changed)
+ {
if (maildir_update_flags(m, e, md->email))
flags_changed =3D true;
+ }
+ else if (maildir_merge_flags(m, e, md->email))
+ {
+ flags_changed =3D true;
+ }
+ maildir_edata_set_disk_flags(e, md->email);
+
+ /* custom flags can only be changed by other programs */
+ struct MaildirEmailData *edata =3D maildir_edata_get(e);
+ struct MaildirEmailData *edata_new =3D maildir_edata_get(md->email);
+ if (edata && edata_new)
+ mutt_str_replace(&edata->custom_flags, edata_new->custom_flags);
=20
if (e->deleted =3D=3D e->trash)
{
diff --git a/maildir/message.c b/maildir/message.c
index 5177b4b14..2f2580611 100644
--- a/maildir/message.c
+++ b/maildir/message.c
@@ -331,6 +331,11 @@ bool maildir_sync_mailbox_message(struct Mailbox *m, s=
truct Email *e, struct Hea
{
if (maildir_sync_message(m, e) =3D=3D -1)
return false;
+ maildir_edata_set_disk_flags(e, e);
+ // A scan reports any file in cur/ as old, whatever e->old says
+ struct MaildirEmailData *edata =3D maildir_edata_get(e);
+ if (edata)
+ edata->disk_old =3D mutt_strn_equal(e->path, "cur/", 4);
}
=20
if (e->changed)
diff --git a/maildir/shared.c b/maildir/shared.c
index 28bf0d188..82c985789 100644
--- a/maildir/shared.c
+++ b/maildir/shared.c
@@ -36,6 +36,7 @@
#include "email/lib.h"
#include "core/lib.h"
#include "mutt.h"
+#include "edata.h"
#include "mdata.h"
=20
/**
@@ -139,3 +140,51 @@ bool maildir_update_flags(struct Mailbox *m, struct Em=
ail *e_old, struct Email *
=20
return header_changed;
}
+
+/**
+ * maildir_merge_flags - Merge external flag changes into a locally modifi=
ed Email
+ * @param m Mailbox
+ * @param e_old Email with unsynced local changes
+ * @param e_new Email parsed from the file currently on disk
+ * @retval true Flags were changed
+ * @retval false No change
+ *
+ * Another program changed the file's flags while we had our own unsynced
+ * changes. Each flag that we did not change since we last saw the file t=
akes
+ * the on-disk value; a flag we did change keeps our value, so the next sy=
nc
+ * writes our changes as a delta over theirs rather than replacing them.
+ */
+bool maildir_merge_flags(struct Mailbox *m, struct Email *e_old, struct Em=
ail *e_new)
+{
+ if (!m || !e_old || !e_new)
+ return false;
+
+ struct MaildirEmailData *edata =3D maildir_edata_get(e_old);
+ if (!edata)
+ return false;
+
+ bool changed =3D false;
+
+ if ((e_new->flagged !=3D edata->disk_flagged) && (e_old->flagged =3D=3D =
edata->disk_flagged))
+ {
+ mutt_set_flag(m, e_old, MUTT_FLAG, e_new->flagged, true);
+ changed =3D true;
+ }
+ if ((e_new->replied !=3D edata->disk_replied) && (e_old->replied =3D=3D =
edata->disk_replied))
+ {
+ mutt_set_flag(m, e_old, MUTT_REPLIED, e_new->replied, true);
+ changed =3D true;
+ }
+ if ((e_new->read !=3D edata->disk_read) && (e_old->read =3D=3D edata->di=
sk_read))
+ {
+ mutt_set_flag(m, e_old, MUTT_READ, e_new->read, true);
+ changed =3D true;
+ }
+ if ((e_new->old !=3D edata->disk_old) && (e_old->old =3D=3D edata->disk_=
old))
+ {
+ mutt_set_flag(m, e_old, MUTT_OLD, e_new->old, true);
+ changed =3D true;
+ }
+
+ return changed;
+}
diff --git a/maildir/shared.h b/maildir/shared.h
index 2a27b6038..2a8e323a4 100644
--- a/maildir/shared.h
+++ b/maildir/shared.h
@@ -37,6 +37,7 @@ struct Message;
void maildir_canon_filename (struct Buffer *dest, const char=
*src);
mode_t maildir_umask (struct Mailbox *m);
bool maildir_update_flags (struct Mailbox *m, struct Email=
*e_old, struct Email *e_new);
+bool maildir_merge_flags (struct Mailbox *m, struct Email=
*e_old, struct Email *e_new);
=20
// These are needed by Notmuch
struct Email *maildir_email_new (void);
--=20
2.47.3
--4wij4jyfwzsogyo3--
--yfmbydepypqzkrhw
Content-Type: application/pgp-signature; name="signature.asc"
-----BEGIN PGP SIGNATURE-----
iQIzBAABCAAdFiEEfGsMgrD+o7iQi1uRu+m/omm+WTUFAmruhqMACgkQu+m/omm+
WTXEGg//Tp2zdZuP3nAqMSg5jtbFNSJosKR52tBa6srn2rezKmfffArate54s9aa
xjTqlEI+pnNYOebDViq5hGjdxpzq77ir13i839uLvIuGb1MaNNPfUSuvvF5DLlD+
53do7gh1+82RUGJjCnL8tUzkv147eMF3z8ZGFKMP4wN8c+vElz+YpQTQkYkHBvSv
K8Y3+zp6paso/M6JX1YkUDr7s7wJhx6vs8F0F6jScMi1CX0B7jTJFqPML6fMqMic
hmy1MX9EgJWkryhFPdNnU36g8GR/wy6FIPFVxvFAyZMFdFewhPukosN/vQ2Sbwhw
4F4MLEo76BhuAPVI3SD0VaAvvmQDpyxp1ZEN1y+UUanZM34EjgCPr29rLx5tGSA9
R+DV22LmTnRx4PjGOA5rao9XBdfAxAAqed2NhXuyco9zXSsQS7RTK9D7IqnIZhLy
IJkQaOqW6vRBfw7TOyPtx2RPQJvu07llCZ3VIckIatULJ+Ksh7z9Pj7rfevRQajl
m9H6VUgcYfK5RmK5T9zJIQtegsxRPxBrJ+R6vNUMBowy5G0YGNfC20jvKzW0lnOW
l6RwfafyH5KF2RO+PWDVStUNiQ9Q8m6Q4P0QXfx9PLCzO9FncMUdjIy0CDJTZCXW
xoumbycuBqsaa3Cx/dHUPAQSgpLyv8Em1H3+wfolGN/scT6ps/Y=
=Oj0y
-----END PGP SIGNATURE-----
--yfmbydepypqzkrhw--
Technical Details
Message-ID:
<NWE2t-aj7E-1@gated-at.bofh.it>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!news.corradoroberto.it!diesel.cu.mi.it!bofh.it!news.nic.it!robomodShow Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!news.corradoroberto.it!diesel.cu.mi.it!bofh.it!news.nic.it!robomod From: "Benj. Mako Hill" <mako@atdot.cc> Newsgroups: linux.debian.bugs.dist Subject: Bug#1153304: neomutt: Maildir sync overwrites flags changed by another program while a local change is pending Date: Sat, 07 Nov 2026 03:10:01 +0100 Message-ID: <NWE2t-aj7E-1@gated-at.bofh.it> X-Mailbox-Line: From debian-bugs-dist-request@lists.debian.org Sat Nov 7 02:05:12 2026 Old-Return-Path: <debbugs@buxtehude.debian.org> X-Spam-Flag: NO X-Spam-Score: -1.45 Reply-To: "Benj. Mako Hill" <mako@atdot.cc>, 1153304@bugs.debian.org Resent-To: debian-bugs-dist@lists.debian.org Resent-Cc: mutt@packages.debian.org X-Debian-Pr-Message: report 1153304 X-Debian-Pr-Package: neomutt X-Debian-Pr-Keywords: patch upstream X-Debian-Pr-Source: neomutt MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="yfmbydepypqzkrhw" Content-Disposition: inline X-Debian-Message: from BTS X-Mailing-List: <debian-bugs-dist@lists.debian.org> archive/latest/2001196 List-ID: <debian-bugs-dist.lists.debian.org> List-URL: <https://lists.debian.org/debian-bugs-dist/> Approved: robomod@news.nic.it Lines: 378 Organization: linux.* mail to news gateway Sender: robomod@news.nic.it X-Original-Date: Fri, 6 Nov 2026 18:02:12 -0800 X-Original-Message-ID: <au6Ge4a5bb7aqtoC@yukidoke.org>