* Copyright (C) 1996-1998,2012 Michael R. Elkins <me@mutt.org>
* Copyright (C) 1996-1999 Brandon Long <blong@fiction.net>
* Copyright (C) 1999-2009,2012,2017 Brendan Cully <brendan@kublai.com>
+ * Copyright (C) 2018 Richard Russon <rich@flatcap.org>
*
* @copyright
* This program is free software: you can redistribute it and/or modify it under
#include "conn/conn.h"
#include "mutt.h"
#include "imap.h"
+#include "account.h"
#include "auth.h"
#include "bcache.h"
#include "commands.h"
}
mutt_socket_close((*adata)->conn);
- imap_adata_free(adata);
+ imap_adata_free((void **) adata);
}
/**
return rc;
}
+/**
+ * imap_ac_find - Find a Account that matches a Mailbox path
+ */
+struct Account *imap_ac_find(struct Account *a, const char *path)
+{
+ if (!a || (a->type != MUTT_IMAP) || !path)
+ return NULL;
+
+ struct Url url;
+ char tmp[PATH_MAX];
+ mutt_str_strfcpy(tmp, path, sizeof(tmp));
+ url_parse(&url, tmp);
+
+ struct ImapAccountData *adata = a->adata;
+ struct ConnAccount *ac = &adata->conn_account;
+
+ if (mutt_str_strcasecmp(url.host, ac->host) != 0)
+ return NULL;
+
+ if (mutt_str_strcasecmp(url.user, ac->user) != 0)
+ return NULL;
+
+ // if (mutt_str_strcmp(path, a->mailbox->realpath) == 0)
+ // return a;
+
+ return a;
+}
+
+/**
+ * imap_ac_add - Add a Mailbox to a Account
+ */
+int imap_ac_add(struct Account *a, struct Mailbox *m)
+{
+ if (!a || !m)
+ return -1;
+
+ if (m->magic != MUTT_IMAP)
+ return -1;
+
+ // if (a->type == MUTT_UNKNOWN)
+ if (!a->adata)
+ {
+ struct ImapAccountData *adata = imap_adata_new();
+ a->type = MUTT_IMAP;
+ a->adata = adata;
+ a->free_adata = imap_adata_free;
+
+ struct Url url;
+ char tmp[PATH_MAX];
+ mutt_str_strfcpy(tmp, m->path, sizeof(tmp));
+ url_parse(&url, tmp);
+
+ mutt_str_strfcpy(adata->conn_account.user, url.user,
+ sizeof(adata->conn_account.user));
+ mutt_str_strfcpy(adata->conn_account.pass, url.pass,
+ sizeof(adata->conn_account.pass));
+ mutt_str_strfcpy(adata->conn_account.host, url.host,
+ sizeof(adata->conn_account.host));
+ adata->conn_account.port = url.port;
+ }
+
+ m->account = a;
+
+ struct MailboxNode *np = mutt_mem_calloc(1, sizeof(*np));
+ np->m = m;
+ STAILQ_INSERT_TAIL(&a->mailboxes, np, entries);
+ return 0;
+}
+
/**
* imap_mbox_open - Implements MxOps::mbox_open()
*/
struct MxOps mx_imap_ops = {
.magic = MUTT_IMAP,
.name = "imap",
+ .ac_find = imap_ac_find,
+ .ac_add = imap_ac_add,
.mbox_open = imap_mbox_open,
.mbox_open_append = imap_mbox_open_append,
.mbox_check = imap_mbox_check,
* @authors
* Copyright (C) 1996-1999 Brandon Long <blong@fiction.net>
* Copyright (C) 1999-2009 Brendan Cully <brendan@kublai.com>
+ * Copyright (C) 2018 Richard Russon <rich@flatcap.org>
*
* @copyright
* This program is free software: you can redistribute it and/or modify it under
#include <stdio.h>
#include <time.h>
#include "mutt/mutt.h"
+#include "conn/conn.h"
#ifdef USE_HCACHE
#include "hcache/hcache.h"
#endif
-struct ConnAccount;
struct Context;
struct Email;
struct ImapEmailData;
struct ImapAccountData
{
struct Connection *conn;
+ struct ConnAccount conn_account;
+ struct Account *account;
bool recovering;
unsigned char state; ///< ImapState, e.g. #IMAP_AUTHENTICATED
unsigned char status; ///< ImapFlags, e.g. #IMAP_FATAL
/* The following data is all specific to the currently SELECTED mbox */
char delim;
struct Context *ctx;
+ struct Mailbox *mailbox;
char *mbox_name;
unsigned short check_status; /**< Flags, e.g. #IMAP_NEWMAIL_PENDING */
unsigned char reopen; /**< Flags, e.g. #IMAP_REOPEN_ALLOW */
int imap_continue(const char *msg, const char *resp);
void imap_error(const char *where, const char *msg);
struct ImapAccountData *imap_adata_new(void);
-void imap_adata_free(struct ImapAccountData **adata);
+void imap_adata_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);
/**
* imap_adata_free - Release and clear storage in an ImapAccountData structure
- * @param adata Imap Account data
+ * @param ptr Imap Account data
*/
-void imap_adata_free(struct ImapAccountData **adata)
+void imap_adata_free(void **ptr)
{
- if (!adata)
+ if (!ptr || !*ptr)
return;
- FREE(&(*adata)->capstr);
- mutt_list_free(&(*adata)->flags);
- imap_mboxcache_free(*adata);
- mutt_buffer_free(&(*adata)->cmdbuf);
- FREE(&(*adata)->buf);
- mutt_bcache_close(&(*adata)->bcache);
- FREE(&(*adata)->cmds);
- FREE(adata);
+ struct ImapAccountData *adata = *ptr;
+
+ FREE(&adata->capstr);
+ mutt_list_free(&adata->flags);
+ imap_mboxcache_free(adata);
+ mutt_buffer_free(&adata->cmdbuf);
+ FREE(&adata->buf);
+ mutt_bcache_close(&adata->bcache);
+ FREE(&adata->cmds);
+ FREE(ptr);
}
/**