NeoMutt  2024-04-25-89-g194907
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: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:148
#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 532 of file message.c.

533{
534 int fd;
535 char path[PATH_MAX] = { 0 };
536 char suffix[16] = { 0 };
537 char subdir[16] = { 0 };
538
539 if (e)
540 {
541 struct Email tmp = *e;
542 tmp.deleted = false;
543 tmp.edata = NULL;
544 maildir_gen_flags(suffix, sizeof(suffix), &tmp);
545 }
546 else
547 {
548 *suffix = '\0';
549 }
550
551 if (e && (e->read || e->old))
552 mutt_str_copy(subdir, "cur", sizeof(subdir));
553 else
554 mutt_str_copy(subdir, "new", sizeof(subdir));
555
556 mode_t new_umask = maildir_umask(m);
557 mode_t old_umask = umask(new_umask);
558 mutt_debug(LL_DEBUG3, "umask set to %03o\n", new_umask);
559
560 while (true)
561 {
562 snprintf(path, sizeof(path), "%s/tmp/%s.%lld.R%" PRIu64 ".%s%s",
563 mailbox_path(m), subdir, (long long) mutt_date_now(),
564 mutt_rand64(), NONULL(ShortHostname), suffix);
565
566 mutt_debug(LL_DEBUG2, "Trying %s\n", path);
567
568 fd = open(path, O_WRONLY | O_EXCL | O_CREAT, 0666);
569 if (fd == -1)
570 {
571 if (errno != EEXIST)
572 {
573 umask(old_umask);
574 mutt_debug(LL_DEBUG3, "umask set to %03o\n", old_umask);
575 mutt_perror("%s", path);
576 return false;
577 }
578 }
579 else
580 {
581 mutt_debug(LL_DEBUG2, "Success\n");
582 msg->path = mutt_str_dup(path);
583 break;
584 }
585 }
586 umask(old_umask);
587 mutt_debug(LL_DEBUG3, "umask set to %03o\n", old_umask);
588
589 msg->fp = fdopen(fd, "w");
590 if (!msg->fp)
591 {
592 FREE(&msg->path);
593 close(fd);
594 unlink(path);
595 return false;
596 }
597
598 return true;
599}
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_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:73
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: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 1490 of file mbox.c.

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