NeoMutt  2024-11-14-34-g5aaf0d
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
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.

Functions

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.

Authors
  • 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 shared.c.

Function Documentation

◆ maildir_umask()

mode_t maildir_umask ( struct Mailbox m)

Create a umask from the mailbox directory.

Parameters
mMailbox
Return values
numUmask

Definition at line 47 of file shared.c.

48{
50 if (mdata && mdata->umask)
51 return mdata->umask;
52
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 }
59
60 return 0777 & ~st.st_mode;
61}
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
@ LL_DEBUG1
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:59
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.

Parameters
destBuffer for the result
srcBuffer containing source filename
Note
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.

74{
75 if (!dest || !src)
76 return;
77
78 char *t = strrchr(src, '/');
79 if (t)
80 src = t + 1;
81
82 buf_strcpy(dest, src);
83
84 const char c_maildir_field_delimiter = *cc_maildir_field_delimiter();
85
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);
89
90 if (u)
91 {
92 *u = '\0';
93 dest->dptr = u;
94 }
95}
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.

Parameters
mMailbox
e_oldOld Email
e_newNew Email
Return values
trueThe flags changed
falseOtherwise

Definition at line 105 of file shared.c.

106{
107 if (!m)
108 return false;
109
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;
113
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);
127
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;
134
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;
140
141 return header_changed;
142}
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
@ MUTT_READ
Messages that have been read.
Definition: mutt.h:73
@ MUTT_OLD
Old messages.
Definition: mutt.h:71
@ MUTT_FLAG
Flagged messages.
Definition: mutt.h:79
@ MUTT_REPLIED
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: