if (m->magic != MUTT_IMAP)
return -1;
+ // NOTE(sileht): The goal is to use ImapMbox and imap_parse_path() only here
+ // So we can remove it at this end.
+ struct ImapMbox mx;
+
+ if (imap_parse_path(m->path, &mx) < 0)
+ return -1;
+
// if (a->type == MUTT_UNKNOWN)
if (!a->adata)
{
struct ImapAccountData *adata = imap_adata_new();
- struct ImapMbox mx;
a->magic = MUTT_IMAP;
a->adata = adata;
a->free_adata = imap_adata_free;
-
- if (imap_parse_path(m->path, &mx) < 0)
- return -1;
- FREE(&mx.mbox);
adata->conn_account = mx.account;
adata->conn = mutt_conn_new(&adata->conn_account);
if (!adata->conn)
+ {
+ FREE(&mx.mbox);
return -1;
+ }
}
m->account = a;
+ if (!m->mdata)
+ {
+ struct ImapMailboxData *mdata = imap_mdata_new(a->adata, mx.mbox);
+ if (!mdata)
+ {
+ FREE(&mx.mbox);
+ return -1;
+ }
+ m->mdata = mdata;
+ m->free_mdata = imap_mdata_free;
+ }
+
struct MailboxNode *np = mutt_mem_calloc(1, sizeof(*np));
np->m = m;
STAILQ_INSERT_TAIL(&a->mailboxes, np, entries);
#endif
};
+/**
+ * struct ImapMailboxData - IMAP-specific Mailbox data
+ *
+ * This data is specific to a Mailbox of an IMAP server
+ */
+struct ImapMailboxData
+{
+ char *name;
+ char *munge_name;
+ char *real_name;
+};
+
/**
* struct SeqsetIterator - UID Sequence Set Iterator
*/
void imap_error(const char *where, const char *msg);
struct ImapAccountData *imap_adata_new(void);
void imap_adata_free(void **ptr);
+struct ImapMailboxData *imap_mdata_new(struct ImapAccountData *adata, const char* name);
+void imap_mdata_free(void **ptr);
char *imap_fix_path(struct ImapAccountData *adata, const char *mailbox, char *path, size_t plen);
void imap_cachepath(struct ImapAccountData *adata, const char *mailbox, char *dest, size_t dlen);
int imap_get_literal_count(const char *buf, unsigned int *bytes);
*/
struct ImapAccountData *imap_adata_get(struct Mailbox *m)
{
- if (!m || (m->magic != MUTT_IMAP))
+ if (!m || (m->magic != MUTT_IMAP) || !m->account)
return NULL;
- struct Account *a = m->account;
- if (!a)
- return NULL;
- return a->adata;
+ return m->account->adata;
}
/**
return NULL;
}
+/**
+ * imap_mdata_new - Allocate and initialise a new ImapMailboxData structure
+ * @retval ptr New ImapMailboxData
+ */
+struct ImapMailboxData *imap_mdata_new(struct ImapAccountData *adata, const char *name)
+{
+ char buf[LONG_STRING];
+ struct ImapMailboxData *mdata = mutt_mem_calloc(1, sizeof(struct ImapMailboxData));
+
+ mdata->real_name = mutt_str_strdup(name);
+
+ imap_fix_path(adata, name, buf, sizeof(buf));
+ if (!*buf)
+ mutt_str_strfcpy(buf, "INBOX", sizeof(buf));
+ mdata->name = mutt_str_strdup(buf);
+
+ imap_munge_mbox_name(adata, buf, sizeof(buf), mdata->name);
+ mdata->munge_name = mutt_str_strdup(buf);
+
+ return mdata;
+}
+
+/**
+ * imap_mdata_free - Release and clear storage in an ImapMailboxData structure
+ * @param ptr Imap Mailbox data
+ */
+void imap_mdata_free(void **ptr)
+{
+ if (!ptr || !*ptr)
+ return;
+
+ struct ImapMailboxData *mdata = *ptr;
+
+ FREE(&mdata->name);
+ FREE(&mdata->real_name);
+ FREE(&mdata->munge_name);
+ FREE(ptr);
+}
+
+/**
+ * imap_mdata_get - Get the Mailbox data for this mailbox
+ */
+struct ImapMailboxData *imap_mdata_get(struct Mailbox *m)
+{
+ if (!m || (m->magic != MUTT_IMAP) || !m->mdata)
+ return NULL;
+ return m->mdata;
+}
+
/**
* imap_get_parent - Get an IMAP folder's parent
* @param mbox Mailbox whose parent is to be determined