diff options
author | Sergey Poznyakoff <gray@gnu.org> | 2020-11-20 15:23:12 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org> | 2020-11-20 15:23:12 +0200 |
commit | ae91979e9664d99204beb116b9b5e4122e43938e (patch) | |
tree | e48011818ae171f2ca49218b90175df94fbf4205 | |
parent | 18aff26c654c04f7ca3ffa33f997305e3942706d (diff) | |
download | mailutils-ae91979e9664d99204beb116b9b5e4122e43938e.tar.gz mailutils-ae91979e9664d99204beb116b9b5e4122e43938e.tar.bz2 |
dotmail: update uids in append mode as well.
* include/mailutils/sys/dotmail.h (mu_dotmail_mailbox): New member
stream_flags.
* libproto/dotmail/dotmail.c (dotmail_mailbox_init_stream): Translate
MU_STREAM_APPEND to MU_STREAM_RDWR.
(dotmail_rescan_unlocked,dotmail_rescan): Check actual stream flags,
not the mailbox ones.
(dotmail_flush_unlocked): Remove check for MU_STREAM_APPEND.
* libproto/dotmail/tests/append.at: Test appends in append mode.
* testsuite/mbop.c: New option -a (--append).
-rw-r--r-- | include/mailutils/sys/dotmail.h | 3 | ||||
-rw-r--r-- | libproto/dotmail/dotmail.c | 17 | ||||
-rw-r--r-- | libproto/dotmail/tests/append.at | 61 | ||||
-rw-r--r-- | testsuite/mbop.c | 7 |
4 files changed, 80 insertions, 8 deletions
diff --git a/include/mailutils/sys/dotmail.h b/include/mailutils/sys/dotmail.h index 9510ab1bf..16b60177a 100644 --- a/include/mailutils/sys/dotmail.h +++ b/include/mailutils/sys/dotmail.h @@ -62,7 +62,8 @@ struct mu_dotmail_mailbox { char *name; /* Disk file name */ mu_mailbox_t mailbox; /* Associated mailbox */ - + int stream_flags; /* Flags used to create the mailbox stream */ + mu_off_t size; /* Size of the mailbox. */ unsigned long uidvalidity; /* Uidvalidity value */ unsigned long uidnext; /* Expected next UID value */ diff --git a/libproto/dotmail/dotmail.c b/libproto/dotmail/dotmail.c index 5f8d629cb..ce06e5f07 100644 --- a/libproto/dotmail/dotmail.c +++ b/libproto/dotmail/dotmail.c @@ -69,7 +69,15 @@ dotmail_mailbox_init_stream (struct mu_dotmail_mailbox *dmp) int rc; mu_mailbox_t mailbox = dmp->mailbox; - rc = mu_mapfile_stream_create (&mailbox->stream, dmp->name, mailbox->flags); + /* + * Initialize stream flags. If append mode is requested, convert it to + * read-write, so that dotmail_flush_unlocked be able to update the + * X-IMAPbase header in the first message, if necessary. + */ + dmp->stream_flags = mailbox->flags; + if (dmp->stream_flags & MU_STREAM_APPEND) + dmp->stream_flags = (dmp->stream_flags & ~MU_STREAM_APPEND) | MU_STREAM_RDWR; + rc = mu_mapfile_stream_create (&mailbox->stream, dmp->name, dmp->stream_flags); if (rc) { mu_debug (MU_DEBCAT_MAILBOX, MU_DEBUG_ERROR, @@ -376,7 +384,7 @@ dotmail_rescan_unlocked (mu_mailbox_t mailbox, mu_off_t offset) int i, j; int force_init_uids = 0; - if (!(mailbox->flags & MU_STREAM_READ)) + if (!(dmp->stream_flags & MU_STREAM_READ)) return 0; rc = mu_streamref_create (&stream, mailbox->stream); @@ -665,7 +673,7 @@ dotmail_rescan (mu_mailbox_t mailbox, mu_off_t offset) if (!dmp) return EINVAL; - if (!(mailbox->flags & MU_STREAM_READ)) + if (!(dmp->stream_flags & MU_STREAM_READ)) return 0; mu_monitor_wrlock (mailbox->monitor); @@ -1307,9 +1315,6 @@ dotmail_flush_unlocked (struct mu_dotmail_flush_tracker *trk, int mode) if (mode == FLUSH_UIDVALIDITY && !dmp->uidvalidity_changed) return 0; - if (dmp->mailbox->flags & MU_STREAM_APPEND)//FIXME - return mu_stream_flush (dmp->mailbox->stream); - rc = dotmail_refresh (dmp->mailbox); if (rc) return rc; diff --git a/libproto/dotmail/tests/append.at b/libproto/dotmail/tests/append.at index 0eb471524..ae4b28273 100644 --- a/libproto/dotmail/tests/append.at +++ b/libproto/dotmail/tests/append.at @@ -230,3 +230,64 @@ Return-Path:hare@wonder.land 1 body_text: Have some wine ]) +# +# Test whether UIDs are updated in append mode. +# +AT_SETUP([append mode]) +AT_DATA([inbox], +[Received: (from hare@wonder.land) + by wonder.land id 3301 + for alice@wonder.land; Mon, 29 Jul 2002 22:00:06 +0100 +Date: Mon, 29 Jul 2002 22:00:01 +0100 +From: March Hare <hare@wonder.land> +Message-Id: <200207292200.3301@wonder.land> +To: Alice <alice@wonder.land> +Subject: Invitation +Return-Path: hare@wonder.land +X-IMAPbase: 10 3 +X-UID: 1 + +Have some wine +. +Received: (from alice@wonder.land) + by wonder.land id 3302 + for hare@wonder.land; Mon, 29 Jul 2002 22:00:07 +0100 +Date: Mon, 29 Jul 2002 22:00:02 +0100 +From: Alice <alice@wonder.land> +Message-Id: <200207292200.3302@wonder.land> +To: March Hare <hare@wonder.land> +Subject: Re: Invitation +Return-Path: alice@wonder.land +X-UID: 2 + +I don't see any wine +. +]) +AT_DATA([msg], +[Received: (from hare@wonder.land) + by wonder.land id 3303 + for alice@wonder.land; Mon, 29 Jul 2002 22:00:08 +0100 +Date: Mon, 29 Jul 2002 22:00:03 +0100 +From: March Hare <hare@wonder.land> +Message-Id: <200207292200.3303@wonder.land> +To: Alice <alice@wonder.land> +Subject: Re: Invitation +Return-Path: hare@wonder.land + +There isn't any +]) +AT_CHECK([mbop -a -m inbox append msg], +[0], +[append: OK +]) +AT_CHECK([grep X-UID inbox], +[0], +[X-UID: 1 +X-UID: 2 +X-UID: 3 +]) +AT_CHECK([grep X-IMAPbase inbox | tr -s ' '], +[0], +[X-IMAPbase: 10 4 +]) +AT_CLEANUP diff --git a/testsuite/mbop.c b/testsuite/mbop.c index ee7de5a1f..3b511f7e5 100644 --- a/testsuite/mbop.c +++ b/testsuite/mbop.c @@ -515,6 +515,7 @@ main (int argc, char **argv) int debug_option = 0; int detect_option = 0; int notify_option = 0; + int append_option = 0; struct mu_option options[] = { { "debug", 'd', NULL, MU_OPTION_DEFAULT, "enable debugging", @@ -528,6 +529,9 @@ main (int argc, char **argv) { "notify", 'N', NULL, MU_OPTION_DEFAULT, "test notification code", mu_c_incr, ¬ify_option }, + { "append", 'a', NULL, MU_OPTION_DEFAULT, + "open mailbox in append mode", + mu_c_incr, &append_option }, MU_OPTION_END }; @@ -566,7 +570,8 @@ main (int argc, char **argv) } MU_ASSERT (mu_mailbox_create_default (&env.mbx, env.mbxname)); - MU_ASSERT (mu_mailbox_open (env.mbx, MU_STREAM_RDWR)); + MU_ASSERT (mu_mailbox_open (env.mbx, + append_option ? MU_STREAM_APPEND : MU_STREAM_RDWR)); if (notify_option) { |