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