]> granicus.if.org Git - neomutt/commitdiff
New option: $imap_check_subscribed. If set, mutt will fetch the set of
authorBrendan Cully <brendan@kublai.com>
Sun, 7 Aug 2005 23:52:07 +0000 (23:52 +0000)
committerBrendan Cully <brendan@kublai.com>
Sun, 7 Aug 2005 23:52:07 +0000 (23:52 +0000)
subscribed mailboxes from the server and add them to the buffy list.

imap/browse.c
imap/command.c
imap/imap.c
init.h
mutt.h

index 0e7ec990d607a10d502615cc088100f0653d8640..4d1d445e1b62488dffeb1607a1460453ff734b8d 100644 (file)
@@ -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;
 }
index 74fa21a07c014acdb736e2c8509e94e390fc1bc6..20f76cabd7ed239fdd2d99fae6f74952feebd25a 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Copyright (C) 1996-8 Michael R. Elkins <me@mutt.org>
  * Copyright (C) 1996-9 Brandon Long <blong@fiction.net>
- * Copyright (C) 1999-2002 Brendan Cully <brendan@kublai.com>
+ * Copyright (C) 1999-2005 Brendan Cully <brendan@kublai.com>
  * 
  *     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)
 {
index 731258c86865d862f6c8694ae4104e38e14da6f7..4e7ad5b14d47a952ee104f0bc7f4f1e52924d275 100644 (file)
@@ -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 3e57ec5a77b1767d30aefd7da8368fb8999ed535..0ec78c7417b0ebb857fcfb9ac301e1a4786be1f5 100644 (file)
--- 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 10653aba19c093742ac56c9d00c31d99ea81565c..e27c2ed8e81858d2988fd45e59235ec7e55a8424 100644 (file)
--- a/mutt.h
+++ b/mutt.h
@@ -368,6 +368,7 @@ enum
   OPTHIDETOPMISSING,
   OPTIGNORELISTREPLYTO,
 #ifdef USE_IMAP
+  OPTIMAPCHECKSUBSCRIBED,
   OPTIMAPLSUB,
   OPTIMAPPASSIVE,
   OPTIMAPPEEK,