NeoMutt  2025-12-11-694-ga89709
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
mbox_open()

Open a Mailbox. More...

+ Collaboration diagram for mbox_open():

Functions

static enum MxOpenReturns comp_mbox_open (struct Mailbox *m)
 Open a Mailbox - Implements MxOps::mbox_open() -.
 
static enum MxOpenReturns imap_mbox_open (struct Mailbox *m)
 Open a mailbox - Implements MxOps::mbox_open() -.
 
enum MxOpenReturns maildir_mbox_open (struct Mailbox *m)
 Open a Mailbox - Implements MxOps::mbox_open() -.
 
static enum MxOpenReturns mbox_mbox_open (struct Mailbox *m)
 Open a Mailbox - Implements MxOps::mbox_open() -.
 
static enum MxOpenReturns mh_mbox_open (struct Mailbox *m)
 Open a Mailbox - Implements MxOps::mbox_open() -.
 
static enum MxOpenReturns nntp_mbox_open (struct Mailbox *m)
 Open a Mailbox - Implements MxOps::mbox_open() -.
 
static enum MxOpenReturns nm_mbox_open (struct Mailbox *m)
 Open a Mailbox - Implements MxOps::mbox_open() -.
 
static enum MxOpenReturns pop_mbox_open (struct Mailbox *m)
 Open a Mailbox - Implements MxOps::mbox_open() -.
 

Detailed Description

Open a Mailbox.

Parameters
mMailbox to open
Return values
enumMxOpenReturns
Precondition
m is not NULL

Function Documentation

◆ comp_mbox_open()

static enum MxOpenReturns comp_mbox_open ( struct Mailbox * m)
static

Open a Mailbox - Implements MxOps::mbox_open() -.

Set up a compressed mailbox to be read. Decompress the mailbox and set up the paths and hooks needed. Then determine the type of the mailbox so we can delegate the handling of messages.

Definition at line 419 of file compress.c.

420{
421 struct CompressInfo *ci = set_compress_info(m);
422 if (!ci)
423 return MX_OPEN_ERROR;
424
425 /* If there's no close-hook, or the file isn't writable */
426 if (!ci->cmd_close || (access(mailbox_path(m), W_OK) != 0))
427 m->readonly = true;
428
429 if (setup_paths(m) != 0)
430 goto cmo_fail;
431 store_size(m);
432
433 if (!lock_realpath(m, false))
434 {
435 mutt_error(_("Unable to lock mailbox"));
436 goto cmo_fail;
437 }
438
439 if (!execute_command(m, ci->cmd_open, _("Decompressing %s")))
440 goto cmo_fail;
441
443
445 if (m->type == MUTT_UNKNOWN)
446 {
447 mutt_error(_("Can't identify the contents of the compressed file"));
448 goto cmo_fail;
449 }
450
451 ci->child_ops = mx_get_ops(m->type);
452 if (!ci->child_ops)
453 {
454 mutt_error(_("Can't find mailbox ops for mailbox type %d"), m->type);
455 goto cmo_fail;
456 }
457
458 m->account->type = m->type;
459 return ci->child_ops->mbox_open(m);
460
461cmo_fail:
462 /* remove the partial uncompressed file */
463 (void) remove(mailbox_path(m));
465 return MX_OPEN_ERROR;
466}
static struct CompressInfo * set_compress_info(struct Mailbox *m)
Find the compress hooks for a mailbox.
Definition compress.c:239
static void compress_info_free(struct Mailbox *m)
Frees the compress info members and structure.
Definition compress.c:269
static int setup_paths(struct Mailbox *m)
Set the mailbox paths.
Definition compress.c:179
static void store_size(const struct Mailbox *m)
Save the size of the compressed file.
Definition compress.c:202
static bool lock_realpath(struct Mailbox *m, bool excl)
Try to lock the Mailbox.realpath.
Definition compress.c:108
static void unlock_realpath(struct Mailbox *m)
Unlock the mailbox->realpath.
Definition compress.c:153
static bool execute_command(struct Mailbox *m, const struct Expando *exp, const char *progress)
Run a system command.
Definition compress.c:295
static const char * mailbox_path(const struct Mailbox *m)
Get the Mailbox's path string.
Definition mailbox.h:213
@ MUTT_UNKNOWN
Mailbox wasn't recognised.
Definition mailbox.h:43
#define mutt_error(...)
Definition logging2.h:94
#define _(a)
Definition message.h:28
const struct MxOps * mx_get_ops(enum MailboxType type)
Get mailbox operations.
Definition mx.c:124
enum MailboxType mx_path_probe(const char *path)
Find a mailbox that understands a path.
Definition mx.c:1323
@ MX_OPEN_ERROR
Open failed with an error.
Definition mxapi.h:74
enum MailboxType type
Type of Mailboxes this Account contains.
Definition account.h:37
Private data for compress.
Definition lib.h:61
struct Expando * cmd_open
open-hook command
Definition lib.h:64
const struct MxOps * child_ops
callbacks of de-compressed file
Definition lib.h:66
struct Expando * cmd_close
close-hook command
Definition lib.h:63
enum MailboxType type
Mailbox type.
Definition mailbox.h:101
struct Account * account
Account that owns this Mailbox.
Definition mailbox.h:126
bool readonly
Don't allow changes to the mailbox.
Definition mailbox.h:115
enum MxOpenReturns(* mbox_open)(struct Mailbox *m)
Definition mxapi.h:132
+ Here is the call graph for this function:

◆ imap_mbox_open()

static enum MxOpenReturns imap_mbox_open ( struct Mailbox * m)
static

Open a mailbox - Implements MxOps::mbox_open() -.

Definition at line 2059 of file imap.c.

2060{
2061 if (!m->account || !m->mdata)
2062 return MX_OPEN_ERROR;
2063
2064 char buf[PATH_MAX] = { 0 };
2065 int count = 0;
2066 int rc;
2067
2069 struct ImapMboxData *mdata = imap_mdata_get(m);
2070 if (!adata || !mdata)
2071 return MX_OPEN_ERROR;
2072
2073 mutt_debug(LL_DEBUG3, "opening %s, stranding %p\n", m->pathbuf.data,
2074 (void *) adata->mailbox);
2075 adata->prev_mailbox = adata->mailbox;
2076 adata->mailbox = m;
2077
2078 /* clear mailbox status */
2079 adata->status = 0;
2080 m->rights = 0;
2081 mdata->new_mail_count = 0;
2082
2083 if (m->verbose)
2084 mutt_message(_("Selecting %s..."), mdata->name);
2085
2086 /* pipeline ACL test */
2087 if (adata->capabilities & IMAP_CAP_ACL)
2088 {
2089 snprintf(buf, sizeof(buf), "MYRIGHTS %s", mdata->munge_name);
2090 imap_exec(adata, buf, IMAP_CMD_QUEUE);
2091 }
2092 else
2093 {
2094 /* assume we have all rights if ACL is unavailable */
2097 }
2098
2099 /* pipeline the postponed count if possible */
2100 const char *const c_postponed = cs_subset_string(NeoMutt->sub, "postponed");
2101 struct Mailbox *m_postponed = mx_mbox_find2(c_postponed);
2102 struct ImapAccountData *postponed_adata = imap_adata_get(m_postponed);
2103 if (postponed_adata &&
2104 imap_account_match(&postponed_adata->conn->account, &adata->conn->account))
2105 {
2106 imap_mailbox_status(m_postponed, true);
2107 }
2108
2109 const bool c_imap_check_subscribed = cs_subset_bool(NeoMutt->sub, "imap_check_subscribed");
2110 if (c_imap_check_subscribed)
2111 imap_exec(adata, "LSUB \"\" \"*\"", IMAP_CMD_QUEUE);
2112
2114
2115 do
2116 {
2117 char *pc = NULL;
2118
2119 rc = imap_cmd_step(adata);
2120 if (rc != IMAP_RES_CONTINUE)
2121 break;
2122
2123 if (!mutt_strn_equal(adata->buf, "* ", 2))
2124 continue;
2125 pc = imap_next_word(adata->buf);
2126
2127 /* Obtain list of available flags here, may be overridden by a
2128 * PERMANENTFLAGS tag in the OK response */
2129 if (mutt_istr_startswith(pc, "FLAGS"))
2130 {
2131 /* don't override PERMANENTFLAGS */
2132 if (STAILQ_EMPTY(&mdata->flags))
2133 {
2134 mutt_debug(LL_DEBUG3, "Getting mailbox FLAGS\n");
2135 pc = get_flags(&mdata->flags, pc);
2136 if (!pc)
2137 goto fail;
2138 }
2139 }
2140 else if (mutt_istr_startswith(pc, "OK [PERMANENTFLAGS"))
2141 {
2142 /* PERMANENTFLAGS are massaged to look like FLAGS, then override FLAGS */
2143 mutt_debug(LL_DEBUG3, "Getting mailbox PERMANENTFLAGS\n");
2144 /* safe to call on NULL */
2145 mutt_list_free(&mdata->flags);
2146 /* skip "OK [PERMANENT" so syntax is the same as FLAGS */
2147 pc += 13;
2148 pc = get_flags(&(mdata->flags), pc);
2149 if (!pc)
2150 goto fail;
2151 }
2152 else if (mutt_istr_startswith(pc, "OK [UIDVALIDITY"))
2153 {
2154 /* save UIDVALIDITY for the header cache */
2155 mutt_debug(LL_DEBUG3, "Getting mailbox UIDVALIDITY\n");
2156 pc += 3;
2157 pc = imap_next_word(pc);
2158 if (!mutt_str_atoui(pc, &mdata->uidvalidity))
2159 goto fail;
2160 }
2161 else if (mutt_istr_startswith(pc, "OK [UIDNEXT"))
2162 {
2163 mutt_debug(LL_DEBUG3, "Getting mailbox UIDNEXT\n");
2164 pc += 3;
2165 pc = imap_next_word(pc);
2166 if (!mutt_str_atoui(pc, &mdata->uid_next))
2167 goto fail;
2168 }
2169 else if (mutt_istr_startswith(pc, "OK [HIGHESTMODSEQ"))
2170 {
2171 mutt_debug(LL_DEBUG3, "Getting mailbox HIGHESTMODSEQ\n");
2172 pc += 3;
2173 pc = imap_next_word(pc);
2174 if (!mutt_str_atoull(pc, &mdata->modseq))
2175 goto fail;
2176 }
2177 else if (mutt_istr_startswith(pc, "OK [NOMODSEQ"))
2178 {
2179 mutt_debug(LL_DEBUG3, "Mailbox has NOMODSEQ set\n");
2180 mdata->modseq = 0;
2181 }
2182 else
2183 {
2184 pc = imap_next_word(pc);
2185 if (mutt_istr_startswith(pc, "EXISTS"))
2186 {
2187 count = mdata->new_mail_count;
2188 mdata->new_mail_count = 0;
2189 }
2190 }
2191 } while (rc == IMAP_RES_CONTINUE);
2192
2193 if (rc == IMAP_RES_NO)
2194 {
2195 char *s = imap_next_word(adata->buf); /* skip seq */
2196 s = imap_next_word(s); /* Skip response */
2197 mutt_error("%s", s);
2198 goto fail;
2199 }
2200
2201 if (rc != IMAP_RES_OK)
2202 goto fail;
2203
2204 /* check for READ-ONLY notification */
2205 if (mutt_istr_startswith(imap_get_qualifier(adata->buf), "[READ-ONLY]") &&
2206 !(adata->capabilities & IMAP_CAP_ACL))
2207 {
2208 mutt_debug(LL_DEBUG2, "Mailbox is read-only\n");
2209 m->readonly = true;
2210 }
2211
2212 /* dump the mailbox flags we've found */
2213 const short c_debug_level = cs_subset_number(NeoMutt->sub, "debug_level");
2214 if (c_debug_level > LL_DEBUG2)
2215 {
2216 if (STAILQ_EMPTY(&mdata->flags))
2217 {
2218 mutt_debug(LL_DEBUG3, "No folder flags found\n");
2219 }
2220 else
2221 {
2222 struct ListNode *np = NULL;
2223 struct Buffer *flag_buffer = buf_pool_get();
2224 buf_printf(flag_buffer, "Mailbox flags: ");
2225 STAILQ_FOREACH(np, &mdata->flags, entries)
2226 {
2227 buf_add_printf(flag_buffer, "[%s] ", np->data);
2228 }
2229 mutt_debug(LL_DEBUG3, "%s\n", buf_string(flag_buffer));
2230 buf_pool_release(&flag_buffer);
2231 }
2232 }
2233
2234 if (!((m->rights & MUTT_ACL_DELETE) || (m->rights & MUTT_ACL_SEEN) ||
2235 (m->rights & MUTT_ACL_WRITE) || (m->rights & MUTT_ACL_INSERT)))
2236 {
2237 m->readonly = true;
2238 }
2239
2240 mx_alloc_memory(m, count);
2241
2242 m->msg_count = 0;
2243 m->msg_unread = 0;
2244 m->msg_flagged = 0;
2245 m->msg_new = 0;
2246 m->msg_deleted = 0;
2247 m->size = 0;
2248 m->vcount = 0;
2249
2250 if ((count > 0) && (imap_read_headers(m, 1, count, true) < 0))
2251 {
2252 mutt_error(_("Error opening mailbox"));
2253 goto fail;
2254 }
2255
2256 mutt_debug(LL_DEBUG2, "msg_count is %d\n", m->msg_count);
2257 return MX_OPEN_OK;
2258
2259fail:
2260 adata->mailbox = adata->prev_mailbox;
2261 adata->prev_mailbox = NULL;
2262 if (adata->state == IMAP_SELECTED)
2263 adata->state = IMAP_AUTHENTICATED;
2264 return MX_OPEN_ERROR;
2265}
const char * mutt_str_atoull(const char *str, unsigned long long *dst)
Convert ASCII string to an unsigned long long.
Definition atoi.c:295
const char * mutt_str_atoui(const char *str, unsigned int *dst)
Convert ASCII string to an unsigned integer.
Definition atoi.c:217
int buf_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition buffer.c:161
int buf_add_printf(struct Buffer *buf, const char *fmt,...)
Format a string appending a Buffer.
Definition buffer.c:204
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition buffer.h:96
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
Definition helpers.c:291
short cs_subset_number(const struct ConfigSubset *sub, const char *name)
Get a number config item by name.
Definition helpers.c:143
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition helpers.c:47
#define MUTT_ACL_CREATE
Create a mailbox.
Definition mailbox.h:61
#define MUTT_ACL_POST
Post (submit messages to the server)
Definition mailbox.h:67
#define MUTT_ACL_LOOKUP
Lookup mailbox (visible to 'list')
Definition mailbox.h:66
#define MUTT_ACL_INSERT
Add/copy into the mailbox (used when editing a message)
Definition mailbox.h:65
#define MUTT_ACL_DELETE
Delete a message.
Definition mailbox.h:62
#define MUTT_ACL_WRITE
Write to a message (for flagging or linking threads)
Definition mailbox.h:70
#define MUTT_ACL_SEEN
Change the 'seen' status of a message.
Definition mailbox.h:69
#define MUTT_ACL_READ
Read the mailbox.
Definition mailbox.h:68
#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_step(struct ImapAccountData *adata)
Reads server responses from an IMAP command.
Definition command.c:1225
int imap_exec(struct ImapAccountData *adata, const char *cmdstr, ImapCmdFlags flags)
Execute a command and wait for the response from the server.
Definition command.c:1415
struct ImapMboxData * imap_mdata_get(struct Mailbox *m)
Get the Mailbox data for this mailbox.
Definition mdata.c:61
int imap_read_headers(struct Mailbox *m, unsigned int msn_begin, unsigned int msn_end, bool initial_download)
Read headers from the server.
Definition message.c:1363
@ IMAP_AUTHENTICATED
Connection is authenticated.
Definition private.h:107
@ IMAP_SELECTED
Mailbox is selected.
Definition private.h:108
#define IMAP_RES_OK
<tag> OK ...
Definition private.h:54
#define IMAP_CAP_ACL
RFC2086: IMAP4 ACL extension.
Definition private.h:124
#define IMAP_RES_NO
<tag> NO ...
Definition private.h:52
bool imap_account_match(const struct ConnAccount *a1, const struct ConnAccount *a2)
Compare two Accounts.
Definition util.c:1103
#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
#define IMAP_CMD_QUEUE
Queue a command, do not execute.
Definition private.h:73
char * imap_get_qualifier(char *buf)
Get the qualifier from a tagged response.
Definition util.c:809
int imap_mailbox_status(struct Mailbox *m, bool queue)
Refresh the number of total and new messages.
Definition imap.c:1389
static char * get_flags(struct ListHead *hflags, char *s)
Make a simple list out of a FLAGS response.
Definition imap.c:233
static void imap_mbox_select(struct Mailbox *m)
Select a Mailbox.
Definition imap.c:1936
void mutt_list_free(struct ListHead *h)
Free a List AND its strings.
Definition list.c:123
@ LL_DEBUG3
Log at debug level 3.
Definition logging2.h:47
@ LL_DEBUG2
Log at debug level 2.
Definition logging2.h:46
bool mutt_strn_equal(const char *a, const char *b, size_t num)
Check for equality of two strings (to a maximum), safely.
Definition string.c:429
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
#define PATH_MAX
Definition mutt.h:49
void mx_alloc_memory(struct Mailbox *m, int req_size)
Create storage for the emails.
Definition mx.c:1208
struct Mailbox * mx_mbox_find2(const char *path)
Find a Mailbox on an Account.
Definition mx.c:1615
@ MX_OPEN_OK
Open succeeded.
Definition mxapi.h:73
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
#define STAILQ_FOREACH(var, head, field)
Definition queue.h:390
#define STAILQ_EMPTY(head)
Definition queue.h:382
void * adata
Private data (for Mailbox backends)
Definition account.h:42
String manipulation buffer.
Definition buffer.h:36
char * data
Pointer to data.
Definition buffer.h:37
struct ConnAccount account
Account details: username, password, etc.
Definition connection.h:49
IMAP-specific Account data -.
Definition adata.h:40
struct Mailbox * prev_mailbox
Previously selected mailbox.
Definition adata.h:80
ImapCapFlags capabilities
Capability flags.
Definition adata.h:55
unsigned char state
ImapState, e.g. IMAP_AUTHENTICATED.
Definition adata.h:44
struct Mailbox * mailbox
Current selected mailbox.
Definition adata.h:79
unsigned char status
ImapFlags, e.g. IMAP_FATAL.
Definition adata.h:45
struct Connection * conn
Connection to IMAP server.
Definition adata.h:41
IMAP-specific Mailbox data -.
Definition mdata.h:40
unsigned int uid_next
Next UID for new message.
Definition mdata.h:52
struct ListHead flags
List of permanent flags.
Definition mdata.h:50
unsigned int new_mail_count
Set when EXISTS notifies of new mail.
Definition mdata.h:47
unsigned long long modseq
Modification sequence number.
Definition mdata.h:53
uint32_t uidvalidity
UID validity.
Definition mdata.h:51
A List node for strings.
Definition list.h:37
char * data
String.
Definition list.h:38
A mailbox.
Definition mailbox.h:78
int vcount
The number of virtual messages.
Definition mailbox.h:98
int msg_new
Number of new messages.
Definition mailbox.h:91
int msg_count
Total number of messages.
Definition mailbox.h:87
AclFlags rights
ACL bits, see AclFlags.
Definition mailbox.h:118
void * mdata
Driver specific data.
Definition mailbox.h:131
struct Buffer pathbuf
Path of the Mailbox.
Definition mailbox.h:79
int msg_deleted
Number of deleted messages.
Definition mailbox.h:92
off_t size
Size of the Mailbox.
Definition mailbox.h:83
int msg_flagged
Number of flagged messages.
Definition mailbox.h:89
bool verbose
Display status messages?
Definition mailbox.h:116
int msg_unread
Number of unread messages.
Definition mailbox.h:88
Container for Accounts, Notifications.
Definition neomutt.h:41
struct ConfigSubset * sub
Inherited config items.
Definition neomutt.h:49
+ Here is the call graph for this function:

◆ maildir_mbox_open()

enum MxOpenReturns maildir_mbox_open ( struct Mailbox * m)

Open a Mailbox - Implements MxOps::mbox_open() -.

Definition at line 746 of file mailbox.c.

747{
748 if ((maildir_read_dir(m, "new") == -1) || (maildir_read_dir(m, "cur") == -1))
749 return MX_OPEN_ERROR;
750
751 return MX_OPEN_OK;
752}
static int maildir_read_dir(struct Mailbox *m, const char *subdir)
Read a Maildir style mailbox.
Definition mailbox.c:487
+ Here is the call graph for this function:

◆ mbox_mbox_open()

static enum MxOpenReturns mbox_mbox_open ( struct Mailbox * m)
static

Open a Mailbox - Implements MxOps::mbox_open() -.

Definition at line 832 of file mbox.c.

833{
834 if (init_mailbox(m) != 0)
835 return MX_OPEN_ERROR;
836
838 if (!adata)
839 return MX_OPEN_ERROR;
840
841 adata->fp = m->readonly ? NULL : mbox_open_readwrite(m);
842 if (!adata->fp)
843 {
844 adata->fp = mbox_open_readonly(m);
845 }
846 if (!adata->fp)
847 {
848 mutt_perror("%s", mailbox_path(m));
849 return MX_OPEN_ERROR;
850 }
851
853 if (mbox_lock_mailbox(m, false, true) == -1)
854 {
856 return MX_OPEN_ERROR;
857 }
858
859 m->has_new = true;
861 if (m->type == MUTT_MBOX)
862 rc = mbox_parse_mailbox(m);
863 else if (m->type == MUTT_MMDF)
864 rc = mmdf_parse_mailbox(m);
865 else
866 rc = MX_OPEN_ERROR;
867
868 if (!mbox_has_new(m))
869 m->has_new = false;
870 clearerr(adata->fp); // Clear the EOF flag
871 mutt_file_touch_atime(fileno(adata->fp));
872
875 return rc;
876}
@ MUTT_MMDF
'mmdf' Mailbox type
Definition mailbox.h:45
@ MUTT_MBOX
'mbox' Mailbox type
Definition mailbox.h:44
void mutt_file_touch_atime(int fd)
Set the access time to current time.
Definition file.c:961
#define mutt_perror(...)
Definition logging2.h:95
static enum MxOpenReturns mbox_parse_mailbox(struct Mailbox *m)
Read a mailbox from disk.
Definition mbox.c:355
static bool mbox_has_new(struct Mailbox *m)
Does the mailbox have new mail.
Definition mbox.c:730
static int mbox_lock_mailbox(struct Mailbox *m, bool excl, bool retry)
Lock a mailbox.
Definition mbox.c:136
static struct MboxAccountData * mbox_adata_get(struct Mailbox *m)
Get the private data associated with a Mailbox.
Definition mbox.c:121
static int init_mailbox(struct Mailbox *m)
Add Mbox data to the Mailbox.
Definition mbox.c:102
static FILE * mbox_open_readwrite(struct Mailbox *m)
Open an mbox read-write.
Definition mbox.c:806
static FILE * mbox_open_readonly(struct Mailbox *m)
Open an mbox read-only.
Definition mbox.c:821
static void mbox_unlock_mailbox(struct Mailbox *m)
Unlock a mailbox.
Definition mbox.c:160
static enum MxOpenReturns mmdf_parse_mailbox(struct Mailbox *m)
Read a mailbox in MMDF format.
Definition mbox.c:180
MxOpenReturns
Return values for mbox_open()
Definition mxapi.h:72
void mutt_sig_block(void)
Block signals during critical operations.
Definition signal.c:227
void mutt_sig_unblock(void)
Restore previously blocked signals.
Definition signal.c:245
bool has_new
Mailbox has new mail.
Definition mailbox.h:84
Mbox-specific Account data -.
Definition lib.h:50
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mh_mbox_open()

static enum MxOpenReturns mh_mbox_open ( struct Mailbox * m)
static

Open a Mailbox - Implements MxOps::mbox_open() -.

Definition at line 819 of file mh.c.

820{
822}
static bool mh_read_dir(struct Mailbox *m)
Read an MH mailbox.
Definition mh.c:665
+ Here is the call graph for this function:

◆ nntp_mbox_open()

static enum MxOpenReturns nntp_mbox_open ( struct Mailbox * m)
static

Open a Mailbox - Implements MxOps::mbox_open() -.

Definition at line 2384 of file nntp.c.

2385{
2386 if (!m->account)
2387 return MX_OPEN_ERROR;
2388
2389 char buf[8192] = { 0 };
2390 char server[1024] = { 0 };
2391 char *group = NULL;
2392 int rc;
2393 struct HeaderCache *hc = NULL;
2394 anum_t first = 0, last = 0, count = 0;
2395
2396 struct Url *url = url_parse(mailbox_path(m));
2397 if (!url || !url->host || !url->path ||
2398 !((url->scheme == U_NNTP) || (url->scheme == U_NNTPS)))
2399 {
2400 url_free(&url);
2401 mutt_error(_("%s is an invalid newsgroup specification"), mailbox_path(m));
2402 return MX_OPEN_ERROR;
2403 }
2404
2405 group = url->path;
2406 if (group[0] == '/') /* Skip a leading '/' */
2407 group++;
2408
2409 url->path = strchr(url->path, '\0');
2410 url_tostring(url, server, sizeof(server), U_NO_FLAGS);
2411
2413 struct NntpAccountData *adata = m->account->adata;
2414 if (!adata)
2416 if (!adata)
2417 {
2418 adata = nntp_select_server(m, server, true);
2419 m->account->adata = adata;
2421 }
2422
2423 if (!adata)
2424 {
2425 url_free(&url);
2426 return MX_OPEN_ERROR;
2427 }
2429
2430 m->msg_count = 0;
2431 m->msg_unread = 0;
2432 m->vcount = 0;
2433
2434 if (group[0] == '/')
2435 group++;
2436
2437 /* find news group data structure */
2439 if (!mdata)
2440 {
2442 mutt_error(_("Newsgroup %s not found on the server"), group);
2443 url_free(&url);
2444 return MX_OPEN_ERROR;
2445 }
2446
2447 m->rights &= ~MUTT_ACL_INSERT; // Clear the flag
2448 const bool c_save_unsubscribed = cs_subset_bool(NeoMutt->sub, "save_unsubscribed");
2449 if (!mdata->newsrc_ent && !mdata->subscribed && !c_save_unsubscribed)
2450 m->readonly = true;
2451
2452 /* select newsgroup */
2453 mutt_message(_("Selecting %s..."), group);
2454 url_free(&url);
2455 buf[0] = '\0';
2456 if (nntp_query(mdata, buf, sizeof(buf)) < 0)
2457 {
2459 return MX_OPEN_ERROR;
2460 }
2461
2462 /* newsgroup not found, remove it */
2463 if (mutt_str_startswith(buf, "411"))
2464 {
2465 mutt_error(_("Newsgroup %s has been removed from the server"), mdata->group);
2466 if (!mdata->deleted)
2467 {
2468 mdata->deleted = true;
2470 }
2471 if (mdata->newsrc_ent && !mdata->subscribed && !c_save_unsubscribed)
2472 {
2473 FREE(&mdata->newsrc_ent);
2474 mdata->newsrc_len = 0;
2477 }
2478 }
2479 else
2480 {
2481 /* parse newsgroup info */
2482 if (sscanf(buf, "211 " ANUM_FMT " " ANUM_FMT " " ANUM_FMT, &count, &first, &last) != 3)
2483 {
2485 mutt_error("GROUP: %s", buf);
2486 return MX_OPEN_ERROR;
2487 }
2488 mdata->first_message = first;
2489 mdata->last_message = last;
2490 mdata->deleted = false;
2491
2492 /* get description if empty */
2493 const bool c_nntp_load_description = cs_subset_bool(NeoMutt->sub, "nntp_load_description");
2494 if (c_nntp_load_description && !mdata->desc)
2495 {
2496 if (get_description(mdata, NULL, NULL) < 0)
2497 {
2499 return MX_OPEN_ERROR;
2500 }
2501 if (mdata->desc)
2503 }
2504 }
2505
2507 m->mdata = mdata;
2508 // Every known newsgroup has an mdata which is stored in adata->groups_list.
2509 // Currently we don't let the Mailbox free the mdata.
2510 // m->mdata_free = nntp_mdata_free;
2511 if (!mdata->bcache && (mdata->newsrc_ent || mdata->subscribed || c_save_unsubscribed))
2512 mdata->bcache = mutt_bcache_open(&adata->conn->account, mdata->group);
2513
2514 /* strip off extra articles if adding context is greater than $nntp_context */
2515 first = mdata->first_message;
2516 const long c_nntp_context = cs_subset_long(NeoMutt->sub, "nntp_context");
2517 if (c_nntp_context && ((mdata->last_message - first + 1) > c_nntp_context))
2518 first = mdata->last_message - c_nntp_context + 1;
2519 mdata->last_loaded = first ? first - 1 : 0;
2520 count = mdata->first_message;
2521 mdata->first_message = first;
2523 mdata->first_message = count;
2524#ifdef USE_HCACHE
2525 hc = nntp_hcache_open(mdata);
2527#endif
2528 if (!hc)
2529 m->rights &= ~(MUTT_ACL_WRITE | MUTT_ACL_DELETE); // Clear the flags
2530
2532 rc = nntp_fetch_headers(m, hc, first, mdata->last_message, false);
2533#ifdef USE_HCACHE
2534 hcache_close(&hc);
2535#endif
2536 if (rc < 0)
2537 return MX_OPEN_ERROR;
2538 mdata->last_loaded = mdata->last_message;
2539 adata->newsrc_modified = false;
2540 return MX_OPEN_OK;
2541}
struct BodyCache * mutt_bcache_open(struct ConnAccount *account, const char *mailbox)
Open an Email-Body Cache.
Definition bcache.c:146
long cs_subset_long(const struct ConfigSubset *sub, const char *name)
Get a long config item by name.
Definition helpers.c:95
void nntp_adata_free(void **ptr)
Free the private Account data - Implements Account::adata_free() -.
Definition adata.c:42
void * mutt_hash_find(const struct HashTable *table, const char *strkey)
Find the HashElem data in a Hash Table element using a key.
Definition hash.c:364
void hcache_close(struct HeaderCache **ptr)
Multiplexor for StoreOps::close.
Definition hcache.c:550
void exec_account_hook(const char *url)
Perform an account hook.
Definition exec.c:323
#define FREE(x)
Free memory and set the pointer to NULL.
Definition memory.h:68
time_t mutt_date_now(void)
Return the number of seconds since the Unix epoch.
Definition date.c:457
size_t mutt_str_startswith(const char *str, const char *prefix)
Check whether a string starts with a prefix.
Definition string.c:234
struct HeaderCache * nntp_hcache_open(struct NntpMboxData *mdata)
Open newsgroup hcache.
Definition newsrc.c:707
void nntp_delete_group_cache(struct NntpMboxData *mdata)
Remove hcache and bcache of newsgroup.
Definition newsrc.c:808
void nntp_hcache_update(struct NntpMboxData *mdata, struct HeaderCache *hc)
Remove stale cached headers.
Definition newsrc.c:731
int nntp_active_save_cache(struct NntpAccountData *adata)
Save list of all newsgroups to cache.
Definition newsrc.c:646
void nntp_bcache_update(struct NntpMboxData *mdata)
Remove stale cached messages.
Definition newsrc.c:799
void nntp_newsrc_close(struct NntpAccountData *adata)
Unlock and close .newsrc file.
Definition newsrc.c:119
int nntp_newsrc_update(struct NntpAccountData *adata)
Update .newsrc file.
Definition newsrc.c:442
#define ANUM_FMT
Definition lib.h:64
struct NntpAccountData * CurrentNewsSrv
Current NNTP news server.
Definition nntp.c:74
struct NntpAccountData * nntp_select_server(struct Mailbox *m, const char *server, bool leave_lock)
Open a connection to an NNTP server.
Definition newsrc.c:951
#define anum_t
Definition lib.h:63
static int nntp_query(struct NntpMboxData *mdata, char *line, size_t linelen)
Send data from buffer and receive answer to same buffer.
Definition nntp.c:731
static int get_description(struct NntpMboxData *mdata, const char *wildmat, const char *msg)
Fetch newsgroups descriptions.
Definition nntp.c:937
static int nntp_fetch_headers(struct Mailbox *m, void *hc, anum_t first, anum_t last, bool restore)
Fetch headers.
Definition nntp.c:1205
void(* adata_free)(void **ptr)
Definition account.h:53
Header Cache.
Definition lib.h:87
char * realpath
Used for duplicate detection, context comparison, and the sidebar.
Definition mailbox.h:80
NNTP-specific Account data -.
Definition adata.h:36
bool newsrc_modified
Newsrc file was modified.
Definition adata.h:49
struct HashTable * groups_hash
Hash Table: "newsgroup" -> NntpMboxData.
Definition adata.h:62
struct Connection * conn
Connection to NNTP Server.
Definition adata.h:63
time_t check_time
Last check time.
Definition adata.h:57
NNTP-specific Mailbox data -.
Definition mdata.h:34
char * group
Name of newsgroup.
Definition mdata.h:35
struct NntpAccountData * adata
Account data.
Definition mdata.h:48
A parsed URL proto://user:password@host:port/path?a=1&b=2
Definition url.h:69
char * host
Host.
Definition url.h:73
char * path
Path.
Definition url.h:75
enum UrlScheme scheme
Scheme, e.g. U_SMTPS.
Definition url.h:70
struct Url * url_parse(const char *src)
Fill in Url.
Definition url.c:239
void url_free(struct Url **ptr)
Free the contents of a URL.
Definition url.c:124
int url_tostring(const struct Url *url, char *dest, size_t len, uint8_t flags)
Output the URL string for a given Url object.
Definition url.c:423
#define U_NO_FLAGS
No flags are set for URL parsing.
Definition url.h:49
@ U_NNTPS
Url is nntps://.
Definition url.h:42
@ U_NNTP
Url is nntp://.
Definition url.h:41
+ Here is the call graph for this function:

◆ nm_mbox_open()

static enum MxOpenReturns nm_mbox_open ( struct Mailbox * m)
static

Open a Mailbox - Implements MxOps::mbox_open() -.

Definition at line 2090 of file notmuch.c.

2091{
2092 if (init_mailbox(m) != 0)
2093 return MX_OPEN_ERROR;
2094
2095 struct NmMboxData *mdata = nm_mdata_get(m);
2096 if (!mdata)
2097 return MX_OPEN_ERROR;
2098
2099 mutt_debug(LL_DEBUG1, "nm: reading messages...[current count=%d]\n", m->msg_count);
2100
2101 progress_setup(m);
2102 enum MxOpenReturns rc = MX_OPEN_ERROR;
2103
2104 notmuch_query_t *q = get_query(m, false);
2105 if (q)
2106 {
2107 rc = MX_OPEN_OK;
2108 switch (mdata->query_type)
2109 {
2110 case NM_QUERY_TYPE_UNKNOWN: // UNKNOWN should never occur, but MESGS is default
2112 if (!read_mesgs_query(m, q, false))
2113 rc = MX_OPEN_ABORT;
2114 break;
2116 if (!read_threads_query(m, q, false, get_limit(mdata)))
2117 rc = MX_OPEN_ABORT;
2118 break;
2119 }
2120 notmuch_query_destroy(q);
2121 }
2122
2123 nm_db_release(m);
2124
2125 mdata->mtime.tv_sec = mutt_date_now();
2126 mdata->mtime.tv_nsec = 0;
2127
2128 mdata->oldmsgcount = 0;
2129
2130 mutt_debug(LL_DEBUG1, "nm: reading messages... done [rc=%d, count=%d]\n", rc, m->msg_count);
2131 progress_free(&mdata->progress);
2132 return rc;
2133}
@ LL_DEBUG1
Log at debug level 1.
Definition logging2.h:45
@ MX_OPEN_ABORT
Open was aborted.
Definition mxapi.h:75
int nm_db_release(struct Mailbox *m)
Close the Notmuch database.
Definition db.c:233
struct NmMboxData * nm_mdata_get(struct Mailbox *m)
Get the Notmuch Mailbox data.
Definition mdata.c:96
static int init_mailbox(struct Mailbox *m)
Add Notmuch data to the Mailbox.
Definition notmuch.c:192
static int get_limit(struct NmMboxData *mdata)
Get the database limit.
Definition notmuch.c:414
static bool read_threads_query(struct Mailbox *m, notmuch_query_t *q, bool dedup, int limit)
Perform a query with threads.
Definition notmuch.c:1044
static notmuch_query_t * get_query(struct Mailbox *m, bool writable)
Create a new query.
Definition notmuch.c:449
static bool read_mesgs_query(struct Mailbox *m, notmuch_query_t *q, bool dedup)
Search for matching messages.
Definition notmuch.c:974
static void progress_setup(struct Mailbox *m)
Set up the Progress Bar.
Definition notmuch.c:704
void progress_free(struct Progress **ptr)
Free a Progress Bar.
Definition progress.c:110
@ NM_QUERY_TYPE_UNKNOWN
Unknown query type. Error in notmuch query.
Definition query.h:38
@ NM_QUERY_TYPE_THREADS
Whole threads.
Definition query.h:40
@ NM_QUERY_TYPE_MESSAGES
Default: Messages only.
Definition query.h:39
Notmuch-specific Mailbox data -.
Definition mdata.h:35
+ Here is the call graph for this function:

◆ pop_mbox_open()

static enum MxOpenReturns pop_mbox_open ( struct Mailbox * m)
static

Open a Mailbox - Implements MxOps::mbox_open() -.

Fetch only headers

Definition at line 746 of file pop.c.

747{
748 if (!m->account)
749 return MX_OPEN_ERROR;
750
751 char buf[PATH_MAX] = { 0 };
752 struct ConnAccount cac = { { 0 } };
753 struct Url url = { 0 };
754
755 if (pop_parse_path(mailbox_path(m), &cac))
756 {
757 mutt_error(_("%s is an invalid POP path"), mailbox_path(m));
758 return MX_OPEN_ERROR;
759 }
760
761 account_to_url(&cac, &url);
762 url.path = NULL;
763 url_tostring(&url, buf, sizeof(buf), U_NO_FLAGS);
764
765 buf_strcpy(&m->pathbuf, buf);
767
768 struct PopAccountData *adata = m->account->adata;
769 if (!adata)
770 {
772 m->account->adata = adata;
774 }
775
776 struct Connection *conn = adata->conn;
777 if (!conn)
778 {
779 adata->conn = mutt_conn_new(&cac);
780 conn = adata->conn;
781 if (!conn)
782 return MX_OPEN_ERROR;
783 }
784
785 if (conn->fd < 0)
787
788 if (pop_open_connection(adata) < 0)
789 return MX_OPEN_ERROR;
790
791 adata->bcache = mutt_bcache_open(&cac, NULL);
792
793 /* init (hard-coded) ACL rights */
795#ifdef USE_HCACHE
796 /* flags are managed using header cache, so it only makes sense to
797 * enable them in that case */
799#endif
800
801 while (true)
802 {
803 if (pop_reconnect(m) < 0)
804 return MX_OPEN_ERROR;
805
806 m->size = adata->size;
807
808 mutt_message(_("Fetching list of messages..."));
809
810 const int rc = pop_fetch_headers(m);
811
812 if (rc >= 0)
813 return MX_OPEN_OK;
814
815 if (rc < -1)
816 return MX_OPEN_ERROR;
817 }
818}
size_t buf_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition buffer.c:395
void pop_adata_free(void **ptr)
Free the private Account data - Implements Account::adata_free() -.
Definition adata.c:41
char * mutt_str_replace(char **p, const char *s)
Replace one string with another.
Definition string.c:284
void account_to_url(struct ConnAccount *cac, struct Url *url)
Fill URL with info from account.
struct Connection * mutt_conn_new(const struct ConnAccount *cac)
Create a new Connection.
Definition mutt_socket.c:47
struct PopAccountData * pop_adata_new(void)
Create a new PopAccountData object.
Definition adata.c:63
int pop_open_connection(struct PopAccountData *adata)
Open connection and authenticate.
Definition lib.c:316
int pop_parse_path(const char *path, struct ConnAccount *cac)
Parse a POP mailbox name.
Definition lib.c:82
int pop_reconnect(struct Mailbox *m)
Reconnect and verify indexes if connection was lost.
Definition lib.c:609
static int pop_fetch_headers(struct Mailbox *m)
Read headers.
Definition pop.c:329
Login details for a remote server.
Definition connaccount.h:53
int fd
Socket file descriptor.
Definition connection.h:53
POP-specific Account data -.
Definition adata.h:37
size_t size
Mailbox size.
Definition adata.h:50
struct Connection * conn
Connection to POP server.
Definition adata.h:38
struct BodyCache * bcache
body cache
Definition adata.h:56
+ Here is the call graph for this function: