NeoMutt  2024-04-25-89-g194907
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
mdata.c
Go to the documentation of this file.
1
29#include "config.h"
30#include "mutt/lib.h"
31#include "config/lib.h"
32#include "email/lib.h"
33#include "core/lib.h"
34#include "mdata.h"
35#include "progress/lib.h"
36#include "query.h"
37
45void nm_mdata_free(void **ptr)
46{
47 if (!ptr || !*ptr)
48 return;
49
50 struct NmMboxData *mdata = *ptr;
51
52 mutt_debug(LL_DEBUG1, "nm: freeing context data %p\n", (void *) mdata);
53
54 url_free(&mdata->db_url);
55 FREE(&mdata->db_query);
56 progress_free(&mdata->progress);
57 FREE(ptr);
58}
59
68struct NmMboxData *nm_mdata_new(const char *url)
69{
70 if (!url)
71 return NULL;
72
73 struct NmMboxData *mdata = mutt_mem_calloc(1, sizeof(struct NmMboxData));
74 mutt_debug(LL_DEBUG1, "nm: initialize mailbox mdata %p\n", (void *) mdata);
75
76 const short c_nm_db_limit = cs_subset_number(NeoMutt->sub, "nm_db_limit");
77 const char *const c_nm_query_type = cs_subset_string(NeoMutt->sub, "nm_query_type");
78 mdata->db_limit = c_nm_db_limit;
79 mdata->query_type = nm_string_to_query_type(c_nm_query_type);
80 mdata->db_url = url_parse(url);
81 if (!mdata->db_url)
82 {
83 mutt_error(_("failed to parse notmuch url: %s"), url);
84 FREE(&mdata);
85 return NULL;
86 }
87 return mdata;
88}
89
97{
98 if (!m || (m->type != MUTT_NOTMUCH))
99 return NULL;
100
101 return m->mdata;
102}
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
Definition: helpers.c:291
short cs_subset_number(const struct ConfigSubset *sub, const char *name)
Get a number config item by name.
Definition: helpers.c:143
Convenience wrapper for the config headers.
Convenience wrapper for the core headers.
@ MUTT_NOTMUCH
'Notmuch' (virtual) Mailbox type
Definition: mailbox.h:51
Structs that make up an email.
#define mutt_error(...)
Definition: logging2.h:92
#define mutt_debug(LEVEL,...)
Definition: logging2.h:89
void nm_mdata_free(void **ptr)
Free the private Mailbox data - Implements Mailbox::mdata_free() -.
Definition: mdata.c:45
@ LL_DEBUG1
Log at debug level 1.
Definition: logging2.h:43
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:51
#define FREE(x)
Definition: memory.h:45
Convenience wrapper for the library headers.
#define _(a)
Definition: message.h:28
struct NmMboxData * nm_mdata_new(const char *url)
Create a new NmMboxData object from a query.
Definition: mdata.c:68
struct NmMboxData * nm_mdata_get(struct Mailbox *m)
Get the Notmuch Mailbox data.
Definition: mdata.c:96
Notmuch-specific Mailbox data.
Progress Bar.
void progress_free(struct Progress **ptr)
Free a Progress Bar.
Definition: progress.c:110
enum NmQueryType nm_string_to_query_type(const char *str)
Lookup a query type.
Definition: query.c:110
Notmuch query functions.
A mailbox.
Definition: mailbox.h:79
enum MailboxType type
Mailbox type.
Definition: mailbox.h:102
void * mdata
Driver specific data.
Definition: mailbox.h:132
Container for Accounts, Notifications.
Definition: neomutt.h:42
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:46
Notmuch-specific Mailbox data -.
Definition: mdata.h:35
struct Url * url_parse(const char *src)
Fill in Url.
Definition: url.c:239
void url_free(struct Url **ptr)
Free the contents of a URL.
Definition: url.c:124