NeoMutt  2021-02-05-666-ge300cd
Teaching an old dog new tricks
DOXYGEN
msn.c File Reference

IMAP MSN helper functions. More...

#include <limits.h>
#include <stdlib.h>
#include "mutt/lib.h"
#include "msn.h"
#include "mdata.h"
+ Include dependency graph for msn.c:

Go to the source code of this file.

Functions

void imap_msn_reserve (struct MSN *msn, size_t num)
 Create / reallocate the cache. More...
 
void imap_msn_free (struct MSN *msn)
 Free the cache. More...
 
size_t imap_msn_highest (const struct MSN *msn)
 Return the highest MSN in use. More...
 
struct Emailimap_msn_get (const struct MSN *msn, size_t idx)
 Return the Email associated with an msn. More...
 
void imap_msn_set (struct MSN *msn, size_t idx, struct Email *e)
 Cache an Email into a given position. More...
 
size_t imap_msn_shrink (struct MSN *msn, size_t num)
 Remove a number of entries from the end of the cache. More...
 
void imap_msn_remove (struct MSN *msn, size_t idx)
 Remove an entry from the cache. More...
 

Detailed Description

IMAP MSN helper functions.

Authors
  • Pietro Cerutti

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 msn.c.

Function Documentation

◆ imap_msn_reserve()

void imap_msn_reserve ( struct MSN *  msn,
size_t  num 
)

Create / reallocate the cache.

Parameters
msnMSN structure
numNumber of MSNs to make room for

Definition at line 40 of file msn.c.

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 }
#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 _(a)
Definition: message.h:28
unsigned int msn
Message Sequence Number.
Definition: edata.h:45
void mutt_exit(int code)
Leave NeoMutt NOW.
Definition: main.c:279
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ imap_msn_free()

void imap_msn_free ( struct MSN *  msn)

Free the cache.

Parameters
msnMSN structure

Definition at line 58 of file msn.c.

59 {
60  ARRAY_FREE(msn);
61 }
#define ARRAY_FREE(head)
Release all memory.
Definition: array.h:198
unsigned int msn
Message Sequence Number.
Definition: edata.h:45
+ Here is the caller graph for this function:

◆ imap_msn_highest()

size_t imap_msn_highest ( const struct MSN *  msn)

Return the highest MSN in use.

Parameters
msnMSN structure
Return values
numThe highest MSN in use

Definition at line 68 of file msn.c.

69 {
70  return ARRAY_SIZE(msn);
71 }
unsigned int msn
Message Sequence Number.
Definition: edata.h:45
#define ARRAY_SIZE(head)
The number of elements stored.
Definition: array.h:83
+ Here is the caller graph for this function:

◆ imap_msn_get()

struct Email* imap_msn_get ( const struct MSN *  msn,
size_t  idx 
)

Return the Email associated with an msn.

Parameters
msnMSN structure
idxIndex to retrieve
Return values
ptrPointer to Email or NULL

Definition at line 79 of file msn.c.

80 {
81  struct Email **ep = ARRAY_GET(msn, idx);
82  return ep ? *ep : NULL;
83 }
The envelope/body of an email.
Definition: email.h:37
size_t idx
Definition: mailbox.c:257
#define ARRAY_GET(head, idx)
Return the element at index.
Definition: array.h:105
+ Here is the caller graph for this function:

◆ imap_msn_set()

void imap_msn_set ( struct MSN *  msn,
size_t  idx,
struct Email e 
)

Cache an Email into a given position.

Parameters
msnMSN structure
idxIndex in the cache
eEmail to cache

Definition at line 91 of file msn.c.

92 {
93  ARRAY_SET(msn, idx, e);
94 }
size_t idx
Definition: mailbox.c:257
#define ARRAY_SET(head, idx, elem)
Set an element in the array.
Definition: array.h:119
+ Here is the caller graph for this function:

◆ imap_msn_shrink()

size_t imap_msn_shrink ( struct MSN *  msn,
size_t  num 
)

Remove a number of entries from the end of the cache.

Parameters
msnMSN structure
numNumber of entries to remove
Return values
numNumber of entries actually removed

Definition at line 102 of file msn.c.

103 {
104  return ARRAY_SHRINK(msn, num);
105 }
#define ARRAY_SHRINK(head, num)
Mark a number of slots at the end of the array as unused.
Definition: array.h:168
+ Here is the caller graph for this function:

◆ imap_msn_remove()

void imap_msn_remove ( struct MSN *  msn,
size_t  idx 
)

Remove an entry from the cache.

Parameters
msnMSN structure
idxIndex to invalidate

Definition at line 112 of file msn.c.

113 {
114  struct Email **ep = ARRAY_GET(msn, idx);
115  if (ep)
116  *ep = NULL;
117 }
The envelope/body of an email.
Definition: email.h:37
size_t idx
Definition: mailbox.c:257
#define ARRAY_GET(head, idx)
Return the element at index.
Definition: array.h:105
+ Here is the caller graph for this function: