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 "private.h"
32 #include "core/lib.h"
33 #include "mdata.h"
34 #include "hcache/lib.h"
35 #include "adata.h"
36 
40 void imap_mdata_free(void **ptr)
41 {
42  if (!ptr || !*ptr)
43  return;
44 
45  struct ImapMboxData *mdata = *ptr;
46 
48  mutt_list_free(&mdata->flags);
49  FREE(&mdata->name);
50  FREE(&mdata->real_name);
51  FREE(&mdata->munge_name);
52  FREE(ptr);
53 }
54 
60 {
61  if (!m || (m->type != MUTT_IMAP) || !m->mdata)
62  return NULL;
63  return m->mdata;
64 }
65 
72 struct ImapMboxData *imap_mdata_new(struct ImapAccountData *adata, const char *name)
73 {
74  char buf[1024];
75  struct ImapMboxData *mdata = mutt_mem_calloc(1, sizeof(struct ImapMboxData));
76 
77  mdata->real_name = mutt_str_dup(name);
78 
79  imap_fix_path(adata->delim, name, buf, sizeof(buf));
80  if (buf[0] == '\0')
81  mutt_str_copy(buf, "INBOX", sizeof(buf));
82  mdata->name = mutt_str_dup(buf);
83 
84  imap_munge_mbox_name(adata->unicode, buf, sizeof(buf), mdata->name);
85  mdata->munge_name = mutt_str_dup(buf);
86 
87  mdata->reopen &= IMAP_REOPEN_ALLOW;
88 
89  STAILQ_INIT(&mdata->flags);
90 
91 #ifdef USE_HCACHE
92  imap_hcache_open(adata, mdata);
93  if (mdata->hcache)
94  {
95  size_t dlen = 0;
96  void *uidvalidity = mutt_hcache_fetch_raw(mdata->hcache, "/UIDVALIDITY", 12, &dlen);
97  void *uidnext = mutt_hcache_fetch_raw(mdata->hcache, "/UIDNEXT", 8, &dlen);
98  unsigned long long *modseq =
99  mutt_hcache_fetch_raw(mdata->hcache, "/MODSEQ", 7, &dlen);
100  if (uidvalidity)
101  {
102  mdata->uidvalidity = *(uint32_t *) uidvalidity;
103  mdata->uid_next = uidnext ? *(unsigned int *) uidnext : 0;
104  mdata->modseq = modseq ? *modseq : 0;
105  mutt_debug(LL_DEBUG3, "hcache uidvalidity %u, uidnext %u, modseq %llu\n",
106  mdata->uidvalidity, mdata->uid_next, mdata->modseq);
107  }
108  mutt_hcache_free_raw(mdata->hcache, &uidvalidity);
109  mutt_hcache_free_raw(mdata->hcache, &uidnext);
110  mutt_hcache_free_raw(mdata->hcache, (void **) &modseq);
111  imap_hcache_close(mdata);
112  }
113 #endif
114 
115  return mdata;
116 }
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
void imap_mdata_cache_reset(struct ImapMboxData *mdata)
Release and clear cache data of ImapMboxData structure.
Definition: util.c:106
uint32_t uidvalidity
Definition: mdata.h:50
#define IMAP_REOPEN_ALLOW
Allow re-opening a folder upon expunge.
Definition: private.h:66
void imap_munge_mbox_name(bool unicode, char *dest, size_t dlen, const char *src)
Quote awkward characters in a mailbox name.
Definition: util.c:914
void imap_mdata_free(void **ptr)
Free the private Mailbox data - Implements Mailbox::mdata_free()
Definition: mdata.c:40
ImapOpenFlags reopen
Flags, e.g. IMAP_REOPEN_ALLOW.
Definition: mdata.h:44
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:370
struct HeaderCache * hcache
Definition: mdata.h:62
Imap-specific Account data.
void mutt_hcache_free_raw(struct HeaderCache *hc, void **data)
Multiplexor for StoreOps::free.
Definition: hcache.c:541
struct ImapMboxData * imap_mdata_new(struct ImapAccountData *adata, const char *name)
Allocate and initialise a new ImapMboxData structure.
Definition: mdata.c:72
void mutt_list_free(struct ListHead *h)
Free a List AND its strings.
Definition: list.c:122
Imap-specific Mailbox data.
Header cache multiplexor.
void imap_hcache_close(struct ImapMboxData *mdata)
Close the header cache.
Definition: util.c:340
#define STAILQ_INIT(head)
Definition: queue.h:372
struct ImapMboxData * imap_mdata_get(struct Mailbox *m)
Get the Mailbox data for this mailbox.
Definition: mdata.c:59
Convenience wrapper for the core headers.
char delim
Definition: adata.h:75
Shared constants/structs that are private to IMAP.
void * mdata
Driver specific data.
Definition: mailbox.h:136
unsigned long long modseq
Definition: mdata.h:52
A mailbox.
Definition: mailbox.h:81
struct ListHead flags
Definition: mdata.h:49
char * name
Mailbox name.
Definition: mdata.h:40
#define mutt_debug(LEVEL,...)
Definition: logging.h:85
char * real_name
Original Mailbox name, e.g.: INBOX can be just \0.
Definition: mdata.h:42
IMAP-specific Account data -.
Definition: adata.h:39
unsigned int uid_next
Definition: mdata.h:51
char * imap_fix_path(char delim, const char *mailbox, char *path, size_t plen)
Fix up the imap path.
Definition: util.c:687
size_t mutt_str_copy(char *dest, const char *src, size_t dsize)
Copy a string into a buffer (guaranteeing NUL-termination)
Definition: string.c:749
IMAP-specific Mailbox data -.
Definition: mdata.h:38
#define FREE(x)
Definition: memory.h:40
void * mutt_hcache_fetch_raw(struct HeaderCache *hc, const char *key, size_t keylen, size_t *dlen)
Fetch a message&#39;s header from the cache.
Definition: hcache.c:521
char * munge_name
Munged version of the mailbox name.
Definition: mdata.h:41
&#39;IMAP&#39; Mailbox type
Definition: mailbox.h:53
void imap_hcache_open(struct ImapAccountData *adata, struct ImapMboxData *mdata)
Open a header cache.
Definition: util.c:297
Log at debug level 3.
Definition: logging.h:42
bool unicode
If true, we can send UTF-8, and the server will use UTF8 rather than mUTF7.
Definition: adata.h:62