NeoMutt  2018-07-16 +2225-8687db
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"

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

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

#define MB_NORMAL   0

Definition at line 37 of file mailbox.h.

#define MB_HIDDEN   1

Definition at line 38 of file mailbox.h.

#define MUTT_ACL_NO_FLAGS   0

No flags are set.

Definition at line 75 of file mailbox.h.

#define MUTT_ACL_ADMIN   (1 << 0)

Administer the account (get/set permissions)

Definition at line 76 of file mailbox.h.

#define MUTT_ACL_CREATE   (1 << 1)

Create a mailbox.

Definition at line 77 of file mailbox.h.

#define MUTT_ACL_DELETE   (1 << 2)

Delete a message.

Definition at line 78 of file mailbox.h.

#define MUTT_ACL_DELMX   (1 << 3)

Delete a mailbox.

Definition at line 79 of file mailbox.h.

#define MUTT_ACL_EXPUNGE   (1 << 4)

Expunge messages.

Definition at line 80 of file mailbox.h.

#define MUTT_ACL_INSERT   (1 << 5)

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

Definition at line 81 of file mailbox.h.

#define MUTT_ACL_LOOKUP   (1 << 6)

Lookup mailbox (visible to 'list')

Definition at line 82 of file mailbox.h.

#define MUTT_ACL_POST   (1 << 7)

Post (submit messages to the server)

Definition at line 83 of file mailbox.h.

#define MUTT_ACL_READ   (1 << 8)

Read the mailbox.

Definition at line 84 of file mailbox.h.

#define MUTT_ACL_SEEN   (1 << 9)

Change the 'seen' status of a message.

Definition at line 85 of file mailbox.h.

#define MUTT_ACL_WRITE   (1 << 10)

Write to a message (for flagging or linking threads)

Definition at line 86 of file mailbox.h.

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

Definition at line 88 of file mailbox.h.

Typedef Documentation

typedef uint16_t AclFlags

ACL Rights - These show permission to...

Flags, e.g. MUTT_ACL_ADMIN

Definition at line 74 of file mailbox.h.

Enumeration Type Documentation

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

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 62 of file mailbox.h.

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

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 175 of file mailbox.h.

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

Function Documentation

STAILQ_HEAD ( MailboxList  ,
MailboxNode   
)
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 159 of file mailbox.c.

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

79 {
80  if (!path)
81  return NULL;
82 
83  struct stat sb;
84  struct stat tmp_sb;
85 
86  if (stat(path, &sb) != 0)
87  return NULL;
88 
89  struct MailboxList ml = neomutt_mailboxlist_get_all(NeoMutt, MUTT_MAILBOX_ANY);
90  struct MailboxNode *np = NULL;
91  struct Mailbox *m = NULL;
92  STAILQ_FOREACH(np, &ml, entries)
93  {
94  if ((stat(mutt_b2s(np->mailbox->pathbuf), &tmp_sb) == 0) &&
95  (sb.st_dev == tmp_sb.st_dev) && (sb.st_ino == tmp_sb.st_ino))
96  {
97  m = np->mailbox;
98  break;
99  }
100  }
102 
103  return m;
104 }
void neomutt_mailboxlist_clear(struct MailboxList *ml)
Free a Mailbox List.
Definition: neomutt.c:134
Match any Mailbox type.
Definition: mailbox.h:45
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
#define mutt_b2s(buf)
Definition: buffer.h:42
A mailbox.
Definition: mailbox.h:93
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:350
struct Buffer * pathbuf
Definition: mailbox.h:95
List of Mailboxes.
Definition: mailbox.h:157
struct Mailbox * mailbox
Mailbox in the list.
Definition: mailbox.h:159
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 114 of file mailbox.c.

115 {
116  if (!name)
117  return NULL;
118 
119  struct MailboxList ml = neomutt_mailboxlist_get_all(NeoMutt, MUTT_MAILBOX_ANY);
120  struct MailboxNode *np = NULL;
121  struct Mailbox *m = NULL;
122  STAILQ_FOREACH(np, &ml, entries)
123  {
124  if (mutt_str_strcmp(np->mailbox->name, name) == 0)
125  {
126  m = np->mailbox;
127  break;
128  }
129  }
131 
132  return m;
133 }
void neomutt_mailboxlist_clear(struct MailboxList *ml)
Free a Mailbox List.
Definition: neomutt.c:134
Match any Mailbox type.
Definition: mailbox.h:45
Container for Accounts, Notifications.
Definition: neomutt.h:35
char * name
A short name for the Mailbox.
Definition: mailbox.h:97
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:93
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:350
List of Mailboxes.
Definition: mailbox.h:157
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:159
void mailbox_free ( struct Mailbox **  ptr)

Free a Mailbox.

Parameters
[out]ptrMailbox to free

Definition at line 56 of file mailbox.c.

57 {
58  if (!ptr || !*ptr)
59  return;
60 
61  struct Mailbox *m = *ptr;
63  notify_free(&m->notify);
64 
66  FREE(&m->name);
67  if (m->mdata && m->free_mdata)
68  m->free_mdata(&m->mdata);
69  FREE(&m->realpath);
70  FREE(ptr);
71 }
void mailbox_changed(struct Mailbox *m, enum MailboxNotification action)
Notify observers of a change to a Mailbox.
Definition: mailbox.c:159
char * realpath
Used for duplicate detection, context comparison, and the sidebar.
Definition: mailbox.h:96
Mailbox was closed.
Definition: mailbox.h:64
void(* free_mdata)(void **)
Driver-specific data free function.
Definition: mailbox.h:149
char * name
A short name for the Mailbox.
Definition: mailbox.h:97
void mutt_buffer_free(struct Buffer **p)
Release a Buffer and its contents.
Definition: buffer.c:134
void * mdata
Driver specific data.
Definition: mailbox.h:148
A mailbox.
Definition: mailbox.h:93
void notify_free(struct Notify **ptr)
Free a notification handler.
Definition: notify.c:69
struct Buffer * pathbuf
Definition: mailbox.h:95
#define FREE(x)
Definition: memory.h:40
struct Notify * notify
Notifications handler.
Definition: mailbox.h:151
struct Mailbox* mailbox_new ( void  )

Create a new Mailbox.

Return values
ptrNew Mailbox

Definition at line 42 of file mailbox.c.

43 {
44  struct Mailbox *m = mutt_mem_calloc(1, sizeof(struct Mailbox));
45 
46  m->pathbuf = mutt_buffer_new();
47  m->notify = notify_new(m, NT_MAILBOX);
48 
49  return m;
50 }
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:93
struct Buffer * mutt_buffer_new(void)
Create and initialise a Buffer.
Definition: buffer.c:45
struct Buffer * pathbuf
Definition: mailbox.h:95
Mailbox has changed.
Definition: notify_type.h:35
struct Notify * notify
Notifications handler.
Definition: mailbox.h:151
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 172 of file mailbox.c.

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

183 {
184  m->size -= mutt_email_size(e);
185 }
off_t size
Size of the Mailbox.
Definition: mailbox.h:99
size_t mutt_email_size(const struct Email *e)
compute the size of an email
Definition: email.c:109
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 141 of file mailbox.c.

142 {
143  struct stat sb;
144 
145  if (!m)
146  return;
147 
148  if (stat(mutt_b2s(m->pathbuf), &sb) == 0)
149  m->size = (off_t) sb.st_size;
150  else
151  m->size = 0;
152 }
off_t size
Size of the Mailbox.
Definition: mailbox.h:99
#define mutt_b2s(buf)
Definition: buffer.h:42
struct Buffer * pathbuf
Definition: mailbox.h:95