NeoMutt  2024-12-12-14-g7b49f7
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 743 of file compress.c.

744{
745 if (!m->compress_info)
746 return false;
747
748 struct CompressInfo *ci = m->compress_info;
749
750 const struct MxOps *ops = ci->child_ops;
751 if (!ops)
752 return false;
753
754 /* Delegate */
755 return ops->msg_open_new(m, msg, e);
756}
Private data for compress.
Definition: lib.h:60
const struct MxOps * child_ops
callbacks of de-compressed file
Definition: lib.h:65
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 2164 of file imap.c.

2165{
2166 bool success = false;
2167
2168 struct Buffer *tempfile = buf_pool_get();
2169 buf_mktemp(tempfile);
2170
2171 msg->fp = mutt_file_fopen(buf_string(tempfile), "w");
2172 if (!msg->fp)
2173 {
2174 mutt_perror("%s", buf_string(tempfile));
2175 goto cleanup;
2176 }
2177
2178 msg->path = buf_strdup(tempfile);
2179 success = true;
2180
2181cleanup:
2182 buf_pool_release(&tempfile);
2183 return success;
2184}
char * buf_strdup(const struct Buffer *buf)
Copy a Buffer's string.
Definition: buffer.c:571
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:137
#define mutt_perror(...)
Definition: logging2.h:93
struct Buffer * buf_pool_get(void)
Get a Buffer from the pool.
Definition: pool.c:82
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
Definition: pool.c:96
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[PATH_MAX] = { 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 new_umask = maildir_umask(m);
556 mode_t old_umask = umask(new_umask);
557 mutt_debug(LL_DEBUG3, "umask set to %03o\n", new_umask);
558
559 while (true)
560 {
561 snprintf(path, sizeof(path), "%s/tmp/%s.%lld.R%" PRIu64 ".%s%s",
562 mailbox_path(m), subdir, (long long) mutt_date_now(),
563 mutt_rand64(), NONULL(ShortHostname), suffix);
564
565 mutt_debug(LL_DEBUG2, "Trying %s\n", path);
566
567 fd = open(path, O_WRONLY | O_EXCL | O_CREAT, 0666);
568 if (fd == -1)
569 {
570 if (errno != EEXIST)
571 {
572 umask(old_umask);
573 mutt_debug(LL_DEBUG3, "umask set to %03o\n", old_umask);
574 mutt_perror("%s", path);
575 return false;
576 }
577 }
578 else
579 {
580 mutt_debug(LL_DEBUG2, "Success\n");
581 msg->path = mutt_str_dup(path);
582 break;
583 }
584 }
585 umask(old_umask);
586 mutt_debug(LL_DEBUG3, "umask set to %03o\n", old_umask);
587
588 msg->fp = fdopen(fd, "w");
589 if (!msg->fp)
590 {
591 FREE(&msg->path);
592 close(fd);
593 unlink(path);
594 return false;
595 }
596
597 return true;
598}
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:38
#define mutt_debug(LEVEL,...)
Definition: logging2.h:89
@ LL_DEBUG3
Log at debug level 3.
Definition: logging2.h:45
@ 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:55
time_t mutt_date_now(void)
Return the number of seconds since the Unix epoch.
Definition: date.c:456
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:581
#define PATH_MAX
Definition: mutt.h:42
uint64_t mutt_rand64(void)
Create a 64-bit random number.
Definition: random.c:123
#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 1489 of file mbox.c.

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