NeoMutt  2019-12-07-60-g0cfa53
Teaching an old dog new tricks
DOXYGEN
mailbox.c File Reference

Representation of a mailbox. More...

#include "config.h"
#include <sys/stat.h>
#include "config/lib.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 NotifyMailbox 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...
 
bool mailbox_set_subset (struct Mailbox *m, struct ConfigSubset *sub)
 Set a Mailbox's Config Subset. 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 42 of file mailbox.c.

43 {
44  struct Mailbox *m = mutt_mem_calloc(1, sizeof(struct Mailbox));
45 
47  m->notify = notify_new();
48 
49  m->email_max = 25;
50  m->emails = mutt_mem_calloc(m->email_max, sizeof(struct Email *));
51  m->v2r = mutt_mem_calloc(m->email_max, sizeof(int));
52 
53  return m;
54 }
struct Email ** emails
Array of Emails.
Definition: mailbox.h:98
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
int email_max
Number of pointers in emails.
Definition: mailbox.h:99
A mailbox.
Definition: mailbox.h:80
int * v2r
Mapping from virtual to real msgno.
Definition: mailbox.h:100
struct Notify * notify_new(void)
Create a new notifications handler.
Definition: notify.c:50
struct Notify * notify
Notifications handler.
Definition: mailbox.h:138
struct Buffer * mutt_buffer_init(struct Buffer *buf)
Initialise a new Buffer.
Definition: buffer.c:46
struct Buffer pathbuf
Definition: mailbox.h:82
+ 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 60 of file mailbox.c.

61 {
62  if (!ptr || !*ptr)
63  return;
64 
65  struct Mailbox *m = *ptr;
66  if (m->mdata && m->free_mdata)
67  m->free_mdata(&m->mdata);
68 
70 
71  if (m->mdata && m->free_mdata)
72  m->free_mdata(&m->mdata);
73 
75  cs_subset_free(&m->sub);
76  FREE(&m->name);
77  FREE(&m->realpath);
78  FREE(&m->emails);
79  FREE(&m->v2r);
80  notify_free(&m->notify);
81 
82  FREE(ptr);
83 }
struct Email ** emails
Array of Emails.
Definition: mailbox.h:98
char * realpath
Used for duplicate detection, context comparison, and the sidebar.
Definition: mailbox.h:83
void cs_subset_free(struct ConfigSubset **ptr)
Free a Config Subset.
Definition: subset.c:44
void(* free_mdata)(void **)
Driver-specific data free function.
Definition: mailbox.h:136
Mailbox was closed.
Definition: mailbox.h:169
char * name
A short name for the Mailbox.
Definition: mailbox.h:84
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:135
A mailbox.
Definition: mailbox.h:80
struct ConfigSubset * sub
Inherited config items.
Definition: mailbox.h:85
void notify_free(struct Notify **ptr)
Free a notification handler.
Definition: notify.c:63
int * v2r
Mapping from virtual to real msgno.
Definition: mailbox.h:100
#define FREE(x)
Definition: memory.h:40
struct Notify * notify
Notifications handler.
Definition: mailbox.h:138
struct Buffer pathbuf
Definition: mailbox.h:82
void mailbox_changed(struct Mailbox *m, enum NotifyMailbox action)
Notify observers of a change to a Mailbox.
Definition: mailbox.c:171
+ 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 90 of file mailbox.c.

91 {
92  if (!path)
93  return NULL;
94 
95  struct stat sb;
96  struct stat tmp_sb;
97 
98  if (stat(path, &sb) != 0)
99  return NULL;
100 
101  struct MailboxList ml = neomutt_mailboxlist_get_all(NeoMutt, MUTT_MAILBOX_ANY);
102  struct MailboxNode *np = NULL;
103  struct Mailbox *m = NULL;
104  STAILQ_FOREACH(np, &ml, entries)
105  {
106  if ((stat(mailbox_path(np->mailbox), &tmp_sb) == 0) &&
107  (sb.st_dev == tmp_sb.st_dev) && (sb.st_ino == tmp_sb.st_ino))
108  {
109  m = np->mailbox;
110  break;
111  }
112  }
114 
115  return m;
116 }
static const char * mailbox_path(const struct Mailbox *m)
Get the Mailbox&#39;s path string.
Definition: mailbox.h:191
void neomutt_mailboxlist_clear(struct MailboxList *ml)
Free a Mailbox List.
Definition: neomutt.c:135
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:157
A mailbox.
Definition: mailbox.h:80
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:349
List of Mailboxes.
Definition: mailbox.h:144
struct Mailbox * mailbox
Mailbox in the list.
Definition: mailbox.h:146
+ 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 126 of file mailbox.c.

127 {
128  if (!name)
129  return NULL;
130 
131  struct MailboxList ml = neomutt_mailboxlist_get_all(NeoMutt, MUTT_MAILBOX_ANY);
132  struct MailboxNode *np = NULL;
133  struct Mailbox *m = NULL;
134  STAILQ_FOREACH(np, &ml, entries)
135  {
136  if (mutt_str_strcmp(np->mailbox->name, name) == 0)
137  {
138  m = np->mailbox;
139  break;
140  }
141  }
143 
144  return m;
145 }
void neomutt_mailboxlist_clear(struct MailboxList *ml)
Free a Mailbox List.
Definition: neomutt.c:135
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:84
const char * name
Definition: pgpmicalg.c:46
struct MailboxList neomutt_mailboxlist_get_all(struct NeoMutt *n, enum MailboxType magic)
Get a List of all Mailboxes.
Definition: neomutt.c:157
A mailbox.
Definition: mailbox.h:80
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:349
List of Mailboxes.
Definition: mailbox.h:144
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:146
+ 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 153 of file mailbox.c.

154 {
155  struct stat sb;
156 
157  if (!m)
158  return;
159 
160  if (stat(mailbox_path(m), &sb) == 0)
161  m->size = (off_t) sb.st_size;
162  else
163  m->size = 0;
164 }
static const char * mailbox_path(const struct Mailbox *m)
Get the Mailbox&#39;s path string.
Definition: mailbox.h:191
off_t size
Size of the Mailbox.
Definition: mailbox.h:86
+ 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 NotifyMailbox  action 
)

Notify observers of a change to a Mailbox.

Parameters
mMailbox
actionChange to Mailbox

Definition at line 171 of file mailbox.c.

172 {
173  if (!m)
174  return;
175 
176  struct EventMailbox ev_m = { m };
177  notify_send(m->notify, NT_MAILBOX, action, &ev_m);
178 }
An Event that happened to a Mailbox.
Definition: mailbox.h:154
bool notify_send(struct Notify *notify, enum NotifyType event_type, int event_subtype, void *event_data)
Send out a notification message.
Definition: notify.c:138
Mailbox has changed.
Definition: notify_type.h:38
struct Notify * notify
Notifications handler.
Definition: mailbox.h:138
+ 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 185 of file mailbox.c.

186 {
187  m->size += email_size(e);
188 }
off_t size
Size of the Mailbox.
Definition: mailbox.h:86
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 195 of file mailbox.c.

196 {
197  m->size -= email_size(e);
198 }
off_t size
Size of the Mailbox.
Definition: mailbox.h:86
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_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 206 of file mailbox.c.

207 {
208  if (!m || m->sub || !sub)
209  return false;
210 
211  m->sub = cs_subset_new(m->name, sub, m->notify);
213  return true;
214 }
struct ConfigSubset * cs_subset_new(const char *name, struct ConfigSubset *sub_parent, struct Notify *not_parent)
Create a new Config Subset.
Definition: subset.c:84
char * name
A short name for the Mailbox.
Definition: mailbox.h:84
struct ConfigSubset * sub
Inherited config items.
Definition: mailbox.h:85
enum ConfigScope scope
Scope of Subset, e.g. SET_SCOPE_ACCOUNT.
Definition: subset.h:47
This Config is Mailbox-specific.
Definition: subset.h:38
struct Notify * notify
Notifications handler.
Definition: mailbox.h:138
+ Here is the call graph for this function:
+ Here is the caller graph for this function: