Commit ed04bc83 ed04bc837e353e61e4c43f6bdbd9a67859c61f61 by Sergey Poznyakoff

Fix delivery to MH and Maildir mailboxes

After successful delivery, maidag would switch back to root privileges
too early, due to which the mailbox would be closed when running with
root UID.  I the property file (.mu-prop) did not exist, it would
therefore be created by root.  Subsequent attempts to open it by user
would fail.  One of consequences is that the UIDVALIDITY value would
be recalculated each time the mailbox is opened.  This would force
imap4 clients to rescan mailboxes infinitely, as each scan would change
the UIDVALIDITY again.

This patch fixes the initialization of UIDVALIDITY and fixes maidag to
switch back to root privileges only after closing the mailbox.  It also
makes sure MH and Maildir mailboxes write .mu-prop upon closing, not
upon destroying the mailbox.

* libmailutils/base/amd.c (amd_close): Save property.
(_amd_scan0): Use mailbox modification time as initial
uidvalidity value.
* maidag/deliver.c (deliver_to_mailbox): Remove uselsess UID/GID
transitions.
1 parent 1186b695
......@@ -519,6 +519,8 @@ amd_close (mu_mailbox_t mailbox)
free (amd->msg_array);
amd->msg_array = NULL;
mu_property_save (amd->prop);
amd->msg_count = 0; /* number of messages in the list */
amd->msg_max = 0; /* maximum message buffer capacity */
......@@ -675,7 +677,7 @@ _amd_scan0 (struct _amd_data *amd, size_t msgno, size_t *pcount,
_amd_prop_fetch_ulong (amd, _MU_AMD_PROP_UIDVALIDITY, &uidval) ||
!uidval)
{
uidval = (unsigned long)time (NULL);
uidval = (unsigned long) amd->mtime;
_amd_prop_store_off (amd, _MU_AMD_PROP_UIDVALIDITY, uidval);
}
return 0;
......
......@@ -225,7 +225,7 @@ deliver_to_mailbox (mu_mailbox_t mbox, mu_message_t msg,
}
#endif
if (!failed && switch_user_id (auth, 1) == 0)
if (!failed)
{
status = mu_mailbox_append_message (mbox, msg);
if (status)
......@@ -244,7 +244,6 @@ deliver_to_mailbox (mu_mailbox_t mbox, mu_message_t msg,
failed++;
}
}
switch_user_id (auth, 0);
}
mu_mailbox_close (mbox);
......