Skip to content

Commit

Permalink
imapd.c: make sure we delete XFERed mailboxes from source (issue #4370)
Browse files Browse the repository at this point in the history
this commit also removes an extra write to mailboxes.db,
since mboxlist_deletemailbox() already sets MBTYPE_DELETED
  • Loading branch information
ksmurchison committed Aug 8, 2023
1 parent ed02770 commit 821bd0d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 26 deletions.
27 changes: 3 additions & 24 deletions imap/imapd.c
Original file line number Diff line number Diff line change
Expand Up @@ -12503,7 +12503,6 @@ static int xfer_reactivate(struct xfer_header *xfer)

static int xfer_delete(struct xfer_header *xfer)
{
mbentry_t *newentry = NULL;
struct xfer_item *item;
int r;

Expand All @@ -12512,38 +12511,18 @@ static int xfer_delete(struct xfer_header *xfer)
/* 7) local delete of mailbox
* & remove local "remote" mailboxlist entry */
for (item = xfer->items; item; item = item->next) {
/* Set mailbox as DELETED on local server
(need to also reset to local partition,
otherwise mailbox can not be opened for deletion) */
/* XXX - this code is awful... need a sane way to manage mbentries */
newentry = mboxlist_entry_create();
newentry->name = xstrdupnull(item->mbentry->name);
newentry->uniqueid = xstrdupnull(item->mbentry->uniqueid);
newentry->acl = xstrdupnull(item->mbentry->acl);
newentry->server = xstrdupnull(item->mbentry->server);
newentry->partition = xstrdupnull(item->mbentry->partition);
newentry->mbtype = item->mbentry->mbtype | MBTYPE_DELETED;
r = mboxlist_updatelock(newentry, 1);
mboxlist_entry_free(&newentry);

if (r) {
syslog(LOG_ERR,
"Could not move mailbox: %s, mboxlist_update failed (%s)",
item->mbentry->name, error_message(r));
}

/* Note that we do not check the ACL, and we don't update MUPDATE */
/* note also that we need to remember to let proxyadmins do this */
/* On a unified system, the subsequent MUPDATE PUSH on the remote
should repopulate the local mboxlist entry */
r = mboxlist_deletemailboxlock(item->mbentry->name,
imapd_userisadmin || imapd_userisproxyadmin,
imapd_userid, imapd_authstate, NULL,
MBOXLIST_DELETE_LOCALONLY);
MBOXLIST_DELETE_LOCALONLY|MBOXLIST_DELETE_FORCE);
if (r) {
syslog(LOG_ERR,
"Could not delete local mailbox during move of %s",
item->mbentry->name);
"Could not delete local mailbox during move of %s: %s",
item->mbentry->name, error_message(r));
/* can't abort now! */
}
}
Expand Down
9 changes: 7 additions & 2 deletions imap/mboxlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -2380,7 +2380,11 @@ EXPORTED int mboxlist_deletemailbox(const char *name, int isadmin,

/* Lock the mailbox if it isn't a remote mailbox */
if (!isremote) {
r = mailbox_open_iwl(name, &mailbox);
if (force) {
/* Allow deleting moved (XFERed) mailboxes */
mbentry->mbtype &= ~MBTYPE_MOVING;
}
r = mailbox_open_from_mbe(mbentry, &mailbox);
if (!r) mailbox->silentchanges = silent;
}
if (r && !force) goto done;
Expand Down Expand Up @@ -2409,7 +2413,8 @@ EXPORTED int mboxlist_deletemailbox(const char *name, int isadmin,
int haschildren = mboxlist_haschildren(name);
mbentry_t *newmbentry = mboxlist_entry_create();
newmbentry->name = xstrdupnull(name);
newmbentry->mbtype |= haschildren ? MBTYPE_INTERMEDIATE : MBTYPE_DELETED;
newmbentry->mbtype = mbentry->mbtype |
(haschildren ? MBTYPE_INTERMEDIATE : MBTYPE_DELETED);
if (mailbox) {
newmbentry->uniqueid = xstrdupnull(mailbox_uniqueid(mailbox));
newmbentry->uidvalidity = mailbox->i.uidvalidity;
Expand Down

0 comments on commit 821bd0d

Please sign in to comment.