NeoMutt  2021-02-05-666-ge300cd
Teaching an old dog new tricks
DOXYGEN
shared.c File Reference

Maildir/MH local mailbox type. More...

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

Go to the source code of this file.

Functions

mode_t mh_umask (struct Mailbox *m)
 Create a umask from the mailbox directory. More...
 
int maildir_move_to_mailbox (struct Mailbox *m, struct MdEmailArray *mda)
 Copy the Maildir list to the Mailbox. More...
 
bool maildir_update_flags (struct Mailbox *m, struct Email *e_old, struct Email *e_new)
 Update the mailbox flags. More...
 

Detailed Description

Maildir/MH local mailbox type.

Authors
  • Michael R. Elkins
  • Thomas Roessler
  • Michael R. Elkins
  • 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

◆ mh_umask()

mode_t mh_umask ( struct Mailbox m)

Create a umask from the mailbox directory.

Parameters
mMailbox
Return values
numUmask

Definition at line 52 of file shared.c.

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 }
static const char * mailbox_path(const struct Mailbox *m)
Get the Mailbox&#39;s path string.
Definition: mailbox.h:215
void * mdata
Driver specific data.
Definition: mailbox.h:136
mode_t mh_umask
Definition: mdata.h:37
#define mutt_debug(LEVEL,...)
Definition: logging.h:85
Log at debug level 1.
Definition: logging.h:40
Maildir-specific Mailbox data -.
Definition: mdata.h:34
struct MaildirMboxData * maildir_mdata_get(struct Mailbox *m)
Get the private data for this Mailbox.
Definition: mdata.c:58
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ maildir_move_to_mailbox()

int maildir_move_to_mailbox ( struct Mailbox m,
struct MdEmailArray *  mda 
)

Copy the Maildir list to the Mailbox.

Parameters
[in]mMailbox
[out]mdaMaildir array to copy, then free
Return values
numNumber of new emails
0Error

Definition at line 75 of file shared.c.

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 }
struct Email ** emails
Array of Emails.
Definition: mailbox.h:99
#define NONULL(x)
Definition: string2.h:37
int msg_count
Total number of messages.
Definition: mailbox.h:91
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
#define ARRAY_FOREACH(elem, head)
Iterate over all elements of the array.
Definition: array.h:206
void mx_alloc_memory(struct Mailbox *m)
Create storage for the emails.
Definition: mx.c:1212
char * canon_fname
Definition: mdemail.h:36
void maildirarray_clear(struct MdEmailArray *mda)
Free a Maildir array.
Definition: mdemail.c:64
bool read
Email is read.
Definition: email.h:51
A Maildir Email helper.
Definition: mdemail.h:33
Log at debug level 2.
Definition: logging.h:41
bool old
Email is seen, but unread.
Definition: email.h:50
struct Email * email
Definition: mdemail.h:35
int email_max
Number of pointers in emails.
Definition: mailbox.h:100
#define mutt_debug(LEVEL,...)
Definition: logging.h:85
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
+ 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 122 of file shared.c.

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 }
#define mutt_set_flag(m, e, flag, bf)
Definition: protos.h:66
Flagged messages.
Definition: mutt.h:98
bool changed
Email has been edited.
Definition: email.h:48
Messages that have been replied to.
Definition: mutt.h:91
bool read
Email is read.
Definition: email.h:51
bool old
Email is seen, but unread.
Definition: email.h:50
Old messages.
Definition: mutt.h:90
Messages that have been read.
Definition: mutt.h:92
bool flagged
Marked important?
Definition: email.h:43
bool replied
Email has been replied to.
Definition: email.h:54
bool changed
Mailbox has been modified.
Definition: mailbox.h:114
+ Here is the caller graph for this function: