NeoMutt  2021-02-05-666-ge300cd
Teaching an old dog new tricks
DOXYGEN
msn.c
Go to the documentation of this file.
1 
29 #include <limits.h>
30 #include <stdlib.h>
31 #include "mutt/lib.h"
32 #include "msn.h"
33 #include "mdata.h" // IWYU pragma: keep
34 
40 void imap_msn_reserve(struct MSN *msn, size_t num)
41 {
42  /* This is a conservative check to protect against a malicious imap
43  * server. Most likely size_t is bigger than an unsigned int, but
44  * if msn_count is this big, we have a serious problem. */
45  if (num >= (UINT_MAX / sizeof(struct Email *)))
46  {
47  mutt_error(_("Out of memory"));
48  mutt_exit(1);
49  }
50 
51  ARRAY_RESERVE(msn, num);
52 }
53 
58 void imap_msn_free(struct MSN *msn)
59 {
60  ARRAY_FREE(msn);
61 }
62 
68 size_t imap_msn_highest(const struct MSN *msn)
69 {
70  return ARRAY_SIZE(msn);
71 }
72 
79 struct Email *imap_msn_get(const struct MSN *msn, size_t idx)
80 {
81  struct Email **ep = ARRAY_GET(msn, idx);
82  return ep ? *ep : NULL;
83 }
84 
91 void imap_msn_set(struct MSN *msn, size_t idx, struct Email *e)
92 {
93  ARRAY_SET(msn, idx, e);
94 }
95 
102 size_t imap_msn_shrink(struct MSN *msn, size_t num)
103 {
104  return ARRAY_SHRINK(msn, num);
105 }
106 
112 void imap_msn_remove(struct MSN *msn, size_t idx)
113 {
114  struct Email **ep = ARRAY_GET(msn, idx);
115  if (ep)
116  *ep = NULL;
117 }
#define ARRAY_RESERVE(head, num)
Reserve memory for the array.
Definition: array.h:185
The envelope/body of an email.
Definition: email.h:37
#define mutt_error(...)
Definition: logging.h:88
#define ARRAY_FREE(head)
Release all memory.
Definition: array.h:198
size_t idx
Definition: mailbox.c:257
#define ARRAY_GET(head, idx)
Return the element at index.
Definition: array.h:105
#define _(a)
Definition: message.h:28
#define ARRAY_SHRINK(head, num)
Mark a number of slots at the end of the array as unused.
Definition: array.h:168
IMAP MSN helper functions.
void imap_msn_free(struct MSN *msn)
Free the cache.
Definition: msn.c:58
Imap-specific Mailbox data.
void imap_msn_remove(struct MSN *msn, size_t idx)
Remove an entry from the cache.
Definition: msn.c:112
struct Email * imap_msn_get(const struct MSN *msn, size_t idx)
Return the Email associated with an msn.
Definition: msn.c:79
void imap_msn_reserve(struct MSN *msn, size_t num)
Create / reallocate the cache.
Definition: msn.c:40
size_t imap_msn_shrink(struct MSN *msn, size_t num)
Remove a number of entries from the end of the cache.
Definition: msn.c:102
#define ARRAY_SET(head, idx, elem)
Set an element in the array.
Definition: array.h:119
void mutt_exit(int code)
Leave NeoMutt NOW.
Definition: main.c:279
size_t imap_msn_highest(const struct MSN *msn)
Return the highest MSN in use.
Definition: msn.c:68
void imap_msn_set(struct MSN *msn, size_t idx, struct Email *e)
Cache an Email into a given position.
Definition: msn.c:91
Convenience wrapper for the library headers.
#define ARRAY_SIZE(head)
The number of elements stored.
Definition: array.h:83