1 /**
2  * @file
3  * Notmuch-specific Account data
4  *
5  * @authors
6  * Copyright (C) 2021 Richard Russon <rich@flatcap.org>
7  *
8  * @copyright
9  * This program is free software: you can redistribute it and/or modify it under
10  * the terms of the GNU General Public License as published by the Free Software
11  * Foundation, either version 2 of the License, or (at your option) any later
12  * version.
13  *
14  * This program is distributed in the hope that it will be useful, but WITHOUT
15  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
17  * details.
18  *
19  * You should have received a copy of the GNU General Public License along with
20  * this program.  If not, see <http://www.gnu.org/licenses/>.
21  */
22 
23 /**
24  * @page nm_adata Notmuch-specific Account data
25  *
26  * Notmuch-specific Account data
27  */
28 
29 #include "config.h"
30 #include <stddef.h>
31 #include "private.h"
32 #include "mutt/lib.h"
33 #include "core/lib.h"
34 #include "adata.h"
35 
36 /**
37  * nm_adata_free - Free the private Account data - Implements Account::adata_free()
38  */
nm_adata_free(void ** ptr)39 void nm_adata_free(void **ptr)
40 {
41   struct NmAccountData *adata = *ptr;
42   if (adata->db)
43   {
44     nm_db_free(adata->db);
45     adata->db = NULL;
46   }
47 
48   FREE(ptr);
49 }
50 
51 /**
52  * nm_adata_new - Allocate and initialise a new NmAccountData structure
53  * @retval ptr New NmAccountData
54  */
nm_adata_new(void)55 struct NmAccountData *nm_adata_new(void)
56 {
57   struct NmAccountData *adata = mutt_mem_calloc(1, sizeof(struct NmAccountData));
58 
59   return adata;
60 }
61 
62 /**
63  * nm_adata_get - Get the Notmuch Account data
64  * @param m Mailbox
65  * @retval ptr  Success
66  * @retval NULL Failure, not a Notmuch mailbox
67  */
nm_adata_get(struct Mailbox * m)68 struct NmAccountData *nm_adata_get(struct Mailbox *m)
69 {
70   if (!m || (m->type != MUTT_NOTMUCH))
71     return NULL;
72 
73   struct Account *a = m->account;
74   if (!a)
75     return NULL;
76 
77   return a->adata;
78 }
79