NeoMutt  2020-11-20
Teaching an old dog new tricks
DOXYGEN
mailbox.h File Reference

Representation of a mailbox. More...

#include "config.h"
#include <stdbool.h>
#include <stdint.h>
#include <sys/types.h>
#include <time.h>
#include "mutt/lib.h"
+ Include dependency graph for mailbox.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  Mailbox
 A mailbox. More...
 
struct  MailboxNode
 List of Mailboxes. More...
 
struct  EventMailbox
 An Event that happened to a Mailbox. More...
 

Macros

#define MB_NORMAL   0
 
#define MB_HIDDEN   1
 
#define MUTT_ACL_NO_FLAGS   0
 No flags are set. More...
 
#define MUTT_ACL_ADMIN   (1 << 0)
 Administer the account (get/set permissions) More...
 
#define MUTT_ACL_CREATE   (1 << 1)
 Create a mailbox. More...
 
#define MUTT_ACL_DELETE   (1 << 2)
 Delete a message. More...
 
#define MUTT_ACL_DELMX   (1 << 3)
 Delete a mailbox. More...
 
#define MUTT_ACL_EXPUNGE   (1 << 4)
 Expunge messages. More...
 
#define MUTT_ACL_INSERT   (1 << 5)
 Add/copy into the mailbox (used when editing a message) More...
 
#define MUTT_ACL_LOOKUP   (1 << 6)
 Lookup mailbox (visible to 'list') More...
 
#define MUTT_ACL_POST   (1 << 7)
 Post (submit messages to the server) More...
 
#define MUTT_ACL_READ   (1 << 8)
 Read the mailbox. More...
 
#define MUTT_ACL_SEEN   (1 << 9)
 Change the 'seen' status of a message. More...
 
#define MUTT_ACL_WRITE   (1 << 10)
 Write to a message (for flagging or linking threads) More...
 
#define MUTT_ACL_ALL   ((1 << 11) - 1)
 

Typedefs

typedef uint16_t AclFlags
 ACL Rights - These show permission to... More...
 

Enumerations

enum  MailboxType {
  MUTT_MAILBOX_ANY = -2, MUTT_MAILBOX_ERROR = -1, MUTT_UNKNOWN = 0, MUTT_MBOX,
  MUTT_MMDF, MUTT_MH, MUTT_MAILDIR, MUTT_NNTP,
  MUTT_IMAP, MUTT_NOTMUCH, MUTT_POP, MUTT_COMPRESSED
}
 Supported mailbox formats. More...
 
enum  NotifyMailbox {
  NT_MAILBOX_ADD = 1, NT_MAILBOX_REMOVE, NT_MAILBOX_CHANGED, NT_MAILBOX_CLOSED,
  NT_MAILBOX_INVALID, NT_MAILBOX_RESORT, NT_MAILBOX_SWITCH, NT_MAILBOX_UPDATE,
  NT_MAILBOX_UNTAG
}
 Types of Mailbox Event. More...
 

Functions

 STAILQ_HEAD (MailboxList, MailboxNode)
 
void mailbox_changed (struct Mailbox *m, enum NotifyMailbox action)
 Notify observers of a change to a Mailbox. More...
 
struct Mailboxmailbox_find (const char *path)
 Find the mailbox with a given path. More...
 
struct Mailboxmailbox_find_name (const char *name)
 Find the mailbox with a given name. More...
 
void mailbox_free (struct Mailbox **ptr)
 Free a Mailbox. More...
 
struct Mailboxmailbox_new (void)
 Create a new Mailbox. More...
 
bool mailbox_set_subset (struct Mailbox *m, struct ConfigSubset *sub)
 Set a Mailbox's Config Subset. More...
 
void mailbox_size_add (struct Mailbox *m, const struct Email *e)
 Add an email's size to the total size of a Mailbox. More...
 
void mailbox_size_sub (struct Mailbox *m, const struct Email *e)
 Subtract an email's size from the total size of a Mailbox. More...
 
void mailbox_update (struct Mailbox *m)
 Get the mailbox's current size. More...
 
static const char * mailbox_path (const struct Mailbox *m)
 Get the Mailbox's path string. More...
 

Detailed Description

Representation of a mailbox.

Authors
  • Michael R. Elkins
  • 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 mailbox.h.

Macro Definition Documentation

◆ MB_NORMAL

#define MB_NORMAL   0

Definition at line 37 of file mailbox.h.

◆ MB_HIDDEN

#define MB_HIDDEN   1

Definition at line 38 of file mailbox.h.

◆ MUTT_ACL_NO_FLAGS

#define MUTT_ACL_NO_FLAGS   0

No flags are set.

Definition at line 63 of file mailbox.h.

◆ MUTT_ACL_ADMIN

#define MUTT_ACL_ADMIN   (1 << 0)

Administer the account (get/set permissions)

Definition at line 64 of file mailbox.h.

◆ MUTT_ACL_CREATE

#define MUTT_ACL_CREATE   (1 << 1)

Create a mailbox.

Definition at line 65 of file mailbox.h.

◆ MUTT_ACL_DELETE

#define MUTT_ACL_DELETE   (1 << 2)

Delete a message.

Definition at line 66 of file mailbox.h.

◆ MUTT_ACL_DELMX

#define MUTT_ACL_DELMX   (1 << 3)

Delete a mailbox.

Definition at line 67 of file mailbox.h.

◆ MUTT_ACL_EXPUNGE

#define MUTT_ACL_EXPUNGE   (1 << 4)

Expunge messages.

Definition at line 68 of file mailbox.h.

◆ MUTT_ACL_INSERT

#define MUTT_ACL_INSERT   (1 << 5)

Add/copy into the mailbox (used when editing a message)

Definition at line 69 of file mailbox.h.

◆ MUTT_ACL_LOOKUP

#define MUTT_ACL_LOOKUP   (1 << 6)

Lookup mailbox (visible to 'list')

Definition at line 70 of file mailbox.h.

◆ MUTT_ACL_POST

#define MUTT_ACL_POST   (1 << 7)

Post (submit messages to the server)

Definition at line 71 of file mailbox.h.

◆ MUTT_ACL_READ

#define MUTT_ACL_READ   (1 << 8)

Read the mailbox.

Definition at line 72 of file mailbox.h.

◆ MUTT_ACL_SEEN

#define MUTT_ACL_SEEN   (1 << 9)

Change the 'seen' status of a message.

Definition at line 73 of file mailbox.h.

◆ MUTT_ACL_WRITE

#define MUTT_ACL_WRITE   (1 << 10)

Write to a message (for flagging or linking threads)

Definition at line 74 of file mailbox.h.

◆ MUTT_ACL_ALL

#define MUTT_ACL_ALL   ((1 << 11) - 1)

Definition at line 76 of file mailbox.h.

Typedef Documentation

◆ AclFlags

typedef uint16_t AclFlags

ACL Rights - These show permission to...

Flags, e.g. MUTT_ACL_ADMIN

Definition at line 62 of file mailbox.h.

Enumeration Type Documentation

◆ MailboxType

Supported mailbox formats.

Enumerator
MUTT_MAILBOX_ANY 

Match any Mailbox type.

MUTT_MAILBOX_ERROR 

Error occurred examining Mailbox.

MUTT_UNKNOWN 

Mailbox wasn't recognised.

MUTT_MBOX 

'mbox' Mailbox type

MUTT_MMDF 

'mmdf' Mailbox type

MUTT_MH 

'MH' Mailbox type

MUTT_MAILDIR 

'Maildir' Mailbox type

MUTT_NNTP 

'NNTP' (Usenet) Mailbox type

MUTT_IMAP 

'IMAP' Mailbox type

MUTT_NOTMUCH 

'Notmuch' (virtual) Mailbox type

MUTT_POP 

'POP3' Mailbox type

MUTT_COMPRESSED 

Compressed file Mailbox type.

Definition at line 43 of file mailbox.h.

44 {
45  MUTT_MAILBOX_ANY = -2,
46  MUTT_MAILBOX_ERROR = -1,
47  MUTT_UNKNOWN = 0,
48  MUTT_MBOX,
49  MUTT_MMDF,
50  MUTT_MH,
51  MUTT_MAILDIR,
52  MUTT_NNTP,
53  MUTT_IMAP,
54  MUTT_NOTMUCH,
55  MUTT_POP,
57 };
&#39;NNTP&#39; (Usenet) Mailbox type
Definition: mailbox.h:52
Match any Mailbox type.
Definition: mailbox.h:45
Mailbox wasn&#39;t recognised.
Definition: mailbox.h:47
Error occurred examining Mailbox.
Definition: mailbox.h:46
&#39;Maildir&#39; Mailbox type
Definition: mailbox.h:51
&#39;POP3&#39; Mailbox type
Definition: mailbox.h:55
&#39;mmdf&#39; Mailbox type
Definition: mailbox.h:49
Compressed file Mailbox type.
Definition: mailbox.h:56
&#39;MH&#39; Mailbox type
Definition: mailbox.h:50
&#39;Notmuch&#39; (virtual) Mailbox type
Definition: mailbox.h:54
&#39;mbox&#39; Mailbox type
Definition: mailbox.h:48
&#39;IMAP&#39; Mailbox type
Definition: mailbox.h:53

◆ NotifyMailbox

Types of Mailbox Event.

Observers of NT_MAILBOX will be passed an EventMailbox.

Enumerator
NT_MAILBOX_ADD 

A new Mailbox has been created.

NT_MAILBOX_REMOVE 

A Mailbox is about to be destroyed.

NT_MAILBOX_CHANGED 

Mailbox data has changed.

NT_MAILBOX_CLOSED 

Mailbox was closed.

NT_MAILBOX_INVALID 

Email list was changed.

NT_MAILBOX_RESORT 

Email list needs resorting.

NT_MAILBOX_SWITCH 

Current Mailbox has changed.

NT_MAILBOX_UPDATE 

Update internal tables.

NT_MAILBOX_UNTAG 

Clear the 'last-tagged' pointer.

Definition at line 164 of file mailbox.h.

165 {
166  NT_MAILBOX_ADD = 1,
169 
170  /* These don't really belong here as they are tied to GUI operations.
171  * Eventually, they'll be eliminated. */
178 };
Clear the &#39;last-tagged&#39; pointer.
Definition: mailbox.h:177
Update internal tables.
Definition: mailbox.h:176
Email list was changed.
Definition: mailbox.h:173
Mailbox was closed.
Definition: mailbox.h:172
A new Mailbox has been created.
Definition: mailbox.h:166
Email list needs resorting.
Definition: mailbox.h:174
Mailbox data has changed.
Definition: mailbox.h:168
Current Mailbox has changed.
Definition: mailbox.h:175
A Mailbox is about to be destroyed.
Definition: mailbox.h:167

Function Documentation

◆ STAILQ_HEAD()

STAILQ_HEAD ( MailboxList  ,
MailboxNode   
)

◆ mailbox_changed()

void mailbox_changed ( struct Mailbox m,
enum NotifyMailbox  action 
)

Notify observers of a change to a Mailbox.

Parameters
mMailbox
actionChange to Mailbox

Definition at line 177 of file mailbox.c.

178 {
179  if (!m)
180  return;
181 
182  struct EventMailbox ev_m = { m };
183  notify_send(m->notify, NT_MAILBOX, action, &ev_m);
184 }
An Event that happened to a Mailbox.
Definition: mailbox.h:183
Mailbox has changed, NotifyMailbox, EventMailbox.
Definition: notify_type.h:42
struct Notify * notify
Notifications handler.
Definition: mailbox.h:144
bool notify_send(struct Notify *notify, enum NotifyType event_type, int event_subtype, void *event_data)
Send out a notification message.
Definition: notify.c:152
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mailbox_find()

struct Mailbox* mailbox_find ( const char *  path)

Find the mailbox with a given path.

Parameters
pathPath to match
Return values
ptrMatching Mailbox

Definition at line 94 of file mailbox.c.

95 {
96  if (!path)
97  return NULL;
98 
99  struct stat sb;
100  struct stat tmp_sb;
101 
102  if (stat(path, &sb) != 0)
103  return NULL;
104 
105  struct MailboxList ml = STAILQ_HEAD_INITIALIZER(ml);
107  struct MailboxNode *np = NULL;
108  struct Mailbox *m = NULL;
109  STAILQ_FOREACH(np, &ml, entries)
110  {
111  if ((stat(mailbox_path(np->mailbox), &tmp_sb) == 0) &&
112  (sb.st_dev == tmp_sb.st_dev) && (sb.st_ino == tmp_sb.st_ino))
113  {
114  m = np->mailbox;
115  break;
116  }
117  }
119 
120  return m;
121 }
static const char * mailbox_path(const struct Mailbox *m)
Get the Mailbox&#39;s path string.
Definition: mailbox.h:203
void neomutt_mailboxlist_clear(struct MailboxList *ml)
Free a Mailbox List.
Definition: neomutt.c:137
Match any Mailbox type.
Definition: mailbox.h:45
size_t neomutt_mailboxlist_get_all(struct MailboxList *head, struct NeoMutt *n, enum MailboxType type)
Get a List of all Mailboxes.
Definition: neomutt.c:160
Container for Accounts, Notifications.
Definition: neomutt.h:36
A mailbox.
Definition: mailbox.h:81
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:349
#define STAILQ_HEAD_INITIALIZER(head)
Definition: queue.h:321
List of Mailboxes.
Definition: mailbox.h:152
struct Mailbox * mailbox
Mailbox in the list.
Definition: mailbox.h:154
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mailbox_find_name()

struct Mailbox* mailbox_find_name ( const char *  name)

Find the mailbox with a given name.

Parameters
nameName to match
Return values
ptrMatching Mailbox
NULLNo matching mailbox found
Note
This searches across all Accounts

Definition at line 131 of file mailbox.c.

132 {
133  if (!name)
134  return NULL;
135 
136  struct MailboxList ml = STAILQ_HEAD_INITIALIZER(ml);
138  struct MailboxNode *np = NULL;
139  struct Mailbox *m = NULL;
140  STAILQ_FOREACH(np, &ml, entries)
141  {
142  if (mutt_str_equal(np->mailbox->name, name))
143  {
144  m = np->mailbox;
145  break;
146  }
147  }
149 
150  return m;
151 }
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:871
void neomutt_mailboxlist_clear(struct MailboxList *ml)
Free a Mailbox List.
Definition: neomutt.c:137
Match any Mailbox type.
Definition: mailbox.h:45
size_t neomutt_mailboxlist_get_all(struct MailboxList *head, struct NeoMutt *n, enum MailboxType type)
Get a List of all Mailboxes.
Definition: neomutt.c:160
Container for Accounts, Notifications.
Definition: neomutt.h:36
char * name
A short name for the Mailbox.
Definition: mailbox.h:85
A mailbox.
Definition: mailbox.h:81
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:349
#define STAILQ_HEAD_INITIALIZER(head)
Definition: queue.h:321
List of Mailboxes.
Definition: mailbox.h:152
struct Mailbox * mailbox
Mailbox in the list.
Definition: mailbox.h:154
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mailbox_free()

void mailbox_free ( struct Mailbox **  ptr)

Free a Mailbox.

Parameters
[out]ptrMailbox to free

Definition at line 63 of file mailbox.c.

64 {
65  if (!ptr || !*ptr)
66  return;
67 
68  struct Mailbox *m = *ptr;
69 
71 
72  if (m->mdata && m->mdata_free)
73  m->mdata_free(&m->mdata);
74 
75  for (size_t i = 0; i < m->email_max; i++)
76  email_free(&m->emails[i]);
77 
79  cs_subset_free(&m->sub);
80  FREE(&m->name);
81  FREE(&m->realpath);
82  FREE(&m->emails);
83  FREE(&m->v2r);
84  notify_free(&m->notify);
85 
86  FREE(ptr);
87 }
struct Email ** emails
Array of Emails.
Definition: mailbox.h:99
void notify_free(struct Notify **ptr)
Free a notification handler.
Definition: notify.c:62
char * realpath
Used for duplicate detection, context comparison, and the sidebar.
Definition: mailbox.h:84
void cs_subset_free(struct ConfigSubset **ptr)
Free a Config Subset.
Definition: subset.c:93
Mailbox was closed.
Definition: mailbox.h:172
void(* mdata_free)(void **ptr)
Free the private data attached to the Mailbox.
Definition: mailbox.h:142
char * name
A short name for the Mailbox.
Definition: mailbox.h:85
void mutt_buffer_dealloc(struct Buffer *buf)
Release the memory allocated by a buffer.
Definition: buffer.c:294
void * mdata
Driver specific data.
Definition: mailbox.h:136
int email_max
Number of pointers in emails.
Definition: mailbox.h:100
A mailbox.
Definition: mailbox.h:81
struct ConfigSubset * sub
Inherited config items.
Definition: mailbox.h:86
int * v2r
Mapping from virtual to real msgno.
Definition: mailbox.h:101
#define FREE(x)
Definition: memory.h:40
struct Notify * notify
Notifications handler.
Definition: mailbox.h:144
struct Buffer pathbuf
Definition: mailbox.h:83
void email_free(struct Email **ptr)
Free an Email.
Definition: email.c:43
void mailbox_changed(struct Mailbox *m, enum NotifyMailbox action)
Notify observers of a change to a Mailbox.
Definition: mailbox.c:177
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mailbox_new()

struct Mailbox* mailbox_new ( void  )

Create a new Mailbox.

Return values
ptrNew Mailbox

Definition at line 42 of file mailbox.c.

43 {
44  static int gen = 0;
45 
46  struct Mailbox *m = mutt_mem_calloc(1, sizeof(struct Mailbox));
47 
49  m->notify = notify_new();
50 
51  m->email_max = 25;
52  m->emails = mutt_mem_calloc(m->email_max, sizeof(struct Email *));
53  m->v2r = mutt_mem_calloc(m->email_max, sizeof(int));
54  m->gen = gen++;
55 
56  return m;
57 }
struct Email ** emails
Array of Emails.
Definition: mailbox.h:99
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:50
The envelope/body of an email.
Definition: email.h:37
struct Notify * notify_new(void)
Create a new notifications handler.
Definition: notify.c:49
int email_max
Number of pointers in emails.
Definition: mailbox.h:100
A mailbox.
Definition: mailbox.h:81
int * v2r
Mapping from virtual to real msgno.
Definition: mailbox.h:101
struct Notify * notify
Notifications handler.
Definition: mailbox.h:144
struct Buffer * mutt_buffer_init(struct Buffer *buf)
Initialise a new Buffer.
Definition: buffer.c:46
struct Buffer pathbuf
Definition: mailbox.h:83
int gen
Generation number, for sorting.
Definition: mailbox.h:146
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mailbox_set_subset()

bool mailbox_set_subset ( struct Mailbox m,
struct ConfigSubset sub 
)

Set a Mailbox's Config Subset.

Parameters
mMailbox
subParent Config Subset
Return values
trueSuccess

Definition at line 212 of file mailbox.c.

213 {
214  if (!m || m->sub || !sub)
215  return false;
216 
217  m->sub = cs_subset_new(m->name, sub, m->notify);
219  return true;
220 }
char * name
A short name for the Mailbox.
Definition: mailbox.h:85
struct ConfigSubset * sub
Inherited config items.
Definition: mailbox.h:86
enum ConfigScope scope
Scope of Subset, e.g. SET_SCOPE_ACCOUNT.
Definition: subset.h:49
struct ConfigSubset * cs_subset_new(const char *name, struct ConfigSubset *sub_parent, struct Notify *not_parent)
Create a new Config Subset.
Definition: subset.c:133
This Config is Mailbox-specific.
Definition: subset.h:40
struct Notify * notify
Notifications handler.
Definition: mailbox.h:144
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mailbox_size_add()

void mailbox_size_add ( struct Mailbox m,
const struct Email e 
)

Add an email's size to the total size of a Mailbox.

Parameters
mMailbox
eEmail

Definition at line 191 of file mailbox.c.

192 {
193  m->size += email_size(e);
194 }
off_t size
Size of the Mailbox.
Definition: mailbox.h:87
size_t email_size(const struct Email *e)
compute the size of an email
Definition: email.c:117
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mailbox_size_sub()

void mailbox_size_sub ( struct Mailbox m,
const struct Email e 
)

Subtract an email's size from the total size of a Mailbox.

Parameters
mMailbox
eEmail

Definition at line 201 of file mailbox.c.

202 {
203  m->size -= email_size(e);
204 }
off_t size
Size of the Mailbox.
Definition: mailbox.h:87
size_t email_size(const struct Email *e)
compute the size of an email
Definition: email.c:117
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mailbox_update()

void mailbox_update ( struct Mailbox m)

Get the mailbox's current size.

Parameters
mMailbox to check
Note
Only applies to local Mailboxes

Definition at line 159 of file mailbox.c.

160 {
161  struct stat sb;
162 
163  if (!m)
164  return;
165 
166  if (stat(mailbox_path(m), &sb) == 0)
167  m->size = (off_t) sb.st_size;
168  else
169  m->size = 0;
170 }
static const char * mailbox_path(const struct Mailbox *m)
Get the Mailbox&#39;s path string.
Definition: mailbox.h:203
off_t size
Size of the Mailbox.
Definition: mailbox.h:87
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mailbox_path()

static const char* mailbox_path ( const struct Mailbox m)
inlinestatic

Get the Mailbox's path string.

Parameters
mMailbox
Return values
ptrPath string

Definition at line 203 of file mailbox.h.

204 {
205  return mutt_b2s(&m->pathbuf); // LCOV_EXCL_LINE
206 }
#define mutt_b2s(buf)
Definition: buffer.h:41
struct Buffer pathbuf
Definition: mailbox.h:83