From: Brendan Cully Date: Sun, 7 Aug 2005 23:52:07 +0000 (+0000) Subject: New option: $imap_check_subscribed. If set, mutt will fetch the set of X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f18898d4d1e2b0c33733a2cac22cf6971f6bb04b;p=neomutt New option: $imap_check_subscribed. If set, mutt will fetch the set of subscribed mailboxes from the server and add them to the buffy list. --- diff --git a/imap/browse.c b/imap/browse.c index 0e7ec990d..4d1d445e1 100644 --- a/imap/browse.c +++ b/imap/browse.c @@ -61,6 +61,7 @@ int imap_browse (char* path, struct browser_state* state) short showparents = 0; int noselect; int noinferiors; + int save_lsub; IMAP_MBOX mx; if (imap_parse_path (path, &mx)) @@ -69,6 +70,8 @@ int imap_browse (char* path, struct browser_state* state) return -1; } + save_lsub = option (OPTIMAPCHECKSUBSCRIBED); + unset_option (OPTIMAPCHECKSUBSCRIBED); strfcpy (list_cmd, option (OPTIMAPLSUB) ? "LSUB" : "LIST", sizeof (list_cmd)); if (!(idata = imap_conn_find (&(mx.account), 0))) @@ -238,10 +241,15 @@ int imap_browse (char* path, struct browser_state* state) } } + if (save_lsub) + set_option (OPTIMAPCHECKSUBSCRIBED); + FREE (&mx.mbox); return 0; fail: + if (save_lsub) + set_option (OPTIMAPCHECKSUBSCRIBED); FREE (&mx.mbox); return -1; } diff --git a/imap/command.c b/imap/command.c index 74fa21a07..20f76cabd 100644 --- a/imap/command.c +++ b/imap/command.c @@ -1,7 +1,7 @@ /* * Copyright (C) 1996-8 Michael R. Elkins * Copyright (C) 1996-9 Brandon Long - * Copyright (C) 1999-2002 Brendan Cully + * Copyright (C) 1999-2005 Brendan Cully * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -41,6 +41,7 @@ static int cmd_handle_untagged (IMAP_DATA* idata); static void cmd_make_sequence (IMAP_DATA* idata); static void cmd_parse_capabilities (IMAP_DATA* idata, char* s); static void cmd_parse_expunge (IMAP_DATA* idata, const char* s); +static void cmd_parse_lsub (IMAP_DATA* idata, char* s); static void cmd_parse_fetch (IMAP_DATA* idata, char* s); static void cmd_parse_myrights (IMAP_DATA* idata, char* s); @@ -362,6 +363,8 @@ static int cmd_handle_untagged (IMAP_DATA* idata) } else if (ascii_strncasecmp ("CAPABILITY", s, 10) == 0) cmd_parse_capabilities (idata, s); + else if (ascii_strncasecmp ("LSUB", s, 4) == 0) + cmd_parse_lsub (idata, s); else if (ascii_strncasecmp ("MYRIGHTS", s, 8) == 0) cmd_parse_myrights (idata, s); else if (ascii_strncasecmp ("BYE", s, 3) == 0) @@ -516,6 +519,63 @@ static void cmd_parse_fetch (IMAP_DATA* idata, char* s) } } +static void cmd_parse_lsub (IMAP_DATA* idata, char* s) +{ + char buf[STRING]; + char errstr[STRING]; + BUFFER err, token; + ciss_url_t url; + char *ep; + + if (!option (OPTIMAPCHECKSUBSCRIBED)) + return; + + s = imap_next_word (s); /* flags */ + + if (*s != '(') + { + dprint (1, (debugfile, "Bad LSUB response\n")); + return; + } + + s++; + ep = s; + for (ep = s; *ep && *ep != ')'; ep++) + ; + do + { + if (!ascii_strncasecmp (s, "\\NoSelect", 9)) + return; + if (*s != ')') + s = imap_next_word (s); + } while (s != ep); + + s = imap_next_word (s); /* delim */ + s = imap_next_word (s); /* name */ + + if (s) + { + imap_unmunge_mbox_name (s); + dprint (2, (debugfile, "Subscribing to %s\n", s)); + + strfcpy (buf, "mailboxes \"", sizeof (buf)); + mutt_account_tourl (&idata->conn->account, &url); + url.path = s; + if (!mutt_strcmp (url.user, ImapUser)) + url.user = NULL; + url_ciss_tostring (&url, buf + 11, sizeof (buf) - 10, 0); + safe_strcat (buf, sizeof (buf), "\""); + memset (&token, 0, sizeof (token)); + err.data = errstr; + err.dsize = sizeof (errstr); + if (mutt_parse_rc_line (buf, &token, &err)) + dprint (1, (debugfile, "Error adding subscribed mailbox: %s\n", errstr)); + FREE (&token.data); + } + else + dprint (1, (debugfile, "Bad LSUB response\n")); +} + /* cmd_parse_myrights: set rights bits according to MYRIGHTS response */ static void cmd_parse_myrights (IMAP_DATA* idata, char* s) { diff --git a/imap/imap.c b/imap/imap.c index 731258c86..4e7ad5b14 100644 --- a/imap/imap.c +++ b/imap/imap.c @@ -411,8 +411,15 @@ IMAP_DATA* imap_conn_find (const ACCOUNT* account, int flags) FREE (&idata->capstr); } if (idata->state == IMAP_AUTHENTICATED) + { imap_get_delim (idata); - + if (option (OPTIMAPCHECKSUBSCRIBED)) + { + mutt_message _("Checking mailbox subscriptions"); + imap_exec (idata, "LSUB \"\" \"*\"", 0); + } + } + return idata; } diff --git a/init.h b/init.h index 3e57ec5a7..0ec78c741 100644 --- a/init.h +++ b/init.h @@ -811,7 +811,7 @@ struct option_t MuttVars[] = { ** try them. Authentication methods are either 'login' or the right ** side of an IMAP 'AUTH=xxx' capability string, eg 'digest-md5', 'gssapi' ** or 'cram-md5'. This parameter is case-insensitive. If this - ** parameter is unset (the default) mutt will try all available methods, + ** parameter is \fIunset\fP (the default) mutt will try all available methods, ** in order from most-secure to least-secure. ** .pp ** Example: set imap_authenticators="gssapi:cram-md5:login" @@ -820,6 +820,14 @@ struct option_t MuttVars[] = { ** the previous methods are unavailable. If a method is available but ** authentication fails, mutt will not connect to the IMAP server. */ + { "imap_check_subscribed", DT_BOOL, R_NONE, OPTIMAPCHECKSUBSCRIBED, 0 }, + /* + ** .pp + ** When \fIset\fP, mutt will fetch the set of subscribed folders from + ** your server on connection, and add them to the set of mailboxes + ** it polls for new mail. See also the ``$mailboxes'' and + ** ``$unmailboxes'' commands. + */ { "imap_delim_chars", DT_STR, R_NONE, UL &ImapDelimChars, UL "/." }, /* ** .pp @@ -871,7 +879,7 @@ struct option_t MuttVars[] = { { "imap_pass", DT_STR, R_NONE, UL &ImapPass, UL 0 }, /* ** .pp - ** Specifies the password for your IMAP account. If unset, Mutt will + ** Specifies the password for your IMAP account. If \fIunset\fP, Mutt will ** prompt you for your password when you invoke the fetch-mail function. ** \fBWarning\fP: you should only use this option when you are on a ** fairly secure machine, because the superuser can read your muttrc even @@ -880,7 +888,7 @@ struct option_t MuttVars[] = { { "imap_passive", DT_BOOL, R_NONE, OPTIMAPPASSIVE, 1 }, /* ** .pp - ** When set, mutt will not open new IMAP connections to check for new + ** When \fIset\fP, mutt will not open new IMAP connections to check for new ** mail. Mutt will only check for new mail over existing IMAP ** connections. This is useful if you don't want to be prompted to ** user/password pairs on mutt invocation, or if opening the connection @@ -889,7 +897,7 @@ struct option_t MuttVars[] = { { "imap_peek", DT_BOOL, R_NONE, OPTIMAPPEEK, 1 }, /* ** .pp - ** If set, mutt will avoid implicitly marking your mail as read whenever + ** When \fIset\fP, mutt will avoid implicitly marking your mail as read whenever ** you fetch a message from the server. This is generally a good thing, ** but can make closing an IMAP folder somewhat slower. This option ** exists to appease speed freaks. @@ -897,7 +905,7 @@ struct option_t MuttVars[] = { { "imap_servernoise", DT_BOOL, R_NONE, OPTIMAPSERVERNOISE, 1 }, /* ** .pp - ** When set, mutt will display warning messages from the IMAP + ** When \fIset\fP, mutt will display warning messages from the IMAP ** server as error messages. Since these messages are often ** harmless, or generated due to configuration problems on the ** server which are out of the users' hands, you may wish to suppress diff --git a/mutt.h b/mutt.h index 10653aba1..e27c2ed8e 100644 --- a/mutt.h +++ b/mutt.h @@ -368,6 +368,7 @@ enum OPTHIDETOPMISSING, OPTIGNORELISTREPLYTO, #ifdef USE_IMAP + OPTIMAPCHECKSUBSCRIBED, OPTIMAPLSUB, OPTIMAPPASSIVE, OPTIMAPPEEK,