NeoMutt  2024-04-16-36-g75b6fb
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 771 of file compress.c.

772{
773 if (!m->compress_info)
774 return false;
775
776 struct CompressInfo *ci = m->compress_info;
777
778 const struct MxOps *ops = ci->child_ops;
779 if (!ops)
780 return false;
781
782 /* Delegate */
783 return ops->msg_open_new(m, msg, e);
784}
Private data for compress.
Definition: lib.h:58
const struct MxOps * child_ops
callbacks of de-compressed file
Definition: lib.h:63
void * compress_info
Compressed mbox module private data.
Definition: mailbox.h:121
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 2165 of file imap.c.

2166{
2167 bool success = false;
2168
2169 struct Buffer *tmp = buf_pool_get();
2170 buf_mktemp(tmp);
2171
2172 msg->fp = mutt_file_fopen(buf_string(tmp), "w");
2173 if (!msg->fp)
2174 {
2175 mutt_perror("%s", buf_string(tmp));
2176 goto cleanup;
2177 }
2178
2179 msg->path = buf_strdup(tmp);
2180 success = true;
2181
2182cleanup:
2183 buf_pool_release(&tmp);
2184 return success;
2185}
char * buf_strdup(const struct Buffer *buf)
Copy a Buffer's string.
Definition: buffer.c:570
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:146
#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: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 531 of file message.c.

532{
533 int fd;
534 char path[PATH_MAX] = { 0 };
535 char suffix[16] = { 0 };
536 char subdir[16] = { 0 };
537
538 if (e)
539 {
540 struct Email tmp = *e;
541 tmp.deleted = false;
542 tmp.edata = NULL;
543 maildir_gen_flags(suffix, sizeof(suffix), &tmp);
544 }
545 else
546 {
547 *suffix = '\0';
548 }
549
550 if (e && (e->read || e->old))
551 mutt_str_copy(subdir, "cur", sizeof(subdir));
552 else
553 mutt_str_copy(subdir, "new", sizeof(subdir));
554
555 mode_t omask = umask(maildir_umask(m));
556 while (true)
557 {
558 snprintf(path, sizeof(path), "%s/tmp/%s.%lld.R%" PRIu64 ".%s%s",
559 mailbox_path(m), subdir, (long long) mutt_date_now(),
560 mutt_rand64(), NONULL(ShortHostname), suffix);
561
562 mutt_debug(LL_DEBUG2, "Trying %s\n", path);
563
564 fd = open(path, O_WRONLY | O_EXCL | O_CREAT, 0666);
565 if (fd == -1)
566 {
567 if (errno != EEXIST)
568 {
569 umask(omask);
570 mutt_perror("%s", path);
571 return false;
572 }
573 }
574 else
575 {
576 mutt_debug(LL_DEBUG2, "Success\n");
577 msg->path = mutt_str_dup(path);
578 break;
579 }
580 }
581 umask(omask);
582
583 msg->fp = fdopen(fd, "w");
584 if (!msg->fp)
585 {
586 FREE(&msg->path);
587 close(fd);
588 unlink(path);
589 return false;
590 }
591
592 return true;
593}
static const char * mailbox_path(const struct Mailbox *m)
Get the Mailbox's path string.
Definition: mailbox.h:223
char * ShortHostname
Short version of the hostname.
Definition: globals.c:39
#define mutt_debug(LEVEL,...)
Definition: logging2.h:89
@ LL_DEBUG2
Log at debug level 2.
Definition: logging2.h:44
void maildir_gen_flags(char *dest, size_t destlen, struct Email *e)
Generate the Maildir flags for an email.
Definition: message.c:72
mode_t maildir_umask(struct Mailbox *m)
Create a umask from the mailbox directory.
Definition: shared.c:47
#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:455
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:253
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:575
#define PATH_MAX
Definition: mutt.h:42
uint64_t mutt_rand64(void)
Create a 64-bit random number.
Definition: random.c:122
#define NONULL(x)
Definition: string2.h:37
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 1488 of file mbox.c.

1489{
1491 if (!adata)
1492 return false;
1493
1494 msg->fp = adata->fp;
1495 return true;
1496}
static struct MboxAccountData * mbox_adata_get(struct Mailbox *m)
Get the private data associated with a Mailbox.
Definition: mbox.c:123
void * adata
Private data (for Mailbox backends)
Definition: account.h:42
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 1164 of file mh.c.

1165{
1166 return mh_mkstemp(m, &msg->fp, &msg->path);
1167}
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: