~sircmpwn/aerc

3 3

Why does aerc move unread mail from new to cur?

Ondřej Synáček
Details
Message ID
<C9ADX41FOGU8.1ZG2DUYUZX7II@Prefab.local>
DKIM signature
pass
Download raw message
If I leave aerc open and new email is added to my maildir, aerc correctly detects
that it's a new unread email. However it is immediately moved from `new` subfolder
to `cur` subfolder.

I am unsure if this is how it is supposed to work or needs to worker in order
for aerc to function correctly. It's just that I'm using tmux script that
shows number of mails in certain folder and I basically want to display
number of unread emails. This means reading `$HOME/maildir/INBOX/new` but
if I keep aerc open which I will most likely do, then it does not work
as intented.

Maybe if someone explains to me how aerc keeps track of unread emails I
might be able to adjust the script. (I assume it's some kind of flag?).

Thanks.
Details
Message ID
<4fsmTjMb-3INpxD6lfgLzYkjSvnWAH9gSmjDaGvo43l45Sv7fk832w65tg5haiBOQVyaOi6yFIh439_d9LDyaOQcCKuceZXQGS3mdAQoX0w=@emersion.fr>
In-Reply-To
<C9ADX41FOGU8.1ZG2DUYUZX7II@Prefab.local> (view parent)
DKIM signature
pass
Download raw message
That's not how maildir works. To count unread messages, you need to
count the number of files without the 'S' flag in the cur directory.
Kian Kasad
Details
Message ID
<20210215205824.5f354hcj2otwvxo6@frisbee>
In-Reply-To
<C9ADX41FOGU8.1ZG2DUYUZX7II@Prefab.local> (view parent)
DKIM signature
pass
Download raw message
On 21/02/15 09:25PM, Ondřej Synáček wrote:
> If I leave aerc open and new email is added to my maildir, aerc correctly detects
> that it's a new unread email. However it is immediately moved from `new` subfolder
> to `cur` subfolder.
> 
> I am unsure if this is how it is supposed to work or needs to worker in order
> for aerc to function correctly. It's just that I'm using tmux script that
> shows number of mails in certain folder and I basically want to display
> number of unread emails. This means reading `$HOME/maildir/INBOX/new` but
> if I keep aerc open which I will most likely do, then it does not work
> as intented.
> 
> Maybe if someone explains to me how aerc keeps track of unread emails I
> might be able to adjust the script. (I assume it's some kind of flag?).

I must admit that I don't use aerc (yet), however here's an excerpt from
Wikipedia on the Maildir format:

	A Maildir directory (often named Maildir) usually has three
	subdirectories named tmp, new, and cur.

	The tmp subdirectory temporarily stores e-mail messages that are
	in the process of being delivered. This subdirectory may also
	store other kinds of temporary files. The new subdirectory
	stores messages that have been delivered, but have not yet been
	seen by any mail application. The cur subdirectory stores
	messages that have already been seen by mail applications.[2]

	2. http://www.courier-mta.org/maildir.html

That reference, which seems to point to a technical specification of
Maildir, says the following about reading messages in maildirs:

	Look for new messages in the new subdirectory. Rename
	new/filename, as cur/filename:2,info. Here, info represents the
	state of the message, and it consists of zero or more boolean
	flags chosen from the following: “D” - this is a 'draft'
	message, “R” - this message has been replied to, “S” - this
	message has been viewed (seen), “T” - this message has been
	marked to be deleted (trashed), but is not yet removed (messages
	are removed from maildirs simply by deleting their file), “F” -
	this message has been marked by the user, for some purpose.
	These flags must be stored in alphabetical order. New messages
	contain only the :2, suffix, with no flags, indicating that the
	messages were not seen, replied, marked, or deleted.

So my guess is that unread messages will be stored as follows:

1. In the new/ subdirectory.
2. In the cur/ subdirectory, with a filename ending in ":2" or
   ":2<flags>", where <flags> *does not* contain an "S".

You should be good to count the files according to those rules to get a
count of total unread messages.

--
Kian Kasad
PGP 0x1715EEAA14DAEC1
Ondřej Synáček
Details
Message ID
<C9AFG4WEY4QO.34CNDM38BB3VE@Prefab.local>
In-Reply-To
<20210215205824.5f354hcj2otwvxo6@frisbee> (view parent)
DKIM signature
pass
Download raw message
On Mon Feb 15, 2021 at 9:58 PM CET, Kian Kasad wrote:
> So my guess is that unread messages will be stored as follows:
>
> 1. In the new/ subdirectory.
> 2. In the cur/ subdirectory, with a filename ending in ":2" or
> ":2<flags>", where <flags> *does not* contain an "S".

Will try that out. Thanks for helping me.
Reply to thread Export thread (mbox)