nicm / fdm

fdm source code
269 stars 50 forks source link

FEATURE REQUEST: honor imap- and maildir-flags #133

Open herrsimon opened 1 year ago

herrsimon commented 1 year ago

First of all, thank you very much for this very nice tool, I partially replaced a combination of mbsync/maildrop with it a couple of days ago and it works like a charm, simplifying my email workflow a lot.

In the manual, an explicitly stated purpose of fdm is filtering and archiving. Here, it is a bit problematic that email delivered to maildirs is always categorized as new, without any flags. In particular, when archiving an existing maildir or filtering mailinglist-messages from the inbox to a dedicated folder, those flags will be lost, resulting in all mail to be marked as new (even though they have been read or bounced before, replied to etc.). For me, this unfortunately renders fdm unusable for this purpose, that's why I wrote “partially“ in the first paragraph. The same problem occurs when fetching mail which has been read/replied to before from an imap server.

Therefore, two feature requests:

1. Add standard flags to messages fetched from maildir or imap

When fetching from an imap or maildir source, fdm adds the flags of a message as tags flag_seen, flag_answered, flag_flagged, flag_deleted flag_draft, flag_recent, flag_passed (flag_recent is imap-specific, flag_passed maildir-specific). For reference: maildir flags (at the bottom) and imap-flags (RFC3501, Section 2.3.2).

2. Optionally honor flags when delivering to a maildir

A global configuration option honor-flags is introduced. Upon setting this option, when delivering to a maildir, fdm honors the presence (in the case of flag_recent absence) of at least one of the flag-tags described in the first feature request to decide whether to place a message into cur or new and altering the filename of the respective message to indicate the presence of the respective flags according to the specification.

herrsimon commented 1 year ago

In case you decide that the proposed functionality is beyond the scope of fdm (or somebody else reads this and wants to have a quick solution for the maildir-case):

How about simply adding a tag, say source_file, containing the name (including full path) of the source file when reading from a maildir? Then one could first deliver to a maildir and then use the source_file and mail_file tags to do the necessary renaming via an action.

The change to have fdm add the tag is of course trivial, one just needs to add

add_tag(&m->tags, "source_file", "%s", name);

at line 399 of fetch-maildir.c.

Then the action

action "sync_flags" exec
"FLAGS=$(perl -e '\"%[source_file]\" =~ /:2,(D?F?P?R?S?T?)$/; print $1;') ;" +
"if [ -n \"\${FLAGS}\" ] ; then " +
"mf=\"%[mail_file]\" ;" +
"mv \"\${mf}\"  \"\${mf%%/*}\"/../cur/\"\${mf##*/}:2,\${FLAGS}\" ;" +
"fi"

will do the trick (adopted from the maildir-mark-as-read-action found in EXAMPLES/f-terbeck.conf). Full flag synchronization is a bit cumbersome to configure this way and it also doesn't solve the issue when fetching from an IMAP-server, but for me it's good enough.