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

Maildir/MH private types. More...

#include <stdio.h>
#include <stdbool.h>
#include <sys/types.h>
+ Include dependency graph for private.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

int maildir_move_to_mailbox (struct Mailbox *m, struct MdEmailArray *mda)
 Copy the Maildir list to the Mailbox. More...
 
bool mh_mkstemp (struct Mailbox *m, FILE **fp, char **tgt)
 Create a temporary file. More...
 
mode_t mh_umask (struct Mailbox *m)
 Create a umask from the mailbox directory. More...
 

Detailed Description

Maildir/MH private types.

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 private.h.

Function Documentation

◆ 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:

◆ mh_mkstemp()

bool mh_mkstemp ( struct Mailbox m,
FILE **  fp,
char **  tgt 
)

Create a temporary file.

Parameters
[in]mMailbox to create the file in
[out]fpFile handle
[out]tgtFile name
Return values
trueSuccess
falseFailure

Definition at line 77 of file mh.c.

78 {
79  int fd;
80  char path[PATH_MAX];
81 
82  mode_t omask = umask(mh_umask(m));
83  while (true)
84  {
85  snprintf(path, sizeof(path), "%s/.neomutt-%s-%d-%" PRIu64, mailbox_path(m),
86  NONULL(ShortHostname), (int) getpid(), mutt_rand64());
87  fd = open(path, O_WRONLY | O_EXCL | O_CREAT, 0666);
88  if (fd == -1)
89  {
90  if (errno != EEXIST)
91  {
92  mutt_perror(path);
93  umask(omask);
94  return false;
95  }
96  }
97  else
98  {
99  *tgt = mutt_str_dup(path);
100  break;
101  }
102  }
103  umask(omask);
104 
105  *fp = fdopen(fd, "w");
106  if (!*fp)
107  {
108  FREE(tgt);
109  close(fd);
110  unlink(path);
111  return false;
112  }
113 
114  return true;
115 }
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
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:370
#define mutt_perror(...)
Definition: logging.h:89
uint64_t mutt_rand64(void)
Create a 64-bit random number.
Definition: random.c:130
#define PATH_MAX
Definition: mutt.h:40
WHERE char * ShortHostname
Short version of the hostname.
Definition: mutt_globals.h:46
mode_t mh_umask(struct Mailbox *m)
Create a umask from the mailbox directory.
Definition: shared.c:52
#define FREE(x)
Definition: memory.h:40
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ 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: