NeoMutt  2022-04-29-247-gc6aae8
Teaching an old dog new tricks
DOXYGEN
msg_open()

Open an email message in a Mailbox. More...

+ Collaboration diagram for msg_open():

Functions

static bool comp_msg_open (struct Mailbox *m, struct Message *msg, int msgno)
 Open an email message in a Mailbox - Implements MxOps::msg_open() -. More...
 
bool imap_msg_open (struct Mailbox *m, struct Message *msg, int msgno)
 Open an email message in a Mailbox - Implements MxOps::msg_open() -. More...
 
static bool maildir_msg_open (struct Mailbox *m, struct Message *msg, int msgno)
 Open an email message in a Mailbox - Implements MxOps::msg_open() -. More...
 
static bool mh_msg_open (struct Mailbox *m, struct Message *msg, int msgno)
 Open an email message in a Mailbox - Implements MxOps::msg_open() -. More...
 
static bool mbox_msg_open (struct Mailbox *m, struct Message *msg, int msgno)
 Open an email message in a Mailbox - Implements MxOps::msg_open() -. More...
 
static bool nntp_msg_open (struct Mailbox *m, struct Message *msg, int msgno)
 Open an email message in a Mailbox - Implements MxOps::msg_open() -. More...
 
static bool nm_msg_open (struct Mailbox *m, struct Message *msg, int msgno)
 Open an email message in a Mailbox - Implements MxOps::msg_open() -. More...
 
static bool pop_msg_open (struct Mailbox *m, struct Message *msg, int msgno)
 Open an email message in a Mailbox - Implements MxOps::msg_open() -. More...
 

Detailed Description

Open an email message in a Mailbox.

Parameters
mMailbox
msgMessage to open
msgnoIndex of message to open
Return values
trueSuccess
falseError

Contract

Function Documentation

◆ comp_msg_open()

static bool comp_msg_open ( struct Mailbox m,
struct Message msg,
int  msgno 
)
static

Open an email message in a Mailbox - Implements MxOps::msg_open() -.

Definition at line 740 of file compress.c.

741{
742 if (!m->compress_info)
743 return false;
744
745 struct CompressInfo *ci = m->compress_info;
746
747 const struct MxOps *ops = ci->child_ops;
748 if (!ops)
749 return false;
750
751 /* Delegate */
752 return ops->msg_open(m, msg, msgno);
753}
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:112
bool(* msg_open)(struct Mailbox *m, struct Message *msg, int msgno)
Definition: mxapi.h:246

◆ imap_msg_open()

bool imap_msg_open ( struct Mailbox m,
struct Message msg,
int  msgno 
)

Open an email message in a Mailbox - Implements MxOps::msg_open() -.

Definition at line 1965 of file message.c.

1966{
1967 struct Envelope *newenv = NULL;
1968 char buf[1024] = { 0 };
1969 char *pc = NULL;
1970 unsigned int bytes;
1971 unsigned int uid;
1972 bool retried = false;
1973 bool read;
1974 int rc;
1975
1976 /* Sam's weird courier server returns an OK response even when FETCH
1977 * fails. Thanks Sam. */
1978 bool fetched = false;
1979
1981
1982 if (!adata || (adata->mailbox != m))
1983 return false;
1984
1985 struct Email *e = m->emails[msgno];
1986 if (!e)
1987 return false;
1988
1989 msg->fp = msg_cache_get(m, e);
1990 if (msg->fp)
1991 {
1992 if (imap_edata_get(e)->parsed)
1993 return true;
1994 goto parsemsg;
1995 }
1996
1997 /* This function is called in a few places after endwin()
1998 * e.g. mutt_pipe_message(). */
1999 bool output_progress = !isendwin() && m->verbose;
2000 if (output_progress)
2001 mutt_message(_("Fetching message..."));
2002
2003 msg->fp = msg_cache_put(m, e);
2004 if (!msg->fp)
2005 {
2006 struct Buffer *path = mutt_buffer_pool_get();
2007 mutt_buffer_mktemp(path);
2008 msg->fp = mutt_file_fopen(mutt_buffer_string(path), "w+");
2009 unlink(mutt_buffer_string(path));
2011
2012 if (!msg->fp)
2013 return false;
2014 }
2015
2016 /* mark this header as currently inactive so the command handler won't
2017 * also try to update it. HACK until all this code can be moved into the
2018 * command handler */
2019 e->active = false;
2020
2021 const bool c_imap_peek = cs_subset_bool(NeoMutt->sub, "imap_peek");
2022 snprintf(buf, sizeof(buf), "UID FETCH %u %s", imap_edata_get(e)->uid,
2023 ((adata->capabilities & IMAP_CAP_IMAP4REV1) ?
2024 (c_imap_peek ? "BODY.PEEK[]" : "BODY[]") :
2025 "RFC822"));
2026
2027 imap_cmd_start(adata, buf);
2028 do
2029 {
2030 rc = imap_cmd_step(adata);
2031 if (rc != IMAP_RES_CONTINUE)
2032 break;
2033
2034 pc = adata->buf;
2035 pc = imap_next_word(pc);
2036 pc = imap_next_word(pc);
2037
2038 if (mutt_istr_startswith(pc, "FETCH"))
2039 {
2040 while (*pc)
2041 {
2042 pc = imap_next_word(pc);
2043 if (pc[0] == '(')
2044 pc++;
2045 if (mutt_istr_startswith(pc, "UID"))
2046 {
2047 pc = imap_next_word(pc);
2048 if (!mutt_str_atoui(pc, &uid))
2049 goto bail;
2050 if (uid != imap_edata_get(e)->uid)
2051 {
2052 mutt_error(_("The message index is incorrect. Try reopening the mailbox."));
2053 }
2054 }
2055 else if (mutt_istr_startswith(pc, "RFC822") || mutt_istr_startswith(pc, "BODY[]"))
2056 {
2057 pc = imap_next_word(pc);
2058 if (imap_get_literal_count(pc, &bytes) < 0)
2059 {
2060 imap_error("imap_msg_open()", buf);
2061 goto bail;
2062 }
2063 // struct Progress *progress = output_progress ?
2064 // progress_new(_("Fetching message..."),
2065 // MUTT_PROGRESS_NET, bytes) :
2066 // NULL;
2067 const int res = imap_read_literal(msg->fp, adata, bytes, NULL);
2068 // progress_free(&progress);
2069 if (res < 0)
2070 {
2071 goto bail;
2072 }
2073 /* pick up trailing line */
2074 rc = imap_cmd_step(adata);
2075 if (rc != IMAP_RES_CONTINUE)
2076 goto bail;
2077 pc = adata->buf;
2078
2079 fetched = true;
2080 }
2081 /* UW-IMAP will provide a FLAGS update here if the FETCH causes a
2082 * change (eg from \Unseen to \Seen).
2083 * Uncommitted changes in neomutt take precedence. If we decide to
2084 * incrementally update flags later, this won't stop us syncing */
2085 else if (!e->changed && mutt_istr_startswith(pc, "FLAGS"))
2086 {
2087 pc = imap_set_flags(m, e, pc, NULL);
2088 if (!pc)
2089 goto bail;
2090 }
2091 }
2092 }
2093 } while (rc == IMAP_RES_CONTINUE);
2094
2095 /* see comment before command start. */
2096 e->active = true;
2097
2098 fflush(msg->fp);
2099 if (ferror(msg->fp))
2100 goto bail;
2101
2102 if (rc != IMAP_RES_OK)
2103 goto bail;
2104
2105 if (!fetched || !imap_code(adata->buf))
2106 goto bail;
2107
2108 msg_cache_commit(m, e);
2109
2110parsemsg:
2111 /* Update the header information. Previously, we only downloaded a
2112 * portion of the headers, those required for the main display. */
2113 rewind(msg->fp);
2114 /* It may be that the Status header indicates a message is read, but the
2115 * IMAP server doesn't know the message has been \Seen. So we capture
2116 * the server's notion of 'read' and if it differs from the message info
2117 * picked up in mutt_rfc822_read_header, we mark the message (and context
2118 * changed). Another possibility: ignore Status on IMAP? */
2119 read = e->read;
2120 newenv = mutt_rfc822_read_header(msg->fp, e, false, false);
2121 mutt_env_merge(e->env, &newenv);
2122
2123 /* see above. We want the new status in e->read, so we unset it manually
2124 * and let mutt_set_flag set it correctly, updating context. */
2125 if (read != e->read)
2126 {
2127 e->read = read;
2128 mutt_set_flag(m, e, MUTT_NEW, read);
2129 }
2130
2131 e->lines = 0;
2132 fgets(buf, sizeof(buf), msg->fp);
2133 while (!feof(msg->fp))
2134 {
2135 e->lines++;
2136 fgets(buf, sizeof(buf), msg->fp);
2137 }
2138
2139 e->body->length = ftell(msg->fp) - e->body->offset;
2140
2142 rewind(msg->fp);
2143 imap_edata_get(e)->parsed = true;
2144
2145 /* retry message parse if cached message is empty */
2146 if (!retried && ((e->lines == 0) || (e->body->length == 0)))
2147 {
2148 imap_cache_del(m, e);
2149 retried = true;
2150 goto parsemsg;
2151 }
2152
2153 return true;
2154
2155bail:
2156 e->active = true;
2157 mutt_file_fclose(&msg->fp);
2158 imap_cache_del(m, e);
2159 return false;
2160}
const char * mutt_str_atoui(const char *str, unsigned int *dst)
Convert ASCII string to an unsigned integer.
Definition: atoi.c:202
static const char * mutt_buffer_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition: buffer.h:77
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:73
void mutt_env_merge(struct Envelope *base, struct Envelope **extra)
Merge the headers of two Envelopes.
Definition: envelope.c:166
FILE * mutt_file_fopen(const char *path, const char *mode)
Call fopen() safely.
Definition: file.c:618
int mutt_file_fclose(FILE **fp)
Close a FILE handle (and NULL the pointer)
Definition: file.c:152
#define mutt_error(...)
Definition: logging.h:87
#define mutt_message(...)
Definition: logging.h:86
struct ImapAccountData * imap_adata_get(struct Mailbox *m)
Get the Account data for this mailbox.
Definition: adata.c:89
int imap_cmd_start(struct ImapAccountData *adata, const char *cmdstr)
Given an IMAP command, send it to the server.
Definition: command.c:1062
int imap_cmd_step(struct ImapAccountData *adata)
Reads server responses from an IMAP command.
Definition: command.c:1076
bool imap_code(const char *s)
Was the command successful.
Definition: command.c:1199
struct ImapEmailData * imap_edata_get(struct Email *e)
Get the private data for this Email.
Definition: edata.c:65
static FILE * msg_cache_put(struct Mailbox *m, struct Email *e)
Put an email into the message cache.
Definition: message.c:127
char * imap_set_flags(struct Mailbox *m, struct Email *e, char *s, bool *server_changes)
Fill the message header according to the server flags.
Definition: message.c:1908
static FILE * msg_cache_get(struct Mailbox *m, struct Email *e)
Get the message cache entry for an email.
Definition: message.c:106
int imap_cache_del(struct Mailbox *m, struct Email *e)
Delete an email from the body cache.
Definition: message.c:1857
static int msg_cache_commit(struct Mailbox *m, struct Email *e)
Add to the message cache.
Definition: message.c:148
int imap_get_literal_count(const char *buf, unsigned int *bytes)
Write number of bytes in an IMAP literal into bytes.
Definition: util.c:745
#define IMAP_RES_OK
<tag> OK ...
Definition: private.h:56
#define IMAP_CAP_IMAP4REV1
Server supports IMAP4rev1.
Definition: private.h:124
void imap_error(const char *where, const char *msg)
Show an error and abort.
Definition: util.c:663
#define IMAP_RES_CONTINUE
* ...
Definition: private.h:57
char * imap_next_word(char *s)
Find where the next IMAP word begins.
Definition: util.c:789
int imap_read_literal(FILE *fp, struct ImapAccountData *adata, unsigned long bytes, struct Progress *progress)
Read bytes bytes from server into file.
Definition: imap.c:598
#define _(a)
Definition: message.h:28
size_t mutt_istr_startswith(const char *str, const char *prefix)
Check whether a string starts with a prefix, ignoring case.
Definition: string.c:239
@ MUTT_NEW
New messages.
Definition: mutt.h:90
void mutt_clear_error(void)
Clear the message line (bottom line of screen)
Definition: mutt_logging.c:74
#define mutt_buffer_mktemp(buf)
Definition: muttlib.h:74
struct Envelope * mutt_rfc822_read_header(FILE *fp, struct Email *e, bool user_hdrs, bool weed)
Parses an RFC822 header.
Definition: parse.c:1157
void mutt_buffer_pool_release(struct Buffer **pbuf)
Free a Buffer from the pool.
Definition: pool.c:112
struct Buffer * mutt_buffer_pool_get(void)
Get a Buffer from the pool.
Definition: pool.c:101
#define mutt_set_flag(m, e, flag, bf)
Definition: protos.h:63
void * adata
Private data (for Mailbox backends)
Definition: account.h:43
LOFF_T offset
offset where the actual data begins
Definition: body.h:52
LOFF_T length
length (in bytes) of attachment
Definition: body.h:53
String manipulation buffer.
Definition: buffer.h:34
The envelope/body of an email.
Definition: email.h:37
bool read
Email is read.
Definition: email.h:48
struct Envelope * env
Envelope information.
Definition: email.h:66
int lines
How many lines in the body of this message?
Definition: email.h:60
struct Body * body
List of MIME parts.
Definition: email.h:67
bool active
Message is not to be removed.
Definition: email.h:74
bool changed
Email has been edited.
Definition: email.h:75
int msgno
Number displayed to the user.
Definition: email.h:111
The header of an Email.
Definition: envelope.h:57
IMAP-specific Account data -.
Definition: adata.h:40
ImapCapFlags capabilities
Capability flags.
Definition: adata.h:55
char * buf
Definition: adata.h:59
bool parsed
Definition: edata.h:42
struct Email ** emails
Array of Emails.
Definition: mailbox.h:96
bool verbose
Display status messages?
Definition: mailbox.h:114
FILE * fp
pointer to the message data
Definition: mxapi.h:44
Container for Accounts, Notifications.
Definition: neomutt.h:37
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:39
+ Here is the call graph for this function:

◆ maildir_msg_open()

static bool maildir_msg_open ( struct Mailbox m,
struct Message msg,
int  msgno 
)
static

Open an email message in a Mailbox - Implements MxOps::msg_open() -.

Definition at line 1454 of file maildir.c.

1455{
1456 struct Email *e = m->emails[msgno];
1457 if (!e)
1458 return false;
1459
1460 char path[PATH_MAX] = { 0 };
1461
1462 snprintf(path, sizeof(path), "%s/%s", mailbox_path(m), e->path);
1463
1464 msg->fp = fopen(path, "r");
1465 if (!msg->fp && (errno == ENOENT))
1466 msg->fp = maildir_open_find_message(mailbox_path(m), e->path, NULL);
1467
1468 if (!msg->fp)
1469 {
1471 mutt_debug(LL_DEBUG1, "fopen: %s: %s (errno %d)\n", path, strerror(errno), errno);
1472 return false;
1473 }
1474
1475 return true;
1476}
#define mutt_debug(LEVEL,...)
Definition: logging.h:84
#define mutt_perror(...)
Definition: logging.h:88
@ LL_DEBUG1
Log at debug level 1.
Definition: logging.h:40
static const char * mailbox_path(const struct Mailbox *m)
Get the Mailbox's path string.
Definition: mailbox.h:210
FILE * maildir_open_find_message(const char *folder, const char *msg, char **newname)
Find a new.
Definition: maildir.c:994
#define PATH_MAX
Definition: mutt.h:40
char * path
Path of Email (for local Mailboxes)
Definition: email.h:68
+ Here is the call graph for this function:

◆ mh_msg_open()

static bool mh_msg_open ( struct Mailbox m,
struct Message msg,
int  msgno 
)
static

Open an email message in a Mailbox - Implements MxOps::msg_open() -.

Definition at line 1119 of file mh.c.

1120{
1121 if (!m || !m->emails || (msgno >= m->msg_count))
1122 return false;
1123
1124 struct Email *e = m->emails[msgno];
1125 if (!e)
1126 return false;
1127
1128 char path[PATH_MAX] = { 0 };
1129
1130 snprintf(path, sizeof(path), "%s/%s", mailbox_path(m), e->path);
1131
1132 msg->fp = fopen(path, "r");
1133 if (!msg->fp)
1134 {
1136 mutt_debug(LL_DEBUG1, "fopen: %s: %s (errno %d)\n", path, strerror(errno), errno);
1137 return false;
1138 }
1139
1140 return true;
1141}
int msg_count
Total number of messages.
Definition: mailbox.h:88
+ Here is the call graph for this function:

◆ mbox_msg_open()

static bool mbox_msg_open ( struct Mailbox m,
struct Message msg,
int  msgno 
)
static

Open an email message in a Mailbox - Implements MxOps::msg_open() -.

Definition at line 1574 of file mbox.c.

1575{
1577 if (!adata)
1578 return false;
1579
1580 msg->fp = mutt_file_fopen(mailbox_path(m), "r");
1581 if (!msg->fp)
1582 return false;
1583
1584 return true;
1585}
static struct MboxAccountData * mbox_adata_get(struct Mailbox *m)
Get the private data associated with a Mailbox.
Definition: mbox.c:119
Mbox-specific Account data -.
Definition: lib.h:49
+ Here is the call graph for this function:

◆ nntp_msg_open()

static bool nntp_msg_open ( struct Mailbox m,
struct Message msg,
int  msgno 
)
static

Open an email message in a Mailbox - Implements MxOps::msg_open() -.

Definition at line 2560 of file nntp.c.

2561{
2562 struct NntpMboxData *mdata = m->mdata;
2563 struct Email *e = m->emails[msgno];
2564 if (!e)
2565 return false;
2566
2567 char article[16] = { 0 };
2568
2569 /* try to get article from cache */
2570 struct NntpAcache *acache = &mdata->acache[e->index % NNTP_ACACHE_LEN];
2571 if (acache->path)
2572 {
2573 if (acache->index == e->index)
2574 {
2575 msg->fp = mutt_file_fopen(acache->path, "r");
2576 if (msg->fp)
2577 return true;
2578 }
2579 /* clear previous entry */
2580 else
2581 {
2582 unlink(acache->path);
2583 FREE(&acache->path);
2584 }
2585 }
2586 snprintf(article, sizeof(article), ANUM, nntp_edata_get(e)->article_num);
2587 msg->fp = mutt_bcache_get(mdata->bcache, article);
2588 if (msg->fp)
2589 {
2590 if (nntp_edata_get(e)->parsed)
2591 return true;
2592 }
2593 else
2594 {
2595 char buf[PATH_MAX] = { 0 };
2596 /* don't try to fetch article from removed newsgroup */
2597 if (mdata->deleted)
2598 return false;
2599
2600 /* create new cache file */
2601 const char *fetch_msg = _("Fetching message...");
2602 mutt_message(fetch_msg);
2603 msg->fp = mutt_bcache_put(mdata->bcache, article);
2604 if (!msg->fp)
2605 {
2606 mutt_mktemp(buf, sizeof(buf));
2607 acache->path = mutt_str_dup(buf);
2608 acache->index = e->index;
2609 msg->fp = mutt_file_fopen(acache->path, "w+");
2610 if (!msg->fp)
2611 {
2612 mutt_perror(acache->path);
2613 unlink(acache->path);
2614 FREE(&acache->path);
2615 return false;
2616 }
2617 }
2618
2619 /* fetch message to cache file */
2620 snprintf(buf, sizeof(buf), "ARTICLE %s\r\n",
2621 nntp_edata_get(e)->article_num ? article : e->env->message_id);
2622 const int rc = nntp_fetch_lines(mdata, buf, sizeof(buf), fetch_msg,
2623 fetch_tempfile, msg->fp);
2624 if (rc)
2625 {
2626 mutt_file_fclose(&msg->fp);
2627 if (acache->path)
2628 {
2629 unlink(acache->path);
2630 FREE(&acache->path);
2631 }
2632 if (rc > 0)
2633 {
2634 if (mutt_str_startswith(buf, nntp_edata_get(e)->article_num ? "423" : "430"))
2635 {
2636 mutt_error(_("Article %s not found on the server"),
2637 nntp_edata_get(e)->article_num ? article : e->env->message_id);
2638 }
2639 else
2640 mutt_error("ARTICLE: %s", buf);
2641 }
2642 return false;
2643 }
2644
2645 if (!acache->path)
2646 mutt_bcache_commit(mdata->bcache, article);
2647 }
2648
2649 /* replace envelope with new one
2650 * hash elements must be updated because pointers will be changed */
2651 if (m->id_hash && e->env->message_id)
2653 if (m->subj_hash && e->env->real_subj)
2655
2656 mutt_env_free(&e->env);
2657 e->env = mutt_rfc822_read_header(msg->fp, e, false, false);
2658
2659 if (m->id_hash && e->env->message_id)
2661 if (m->subj_hash && e->env->real_subj)
2663
2664 /* fix content length */
2665 if (!mutt_file_seek(msg->fp, 0, SEEK_END))
2666 {
2667 return false;
2668 }
2669 e->body->length = ftell(msg->fp) - e->body->offset;
2670
2671 /* this is called in neomutt before the open which fetches the message,
2672 * which is probably wrong, but we just call it again here to handle
2673 * the problem instead of fixing it */
2674 nntp_edata_get(e)->parsed = true;
2675 mutt_parse_mime_message(e, msg->fp);
2676
2677 /* these would normally be updated in mview_update(), but the
2678 * full headers aren't parsed with overview, so the information wasn't
2679 * available then */
2680 if (WithCrypto)
2681 e->security = crypt_query(e->body);
2682
2683 rewind(msg->fp);
2685 return true;
2686}
void mutt_parse_mime_message(struct Email *e, FILE *fp)
Parse a MIME email.
Definition: attachments.c:591
int mutt_bcache_commit(struct BodyCache *bcache, const char *id)
Move a temporary file into the Body Cache.
Definition: bcache.c:248
FILE * mutt_bcache_get(struct BodyCache *bcache, const char *id)
Open a file in the Body Cache.
Definition: bcache.c:180
FILE * mutt_bcache_put(struct BodyCache *bcache, const char *id)
Create a file in the Body Cache.
Definition: bcache.c:208
SecurityFlags crypt_query(struct Body *b)
Check out the type of encryption used.
Definition: crypt.c:675
void mutt_env_free(struct Envelope **ptr)
Free an Envelope.
Definition: envelope.c:97
bool mutt_file_seek(FILE *fp, LOFF_T offset, int whence)
Wrapper for fseeko with error handling.
Definition: file.c:690
struct HashElem * mutt_hash_insert(struct HashTable *table, const char *strkey, void *data)
Add a new element to the Hash Table (with string keys)
Definition: hash.c:335
void mutt_hash_delete(struct HashTable *table, const char *strkey, const void *data)
Remove an element from a Hash Table.
Definition: hash.c:427
#define FREE(x)
Definition: memory.h:43
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:250
size_t mutt_str_startswith(const char *str, const char *prefix)
Check whether a string starts with a prefix.
Definition: string.c:227
#define mutt_mktemp(buf, buflen)
Definition: muttlib.h:71
#define WithCrypto
Definition: lib.h:116
struct NntpEmailData * nntp_edata_get(struct Email *e)
Get the private data for this Email.
Definition: edata.c:58
#define NNTP_ACACHE_LEN
Definition: lib.h:82
#define ANUM
Definition: lib.h:61
static int nntp_fetch_lines(struct NntpMboxData *mdata, char *query, size_t qlen, const char *msg, int(*func)(char *, void *), void *data)
Read lines, calling a callback function for each.
Definition: nntp.c:763
static int fetch_tempfile(char *line, void *data)
Write line to temporary file.
Definition: nntp.c:952
SecurityFlags security
bit 0-10: flags, bit 11,12: application, bit 13: traditional pgp See: ncrypt/lib.h pgplib....
Definition: email.h:41
int index
The absolute (unsorted) message number.
Definition: email.h:110
char * message_id
Message ID.
Definition: envelope.h:73
char * real_subj
Offset of the real subject.
Definition: envelope.h:71
void * mdata
Driver specific data.
Definition: mailbox.h:132
struct HashTable * subj_hash
Hash Table by subject.
Definition: mailbox.h:124
struct HashTable * id_hash
Hash Table by msg id.
Definition: mailbox.h:123
NNTP article cache.
Definition: lib.h:67
char * path
Cache path.
Definition: lib.h:69
unsigned int index
Index number.
Definition: lib.h:68
bool parsed
Email has been parse.
Definition: edata.h:37
NNTP-specific Mailbox data -.
Definition: mdata.h:33
bool deleted
Definition: mdata.h:44
struct BodyCache * bcache
Definition: mdata.h:49
struct NntpAcache acache[NNTP_ACACHE_LEN]
Definition: mdata.h:48
+ Here is the call graph for this function:

◆ nm_msg_open()

static bool nm_msg_open ( struct Mailbox m,
struct Message msg,
int  msgno 
)
static

Open an email message in a Mailbox - Implements MxOps::msg_open() -.

Definition at line 2338 of file notmuch.c.

2339{
2340 struct Email *e = m->emails[msgno];
2341 if (!e)
2342 return false;
2343
2344 char path[PATH_MAX] = { 0 };
2345 char *folder = nm_email_get_folder(e);
2346
2347 snprintf(path, sizeof(path), "%s/%s", folder, e->path);
2348
2349 msg->fp = fopen(path, "r");
2350 if (!msg->fp && (errno == ENOENT) && ((m->type == MUTT_MAILDIR) || (m->type == MUTT_NOTMUCH)))
2351 {
2352 msg->fp = maildir_open_find_message(folder, e->path, NULL);
2353 }
2354
2355 return msg->fp != NULL;
2356}
@ MUTT_NOTMUCH
'Notmuch' (virtual) Mailbox type
Definition: mailbox.h:51
@ MUTT_MAILDIR
'Maildir' Mailbox type
Definition: mailbox.h:48
FILE * maildir_open_find_message(const char *folder, const char *msg, char **newname)
Find a new.
Definition: maildir.c:994
char * nm_email_get_folder(struct Email *e)
Get the folder for a Email.
Definition: notmuch.c:1450
enum MailboxType type
Mailbox type.
Definition: mailbox.h:102
+ Here is the call graph for this function:

◆ pop_msg_open()

static bool pop_msg_open ( struct Mailbox m,
struct Message msg,
int  msgno 
)
static

Open an email message in a Mailbox - Implements MxOps::msg_open() -.

Definition at line 976 of file pop.c.

977{
978 char buf[1024] = { 0 };
980 struct Email *e = m->emails[msgno];
981 struct PopEmailData *edata = pop_edata_get(e);
982 bool bcache = true;
983 bool success = false;
984 struct Buffer *path = NULL;
985
986 /* see if we already have the message in body cache */
987 msg->fp = mutt_bcache_get(adata->bcache, cache_id(edata->uid));
988 if (msg->fp)
989 return true;
990
991 /* see if we already have the message in our cache in
992 * case $message_cachedir is unset */
993 struct PopCache *cache = &adata->cache[e->index % POP_CACHE_LEN];
994
995 if (cache->path)
996 {
997 if (cache->index == e->index)
998 {
999 /* yes, so just return a pointer to the message */
1000 msg->fp = fopen(cache->path, "r");
1001 if (msg->fp)
1002 return true;
1003
1004 mutt_perror(cache->path);
1005 return false;
1006 }
1007 else
1008 {
1009 /* clear the previous entry */
1010 unlink(cache->path);
1011 FREE(&cache->path);
1012 }
1013 }
1014
1016
1017 while (true)
1018 {
1019 if (pop_reconnect(m) < 0)
1020 goto cleanup;
1021
1022 /* verify that massage index is correct */
1023 if (edata->refno < 0)
1024 {
1025 mutt_error(_("The message index is incorrect. Try reopening the mailbox."));
1026 goto cleanup;
1027 }
1028
1029 /* see if we can put in body cache; use our cache as fallback */
1030 msg->fp = mutt_bcache_put(adata->bcache, cache_id(edata->uid));
1031 if (!msg->fp)
1032 {
1033 /* no */
1034 bcache = false;
1037 if (!msg->fp)
1038 {
1040 goto cleanup;
1041 }
1042 }
1043
1044 snprintf(buf, sizeof(buf), "RETR %d\r\n", edata->refno);
1045
1046 struct Progress *progress = progress_new(_("Fetching message..."), MUTT_PROGRESS_NET,
1047 e->body->length + e->body->offset - 1);
1048 const int rc = pop_fetch_data(adata, buf, progress, fetch_message, msg->fp);
1049 progress_free(&progress);
1050
1051 if (rc == 0)
1052 break;
1053
1054 mutt_file_fclose(&msg->fp);
1055
1056 /* if RETR failed (e.g. connection closed), be sure to remove either
1057 * the file in bcache or from POP's own cache since the next iteration
1058 * of the loop will re-attempt to put() the message */
1059 if (!bcache)
1060 unlink(mutt_buffer_string(path));
1061
1062 if (rc == -2)
1063 {
1064 mutt_error("%s", adata->err_msg);
1065 goto cleanup;
1066 }
1067
1068 if (rc == -3)
1069 {
1070 mutt_error(_("Can't write message to temporary file"));
1071 goto cleanup;
1072 }
1073 }
1074
1075 /* Update the header information. Previously, we only downloaded a
1076 * portion of the headers, those required for the main display. */
1077 if (bcache)
1078 mutt_bcache_commit(adata->bcache, cache_id(edata->uid));
1079 else
1080 {
1081 cache->index = e->index;
1082 cache->path = mutt_buffer_strdup(path);
1083 }
1084 rewind(msg->fp);
1085
1086 /* Detach the private data */
1087 e->edata = NULL;
1088
1089 /* we replace envelope, key in subj_hash has to be updated as well */
1090 if (m->subj_hash && e->env->real_subj)
1093 mutt_env_free(&e->env);
1094 e->env = mutt_rfc822_read_header(msg->fp, e, false, false);
1095 if (m->subj_hash && e->env->real_subj)
1097 mutt_label_hash_add(m, e);
1098
1099 /* Reattach the private data */
1100 e->edata = edata;
1102
1103 e->lines = 0;
1104 fgets(buf, sizeof(buf), msg->fp);
1105 while (!feof(msg->fp))
1106 {
1107 m->emails[msgno]->lines++;
1108 fgets(buf, sizeof(buf), msg->fp);
1109 }
1110
1111 e->body->length = ftello(msg->fp) - e->body->offset;
1112
1113 /* This needs to be done in case this is a multipart message */
1114 if (!WithCrypto)
1115 e->security = crypt_query(e->body);
1116
1118 rewind(msg->fp);
1119
1120 success = true;
1121
1122cleanup:
1124 return success;
1125}
char * mutt_buffer_strdup(const struct Buffer *buf)
Copy a Buffer's string.
Definition: buffer.c:447
static int fetch_message(const char *line, void *data)
Write line to file - Implements pop_fetch_t -.
Definition: pop.c:98
void mutt_label_hash_remove(struct Mailbox *m, struct Email *e)
Remove a message's labels from the Hash Table.
Definition: mutt_header.c:396
void mutt_label_hash_add(struct Mailbox *m, struct Email *e)
Add a message's labels to the Hash Table.
Definition: mutt_header.c:383
struct PopAccountData * pop_adata_get(struct Mailbox *m)
Get the Account data for this mailbox.
Definition: adata.c:64
void pop_edata_free(void **ptr)
Free the private Email data - Implements Email::edata_free()
Definition: edata.c:41
struct PopEmailData * pop_edata_get(struct Email *e)
Get the private data for this Email.
Definition: edata.c:65
int pop_fetch_data(struct PopAccountData *adata, const char *query, struct Progress *progress, pop_fetch_t callback, void *data)
Read Headers with callback function.
Definition: lib.c:502
int pop_reconnect(struct Mailbox *m)
Reconnect and verify indexes if connection was lost.
Definition: lib.c:599
#define POP_CACHE_LEN
Definition: private.h:39
static const char * cache_id(const char *id)
Make a message-cache-compatible id.
Definition: pop.c:83
@ MUTT_PROGRESS_NET
Progress tracks bytes, according to $net_inc
Definition: lib.h:51
void progress_free(struct Progress **ptr)
Free a Progress Bar.
Definition: progress.c:86
struct Progress * progress_new(const char *msg, enum ProgressType type, size_t size)
Create a new Progress Bar.
Definition: progress.c:118
void * edata
Driver-specific data.
Definition: email.h:72
void(* edata_free)(void **ptr)
Free the private data attached to the Email.
Definition: email.h:87
POP-specific Account data -.
Definition: adata.h:37
char err_msg[POP_CMD_RESPONSE]
Definition: adata.h:56
struct PopCache cache[POP_CACHE_LEN]
Definition: adata.h:57
struct BodyCache * bcache
body cache
Definition: adata.h:55
POP-specific email cache.
Definition: private.h:69
unsigned int index
Definition: private.h:70
char * path
Definition: private.h:71
POP-specific Email data -.
Definition: edata.h:32
int refno
Message number on server.
Definition: edata.h:34
const char * uid
UID of email.
Definition: edata.h:33
+ Here is the call graph for this function: