NeoMutt  2025-12-11-694-ga89709
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
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, struct Email *e)
 Open an email message in a Mailbox - Implements MxOps::msg_open() -.
 
bool imap_msg_open (struct Mailbox *m, struct Message *msg, struct Email *e)
 Open an email message in a Mailbox - Implements MxOps::msg_open() -.
 
bool maildir_msg_open (struct Mailbox *m, struct Message *msg, struct Email *e)
 Open an email message in a Mailbox - Implements MxOps::msg_open() -.
 
static bool mbox_msg_open (struct Mailbox *m, struct Message *msg, struct Email *e)
 Open an email message in a Mailbox - Implements MxOps::msg_open() -.
 
static bool mh_msg_open (struct Mailbox *m, struct Message *msg, struct Email *e)
 Open an email message in a Mailbox - Implements MxOps::msg_open() -.
 
static bool nntp_msg_open (struct Mailbox *m, struct Message *msg, struct Email *e)
 Open an email message in a Mailbox - Implements MxOps::msg_open() -.
 
static bool nm_msg_open (struct Mailbox *m, struct Message *msg, struct Email *e)
 Open an email message in a Mailbox - Implements MxOps::msg_open() -.
 
static bool pop_msg_open (struct Mailbox *m, struct Message *msg, struct Email *e)
 Open an email message in a Mailbox - Implements MxOps::msg_open() -.
 

Detailed Description

Open an email message in a Mailbox.

Parameters
mMailbox
msgMessage to open
eEmail to open
Return values
trueSuccess
falseError
Precondition
m is not NULL
msg is not NULL
e is not NULL

Function Documentation

◆ comp_msg_open()

static bool comp_msg_open ( struct Mailbox * m,
struct Message * msg,
struct Email * e )
static

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

Definition at line 724 of file compress.c.

725{
726 if (!m->compress_info)
727 return false;
728
729 struct CompressInfo *ci = m->compress_info;
730
731 const struct MxOps *ops = ci->child_ops;
732 if (!ops)
733 return false;
734
735 /* Delegate */
736 return ops->msg_open(m, msg, e);
737}
Private data for compress.
Definition lib.h:61
const struct MxOps * child_ops
callbacks of de-compressed file
Definition lib.h:66
void * compress_info
Compressed mbox module private data.
Definition mailbox.h:120
Definition mxapi.h:87
bool(* msg_open)(struct Mailbox *m, struct Message *msg, struct Email *e)
Definition mxapi.h:212

◆ imap_msg_open()

bool imap_msg_open ( struct Mailbox * m,
struct Message * msg,
struct Email * e )

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

Definition at line 2005 of file message.c.

2006{
2007 struct Envelope *newenv = NULL;
2008 char buf[1024] = { 0 };
2009 char *pc = NULL;
2010 unsigned int bytes;
2011 unsigned int uid;
2012 bool retried = false;
2013 bool read;
2014 int rc;
2015
2016 /* Sam's weird courier server returns an OK response even when FETCH
2017 * fails. Thanks Sam. */
2018 bool fetched = false;
2019
2021
2022 if (!adata || (adata->mailbox != m))
2023 return false;
2024
2025 msg->fp = msg_cache_get(m, e);
2026 if (msg->fp)
2027 {
2028 if (imap_edata_get(e)->parsed)
2029 return true;
2030 goto parsemsg;
2031 }
2032
2033 /* This function is called in a few places after endwin()
2034 * e.g. mutt_pipe_message(). */
2035 bool output_progress = !isendwin() && m->verbose;
2036 if (output_progress)
2037 mutt_message(_("Fetching message..."));
2038
2039 msg->fp = msg_cache_put(m, e);
2040 if (!msg->fp)
2041 {
2042 struct Buffer *tempfile = buf_pool_get();
2043 buf_mktemp(tempfile);
2044 msg->fp = mutt_file_fopen(buf_string(tempfile), "w+");
2045 unlink(buf_string(tempfile));
2046 buf_pool_release(&tempfile);
2047
2048 if (!msg->fp)
2049 return false;
2050 }
2051
2052 /* mark this header as currently inactive so the command handler won't
2053 * also try to update it. HACK until all this code can be moved into the
2054 * command handler */
2055 e->active = false;
2056
2057 const bool c_imap_peek = cs_subset_bool(NeoMutt->sub, "imap_peek");
2058 snprintf(buf, sizeof(buf), "UID FETCH %u %s", imap_edata_get(e)->uid,
2059 ((adata->capabilities & IMAP_CAP_IMAP4REV1) ?
2060 (c_imap_peek ? "BODY.PEEK[]" : "BODY[]") :
2061 "RFC822"));
2062
2063 imap_cmd_start(adata, buf);
2064 do
2065 {
2066 rc = imap_cmd_step(adata);
2067 if (rc != IMAP_RES_CONTINUE)
2068 break;
2069
2070 pc = adata->buf;
2071 pc = imap_next_word(pc);
2072 pc = imap_next_word(pc);
2073
2074 if (mutt_istr_startswith(pc, "FETCH"))
2075 {
2076 while (*pc)
2077 {
2078 pc = imap_next_word(pc);
2079 if (pc[0] == '(')
2080 pc++;
2081 if (mutt_istr_startswith(pc, "UID"))
2082 {
2083 pc = imap_next_word(pc);
2084 if (!mutt_str_atoui(pc, &uid))
2085 goto bail;
2086 if (uid != imap_edata_get(e)->uid)
2087 {
2088 mutt_error(_("The message index is incorrect. Try reopening the mailbox."));
2089 }
2090 }
2091 else if (mutt_istr_startswith(pc, "RFC822") || mutt_istr_startswith(pc, "BODY[]"))
2092 {
2093 pc = imap_next_word(pc);
2094 if (imap_get_literal_count(pc, &bytes) < 0)
2095 {
2096 imap_error("imap_msg_open()", buf);
2097 goto bail;
2098 }
2099
2100 const int res = imap_read_literal(msg->fp, adata, bytes, NULL);
2101 if (res < 0)
2102 {
2103 goto bail;
2104 }
2105 /* pick up trailing line */
2106 rc = imap_cmd_step(adata);
2107 if (rc != IMAP_RES_CONTINUE)
2108 goto bail;
2109 pc = adata->buf;
2110
2111 fetched = true;
2112 }
2113 else if (!e->changed && mutt_istr_startswith(pc, "FLAGS"))
2114 {
2115 /* UW-IMAP will provide a FLAGS update here if the FETCH causes a
2116 * change (eg from \Unseen to \Seen).
2117 * Uncommitted changes in neomutt take precedence. If we decide to
2118 * incrementally update flags later, this won't stop us syncing */
2119 pc = imap_set_flags(m, e, pc, NULL);
2120 if (!pc)
2121 goto bail;
2122 }
2123 }
2124 }
2125 } while (rc == IMAP_RES_CONTINUE);
2126
2127 /* see comment before command start. */
2128 e->active = true;
2129
2130 fflush(msg->fp);
2131 if (ferror(msg->fp))
2132 goto bail;
2133
2134 if (rc != IMAP_RES_OK)
2135 goto bail;
2136
2137 if (!fetched || !imap_code(adata->buf))
2138 goto bail;
2139
2140 if (msg_cache_commit(m, e) < 0)
2141 mutt_debug(LL_DEBUG1, "failed to add message to cache\n");
2142
2143parsemsg:
2144 /* Update the header information. Previously, we only downloaded a
2145 * portion of the headers, those required for the main display. */
2146 rewind(msg->fp);
2147 /* It may be that the Status header indicates a message is read, but the
2148 * IMAP server doesn't know the message has been \Seen. So we capture
2149 * the server's notion of 'read' and if it differs from the message info
2150 * picked up in mutt_rfc822_read_header, we mark the message (and context
2151 * changed). Another possibility: ignore Status on IMAP? */
2152 read = e->read;
2153 newenv = mutt_rfc822_read_header(msg->fp, e, false, false);
2154 mutt_env_merge(e->env, &newenv);
2155
2156 /* see above. We want the new status in e->read, so we unset it manually
2157 * and let mutt_set_flag set it correctly, updating context. */
2158 if (read != e->read)
2159 {
2160 e->read = read;
2161 mutt_set_flag(m, e, MUTT_NEW, read, true);
2162 }
2163
2164 e->lines = 0;
2165 while (fgets(buf, sizeof(buf), msg->fp) && !feof(msg->fp))
2166 {
2167 e->lines++;
2168 }
2169
2170 e->body->length = ftell(msg->fp) - e->body->offset;
2171
2173 rewind(msg->fp);
2174 imap_edata_get(e)->parsed = true;
2175
2176 /* retry message parse if cached message is empty */
2177 if (!retried && ((e->lines == 0) || (e->body->length == 0)))
2178 {
2179 imap_cache_del(m, e);
2180 retried = true;
2181 goto parsemsg;
2182 }
2183
2184 return true;
2185
2186bail:
2187 e->active = true;
2188 mutt_file_fclose(&msg->fp);
2189 imap_cache_del(m, e);
2190 return false;
2191}
const char * mutt_str_atoui(const char *str, unsigned int *dst)
Convert ASCII string to an unsigned integer.
Definition atoi.c:217
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition buffer.h:96
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition helpers.c:47
struct Envelope * mutt_rfc822_read_header(FILE *fp, struct Email *e, bool user_hdrs, bool weed)
Parses an RFC822 header.
Definition parse.c:1210
void mutt_env_merge(struct Envelope *base, struct Envelope **extra)
Merge the headers of two Envelopes.
Definition envelope.c:192
#define mutt_file_fclose(FP)
Definition file.h:139
#define mutt_file_fopen(PATH, MODE)
Definition file.h:138
void mutt_set_flag(struct Mailbox *m, struct Email *e, enum MessageType flag, bool bf, bool upd_mbox)
Set a flag on an email.
Definition flags.c:54
#define mutt_error(...)
Definition logging2.h:94
#define mutt_message(...)
Definition logging2.h:93
#define mutt_debug(LEVEL,...)
Definition logging2.h:91
struct ImapAccountData * imap_adata_get(struct Mailbox *m)
Get the Account data for this mailbox.
Definition adata.c:158
int imap_cmd_start(struct ImapAccountData *adata, const char *cmdstr)
Given an IMAP command, send it to the server.
Definition command.c:1211
int imap_cmd_step(struct ImapAccountData *adata)
Reads server responses from an IMAP command.
Definition command.c:1225
bool imap_code(const char *s)
Was the command successful.
Definition command.c:1367
struct ImapEmailData * imap_edata_get(struct Email *e)
Get the private data for this Email.
Definition edata.c:66
static FILE * msg_cache_put(struct Mailbox *m, struct Email *e)
Put an email into the message cache.
Definition message.c:129
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:1948
static FILE * msg_cache_get(struct Mailbox *m, struct Email *e)
Get the message cache entry for an email.
Definition message.c:108
int imap_cache_del(struct Mailbox *m, struct Email *e)
Delete an email from the body cache.
Definition message.c:1897
static int msg_cache_commit(struct Mailbox *m, struct Email *e)
Add to the message cache.
Definition message.c:150
#define IMAP_RES_OK
<tag> OK ...
Definition private.h:54
#define IMAP_CAP_IMAP4REV1
Server supports IMAP4rev1.
Definition private.h:122
int imap_get_literal_count(char *buf, unsigned int *bytes)
Write number of bytes in an IMAP literal into bytes.
Definition util.c:782
void imap_error(const char *where, const char *msg)
Show an error and abort.
Definition util.c:662
#define IMAP_RES_CONTINUE
* ...
Definition private.h:55
char * imap_next_word(char *s)
Find where the next IMAP word begins.
Definition util.c:826
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:704
@ LL_DEBUG1
Log at debug level 1.
Definition logging2.h:45
#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:246
@ MUTT_NEW
New messages.
Definition mutt.h:89
void mutt_clear_error(void)
Clear the message line (bottom line of screen)
struct Buffer * buf_pool_get(void)
Get a Buffer from the pool.
Definition pool.c:91
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
Definition pool.c:111
void * adata
Private data (for Mailbox backends)
Definition account.h:42
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:36
bool read
Email is read.
Definition email.h:50
struct Envelope * env
Envelope information.
Definition email.h:68
int lines
How many lines in the body of this message?
Definition email.h:62
struct Body * body
List of MIME parts.
Definition email.h:69
bool active
Message is not to be removed.
Definition email.h:76
bool changed
Email has been edited.
Definition email.h:77
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
Command buffer.
Definition adata.h:60
bool parsed
Email has been parsed.
Definition edata.h:43
bool verbose
Display status messages?
Definition mailbox.h:116
FILE * fp
pointer to the message data
Definition message.h:35
Container for Accounts, Notifications.
Definition neomutt.h:41
struct ConfigSubset * sub
Inherited config items.
Definition neomutt.h:49
#define buf_mktemp(buf)
Definition tmp.h:33
+ Here is the call graph for this function:

◆ maildir_msg_open()

bool maildir_msg_open ( struct Mailbox * m,
struct Message * msg,
struct Email * e )

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

Definition at line 522 of file message.c.

523{
524 char path[PATH_MAX] = { 0 };
525
526 snprintf(path, sizeof(path), "%s/%s", mailbox_path(m), e->path);
527
528 msg->fp = mutt_file_fopen(path, "r");
529 if (!msg->fp && (errno == ENOENT))
530 msg->fp = maildir_open_find_message(mailbox_path(m), e->path, NULL);
531
532 if (!msg->fp)
533 {
534 mutt_perror("%s", path);
535 return false;
536 }
537
538 return true;
539}
static const char * mailbox_path(const struct Mailbox *m)
Get the Mailbox's path string.
Definition mailbox.h:213
#define mutt_perror(...)
Definition logging2.h:95
FILE * maildir_open_find_message(const char *folder, const char *msg, char **newname)
Find a message by name.
Definition message.c:168
#define PATH_MAX
Definition mutt.h:49
char * path
Path of Email (for local Mailboxes)
Definition email.h:70
+ Here is the call graph for this function:

◆ mbox_msg_open()

static bool mbox_msg_open ( struct Mailbox * m,
struct Message * msg,
struct Email * e )
static

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

Definition at line 1477 of file mbox.c.

1478{
1480 if (!adata)
1481 return false;
1482
1483 msg->fp = mutt_file_fopen(mailbox_path(m), "r");
1484 if (!msg->fp)
1485 return false;
1486
1487 return true;
1488}
static struct MboxAccountData * mbox_adata_get(struct Mailbox *m)
Get the private data associated with a Mailbox.
Definition mbox.c:121
Mbox-specific Account data -.
Definition lib.h:50
+ Here is the call graph for this function:

◆ mh_msg_open()

static bool mh_msg_open ( struct Mailbox * m,
struct Message * msg,
struct Email * e )
static

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

Definition at line 1145 of file mh.c.

1146{
1147 char path[PATH_MAX] = { 0 };
1148
1149 snprintf(path, sizeof(path), "%s/%s", mailbox_path(m), e->path);
1150
1151 msg->fp = mutt_file_fopen(path, "r");
1152 if (!msg->fp)
1153 {
1154 mutt_perror("%s", path);
1155 return false;
1156 }
1157
1158 return true;
1159}
+ Here is the call graph for this function:

◆ nntp_msg_open()

static bool nntp_msg_open ( struct Mailbox * m,
struct Message * msg,
struct Email * e )
static

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

Definition at line 2647 of file nntp.c.

2648{
2649 struct NntpMboxData *mdata = m->mdata;
2650 char article[16] = { 0 };
2651
2652 /* try to get article from cache */
2653 struct NntpAcache *acache = &mdata->acache[e->index % NNTP_ACACHE_LEN];
2654 if (acache->path)
2655 {
2656 if (acache->index == e->index)
2657 {
2658 msg->fp = mutt_file_fopen(acache->path, "r");
2659 if (msg->fp)
2660 return true;
2661 }
2662 else
2663 {
2664 /* clear previous entry */
2665 unlink(acache->path);
2666 FREE(&acache->path);
2667 }
2668 }
2669 snprintf(article, sizeof(article), ANUM_FMT, nntp_edata_get(e)->article_num);
2670 msg->fp = mutt_bcache_get(mdata->bcache, article);
2671 if (msg->fp)
2672 {
2673 if (nntp_edata_get(e)->parsed)
2674 return true;
2675 }
2676 else
2677 {
2678 /* don't try to fetch article from removed newsgroup */
2679 if (mdata->deleted)
2680 return false;
2681
2682 /* create new cache file */
2683 const char *fetch_msg = _("Fetching message...");
2684 mutt_message("%s", fetch_msg);
2685 msg->fp = mutt_bcache_put(mdata->bcache, article);
2686 if (!msg->fp)
2687 {
2688 struct Buffer *tempfile = buf_pool_get();
2689 buf_mktemp(tempfile);
2690 acache->path = buf_strdup(tempfile);
2691 buf_pool_release(&tempfile);
2692 acache->index = e->index;
2693 msg->fp = mutt_file_fopen(acache->path, "w+");
2694 if (!msg->fp)
2695 {
2696 mutt_perror("%s", acache->path);
2697 unlink(acache->path);
2698 FREE(&acache->path);
2699 return false;
2700 }
2701 }
2702
2703 /* fetch message to cache file */
2704 char buf[2048] = { 0 };
2705 snprintf(buf, sizeof(buf), "ARTICLE %s\r\n",
2706 nntp_edata_get(e)->article_num ? article : e->env->message_id);
2707 const int rc = nntp_fetch_lines(mdata, buf, sizeof(buf), NULL, fetch_tempfile, msg->fp);
2708 if (rc)
2709 {
2710 mutt_file_fclose(&msg->fp);
2711 if (acache->path)
2712 {
2713 unlink(acache->path);
2714 FREE(&acache->path);
2715 }
2716 if (rc > 0)
2717 {
2718 if (mutt_str_startswith(buf, nntp_edata_get(e)->article_num ? "423" : "430"))
2719 {
2720 mutt_error(_("Article %s not found on the server"),
2721 nntp_edata_get(e)->article_num ? article : e->env->message_id);
2722 }
2723 else
2724 {
2725 mutt_error("ARTICLE: %s", buf);
2726 }
2727 }
2728 return false;
2729 }
2730
2731 if (!acache->path)
2732 mutt_bcache_commit(mdata->bcache, article);
2733 }
2734
2735 /* replace envelope with new one
2736 * hash elements must be updated because pointers will be changed */
2737 if (m->id_hash && e->env->message_id)
2739 if (m->subj_hash && e->env->real_subj)
2741
2742 mutt_env_free(&e->env);
2743 e->env = mutt_rfc822_read_header(msg->fp, e, false, false);
2744
2745 if (m->id_hash && e->env->message_id)
2747 if (m->subj_hash && e->env->real_subj)
2749
2750 /* fix content length */
2751 if (!mutt_file_seek(msg->fp, 0, SEEK_END))
2752 {
2753 return false;
2754 }
2755 e->body->length = ftell(msg->fp) - e->body->offset;
2756
2757 /* this is called in neomutt before the open which fetches the message,
2758 * which is probably wrong, but we just call it again here to handle
2759 * the problem instead of fixing it */
2760 nntp_edata_get(e)->parsed = true;
2761 mutt_parse_mime_message(e, msg->fp);
2762
2763 /* these would normally be updated in mview_update(), but the
2764 * full headers aren't parsed with overview, so the information wasn't
2765 * available then */
2766 if (WithCrypto)
2767 e->security = crypt_query(e->body);
2768
2769 rewind(msg->fp);
2771 return true;
2772}
void mutt_parse_mime_message(struct Email *e, FILE *fp)
Parse a MIME email.
Definition commands.c:627
int mutt_bcache_commit(struct BodyCache *bcache, const char *id)
Move a temporary file into the Body Cache.
Definition bcache.c:254
FILE * mutt_bcache_get(struct BodyCache *bcache, const char *id)
Open a file in the Body Cache.
Definition bcache.c:185
FILE * mutt_bcache_put(struct BodyCache *bcache, const char *id)
Create a file in the Body Cache.
Definition bcache.c:212
char * buf_strdup(const struct Buffer *buf)
Copy a Buffer's string.
Definition buffer.c:571
SecurityFlags crypt_query(struct Body *b)
Check out the type of encryption used.
Definition crypt.c:687
void mutt_env_free(struct Envelope **ptr)
Free an Envelope.
Definition envelope.c:125
bool mutt_file_seek(FILE *fp, LOFF_T offset, int whence)
Wrapper for fseeko with error handling.
Definition file.c:648
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:337
void mutt_hash_delete(struct HashTable *table, const char *strkey, const void *data)
Remove an element from a Hash Table.
Definition hash.c:429
#define FREE(x)
Free memory and set the pointer to NULL.
Definition memory.h:68
size_t mutt_str_startswith(const char *str, const char *prefix)
Check whether a string starts with a prefix.
Definition string.c:234
#define WithCrypto
Definition lib.h:124
struct NntpEmailData * nntp_edata_get(struct Email *e)
Get the private data for this Email.
Definition edata.c:60
#define NNTP_ACACHE_LEN
Definition lib.h:85
#define ANUM_FMT
Definition lib.h:64
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:815
static int fetch_tempfile(char *line, void *data)
Write line to temporary file.
Definition nntp.c:1010
SecurityFlags security
bit 0-10: flags, bit 11,12: application, bit 13: traditional pgp See: ncrypt/lib.h pgplib....
Definition email.h:43
int index
The absolute (unsorted) message number.
Definition email.h:110
char * message_id
Message ID.
Definition envelope.h:73
char *const real_subj
Offset of the real subject.
Definition envelope.h:71
void * mdata
Driver specific data.
Definition mailbox.h:131
struct HashTable * subj_hash
Hash Table: "Subject" -> Email.
Definition mailbox.h:123
struct HashTable * id_hash
Hash Table: "Message-ID" -> Email.
Definition mailbox.h:122
NNTP article cache.
Definition lib.h:70
char * path
Cache path.
Definition lib.h:72
unsigned int index
Index number.
Definition lib.h:71
bool parsed
Email has been parse.
Definition edata.h:37
NNTP-specific Mailbox data -.
Definition mdata.h:34
bool deleted
Newsgroup is deleted.
Definition mdata.h:45
struct BodyCache * bcache
Body cache.
Definition mdata.h:50
struct NntpAcache acache[NNTP_ACACHE_LEN]
Article cache.
Definition mdata.h:49
+ Here is the call graph for this function:

◆ nm_msg_open()

static bool nm_msg_open ( struct Mailbox * m,
struct Message * msg,
struct Email * e )
static

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

Definition at line 2422 of file notmuch.c.

2423{
2424 char path[PATH_MAX] = { 0 };
2425 char *folder = nm_email_get_folder(e);
2426 if (!folder)
2427 return false;
2428
2429 snprintf(path, sizeof(path), "%s/%s", folder, e->path);
2430
2431 msg->fp = mutt_file_fopen(path, "r");
2432 if (!msg->fp && (errno == ENOENT) && ((m->type == MUTT_MAILDIR) || (m->type == MUTT_NOTMUCH)))
2433 {
2434 msg->fp = maildir_open_find_message(folder, e->path, NULL);
2435 }
2436
2437 return msg->fp != NULL;
2438}
@ MUTT_NOTMUCH
'Notmuch' (virtual) Mailbox type
Definition mailbox.h:50
@ MUTT_MAILDIR
'Maildir' Mailbox type
Definition mailbox.h:47
char * nm_email_get_folder(struct Email *e)
Get the folder for a Email.
Definition notmuch.c:1505
enum MailboxType type
Mailbox type.
Definition mailbox.h:101
+ Here is the call graph for this function:

◆ pop_msg_open()

static bool pop_msg_open ( struct Mailbox * m,
struct Message * msg,
struct Email * e )
static

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

Definition at line 981 of file pop.c.

982{
983 char buf[1024] = { 0 };
985 struct PopEmailData *edata = pop_edata_get(e);
986 bool bcache = true;
987 bool success = false;
988 struct Buffer *path = NULL;
989
990 /* see if we already have the message in body cache */
991 msg->fp = mutt_bcache_get(adata->bcache, cache_id(edata->uid));
992 if (msg->fp)
993 return true;
994
995 /* see if we already have the message in our cache in
996 * case $message_cache_dir is unset */
997 struct PopCache *cache = &adata->cache[e->index % POP_CACHE_LEN];
998
999 if (cache->path)
1000 {
1001 if (cache->index == e->index)
1002 {
1003 /* yes, so just return a pointer to the message */
1004 msg->fp = mutt_file_fopen(cache->path, "r");
1005 if (msg->fp)
1006 return true;
1007
1008 mutt_perror("%s", cache->path);
1009 return false;
1010 }
1011 else
1012 {
1013 /* clear the previous entry */
1014 unlink(cache->path);
1015 FREE(&cache->path);
1016 }
1017 }
1018
1019 path = buf_pool_get();
1020
1021 while (true)
1022 {
1023 if (pop_reconnect(m) < 0)
1024 goto cleanup;
1025
1026 /* verify that massage index is correct */
1027 if (edata->refno < 0)
1028 {
1029 mutt_error(_("The message index is incorrect. Try reopening the mailbox."));
1030 goto cleanup;
1031 }
1032
1033 /* see if we can put in body cache; use our cache as fallback */
1034 msg->fp = mutt_bcache_put(adata->bcache, cache_id(edata->uid));
1035 if (!msg->fp)
1036 {
1037 /* no */
1038 bcache = false;
1040 msg->fp = mutt_file_fopen(buf_string(path), "w+");
1041 if (!msg->fp)
1042 {
1043 mutt_perror("%s", buf_string(path));
1044 goto cleanup;
1045 }
1046 }
1047
1048 snprintf(buf, sizeof(buf), "RETR %d\r\n", edata->refno);
1049
1050 struct Progress *progress = progress_new(MUTT_PROGRESS_NET,
1051 e->body->length + e->body->offset - 1);
1052 progress_set_message(progress, _("Fetching message..."));
1053 const int rc = pop_fetch_data(adata, buf, progress, fetch_message, msg->fp);
1054 progress_free(&progress);
1055
1056 if (rc == 0)
1057 break;
1058
1059 mutt_file_fclose(&msg->fp);
1060
1061 /* if RETR failed (e.g. connection closed), be sure to remove either
1062 * the file in bcache or from POP's own cache since the next iteration
1063 * of the loop will re-attempt to put() the message */
1064 if (!bcache)
1065 unlink(buf_string(path));
1066
1067 if (rc == -2)
1068 {
1069 mutt_error("%s", adata->err_msg);
1070 goto cleanup;
1071 }
1072
1073 if (rc == -3)
1074 {
1075 mutt_error(_("Can't write message to temporary file"));
1076 goto cleanup;
1077 }
1078 }
1079
1080 /* Update the header information. Previously, we only downloaded a
1081 * portion of the headers, those required for the main display. */
1082 if (bcache)
1083 {
1084 mutt_bcache_commit(adata->bcache, cache_id(edata->uid));
1085 }
1086 else
1087 {
1088 cache->index = e->index;
1089 cache->path = buf_strdup(path);
1090 }
1091 rewind(msg->fp);
1092
1093 /* Detach the private data */
1094 e->edata = NULL;
1095
1096 /* we replace envelope, key in subj_hash has to be updated as well */
1097 if (m->subj_hash && e->env->real_subj)
1100 mutt_env_free(&e->env);
1101 e->env = mutt_rfc822_read_header(msg->fp, e, false, false);
1102 if (m->subj_hash && e->env->real_subj)
1104 mutt_label_hash_add(m, e);
1105
1106 /* Reattach the private data */
1107 e->edata = edata;
1109
1110 e->lines = 0;
1111 while (fgets(buf, sizeof(buf), msg->fp) && !feof(msg->fp))
1112 {
1113 e->lines++;
1114 }
1115
1116 e->body->length = ftello(msg->fp) - e->body->offset;
1117
1118 /* This needs to be done in case this is a multipart message */
1119 if (!WithCrypto)
1120 e->security = crypt_query(e->body);
1121
1123 rewind(msg->fp);
1124
1125 success = true;
1126
1127cleanup:
1128 buf_pool_release(&path);
1129 return success;
1130}
void mutt_label_hash_remove(struct Mailbox *m, struct Email *e)
Remove a message's labels from the Hash Table.
Definition header.c:430
void mutt_label_hash_add(struct Mailbox *m, struct Email *e)
Add a message's labels to the Hash Table.
Definition header.c:417
void pop_edata_free(void **ptr)
Free the private Email data - Implements Email::edata_free() -.
Definition edata.c:41
static int fetch_message(const char *line, void *data)
Parse a Message response - Implements pop_fetch_t -.
Definition pop.c:97
struct PopAccountData * pop_adata_get(struct Mailbox *m)
Get the Account data for this mailbox.
Definition adata.c:73
struct PopEmailData * pop_edata_get(struct Email *e)
Get the private data for this Email.
Definition edata.c:68
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:511
int pop_reconnect(struct Mailbox *m)
Reconnect and verify indexes if connection was lost.
Definition lib.c:609
#define POP_CACHE_LEN
Number of entries in the POP cache hash table.
Definition private.h:38
static const char * cache_id(const char *id)
Make a message-cache-compatible id.
Definition pop.c:80
@ MUTT_PROGRESS_NET
Progress tracks bytes, according to $net_inc
Definition lib.h:83
struct Progress * progress_new(enum ProgressType type, size_t size)
Create a new Progress Bar.
Definition progress.c:139
void progress_free(struct Progress **ptr)
Free a Progress Bar.
Definition progress.c:110
void progress_set_message(struct Progress *progress, const char *fmt,...) __attribute__((__format__(__printf__
void * edata
Driver-specific data.
Definition email.h:74
void(* edata_free)(void **ptr)
Definition email.h:90
POP-specific Account data -.
Definition adata.h:37
char err_msg[POP_CMD_RESPONSE]
Last error message.
Definition adata.h:57
struct PopCache cache[POP_CACHE_LEN]
Message cache.
Definition adata.h:58
struct BodyCache * bcache
body cache
Definition adata.h:56
POP-specific email cache.
Definition private.h:67
unsigned int index
Message index.
Definition private.h:68
char * path
Filesystem path.
Definition private.h:69
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: