NeoMutt  2024-04-25-85-g27bab4
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
shared.c
Go to the documentation of this file.
1
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#include "protos.h"
41
47mode_t maildir_umask(struct Mailbox *m)
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}
62
73void maildir_canon_filename(struct Buffer *dest, const char *src)
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}
96
105bool maildir_update_flags(struct Mailbox *m, struct Email *e_old, struct Email *e_new)
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}
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
Convenience wrapper for the core headers.
static const char * mailbox_path(const struct Mailbox *m)
Get the Mailbox's path string.
Definition: mailbox.h:223
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:57
#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:60
bool maildir_update_flags(struct Mailbox *m, struct Email *e_old, struct Email *e_new)
Update the mailbox flags.
Definition: shared.c:105
mode_t maildir_umask(struct Mailbox *m)
Create a umask from the mailbox directory.
Definition: shared.c:47
void maildir_canon_filename(struct Buffer *dest, const char *src)
Generate the canonical filename for a Maildir folder.
Definition: shared.c:73
Convenience wrapper for the library headers.
Many unsorted constants and some structs.
@ 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
Notmuch-specific Mailbox data.
Prototypes for many functions.
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:79
bool changed
Mailbox has been modified.
Definition: mailbox.h:110
void * mdata
Driver specific data.
Definition: mailbox.h:132
Maildir-specific Mailbox data -.
Definition: mdata.h:35