Skip to content

Commit

Permalink
mboxlist.c: add 'U' field (user inboxid) to mbentry_t
Browse files Browse the repository at this point in the history
  • Loading branch information
ksmurchison committed Mar 12, 2024
1 parent 0c2ebac commit b4b5e04
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
5 changes: 5 additions & 0 deletions imap/mailbox.c
Original file line number Diff line number Diff line change
Expand Up @@ -1133,6 +1133,11 @@ EXPORTED const char *mailbox_uniqueid(const struct mailbox *mailbox)
return mbentry->uniqueid ? mbentry->uniqueid : mailbox->h.uniqueid;
}

EXPORTED const char *mailbox_inboxid(const struct mailbox *mailbox)
{
return mailbox->mbentry->inboxid;
}

EXPORTED const char *mailbox_partition(const struct mailbox *mailbox)
{
return mailbox->mbentry->partition;
Expand Down
1 change: 1 addition & 0 deletions imap/mailbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,7 @@ extern int mailbox_delete(struct mailbox **mailboxptr);
/* reading details */
extern const char *mailbox_name(const struct mailbox *mailbox);
extern const char *mailbox_uniqueid(const struct mailbox *mailbox);
extern const char *mailbox_inboxid(const struct mailbox *mailbox);
extern const char *mailbox_partition(const struct mailbox *mailbox);
extern const char *mailbox_acl(const struct mailbox *mailbox);
extern const char *mailbox_quotaroot(const struct mailbox *mailbox);
Expand Down
19 changes: 18 additions & 1 deletion imap/mboxlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ EXPORTED mbentry_t *mboxlist_entry_copy(const mbentry_t *src)
copy->server = xstrdupnull(src->server);
copy->acl = xstrdupnull(src->acl);
copy->uniqueid = xstrdupnull(src->uniqueid);
copy->inboxid = xstrdupnull(src->inboxid);

copy->legacy_specialuse = xstrdupnull(src->legacy_specialuse);

Expand Down Expand Up @@ -187,6 +188,7 @@ EXPORTED void mboxlist_entry_free(mbentry_t **mbentryptr)
free(mbentry->server);
free(mbentry->acl);
free(mbentry->uniqueid);
free(mbentry->inboxid);

free(mbentry->legacy_specialuse);

Expand Down Expand Up @@ -273,6 +275,9 @@ static struct dlist *mboxlist_entry_dlist(const char *dbname,
else if (mbentry->uniqueid)
dlist_setatom(dl, "I", mbentry->uniqueid);

if (mbentry->inboxid)
dlist_setatom(dl, "U", mbentry->inboxid);

if (mbentry->partition)
dlist_setatom(dl, "P", mbentry->partition);

Expand Down Expand Up @@ -618,6 +623,9 @@ static int parseentry_cb(int type, struct dlistsax_data *d)
else if (!strcmp(key, "I")) {
rock->mbentry->uniqueid = xstrdupnull(d->data);
}
else if (!strcmp(key, "U")) {
rock->mbentry->inboxid = xstrdupnull(d->data);
}
else if (!strcmp(key, "M")) {
rock->mbentry->mtime = atoi(d->data);
}
Expand Down Expand Up @@ -652,6 +660,7 @@ static int parseentry_cb(int type, struct dlistsax_data *d)
* F: _f_oldermodseq
* H: name_h_istory
* I: unique_i_d
* U: _u_serinboxid
* M: _m_time
* N: _n_ame
* P: _p_artition
Expand Down Expand Up @@ -1865,6 +1874,7 @@ EXPORTED int mboxlist_createmailbox(const mbentry_t *mbentry,
int isremote = mbtype & MBTYPE_REMOTE;
mbentry_t *usermbentry = NULL, *newmbentry = NULL;
int silent = 0;
int isinbox;

init_internal();

Expand All @@ -1874,6 +1884,8 @@ EXPORTED int mboxlist_createmailbox(const mbentry_t *mbentry,

assert_namespacelocked(mboxname);

isinbox = mboxname_isusermailbox(mboxname, 1);

if ((flags & MBOXLIST_CREATE_SYNC)) {
silent = 1;
}
Expand Down Expand Up @@ -1933,9 +1945,11 @@ EXPORTED int mboxlist_createmailbox(const mbentry_t *mbentry,
newmbentry->mbtype = mbtype;
newmbentry->partition = xstrdupnull(newpartition);
newmbentry->uniqueid = xstrdup(uniqueid ? uniqueid : makeuuid());
if (isinbox) newmbentry->inboxid = xstrdup(newmbentry->uniqueid);
else if (usermbentry) newmbentry->inboxid = xstrdup(usermbentry->uniqueid);

if (!(flags & MBOXLIST_CREATE_DBONLY) && !isremote) {
if (mboxname_isusermailbox(mboxname, 1)) {
if (isinbox) {
/* Create initial mbentry for new users --
the uniqueid in the record is required to open
user metadata files (conversations, counters) */
Expand Down Expand Up @@ -2766,6 +2780,7 @@ EXPORTED int mboxlist_renamemailbox(const mbentry_t *mbentry,
newmbentry->acl = xstrdupnull(mailbox_acl(oldmailbox));
newmbentry->uidvalidity = oldmailbox->i.uidvalidity;
newmbentry->uniqueid = xstrdupnull(mailbox_uniqueid(oldmailbox));
newmbentry->inboxid = xstrdupnull(mailbox_inboxid(oldmailbox));
newmbentry->createdmodseq = oldmailbox->i.createdmodseq;
newmbentry->foldermodseq = silent ? mailbox_foldermodseq(oldmailbox)
: mboxname_nextmodseq(newname, mailbox_foldermodseq(oldmailbox),
Expand Down Expand Up @@ -2830,6 +2845,7 @@ EXPORTED int mboxlist_renamemailbox(const mbentry_t *mbentry,
newmbentry->acl = xstrdupnull(mailbox_acl(newmailbox));
newmbentry->uidvalidity = newmailbox->i.uidvalidity;
newmbentry->uniqueid = xstrdupnull(mailbox_uniqueid(newmailbox));
newmbentry->inboxid = xstrdupnull(mailbox_inboxid(newmailbox));
newmbentry->createdmodseq = newmailbox->i.createdmodseq;
newmbentry->foldermodseq = newmailbox->i.highestmodseq;
}
Expand All @@ -2842,6 +2858,7 @@ EXPORTED int mboxlist_renamemailbox(const mbentry_t *mbentry,
newmbentry->acl = xstrdupnull(mailbox_acl(oldmailbox));
newmbentry->uidvalidity = oldmailbox->i.uidvalidity;
newmbentry->uniqueid = xstrdupnull(mailbox_uniqueid(oldmailbox));
newmbentry->inboxid = xstrdupnull(mailbox_inboxid(oldmailbox));
newmbentry->createdmodseq = oldmailbox->i.createdmodseq;
newmbentry->foldermodseq = oldmailbox->i.highestmodseq;

Expand Down
3 changes: 2 additions & 1 deletion imap/mboxlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,15 @@ struct mboxlist_entry {
char *acl;
/* extra fields */
char *uniqueid;
char *inboxid;
/* legacy upgrade support */
char *legacy_specialuse;
/* replication support */
ptrarray_t name_history;
};

#define MBENTRY_INITIALIZER { NULL, NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, \
NULL, NULL, PTRARRAY_INITIALIZER }
NULL, NULL, NULL, PTRARRAY_INITIALIZER }

typedef struct mboxlist_entry mbentry_t;

Expand Down

0 comments on commit b4b5e04

Please sign in to comment.