NeoMutt  2021-02-05-666-ge300cd
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() -Set up a compressed mailbox to be read. 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() -Fetch only headers. More...
 

Detailed Description

Open a Mailbox.

Parameters
mMailbox to open
Return values
enumMxOpenReturns

Contract

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

441 {
442  struct CompressInfo *ci = set_compress_info(m);
443  if (!ci)
444  return MX_OPEN_ERROR;
445 
446  /* If there's no close-hook, or the file isn't writable */
447  if (!ci->cmd_close || (access(mailbox_path(m), W_OK) != 0))
448  m->readonly = true;
449 
450  if (setup_paths(m) != 0)
451  goto cmo_fail;
452  store_size(m);
453 
454  if (!lock_realpath(m, false))
455  {
456  mutt_error(_("Unable to lock mailbox"));
457  goto cmo_fail;
458  }
459 
460  int rc = execute_command(m, ci->cmd_open, _("Decompressing %s"));
461  if (rc == 0)
462  goto cmo_fail;
463 
464  unlock_realpath(m);
465 
467  if (m->type == MUTT_UNKNOWN)
468  {
469  mutt_error(_("Can't identify the contents of the compressed file"));
470  goto cmo_fail;
471  }
472 
473  ci->child_ops = mx_get_ops(m->type);
474  if (!ci->child_ops)
475  {
476  mutt_error(_("Can't find mailbox ops for mailbox type %d"), m->type);
477  goto cmo_fail;
478  }
479 
480  m->account->type = m->type;
481  return ci->child_ops->mbox_open(m);
482 
483 cmo_fail:
484  /* remove the partial uncompressed file */
485  remove(mailbox_path(m));
487  return MX_OPEN_ERROR;
488 }
static const char * mailbox_path(const struct Mailbox *m)
Get the Mailbox's path string.
Definition: mailbox.h:215
const struct MxOps * mx_get_ops(enum MailboxType type)
Get mailbox operations.
Definition: mx.c:141
enum MailboxType type
Mailbox type.
Definition: mailbox.h:105
static void compress_info_free(struct Mailbox *m)
Frees the compress info members and structure.
Definition: compress.c:226
#define mutt_error(...)
Definition: logging.h:88
#define _(a)
Definition: message.h:28
Mailbox wasn't recognised.
Definition: mailbox.h:47
enum MailboxType type
Type of Mailboxes this Account contains.
Definition: account.h:38
const char * cmd_close
close-hook command
Definition: lib.h:49
static void store_size(const struct Mailbox *m)
Save the size of the compressed file.
Definition: compress.c:178
bool readonly
Don't allow changes to the mailbox.
Definition: mailbox.h:119
static struct CompressInfo * set_compress_info(struct Mailbox *m)
Find the compress hooks for a mailbox.
Definition: compress.c:196
enum MxOpenReturns(* mbox_open)(struct Mailbox *m)
Definition: mxapi.h:152
static void unlock_realpath(struct Mailbox *m)
Unlock the mailbox->realpath.
Definition: compress.c:124
Private data for compress.
Definition: lib.h:46
static int execute_command(struct Mailbox *m, const char *command, const char *progress)
Run a system command.
Definition: compress.c:319
enum MailboxType mx_path_probe(const char *path)
Find a mailbox that understands a path.
Definition: mx.c:1317
struct Account * account
Account that owns this Mailbox.
Definition: mailbox.h:131
static bool lock_realpath(struct Mailbox *m, bool excl)
Try to lock the ctx->realpath.
Definition: compress.c:85
const struct MxOps * child_ops
callbacks of de-compressed file
Definition: lib.h:52
Open failed with an error.
Definition: mxapi.h:91
const char * cmd_open
open-hook command
Definition: lib.h:50
static int setup_paths(struct Mailbox *m)
Set the mailbox paths.
Definition: compress.c:150
+ 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 1929 of file imap.c.

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

1093 {
1094  /* maildir looks sort of like MH, except that there are two subdirectories
1095  * of the main folder path from which to read messages */
1096  if ((maildir_read_dir(m, "new") == -1) || (maildir_read_dir(m, "cur") == -1))
1097  return MX_OPEN_ERROR;
1098 
1099  return MX_OPEN_OK;
1100 }
Open succeeded.
Definition: mxapi.h:90
int maildir_read_dir(struct Mailbox *m, const char *subdir)
Read a Maildir style mailbox.
Definition: maildir.c:673
Open failed with an error.
Definition: mxapi.h:91
+ 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 842 of file mh.c.

843 {
844  return mh_read_dir(m) ? MX_OPEN_OK : MX_OPEN_ERROR;
845 }
Open succeeded.
Definition: mxapi.h:90
static bool mh_read_dir(struct Mailbox *m)
Read an MH mailbox.
Definition: mh.c:687
Open failed with an error.
Definition: mxapi.h:91
+ 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 925 of file mbox.c.

926 {
927  if (init_mailbox(m) != 0)
928  return MX_OPEN_ERROR;
929 
930  struct MboxAccountData *adata = mbox_adata_get(m);
931  if (!adata)
932  return MX_OPEN_ERROR;
933 
934  adata->fp = mbox_open_readwrite(m);
935  if (!adata->fp)
936  {
937  adata->fp = mbox_open_readonly(m);
938  }
939  if (!adata->fp)
940  {
942  return MX_OPEN_ERROR;
943  }
944 
945  mutt_sig_block();
946  if (mbox_lock_mailbox(m, false, true) == -1)
947  {
949  return MX_OPEN_ERROR;
950  }
951 
952  m->has_new = true;
953  enum MxOpenReturns rc = MX_OPEN_ERROR;
954  if (m->type == MUTT_MBOX)
955  rc = mbox_parse_mailbox(m);
956  else if (m->type == MUTT_MMDF)
957  rc = mmdf_parse_mailbox(m);
958  else
959  rc = MX_OPEN_ERROR;
960 
961  if (!mbox_has_new(m))
962  m->has_new = false;
963  clearerr(adata->fp); // Clear the EOF flag
964  mutt_file_touch_atime(fileno(adata->fp));
965 
968  return rc;
969 }
static const char * mailbox_path(const struct Mailbox *m)
Get the Mailbox&#39;s path string.
Definition: mailbox.h:215
void mutt_file_touch_atime(int fd)
Set the access time to current time.
Definition: file.c:1029
void mutt_sig_unblock(void)
Restore previously blocked signals.
Definition: signal.c:168
enum MailboxType type
Mailbox type.
Definition: mailbox.h:105
static FILE * mbox_open_readonly(struct Mailbox *m)
Open an mbox read-only.
Definition: mbox.c:914
Mbox-specific Account data -.
Definition: lib.h:48
static enum MxOpenReturns mbox_parse_mailbox(struct Mailbox *m)
Read a mailbox from disk.
Definition: mbox.c:349
MxOpenReturns
Return values for mbox_open()
Definition: mxapi.h:88
static FILE * mbox_open_readwrite(struct Mailbox *m)
Open an mbox read-write.
Definition: mbox.c:899
static enum MxOpenReturns mmdf_parse_mailbox(struct Mailbox *m)
Read a mailbox in MMDF format.
Definition: mbox.c:182
#define mutt_perror(...)
Definition: logging.h:89
static int mbox_lock_mailbox(struct Mailbox *m, bool excl, bool retry)
Lock a mailbox.
Definition: mbox.c:140
bool has_new
Mailbox has new mail.
Definition: mailbox.h:88
static bool mbox_has_new(struct Mailbox *m)
Does the mailbox have new mail.
Definition: mbox.c:720
void * adata
Private data (for Mailbox backends)
Definition: account.h:43
&#39;mmdf&#39; Mailbox type
Definition: mailbox.h:49
static struct MboxAccountData * mbox_adata_get(struct Mailbox *m)
Get the private data associated with a Mailbox.
Definition: mbox.c:100
&#39;mbox&#39; Mailbox type
Definition: mailbox.h:48
Open failed with an error.
Definition: mxapi.h:91
static void mbox_unlock_mailbox(struct Mailbox *m)
Unlock a mailbox.
Definition: mbox.c:162
FILE * fp
Mailbox file.
Definition: lib.h:50
void mutt_sig_block(void)
Block signals during critical operations.
Definition: signal.c:150
static int init_mailbox(struct Mailbox *m)
Add Mbox data to the Mailbox.
Definition: mbox.c:118
+ 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 2307 of file nntp.c.

2308 {
2309  if (!m->account)
2310  return MX_OPEN_ERROR;
2311 
2312  char buf[8192];
2313  char server[1024];
2314  char *group = NULL;
2315  int rc;
2316  void *hc = NULL;
2317  anum_t first, last, count = 0;
2318 
2319  struct Url *url = url_parse(mailbox_path(m));
2320  if (!url || !url->host || !url->path ||
2321  !((url->scheme == U_NNTP) || (url->scheme == U_NNTPS)))
2322  {
2323  url_free(&url);
2324  mutt_error(_("%s is an invalid newsgroup specification"), mailbox_path(m));
2325  return MX_OPEN_ERROR;
2326  }
2327 
2328  group = url->path;
2329  if (group[0] == '/') /* Skip a leading '/' */
2330  group++;
2331 
2332  url->path = strchr(url->path, '\0');
2333  url_tostring(url, server, sizeof(server), U_NO_FLAGS);
2334 
2336  struct NntpAccountData *adata = m->account->adata;
2337  if (!adata)
2338  {
2339  adata = nntp_select_server(m, server, true);
2340  m->account->adata = adata;
2342  }
2343 
2344  if (!adata)
2345  {
2346  url_free(&url);
2347  return MX_OPEN_ERROR;
2348  }
2350 
2351  m->msg_count = 0;
2352  m->msg_unread = 0;
2353  m->vcount = 0;
2354 
2355  if (group[0] == '/')
2356  group++;
2357 
2358  /* find news group data structure */
2359  struct NntpMboxData *mdata = mutt_hash_find(adata->groups_hash, group);
2360  if (!mdata)
2361  {
2362  nntp_newsrc_close(adata);
2363  mutt_error(_("Newsgroup %s not found on the server"), group);
2364  url_free(&url);
2365  return MX_OPEN_ERROR;
2366  }
2367 
2368  m->rights &= ~MUTT_ACL_INSERT; // Clear the flag
2369  const bool c_save_unsubscribed =
2370  cs_subset_bool(NeoMutt->sub, "save_unsubscribed");
2371  if (!mdata->newsrc_ent && !mdata->subscribed && !c_save_unsubscribed)
2372  m->readonly = true;
2373 
2374  /* select newsgroup */
2375  mutt_message(_("Selecting %s..."), group);
2376  url_free(&url);
2377  buf[0] = '\0';
2378  if (nntp_query(mdata, buf, sizeof(buf)) < 0)
2379  {
2380  nntp_newsrc_close(adata);
2381  return MX_OPEN_ERROR;
2382  }
2383 
2384  /* newsgroup not found, remove it */
2385  if (mutt_str_startswith(buf, "411"))
2386  {
2387  mutt_error(_("Newsgroup %s has been removed from the server"), mdata->group);
2388  if (!mdata->deleted)
2389  {
2390  mdata->deleted = true;
2391  nntp_active_save_cache(adata);
2392  }
2393  if (mdata->newsrc_ent && !mdata->subscribed && !c_save_unsubscribed)
2394  {
2395  FREE(&mdata->newsrc_ent);
2396  mdata->newsrc_len = 0;
2397  nntp_delete_group_cache(mdata);
2398  nntp_newsrc_update(adata);
2399  }
2400  }
2401 
2402  /* parse newsgroup info */
2403  else
2404  {
2405  if (sscanf(buf, "211 " ANUM " " ANUM " " ANUM, &count, &first, &last) != 3)
2406  {
2407  nntp_newsrc_close(adata);
2408  mutt_error("GROUP: %s", buf);
2409  return MX_OPEN_ERROR;
2410  }
2411  mdata->first_message = first;
2412  mdata->last_message = last;
2413  mdata->deleted = false;
2414 
2415  /* get description if empty */
2416  const bool c_nntp_load_description =
2417  cs_subset_bool(NeoMutt->sub, "nntp_load_description");
2418  if (c_nntp_load_description && !mdata->desc)
2419  {
2420  if (get_description(mdata, NULL, NULL) < 0)
2421  {
2422  nntp_newsrc_close(adata);
2423  return MX_OPEN_ERROR;
2424  }
2425  if (mdata->desc)
2426  nntp_active_save_cache(adata);
2427  }
2428  }
2429 
2430  adata->check_time = mutt_date_epoch();
2431  m->mdata = mdata;
2432  // Every known newsgroup has an mdata which is stored in adata->groups_list.
2433  // Currently we don't let the Mailbox free the mdata.
2434  // m->mdata_free = nntp_mdata_free;
2435  if (!mdata->bcache && (mdata->newsrc_ent || mdata->subscribed || c_save_unsubscribed))
2436  mdata->bcache = mutt_bcache_open(&adata->conn->account, mdata->group);
2437 
2438  /* strip off extra articles if adding context is greater than $nntp_context */
2439  first = mdata->first_message;
2440  const short c_nntp_context = cs_subset_number(NeoMutt->sub, "nntp_context");
2441  if (c_nntp_context && (mdata->last_message - first + 1 > c_nntp_context))
2442  first = mdata->last_message - c_nntp_context + 1;
2443  mdata->last_loaded = first ? first - 1 : 0;
2444  count = mdata->first_message;
2445  mdata->first_message = first;
2446  nntp_bcache_update(mdata);
2447  mdata->first_message = count;
2448 #ifdef USE_HCACHE
2449  hc = nntp_hcache_open(mdata);
2450  nntp_hcache_update(mdata, hc);
2451 #endif
2452  if (!hc)
2453  m->rights &= ~(MUTT_ACL_WRITE | MUTT_ACL_DELETE); // Clear the flags
2454 
2455  nntp_newsrc_close(adata);
2456  rc = nntp_fetch_headers(m, hc, first, mdata->last_message, false);
2457 #ifdef USE_HCACHE
2458  mutt_hcache_close(hc);
2459 #endif
2460  if (rc < 0)
2461  return MX_OPEN_ERROR;
2462  mdata->last_loaded = mdata->last_message;
2463  adata->newsrc_modified = false;
2464  return MX_OPEN_OK;
2465 }
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:354
time_t mutt_date_epoch(void)
Return the number of seconds since the Unix epoch.
Definition: date.c:427
static const char * mailbox_path(const struct Mailbox *m)
Get the Mailbox&#39;s path string.
Definition: mailbox.h:215
int msg_count
Total number of messages.
Definition: mailbox.h:91
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:73
struct ConnAccount account
Account details: username, password, etc.
Definition: connection.h:40
int msg_unread
Number of unread messages.
Definition: mailbox.h:92
#define mutt_error(...)
Definition: logging.h:88
struct BodyCache * mutt_bcache_open(struct ConnAccount *account, const char *mailbox)
Open an Email-Body Cache.
Definition: bcache.c:143
static int nntp_fetch_headers(struct Mailbox *m, void *hc, anum_t first, anum_t last, bool restore)
Fetch headers.
Definition: nntp.c:1154
A parsed URL proto://user:password@host:port/path?a=1&b=2
Definition: url.h:68
bool newsrc_modified
Definition: adata.h:50
enum UrlScheme scheme
Scheme, e.g. U_SMTPS.
Definition: url.h:70
char * realpath
Used for duplicate detection, context comparison, and the sidebar.
Definition: mailbox.h:84
#define MUTT_ACL_INSERT
Add/copy into the mailbox (used when editing a message)
Definition: mailbox.h:69
#define _(a)
Definition: message.h:28
#define U_NO_FLAGS
Definition: url.h:49
void nntp_newsrc_close(struct NntpAccountData *adata)
Unlock and close .newsrc file.
Definition: newsrc.c:118
void url_free(struct Url **ptr)
Free the contents of a URL.
Definition: url.c:123
int nntp_active_save_cache(struct NntpAccountData *adata)
Save list of all newsgroups to cache.
Definition: newsrc.c:650
void nntp_hcache_update(struct NntpMboxData *mdata, struct HeaderCache *hc)
Remove stale cached headers.
Definition: newsrc.c:735
void nntp_delete_group_cache(struct NntpMboxData *mdata)
Remove hcache and bcache of newsgroup.
Definition: newsrc.c:812
short cs_subset_number(const struct ConfigSubset *sub, const char *name)
Get a number config item by name.
Definition: helpers.c:169
Container for Accounts, Notifications.
Definition: neomutt.h:36
struct HashTable * groups_hash
Definition: adata.h:62
NNTP-specific Account data -.
Definition: adata.h:36
#define MUTT_ACL_DELETE
Delete a message.
Definition: mailbox.h:66
Open succeeded.
Definition: mxapi.h:90
bool subscribed
Definition: mdata.h:41
int vcount
The number of virtual messages.
Definition: mailbox.h:102
bool readonly
Don&#39;t allow changes to the mailbox.
Definition: mailbox.h:119
anum_t last_loaded
Definition: mdata.h:38
char * group
Definition: mdata.h:34
void(* adata_free)(void **ptr)
Free the private data attached to the Account.
Definition: account.h:53
void * mdata
Driver specific data.
Definition: mailbox.h:136
struct NntpAccountData * nntp_select_server(struct Mailbox *m, const char *server, bool leave_lock)
Open a connection to an NNTP server.
Definition: newsrc.c:1017
#define MUTT_ACL_WRITE
Write to a message (for flagging or linking threads)
Definition: mailbox.h:74
Url is nntps://.
Definition: url.h:42
void nntp_bcache_update(struct NntpMboxData *mdata)
Remove stale cached messages.
Definition: newsrc.c:803
#define ANUM
Definition: lib.h:61
size_t mutt_str_startswith(const char *str, const char *prefix)
Check whether a string starts with a prefix.
Definition: string.c:160
struct BodyCache * bcache
Definition: mdata.h:49
void mutt_account_hook(const char *url)
Perform an account hook.
Definition: hook.c:782
void * adata
Private data (for Mailbox backends)
Definition: account.h:43
struct HeaderCache * nntp_hcache_open(struct NntpMboxData *mdata)
Open newsgroup hcache.
Definition: newsrc.c:709
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:418
char * host
Host.
Definition: url.h:73
AclFlags rights
ACL bits, see AclFlags.
Definition: mailbox.h:121
static int get_description(struct NntpMboxData *mdata, const char *wildmat, const char *msg)
Fetch newsgroups descriptions.
Definition: nntp.c:884
struct NewsrcEntry * newsrc_ent
Definition: mdata.h:46
NNTP-specific Mailbox data -.
Definition: mdata.h:32
unsigned int newsrc_len
Definition: mdata.h:45
char * path
Path.
Definition: url.h:75
void mutt_hcache_close(struct HeaderCache *hc)
Multiplexor for StoreOps::close.
Definition: hcache.c:435
struct Connection * conn
Definition: adata.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:691
time_t check_time
Definition: adata.h:58
struct Account * account
Account that owns this Mailbox.
Definition: mailbox.h:131
bool deleted
Definition: mdata.h:44
anum_t first_message
Definition: mdata.h:36
Url is nntp://.
Definition: url.h:41
void nntp_adata_free(void **ptr)
Free the private Account data - Implements Account::adata_free()
Definition: adata.c:43
#define mutt_message(...)
Definition: logging.h:87
#define FREE(x)
Definition: memory.h:40
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:39
int nntp_newsrc_update(struct NntpAccountData *adata)
Update .newsrc file.
Definition: newsrc.c:439
Open failed with an error.
Definition: mxapi.h:91
#define anum_t
Definition: lib.h:60
struct NntpAccountData * CurrentNewsSrv
Current NNTP news server.
Definition: nntp.c:78
char * desc
Definition: mdata.h:35
struct Url * url_parse(const char *src)
Fill in Url.
Definition: url.c:234
anum_t last_message
Definition: mdata.h:37
+ 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 2044 of file notmuch.c.

2045 {
2046  if (init_mailbox(m) != 0)
2047  return MX_OPEN_ERROR;
2048 
2049  struct NmMboxData *mdata = nm_mdata_get(m);
2050  if (!mdata)
2051  return MX_OPEN_ERROR;
2052 
2053  mutt_debug(LL_DEBUG1, "nm: reading messages...[current count=%d]\n", m->msg_count);
2054 
2055  progress_setup(m);
2056  enum MxOpenReturns rc = MX_OPEN_ERROR;
2057 
2058  notmuch_query_t *q = get_query(m, false);
2059  if (q)
2060  {
2061  rc = MX_OPEN_OK;
2062  switch (mdata->query_type)
2063  {
2064  case NM_QUERY_TYPE_UNKNOWN: // UNKNOWN should never occur, but MESGS is default
2065  case NM_QUERY_TYPE_MESGS:
2066  if (!read_mesgs_query(m, q, false))
2067  rc = MX_OPEN_ABORT;
2068  break;
2069  case NM_QUERY_TYPE_THREADS:
2070  if (!read_threads_query(m, q, false, get_limit(mdata)))
2071  rc = MX_OPEN_ABORT;
2072  break;
2073  }
2074  notmuch_query_destroy(q);
2075  }
2076 
2077  nm_db_release(m);
2078 
2079  m->mtime.tv_sec = mutt_date_epoch();
2080  m->mtime.tv_nsec = 0;
2081 
2082  mdata->oldmsgcount = 0;
2083 
2084  mutt_debug(LL_DEBUG1, "nm: reading messages... done [rc=%d, count=%d]\n", rc, m->msg_count);
2085  progress_free(&mdata->progress);
2086  return rc;
2087 }
time_t mutt_date_epoch(void)
Return the number of seconds since the Unix epoch.
Definition: date.c:427
static notmuch_query_t * get_query(struct Mailbox *m, bool writable)
Create a new query.
Definition: notmuch.c:440
int msg_count
Total number of messages.
Definition: mailbox.h:91
static void progress_setup(struct Mailbox *m)
Set up the Progress Bar.
Definition: notmuch.c:668
struct timespec mtime
Time Mailbox was last changed.
Definition: mailbox.h:107
MxOpenReturns
Return values for mbox_open()
Definition: mxapi.h:88
Open succeeded.
Definition: mxapi.h:90
time_t tv_sec
Definition: file.h:50
int oldmsgcount
Definition: mdata.h:41
static int get_limit(struct NmMboxData *mdata)
Get the database limit.
Definition: notmuch.c:404
Notmuch-specific Mailbox data -.
Definition: mdata.h:33
long tv_nsec
Definition: file.h:51
struct Progress * progress
A progress bar.
Definition: mdata.h:40
void * mdata
Driver specific data.
Definition: mailbox.h:136
struct NmMboxData * nm_mdata_get(struct Mailbox *m)
Get the Notmuch Mailbox data.
Definition: mdata.c:98
static int init_mailbox(struct Mailbox *m)
Add Notmuch data to the Mailbox.
Definition: notmuch.c:188
Open was aborted.
Definition: mxapi.h:92
Default: Messages only.
Definition: query.h:36
#define mutt_debug(LEVEL,...)
Definition: logging.h:85
Unknown query type. Error in notmuch query.
Definition: query.h:38
void progress_free(struct Progress **ptr)
Free a Progress Bar.
Definition: progress.c:228
Log at debug level 1.
Definition: logging.h:40
static bool read_mesgs_query(struct Mailbox *m, notmuch_query_t *q, bool dedup)
Search for matching messages.
Definition: notmuch.c:931
int nm_db_release(struct Mailbox *m)
Close the Notmuch database.
Definition: db.c:196
Whole threads.
Definition: query.h:37
Open failed with an error.
Definition: mxapi.h:91
enum NmQueryType query_type
Messages or Threads.
Definition: mdata.h:38
static bool read_threads_query(struct Mailbox *m, notmuch_query_t *q, bool dedup, int limit)
Perform a query with threads.
Definition: notmuch.c:1001
+ 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 748 of file pop.c.

749 {
750  if (!m->account)
751  return MX_OPEN_ERROR;
752 
753  char buf[PATH_MAX];
754  struct ConnAccount cac = { { 0 } };
755  struct Url url = { 0 };
756 
757  if (pop_parse_path(mailbox_path(m), &cac))
758  {
759  mutt_error(_("%s is an invalid POP path"), mailbox_path(m));
760  return MX_OPEN_ERROR;
761  }
762 
763  mutt_account_tourl(&cac, &url);
764  url.path = NULL;
765  url_tostring(&url, buf, sizeof(buf), U_NO_FLAGS);
766 
767  mutt_buffer_strcpy(&m->pathbuf, buf);
769 
770  struct PopAccountData *adata = m->account->adata;
771  if (!adata)
772  {
773  adata = pop_adata_new();
774  m->account->adata = adata;
776  }
777 
778  struct Connection *conn = adata->conn;
779  if (!conn)
780  {
781  adata->conn = mutt_conn_new(&cac);
782  conn = adata->conn;
783  if (!conn)
784  return MX_OPEN_ERROR;
785  }
786 
787  if (conn->fd < 0)
789 
790  if (pop_open_connection(adata) < 0)
791  return MX_OPEN_ERROR;
792 
793  adata->bcache = mutt_bcache_open(&cac, NULL);
794 
795  /* init (hard-coded) ACL rights */
797 #ifdef USE_HCACHE
798  /* flags are managed using header cache, so it only makes sense to
799  * enable them in that case */
800  m->rights |= MUTT_ACL_WRITE;
801 #endif
802 
803  while (true)
804  {
805  if (pop_reconnect(m) < 0)
806  return MX_OPEN_ERROR;
807 
808  m->size = adata->size;
809 
810  mutt_message(_("Fetching list of messages..."));
811 
812  const int rc = pop_fetch_headers(m);
813 
814  if (rc >= 0)
815  return MX_OPEN_OK;
816 
817  if (rc < -1)
818  return MX_OPEN_ERROR;
819  }
820 }
static const char * mailbox_path(const struct Mailbox *m)
Get the Mailbox&#39;s path string.
Definition: mailbox.h:215
off_t size
Size of the Mailbox.
Definition: mailbox.h:87
size_t size
Definition: adata.h:50
int pop_parse_path(const char *path, struct ConnAccount *cac)
Parse a POP mailbox name.
Definition: lib.c:83
#define mutt_error(...)
Definition: logging.h:88
struct BodyCache * mutt_bcache_open(struct ConnAccount *account, const char *mailbox)
Open an Email-Body Cache.
Definition: bcache.c:143
int pop_open_connection(struct PopAccountData *adata)
Open connection and authenticate.
Definition: lib.c:310
A parsed URL proto://user:password@host:port/path?a=1&b=2
Definition: url.h:68
char * realpath
Used for duplicate detection, context comparison, and the sidebar.
Definition: mailbox.h:84
struct BodyCache * bcache
body cache
Definition: adata.h:55
#define _(a)
Definition: message.h:28
struct Connection * conn
Definition: adata.h:38
#define U_NO_FLAGS
Definition: url.h:49
#define MUTT_ACL_DELETE
Delete a message.
Definition: mailbox.h:66
Open succeeded.
Definition: mxapi.h:90
static int pop_fetch_headers(struct Mailbox *m)
Read headers.
Definition: pop.c:322
void mutt_account_tourl(struct ConnAccount *cac, struct Url *url)
Fill URL with info from account.
Definition: mutt_account.c:79
struct PopAccountData * pop_adata_new(void)
Create a new PopAccountData object.
Definition: adata.c:54
void(* adata_free)(void **ptr)
Free the private data attached to the Account.
Definition: account.h:53
#define MUTT_ACL_WRITE
Write to a message (for flagging or linking threads)
Definition: mailbox.h:74
struct Connection * mutt_conn_new(const struct ConnAccount *cac)
Create a new Connection.
Definition: mutt_socket.c:48
void mutt_account_hook(const char *url)
Perform an account hook.
Definition: hook.c:782
int pop_reconnect(struct Mailbox *m)
reconnect and verify indexes if connection was lost
Definition: lib.c:604
#define PATH_MAX
Definition: mutt.h:40
int fd
Socket file descriptor.
Definition: connection.h:44
void * adata
Private data (for Mailbox backends)
Definition: account.h:43
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:418
void pop_adata_free(void **ptr)
Free the private Account data - Implements Account::adata_free()
Definition: adata.c:40
AclFlags rights
ACL bits, see AclFlags.
Definition: mailbox.h:121
Login details for a remote server.
Definition: connaccount.h:51
size_t mutt_buffer_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition: buffer.c:312
char * path
Path.
Definition: url.h:75
struct Account * account
Account that owns this Mailbox.
Definition: mailbox.h:131
char * mutt_str_replace(char **p, const char *s)
Replace one string with another.
Definition: string.c:446
#define mutt_message(...)
Definition: logging.h:87
#define MUTT_ACL_SEEN
Change the &#39;seen&#39; status of a message.
Definition: mailbox.h:73
POP-specific Account data -.
Definition: adata.h:36
struct Buffer pathbuf
Definition: mailbox.h:83
Open failed with an error.
Definition: mxapi.h:91
+ Here is the call graph for this function: