NeoMutt  2023-03-22-27-g3cb248
Teaching an old dog new tricks
shared.c File Reference

Maildir/MH local mailbox type. More...

#include "config.h"
#include <stdbool.h>
#include <stdio.h>
#include <sys/stat.h>
#include "private.h"
#include "mutt/lib.h"
#include "email/lib.h"
#include "core/lib.h"
#include "mutt.h"
#include "lib.h"
#include "mdata.h"
#include "mdemail.h"
#include "mx.h"
#include "protos.h"
+ Include dependency graph for shared.c:

Go to the source code of this file.


mode_t mh_umask (struct Mailbox *m)
 Create a umask from the mailbox directory. More...
int maildir_move_to_mailbox (struct Mailbox *m, struct MdEmailArray *mda)
 Copy the Maildir list to the Mailbox. More...
bool maildir_update_flags (struct Mailbox *m, struct Email *e_old, struct Email *e_new)
 Update the mailbox flags. More...

Detailed Description

Maildir/MH local mailbox type.

  • Michael R. Elkins
  • Thomas Roessler
  • 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

Definition in file shared.c.

Function Documentation

◆ mh_umask()

mode_t mh_umask ( struct Mailbox m)

Create a umask from the mailbox directory.

Return values

Definition at line 52 of file shared.c.

55 if (mdata && mdata->mh_umask)
56 return mdata->mh_umask;
58 struct stat st = { 0 };
59 if (stat(mailbox_path(m), &st) != 0)
60 {
61 mutt_debug(LL_DEBUG1, "stat failed on %s\n", mailbox_path(m));
62 return 077;
63 }
65 return 0777 & ~st.st_mode;
#define mutt_debug(LEVEL,...)
Definition: logging.h:84
Log at debug level 1.
Definition: logging.h:40
static const char * mailbox_path(const struct Mailbox *m)
Get the Mailbox's path string.
Definition: mailbox.h:209
struct MaildirMboxData * maildir_mdata_get(struct Mailbox *m)
Get the private data for this Mailbox.
Definition: mdata.c:58
void * mdata
Driver specific data.
Definition: mailbox.h:132
Maildir-specific Mailbox data -.
Definition: mdata.h:35
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ maildir_move_to_mailbox()

int maildir_move_to_mailbox ( struct Mailbox m,
struct MdEmailArray *  mda 

Copy the Maildir list to the Mailbox.

[out]mdaMaildir array to copy, then free
Return values
numNumber of new emails

Definition at line 75 of file shared.c.

77 if (!m)
78 return 0;
80 int oldmsgcount = m->msg_count;
82 struct MdEmail *md = NULL;
83 struct MdEmail **mdp = NULL;
84 ARRAY_FOREACH(mdp, mda)
85 {
86 md = *mdp;
87 mutt_debug(LL_DEBUG2, "Considering %s\n", NONULL(md->canon_fname));
88 if (!md->email)
89 continue;
91 mutt_debug(LL_DEBUG2, "Adding header structure. Flags: %s%s%s%s%s\n",
92 md->email->flagged ? "f" : "", md->email->deleted ? "D" : "",
93 md->email->replied ? "r" : "", md->email->old ? "O" : "",
94 md->email->read ? "R" : "");
95 if (m->msg_count == m->email_max)
98 m->emails[m->msg_count] = md->email;
99 m->emails[m->msg_count]->index = m->msg_count;
100 mailbox_size_add(m, md->email);
102 md->email = NULL;
103 m->msg_count++;
104 }
106 int num = 0;
107 if (m->msg_count > oldmsgcount)
108 num = m->msg_count - oldmsgcount;
111 return num;
#define ARRAY_FOREACH(elem, head)
Iterate over all elements of the array.
Definition: array.h:211
Log at debug level 2.
Definition: logging.h:41
void mailbox_size_add(struct Mailbox *m, const struct Email *e)
Add an email's size to the total size of a Mailbox.
Definition: mailbox.c:237
void maildirarray_clear(struct MdEmailArray *mda)
Free a Maildir array.
Definition: mdemail.c:64
void mx_alloc_memory(struct Mailbox *m)
Create storage for the emails.
Definition: mx.c:1226
#define NONULL(x)
Definition: string2.h:37
bool read
Email is read.
Definition: email.h:48
bool old
Email is seen, but unread.
Definition: email.h:47
bool flagged
Marked important?
Definition: email.h:45
bool replied
Email has been replied to.
Definition: email.h:49
bool deleted
Email is deleted.
Definition: email.h:76
int index
The absolute (unsorted) message number.
Definition: email.h:109
int msg_count
Total number of messages.
Definition: mailbox.h:88
int email_max
Number of pointers in emails.
Definition: mailbox.h:97
struct Email ** emails
Array of Emails.
Definition: mailbox.h:96
A Maildir Email helper.
Definition: mdemail.h:34
char * canon_fname
Definition: mdemail.h:36
struct Email * email
Definition: mdemail.h:35
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ maildir_update_flags()

bool maildir_update_flags ( struct Mailbox m,
struct Email e_old,
struct Email e_new 

Update the mailbox flags.

e_oldOld Email
e_newNew Email
Return values
trueThe flags changed

Definition at line 122 of file shared.c.

124 if (!m)
125 return false;
127 /* save the global state here so we can reset it at the
128 * end of list block if required. */
129 bool context_changed = m->changed;
131 /* user didn't modify this message. alter the flags to match the
132 * current state on disk. This may not actually do
133 * anything. mutt_set_flag() will just ignore the call if the status
134 * bits are already properly set, but it is still faster not to pass
135 * through it */
136 if (e_old->flagged != e_new->flagged)
137 mutt_set_flag(m, e_old, MUTT_FLAG, e_new->flagged);
138 if (e_old->replied != e_new->replied)
139 mutt_set_flag(m, e_old, MUTT_REPLIED, e_new->replied);
140 if (e_old->read != e_new->read)
141 mutt_set_flag(m, e_old, MUTT_READ, e_new->read);
142 if (e_old->old != e_new->old)
143 mutt_set_flag(m, e_old, MUTT_OLD, e_new->old);
145 /* mutt_set_flag() will set this, but we don't need to
146 * sync the changes we made because we just updated the
147 * context to match the current on-disk state of the
148 * message. */
149 bool header_changed = e_old->changed;
150 e_old->changed = false;
152 /* if the mailbox was not modified before we made these
153 * changes, unset the changed flag since nothing needs to
154 * be synchronized. */
155 if (!context_changed)
156 m->changed = false;
158 return header_changed;
Messages that have been read.
Definition: mutt.h:81
Old messages.
Definition: mutt.h:79
Flagged messages.
Definition: mutt.h:87
Messages that have been replied to.
Definition: mutt.h:80
#define mutt_set_flag(m, e, flag, bf)
Definition: protos.h:63
bool changed
Email has been edited.
Definition: email.h:75
bool changed
Mailbox has been modified.
Definition: mailbox.h:110
+ Here is the caller graph for this function: