NeoMutt  2022-04-29-215-gc12b98
Teaching an old dog new tricks
DOXYGEN
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() -. More...
 
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() -. More...
 
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() -. More...
 
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() -. More...
 
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() -. More...
 

Detailed Description

Open a new message in a Mailbox.

Parameters
mMailbox
msgMessage to open
eEmail
Return values
trueSuccess
falseFailure

Contract

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 758 of file compress.c.

759{
760 if (!m->compress_info)
761 return false;
762
763 struct CompressInfo *ci = m->compress_info;
764
765 const struct MxOps *ops = ci->child_ops;
766 if (!ops)
767 return false;
768
769 /* Delegate */
770 return ops->msg_open_new(m, msg, e);
771}
Private data for compress.
Definition: lib.h:47
const struct MxOps * child_ops
callbacks of de-compressed file
Definition: lib.h:52
void * compress_info
Compressed mbox module private data.
Definition: mailbox.h:120
Definition: mxapi.h:112
bool(* msg_open_new)(struct Mailbox *m, struct Message *msg, const struct Email *e)
Definition: mxapi.h:263

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

2224{
2225 bool success = false;
2226
2227 struct Buffer *tmp = mutt_buffer_pool_get();
2228 mutt_buffer_mktemp(tmp);
2229
2230 msg->fp = mutt_file_fopen(mutt_buffer_string(tmp), "w");
2231 if (!msg->fp)
2232 {
2234 goto cleanup;
2235 }
2236
2237 msg->path = mutt_buffer_strdup(tmp);
2238 success = true;
2239
2240cleanup:
2242 return success;
2243}
char * mutt_buffer_strdup(const struct Buffer *buf)
Copy a Buffer's string.
Definition: buffer.c:447
static const char * mutt_buffer_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition: buffer.h:77
FILE * mutt_file_fopen(const char *path, const char *mode)
Call fopen() safely.
Definition: file.c:618
#define mutt_perror(...)
Definition: logging.h:88
#define mutt_buffer_mktemp(buf)
Definition: muttlib.h:74
void mutt_buffer_pool_release(struct Buffer **pbuf)
Free a Buffer from the pool.
Definition: pool.c:112
struct Buffer * mutt_buffer_pool_get(void)
Get a Buffer from the pool.
Definition: pool.c:101
String manipulation buffer.
Definition: buffer.h:34
FILE * fp
pointer to the message data
Definition: mxapi.h:44
char * path
path to temp file
Definition: mxapi.h:45
+ 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 1487 of file maildir.c.

1488{
1489 int fd;
1490 char path[PATH_MAX] = { 0 };
1491 char suffix[16] = { 0 };
1492 char subdir[16] = { 0 };
1493
1494 if (e)
1495 {
1496 struct Email tmp = *e;
1497 tmp.deleted = false;
1498 tmp.edata = NULL;
1499 maildir_gen_flags(suffix, sizeof(suffix), &tmp);
1500 }
1501 else
1502 *suffix = '\0';
1503
1504 if (e && (e->read || e->old))
1505 mutt_str_copy(subdir, "cur", sizeof(subdir));
1506 else
1507 mutt_str_copy(subdir, "new", sizeof(subdir));
1508
1509 mode_t omask = umask(mh_umask(m));
1510 while (true)
1511 {
1512 snprintf(path, sizeof(path), "%s/tmp/%s.%lld.R%" PRIu64 ".%s%s",
1513 mailbox_path(m), subdir, (long long) mutt_date_epoch(),
1514 mutt_rand64(), NONULL(ShortHostname), suffix);
1515
1516 mutt_debug(LL_DEBUG2, "Trying %s\n", path);
1517
1518 fd = open(path, O_WRONLY | O_EXCL | O_CREAT, 0666);
1519 if (fd == -1)
1520 {
1521 if (errno != EEXIST)
1522 {
1523 umask(omask);
1525 return false;
1526 }
1527 }
1528 else
1529 {
1530 mutt_debug(LL_DEBUG2, "Success\n");
1531 msg->path = mutt_str_dup(path);
1532 break;
1533 }
1534 }
1535 umask(omask);
1536
1537 msg->fp = fdopen(fd, "w");
1538 if (!msg->fp)
1539 {
1540 FREE(&msg->path);
1541 close(fd);
1542 unlink(path);
1543 return false;
1544 }
1545
1546 return true;
1547}
time_t mutt_date_epoch(void)
Return the number of seconds since the Unix epoch.
Definition: date.c:428
#define mutt_debug(LEVEL,...)
Definition: logging.h:84
@ LL_DEBUG2
Log at debug level 2.
Definition: logging.h:41
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
void maildir_gen_flags(char *dest, size_t destlen, struct Email *e)
Generate the Maildir flags for an email.
Definition: maildir.c:186
#define FREE(x)
Definition: memory.h:43
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:250
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:652
#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
#define NONULL(x)
Definition: string2.h:37
The envelope/body of an email.
Definition: email.h:37
bool read
Email is read.
Definition: email.h:48
void * edata
Driver-specific data.
Definition: email.h:72
bool old
Email is seen, but unread.
Definition: email.h:47
char * path
Path of Email (for local Mailboxes)
Definition: email.h:68
bool deleted
Email is deleted.
Definition: email.h:76
+ 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 1148 of file mh.c.

1149{
1150 return mh_mkstemp(m, &msg->fp, &msg->path);
1151}
bool mh_mkstemp(struct Mailbox *m, FILE **fp, char **tgt)
Create a temporary file.
Definition: mh.c: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 1590 of file mbox.c.

1591{
1593 if (!adata)
1594 return false;
1595
1596 msg->fp = adata->fp;
1597 return true;
1598}
static struct MboxAccountData * mbox_adata_get(struct Mailbox *m)
Get the private data associated with a Mailbox.
Definition: mbox.c:119
void * adata
Private data (for Mailbox backends)
Definition: account.h:43
Mbox-specific Account data -.
Definition: lib.h:49
+ Here is the call graph for this function: