NeoMutt  2025-12-11-977-g8a21d8
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 741 of file compress.c.

742{
743 if (!m->compress_info)
744 return false;
745
746 struct CompressInfo *ci = m->compress_info;
747
748 const struct MxOps *ops = ci->child_ops;
749 if (!ops)
750 return false;
751
752 /* Delegate */
753 return ops->msg_open_new(m, msg, e);
754}
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:123
Definition mxapi.h:98
bool(* msg_open_new)(struct Mailbox *m, struct Message *msg, const struct Email *e)
Definition mxapi.h:239

◆ 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 2501 of file imap.c.

2502{
2503 bool success = false;
2504
2505 struct Buffer *tempfile = buf_pool_get();
2506 buf_mktemp(tempfile);
2507
2508 msg->fp = mutt_file_fopen(buf_string(tempfile), "w");
2509 if (!msg->fp)
2510 {
2511 mutt_perror("%s", buf_string(tempfile));
2512 goto cleanup;
2513 }
2514
2515 msg->path = buf_strdup(tempfile);
2516 success = true;
2517
2518cleanup:
2519 buf_pool_release(&tempfile);
2520 return success;
2521}
char * buf_strdup(const struct Buffer *buf)
Copy a Buffer's string.
Definition buffer.c:577
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:143
#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 550 of file message.c.

551{
552 int fd;
553 char path[PATH_MAX] = { 0 };
554 char suffix[PATH_MAX] = { 0 };
555 char subdir[16] = { 0 };
556
557 if (e)
558 {
559 struct Email tmp = *e;
560 tmp.deleted = false;
561 tmp.edata = NULL;
562 maildir_gen_flags(suffix, sizeof(suffix), &tmp);
563 }
564 else
565 {
566 *suffix = '\0';
567 }
568
569 if (e && (e->read || e->old))
570 mutt_str_copy(subdir, "cur", sizeof(subdir));
571 else
572 mutt_str_copy(subdir, "new", sizeof(subdir));
573
574 mode_t new_umask = maildir_umask(m);
575 mode_t old_umask = umask(new_umask);
576 mutt_debug(LL_DEBUG3, "umask set to %03o\n", new_umask);
577
578 for (int retries = 0; retries < 16; retries++)
579 {
580 snprintf(path, sizeof(path), "%s/tmp/%s.%lld.R%" PRIu64 ".%s%s",
581 mailbox_path(m), subdir, (long long) mutt_date_now(),
582 mutt_rand64(), NONULL(ShortHostname), suffix);
583
584 mutt_debug(LL_DEBUG2, "Trying %s\n", path);
585
586 fd = open(path, O_WRONLY | O_EXCL | O_CREAT, 0666);
587 if (fd == -1)
588 {
589 if (errno != EEXIST)
590 {
591 umask(old_umask);
592 mutt_debug(LL_DEBUG3, "umask set to %03o\n", old_umask);
593 mutt_perror("%s", path);
594 return false;
595 }
596 }
597 else
598 {
599 mutt_debug(LL_DEBUG2, "Success\n");
600 msg->path = mutt_str_dup(path);
601 break;
602 }
603 }
604
605 if (fd == -1)
606 {
607 umask(old_umask);
608 mutt_debug(LL_DEBUG1, "%s: failed after 16 retries\n", __func__);
609 return false;
610 }
611 umask(old_umask);
612 mutt_debug(LL_DEBUG3, "umask set to %03o\n", old_umask);
613
614 msg->fp = fdopen(fd, "w");
615 if (!msg->fp)
616 {
617 FREE(&msg->path);
618 close(fd);
619 unlink(path);
620 return false;
621 }
622
623 return true;
624}
static const char * mailbox_path(const struct Mailbox *m)
Get the Mailbox's path string.
Definition mailbox.h:216
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:459
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:587
#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 1518 of file mbox.c.

1519{
1521 if (!adata)
1522 return false;
1523
1524 msg->fp = adata->fp;
1525 return true;
1526}
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 1168 of file mh.c.

1169{
1170 return mh_mkstemp(m, &msg->fp, &msg->path);
1171}
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: