NeoMutt  2022-04-29-215-gc12b98
Teaching an old dog new tricks
DOXYGEN
msn.c File Reference

IMAP MSN helper functions. More...

#include "config.h"
#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 41 of file msn.c.

42{
43 /* This is a conservative check to protect against a malicious imap
44 * server. Most likely size_t is bigger than an unsigned int, but
45 * if msn_count is this big, we have a serious problem. */
46 if (num >= (UINT_MAX / sizeof(struct Email *)))
47 {
48 mutt_error(_("Out of memory"));
49 mutt_exit(1);
50 }
51
52 ARRAY_RESERVE(msn, num);
53}
#define ARRAY_RESERVE(head, num)
Reserve memory for the array.
Definition: array.h:188
#define mutt_error(...)
Definition: logging.h:87
void mutt_exit(int code)
Leave NeoMutt NOW.
Definition: main.c:248
#define _(a)
Definition: message.h:28
The envelope/body of an email.
Definition: email.h:37
+ 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 59 of file msn.c.

60{
61 ARRAY_FREE(msn);
62}
#define ARRAY_FREE(head)
Release all memory.
Definition: array.h:203
+ 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 69 of file msn.c.

70{
71 return ARRAY_SIZE(msn);
72}
#define ARRAY_SIZE(head)
The number of elements stored.
Definition: array.h:86
+ 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 80 of file msn.c.

81{
82 struct Email **ep = ARRAY_GET(msn, idx);
83 return ep ? *ep : NULL;
84}
#define ARRAY_GET(head, idx)
Return the element at index.
Definition: array.h:108
+ 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 92 of file msn.c.

93{
94 ARRAY_SET(msn, idx, e);
95}
#define ARRAY_SET(head, idx, elem)
Set an element in the array.
Definition: array.h:122
+ 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 103 of file msn.c.

104{
105 return ARRAY_SHRINK(msn, num);
106}
#define ARRAY_SHRINK(head, num)
Mark a number of slots at the end of the array as unused.
Definition: array.h:171
+ 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 113 of file msn.c.

114{
115 struct Email **ep = ARRAY_GET(msn, idx);
116 if (ep)
117 *ep = NULL;
118}
+ Here is the caller graph for this function: