Skip to content

Commit

Permalink
Merge pull request #4867 from cyrusimap/replicaonly-reset
Browse files Browse the repository at this point in the history
Replicaonly reset
  • Loading branch information
brong committed Mar 27, 2024
2 parents fda0d0a + f7e61b8 commit d8da38b
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 23 deletions.
4 changes: 2 additions & 2 deletions imap/mailbox.c
Expand Up @@ -6568,7 +6568,7 @@ HIDDEN int mailbox_rename_nocopy(struct mailbox *oldmailbox,
mbentry_t *tempmb = oldmailbox->mbentry;
oldmailbox->local_cstate = newcstate;
oldmailbox->mbentry = newmbentry;
r = mailbox_add_conversations(oldmailbox, /*silent*/0);
r = mailbox_add_conversations(oldmailbox, oldmailbox->silentchanges);
oldmailbox->mbentry = tempmb;
oldmailbox->local_cstate = tempcs;
}
Expand Down Expand Up @@ -6685,7 +6685,7 @@ HIDDEN int mailbox_rename_copy(struct mailbox *oldmailbox,
if (oldcstate)
r = mailbox_delete_conversations(oldmailbox);
if (!r && newcstate)
r = mailbox_add_conversations(newmailbox, /*silent*/0);
r = mailbox_add_conversations(newmailbox, newmailbox->silentchanges);
}
if (r) goto fail;

Expand Down
31 changes: 15 additions & 16 deletions imap/mboxlist.c
Expand Up @@ -2299,6 +2299,7 @@ EXPORTED int mboxlist_deletemailbox(const char *name, int isadmin,
int keep_intermediaries = flags & MBOXLIST_DELETE_KEEP_INTERMEDIARIES;
int silent = flags & MBOXLIST_DELETE_SILENT;
int unprotect_specialuse = flags & MBOXLIST_DELETE_UNPROTECT_SPECIALUSE;
int isentirely = flags & MBOXLIST_DELETE_ENTIRELY;

init_internal();

Expand Down Expand Up @@ -2421,7 +2422,20 @@ EXPORTED int mboxlist_deletemailbox(const char *name, int isadmin,
}
if (r && !force) goto done;

if (!isremote && !mboxname_isdeletedmailbox(name, NULL)) {
/* delete underlying mailbox */
if (!isremote && mailbox) {
/* only on a real delete do we delete from the remote end as well */
sync_log_unmailbox(mailbox_name(mailbox));
mboxevent_extract_mailbox(mboxevent, mailbox);
mboxevent_set_access(mboxevent, NULL, NULL, userid, mailbox_name(mailbox), 1);

r = mailbox_delete(&mailbox);
/* abort event notification */
if (r && mboxevent)
mboxevent_free(&mboxevent);
}

if (!isremote && !isentirely && !mboxname_isdeletedmailbox(name, NULL)) {
/* store a DELETED marker */
int haschildren = mboxlist_haschildren(name);
mbentry_t *newmbentry = mboxlist_entry_create();
Expand Down Expand Up @@ -2464,21 +2478,6 @@ EXPORTED int mboxlist_deletemailbox(const char *name, int isadmin,
if (r && !force) goto done;
}


/* delete underlying mailbox */
if (!isremote && mailbox) {
/* only on a real delete do we delete from the remote end as well */
sync_log_unmailbox(mailbox_name(mailbox));
mboxevent_extract_mailbox(mboxevent, mailbox);
mboxevent_set_access(mboxevent, NULL, NULL, userid, mailbox_name(mailbox), 1);

r = mailbox_delete(&mailbox);
/* abort event notification */
if (r && mboxevent)
mboxevent_free(&mboxevent);
}


done:
mailbox_close(&mailbox);
mboxlist_entry_free(&mbentry);
Expand Down
2 changes: 2 additions & 0 deletions imap/mboxlist.h
Expand Up @@ -240,6 +240,8 @@ int mboxlist_createmailboxlock(const mbentry_t *mbentry,
#define MBOXLIST_DELETE_SILENT (1<<4)
/* unprotect_specialuse ignores the specialuse_protect config */
#define MBOXLIST_DELETE_UNPROTECT_SPECIALUSE (1<<5)
/* for sync_reset - wipe everything */
#define MBOXLIST_DELETE_ENTIRELY (1<<6)
/* delayed delete */
/* Translate delete into rename */
/* prepare MailboxDelete notification if mboxevent is not NULL */
Expand Down
6 changes: 1 addition & 5 deletions imap/sync_reset.c
Expand Up @@ -155,17 +155,13 @@ static int reset_single(const char *userid)
for (i = mblist->count; i; i--) {
const char *name = strarray_nth(mblist, i-1);
int delflags = MBOXLIST_DELETE_FORCE | MBOXLIST_DELETE_SILENT |
MBOXLIST_DELETE_LOCALONLY;
MBOXLIST_DELETE_LOCALONLY | MBOXLIST_DELETE_ENTIRELY;
r = mboxlist_deletemailbox(name, 1, sync_userid, sync_authstate,
NULL, delflags);
if (r == IMAP_MAILBOX_NONEXISTENT) {
printf("skipping already removed mailbox %s\n", name);
}
else if (r) goto fail;
/* XXX - cheap and nasty hack around actually cleaning up the entry */
r = mboxlist_deleteremote(name, NULL);
if (r == IMAP_MAILBOX_NONEXISTENT) r = 0;
if (r) goto fail;
}

if (mbentry) r = user_deletedata(mbentry, 1);
Expand Down

0 comments on commit d8da38b

Please sign in to comment.