NeoMutt  2023-03-22-27-g3cb248
Teaching an old dog new tricks
DOXYGEN
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() -. More...
 
static enum MxOpenReturns imap_mbox_open (struct Mailbox *m)
 Open a mailbox - Implements MxOps::mbox_open() -. More...
 
static enum MxOpenReturns maildir_mbox_open (struct Mailbox *m)
 Open a Mailbox - Implements MxOps::mbox_open() -. More...
 
static enum MxOpenReturns mh_mbox_open (struct Mailbox *m)
 Open a Mailbox - Implements MxOps::mbox_open() -. More...
 
static enum MxOpenReturns mbox_mbox_open (struct Mailbox *m)
 Open a Mailbox - Implements MxOps::mbox_open() -. More...
 
static enum MxOpenReturns nntp_mbox_open (struct Mailbox *m)
 Open a Mailbox - Implements MxOps::mbox_open() -. More...
 
static enum MxOpenReturns nm_mbox_open (struct Mailbox *m)
 Open a Mailbox - Implements MxOps::mbox_open() -. More...
 
static enum MxOpenReturns pop_mbox_open (struct Mailbox *m)
 Open a Mailbox - Implements MxOps::mbox_open() -. More...
 

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

448{
449 struct CompressInfo *ci = set_compress_info(m);
450 if (!ci)
451 return MX_OPEN_ERROR;
452
453 /* If there's no close-hook, or the file isn't writable */
454 if (!ci->cmd_close || (access(mailbox_path(m), W_OK) != 0))
455 m->readonly = true;
456
457 if (setup_paths(m) != 0)
458 goto cmo_fail;
459 store_size(m);
460
461 if (!lock_realpath(m, false))
462 {
463 mutt_error(_("Unable to lock mailbox"));
464 goto cmo_fail;
465 }
466
467 int rc = execute_command(m, ci->cmd_open, _("Decompressing %s"));
468 if (rc == 0)
469 goto cmo_fail;
470
472
474 if (m->type == MUTT_UNKNOWN)
475 {
476 mutt_error(_("Can't identify the contents of the compressed file"));
477 goto cmo_fail;
478 }
479
480 ci->child_ops = mx_get_ops(m->type);
481 if (!ci->child_ops)
482 {
483 mutt_error(_("Can't find mailbox ops for mailbox type %d"), m->type);
484 goto cmo_fail;
485 }
486
487 m->account->type = m->type;
488 return ci->child_ops->mbox_open(m);
489
490cmo_fail:
491 /* remove the partial uncompressed file */
492 (void) remove(mailbox_path(m));
494 return MX_OPEN_ERROR;
495}
static struct CompressInfo * set_compress_info(struct Mailbox *m)
Find the compress hooks for a mailbox.
Definition: compress.c:201
static void compress_info_free(struct Mailbox *m)
Frees the compress info members and structure.
Definition: compress.c:231
static int setup_paths(struct Mailbox *m)
Set the mailbox paths.
Definition: compress.c:155
static int execute_command(struct Mailbox *m, const char *command, const char *progress)
Run a system command.
Definition: compress.c:326
static void store_size(const struct Mailbox *m)
Save the size of the compressed file.
Definition: compress.c:183
static bool lock_realpath(struct Mailbox *m, bool excl)
Try to lock the Mailbox.realpath.
Definition: compress.c:88
static void unlock_realpath(struct Mailbox *m)
Unlock the mailbox->realpath.
Definition: compress.c:129
#define mutt_error(...)
Definition: logging.h:87
static const char * mailbox_path(const struct Mailbox *m)
Get the Mailbox's path string.
Definition: mailbox.h:209
@ MUTT_UNKNOWN
Mailbox wasn't recognised.
Definition: mailbox.h:44
#define _(a)
Definition: message.h:28
const struct MxOps * mx_get_ops(enum MailboxType type)
Get mailbox operations.
Definition: mx.c:140
enum MailboxType mx_path_probe(const char *path)
Find a mailbox that understands a path.
Definition: mx.c:1334
@ MX_OPEN_ERROR
Open failed with an error.
Definition: mxapi.h:99
enum MailboxType type
Type of Mailboxes this Account contains.
Definition: account.h:38
Private data for compress.
Definition: lib.h:47
const char * cmd_open
open-hook command
Definition: lib.h:50
const struct MxOps * child_ops
callbacks of de-compressed file
Definition: lib.h:52
const char * cmd_close
close-hook command
Definition: lib.h:49
enum MailboxType type
Mailbox type.
Definition: mailbox.h:102
struct Account * account
Account that owns this Mailbox.
Definition: mailbox.h:127
bool readonly
Don't allow changes to the mailbox.
Definition: mailbox.h:115
enum MxOpenReturns(* mbox_open)(struct Mailbox *m)
Definition: mxapi.h:157
+ 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 1951 of file imap.c.

1952{
1953 if (!m->account || !m->mdata)
1954 return MX_OPEN_ERROR;
1955
1956 char buf[PATH_MAX] = { 0 };
1957 int count = 0;
1958 int rc;
1959
1961 struct ImapMboxData *mdata = imap_mdata_get(m);
1962
1963 mutt_debug(LL_DEBUG3, "opening %s, saving %s\n", m->pathbuf.data,
1964 (adata->mailbox ? adata->mailbox->pathbuf.data : "(none)"));
1965 adata->prev_mailbox = adata->mailbox;
1966 adata->mailbox = m;
1967
1968 /* clear mailbox status */
1969 adata->status = 0;
1970 m->rights = 0;
1971 mdata->new_mail_count = 0;
1972
1973 if (m->verbose)
1974 mutt_message(_("Selecting %s..."), mdata->name);
1975
1976 /* pipeline ACL test */
1977 if (adata->capabilities & IMAP_CAP_ACL)
1978 {
1979 snprintf(buf, sizeof(buf), "MYRIGHTS %s", mdata->munge_name);
1980 imap_exec(adata, buf, IMAP_CMD_QUEUE);
1981 }
1982 /* assume we have all rights if ACL is unavailable */
1983 else
1984 {
1987 }
1988
1989 /* pipeline the postponed count if possible */
1990 const char *const c_postponed = cs_subset_string(NeoMutt->sub, "postponed");
1991 struct Mailbox *m_postponed = mx_mbox_find2(c_postponed);
1992 struct ImapAccountData *postponed_adata = imap_adata_get(m_postponed);
1993 if (postponed_adata &&
1994 imap_account_match(&postponed_adata->conn->account, &adata->conn->account))
1995 {
1996 imap_mailbox_status(m_postponed, true);
1997 }
1998
1999 const bool c_imap_check_subscribed = cs_subset_bool(NeoMutt->sub, "imap_check_subscribed");
2000 if (c_imap_check_subscribed)
2001 imap_exec(adata, "LSUB \"\" \"*\"", IMAP_CMD_QUEUE);
2002
2004
2005 do
2006 {
2007 char *pc = NULL;
2008
2009 rc = imap_cmd_step(adata);
2010 if (rc != IMAP_RES_CONTINUE)
2011 break;
2012
2013 pc = adata->buf + 2;
2014
2015 /* Obtain list of available flags here, may be overridden by a
2016 * PERMANENTFLAGS tag in the OK response */
2017 if (mutt_istr_startswith(pc, "FLAGS"))
2018 {
2019 /* don't override PERMANENTFLAGS */
2020 if (STAILQ_EMPTY(&mdata->flags))
2021 {
2022 mutt_debug(LL_DEBUG3, "Getting mailbox FLAGS\n");
2023 pc = get_flags(&mdata->flags, pc);
2024 if (!pc)
2025 goto fail;
2026 }
2027 }
2028 /* PERMANENTFLAGS are massaged to look like FLAGS, then override FLAGS */
2029 else if (mutt_istr_startswith(pc, "OK [PERMANENTFLAGS"))
2030 {
2031 mutt_debug(LL_DEBUG3, "Getting mailbox PERMANENTFLAGS\n");
2032 /* safe to call on NULL */
2033 mutt_list_free(&mdata->flags);
2034 /* skip "OK [PERMANENT" so syntax is the same as FLAGS */
2035 pc += 13;
2036 pc = get_flags(&(mdata->flags), pc);
2037 if (!pc)
2038 goto fail;
2039 }
2040 /* save UIDVALIDITY for the header cache */
2041 else if (mutt_istr_startswith(pc, "OK [UIDVALIDITY"))
2042 {
2043 mutt_debug(LL_DEBUG3, "Getting mailbox UIDVALIDITY\n");
2044 pc += 3;
2045 pc = imap_next_word(pc);
2046 if (!mutt_str_atoui(pc, &mdata->uidvalidity))
2047 goto fail;
2048 }
2049 else if (mutt_istr_startswith(pc, "OK [UIDNEXT"))
2050 {
2051 mutt_debug(LL_DEBUG3, "Getting mailbox UIDNEXT\n");
2052 pc += 3;
2053 pc = imap_next_word(pc);
2054 if (!mutt_str_atoui(pc, &mdata->uid_next))
2055 goto fail;
2056 }
2057 else if (mutt_istr_startswith(pc, "OK [HIGHESTMODSEQ"))
2058 {
2059 mutt_debug(LL_DEBUG3, "Getting mailbox HIGHESTMODSEQ\n");
2060 pc += 3;
2061 pc = imap_next_word(pc);
2062 if (!mutt_str_atoull(pc, &mdata->modseq))
2063 goto fail;
2064 }
2065 else if (mutt_istr_startswith(pc, "OK [NOMODSEQ"))
2066 {
2067 mutt_debug(LL_DEBUG3, "Mailbox has NOMODSEQ set\n");
2068 mdata->modseq = 0;
2069 }
2070 else
2071 {
2072 pc = imap_next_word(pc);
2073 if (mutt_istr_startswith(pc, "EXISTS"))
2074 {
2075 count = mdata->new_mail_count;
2076 mdata->new_mail_count = 0;
2077 }
2078 }
2079 } while (rc == IMAP_RES_CONTINUE);
2080
2081 if (rc == IMAP_RES_NO)
2082 {
2083 char *s = imap_next_word(adata->buf); /* skip seq */
2084 s = imap_next_word(s); /* Skip response */
2085 mutt_error("%s", s);
2086 goto fail;
2087 }
2088
2089 if (rc != IMAP_RES_OK)
2090 goto fail;
2091
2092 /* check for READ-ONLY notification */
2093 if (mutt_istr_startswith(imap_get_qualifier(adata->buf), "[READ-ONLY]") &&
2094 !(adata->capabilities & IMAP_CAP_ACL))
2095 {
2096 mutt_debug(LL_DEBUG2, "Mailbox is read-only\n");
2097 m->readonly = true;
2098 }
2099
2100 /* dump the mailbox flags we've found */
2101 const short c_debug_level = cs_subset_number(NeoMutt->sub, "debug_level");
2102 if (c_debug_level > LL_DEBUG2)
2103 {
2104 if (STAILQ_EMPTY(&mdata->flags))
2105 {
2106 mutt_debug(LL_DEBUG3, "No folder flags found\n");
2107 }
2108 else
2109 {
2110 struct ListNode *np = NULL;
2111 struct Buffer flag_buffer;
2112 mutt_buffer_init(&flag_buffer);
2113 mutt_buffer_printf(&flag_buffer, "Mailbox flags: ");
2114 STAILQ_FOREACH(np, &mdata->flags, entries)
2115 {
2116 mutt_buffer_add_printf(&flag_buffer, "[%s] ", np->data);
2117 }
2118 mutt_debug(LL_DEBUG3, "%s\n", flag_buffer.data);
2119 FREE(&flag_buffer.data);
2120 }
2121 }
2122
2123 if (!((m->rights & MUTT_ACL_DELETE) || (m->rights & MUTT_ACL_SEEN) ||
2124 (m->rights & MUTT_ACL_WRITE) || (m->rights & MUTT_ACL_INSERT)))
2125 {
2126 m->readonly = true;
2127 }
2128
2129 while (m->email_max < count)
2130 mx_alloc_memory(m);
2131
2132 m->msg_count = 0;
2133 m->msg_unread = 0;
2134 m->msg_flagged = 0;
2135 m->msg_new = 0;
2136 m->msg_deleted = 0;
2137 m->size = 0;
2138 m->vcount = 0;
2139
2140 if (count && (imap_read_headers(m, 1, count, true) < 0))
2141 {
2142 mutt_error(_("Error opening mailbox"));
2143 goto fail;
2144 }
2145
2146 mutt_debug(LL_DEBUG2, "msg_count is %d\n", m->msg_count);
2147 return MX_OPEN_OK;
2148
2149fail:
2150 if (adata->state == IMAP_SELECTED)
2151 adata->state = IMAP_AUTHENTICATED;
2152 return MX_OPEN_ERROR;
2153}
const char * mutt_str_atoull(const char *str, unsigned long long *dst)
Convert ASCII string to an unsigned long long.
Definition: atoi.c:275
const char * mutt_str_atoui(const char *str, unsigned int *dst)
Convert ASCII string to an unsigned integer.
Definition: atoi.c:203
struct Buffer * mutt_buffer_init(struct Buffer *buf)
Initialise a new Buffer.
Definition: buffer.c:52
int mutt_buffer_add_printf(struct Buffer *buf, const char *fmt,...)
Format a string appending a Buffer.
Definition: buffer.c:211
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:168
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
Definition: helpers.c:317
short cs_subset_number(const struct ConfigSubset *sub, const char *name)
Get a number config item by name.
Definition: helpers.c:169
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:73
#define mutt_message(...)
Definition: logging.h:86
#define mutt_debug(LEVEL,...)
Definition: logging.h:84
struct ImapAccountData * imap_adata_get(struct Mailbox *m)
Get the Account data for this mailbox.
Definition: adata.c:89
int imap_cmd_step(struct ImapAccountData *adata)
Reads server responses from an IMAP command.
Definition: command.c:1085
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:1260
struct ImapMboxData * imap_mdata_get(struct Mailbox *m)
Get the Mailbox data for this mailbox.
Definition: mdata.c:60
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:1330
@ IMAP_AUTHENTICATED
Connection is authenticated.
Definition: private.h:109
@ IMAP_SELECTED
Mailbox is selected.
Definition: private.h:110
#define IMAP_RES_OK
<tag> OK ...
Definition: private.h:56
#define IMAP_CAP_ACL
RFC2086: IMAP4 ACL extension.
Definition: private.h:126
#define IMAP_RES_NO
<tag> NO ...
Definition: private.h:54
bool imap_account_match(const struct ConnAccount *a1, const struct ConnAccount *a2)
Compare two Accounts.
Definition: util.c:1040
#define IMAP_RES_CONTINUE
* ...
Definition: private.h:57
char * imap_next_word(char *s)
Find where the next IMAP word begins.
Definition: util.c:785
#define IMAP_CMD_QUEUE
Queue a command, do not execute.
Definition: private.h:75
char * imap_get_qualifier(char *buf)
Get the qualifier from a tagged response.
Definition: util.c:768
int imap_mailbox_status(struct Mailbox *m, bool queue)
Refresh the number of total and new messages.
Definition: imap.c:1284
static char * get_flags(struct ListHead *hflags, char *s)
Make a simple list out of a FLAGS response.
Definition: imap.c:123
static void imap_mbox_select(struct Mailbox *m)
Select a Mailbox.
Definition: imap.c:1828
void mutt_list_free(struct ListHead *h)
Free a List AND its strings.
Definition: list.c:122
@ LL_DEBUG3
Log at debug level 3.
Definition: logging.h:42
@ LL_DEBUG2
Log at debug level 2.
Definition: logging.h:41
#define MUTT_ACL_CREATE
Create a mailbox.
Definition: mailbox.h:62
#define MUTT_ACL_POST
Post (submit messages to the server)
Definition: mailbox.h:68
#define MUTT_ACL_LOOKUP
Lookup mailbox (visible to 'list')
Definition: mailbox.h:67
#define MUTT_ACL_INSERT
Add/copy into the mailbox (used when editing a message)
Definition: mailbox.h:66
#define MUTT_ACL_DELETE
Delete a message.
Definition: mailbox.h:63
#define MUTT_ACL_WRITE
Write to a message (for flagging or linking threads)
Definition: mailbox.h:71
#define MUTT_ACL_SEEN
Change the 'seen' status of a message.
Definition: mailbox.h:70
#define MUTT_ACL_READ
Read the mailbox.
Definition: mailbox.h:69
#define FREE(x)
Definition: memory.h:43
size_t mutt_istr_startswith(const char *str, const char *prefix)
Check whether a string starts with a prefix, ignoring case.
Definition: string.c:239
#define PATH_MAX
Definition: mutt.h:41
struct Mailbox * mx_mbox_find2(const char *path)
Find a Mailbox on an Account.
Definition: mx.c:1656
void mx_alloc_memory(struct Mailbox *m)
Create storage for the emails.
Definition: mx.c:1226
@ MX_OPEN_OK
Open succeeded.
Definition: mxapi.h:98
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:352
#define STAILQ_EMPTY(head)
Definition: queue.h:348
void * adata
Private data (for Mailbox backends)
Definition: account.h:43
String manipulation buffer.
Definition: buffer.h:34
char * data
Pointer to data.
Definition: buffer.h:35
struct ConnAccount account
Account details: username, password, etc.
Definition: connection.h:50
IMAP-specific Account data -.
Definition: adata.h:40
struct Mailbox * prev_mailbox
Previously selected mailbox.
Definition: adata.h:77
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:76
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:39
unsigned int uid_next
Definition: mdata.h:51
struct ListHead flags
Definition: mdata.h:49
unsigned int new_mail_count
Set when EXISTS notifies of new mail.
Definition: mdata.h:46
unsigned long long modseq
Definition: mdata.h:52
uint32_t uidvalidity
Definition: mdata.h:50
A List node for strings.
Definition: list.h:35
char * data
String.
Definition: list.h:36
A mailbox.
Definition: mailbox.h:79
int vcount
The number of virtual messages.
Definition: mailbox.h:99
int msg_new
Number of new messages.
Definition: mailbox.h:92
int msg_count
Total number of messages.
Definition: mailbox.h:88
AclFlags rights
ACL bits, see AclFlags.
Definition: mailbox.h:117
int email_max
Number of pointers in emails.
Definition: mailbox.h:97
void * mdata
Driver specific data.
Definition: mailbox.h:132
struct Buffer pathbuf
Path of the Mailbox.
Definition: mailbox.h:80
int msg_deleted
Number of deleted messages.
Definition: mailbox.h:93
off_t size
Size of the Mailbox.
Definition: mailbox.h:84
int msg_flagged
Number of flagged messages.
Definition: mailbox.h:90
bool verbose
Display status messages?
Definition: mailbox.h:114
int msg_unread
Number of unread messages.
Definition: mailbox.h:89
Container for Accounts, Notifications.
Definition: neomutt.h:37
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:39
+ Here is the call graph for this function:

◆ maildir_mbox_open()

static enum MxOpenReturns maildir_mbox_open ( struct Mailbox m)
static

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

Definition at line 1097 of file maildir.c.

1098{
1099 /* maildir looks sort of like MH, except that there are two subdirectories
1100 * of the main folder path from which to read messages */
1101 if ((maildir_read_dir(m, "new") == -1) || (maildir_read_dir(m, "cur") == -1))
1102 return MX_OPEN_ERROR;
1103
1104 return MX_OPEN_OK;
1105}
static int maildir_read_dir(struct Mailbox *m, const char *subdir)
Read a Maildir style mailbox.
Definition: maildir.c:674
+ Here is the call 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 852 of file mh.c.

853{
855}
static bool mh_read_dir(struct Mailbox *m)
Read an MH mailbox.
Definition: mh.c:695
+ 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 933 of file mbox.c.

934{
935 if (init_mailbox(m) != 0)
936 return MX_OPEN_ERROR;
937
939 if (!adata)
940 return MX_OPEN_ERROR;
941
942 adata->fp = m->readonly ? NULL : mbox_open_readwrite(m);
943 if (!adata->fp)
944 {
945 adata->fp = mbox_open_readonly(m);
946 }
947 if (!adata->fp)
948 {
950 return MX_OPEN_ERROR;
951 }
952
954 if (mbox_lock_mailbox(m, false, true) == -1)
955 {
957 return MX_OPEN_ERROR;
958 }
959
960 m->has_new = true;
962 if (m->type == MUTT_MBOX)
963 rc = mbox_parse_mailbox(m);
964 else if (m->type == MUTT_MMDF)
965 rc = mmdf_parse_mailbox(m);
966 else
967 rc = MX_OPEN_ERROR;
968
969 if (!mbox_has_new(m))
970 m->has_new = false;
971 clearerr(adata->fp); // Clear the EOF flag
972 mutt_file_touch_atime(fileno(adata->fp));
973
976 return rc;
977}
void mutt_file_touch_atime(int fd)
Set the access time to current time.
Definition: file.c:1069
#define mutt_perror(...)
Definition: logging.h:88
@ MUTT_MMDF
'mmdf' Mailbox type
Definition: mailbox.h:46
@ MUTT_MBOX
'mbox' Mailbox type
Definition: mailbox.h:45
static enum MxOpenReturns mbox_parse_mailbox(struct Mailbox *m)
Read a mailbox from disk.
Definition: mbox.c:349
static bool mbox_has_new(struct Mailbox *m)
Does the mailbox have new mail.
Definition: mbox.c:717
static int mbox_lock_mailbox(struct Mailbox *m, bool excl, bool retry)
Lock a mailbox.
Definition: mbox.c:134
static struct MboxAccountData * mbox_adata_get(struct Mailbox *m)
Get the private data associated with a Mailbox.
Definition: mbox.c:119
static int init_mailbox(struct Mailbox *m)
Add Mbox data to the Mailbox.
Definition: mbox.c:100
static FILE * mbox_open_readwrite(struct Mailbox *m)
Open an mbox read-write.
Definition: mbox.c:907
static FILE * mbox_open_readonly(struct Mailbox *m)
Open an mbox read-only.
Definition: mbox.c:922
static void mbox_unlock_mailbox(struct Mailbox *m)
Unlock a mailbox.
Definition: mbox.c:158
static enum MxOpenReturns mmdf_parse_mailbox(struct Mailbox *m)
Read a mailbox in MMDF format.
Definition: mbox.c:178
MxOpenReturns
Return values for mbox_open()
Definition: mxapi.h:97
void mutt_sig_block(void)
Block signals during critical operations.
Definition: signal.c:150
void mutt_sig_unblock(void)
Restore previously blocked signals.
Definition: signal.c:168
bool has_new
Mailbox has new mail.
Definition: mailbox.h:85
Mbox-specific Account data -.
Definition: lib.h:49
+ Here is the call graph for this function:
+ Here is the caller 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 2328 of file nntp.c.

2329{
2330 if (!m->account)
2331 return MX_OPEN_ERROR;
2332
2333 char buf[8192] = { 0 };
2334 char server[1024] = { 0 };
2335 char *group = NULL;
2336 int rc;
2337 void *hc = NULL;
2338 anum_t first, last, count = 0;
2339
2340 struct Url *url = url_parse(mailbox_path(m));
2341 if (!url || !url->host || !url->path ||
2342 !((url->scheme == U_NNTP) || (url->scheme == U_NNTPS)))
2343 {
2344 url_free(&url);
2345 mutt_error(_("%s is an invalid newsgroup specification"), mailbox_path(m));
2346 return MX_OPEN_ERROR;
2347 }
2348
2349 group = url->path;
2350 if (group[0] == '/') /* Skip a leading '/' */
2351 group++;
2352
2353 url->path = strchr(url->path, '\0');
2354 url_tostring(url, server, sizeof(server), U_NO_FLAGS);
2355
2357 struct NntpAccountData *adata = m->account->adata;
2358 if (!adata)
2359 {
2360 adata = nntp_select_server(m, server, true);
2361 m->account->adata = adata;
2363 }
2364
2365 if (!adata)
2366 {
2367 url_free(&url);
2368 return MX_OPEN_ERROR;
2369 }
2371
2372 m->msg_count = 0;
2373 m->msg_unread = 0;
2374 m->vcount = 0;
2375
2376 if (group[0] == '/')
2377 group++;
2378
2379 /* find news group data structure */
2381 if (!mdata)
2382 {
2384 mutt_error(_("Newsgroup %s not found on the server"), group);
2385 url_free(&url);
2386 return MX_OPEN_ERROR;
2387 }
2388
2389 m->rights &= ~MUTT_ACL_INSERT; // Clear the flag
2390 const bool c_save_unsubscribed = cs_subset_bool(NeoMutt->sub, "save_unsubscribed");
2391 if (!mdata->newsrc_ent && !mdata->subscribed && !c_save_unsubscribed)
2392 m->readonly = true;
2393
2394 /* select newsgroup */
2395 mutt_message(_("Selecting %s..."), group);
2396 url_free(&url);
2397 buf[0] = '\0';
2398 if (nntp_query(mdata, buf, sizeof(buf)) < 0)
2399 {
2401 return MX_OPEN_ERROR;
2402 }
2403
2404 /* newsgroup not found, remove it */
2405 if (mutt_str_startswith(buf, "411"))
2406 {
2407 mutt_error(_("Newsgroup %s has been removed from the server"), mdata->group);
2408 if (!mdata->deleted)
2409 {
2410 mdata->deleted = true;
2412 }
2413 if (mdata->newsrc_ent && !mdata->subscribed && !c_save_unsubscribed)
2414 {
2415 FREE(&mdata->newsrc_ent);
2416 mdata->newsrc_len = 0;
2419 }
2420 }
2421
2422 /* parse newsgroup info */
2423 else
2424 {
2425 if (sscanf(buf, "211 " ANUM " " ANUM " " ANUM, &count, &first, &last) != 3)
2426 {
2428 mutt_error("GROUP: %s", buf);
2429 return MX_OPEN_ERROR;
2430 }
2431 mdata->first_message = first;
2432 mdata->last_message = last;
2433 mdata->deleted = false;
2434
2435 /* get description if empty */
2436 const bool c_nntp_load_description = cs_subset_bool(NeoMutt->sub, "nntp_load_description");
2437 if (c_nntp_load_description && !mdata->desc)
2438 {
2439 if (get_description(mdata, NULL, NULL) < 0)
2440 {
2442 return MX_OPEN_ERROR;
2443 }
2444 if (mdata->desc)
2446 }
2447 }
2448
2450 m->mdata = mdata;
2451 // Every known newsgroup has an mdata which is stored in adata->groups_list.
2452 // Currently we don't let the Mailbox free the mdata.
2453 // m->mdata_free = nntp_mdata_free;
2454 if (!mdata->bcache && (mdata->newsrc_ent || mdata->subscribed || c_save_unsubscribed))
2455 mdata->bcache = mutt_bcache_open(&adata->conn->account, mdata->group);
2456
2457 /* strip off extra articles if adding context is greater than $nntp_context */
2458 first = mdata->first_message;
2459 const long c_nntp_context = cs_subset_long(NeoMutt->sub, "nntp_context");
2460 if (c_nntp_context && (mdata->last_message - first + 1 > c_nntp_context))
2461 first = mdata->last_message - c_nntp_context + 1;
2462 mdata->last_loaded = first ? first - 1 : 0;
2463 count = mdata->first_message;
2464 mdata->first_message = first;
2466 mdata->first_message = count;
2467#ifdef USE_HCACHE
2468 hc = nntp_hcache_open(mdata);
2470#endif
2471 if (!hc)
2472 m->rights &= ~(MUTT_ACL_WRITE | MUTT_ACL_DELETE); // Clear the flags
2473
2475 rc = nntp_fetch_headers(m, hc, first, mdata->last_message, false);
2476#ifdef USE_HCACHE
2478#endif
2479 if (rc < 0)
2480 return MX_OPEN_ERROR;
2481 mdata->last_loaded = mdata->last_message;
2482 adata->newsrc_modified = false;
2483 return MX_OPEN_OK;
2484}
struct BodyCache * mutt_bcache_open(struct ConnAccount *account, const char *mailbox)
Open an Email-Body Cache.
Definition: bcache.c:144
long cs_subset_long(const struct ConfigSubset *sub, const char *name)
Get a long config item by name.
Definition: helpers.c:121
time_t mutt_date_now(void)
Return the number of seconds since the Unix epoch.
Definition: date.c:432
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:362
void mutt_hcache_close(struct HeaderCache *hc)
Multiplexor for StoreOps::close.
Definition: hcache.c:483
void mutt_account_hook(const char *url)
Perform an account hook.
Definition: hook.c:845
size_t mutt_str_startswith(const char *str, const char *prefix)
Check whether a string starts with a prefix.
Definition: string.c:227
struct HeaderCache * nntp_hcache_open(struct NntpMboxData *mdata)
Open newsgroup hcache.
Definition: newsrc.c:715
void nntp_delete_group_cache(struct NntpMboxData *mdata)
Remove hcache and bcache of newsgroup.
Definition: newsrc.c:815
void nntp_hcache_update(struct NntpMboxData *mdata, struct HeaderCache *hc)
Remove stale cached headers.
Definition: newsrc.c:739
int nntp_active_save_cache(struct NntpAccountData *adata)
Save list of all newsgroups to cache.
Definition: newsrc.c:656
void nntp_bcache_update(struct NntpMboxData *mdata)
Remove stale cached messages.
Definition: newsrc.c:806
void nntp_adata_free(void **ptr)
Free the private Account data - Implements Account::adata_free()
Definition: adata.c:43
void nntp_newsrc_close(struct NntpAccountData *adata)
Unlock and close .newsrc file.
Definition: newsrc.c:118
int nntp_newsrc_update(struct NntpAccountData *adata)
Update .newsrc file.
Definition: newsrc.c:442
struct NntpAccountData * nntp_select_server(struct Mailbox *m, const char *server, bool leave_lock)
Open a connection to an NNTP server.
Definition: newsrc.c:1021
#define ANUM
Definition: lib.h:61
#define anum_t
Definition: lib.h:60
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:696
static int get_description(struct NntpMboxData *mdata, const char *wildmat, const char *msg)
Fetch newsgroups descriptions.
Definition: nntp.c:895
struct NntpAccountData * CurrentNewsSrv
Current NNTP news server.
Definition: nntp.c:77
static int nntp_fetch_headers(struct Mailbox *m, void *hc, anum_t first, anum_t last, bool restore)
Fetch headers.
Definition: nntp.c:1169
void(* adata_free)(void **ptr)
Free the private data attached to the Account.
Definition: account.h:52
char * realpath
Used for duplicate detection, context comparison, and the sidebar.
Definition: mailbox.h:81
NNTP-specific Account data -.
Definition: adata.h:37
bool newsrc_modified
Definition: adata.h:50
struct HashTable * groups_hash
Definition: adata.h:62
struct Connection * conn
Connection to NNTP Server.
Definition: adata.h:63
time_t check_time
Definition: adata.h:58
NNTP-specific Mailbox data -.
Definition: mdata.h:33
char * group
Name of newsgroup.
Definition: mdata.h:34
struct NntpAccountData * adata
Definition: mdata.h:47
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:236
int url_tostring(struct Url *url, char *dest, size_t len, uint8_t flags)
Output the URL string for a given Url object.
Definition: url.c:420
void url_free(struct Url **ptr)
Free the contents of a URL.
Definition: url.c:123
#define U_NO_FLAGS
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 2026 of file notmuch.c.

2027{
2028 if (init_mailbox(m) != 0)
2029 return MX_OPEN_ERROR;
2030
2031 struct NmMboxData *mdata = nm_mdata_get(m);
2032 if (!mdata)
2033 return MX_OPEN_ERROR;
2034
2035 mutt_debug(LL_DEBUG1, "nm: reading messages...[current count=%d]\n", m->msg_count);
2036
2037 progress_setup(m);
2038 enum MxOpenReturns rc = MX_OPEN_ERROR;
2039
2040 notmuch_query_t *q = get_query(m, false);
2041 if (q)
2042 {
2043 rc = MX_OPEN_OK;
2044 switch (mdata->query_type)
2045 {
2046 case NM_QUERY_TYPE_UNKNOWN: // UNKNOWN should never occur, but MESGS is default
2048 if (!read_mesgs_query(m, q, false))
2049 rc = MX_OPEN_ABORT;
2050 break;
2052 if (!read_threads_query(m, q, false, get_limit(mdata)))
2053 rc = MX_OPEN_ABORT;
2054 break;
2055 }
2056 notmuch_query_destroy(q);
2057 }
2058
2059 nm_db_release(m);
2060
2061 m->mtime.tv_sec = mutt_date_now();
2062 m->mtime.tv_nsec = 0;
2063
2064 mdata->oldmsgcount = 0;
2065
2066 mutt_debug(LL_DEBUG1, "nm: reading messages... done [rc=%d, count=%d]\n", rc, m->msg_count);
2067 progress_free(&mdata->progress);
2068 return rc;
2069}
@ LL_DEBUG1
Log at debug level 1.
Definition: logging.h:40
@ MX_OPEN_ABORT
Open was aborted.
Definition: mxapi.h:100
int nm_db_release(struct Mailbox *m)
Close the Notmuch database.
Definition: db.c:224
struct NmMboxData * nm_mdata_get(struct Mailbox *m)
Get the Notmuch Mailbox data.
Definition: mdata.c:97
static int init_mailbox(struct Mailbox *m)
Add Notmuch data to the Mailbox.
Definition: notmuch.c:188
static int get_limit(struct NmMboxData *mdata)
Get the database limit.
Definition: notmuch.c:400
static bool read_threads_query(struct Mailbox *m, notmuch_query_t *q, bool dedup, int limit)
Perform a query with threads.
Definition: notmuch.c:999
static notmuch_query_t * get_query(struct Mailbox *m, bool writable)
Create a new query.
Definition: notmuch.c:435
static bool read_mesgs_query(struct Mailbox *m, notmuch_query_t *q, bool dedup)
Search for matching messages.
Definition: notmuch.c:929
static void progress_setup(struct Mailbox *m)
Set up the Progress Bar.
Definition: notmuch.c:667
void progress_free(struct Progress **ptr)
Free a Progress Bar.
Definition: progress.c:86
@ NM_QUERY_TYPE_UNKNOWN
Unknown query type. Error in notmuch query.
Definition: query.h:38
@ NM_QUERY_TYPE_THREADS
Whole threads.
Definition: query.h:37
@ NM_QUERY_TYPE_MESGS
Default: Messages only.
Definition: query.h:36
struct timespec mtime
Time Mailbox was last changed.
Definition: mailbox.h:104
Notmuch-specific Mailbox data -.
Definition: mdata.h:34
long tv_nsec
Number of nanosecond, on top.
Definition: file.h:52
time_t tv_sec
Number of seconds since the epoch.
Definition: file.h:51
+ 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 739 of file pop.c.

740{
741 if (!m->account)
742 return MX_OPEN_ERROR;
743
744 char buf[PATH_MAX] = { 0 };
745 struct ConnAccount cac = { { 0 } };
746 struct Url url = { 0 };
747
748 if (pop_parse_path(mailbox_path(m), &cac))
749 {
750 mutt_error(_("%s is an invalid POP path"), mailbox_path(m));
751 return MX_OPEN_ERROR;
752 }
753
754 mutt_account_tourl(&cac, &url);
755 url.path = NULL;
756 url_tostring(&url, buf, sizeof(buf), U_NO_FLAGS);
757
758 mutt_buffer_strcpy(&m->pathbuf, buf);
760
761 struct PopAccountData *adata = m->account->adata;
762 if (!adata)
763 {
765 m->account->adata = adata;
767 }
768
769 struct Connection *conn = adata->conn;
770 if (!conn)
771 {
772 adata->conn = mutt_conn_new(&cac);
773 conn = adata->conn;
774 if (!conn)
775 return MX_OPEN_ERROR;
776 }
777
778 if (conn->fd < 0)
780
781 if (pop_open_connection(adata) < 0)
782 return MX_OPEN_ERROR;
783
784 adata->bcache = mutt_bcache_open(&cac, NULL);
785
786 /* init (hard-coded) ACL rights */
788#ifdef USE_HCACHE
789 /* flags are managed using header cache, so it only makes sense to
790 * enable them in that case */
792#endif
793
794 while (true)
795 {
796 if (pop_reconnect(m) < 0)
797 return MX_OPEN_ERROR;
798
799 m->size = adata->size;
800
801 mutt_message(_("Fetching list of messages..."));
802
803 const int rc = pop_fetch_headers(m);
804
805 if (rc >= 0)
806 return MX_OPEN_OK;
807
808 if (rc < -1)
809 return MX_OPEN_ERROR;
810 }
811}
size_t mutt_buffer_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition: buffer.c:365
char * mutt_str_replace(char **p, const char *s)
Replace one string with another.
Definition: string.c:326
void mutt_account_tourl(struct ConnAccount *cac, struct Url *url)
Fill URL with info from account.
Definition: mutt_account.c:79
struct Connection * mutt_conn_new(const struct ConnAccount *cac)
Create a new Connection.
Definition: mutt_socket.c:48
struct PopAccountData * pop_adata_new(void)
Create a new PopAccountData object.
Definition: adata.c:63
void pop_adata_free(void **ptr)
Free the private Account data - Implements Account::adata_free()
Definition: adata.c:41
int pop_open_connection(struct PopAccountData *adata)
Open connection and authenticate.
Definition: lib.c:308
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:599
static int pop_fetch_headers(struct Mailbox *m)
Read headers.
Definition: pop.c:320
Login details for a remote server.
Definition: connaccount.h:53
int fd
Socket file descriptor.
Definition: connection.h:54
POP-specific Account data -.
Definition: adata.h:37
size_t size
Definition: adata.h:50
struct Connection * conn
Connection to POP server.
Definition: adata.h:38
struct BodyCache * bcache
body cache
Definition: adata.h:55
+ Here is the call graph for this function: