NeoMutt  2024-04-25-85-g27bab4
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
mbox_open()

Open a Mailbox. More...

+ Collaboration diagram for mbox_open():

Functions

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

Detailed Description

Open a Mailbox.

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

Function Documentation

◆ comp_mbox_open()

static enum MxOpenReturns comp_mbox_open ( struct Mailbox m)
static

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

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

Definition at line 446 of file compress.c.

447{
448 struct CompressInfo *ci = set_compress_info(m);
449 if (!ci)
450 return MX_OPEN_ERROR;
451
452 /* If there's no close-hook, or the file isn't writable */
453 if (!ci->cmd_close || (access(mailbox_path(m), W_OK) != 0))
454 m->readonly = true;
455
456 if (setup_paths(m) != 0)
457 goto cmo_fail;
458 store_size(m);
459
460 if (!lock_realpath(m, false))
461 {
462 mutt_error(_("Unable to lock mailbox"));
463 goto cmo_fail;
464 }
465
466 if (!execute_command(m, ci->cmd_open, _("Decompressing %s")))
467 goto cmo_fail;
468
470
472 if (m->type == MUTT_UNKNOWN)
473 {
474 mutt_error(_("Can't identify the contents of the compressed file"));
475 goto cmo_fail;
476 }
477
478 ci->child_ops = mx_get_ops(m->type);
479 if (!ci->child_ops)
480 {
481 mutt_error(_("Can't find mailbox ops for mailbox type %d"), m->type);
482 goto cmo_fail;
483 }
484
485 m->account->type = m->type;
486 return ci->child_ops->mbox_open(m);
487
488cmo_fail:
489 /* remove the partial uncompressed file */
490 (void) remove(mailbox_path(m));
492 return MX_OPEN_ERROR;
493}
static struct CompressInfo * set_compress_info(struct Mailbox *m)
Find the compress hooks for a mailbox.
Definition: compress.c:239
static void compress_info_free(struct Mailbox *m)
Frees the compress info members and structure.
Definition: compress.c:269
static int setup_paths(struct Mailbox *m)
Set the mailbox paths.
Definition: compress.c:174
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:107
static void unlock_realpath(struct Mailbox *m)
Unlock the mailbox->realpath.
Definition: compress.c:148
static bool execute_command(struct Mailbox *m, const struct Expando *exp, const char *progress)
Run a system command.
Definition: compress.c:323
static const char * mailbox_path(const struct Mailbox *m)
Get the Mailbox's path string.
Definition: mailbox.h:223
@ MUTT_UNKNOWN
Mailbox wasn't recognised.
Definition: mailbox.h:44
#define mutt_error(...)
Definition: logging2.h:92
#define _(a)
Definition: message.h:28
const struct MxOps * mx_get_ops(enum MailboxType type)
Get mailbox operations.
Definition: mx.c:127
enum MailboxType mx_path_probe(const char *path)
Find a mailbox that understands a path.
Definition: mx.c:1321
@ MX_OPEN_ERROR
Open failed with an error.
Definition: mxapi.h:78
enum MailboxType type
Type of Mailboxes this Account contains.
Definition: account.h:37
Private data for compress.
Definition: lib.h:58
struct Expando * cmd_open
open-hook command
Definition: lib.h:61
const struct MxOps * child_ops
callbacks of de-compressed file
Definition: lib.h:63
struct Expando * cmd_close
close-hook command
Definition: lib.h:60
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:116
enum MxOpenReturns(* mbox_open)(struct Mailbox *m)
Definition: mxapi.h:136
+ 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 1867 of file imap.c.

1868{
1869 if (!m->account || !m->mdata)
1870 return MX_OPEN_ERROR;
1871
1872 char buf[PATH_MAX] = { 0 };
1873 int count = 0;
1874 int rc;
1875
1877 struct ImapMboxData *mdata = imap_mdata_get(m);
1878
1879 mutt_debug(LL_DEBUG3, "opening %s, saving %s\n", m->pathbuf.data,
1880 (adata->mailbox ? adata->mailbox->pathbuf.data : "(none)"));
1881 adata->prev_mailbox = adata->mailbox;
1882 adata->mailbox = m;
1883
1884 /* clear mailbox status */
1885 adata->status = 0;
1886 m->rights = 0;
1887 mdata->new_mail_count = 0;
1888
1889 if (m->verbose)
1890 mutt_message(_("Selecting %s..."), mdata->name);
1891
1892 /* pipeline ACL test */
1893 if (adata->capabilities & IMAP_CAP_ACL)
1894 {
1895 snprintf(buf, sizeof(buf), "MYRIGHTS %s", mdata->munge_name);
1896 imap_exec(adata, buf, IMAP_CMD_QUEUE);
1897 }
1898 else
1899 {
1900 /* assume we have all rights if ACL is unavailable */
1903 }
1904
1905 /* pipeline the postponed count if possible */
1906 const char *const c_postponed = cs_subset_string(NeoMutt->sub, "postponed");
1907 struct Mailbox *m_postponed = mx_mbox_find2(c_postponed);
1908 struct ImapAccountData *postponed_adata = imap_adata_get(m_postponed);
1909 if (postponed_adata &&
1910 imap_account_match(&postponed_adata->conn->account, &adata->conn->account))
1911 {
1912 imap_mailbox_status(m_postponed, true);
1913 }
1914
1915 const bool c_imap_check_subscribed = cs_subset_bool(NeoMutt->sub, "imap_check_subscribed");
1916 if (c_imap_check_subscribed)
1917 imap_exec(adata, "LSUB \"\" \"*\"", IMAP_CMD_QUEUE);
1918
1920
1921 do
1922 {
1923 char *pc = NULL;
1924
1925 rc = imap_cmd_step(adata);
1926 if (rc != IMAP_RES_CONTINUE)
1927 break;
1928
1929 if (!mutt_strn_equal(adata->buf, "* ", 2))
1930 continue;
1931 pc = imap_next_word(adata->buf);
1932
1933 /* Obtain list of available flags here, may be overridden by a
1934 * PERMANENTFLAGS tag in the OK response */
1935 if (mutt_istr_startswith(pc, "FLAGS"))
1936 {
1937 /* don't override PERMANENTFLAGS */
1938 if (STAILQ_EMPTY(&mdata->flags))
1939 {
1940 mutt_debug(LL_DEBUG3, "Getting mailbox FLAGS\n");
1941 pc = get_flags(&mdata->flags, pc);
1942 if (!pc)
1943 goto fail;
1944 }
1945 }
1946 else if (mutt_istr_startswith(pc, "OK [PERMANENTFLAGS"))
1947 {
1948 /* PERMANENTFLAGS are massaged to look like FLAGS, then override FLAGS */
1949 mutt_debug(LL_DEBUG3, "Getting mailbox PERMANENTFLAGS\n");
1950 /* safe to call on NULL */
1951 mutt_list_free(&mdata->flags);
1952 /* skip "OK [PERMANENT" so syntax is the same as FLAGS */
1953 pc += 13;
1954 pc = get_flags(&(mdata->flags), pc);
1955 if (!pc)
1956 goto fail;
1957 }
1958 else if (mutt_istr_startswith(pc, "OK [UIDVALIDITY"))
1959 {
1960 /* save UIDVALIDITY for the header cache */
1961 mutt_debug(LL_DEBUG3, "Getting mailbox UIDVALIDITY\n");
1962 pc += 3;
1963 pc = imap_next_word(pc);
1964 if (!mutt_str_atoui(pc, &mdata->uidvalidity))
1965 goto fail;
1966 }
1967 else if (mutt_istr_startswith(pc, "OK [UIDNEXT"))
1968 {
1969 mutt_debug(LL_DEBUG3, "Getting mailbox UIDNEXT\n");
1970 pc += 3;
1971 pc = imap_next_word(pc);
1972 if (!mutt_str_atoui(pc, &mdata->uid_next))
1973 goto fail;
1974 }
1975 else if (mutt_istr_startswith(pc, "OK [HIGHESTMODSEQ"))
1976 {
1977 mutt_debug(LL_DEBUG3, "Getting mailbox HIGHESTMODSEQ\n");
1978 pc += 3;
1979 pc = imap_next_word(pc);
1980 if (!mutt_str_atoull(pc, &mdata->modseq))
1981 goto fail;
1982 }
1983 else if (mutt_istr_startswith(pc, "OK [NOMODSEQ"))
1984 {
1985 mutt_debug(LL_DEBUG3, "Mailbox has NOMODSEQ set\n");
1986 mdata->modseq = 0;
1987 }
1988 else
1989 {
1990 pc = imap_next_word(pc);
1991 if (mutt_istr_startswith(pc, "EXISTS"))
1992 {
1993 count = mdata->new_mail_count;
1994 mdata->new_mail_count = 0;
1995 }
1996 }
1997 } while (rc == IMAP_RES_CONTINUE);
1998
1999 if (rc == IMAP_RES_NO)
2000 {
2001 char *s = imap_next_word(adata->buf); /* skip seq */
2002 s = imap_next_word(s); /* Skip response */
2003 mutt_error("%s", s);
2004 goto fail;
2005 }
2006
2007 if (rc != IMAP_RES_OK)
2008 goto fail;
2009
2010 /* check for READ-ONLY notification */
2011 if (mutt_istr_startswith(imap_get_qualifier(adata->buf), "[READ-ONLY]") &&
2012 !(adata->capabilities & IMAP_CAP_ACL))
2013 {
2014 mutt_debug(LL_DEBUG2, "Mailbox is read-only\n");
2015 m->readonly = true;
2016 }
2017
2018 /* dump the mailbox flags we've found */
2019 const short c_debug_level = cs_subset_number(NeoMutt->sub, "debug_level");
2020 if (c_debug_level > LL_DEBUG2)
2021 {
2022 if (STAILQ_EMPTY(&mdata->flags))
2023 {
2024 mutt_debug(LL_DEBUG3, "No folder flags found\n");
2025 }
2026 else
2027 {
2028 struct ListNode *np = NULL;
2029 struct Buffer *flag_buffer = buf_pool_get();
2030 buf_printf(flag_buffer, "Mailbox flags: ");
2031 STAILQ_FOREACH(np, &mdata->flags, entries)
2032 {
2033 buf_add_printf(flag_buffer, "[%s] ", np->data);
2034 }
2035 mutt_debug(LL_DEBUG3, "%s\n", buf_string(flag_buffer));
2036 buf_pool_release(&flag_buffer);
2037 }
2038 }
2039
2040 if (!((m->rights & MUTT_ACL_DELETE) || (m->rights & MUTT_ACL_SEEN) ||
2041 (m->rights & MUTT_ACL_WRITE) || (m->rights & MUTT_ACL_INSERT)))
2042 {
2043 m->readonly = true;
2044 }
2045
2046 mx_alloc_memory(m, count);
2047
2048 m->msg_count = 0;
2049 m->msg_unread = 0;
2050 m->msg_flagged = 0;
2051 m->msg_new = 0;
2052 m->msg_deleted = 0;
2053 m->size = 0;
2054 m->vcount = 0;
2055
2056 if ((count > 0) && (imap_read_headers(m, 1, count, true) < 0))
2057 {
2058 mutt_error(_("Error opening mailbox"));
2059 goto fail;
2060 }
2061
2062 mutt_debug(LL_DEBUG2, "msg_count is %d\n", m->msg_count);
2063 return MX_OPEN_OK;
2064
2065fail:
2066 if (adata->state == IMAP_SELECTED)
2067 adata->state = IMAP_AUTHENTICATED;
2068 return MX_OPEN_ERROR;
2069}
const char * mutt_str_atoull(const char *str, unsigned long long *dst)
Convert ASCII string to an unsigned long long.
Definition: atoi.c:292
const char * mutt_str_atoui(const char *str, unsigned int *dst)
Convert ASCII string to an unsigned integer.
Definition: atoi.c:214
int buf_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:161
int buf_add_printf(struct Buffer *buf, const char *fmt,...)
Format a string appending a Buffer.
Definition: buffer.c:204
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition: buffer.h:96
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
Definition: helpers.c:291
short cs_subset_number(const struct ConfigSubset *sub, const char *name)
Get a number config item by name.
Definition: helpers.c:143
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:47
#define MUTT_ACL_CREATE
Create a mailbox.
Definition: mailbox.h: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 mutt_message(...)
Definition: logging2.h:91
#define mutt_debug(LEVEL,...)
Definition: logging2.h:89
struct ImapAccountData * imap_adata_get(struct Mailbox *m)
Get the Account data for this mailbox.
Definition: adata.c:123
int imap_cmd_step(struct ImapAccountData *adata)
Reads server responses from an IMAP command.
Definition: command.c:1129
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:1304
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:1340
@ IMAP_AUTHENTICATED
Connection is authenticated.
Definition: private.h:107
@ IMAP_SELECTED
Mailbox is selected.
Definition: private.h:108
#define IMAP_RES_OK
<tag> OK ...
Definition: private.h:55
#define IMAP_CAP_ACL
RFC2086: IMAP4 ACL extension.
Definition: private.h:124
#define IMAP_RES_NO
<tag> NO ...
Definition: private.h:53
bool imap_account_match(const struct ConnAccount *a1, const struct ConnAccount *a2)
Compare two Accounts.
Definition: util.c:1055
#define IMAP_RES_CONTINUE
* ...
Definition: private.h:56
char * imap_next_word(char *s)
Find where the next IMAP word begins.
Definition: util.c:786
#define IMAP_CMD_QUEUE
Queue a command, do not execute.
Definition: private.h:73
char * imap_get_qualifier(char *buf)
Get the qualifier from a tagged response.
Definition: util.c:769
int imap_mailbox_status(struct Mailbox *m, bool queue)
Refresh the number of total and new messages.
Definition: imap.c:1207
static char * get_flags(struct ListHead *hflags, char *s)
Make a simple list out of a FLAGS response.
Definition: imap.c:133
static void imap_mbox_select(struct Mailbox *m)
Select a Mailbox.
Definition: imap.c:1744
void mutt_list_free(struct ListHead *h)
Free a List AND its strings.
Definition: list.c:123
@ LL_DEBUG3
Log at debug level 3.
Definition: logging2.h:45
@ LL_DEBUG2
Log at debug level 2.
Definition: logging2.h:44
bool mutt_strn_equal(const char *a, const char *b, size_t num)
Check for equality of two strings (to a maximum), safely.
Definition: string.c:425
size_t mutt_istr_startswith(const char *str, const char *prefix)
Check whether a string starts with a prefix, ignoring case.
Definition: string.c:242
#define PATH_MAX
Definition: mutt.h:42
void mx_alloc_memory(struct Mailbox *m, int req_size)
Create storage for the emails.
Definition: mx.c:1206
struct Mailbox * mx_mbox_find2(const char *path)
Find a Mailbox on an Account.
Definition: mx.c:1605
@ MX_OPEN_OK
Open succeeded.
Definition: mxapi.h:77
struct Buffer * buf_pool_get(void)
Get a Buffer from the pool.
Definition: pool.c:81
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
Definition: pool.c:94
#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:42
String manipulation buffer.
Definition: buffer.h:36
char * data
Pointer to data.
Definition: buffer.h:37
struct ConnAccount account
Account details: username, password, etc.
Definition: connection.h:49
IMAP-specific Account data -.
Definition: adata.h:40
struct Mailbox * prev_mailbox
Previously selected mailbox.
Definition: adata.h: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:40
unsigned int uid_next
Definition: mdata.h:52
struct ListHead flags
Definition: mdata.h:50
unsigned int new_mail_count
Set when EXISTS notifies of new mail.
Definition: mdata.h:47
unsigned long long modseq
Definition: mdata.h:53
uint32_t uidvalidity
Definition: mdata.h:51
A List node for strings.
Definition: list.h:36
char * data
String.
Definition: list.h:37
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:119
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:117
int msg_unread
Number of unread messages.
Definition: mailbox.h:89
Container for Accounts, Notifications.
Definition: neomutt.h:42
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:46
+ 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 737 of file mailbox.c.

738{
739 if ((maildir_read_dir(m, "new") == -1) || (maildir_read_dir(m, "cur") == -1))
740 return MX_OPEN_ERROR;
741
742 return MX_OPEN_OK;
743}
static int maildir_read_dir(struct Mailbox *m, const char *subdir)
Read a Maildir style mailbox.
Definition: mailbox.c:481
+ 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 829 of file mbox.c.

830{
831 if (init_mailbox(m) != 0)
832 return MX_OPEN_ERROR;
833
835 if (!adata)
836 return MX_OPEN_ERROR;
837
838 adata->fp = m->readonly ? NULL : mbox_open_readwrite(m);
839 if (!adata->fp)
840 {
841 adata->fp = mbox_open_readonly(m);
842 }
843 if (!adata->fp)
844 {
845 mutt_perror("%s", mailbox_path(m));
846 return MX_OPEN_ERROR;
847 }
848
850 if (mbox_lock_mailbox(m, false, true) == -1)
851 {
853 return MX_OPEN_ERROR;
854 }
855
856 m->has_new = true;
858 if (m->type == MUTT_MBOX)
859 rc = mbox_parse_mailbox(m);
860 else if (m->type == MUTT_MMDF)
861 rc = mmdf_parse_mailbox(m);
862 else
863 rc = MX_OPEN_ERROR;
864
865 if (!mbox_has_new(m))
866 m->has_new = false;
867 clearerr(adata->fp); // Clear the EOF flag
868 mutt_file_touch_atime(fileno(adata->fp));
869
872 return rc;
873}
@ MUTT_MMDF
'mmdf' Mailbox type
Definition: mailbox.h:46
@ MUTT_MBOX
'mbox' Mailbox type
Definition: mailbox.h:45
void mutt_file_touch_atime(int fd)
Set the access time to current time.
Definition: file.c:1091
#define mutt_perror(...)
Definition: logging2.h:93
static enum MxOpenReturns mbox_parse_mailbox(struct Mailbox *m)
Read a mailbox from disk.
Definition: mbox.c:352
static bool mbox_has_new(struct Mailbox *m)
Does the mailbox have new mail.
Definition: mbox.c:727
static int mbox_lock_mailbox(struct Mailbox *m, bool excl, bool retry)
Lock a mailbox.
Definition: mbox.c:140
static struct MboxAccountData * mbox_adata_get(struct Mailbox *m)
Get the private data associated with a Mailbox.
Definition: mbox.c:125
static int init_mailbox(struct Mailbox *m)
Add Mbox data to the Mailbox.
Definition: mbox.c:106
static FILE * mbox_open_readwrite(struct Mailbox *m)
Open an mbox read-write.
Definition: mbox.c:803
static FILE * mbox_open_readonly(struct Mailbox *m)
Open an mbox read-only.
Definition: mbox.c:818
static void mbox_unlock_mailbox(struct Mailbox *m)
Unlock a mailbox.
Definition: mbox.c:164
static enum MxOpenReturns mmdf_parse_mailbox(struct Mailbox *m)
Read a mailbox in MMDF format.
Definition: mbox.c:184
MxOpenReturns
Return values for mbox_open()
Definition: mxapi.h:76
void mutt_sig_block(void)
Block signals during critical operations.
Definition: signal.c:212
void mutt_sig_unblock(void)
Restore previously blocked signals.
Definition: signal.c:230
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:

◆ mh_mbox_open()

static enum MxOpenReturns mh_mbox_open ( struct Mailbox m)
static

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

Definition at line 817 of file mh.c.

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

◆ nntp_mbox_open()

static enum MxOpenReturns nntp_mbox_open ( struct Mailbox m)
static

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

Definition at line 2383 of file nntp.c.

2384{
2385 if (!m->account)
2386 return MX_OPEN_ERROR;
2387
2388 char buf[8192] = { 0 };
2389 char server[1024] = { 0 };
2390 char *group = NULL;
2391 int rc;
2392 struct HeaderCache *hc = NULL;
2393 anum_t first = 0, last = 0, count = 0;
2394
2395 struct Url *url = url_parse(mailbox_path(m));
2396 if (!url || !url->host || !url->path ||
2397 !((url->scheme == U_NNTP) || (url->scheme == U_NNTPS)))
2398 {
2399 url_free(&url);
2400 mutt_error(_("%s is an invalid newsgroup specification"), mailbox_path(m));
2401 return MX_OPEN_ERROR;
2402 }
2403
2404 group = url->path;
2405 if (group[0] == '/') /* Skip a leading '/' */
2406 group++;
2407
2408 url->path = strchr(url->path, '\0');
2409 url_tostring(url, server, sizeof(server), U_NO_FLAGS);
2410
2412 struct NntpAccountData *adata = m->account->adata;
2413 if (!adata)
2415 if (!adata)
2416 {
2417 adata = nntp_select_server(m, server, true);
2418 m->account->adata = adata;
2420 }
2421
2422 if (!adata)
2423 {
2424 url_free(&url);
2425 return MX_OPEN_ERROR;
2426 }
2428
2429 m->msg_count = 0;
2430 m->msg_unread = 0;
2431 m->vcount = 0;
2432
2433 if (group[0] == '/')
2434 group++;
2435
2436 /* find news group data structure */
2438 if (!mdata)
2439 {
2441 mutt_error(_("Newsgroup %s not found on the server"), group);
2442 url_free(&url);
2443 return MX_OPEN_ERROR;
2444 }
2445
2446 m->rights &= ~MUTT_ACL_INSERT; // Clear the flag
2447 const bool c_save_unsubscribed = cs_subset_bool(NeoMutt->sub, "save_unsubscribed");
2448 if (!mdata->newsrc_ent && !mdata->subscribed && !c_save_unsubscribed)
2449 m->readonly = true;
2450
2451 /* select newsgroup */
2452 mutt_message(_("Selecting %s..."), group);
2453 url_free(&url);
2454 buf[0] = '\0';
2455 if (nntp_query(mdata, buf, sizeof(buf)) < 0)
2456 {
2458 return MX_OPEN_ERROR;
2459 }
2460
2461 /* newsgroup not found, remove it */
2462 if (mutt_str_startswith(buf, "411"))
2463 {
2464 mutt_error(_("Newsgroup %s has been removed from the server"), mdata->group);
2465 if (!mdata->deleted)
2466 {
2467 mdata->deleted = true;
2469 }
2470 if (mdata->newsrc_ent && !mdata->subscribed && !c_save_unsubscribed)
2471 {
2472 FREE(&mdata->newsrc_ent);
2473 mdata->newsrc_len = 0;
2476 }
2477 }
2478 else
2479 {
2480 /* parse newsgroup info */
2481 if (sscanf(buf, "211 " ANUM_FMT " " ANUM_FMT " " ANUM_FMT, &count, &first, &last) != 3)
2482 {
2484 mutt_error("GROUP: %s", buf);
2485 return MX_OPEN_ERROR;
2486 }
2487 mdata->first_message = first;
2488 mdata->last_message = last;
2489 mdata->deleted = false;
2490
2491 /* get description if empty */
2492 const bool c_nntp_load_description = cs_subset_bool(NeoMutt->sub, "nntp_load_description");
2493 if (c_nntp_load_description && !mdata->desc)
2494 {
2495 if (get_description(mdata, NULL, NULL) < 0)
2496 {
2498 return MX_OPEN_ERROR;
2499 }
2500 if (mdata->desc)
2502 }
2503 }
2504
2506 m->mdata = mdata;
2507 // Every known newsgroup has an mdata which is stored in adata->groups_list.
2508 // Currently we don't let the Mailbox free the mdata.
2509 // m->mdata_free = nntp_mdata_free;
2510 if (!mdata->bcache && (mdata->newsrc_ent || mdata->subscribed || c_save_unsubscribed))
2511 mdata->bcache = mutt_bcache_open(&adata->conn->account, mdata->group);
2512
2513 /* strip off extra articles if adding context is greater than $nntp_context */
2514 first = mdata->first_message;
2515 const long c_nntp_context = cs_subset_long(NeoMutt->sub, "nntp_context");
2516 if (c_nntp_context && ((mdata->last_message - first + 1) > c_nntp_context))
2517 first = mdata->last_message - c_nntp_context + 1;
2518 mdata->last_loaded = first ? first - 1 : 0;
2519 count = mdata->first_message;
2520 mdata->first_message = first;
2522 mdata->first_message = count;
2523#ifdef USE_HCACHE
2524 hc = nntp_hcache_open(mdata);
2526#endif
2527 if (!hc)
2528 m->rights &= ~(MUTT_ACL_WRITE | MUTT_ACL_DELETE); // Clear the flags
2529
2531 rc = nntp_fetch_headers(m, hc, first, mdata->last_message, false);
2532#ifdef USE_HCACHE
2533 hcache_close(&hc);
2534#endif
2535 if (rc < 0)
2536 return MX_OPEN_ERROR;
2537 mdata->last_loaded = mdata->last_message;
2538 adata->newsrc_modified = false;
2539 return MX_OPEN_OK;
2540}
struct BodyCache * mutt_bcache_open(struct ConnAccount *account, const char *mailbox)
Open an Email-Body Cache.
Definition: bcache.c:148
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:43
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 hcache_close(struct HeaderCache **ptr)
Multiplexor for StoreOps::close.
Definition: hcache.c:544
void mutt_account_hook(const char *url)
Perform an account hook.
Definition: hook.c:879
#define FREE(x)
Definition: memory.h:45
time_t mutt_date_now(void)
Return the number of seconds since the Unix epoch.
Definition: date.c:456
size_t mutt_str_startswith(const char *str, const char *prefix)
Check whether a string starts with a prefix.
Definition: string.c:230
struct HeaderCache * nntp_hcache_open(struct NntpMboxData *mdata)
Open newsgroup hcache.
Definition: newsrc.c:709
void nntp_delete_group_cache(struct NntpMboxData *mdata)
Remove hcache and bcache of newsgroup.
Definition: newsrc.c:810
void nntp_hcache_update(struct NntpMboxData *mdata, struct HeaderCache *hc)
Remove stale cached headers.
Definition: newsrc.c:733
int nntp_active_save_cache(struct NntpAccountData *adata)
Save list of all newsgroups to cache.
Definition: newsrc.c:649
void nntp_bcache_update(struct NntpMboxData *mdata)
Remove stale cached messages.
Definition: newsrc.c:801
void nntp_newsrc_close(struct NntpAccountData *adata)
Unlock and close .newsrc file.
Definition: newsrc.c:122
int nntp_newsrc_update(struct NntpAccountData *adata)
Update .newsrc file.
Definition: newsrc.c:445
#define ANUM_FMT
Definition: lib.h:61
struct NntpAccountData * nntp_select_server(struct Mailbox *m, const char *server, bool leave_lock)
Open a connection to an NNTP server.
Definition: newsrc.c:1063
#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:730
static int get_description(struct NntpMboxData *mdata, const char *wildmat, const char *msg)
Fetch newsgroups descriptions.
Definition: nntp.c:936
struct NntpAccountData * CurrentNewsSrv
Current 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:1204
void(* adata_free)(void **ptr)
Definition: account.h:53
Header Cache.
Definition: lib.h:86
char * realpath
Used for duplicate detection, context comparison, and the sidebar.
Definition: mailbox.h:81
NNTP-specific Account data -.
Definition: adata.h:36
bool newsrc_modified
Definition: adata.h:49
struct HashTable * groups_hash
Hash Table: "newsgroup" -> NntpMboxData.
Definition: adata.h:61
struct Connection * conn
Connection to NNTP Server.
Definition: adata.h:62
time_t 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
Definition: mdata.h:48
A parsed URL proto://user:password@host:port/path?a=1&b=2
Definition: url.h:69
char * host
Host.
Definition: url.h:73
char * path
Path.
Definition: url.h:75
enum UrlScheme scheme
Scheme, e.g. U_SMTPS.
Definition: url.h:70
struct Url * url_parse(const char *src)
Fill in Url.
Definition: url.c:239
void url_free(struct Url **ptr)
Free the contents of a URL.
Definition: url.c:124
int url_tostring(const struct Url *url, char *dest, size_t len, uint8_t flags)
Output the URL string for a given Url object.
Definition: url.c:423
#define U_NO_FLAGS
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 2046 of file notmuch.c.

2047{
2048 if (init_mailbox(m) != 0)
2049 return MX_OPEN_ERROR;
2050
2051 struct NmMboxData *mdata = nm_mdata_get(m);
2052 if (!mdata)
2053 return MX_OPEN_ERROR;
2054
2055 mutt_debug(LL_DEBUG1, "nm: reading messages...[current count=%d]\n", m->msg_count);
2056
2057 progress_setup(m);
2058 enum MxOpenReturns rc = MX_OPEN_ERROR;
2059
2060 notmuch_query_t *q = get_query(m, false);
2061 if (q)
2062 {
2063 rc = MX_OPEN_OK;
2064 switch (mdata->query_type)
2065 {
2066 case NM_QUERY_TYPE_UNKNOWN: // UNKNOWN should never occur, but MESGS is default
2068 if (!read_mesgs_query(m, q, false))
2069 rc = MX_OPEN_ABORT;
2070 break;
2072 if (!read_threads_query(m, q, false, get_limit(mdata)))
2073 rc = MX_OPEN_ABORT;
2074 break;
2075 }
2076 notmuch_query_destroy(q);
2077 }
2078
2079 nm_db_release(m);
2080
2081 mdata->mtime.tv_sec = mutt_date_now();
2082 mdata->mtime.tv_nsec = 0;
2083
2084 mdata->oldmsgcount = 0;
2085
2086 mutt_debug(LL_DEBUG1, "nm: reading messages... done [rc=%d, count=%d]\n", rc, m->msg_count);
2087 progress_free(&mdata->progress);
2088 return rc;
2089}
@ LL_DEBUG1
Log at debug level 1.
Definition: logging2.h:43
@ MX_OPEN_ABORT
Open was aborted.
Definition: mxapi.h:79
int nm_db_release(struct Mailbox *m)
Close the Notmuch database.
Definition: db.c:233
struct NmMboxData * nm_mdata_get(struct Mailbox *m)
Get the Notmuch Mailbox data.
Definition: mdata.c:96
static int init_mailbox(struct Mailbox *m)
Add Notmuch data to the Mailbox.
Definition: notmuch.c:199
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:1010
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:940
static void progress_setup(struct Mailbox *m)
Set up the Progress Bar.
Definition: notmuch.c:678
void progress_free(struct Progress **ptr)
Free a Progress Bar.
Definition: progress.c:110
@ NM_QUERY_TYPE_UNKNOWN
Unknown query type. Error in notmuch query.
Definition: query.h:38
@ NM_QUERY_TYPE_THREADS
Whole threads.
Definition: query.h:37
@ NM_QUERY_TYPE_MESGS
Default: Messages only.
Definition: query.h:36
Notmuch-specific Mailbox data -.
Definition: mdata.h:35
+ Here is the call graph for this function:

◆ pop_mbox_open()

static enum MxOpenReturns pop_mbox_open ( struct Mailbox m)
static

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

Fetch only headers

Definition at line 741 of file pop.c.

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