NeoMutt  2023-11-03-107-g582dc1
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 773 of file compress.c.

774{
775 if (!m->compress_info)
776 return false;
777
778 struct CompressInfo *ci = m->compress_info;
779
780 const struct MxOps *ops = ci->child_ops;
781 if (!ops)
782 return false;
783
784 /* Delegate */
785 return ops->msg_open_new(m, msg, e);
786}
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:91
bool(* msg_open_new)(struct Mailbox *m, struct Message *msg, const struct Email *e)
Definition: mxapi.h:232

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

2151{
2152 bool success = false;
2153
2154 struct Buffer *tmp = buf_pool_get();
2155 buf_mktemp(tmp);
2156
2157 msg->fp = mutt_file_fopen(buf_string(tmp), "w");
2158 if (!msg->fp)
2159 {
2160 mutt_perror("%s", buf_string(tmp));
2161 goto cleanup;
2162 }
2163
2164 msg->path = buf_strdup(tmp);
2165 success = true;
2166
2167cleanup:
2168 buf_pool_release(&tmp);
2169 return success;
2170}
char * buf_strdup(const struct Buffer *buf)
Copy a Buffer's string.
Definition: buffer.c:542
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition: buffer.h:93
FILE * mutt_file_fopen(const char *path, const char *mode)
Call fopen() safely.
Definition: file.c:636
#define mutt_perror(...)
Definition: logging2.h:93
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: 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 1631 of file maildir.c.

1632{
1633 int fd;
1634 char path[PATH_MAX] = { 0 };
1635 char suffix[16] = { 0 };
1636 char subdir[16] = { 0 };
1637
1638 if (e)
1639 {
1640 struct Email tmp = *e;
1641 tmp.deleted = false;
1642 tmp.edata = NULL;
1643 maildir_gen_flags(suffix, sizeof(suffix), &tmp);
1644 }
1645 else
1646 {
1647 *suffix = '\0';
1648 }
1649
1650 if (e && (e->read || e->old))
1651 mutt_str_copy(subdir, "cur", sizeof(subdir));
1652 else
1653 mutt_str_copy(subdir, "new", sizeof(subdir));
1654
1655 mode_t omask = umask(maildir_umask(m));
1656 while (true)
1657 {
1658 snprintf(path, sizeof(path), "%s/tmp/%s.%lld.R%" PRIu64 ".%s%s",
1659 mailbox_path(m), subdir, (long long) mutt_date_now(),
1660 mutt_rand64(), NONULL(ShortHostname), suffix);
1661
1662 mutt_debug(LL_DEBUG2, "Trying %s\n", path);
1663
1664 fd = open(path, O_WRONLY | O_EXCL | O_CREAT, 0666);
1665 if (fd == -1)
1666 {
1667 if (errno != EEXIST)
1668 {
1669 umask(omask);
1670 mutt_perror("%s", path);
1671 return false;
1672 }
1673 }
1674 else
1675 {
1676 mutt_debug(LL_DEBUG2, "Success\n");
1677 msg->path = mutt_str_dup(path);
1678 break;
1679 }
1680 }
1681 umask(omask);
1682
1683 msg->fp = fdopen(fd, "w");
1684 if (!msg->fp)
1685 {
1686 FREE(&msg->path);
1687 close(fd);
1688 unlink(path);
1689 return false;
1690 }
1691
1692 return true;
1693}
char * ShortHostname
Short version of the hostname.
Definition: globals.c:40
#define mutt_debug(LEVEL,...)
Definition: logging2.h:89
@ 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:210
mode_t maildir_umask(struct Mailbox *m)
Create a umask from the mailbox directory.
Definition: maildir.c:85
void maildir_gen_flags(char *dest, size_t destlen, struct Email *e)
Generate the Maildir flags for an email.
Definition: maildir.c:240
#define FREE(x)
Definition: memory.h:45
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:121
#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:

◆ 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 1492 of file mbox.c.

1493{
1495 if (!adata)
1496 return false;
1497
1498 msg->fp = adata->fp;
1499 return true;
1500}
static struct MboxAccountData * mbox_adata_get(struct Mailbox *m)
Get the private data associated with a Mailbox.
Definition: mbox.c:122
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:

◆ 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 1163 of file mh.c.

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