NeoMutt  2025-12-11-1061-g88ae84
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()

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 377 of file compress.c.

378{
379 struct CompressInfo *ci = set_compress_info(m);
380 if (!ci)
381 return MX_OPEN_ERROR;
382
383 /* If there's no close-hook, or the file isn't writable */
384 if (!ci->cmd_close || (access(mailbox_path(m), W_OK) != 0))
385 m->readonly = true;
386
387 if (setup_paths(m) != 0)
388 goto cmo_fail;
389 store_size(m);
390
391 if (!lock_realpath(m, false))
392 {
393 mutt_error(_("Unable to lock mailbox"));
394 goto cmo_fail;
395 }
396
397 if (!execute_command(m, ci->cmd_open, _("Decompressing %s")))
398 goto cmo_fail;
399
401
403 if (m->type == MUTT_UNKNOWN)
404 {
405 mutt_error(_("Can't identify the contents of the compressed file"));
406 goto cmo_fail;
407 }
408
409 ci->child_ops = mx_get_ops(m->type);
410 if (!ci->child_ops)
411 {
412 mutt_error(_("Can't find mailbox ops for mailbox type %d"), m->type);
413 goto cmo_fail;
414 }
415
416 m->account->type = m->type;
417 return ci->child_ops->mbox_open(m);
418
419cmo_fail:
420 /* remove the partial uncompressed file */
421 (void) remove(mailbox_path(m));
423 return MX_OPEN_ERROR;
424}
static struct CompressInfo * set_compress_info(struct Mailbox *m)
Find the compress hooks for a mailbox.
Definition compress.c:220
static void compress_info_free(struct Mailbox *m)
Frees the compress info members and structure.
Definition compress.c:250
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:271
static const char * mailbox_path(const struct Mailbox *m)
Get the Mailbox's path string.
Definition mailbox.h:217
@ 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:85
enum MailboxType type
Type of Mailboxes this Account contains.
Definition account.h:37
Private data for compress.
Definition lib.h:62
const struct Expando * cmd_open
open-hook command
Definition lib.h:65
const struct Expando * cmd_close
close-hook command
Definition lib.h:64
const struct MxOps * child_ops
callbacks of de-compressed file
Definition lib.h:67
enum MailboxType type
Mailbox type.
Definition mailbox.h:104
struct Account * account
Account that owns this Mailbox.
Definition mailbox.h:129
bool readonly
Don't allow changes to the mailbox.
Definition mailbox.h:118
enum MxOpenReturns(* mbox_open)(struct Mailbox *m)
Definition mxapi.h:143
Here is the call graph for this function:

◆ imap_mbox_open()

enum MxOpenReturns imap_mbox_open ( struct Mailbox * m)
static

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

Definition at line 2309 of file imap.c.

2310{
2311 if (!m->account || !m->mdata)
2312 return MX_OPEN_ERROR;
2313
2314 char buf[PATH_MAX] = { 0 };
2315 int count = 0;
2316
2318 struct ImapMboxData *mdata = imap_mdata_get(m);
2319 if (!adata || !mdata)
2320 return MX_OPEN_ERROR;
2321
2322 mutt_debug(LL_DEBUG3, "opening %s, stranding %p\n", m->pathbuf.data,
2323 (void *) adata->mailbox);
2324 adata->prev_mailbox = adata->mailbox;
2325 adata->mailbox = m;
2326
2327 /* clear mailbox status */
2328 adata->status = 0;
2329 m->rights = 0;
2330 mdata->new_mail_count = 0;
2331
2332 if (m->verbose)
2333 mutt_message(_("Selecting %s..."), mdata->name);
2334
2335 /* pipeline ACL test */
2336 if (adata->capabilities & IMAP_CAP_ACL)
2337 {
2338 snprintf(buf, sizeof(buf), "MYRIGHTS %s", mdata->munge_name);
2339 imap_exec(adata, buf, IMAP_CMD_QUEUE);
2340 }
2341 else
2342 {
2343 /* assume we have all rights if ACL is unavailable */
2346 }
2347
2348 /* pipeline the postponed count if possible */
2349 const char *const c_postponed = cs_subset_string(NeoMutt->sub, "postponed");
2350 struct Mailbox *m_postponed = mx_mbox_find2(c_postponed);
2351 struct ImapAccountData *postponed_adata = imap_adata_get(m_postponed);
2352 if (postponed_adata &&
2353 imap_account_match(&postponed_adata->conn->account, &adata->conn->account))
2354 {
2355 imap_mailbox_status(m_postponed, true);
2356 }
2357
2358 const bool c_imap_check_subscribed = cs_subset_bool(NeoMutt->sub, "imap_check_subscribed");
2359 if (c_imap_check_subscribed)
2360 imap_exec(adata, "LSUB \"\" \"*\"", IMAP_CMD_QUEUE);
2361
2362 if (imap_select_and_poll(m, &count) < 0)
2363 goto fail;
2364
2365 mx_alloc_memory(m, count);
2366
2367 m->msg_count = 0;
2368 m->msg_unread = 0;
2369 m->msg_flagged = 0;
2370 m->msg_new = 0;
2371 m->msg_deleted = 0;
2372 m->size = 0;
2373 m->vcount = 0;
2374
2375 if ((count > 0) && (imap_read_headers(m, 1, count, true) < 0))
2376 {
2377 mutt_error(_("Error opening mailbox"));
2378 goto fail;
2379 }
2380
2381 mutt_debug(LL_DEBUG2, "msg_count is %d\n", m->msg_count);
2382 return MX_OPEN_OK;
2383
2384fail:
2385 adata->mailbox = adata->prev_mailbox;
2386 adata->prev_mailbox = NULL;
2387 if (adata->state == IMAP_SELECTED)
2388 adata->state = IMAP_AUTHENTICATED;
2389 return MX_OPEN_ERROR;
2390}
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
Definition helpers.c:291
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition helpers.c:47
@ MUTT_ACL_WRITE
Write to a message (for flagging or linking threads).
Definition mailbox.h:71
@ MUTT_ACL_INSERT
Add/copy into the mailbox (used when editing a message).
Definition mailbox.h:66
@ MUTT_ACL_READ
Read the mailbox.
Definition mailbox.h:69
@ MUTT_ACL_POST
Post (submit messages to the server).
Definition mailbox.h:68
@ MUTT_ACL_CREATE
Create a mailbox.
Definition mailbox.h:62
@ MUTT_ACL_DELETE
Delete a message.
Definition mailbox.h:63
@ MUTT_ACL_SEEN
Change the 'seen' status of a message.
Definition mailbox.h:70
@ MUTT_ACL_LOOKUP
Lookup mailbox (visible to 'list').
Definition mailbox.h:67
#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:162
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:1423
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:1360
@ IMAP_AUTHENTICATED
Connection is authenticated.
Definition private.h:120
@ IMAP_SELECTED
Mailbox is selected.
Definition private.h:121
bool imap_account_match(const struct ConnAccount *a1, const struct ConnAccount *a2)
Compare two Accounts.
Definition util.c:1108
@ IMAP_CAP_ACL
RFC2086: IMAP4 ACL extension.
Definition private.h:138
@ IMAP_CMD_QUEUE
Queue a command, do not execute.
Definition private.h:84
int imap_mailbox_status(struct Mailbox *m, bool queue)
Refresh the number of total and new messages.
Definition imap.c:1397
static int imap_select_and_poll(struct Mailbox *m, int *countp)
Send SELECT and parse the untagged responses.
Definition imap.c:2112
@ LL_DEBUG3
Log at debug level 3.
Definition logging2.h:47
@ LL_DEBUG2
Log at debug level 2.
Definition logging2.h:46
#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:84
void * adata
Private data (for Mailbox backends).
Definition account.h:42
char * data
Pointer to data.
Definition buffer.h:38
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:81
ImapCapFlags capabilities
Capability flags.
Definition adata.h:56
struct Mailbox * mailbox
Current selected mailbox.
Definition adata.h:80
unsigned char status
ImapFlags, e.g. IMAP_FATAL.
Definition adata.h:46
struct Connection * conn
Connection to IMAP server.
Definition adata.h:41
IMAP-specific Mailbox data -.
Definition mdata.h:40
A mailbox.
Definition mailbox.h:81
int vcount
The number of virtual messages.
Definition mailbox.h:101
int msg_new
Number of new messages.
Definition mailbox.h:94
int msg_count
Total number of messages.
Definition mailbox.h:90
AclFlags rights
ACL bits, see AclFlags.
Definition mailbox.h:121
void * mdata
Driver specific data.
Definition mailbox.h:134
struct Buffer pathbuf
Path of the Mailbox.
Definition mailbox.h:82
int msg_deleted
Number of deleted messages.
Definition mailbox.h:95
off_t size
Size of the Mailbox.
Definition mailbox.h:86
int msg_flagged
Number of flagged messages.
Definition mailbox.h:92
bool verbose
Display status messages?
Definition mailbox.h:119
int msg_unread
Number of unread messages.
Definition mailbox.h:91
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 747 of file mailbox.c.

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

◆ mbox_mbox_open()

enum MxOpenReturns mbox_mbox_open ( struct Mailbox * m)
static

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

Definition at line 856 of file mbox.c.

857{
858 if (init_mailbox(m) != 0)
859 return MX_OPEN_ERROR;
860
862 if (!adata)
863 return MX_OPEN_ERROR;
864
865 adata->fp = m->readonly ? NULL : mbox_open_readwrite(m);
866 if (!adata->fp)
867 {
868 adata->fp = mbox_open_readonly(m);
869 }
870 if (!adata->fp)
871 {
872 mutt_perror("%s", mailbox_path(m));
873 return MX_OPEN_ERROR;
874 }
875
877 if (mbox_lock_mailbox(m, false, true) == -1)
878 {
880 return MX_OPEN_ERROR;
881 }
882
883 m->has_new = true;
885 if (m->type == MUTT_MBOX)
886 rc = mbox_parse_mailbox(m);
887 else if (m->type == MUTT_MMDF)
888 rc = mmdf_parse_mailbox(m);
889 else
890 rc = MX_OPEN_ERROR;
891
892 if (!mbox_has_new(m))
893 m->has_new = false;
894 clearerr(adata->fp); // Clear the EOF flag
895 mutt_file_touch_atime(fileno(adata->fp));
896
899 return rc;
900}
@ 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:356
static bool mbox_has_new(struct Mailbox *m)
Does the mailbox have new mail.
Definition mbox.c:754
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:830
static FILE * mbox_open_readonly(struct Mailbox *m)
Open an mbox read-only.
Definition mbox.c:845
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:83
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:87
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()

enum MxOpenReturns mh_mbox_open ( struct Mailbox * m)
static

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

Definition at line 821 of file mh.c.

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

◆ nntp_mbox_open()

enum MxOpenReturns nntp_mbox_open ( struct Mailbox * m)
static

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

Definition at line 2390 of file nntp.c.

2391{
2393 if (!m->account)
2394 return MX_OPEN_ERROR;
2395
2396 char buf[8192] = { 0 };
2397 char server[1024] = { 0 };
2398 char *group = NULL;
2399 int rc;
2400 struct HeaderCache *hc = NULL;
2401 anum_t first = 0;
2402 anum_t last = 0;
2403 anum_t count = 0;
2404
2405 struct Url *url = url_parse(mailbox_path(m));
2406 if (!url || !url->host || !url->path ||
2407 !((url->scheme == U_NNTP) || (url->scheme == U_NNTPS)))
2408 {
2409 url_free(&url);
2410 mutt_error(_("%s is an invalid newsgroup specification"), mailbox_path(m));
2411 return MX_OPEN_ERROR;
2412 }
2413
2414 group = url->path;
2415 if (group[0] == '/') /* Skip a leading '/' */
2416 group++;
2417
2418 url->path = strchr(url->path, '\0');
2419 url_tostring(url, server, sizeof(server), U_NONE);
2420
2422 struct NntpAccountData *adata = m->account->adata;
2423 if (!adata)
2424 adata = mod_data->current_news_srv;
2425 if (!adata)
2426 {
2427 adata = nntp_select_server(m, server, true);
2428 m->account->adata = adata;
2430 }
2431
2432 if (!adata)
2433 {
2434 url_free(&url);
2435 return MX_OPEN_ERROR;
2436 }
2437 mod_data->current_news_srv = adata;
2438
2439 m->msg_count = 0;
2440 m->msg_unread = 0;
2441 m->vcount = 0;
2442
2443 if (group[0] == '/')
2444 group++;
2445
2446 /* find news group data structure */
2448 if (!mdata)
2449 {
2451 mutt_error(_("Newsgroup %s not found on the server"), group);
2452 url_free(&url);
2453 return MX_OPEN_ERROR;
2454 }
2455
2456 m->rights &= ~MUTT_ACL_INSERT; // Clear the flag
2457 const bool c_save_unsubscribed = cs_subset_bool(NeoMutt->sub, "save_unsubscribed");
2458 if (!mdata->newsrc_ent && !mdata->subscribed && !c_save_unsubscribed)
2459 m->readonly = true;
2460
2461 /* select newsgroup */
2462 mutt_message(_("Selecting %s..."), group);
2463 url_free(&url);
2464 buf[0] = '\0';
2465 if (nntp_query(mdata, buf, sizeof(buf)) < 0)
2466 {
2468 return MX_OPEN_ERROR;
2469 }
2470
2471 /* newsgroup not found, remove it */
2472 if (mutt_str_startswith(buf, "411"))
2473 {
2474 mutt_error(_("Newsgroup %s has been removed from the server"), mdata->group);
2475 if (!mdata->deleted)
2476 {
2477 mdata->deleted = true;
2479 }
2480 if (mdata->newsrc_ent && !mdata->subscribed && !c_save_unsubscribed)
2481 {
2482 FREE(&mdata->newsrc_ent);
2483 mdata->newsrc_len = 0;
2486 }
2487 }
2488 else
2489 {
2490 /* parse newsgroup info */
2491 if (sscanf(buf, "211 " ANUM_FMT " " ANUM_FMT " " ANUM_FMT, &count, &first, &last) != 3)
2492 {
2494 mutt_error("GROUP: %s", buf);
2495 return MX_OPEN_ERROR;
2496 }
2497 mdata->first_message = first;
2498 mdata->last_message = last;
2499 mdata->deleted = false;
2500
2501 /* get description if empty */
2502 const bool c_nntp_load_description = cs_subset_bool(NeoMutt->sub, "nntp_load_description");
2503 if (c_nntp_load_description && !mdata->desc)
2504 {
2505 if (get_description(mdata, NULL, NULL) < 0)
2506 {
2508 return MX_OPEN_ERROR;
2509 }
2510 if (mdata->desc)
2512 }
2513 }
2514
2516 m->mdata = mdata;
2517 // Every known newsgroup has an mdata which is stored in adata->groups_list.
2518 // Currently we don't let the Mailbox free the mdata.
2519 // m->mdata_free = nntp_mdata_free;
2520 if (!mdata->bcache && (mdata->newsrc_ent || mdata->subscribed || c_save_unsubscribed))
2521 mdata->bcache = mutt_bcache_open(&adata->conn->account, mdata->group);
2522
2523 /* strip off extra articles if adding context is greater than $nntp_context */
2524 first = mdata->first_message;
2525 const long c_nntp_context = cs_subset_long(NeoMutt->sub, "nntp_context");
2526 if (c_nntp_context && ((mdata->last_message - first + 1) > c_nntp_context))
2527 first = mdata->last_message - c_nntp_context + 1;
2528 mdata->last_loaded = first ? first - 1 : 0;
2529 count = mdata->first_message;
2530 mdata->first_message = first;
2532 mdata->first_message = count;
2533#ifdef USE_HCACHE
2534 hc = nntp_hcache_open(mdata);
2536#endif
2537 if (!hc)
2538 m->rights &= ~(MUTT_ACL_WRITE | MUTT_ACL_DELETE); // Clear the flags
2539
2541 rc = nntp_fetch_headers(m, hc, first, mdata->last_message, false);
2542#ifdef USE_HCACHE
2543 hcache_close(&hc);
2544#endif
2545 if (rc < 0)
2546 return MX_OPEN_ERROR;
2547 mdata->last_loaded = mdata->last_message;
2548 adata->newsrc_modified = false;
2549 return MX_OPEN_OK;
2550}
struct BodyCache * mutt_bcache_open(struct ConnAccount *account, const char *mailbox)
Open an Email-Body Cache.
Definition bcache.c:162
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:365
void hcache_close(struct HeaderCache **ptr)
Multiplexor for StoreOps::close.
Definition hcache.c:564
void exec_account_hook(const char *url)
Perform an account hook.
Definition exec.c:328
#define FREE(x)
Free memory and set the pointer to NULL.
Definition memory.h:92
@ MODULE_ID_NNTP
ModuleNntp, Nntp
Definition module_api.h:83
time_t mutt_date_now(void)
Return the number of seconds since the Unix epoch.
Definition date.c:459
size_t mutt_str_startswith(const char *str, const char *prefix)
Check whether a string starts with a prefix.
Definition string.c:234
void * neomutt_get_module_data(struct NeoMutt *n, enum ModuleId id)
Get the private data for a Module.
Definition neomutt.c:666
struct HeaderCache * nntp_hcache_open(struct NntpMboxData *mdata)
Open newsgroup hcache.
Definition newsrc.c:712
void nntp_delete_group_cache(struct NntpMboxData *mdata)
Remove hcache and bcache of newsgroup.
Definition newsrc.c:814
void nntp_hcache_update(struct NntpMboxData *mdata, struct HeaderCache *hc)
Remove stale cached headers.
Definition newsrc.c:736
int nntp_active_save_cache(struct NntpAccountData *adata)
Save list of all newsgroups to cache.
Definition newsrc.c:651
void nntp_bcache_update(struct NntpMboxData *mdata)
Remove stale cached messages.
Definition newsrc.c:805
void nntp_newsrc_close(struct NntpAccountData *adata)
Unlock and close .newsrc file.
Definition newsrc.c:121
int nntp_newsrc_update(struct NntpAccountData *adata)
Update .newsrc file.
Definition newsrc.c:446
#define ANUM_FMT
Definition lib.h:64
struct NntpAccountData * nntp_select_server(struct Mailbox *m, const char *server, bool leave_lock)
Open a connection to an NNTP server.
Definition newsrc.c:957
#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:733
static int get_description(struct NntpMboxData *mdata, const char *wildmat, const char *msg)
Fetch newsgroups descriptions.
Definition nntp.c:939
static int nntp_fetch_headers(struct Mailbox *m, void *hc, anum_t first, anum_t last, bool restore)
Fetch headers.
Definition nntp.c:1210
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:83
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
Nntp private Module data.
Definition module_data.h:30
struct NntpAccountData * current_news_srv
Current NNTP news server.
Definition module_data.h:32
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:247
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:431
@ U_NNTPS
Url is nntps://.
Definition url.h:42
@ U_NNTP
Url is nntp://.
Definition url.h:41
#define U_NONE
No flags are set for URL parsing.
Definition url.h:49
Here is the call graph for this function:

◆ nm_mbox_open()

enum MxOpenReturns nm_mbox_open ( struct Mailbox * m)
static

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

Definition at line 2055 of file notmuch.c.

2056{
2057 if (init_mailbox(m) != 0)
2058 return MX_OPEN_ERROR;
2059
2060 struct NmMboxData *mdata = nm_mdata_get(m);
2061 if (!mdata)
2062 return MX_OPEN_ERROR;
2063
2064 mutt_debug(LL_DEBUG1, "nm: reading messages...[current count=%d]\n", m->msg_count);
2065
2066 progress_setup(m);
2067 enum MxOpenReturns rc = MX_OPEN_ERROR;
2068
2069 notmuch_query_t *q = get_query(m, false);
2070 if (q)
2071 {
2072 rc = MX_OPEN_OK;
2073 switch (mdata->query_type)
2074 {
2075 case NM_QUERY_TYPE_UNKNOWN: // UNKNOWN should never occur, but MESGS is default
2077 if (!read_mesgs_query(m, q, false))
2078 rc = MX_OPEN_ABORT;
2079 break;
2081 if (!read_threads_query(m, q, false, get_limit(mdata)))
2082 rc = MX_OPEN_ABORT;
2083 break;
2084 }
2085 notmuch_query_destroy(q);
2086 }
2087
2088 nm_db_release(m);
2089
2090 mdata->mtime.tv_sec = mutt_date_now();
2091 mdata->mtime.tv_nsec = 0;
2092
2093 mdata->oldmsgcount = 0;
2094
2095 mutt_debug(LL_DEBUG1, "nm: reading messages... done [rc=%d, count=%d]\n", rc, m->msg_count);
2096 progress_free(&mdata->progress);
2097 return rc;
2098}
@ LL_DEBUG1
Log at debug level 1.
Definition logging2.h:45
@ MX_OPEN_ABORT
Open was aborted.
Definition mxapi.h:86
int nm_db_release(struct Mailbox *m)
Close the Notmuch database.
Definition db.c:245
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:36
@ NM_QUERY_TYPE_THREADS
Whole threads.
Definition query.h:38
@ NM_QUERY_TYPE_MESSAGES
Default: Messages only.
Definition query.h:37
Notmuch-specific Mailbox data -.
Definition mdata.h:35
Here is the call graph for this function:

◆ pop_mbox_open()

enum MxOpenReturns pop_mbox_open ( struct Mailbox * m)
static

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

Fetch only headers

Definition at line 762 of file pop.c.

763{
764 if (!m->account)
765 return MX_OPEN_ERROR;
766
767 char buf[PATH_MAX] = { 0 };
768 struct ConnAccount cac = { { 0 } };
769 struct Url url = { 0 };
770
771 if (pop_parse_path(mailbox_path(m), &cac) != 0)
772 {
773 mutt_error(_("%s is an invalid POP path"), mailbox_path(m));
774 return MX_OPEN_ERROR;
775 }
776
777 account_to_url(&cac, &url);
778 url.path = NULL;
779 url_tostring(&url, buf, sizeof(buf), U_NONE);
780
781 buf_strcpy(&m->pathbuf, buf);
783
784 struct PopAccountData *adata = m->account->adata;
785 if (!adata)
786 {
788 m->account->adata = adata;
790 }
791
792 struct Connection *conn = adata->conn;
793 if (!conn)
794 {
795 adata->conn = mutt_conn_new(&cac);
796 conn = adata->conn;
797 if (!conn)
798 return MX_OPEN_ERROR;
799 }
800
801 if (conn->fd < 0)
803
804 if (pop_open_connection(adata) < 0)
805 return MX_OPEN_ERROR;
806
807 adata->bcache = mutt_bcache_open(&cac, NULL);
808
809 /* init (hard-coded) ACL rights */
811#ifdef USE_HCACHE
812 /* flags are managed using header cache, so it only makes sense to
813 * enable them in that case */
815#endif
816
817 while (true)
818 {
819 if (pop_reconnect(m) < 0)
820 return MX_OPEN_ERROR;
821
822 m->size = adata->size;
823
824 mutt_message(_("Fetching list of messages..."));
825
826 const int rc = pop_fetch_headers(m);
827
828 if (rc >= 0)
829 return MX_OPEN_OK;
830
831 if (rc < -1)
832 return MX_OPEN_ERROR;
833 }
834}
size_t buf_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition buffer.c:401
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:317
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:610
static int pop_fetch_headers(struct Mailbox *m)
Read headers.
Definition pop.c:343
Login details for a remote server.
Definition connaccount.h:59
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: