NeoMutt  2022-04-29-247-gc6aae8
Teaching an old dog new tricks
DOXYGEN
mdata.c File Reference

Notmuch-specific Mailbox data. More...

#include "config.h"
#include <stddef.h>
#include "mutt/lib.h"
#include "config/lib.h"
#include "email/lib.h"
#include "core/lib.h"
#include "mdata.h"
#include "progress/lib.h"
#include "query.h"
+ Include dependency graph for mdata.c:

Go to the source code of this file.

Functions

void nm_mdata_free (void **ptr)
 Free the private Mailbox data - Implements Mailbox::mdata_free() More...
 
struct NmMboxDatanm_mdata_new (const char *url)
 Create a new NmMboxData object from a query. More...
 
struct NmMboxDatanm_mdata_get (struct Mailbox *m)
 Get the Notmuch Mailbox data. More...
 

Detailed Description

Notmuch-specific Mailbox data.

Authors
  • Richard Russon

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Definition in file mdata.c.

Function Documentation

◆ nm_mdata_free()

void nm_mdata_free ( void **  ptr)

Free the private Mailbox data - Implements Mailbox::mdata_free()

The NmMboxData struct stores global Notmuch data, such as the connection to the database. This function will close the database, free the resources and the struct itself.

Definition at line 46 of file mdata.c.

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}
#define mutt_debug(LEVEL,...)
Definition: logging.h:84
@ LL_DEBUG1
Log at debug level 1.
Definition: logging.h:40
#define FREE(x)
Definition: memory.h:43
void progress_free(struct Progress **ptr)
Free a Progress Bar.
Definition: progress.c:86
void * mdata
Driver specific data.
Definition: mailbox.h:132
Notmuch-specific Mailbox data -.
Definition: mdata.h:34
void url_free(struct Url **ptr)
Free the contents of a URL.
Definition: url.c:123
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ nm_mdata_new()

struct NmMboxData * nm_mdata_new ( const char *  url)

Create a new NmMboxData object from a query.

Parameters
urlNotmuch query string
Return values
ptrNew NmMboxData struct

A new NmMboxData struct is created, then the query is parsed and saved within it. This should be freed using nm_mdata_free().

Definition at line 69 of file mdata.c.

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 = cs_subset_string(NeoMutt->sub, "nm_query_type");
79 mdata->db_limit = c_nm_db_limit;
80 mdata->query_type = nm_string_to_query_type(c_nm_query_type);
81 mdata->db_url = url_parse(url);
82 if (!mdata->db_url)
83 {
84 mutt_error(_("failed to parse notmuch url: %s"), url);
85 FREE(&mdata);
86 return NULL;
87 }
88 return mdata;
89}
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
Definition: helpers.c:317
short cs_subset_number(const struct ConfigSubset *sub, const char *name)
Get a number config item by name.
Definition: helpers.c:169
#define mutt_error(...)
Definition: logging.h:87
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:50
#define _(a)
Definition: message.h:28
enum NmQueryType nm_string_to_query_type(const char *str)
Lookup a query type.
Definition: query.c:110
Container for Accounts, Notifications.
Definition: neomutt.h:37
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:39
struct Url * url_parse(const char *src)
Fill in Url.
Definition: url.c:234
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ nm_mdata_get()

struct NmMboxData * nm_mdata_get ( struct Mailbox m)

Get the Notmuch Mailbox data.

Parameters
mMailbox
Return values
ptrSuccess
NULLFailure, not a Notmuch mailbox

Definition at line 97 of file mdata.c.

98{
99 if (!m || (m->type != MUTT_NOTMUCH))
100 return NULL;
101
102 return m->mdata;
103}
@ MUTT_NOTMUCH
'Notmuch' (virtual) Mailbox type
Definition: mailbox.h:51
enum MailboxType type
Mailbox type.
Definition: mailbox.h:102
+ Here is the caller graph for this function: