diff options
author | Sergey Poznyakoff <gray@gnu.org> | 2020-11-15 18:47:49 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org> | 2020-11-15 18:52:36 +0200 |
commit | d7110faad78c2095ca39e380a7a3a6cdff413b2e (patch) | |
tree | 671391eeaf856406fa3525585bb7268e8234b336 | |
parent | 83893fe3aba60d2e61964135e448b30ab7ff3ed5 (diff) | |
download | mailutils-d7110faad78c2095ca39e380a7a3a6cdff413b2e.tar.gz mailutils-d7110faad78c2095ca39e380a7a3a6cdff413b2e.tar.bz2 |
Encode all Mailutils attributes in maildir file names
The attributes that have no corresponding info letters are
encoded in the 'a' name attribute as a string of mailutils
status flags, e.g.:
1284628225.M17468P3883Q0.localhost,a=FO,u=1:2,S
Meaning: MU_ATTRIBUTE_READ (from the info letter 'S'),
MU_ATTRIBUTE_FLAGGED (attr. 'F') and MU_ATTRIBUTE_SEEN (attr. 'O').
* libproto/maildir/mbox.c (maildir_message_alloc): Parse the
'a' attribute.
(maildir_subdir_scan): Don't force MU_ATTRIBUTE_SEEN on existing
messages.
(maildir_message_fixup): Fixup the (original) MU_ATTRIBUTE_SEEN
attribute.
* libproto/maildir/tests/attfixup.at: Update.
* libproto/maildir/tests/attr.at: Update.
-rw-r--r-- | libproto/dotmail/tests/autodetect.at | 1 | ||||
-rw-r--r-- | libproto/maildir/mbox.c | 43 | ||||
-rw-r--r-- | libproto/maildir/tests/attfixup.at | 19 | ||||
-rw-r--r-- | libproto/maildir/tests/attr.at | 8 |
4 files changed, 49 insertions, 22 deletions
diff --git a/libproto/dotmail/tests/autodetect.at b/libproto/dotmail/tests/autodetect.at index 90270cb84..730b4d79f 100644 --- a/libproto/dotmail/tests/autodetect.at +++ b/libproto/dotmail/tests/autodetect.at @@ -110,6 +110,7 @@ do mbop --mailbox $mbox --detect done done +exit 0 ], [0], [MU_AUTODETECT_ACCURACY=0 diff --git a/libproto/maildir/mbox.c b/libproto/maildir/mbox.c index ac5f244d9..ba7a38b55 100644 --- a/libproto/maildir/mbox.c +++ b/libproto/maildir/mbox.c @@ -566,7 +566,7 @@ maildir_message_alloc (struct _maildir_data *md, int subdir, char const *name, { struct _maildir_message *msg; size_t n; - static char *attrnames[] = { "u", NULL }; + static char *attrnames[] = { "a", "u", NULL }; struct attrib *attrs; char const *p; @@ -592,6 +592,13 @@ maildir_message_alloc (struct _maildir_data *md, int subdir, char const *name, } msg->uniq_len = n; + if ((p = attrib_lookup (attrs, "a")) != NULL) + { + /* NOTICE: mu_attribute_string_to_flags preserves existing bits + in its second argument. */ + mu_attribute_string_to_flags (p, &msg->amd_message.attr_flags); + } + if ((p = attrib_lookup (attrs, "u")) != NULL) { char *endp; @@ -695,10 +702,6 @@ maildir_subdir_scan (struct _maildir_data *md, int subdir) rc = maildir_message_alloc (md, subdir, entry->d_name, &msg); - if (subdir == SUB_CUR) - /* FIXME: Implement MU_ATTRIBUTE_SEEN via attribs */ - msg->amd_message.attr_flags |= MU_ATTRIBUTE_SEEN; - if (!amd_msg_lookup (&md->amd, (struct _amd_message *) msg, &index)) { /* should not happen */ @@ -816,7 +819,12 @@ maildir_message_fixup (struct _maildir_data *md, struct _maildir_message *msg) { int flags = msg->amd_message.attr_flags; - flags &= ~MU_ATTRIBUTE_READ; + if (flags & MU_ATTRIBUTE_READ) + { + flags &= ~MU_ATTRIBUTE_READ; + flags |= MU_ATTRIBUTE_SEEN; + } + if (flags & MU_ATTRIBUTE_ANSWERED) { flags &= ~MU_ATTRIBUTE_ANSWERED; @@ -1112,6 +1120,28 @@ string_buffer_format_flags (struct string_buffer *buf, int flags) return string_buffer_appendz (buf, fbuf); } +/* Format mailutils-specific attribute flags to the string buffer. + Mailutils-specific flags are the flags that have no corresponding + info letter in the maildir memo. These flags are encoded in the + 'a' attribute setting. +*/ +static int +string_buffer_format_mu_flags (struct string_buffer *buf, int flags) +{ + int rc = 0; + char fb[MU_STATUS_BUF_SIZE]; + size_t len; + + mu_attribute_flags_to_string (flags & (MU_ATTRIBUTE_FLAGGED|MU_ATTRIBUTE_SEEN), + fb, sizeof (fb), &len); + if (len > 0) + { + if ((rc = string_buffer_append (buf, ",a=", 3)) == 0) + rc = string_buffer_append (buf, fb, len); + } + return rc; +} + static int string_buffer_format_message_name (struct string_buffer *buf, struct _maildir_message *msg, @@ -1120,6 +1150,7 @@ string_buffer_format_message_name (struct string_buffer *buf, int rc; if ((rc = string_buffer_append (buf, msg->file_name, msg->uniq_len)) == 0 && + (rc = string_buffer_format_mu_flags (buf, flags)) == 0 && (rc = string_buffer_append (buf, ",u=", 3)) == 0 && (rc = string_buffer_format_long (buf, msg->uid, 10)) == 0 && (rc = string_buffer_format_flags (buf, flags)) == 0) diff --git a/libproto/maildir/tests/attfixup.at b/libproto/maildir/tests/attfixup.at index e532be0a0..facb1687e 100644 --- a/libproto/maildir/tests/attfixup.at +++ b/libproto/maildir/tests/attfixup.at @@ -20,25 +20,18 @@ cp inbox/.mu-prop saved_mu_prop ], [0], [count: 5 -inbox/cur/1284628225.M17468P3883Q0.Trurl,u=1:2, -inbox/cur/1284628225.M19181P3883Q1.Trurl,u=2:2,S -inbox/cur/1284628225.M20118P3883Q2.Trurl,u=3:2, -inbox/cur/1284628225.M21284P3883Q3.Trurl,u=4:2, -inbox/cur/1284628225.M22502P3883Q4.Trurl,u=5:2, +inbox/cur/1284628225.M17468P3883Q0.Trurl,a=O,u=1:2, +inbox/cur/1284628225.M19181P3883Q1.Trurl,a=O,u=2:2,S +inbox/cur/1284628225.M20118P3883Q2.Trurl,a=O,u=3:2, +inbox/cur/1284628225.M21284P3883Q3.Trurl,a=O,u=4:2, +inbox/cur/1284628225.M22502P3883Q4.Trurl,a=O,u=5:2, ]) AT_CHECK([ -set -e mbop -m inbox count -find inbox/cur -type f | sort ], [0], [count: 5 -inbox/cur/1284628225.M17468P3883Q0.Trurl,u=1:2, -inbox/cur/1284628225.M19181P3883Q1.Trurl,u=2:2,S -inbox/cur/1284628225.M20118P3883Q2.Trurl,u=3:2, -inbox/cur/1284628225.M21284P3883Q3.Trurl,u=4:2, -inbox/cur/1284628225.M22502P3883Q4.Trurl,u=5:2, ]) AT_CHECK([ @@ -48,4 +41,4 @@ cat inbox/.mu-prop [0], [expout]) -AT_CLEANUP
\ No newline at end of file +AT_CLEANUP diff --git a/libproto/maildir/tests/attr.at b/libproto/maildir/tests/attr.at index 56825930b..1e916d34e 100644 --- a/libproto/maildir/tests/attr.at +++ b/libproto/maildir/tests/attr.at @@ -16,8 +16,8 @@ AT_SETUP([attributes]) AT_DATA([names], -[cur/1284628225.M17468P3883Q0.Trurl,u=1:2, -cur/1284628225.M19181P3883Q1.Trurl,u=20:2,S +[cur/1284628225.M17468P3883Q0.Trurl,a=O,u=1:2, +cur/1284628225.M19181P3883Q1.Trurl,a=O,u=20:2,S cur/1284628225.M20118P3883Q2.Trurl,u=22:2, cur/1284628225.M21284P3883Q3.Trurl,u=43:2, cur/1284628225.M22502P3883Q4.Trurl,u=50:2, @@ -45,6 +45,7 @@ set_draft 5 # Set the answered attribute set_answered +set_seen # Synchronize with the disk storage sync ]) @@ -56,6 +57,7 @@ mbop -m inbox < commands 3 set_draft: OK 5 current message 5 set_answered: OK +5 set_seen: OK sync: OK ]) AT_CHECK([ @@ -63,7 +65,7 @@ mbop -m inbox 3 \; attr \; 5 \; attr ], [0], [3 current message -3 attr: dOR +3 attr: dR 5 current message 5 attr: AO ]) |