NeoMutt  2024-04-25-85-g27bab4
Teaching an old dog new tricks
No Matches
shared.c File Reference

Maildir shared functions. More...

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

Go to the source code of this file.


mode_t maildir_umask (struct Mailbox *m)
 Create a umask from the mailbox directory.
void maildir_canon_filename (struct Buffer *dest, const char *src)
 Generate the canonical filename for a Maildir folder.
bool maildir_update_flags (struct Mailbox *m, struct Email *e_old, struct Email *e_new)
 Update the mailbox flags.

Detailed Description

Maildir shared functions.

  • 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

◆ maildir_umask()

mode_t maildir_umask ( struct Mailbox m)

Create a umask from the mailbox directory.

Return values

Definition at line 47 of file shared.c.

50 if (mdata && mdata->umask)
51 return mdata->umask;
53 struct stat st = { 0 };
54 if (stat(mailbox_path(m), &st) != 0)
55 {
56 mutt_debug(LL_DEBUG1, "stat failed on %s\n", mailbox_path(m));
57 return 077;
58 }
60 return 0777 & ~st.st_mode;
static const char * mailbox_path(const struct Mailbox *m)
Get the Mailbox's path string.
Definition: mailbox.h:223
#define mutt_debug(LEVEL,...)
Definition: logging2.h:89
Log at debug level 1.
Definition: logging2.h:43
struct MaildirMboxData * maildir_mdata_get(struct Mailbox *m)
Get the private data for this Mailbox.
Definition: mdata.c:60
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_canon_filename()

void maildir_canon_filename ( struct Buffer dest,
const char *  src 

Generate the canonical filename for a Maildir folder.

destBuffer for the result
srcBuffer containing source filename
maildir filename is defined as: <base filename>:2,<flags> but <base filename> may contain additional comma separated fields. Additionally, : may be replaced as the field delimiter by a user defined alternative.

Definition at line 73 of file shared.c.

75 if (!dest || !src)
76 return;
78 char *t = strrchr(src, '/');
79 if (t)
80 src = t + 1;
82 buf_strcpy(dest, src);
84 const char c_maildir_field_delimiter = *cc_maildir_field_delimiter();
86 char searchable_bytes[8] = { 0 };
87 snprintf(searchable_bytes, sizeof(searchable_bytes), ",%c", c_maildir_field_delimiter);
88 char *u = strpbrk(dest->data, searchable_bytes);
90 if (u)
91 {
92 *u = '\0';
93 dest->dptr = u;
94 }
size_t buf_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition: buffer.c:395
const char * cc_maildir_field_delimiter(void)
Get the cached value of $maildir_field_delimiter.
Definition: config_cache.c:131
char * dptr
Current read/write position.
Definition: buffer.h:38
char * data
Pointer to data.
Definition: buffer.h:37
+ 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 105 of file shared.c.

107 if (!m)
108 return false;
110 /* save the global state here so we can reset it at the
111 * end of list block if required. */
112 bool context_changed = m->changed;
114 /* user didn't modify this message. alter the flags to match the
115 * current state on disk. This may not actually do
116 * anything. mutt_set_flag() will just ignore the call if the status
117 * bits are already properly set, but it is still faster not to pass
118 * through it */
119 if (e_old->flagged != e_new->flagged)
120 mutt_set_flag(m, e_old, MUTT_FLAG, e_new->flagged, true);
121 if (e_old->replied != e_new->replied)
122 mutt_set_flag(m, e_old, MUTT_REPLIED, e_new->replied, true);
123 if (e_old->read != e_new->read)
124 mutt_set_flag(m, e_old, MUTT_READ, e_new->read, true);
125 if (e_old->old != e_new->old)
126 mutt_set_flag(m, e_old, MUTT_OLD, e_new->old, true);
128 /* mutt_set_flag() will set this, but we don't need to
129 * sync the changes we made because we just updated the
130 * context to match the current on-disk state of the
131 * message. */
132 bool header_changed = e_old->changed;
133 e_old->changed = false;
135 /* if the mailbox was not modified before we made these
136 * changes, unset the changed flag since nothing needs to
137 * be synchronized. */
138 if (!context_changed)
139 m->changed = false;
141 return header_changed;
void mutt_set_flag(struct Mailbox *m, struct Email *e, enum MessageType flag, bool bf, bool upd_mbox)
Set a flag on an email.
Definition: flags.c:57
Messages that have been read.
Definition: mutt.h:73
Old messages.
Definition: mutt.h:71
Flagged messages.
Definition: mutt.h:79
Messages that have been replied to.
Definition: mutt.h:72
bool read
Email is read.
Definition: email.h:50
bool old
Email is seen, but unread.
Definition: email.h:49
bool changed
Email has been edited.
Definition: email.h:77
bool flagged
Marked important?
Definition: email.h:47
bool replied
Email has been replied to.
Definition: email.h:51
bool changed
Mailbox has been modified.
Definition: mailbox.h:110
+ Here is the call graph for this function:
+ Here is the caller graph for this function: