NeoMutt  2025-12-11-435-g4ac674
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
shared.c
Go to the documentation of this file.
1
22
28
29#include "config.h"
30#include <stdbool.h>
31#include <stdio.h>
32#include <string.h>
33#include <sys/stat.h>
34#include <sys/types.h>
35#include "mutt/lib.h"
36#include "email/lib.h"
37#include "core/lib.h"
38#include "mutt.h"
39#include "mdata.h"
40
46mode_t maildir_umask(struct Mailbox *m)
47{
49 if (mdata && mdata->umask)
50 return mdata->umask;
51
52 struct stat st = { 0 };
53 if (stat(mailbox_path(m), &st) != 0)
54 {
55 mutt_debug(LL_DEBUG1, "stat failed on %s\n", mailbox_path(m));
56 return 077;
57 }
58
59 return 0777 & ~st.st_mode;
60}
61
72void maildir_canon_filename(struct Buffer *dest, const char *src)
73{
74 if (!dest || !src)
75 return;
76
77 char *t = strrchr(src, '/');
78 if (t)
79 src = t + 1;
80
81 buf_strcpy(dest, src);
82
83 const char c_maildir_field_delimiter = *cc_maildir_field_delimiter();
84
85 char searchable_bytes[8] = { 0 };
86 snprintf(searchable_bytes, sizeof(searchable_bytes), ",%c", c_maildir_field_delimiter);
87 char *u = strpbrk(dest->data, searchable_bytes);
88
89 if (u)
90 {
91 *u = '\0';
92 dest->dptr = u;
93 }
94}
95
104bool maildir_update_flags(struct Mailbox *m, struct Email *e_old, struct Email *e_new)
105{
106 if (!m)
107 return false;
108
109 /* save the global state here so we can reset it at the
110 * end of list block if required. */
111 bool context_changed = m->changed;
112
113 /* user didn't modify this message. alter the flags to match the
114 * current state on disk. This may not actually do
115 * anything. mutt_set_flag() will just ignore the call if the status
116 * bits are already properly set, but it is still faster not to pass
117 * through it */
118 if (e_old->flagged != e_new->flagged)
119 mutt_set_flag(m, e_old, MUTT_FLAG, e_new->flagged, true);
120 if (e_old->replied != e_new->replied)
121 mutt_set_flag(m, e_old, MUTT_REPLIED, e_new->replied, true);
122 if (e_old->read != e_new->read)
123 mutt_set_flag(m, e_old, MUTT_READ, e_new->read, true);
124 if (e_old->old != e_new->old)
125 mutt_set_flag(m, e_old, MUTT_OLD, e_new->old, true);
126
127 /* mutt_set_flag() will set this, but we don't need to
128 * sync the changes we made because we just updated the
129 * context to match the current on-disk state of the
130 * message. */
131 bool header_changed = e_old->changed;
132 e_old->changed = false;
133
134 /* if the mailbox was not modified before we made these
135 * changes, unset the changed flag since nothing needs to
136 * be synchronized. */
137 if (!context_changed)
138 m->changed = false;
139
140 return header_changed;
141}
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.
Convenience wrapper for the core headers.
static const char * mailbox_path(const struct Mailbox *m)
Get the Mailbox's path string.
Definition mailbox.h:213
Structs that make up an email.
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:54
#define mutt_debug(LEVEL,...)
Definition logging2.h:91
@ LL_DEBUG1
Log at debug level 1.
Definition logging2.h:45
struct MaildirMboxData * maildir_mdata_get(struct Mailbox *m)
Get the private data for this Mailbox.
Definition mdata.c:59
Maildir-specific Mailbox data.
bool maildir_update_flags(struct Mailbox *m, struct Email *e_old, struct Email *e_new)
Update the mailbox flags.
Definition shared.c:104
mode_t maildir_umask(struct Mailbox *m)
Create a umask from the mailbox directory.
Definition shared.c:46
void maildir_canon_filename(struct Buffer *dest, const char *src)
Generate the canonical filename for a Maildir folder.
Definition shared.c:72
Convenience wrapper for the library headers.
Many unsorted constants and some structs.
@ MUTT_READ
Messages that have been read.
Definition mutt.h:92
@ MUTT_OLD
Old messages.
Definition mutt.h:90
@ MUTT_FLAG
Flagged messages.
Definition mutt.h:98
@ MUTT_REPLIED
Messages that have been replied to.
Definition mutt.h:91
String manipulation buffer.
Definition buffer.h:36
char * dptr
Current read/write position.
Definition buffer.h:38
char * data
Pointer to data.
Definition buffer.h:37
The envelope/body of an email.
Definition email.h:39
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
A mailbox.
Definition mailbox.h:78
bool changed
Mailbox has been modified.
Definition mailbox.h:109
void * mdata
Driver specific data.
Definition mailbox.h:131
Maildir-specific Mailbox data -.
Definition mdata.h:35