NeoMutt  2021-02-05-666-ge300cd
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() -Open a new (temporary) message in a maildir folder. 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() -Open a new (temporary) message in an MH folder. 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 752 of file compress.c.

753 {
754  if (!m->compress_info)
755  return false;
756 
757  struct CompressInfo *ci = m->compress_info;
758 
759  const struct MxOps *ops = ci->child_ops;
760  if (!ops)
761  return false;
762 
763  /* Delegate */
764  return ops->msg_open_new(m, msg, e);
765 }
Private data for compress.
Definition: lib.h:46
bool(* msg_open_new)(struct Mailbox *m, struct Message *msg, const struct Email *e)
Definition: mxapi.h:255
void * compress_info
Compressed mbox module private data.
Definition: mailbox.h:124
const struct MxOps * child_ops
callbacks of de-compressed file
Definition: lib.h:52
Definition: mxapi.h:103

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

2226 {
2227  bool success = false;
2228 
2229  struct Buffer *tmp = mutt_buffer_pool_get();
2230  mutt_buffer_mktemp(tmp);
2231 
2232  msg->fp = mutt_file_fopen(mutt_buffer_string(tmp), "w");
2233  if (!msg->fp)
2234  {
2236  goto cleanup;
2237  }
2238 
2239  msg->path = mutt_buffer_strdup(tmp);
2240  success = true;
2241 
2242 cleanup:
2244  return success;
2245 }
#define mutt_buffer_mktemp(buf)
Definition: muttlib.h:74
struct Buffer * mutt_buffer_pool_get(void)
Get a Buffer from the pool.
Definition: pool.c:101
char * mutt_buffer_strdup(const struct Buffer *buf)
Copy a Buffer's string.
Definition: buffer.c:432
void mutt_buffer_pool_release(struct Buffer **pbuf)
Free a Buffer from the pool.
Definition: pool.c:112
String manipulation buffer.
Definition: buffer.h:33
#define mutt_perror(...)
Definition: logging.h:89
static const char * mutt_buffer_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition: buffer.h:77
FILE * fp
pointer to the message data
Definition: mxapi.h:43
FILE * mutt_file_fopen(const char *path, const char *mode)
Call fopen() safely.
Definition: file.c:589
char * path
path to temp file
Definition: mxapi.h:44
+ 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];
1492  char suffix[16];
1493  char subdir[16];
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  *suffix = '\0';
1504 
1505  if (e && (e->read || e->old))
1506  mutt_str_copy(subdir, "cur", sizeof(subdir));
1507  else
1508  mutt_str_copy(subdir, "new", sizeof(subdir));
1509 
1510  mode_t omask = umask(mh_umask(m));
1511  while (true)
1512  {
1513  snprintf(path, sizeof(path), "%s/tmp/%s.%lld.R%" PRIu64 ".%s%s",
1514  mailbox_path(m), subdir, (long long) mutt_date_epoch(),
1515  mutt_rand64(), NONULL(ShortHostname), suffix);
1516 
1517  mutt_debug(LL_DEBUG2, "Trying %s\n", path);
1518 
1519  fd = open(path, O_WRONLY | O_EXCL | O_CREAT, 0666);
1520  if (fd == -1)
1521  {
1522  if (errno != EEXIST)
1523  {
1524  umask(omask);
1525  mutt_perror(path);
1526  return false;
1527  }
1528  }
1529  else
1530  {
1531  mutt_debug(LL_DEBUG2, "Success\n");
1532  msg->path = mutt_str_dup(path);
1533  break;
1534  }
1535  }
1536  umask(omask);
1537 
1538  msg->fp = fdopen(fd, "w");
1539  if (!msg->fp)
1540  {
1541  FREE(&msg->path);
1542  close(fd);
1543  unlink(path);
1544  return false;
1545  }
1546 
1547  return true;
1548 }
time_t mutt_date_epoch(void)
Return the number of seconds since the Unix epoch.
Definition: date.c:427
static const char * mailbox_path(const struct Mailbox *m)
Get the Mailbox's path string.
Definition: mailbox.h:215
#define NONULL(x)
Definition: string2.h:37
The envelope/body of an email.
Definition: email.h:37
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:370
#define mutt_perror(...)
Definition: logging.h:89
bool read
Email is read.
Definition: email.h:51
Log at debug level 2.
Definition: logging.h:41
bool old
Email is seen, but unread.
Definition: email.h:50
uint64_t mutt_rand64(void)
Create a 64-bit random number.
Definition: random.c:130
#define PATH_MAX
Definition: mutt.h:40
void maildir_gen_flags(char *dest, size_t destlen, struct Email *e)
Generate the Maildir flags for an email.
Definition: maildir.c:186
WHERE char * ShortHostname
Short version of the hostname.
Definition: mutt_globals.h:46
mode_t mh_umask(struct Mailbox *m)
Create a umask from the mailbox directory.
Definition: shared.c:52
#define mutt_debug(LEVEL,...)
Definition: logging.h:85
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:749
bool deleted
Email is deleted.
Definition: email.h:45
void * edata
Driver-specific data.
Definition: email.h:111
FILE * fp
pointer to the message data
Definition: mxapi.h:43
#define FREE(x)
Definition: memory.h:40
char * path
path to temp file
Definition: mxapi.h:44
+ 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 1141 of file mh.c.

1142 {
1143  return mh_mkstemp(m, &msg->fp, &msg->path);
1144 }
bool mh_mkstemp(struct Mailbox *m, FILE **fp, char **tgt)
Create a temporary file.
Definition: mh.c:77
FILE * fp
pointer to the message data
Definition: mxapi.h:43
char * path
path to temp file
Definition: mxapi.h:44
+ 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 1580 of file mbox.c.

1581 {
1582  struct MboxAccountData *adata = mbox_adata_get(m);
1583  if (!adata)
1584  return false;
1585 
1586  msg->fp = adata->fp;
1587  return true;
1588 }
Mbox-specific Account data -.
Definition: lib.h:48
void * adata
Private data (for Mailbox backends)
Definition: account.h:43
static struct MboxAccountData * mbox_adata_get(struct Mailbox *m)
Get the private data associated with a Mailbox.
Definition: mbox.c:100
FILE * fp
pointer to the message data
Definition: mxapi.h:43
FILE * fp
Mailbox file.
Definition: lib.h:50
+ Here is the call graph for this function: