NeoMutt  2023-05-17-56-ga67199
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
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 764 of file compress.c.

765{
766 if (!m->compress_info)
767 return false;
768
769 struct CompressInfo *ci = m->compress_info;
770
771 const struct MxOps *ops = ci->child_ops;
772 if (!ops)
773 return false;
774
775 /* Delegate */
776 return ops->msg_open_new(m, msg, e);
777}
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:253

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

2149{
2150 bool success = false;
2151
2152 struct Buffer *tmp = buf_pool_get();
2153 buf_mktemp(tmp);
2154
2155 msg->fp = mutt_file_fopen(buf_string(tmp), "w");
2156 if (!msg->fp)
2157 {
2158 mutt_perror(buf_string(tmp));
2159 goto cleanup;
2160 }
2161
2162 msg->path = buf_strdup(tmp);
2163 success = true;
2164
2165cleanup:
2166 buf_pool_release(&tmp);
2167 return success;
2168}
char * buf_strdup(const struct Buffer *buf)
Copy a Buffer's string.
Definition: buffer.c:536
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition: buffer.h:90
FILE * mutt_file_fopen(const char *path, const char *mode)
Call fopen() safely.
Definition: file.c:634
#define mutt_perror(...)
Definition: logging2.h:91
struct Buffer * buf_pool_get(void)
Get a Buffer from the pool.
Definition: pool.c:81
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
Definition: pool.c:94
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
#define buf_mktemp(buf)
Definition: tmp.h:37
+ 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 1488 of file maildir.c.

1489{
1490 int fd;
1491 char path[PATH_MAX] = { 0 };
1492 char suffix[16] = { 0 };
1493 char subdir[16] = { 0 };
1494
1495 if (e)
1496 {
1497 struct Email tmp = *e;
1498 tmp.deleted = false;
1499 tmp.edata = NULL;
1500 maildir_gen_flags(suffix, sizeof(suffix), &tmp);
1501 }
1502 else
1503 {
1504 *suffix = '\0';
1505 }
1506
1507 if (e && (e->read || e->old))
1508 mutt_str_copy(subdir, "cur", sizeof(subdir));
1509 else
1510 mutt_str_copy(subdir, "new", sizeof(subdir));
1511
1512 mode_t omask = umask(mh_umask(m));
1513 while (true)
1514 {
1515 snprintf(path, sizeof(path), "%s/tmp/%s.%lld.R%" PRIu64 ".%s%s",
1516 mailbox_path(m), subdir, (long long) mutt_date_now(),
1517 mutt_rand64(), NONULL(ShortHostname), suffix);
1518
1519 mutt_debug(LL_DEBUG2, "Trying %s\n", path);
1520
1521 fd = open(path, O_WRONLY | O_EXCL | O_CREAT, 0666);
1522 if (fd == -1)
1523 {
1524 if (errno != EEXIST)
1525 {
1526 umask(omask);
1528 return false;
1529 }
1530 }
1531 else
1532 {
1533 mutt_debug(LL_DEBUG2, "Success\n");
1534 msg->path = mutt_str_dup(path);
1535 break;
1536 }
1537 }
1538 umask(omask);
1539
1540 msg->fp = fdopen(fd, "w");
1541 if (!msg->fp)
1542 {
1543 FREE(&msg->path);
1544 close(fd);
1545 unlink(path);
1546 return false;
1547 }
1548
1549 return true;
1550}
char * ShortHostname
Short version of the hostname.
Definition: globals.c:40
#define mutt_debug(LEVEL,...)
Definition: logging2.h:87
@ LL_DEBUG2
Log at debug level 2.
Definition: logging2.h:44
static const char * mailbox_path(const struct Mailbox *m)
Get the Mailbox's path string.
Definition: mailbox.h:209
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:190
#define FREE(x)
Definition: memory.h:43
time_t mutt_date_now(void)
Return the number of seconds since the Unix epoch.
Definition: date.c:446
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:251
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:653
#define PATH_MAX
Definition: mutt.h:41
uint64_t mutt_rand64(void)
Create a 64-bit random number.
Definition: random.c:131
#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 1134 of file mh.c.

1135{
1136 return mh_mkstemp(m, &msg->fp, &msg->path);
1137}
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 1600 of file mbox.c.

1601{
1603 if (!adata)
1604 return false;
1605
1606 msg->fp = adata->fp;
1607 return true;
1608}
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: