NeoMutt  2018-07-16 +2481-68dcde
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/mutt.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  MailboxNotification {
  MBN_CLOSED = 1, MBN_INVALID, MBN_RESORT, MBN_UPDATE,
  MBN_UNTAG
}
 Notifications about changes to a Mailbox. More...
 
enum  NotifyMailbox { NT_MAILBOX_ADD = 1, NT_MAILBOX_REMOVE }
 Types of Mailbox Event. More...
 

Functions

 STAILQ_HEAD (MailboxList, MailboxNode)
 
void mailbox_changed (struct Mailbox *m, enum MailboxNotification 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...
 
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 36 of file mailbox.h.

◆ MB_HIDDEN

#define MB_HIDDEN   1

Definition at line 37 of file mailbox.h.

◆ MUTT_ACL_NO_FLAGS

#define MUTT_ACL_NO_FLAGS   0

No flags are set.

Definition at line 74 of file mailbox.h.

◆ MUTT_ACL_ADMIN

#define MUTT_ACL_ADMIN   (1 << 0)

Administer the account (get/set permissions)

Definition at line 75 of file mailbox.h.

◆ MUTT_ACL_CREATE

#define MUTT_ACL_CREATE   (1 << 1)

Create a mailbox.

Definition at line 76 of file mailbox.h.

◆ MUTT_ACL_DELETE

#define MUTT_ACL_DELETE   (1 << 2)

Delete a message.

Definition at line 77 of file mailbox.h.

◆ MUTT_ACL_DELMX

#define MUTT_ACL_DELMX   (1 << 3)

Delete a mailbox.

Definition at line 78 of file mailbox.h.

◆ MUTT_ACL_EXPUNGE

#define MUTT_ACL_EXPUNGE   (1 << 4)

Expunge messages.

Definition at line 79 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 80 of file mailbox.h.

◆ MUTT_ACL_LOOKUP

#define MUTT_ACL_LOOKUP   (1 << 6)

Lookup mailbox (visible to 'list')

Definition at line 81 of file mailbox.h.

◆ MUTT_ACL_POST

#define MUTT_ACL_POST   (1 << 7)

Post (submit messages to the server)

Definition at line 82 of file mailbox.h.

◆ MUTT_ACL_READ

#define MUTT_ACL_READ   (1 << 8)

Read the mailbox.

Definition at line 83 of file mailbox.h.

◆ MUTT_ACL_SEEN

#define MUTT_ACL_SEEN   (1 << 9)

Change the 'seen' status of a message.

Definition at line 84 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 85 of file mailbox.h.

◆ MUTT_ACL_ALL

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

Definition at line 87 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 73 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 42 of file mailbox.h.

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

◆ MailboxNotification

Notifications about changes to a Mailbox.

Enumerator
MBN_CLOSED 

Mailbox was closed.

MBN_INVALID 

Email list was changed.

MBN_RESORT 

Email list needs resorting.

MBN_UPDATE 

Update internal tables.

MBN_UNTAG 

Clear the 'last-tagged' pointer.

Definition at line 61 of file mailbox.h.

62 {
63  MBN_CLOSED = 1,
64  MBN_INVALID,
65  MBN_RESORT,
66  MBN_UPDATE,
67  MBN_UNTAG,
68 };
Mailbox was closed.
Definition: mailbox.h:63
Update internal tables.
Definition: mailbox.h:66
Clear the &#39;last-tagged&#39; pointer.
Definition: mailbox.h:67
Email list needs resorting.
Definition: mailbox.h:65
Email list was changed.
Definition: mailbox.h:64

◆ NotifyMailbox

Types of Mailbox Event.

Enumerator
NT_MAILBOX_ADD 

A new Mailbox has been created.

NT_MAILBOX_REMOVE 

A Mailbox is about to be destroyed.

Definition at line 174 of file mailbox.h.

175 {
176  NT_MAILBOX_ADD = 1,
178 };
A new Mailbox has been created.
Definition: mailbox.h:176
A Mailbox is about to be destroyed.
Definition: mailbox.h:177

Function Documentation

◆ STAILQ_HEAD()

STAILQ_HEAD ( MailboxList  ,
MailboxNode   
)

◆ mailbox_changed()

void mailbox_changed ( struct Mailbox m,
enum MailboxNotification  action 
)

Notify observers of a change to a Mailbox.

Parameters
mMailbox
actionChange to Mailbox

Definition at line 160 of file mailbox.c.

161 {
162  if (!m)
163  return;
164 
165  notify_send(m->notify, NT_MAILBOX, action, 0);
166 }
Mailbox has changed.
Definition: notify_type.h:35
struct Notify * notify
Notifications handler.
Definition: mailbox.h:150
bool notify_send(struct Notify *notify, int type, int subtype, intptr_t data)
Send out a notification message.
Definition: notify.c:145
+ 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 79 of file mailbox.c.

80 {
81  if (!path)
82  return NULL;
83 
84  struct stat sb;
85  struct stat tmp_sb;
86 
87  if (stat(path, &sb) != 0)
88  return NULL;
89 
90  struct MailboxList ml = neomutt_mailboxlist_get_all(NeoMutt, MUTT_MAILBOX_ANY);
91  struct MailboxNode *np = NULL;
92  struct Mailbox *m = NULL;
93  STAILQ_FOREACH(np, &ml, entries)
94  {
95  if ((stat(mailbox_path(np->mailbox), &tmp_sb) == 0) &&
96  (sb.st_dev == tmp_sb.st_dev) && (sb.st_ino == tmp_sb.st_ino))
97  {
98  m = np->mailbox;
99  break;
100  }
101  }
103 
104  return m;
105 }
static const char * mailbox_path(const struct Mailbox *m)
Get the Mailbox&#39;s path string.
Definition: mailbox.h:194
void neomutt_mailboxlist_clear(struct MailboxList *ml)
Free a Mailbox List.
Definition: neomutt.c:134
Match any Mailbox type.
Definition: mailbox.h:44
Container for Accounts, Notifications.
Definition: neomutt.h:35
struct MailboxList neomutt_mailboxlist_get_all(struct NeoMutt *n, enum MailboxType magic)
Get a List of all Mailboxes.
Definition: neomutt.c:156
A mailbox.
Definition: mailbox.h:92
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:350
List of Mailboxes.
Definition: mailbox.h:156
struct Mailbox * mailbox
Mailbox in the list.
Definition: mailbox.h:158
+ 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 115 of file mailbox.c.

116 {
117  if (!name)
118  return NULL;
119 
120  struct MailboxList ml = neomutt_mailboxlist_get_all(NeoMutt, MUTT_MAILBOX_ANY);
121  struct MailboxNode *np = NULL;
122  struct Mailbox *m = NULL;
123  STAILQ_FOREACH(np, &ml, entries)
124  {
125  if (mutt_str_strcmp(np->mailbox->name, name) == 0)
126  {
127  m = np->mailbox;
128  break;
129  }
130  }
132 
133  return m;
134 }
void neomutt_mailboxlist_clear(struct MailboxList *ml)
Free a Mailbox List.
Definition: neomutt.c:134
Match any Mailbox type.
Definition: mailbox.h:44
Container for Accounts, Notifications.
Definition: neomutt.h:35
char * name
A short name for the Mailbox.
Definition: mailbox.h:96
const char * name
Definition: pgpmicalg.c:45
struct MailboxList neomutt_mailboxlist_get_all(struct NeoMutt *n, enum MailboxType magic)
Get a List of all Mailboxes.
Definition: neomutt.c:156
A mailbox.
Definition: mailbox.h:92
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:350
List of Mailboxes.
Definition: mailbox.h:156
int mutt_str_strcmp(const char *a, const char *b)
Compare two strings, safely.
Definition: string.c:615
struct Mailbox * mailbox
Mailbox in the list.
Definition: mailbox.h:158
+ 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 55 of file mailbox.c.

56 {
57  if (!ptr || !*ptr)
58  return;
59 
60  struct Mailbox *m = *ptr;
62 
63  if (m->mdata && m->free_mdata)
64  m->free_mdata(&m->mdata);
65 
67  FREE(&m->name);
68  FREE(&m->realpath);
69  notify_free(&m->notify);
70 
71  FREE(ptr);
72 }
void mailbox_changed(struct Mailbox *m, enum MailboxNotification action)
Notify observers of a change to a Mailbox.
Definition: mailbox.c:160
char * realpath
Used for duplicate detection, context comparison, and the sidebar.
Definition: mailbox.h:95
Mailbox was closed.
Definition: mailbox.h:63
void(* free_mdata)(void **)
Driver-specific data free function.
Definition: mailbox.h:148
char * name
A short name for the Mailbox.
Definition: mailbox.h:96
void mutt_buffer_dealloc(struct Buffer *buf)
Release the memory allocated by a buffer.
Definition: buffer.c:293
void * mdata
Driver specific data.
Definition: mailbox.h:147
A mailbox.
Definition: mailbox.h:92
void notify_free(struct Notify **ptr)
Free a notification handler.
Definition: notify.c:69
#define FREE(x)
Definition: memory.h:40
struct Notify * notify
Notifications handler.
Definition: mailbox.h:150
struct Buffer pathbuf
Definition: mailbox.h:94
+ 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 41 of file mailbox.c.

42 {
43  struct Mailbox *m = mutt_mem_calloc(1, sizeof(struct Mailbox));
44 
46  m->notify = notify_new(m, NT_MAILBOX);
47 
48  return m;
49 }
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:50
struct Notify * notify_new(void *object, enum NotifyType type)
Create a new notifications handler.
Definition: notify.c:54
A mailbox.
Definition: mailbox.h:92
Mailbox has changed.
Definition: notify_type.h:35
struct Notify * notify
Notifications handler.
Definition: mailbox.h:150
struct Buffer * mutt_buffer_init(struct Buffer *buf)
Initialise a new Buffer.
Definition: buffer.c:46
struct Buffer pathbuf
Definition: mailbox.h:94
+ 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 173 of file mailbox.c.

174 {
175  m->size += email_size(e);
176 }
off_t size
Size of the Mailbox.
Definition: mailbox.h:98
size_t email_size(const struct Email *e)
compute the size of an email
Definition: email.c:114
+ 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 183 of file mailbox.c.

184 {
185  m->size -= email_size(e);
186 }
off_t size
Size of the Mailbox.
Definition: mailbox.h:98
size_t email_size(const struct Email *e)
compute the size of an email
Definition: email.c:114
+ 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 142 of file mailbox.c.

143 {
144  struct stat sb;
145 
146  if (!m)
147  return;
148 
149  if (stat(mailbox_path(m), &sb) == 0)
150  m->size = (off_t) sb.st_size;
151  else
152  m->size = 0;
153 }
static const char * mailbox_path(const struct Mailbox *m)
Get the Mailbox&#39;s path string.
Definition: mailbox.h:194
off_t size
Size of the Mailbox.
Definition: mailbox.h:98
+ 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 194 of file mailbox.h.

195 {
196  return mutt_b2s(&m->pathbuf);
197 }
#define mutt_b2s(buf)
Definition: buffer.h:41
struct Buffer pathbuf
Definition: mailbox.h:94