NeoMutt
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() -.
 
static enum MxOpenReturns maildir_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 mbox_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 448 of file compress.c.

449{
450 struct CompressInfo *ci = set_compress_info(m);
451 if (!ci)
452 return MX_OPEN_ERROR;
453
454 /* If there's no close-hook, or the file isn't writable */
455 if (!ci->cmd_close || (access(mailbox_path(m), W_OK) != 0))
456 m->readonly = true;
457
458 if (setup_paths(m) != 0)
459 goto cmo_fail;
460 store_size(m);
461
462 if (!lock_realpath(m, false))
463 {
464 mutt_error(_("Unable to lock mailbox"));
465 goto cmo_fail;
466 }
467
468 if (!execute_command(m, ci->cmd_open, _("Decompressing %s")))
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:202
static void compress_info_free(struct Mailbox *m)
Frees the compress info members and structure.
Definition: compress.c:232
static int setup_paths(struct Mailbox *m)
Set the mailbox paths.
Definition: compress.c:156
static void store_size(const struct Mailbox *m)
Save the size of the compressed file.
Definition: compress.c:184
static bool lock_realpath(struct Mailbox *m, bool excl)
Try to lock the Mailbox.realpath.
Definition: compress.c:89
static void unlock_realpath(struct Mailbox *m)
Unlock the mailbox->realpath.
Definition: compress.c:130
static bool execute_command(struct Mailbox *m, const char *command, const char *progress)
Run a system command.
Definition: compress.c:327
#define mutt_error(...)
Definition: logging2.h:92
static const char * mailbox_path(const struct Mailbox *m)
Get the Mailbox's path string.
Definition: mailbox.h:210
@ 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:139
enum MailboxType mx_path_probe(const char *path)
Find a mailbox that understands a path.
Definition: mx.c:1343
@ MX_OPEN_ERROR
Open failed with an error.
Definition: mxapi.h:78
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:128
bool readonly
Don't allow changes to the mailbox.
Definition: mailbox.h:115
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 1855 of file imap.c.

1856{
1857 if (!m->account || !m->mdata)
1858 return MX_OPEN_ERROR;
1859
1860 char buf[PATH_MAX] = { 0 };
1861 int count = 0;
1862 int rc;
1863
1865 struct ImapMboxData *mdata = imap_mdata_get(m);
1866
1867 mutt_debug(LL_DEBUG3, "opening %s, saving %s\n", m->pathbuf.data,
1868 (adata->mailbox ? adata->mailbox->pathbuf.data : "(none)"));
1869 adata->prev_mailbox = adata->mailbox;
1870 adata->mailbox = m;
1871
1872 /* clear mailbox status */
1873 adata->status = 0;
1874 m->rights = 0;
1875 mdata->new_mail_count = 0;
1876
1877 if (m->verbose)
1878 mutt_message(_("Selecting %s..."), mdata->name);
1879
1880 /* pipeline ACL test */
1881 if (adata->capabilities & IMAP_CAP_ACL)
1882 {
1883 snprintf(buf, sizeof(buf), "MYRIGHTS %s", mdata->munge_name);
1884 imap_exec(adata, buf, IMAP_CMD_QUEUE);
1885 }
1886 else
1887 {
1888 /* assume we have all rights if ACL is unavailable */
1891 }
1892
1893 /* pipeline the postponed count if possible */
1894 const char *const c_postponed = cs_subset_string(NeoMutt->sub, "postponed");
1895 struct Mailbox *m_postponed = mx_mbox_find2(c_postponed);
1896 struct ImapAccountData *postponed_adata = imap_adata_get(m_postponed);
1897 if (postponed_adata &&
1898 imap_account_match(&postponed_adata->conn->account, &adata->conn->account))
1899 {
1900 imap_mailbox_status(m_postponed, true);
1901 }
1902
1903 const bool c_imap_check_subscribed = cs_subset_bool(NeoMutt->sub, "imap_check_subscribed");
1904 if (c_imap_check_subscribed)
1905 imap_exec(adata, "LSUB \"\" \"*\"", IMAP_CMD_QUEUE);
1906
1908
1909 do
1910 {
1911 char *pc = NULL;
1912
1913 rc = imap_cmd_step(adata);
1914 if (rc != IMAP_RES_CONTINUE)
1915 break;
1916
1917 pc = adata->buf + 2;
1918
1919 /* Obtain list of available flags here, may be overridden by a
1920 * PERMANENTFLAGS tag in the OK response */
1921 if (mutt_istr_startswith(pc, "FLAGS"))
1922 {
1923 /* don't override PERMANENTFLAGS */
1924 if (STAILQ_EMPTY(&mdata->flags))
1925 {
1926 mutt_debug(LL_DEBUG3, "Getting mailbox FLAGS\n");
1927 pc = get_flags(&mdata->flags, pc);
1928 if (!pc)
1929 goto fail;
1930 }
1931 }
1932 else if (mutt_istr_startswith(pc, "OK [PERMANENTFLAGS"))
1933 {
1934 /* PERMANENTFLAGS are massaged to look like FLAGS, then override FLAGS */
1935 mutt_debug(LL_DEBUG3, "Getting mailbox PERMANENTFLAGS\n");
1936 /* safe to call on NULL */
1937 mutt_list_free(&mdata->flags);
1938 /* skip "OK [PERMANENT" so syntax is the same as FLAGS */
1939 pc += 13;
1940 pc = get_flags(&(mdata->flags), pc);
1941 if (!pc)
1942 goto fail;
1943 }
1944 else if (mutt_istr_startswith(pc, "OK [UIDVALIDITY"))
1945 {
1946 /* save UIDVALIDITY for the header cache */
1947 mutt_debug(LL_DEBUG3, "Getting mailbox UIDVALIDITY\n");
1948 pc += 3;
1949 pc = imap_next_word(pc);
1950 if (!mutt_str_atoui(pc, &mdata->uidvalidity))
1951 goto fail;
1952 }
1953 else if (mutt_istr_startswith(pc, "OK [UIDNEXT"))
1954 {
1955 mutt_debug(LL_DEBUG3, "Getting mailbox UIDNEXT\n");
1956 pc += 3;
1957 pc = imap_next_word(pc);
1958 if (!mutt_str_atoui(pc, &mdata->uid_next))
1959 goto fail;
1960 }
1961 else if (mutt_istr_startswith(pc, "OK [HIGHESTMODSEQ"))
1962 {
1963 mutt_debug(LL_DEBUG3, "Getting mailbox HIGHESTMODSEQ\n");
1964 pc += 3;
1965 pc = imap_next_word(pc);
1966 if (!mutt_str_atoull(pc, &mdata->modseq))
1967 goto fail;
1968 }
1969 else if (mutt_istr_startswith(pc, "OK [NOMODSEQ"))
1970 {
1971 mutt_debug(LL_DEBUG3, "Mailbox has NOMODSEQ set\n");
1972 mdata->modseq = 0;
1973 }
1974 else
1975 {
1976 pc = imap_next_word(pc);
1977 if (mutt_istr_startswith(pc, "EXISTS"))
1978 {
1979 count = mdata->new_mail_count;
1980 mdata->new_mail_count = 0;
1981 }
1982 }
1983 } while (rc == IMAP_RES_CONTINUE);
1984
1985 if (rc == IMAP_RES_NO)
1986 {
1987 char *s = imap_next_word(adata->buf); /* skip seq */
1988 s = imap_next_word(s); /* Skip response */
1989 mutt_error("%s", s);
1990 goto fail;
1991 }
1992
1993 if (rc != IMAP_RES_OK)
1994 goto fail;
1995
1996 /* check for READ-ONLY notification */
1997 if (mutt_istr_startswith(imap_get_qualifier(adata->buf), "[READ-ONLY]") &&
1998 !(adata->capabilities & IMAP_CAP_ACL))
1999 {
2000 mutt_debug(LL_DEBUG2, "Mailbox is read-only\n");
2001 m->readonly = true;
2002 }
2003
2004 /* dump the mailbox flags we've found */
2005 const short c_debug_level = cs_subset_number(NeoMutt->sub, "debug_level");
2006 if (c_debug_level > LL_DEBUG2)
2007 {
2008 if (STAILQ_EMPTY(&mdata->flags))
2009 {
2010 mutt_debug(LL_DEBUG3, "No folder flags found\n");
2011 }
2012 else
2013 {
2014 struct ListNode *np = NULL;
2015 struct Buffer flag_buffer;
2016 buf_init(&flag_buffer);
2017 buf_printf(&flag_buffer, "Mailbox flags: ");
2018 STAILQ_FOREACH(np, &mdata->flags, entries)
2019 {
2020 buf_add_printf(&flag_buffer, "[%s] ", np->data);
2021 }
2022 mutt_debug(LL_DEBUG3, "%s\n", flag_buffer.data);
2023 FREE(&flag_buffer.data);
2024 }
2025 }
2026
2027 if (!((m->rights & MUTT_ACL_DELETE) || (m->rights & MUTT_ACL_SEEN) ||
2028 (m->rights & MUTT_ACL_WRITE) || (m->rights & MUTT_ACL_INSERT)))
2029 {
2030 m->readonly = true;
2031 }
2032
2033 mx_alloc_memory(m, count);
2034
2035 m->msg_count = 0;
2036 m->msg_unread = 0;
2037 m->msg_flagged = 0;
2038 m->msg_new = 0;
2039 m->msg_deleted = 0;
2040 m->size = 0;
2041 m->vcount = 0;
2042
2043 if ((count > 0) && (imap_read_headers(m, 1, count, true) < 0))
2044 {
2045 mutt_error(_("Error opening mailbox"));
2046 goto fail;
2047 }
2048
2049 mutt_debug(LL_DEBUG2, "msg_count is %d\n", m->msg_count);
2050 return MX_OPEN_OK;
2051
2052fail:
2053 if (adata->state == IMAP_SELECTED)
2054 adata->state = IMAP_AUTHENTICATED;
2055 return MX_OPEN_ERROR;
2056}
const char * mutt_str_atoull(const char *str, unsigned long long *dst)
Convert ASCII string to an unsigned long long.
Definition: atoi.c:291
const char * mutt_str_atoui(const char *str, unsigned int *dst)
Convert ASCII string to an unsigned integer.
Definition: atoi.c:213
int buf_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:173
int buf_add_printf(struct Buffer *buf, const char *fmt,...)
Format a string appending a Buffer.
Definition: buffer.c:216
struct Buffer * buf_init(struct Buffer *buf)
Initialise a new Buffer.
Definition: buffer.c:55
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
Definition: helpers.c:292
short cs_subset_number(const struct ConfigSubset *sub, const char *name)
Get a number config item by name.
Definition: helpers.c:144
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:48
#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:1326
@ 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:1051
#define IMAP_RES_CONTINUE
* ...
Definition: private.h:56
char * imap_next_word(char *s)
Find where the next IMAP word begins.
Definition: util.c:782
#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:765
int imap_mailbox_status(struct Mailbox *m, bool queue)
Refresh the number of total and new messages.
Definition: imap.c:1192
static char * get_flags(struct ListHead *hflags, char *s)
Make a simple list out of a FLAGS response.
Definition: imap.c:125
static void imap_mbox_select(struct Mailbox *m)
Select a Mailbox.
Definition: imap.c:1732
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: logging2.h:45
@ LL_DEBUG2
Log at debug level 2.
Definition: logging2.h:44
#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:45
size_t mutt_istr_startswith(const char *str, const char *prefix)
Check whether a string starts with a prefix, ignoring case.
Definition: string.c:240
#define PATH_MAX
Definition: mutt.h:41
void mx_alloc_memory(struct Mailbox *m, int req_size)
Create storage for the emails.
Definition: mx.c:1232
struct Mailbox * mx_mbox_find2(const char *path)
Find a Mailbox on an Account.
Definition: mx.c:1666
@ MX_OPEN_OK
Open succeeded.
Definition: mxapi.h:77
#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: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: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:118
void * mdata
Driver specific data.
Definition: mailbox.h:133
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:116
int msg_unread
Number of unread messages.
Definition: mailbox.h:89
Container for Accounts, Notifications.
Definition: neomutt.h:41
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:45
+ 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 1123 of file maildir.c.

1124{
1125 /* maildir looks sort of like MH, except that there are two subdirectories
1126 * of the main folder path from which to read messages */
1127 if ((maildir_read_dir(m, "new") == -1) || (maildir_read_dir(m, "cur") == -1))
1128 return MX_OPEN_ERROR;
1129
1130 return MX_OPEN_OK;
1131}
static int maildir_read_dir(struct Mailbox *m, const char *subdir)
Read a Maildir style mailbox.
Definition: maildir.c:694
+ 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 835 of file mh.c.

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

829{
830 if (init_mailbox(m) != 0)
831 return MX_OPEN_ERROR;
832
834 if (!adata)
835 return MX_OPEN_ERROR;
836
837 adata->fp = m->readonly ? NULL : mbox_open_readwrite(m);
838 if (!adata->fp)
839 {
840 adata->fp = mbox_open_readonly(m);
841 }
842 if (!adata->fp)
843 {
844 mutt_perror("%s", mailbox_path(m));
845 return MX_OPEN_ERROR;
846 }
847
849 if (mbox_lock_mailbox(m, false, true) == -1)
850 {
852 return MX_OPEN_ERROR;
853 }
854
855 m->has_new = true;
857 if (m->type == MUTT_MBOX)
858 rc = mbox_parse_mailbox(m);
859 else if (m->type == MUTT_MMDF)
860 rc = mmdf_parse_mailbox(m);
861 else
862 rc = MX_OPEN_ERROR;
863
864 if (!mbox_has_new(m))
865 m->has_new = false;
866 clearerr(adata->fp); // Clear the EOF flag
867 mutt_file_touch_atime(fileno(adata->fp));
868
871 return rc;
872}
void mutt_file_touch_atime(int fd)
Set the access time to current time.
Definition: file.c:1094
#define mutt_perror(...)
Definition: logging2.h:93
@ 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:351
static bool mbox_has_new(struct Mailbox *m)
Does the mailbox have new mail.
Definition: mbox.c:726
static int mbox_lock_mailbox(struct Mailbox *m, bool excl, bool retry)
Lock a mailbox.
Definition: mbox.c:138
static struct MboxAccountData * mbox_adata_get(struct Mailbox *m)
Get the private data associated with a Mailbox.
Definition: mbox.c:123
static int init_mailbox(struct Mailbox *m)
Add Mbox data to the Mailbox.
Definition: mbox.c:104
static FILE * mbox_open_readwrite(struct Mailbox *m)
Open an mbox read-write.
Definition: mbox.c:802
static FILE * mbox_open_readonly(struct Mailbox *m)
Open an mbox read-only.
Definition: mbox.c:817
static void mbox_unlock_mailbox(struct Mailbox *m)
Unlock a mailbox.
Definition: mbox.c:162
static enum MxOpenReturns mmdf_parse_mailbox(struct Mailbox *m)
Read a mailbox in MMDF format.
Definition: mbox.c:182
MxOpenReturns
Return values for mbox_open()
Definition: mxapi.h:76
void mutt_sig_block(void)
Block signals during critical operations.
Definition: signal.c:163
void mutt_sig_unblock(void)
Restore previously blocked signals.
Definition: signal.c:181
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 2332 of file nntp.c.

2333{
2334 if (!m->account)
2335 return MX_OPEN_ERROR;
2336
2337 char buf[8192] = { 0 };
2338 char server[1024] = { 0 };
2339 char *group = NULL;
2340 int rc;
2341 struct HeaderCache *hc = NULL;
2342 anum_t first, last, count = 0;
2343
2344 struct Url *url = url_parse(mailbox_path(m));
2345 if (!url || !url->host || !url->path ||
2346 !((url->scheme == U_NNTP) || (url->scheme == U_NNTPS)))
2347 {
2348 url_free(&url);
2349 mutt_error(_("%s is an invalid newsgroup specification"), mailbox_path(m));
2350 return MX_OPEN_ERROR;
2351 }
2352
2353 group = url->path;
2354 if (group[0] == '/') /* Skip a leading '/' */
2355 group++;
2356
2357 url->path = strchr(url->path, '\0');
2358 url_tostring(url, server, sizeof(server), U_NO_FLAGS);
2359
2361 struct NntpAccountData *adata = m->account->adata;
2362 if (!adata)
2363 {
2364 adata = nntp_select_server(m, server, true);
2365 m->account->adata = adata;
2367 }
2368
2369 if (!adata)
2370 {
2371 url_free(&url);
2372 return MX_OPEN_ERROR;
2373 }
2375
2376 m->msg_count = 0;
2377 m->msg_unread = 0;
2378 m->vcount = 0;
2379
2380 if (group[0] == '/')
2381 group++;
2382
2383 /* find news group data structure */
2385 if (!mdata)
2386 {
2388 mutt_error(_("Newsgroup %s not found on the server"), group);
2389 url_free(&url);
2390 return MX_OPEN_ERROR;
2391 }
2392
2393 m->rights &= ~MUTT_ACL_INSERT; // Clear the flag
2394 const bool c_save_unsubscribed = cs_subset_bool(NeoMutt->sub, "save_unsubscribed");
2395 if (!mdata->newsrc_ent && !mdata->subscribed && !c_save_unsubscribed)
2396 m->readonly = true;
2397
2398 /* select newsgroup */
2399 mutt_message(_("Selecting %s..."), group);
2400 url_free(&url);
2401 buf[0] = '\0';
2402 if (nntp_query(mdata, buf, sizeof(buf)) < 0)
2403 {
2405 return MX_OPEN_ERROR;
2406 }
2407
2408 /* newsgroup not found, remove it */
2409 if (mutt_str_startswith(buf, "411"))
2410 {
2411 mutt_error(_("Newsgroup %s has been removed from the server"), mdata->group);
2412 if (!mdata->deleted)
2413 {
2414 mdata->deleted = true;
2416 }
2417 if (mdata->newsrc_ent && !mdata->subscribed && !c_save_unsubscribed)
2418 {
2419 FREE(&mdata->newsrc_ent);
2420 mdata->newsrc_len = 0;
2423 }
2424 }
2425 else
2426 {
2427 /* parse newsgroup info */
2428 if (sscanf(buf, "211 " ANUM " " ANUM " " ANUM, &count, &first, &last) != 3)
2429 {
2431 mutt_error("GROUP: %s", buf);
2432 return MX_OPEN_ERROR;
2433 }
2434 mdata->first_message = first;
2435 mdata->last_message = last;
2436 mdata->deleted = false;
2437
2438 /* get description if empty */
2439 const bool c_nntp_load_description = cs_subset_bool(NeoMutt->sub, "nntp_load_description");
2440 if (c_nntp_load_description && !mdata->desc)
2441 {
2442 if (get_description(mdata, NULL, NULL) < 0)
2443 {
2445 return MX_OPEN_ERROR;
2446 }
2447 if (mdata->desc)
2449 }
2450 }
2451
2453 m->mdata = mdata;
2454 // Every known newsgroup has an mdata which is stored in adata->groups_list.
2455 // Currently we don't let the Mailbox free the mdata.
2456 // m->mdata_free = nntp_mdata_free;
2457 if (!mdata->bcache && (mdata->newsrc_ent || mdata->subscribed || c_save_unsubscribed))
2458 mdata->bcache = mutt_bcache_open(&adata->conn->account, mdata->group);
2459
2460 /* strip off extra articles if adding context is greater than $nntp_context */
2461 first = mdata->first_message;
2462 const long c_nntp_context = cs_subset_long(NeoMutt->sub, "nntp_context");
2463 if (c_nntp_context && ((mdata->last_message - first + 1) > c_nntp_context))
2464 first = mdata->last_message - c_nntp_context + 1;
2465 mdata->last_loaded = first ? first - 1 : 0;
2466 count = mdata->first_message;
2467 mdata->first_message = first;
2469 mdata->first_message = count;
2470#ifdef USE_HCACHE
2471 hc = nntp_hcache_open(mdata);
2473#endif
2474 if (!hc)
2475 m->rights &= ~(MUTT_ACL_WRITE | MUTT_ACL_DELETE); // Clear the flags
2476
2478 rc = nntp_fetch_headers(m, hc, first, mdata->last_message, false);
2479#ifdef USE_HCACHE
2480 hcache_close(&hc);
2481#endif
2482 if (rc < 0)
2483 return MX_OPEN_ERROR;
2484 mdata->last_loaded = mdata->last_message;
2485 adata->newsrc_modified = false;
2486 return MX_OPEN_OK;
2487}
struct BodyCache * mutt_bcache_open(struct ConnAccount *account, const char *mailbox)
Open an Email-Body Cache.
Definition: bcache.c:143
long cs_subset_long(const struct ConfigSubset *sub, const char *name)
Get a long config item by name.
Definition: helpers.c:96
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:563
void mutt_account_hook(const char *url)
Perform an account hook.
Definition: hook.c:846
time_t mutt_date_now(void)
Return the number of seconds since the Unix epoch.
Definition: date.c:446
size_t mutt_str_startswith(const char *str, const char *prefix)
Check whether a string starts with a prefix.
Definition: string.c:228
struct HeaderCache * nntp_hcache_open(struct NntpMboxData *mdata)
Open newsgroup hcache.
Definition: newsrc.c:714
void nntp_delete_group_cache(struct NntpMboxData *mdata)
Remove hcache and bcache of newsgroup.
Definition: newsrc.c:814
void nntp_hcache_update(struct NntpMboxData *mdata, struct HeaderCache *hc)
Remove stale cached headers.
Definition: newsrc.c:738
int nntp_active_save_cache(struct NntpAccountData *adata)
Save list of all newsgroups to cache.
Definition: newsrc.c:655
void nntp_bcache_update(struct NntpMboxData *mdata)
Remove stale cached messages.
Definition: newsrc.c:805
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:441
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:62
#define anum_t
Definition: lib.h:61
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:703
static int get_description(struct NntpMboxData *mdata, const char *wildmat, const char *msg)
Fetch newsgroups descriptions.
Definition: nntp.c:901
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:1169
void(* adata_free)(void **ptr)
Free the private data attached to the Account.
Definition: account.h:52
Header Cache.
Definition: lib.h:88
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:238
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:422
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 2031 of file notmuch.c.

2032{
2033 if (init_mailbox(m) != 0)
2034 return MX_OPEN_ERROR;
2035
2036 struct NmMboxData *mdata = nm_mdata_get(m);
2037 if (!mdata)
2038 return MX_OPEN_ERROR;
2039
2040 mutt_debug(LL_DEBUG1, "nm: reading messages...[current count=%d]\n", m->msg_count);
2041
2042 progress_setup(m);
2043 enum MxOpenReturns rc = MX_OPEN_ERROR;
2044
2045 notmuch_query_t *q = get_query(m, false);
2046 if (q)
2047 {
2048 rc = MX_OPEN_OK;
2049 switch (mdata->query_type)
2050 {
2051 case NM_QUERY_TYPE_UNKNOWN: // UNKNOWN should never occur, but MESGS is default
2053 if (!read_mesgs_query(m, q, false))
2054 rc = MX_OPEN_ABORT;
2055 break;
2057 if (!read_threads_query(m, q, false, get_limit(mdata)))
2058 rc = MX_OPEN_ABORT;
2059 break;
2060 }
2061 notmuch_query_destroy(q);
2062 }
2063
2064 nm_db_release(m);
2065
2066 mdata->mtime.tv_sec = mutt_date_now();
2067 mdata->mtime.tv_nsec = 0;
2068
2069 mdata->oldmsgcount = 0;
2070
2071 mutt_debug(LL_DEBUG1, "nm: reading messages... done [rc=%d, count=%d]\n", rc, m->msg_count);
2072 progress_free(&mdata->progress);
2073 return rc;
2074}
@ 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:224
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:191
static int get_limit(struct NmMboxData *mdata)
Get the database limit.
Definition: notmuch.c:406
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
static notmuch_query_t * get_query(struct Mailbox *m, bool writable)
Create a new query.
Definition: notmuch.c:441
static bool read_mesgs_query(struct Mailbox *m, notmuch_query_t *q, bool dedup)
Search for matching messages.
Definition: notmuch.c:931
static void progress_setup(struct Mailbox *m)
Set up the Progress Bar.
Definition: notmuch.c:669
void progress_free(struct Progress **ptr)
Free a Progress Bar.
Definition: progress.c:92
@ 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 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 buf_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 buf_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition: buffer.c:407
char * mutt_str_replace(char **p, const char *s)
Replace one string with another.
Definition: string.c:327
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:316
int pop_parse_path(const char *path, struct ConnAccount *cac)
Parse a POP mailbox name.
Definition: lib.c:82
int pop_reconnect(struct Mailbox *m)
Reconnect and verify indexes if connection was lost.
Definition: lib.c:606
static int pop_fetch_headers(struct Mailbox *m)
Read headers.
Definition: pop.c:322
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: