NeoMutt  2025-12-11-769-g906513
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
msg_open_new()

Open a new message in a Mailbox. More...

+ Collaboration diagram for msg_open_new():

Functions

static bool comp_msg_open_new (struct Mailbox *m, struct Message *msg, const struct Email *e)
 Open a new message in a Mailbox - Implements MxOps::msg_open_new() -.
 
static bool imap_msg_open_new (struct Mailbox *m, struct Message *msg, const struct Email *e)
 Open a new message in a Mailbox - Implements MxOps::msg_open_new() -.
 
bool maildir_msg_open_new (struct Mailbox *m, struct Message *msg, const struct Email *e)
 Open a new message in a Mailbox - Implements MxOps::msg_open_new() -.
 
static bool mbox_msg_open_new (struct Mailbox *m, struct Message *msg, const struct Email *e)
 Open a new message in a Mailbox - Implements MxOps::msg_open_new() -.
 
static bool mh_msg_open_new (struct Mailbox *m, struct Message *msg, const struct Email *e)
 Open a new message in a Mailbox - Implements MxOps::msg_open_new() -.
 

Detailed Description

Open a new message in a Mailbox.

Parameters
mMailbox
msgMessage to open
eEmail
Return values
trueSuccess
falseFailure
Precondition
m is not NULL
msg is not NULL

Function Documentation

◆ comp_msg_open_new()

static bool comp_msg_open_new ( struct Mailbox * m,
struct Message * msg,
const struct Email * e )
static

Open a new message in a Mailbox - Implements MxOps::msg_open_new() -.

Definition at line 742 of file compress.c.

743{
744 if (!m->compress_info)
745 return false;
746
747 struct CompressInfo *ci = m->compress_info;
748
749 const struct MxOps *ops = ci->child_ops;
750 if (!ops)
751 return false;
752
753 /* Delegate */
754 return ops->msg_open_new(m, msg, e);
755}
Private data for compress.
Definition lib.h:61
const struct MxOps * child_ops
callbacks of de-compressed file
Definition lib.h:66
void * compress_info
Compressed mbox module private data.
Definition mailbox.h:120
Definition mxapi.h:87
bool(* msg_open_new)(struct Mailbox *m, struct Message *msg, const struct Email *e)
Definition mxapi.h:228

◆ imap_msg_open_new()

static bool imap_msg_open_new ( struct Mailbox * m,
struct Message * msg,
const struct Email * e )
static

Open a new message in a Mailbox - Implements MxOps::msg_open_new() -.

Definition at line 2382 of file imap.c.

2383{
2384 bool success = false;
2385
2386 struct Buffer *tempfile = buf_pool_get();
2387 buf_mktemp(tempfile);
2388
2389 msg->fp = mutt_file_fopen(buf_string(tempfile), "w");
2390 if (!msg->fp)
2391 {
2392 mutt_perror("%s", buf_string(tempfile));
2393 goto cleanup;
2394 }
2395
2396 msg->path = buf_strdup(tempfile);
2397 success = true;
2398
2399cleanup:
2400 buf_pool_release(&tempfile);
2401 return success;
2402}
char * buf_strdup(const struct Buffer *buf)
Copy a Buffer's string.
Definition buffer.c:571
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition buffer.h:96
#define mutt_file_fopen(PATH, MODE)
Definition file.h:138
#define mutt_perror(...)
Definition logging2.h:95
struct Buffer * buf_pool_get(void)
Get a Buffer from the pool.
Definition pool.c:91
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
Definition pool.c:111
String manipulation buffer.
Definition buffer.h:36
FILE * fp
pointer to the message data
Definition message.h:35
char * path
path to temp file
Definition message.h:36
#define buf_mktemp(buf)
Definition tmp.h:33
+ Here is the call graph for this function:

◆ maildir_msg_open_new()

bool maildir_msg_open_new ( struct Mailbox * m,
struct Message * msg,
const struct Email * e )

Open a new message in a Mailbox - Implements MxOps::msg_open_new() -.

Open a new (temporary) message in a maildir folder.

Note
This uses almost the maildir file name format, but with a {cur,new} prefix.

Definition at line 549 of file message.c.

550{
551 int fd;
552 char path[PATH_MAX] = { 0 };
553 char suffix[PATH_MAX] = { 0 };
554 char subdir[16] = { 0 };
555
556 if (e)
557 {
558 struct Email tmp = *e;
559 tmp.deleted = false;
560 tmp.edata = NULL;
561 maildir_gen_flags(suffix, sizeof(suffix), &tmp);
562 }
563 else
564 {
565 *suffix = '\0';
566 }
567
568 if (e && (e->read || e->old))
569 mutt_str_copy(subdir, "cur", sizeof(subdir));
570 else
571 mutt_str_copy(subdir, "new", sizeof(subdir));
572
573 mode_t new_umask = maildir_umask(m);
574 mode_t old_umask = umask(new_umask);
575 mutt_debug(LL_DEBUG3, "umask set to %03o\n", new_umask);
576
577 for (int retries = 0; retries < 16; retries++)
578 {
579 snprintf(path, sizeof(path), "%s/tmp/%s.%lld.R%" PRIu64 ".%s%s",
580 mailbox_path(m), subdir, (long long) mutt_date_now(),
581 mutt_rand64(), NONULL(ShortHostname), suffix);
582
583 mutt_debug(LL_DEBUG2, "Trying %s\n", path);
584
585 fd = open(path, O_WRONLY | O_EXCL | O_CREAT, 0666);
586 if (fd == -1)
587 {
588 if (errno != EEXIST)
589 {
590 umask(old_umask);
591 mutt_debug(LL_DEBUG3, "umask set to %03o\n", old_umask);
592 mutt_perror("%s", path);
593 return false;
594 }
595 }
596 else
597 {
598 mutt_debug(LL_DEBUG2, "Success\n");
599 msg->path = mutt_str_dup(path);
600 break;
601 }
602 }
603
604 if (fd == -1)
605 {
606 umask(old_umask);
607 mutt_debug(LL_DEBUG1, "%s: failed after 16 retries\n", __func__);
608 return false;
609 }
610 umask(old_umask);
611 mutt_debug(LL_DEBUG3, "umask set to %03o\n", old_umask);
612
613 msg->fp = fdopen(fd, "w");
614 if (!msg->fp)
615 {
616 FREE(&msg->path);
617 close(fd);
618 unlink(path);
619 return false;
620 }
621
622 return true;
623}
static const char * mailbox_path(const struct Mailbox *m)
Get the Mailbox's path string.
Definition mailbox.h:213
char * ShortHostname
Short version of the hostname.
Definition globals.c:36
#define mutt_debug(LEVEL,...)
Definition logging2.h:91
@ LL_DEBUG3
Log at debug level 3.
Definition logging2.h:47
@ LL_DEBUG2
Log at debug level 2.
Definition logging2.h:46
@ LL_DEBUG1
Log at debug level 1.
Definition logging2.h:45
void maildir_gen_flags(char *dest, size_t destlen, struct Email *e)
Generate the Maildir flags for an email.
Definition message.c:71
mode_t maildir_umask(struct Mailbox *m)
Create a umask from the mailbox directory.
Definition shared.c:46
#define FREE(x)
Free memory and set the pointer to NULL.
Definition memory.h:68
time_t mutt_date_now(void)
Return the number of seconds since the Unix epoch.
Definition date.c:457
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition string.c:257
size_t mutt_str_copy(char *dest, const char *src, size_t dsize)
Copy a string into a buffer (guaranteeing NUL-termination)
Definition string.c:586
#define PATH_MAX
Definition mutt.h:49
uint64_t mutt_rand64(void)
Create a 64-bit random number.
Definition random.c:123
#define NONULL(x)
Definition string2.h:44
The envelope/body of an email.
Definition email.h:39
bool read
Email is read.
Definition email.h:50
void * edata
Driver-specific data.
Definition email.h:74
bool old
Email is seen, but unread.
Definition email.h:49
char * path
Path of Email (for local Mailboxes)
Definition email.h:70
bool deleted
Email is deleted.
Definition email.h:78
+ Here is the call graph for this function:

◆ mbox_msg_open_new()

static bool mbox_msg_open_new ( struct Mailbox * m,
struct Message * msg,
const struct Email * e )
static

Open a new message in a Mailbox - Implements MxOps::msg_open_new() -.

Definition at line 1516 of file mbox.c.

1517{
1519 if (!adata)
1520 return false;
1521
1522 msg->fp = adata->fp;
1523 return true;
1524}
static struct MboxAccountData * mbox_adata_get(struct Mailbox *m)
Get the private data associated with a Mailbox.
Definition mbox.c:121
void * adata
Private data (for Mailbox backends)
Definition account.h:42
Mbox-specific Account data -.
Definition lib.h:50
+ Here is the call graph for this function:

◆ mh_msg_open_new()

static bool mh_msg_open_new ( struct Mailbox * m,
struct Message * msg,
const struct Email * e )
static

Open a new message in a Mailbox - Implements MxOps::msg_open_new() -.

Open a new (temporary) message in an MH folder.

Definition at line 1166 of file mh.c.

1167{
1168 return mh_mkstemp(m, &msg->fp, &msg->path);
1169}
bool mh_mkstemp(struct Mailbox *m, FILE **fp, char **tgt)
Create a temporary file.
Definition shared.c:73
+ Here is the call graph for this function: