NeoMutt  2021-02-05-666-ge300cd
Teaching an old dog new tricks
DOXYGEN
shared.c
Go to the documentation of this file.
1 
32 #include "config.h"
33 #include <stdbool.h>
34 #include <stdio.h>
35 #include <sys/stat.h>
36 #include "private.h"
37 #include "mutt/lib.h"
38 #include "email/lib.h"
39 #include "core/lib.h"
40 #include "mutt.h"
41 #include "lib.h"
42 #include "mdata.h"
43 #include "mdemail.h"
44 #include "mx.h"
45 #include "protos.h"
46 
52 mode_t mh_umask(struct Mailbox *m)
53 {
55  if (mdata && mdata->mh_umask)
56  return mdata->mh_umask;
57 
58  struct stat st;
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  }
64 
65  return 0777 & ~st.st_mode;
66 }
67 
75 int maildir_move_to_mailbox(struct Mailbox *m, struct MdEmailArray *mda)
76 {
77  if (!m)
78  return 0;
79 
80  int oldmsgcount = m->msg_count;
81 
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;
90 
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)
96  mx_alloc_memory(m);
97 
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);
101 
102  md->email = NULL;
103  m->msg_count++;
104  }
105 
106  int num = 0;
107  if (m->msg_count > oldmsgcount)
108  num = m->msg_count - oldmsgcount;
109 
110  maildirarray_clear(mda);
111  return num;
112 }
113 
122 bool maildir_update_flags(struct Mailbox *m, struct Email *e_old, struct Email *e_new)
123 {
124  if (!m)
125  return false;
126 
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;
130 
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);
144 
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;
151 
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;
157 
158  return header_changed;
159 }
struct Email ** emails
Array of Emails.
Definition: mailbox.h:99
static const char * mailbox_path(const struct Mailbox *m)
Get the Mailbox&#39;s path string.
Definition: mailbox.h:215
#define NONULL(x)
Definition: string2.h:37
int msg_count
Total number of messages.
Definition: mailbox.h:91
#define mutt_set_flag(m, e, flag, bf)
Definition: protos.h:66
The envelope/body of an email.
Definition: email.h:37
void mailbox_size_add(struct Mailbox *m, const struct Email *e)
Add an email&#39;s size to the total size of a Mailbox.
Definition: mailbox.c:223
Structs that make up an email.
Maildir-specific Mailbox data.
#define ARRAY_FOREACH(elem, head)
Iterate over all elements of the array.
Definition: array.h:206
Flagged messages.
Definition: mutt.h:98
void mx_alloc_memory(struct Mailbox *m)
Create storage for the emails.
Definition: mx.c:1212
bool changed
Email has been edited.
Definition: email.h:48
char * canon_fname
Definition: mdemail.h:36
void maildirarray_clear(struct MdEmailArray *mda)
Free a Maildir array.
Definition: mdemail.c:64
int maildir_move_to_mailbox(struct Mailbox *m, struct MdEmailArray *mda)
Copy the Maildir list to the Mailbox.
Definition: shared.c:75
Messages that have been replied to.
Definition: mutt.h:91
bool read
Email is read.
Definition: email.h:51
A Maildir Email helper.
Definition: mdemail.h:33
Many unsorted constants and some structs.
Log at debug level 2.
Definition: logging.h:41
API for mailboxes.
bool old
Email is seen, but unread.
Definition: email.h:50
Convenience wrapper for the core headers.
void * mdata
Driver specific data.
Definition: mailbox.h:136
mode_t mh_umask
Definition: mdata.h:37
Old messages.
Definition: mutt.h:90
Maildir/MH private types.
Prototypes for many functions.
struct Email * email
Definition: mdemail.h:35
int email_max
Number of pointers in emails.
Definition: mailbox.h:100
A mailbox.
Definition: mailbox.h:81
Messages that have been read.
Definition: mutt.h:92
bool maildir_update_flags(struct Mailbox *m, struct Email *e_old, struct Email *e_new)
Update the mailbox flags.
Definition: shared.c:122
#define mutt_debug(LEVEL,...)
Definition: logging.h:85
Maildir Email helper.
Log at debug level 1.
Definition: logging.h:40
bool flagged
Marked important?
Definition: email.h:43
bool deleted
Email is deleted.
Definition: email.h:45
bool replied
Email has been replied to.
Definition: email.h:54
int index
The absolute (unsorted) message number.
Definition: email.h:86
bool changed
Mailbox has been modified.
Definition: mailbox.h:114
Convenience wrapper for the library headers.
Maildir-specific Mailbox data -.
Definition: mdata.h:34
mode_t mh_umask(struct Mailbox *m)
Create a umask from the mailbox directory.
Definition: shared.c:52
struct MaildirMboxData * maildir_mdata_get(struct Mailbox *m)
Get the private data for this Mailbox.
Definition: mdata.c:58