NeoMutt  2022-04-29-215-gc12b98
Teaching an old dog new tricks
DOXYGEN
private.h File Reference

Maildir/MH private types. More...

#include <stdbool.h>
#include <stdio.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)
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
111 return num;
112}
#define ARRAY_FOREACH(elem, head)
Iterate over all elements of the array.
Definition: array.h:211
#define mutt_debug(LEVEL,...)
Definition: logging.h:84
@ LL_DEBUG2
Log at debug level 2.
Definition: logging.h:41
void mailbox_size_add(struct Mailbox *m, const struct Email *e)
Add an email's size to the total size of a Mailbox.
Definition: mailbox.c:237
void maildirarray_clear(struct MdEmailArray *mda)
Free a Maildir array.
Definition: mdemail.c:64
void mx_alloc_memory(struct Mailbox *m)
Create storage for the emails.
Definition: mx.c:1219
#define NONULL(x)
Definition: string2.h:37
bool read
Email is read.
Definition: email.h:48
bool old
Email is seen, but unread.
Definition: email.h:47
bool flagged
Marked important?
Definition: email.h:45
bool replied
Email has been replied to.
Definition: email.h:49
bool deleted
Email is deleted.
Definition: email.h:76
int index
The absolute (unsorted) message number.
Definition: email.h:110
int msg_count
Total number of messages.
Definition: mailbox.h:88
int email_max
Number of pointers in emails.
Definition: mailbox.h:97
struct Email ** emails
Array of Emails.
Definition: mailbox.h:96
A Maildir Email helper.
Definition: mdemail.h:34
char * canon_fname
Definition: mdemail.h:36
struct Email * email
Definition: mdemail.h:35
+ 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 78 of file mh.c.

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