NeoMutt  2019-11-11
Teaching an old dog new tricks
DOXYGEN
mailbox.c File Reference

Representation of a mailbox. More...

#include "config.h"
#include <sys/stat.h>
#include "email/lib.h"
#include "mailbox.h"
#include "neomutt.h"
+ Include dependency graph for mailbox.c:

Go to the source code of this file.

Functions

struct Mailboxmailbox_new (void)
 Create a new Mailbox. More...
 
void mailbox_free (struct Mailbox **ptr)
 Free 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_update (struct Mailbox *m)
 Get the mailbox's current size. More...
 
void mailbox_changed (struct Mailbox *m, enum MailboxNotification action)
 Notify observers of a change to a 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...
 

Detailed Description

Representation of a mailbox.

Authors
  • Michael R. Elkins
  • Kevin J. McCarthy
  • 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.c.

Function Documentation

◆ 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_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:294
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_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_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_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_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:110
+ 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:110
+ Here is the call graph for this function:
+ Here is the caller graph for this function: