diff options
author | Kevin McCarthy <kevin@8t8.us> | 2020-07-06 20:17:59 -0700 |
---|---|---|
committer | Kevin McCarthy <kevin@8t8.us> | 2020-07-06 20:17:59 -0700 |
commit | b48f8e1e1510ff1560921a912aa124043a936f05 (patch) | |
tree | df40504ad61c1477587a49ca31365a192f24067d | |
parent | 25f82cf6031c9c37696590924858cf553f51596f (diff) |
Directly add/remove mailboxes for IMAP.
The LSUB processor along with <subscribe> and <unsubscribe> would
construct a mailboxes command and send it to the muttrc parser.
Since the poll/label refactor it's much easier to just directly call
the functions, and is much more secure. So do that instead.
-rw-r--r-- | buffy.c | 32 | ||||
-rw-r--r-- | buffy.h | 3 | ||||
-rw-r--r-- | imap/command.c | 25 | ||||
-rw-r--r-- | imap/imap.c | 16 |
4 files changed, 41 insertions, 35 deletions
@@ -269,20 +269,25 @@ static BUFFY **find_buffy_slot (const char *path) } /* To avoid overwriting existing values: - * - label will be NULL if unspecified - * - nopoll will be -1 if unspecified + * - label should be NULL if unspecified + * - nopoll should be -1 if unspecified */ -static void buffy_add (BUFFER *path, const char *label, int nopoll) +void mutt_buffy_add (const char *path, const char *label, int nopoll) { BUFFY **tmp; struct stat sb; int new = 0; - tmp = find_buffy_slot (mutt_b2s (path)); + if (!path || !*path) + return; + + dprint (3, (debugfile, "mutt_buffy_add: %s\n", path)); + + tmp = find_buffy_slot (path); if (!*tmp) { new = 1; - *tmp = buffy_new (mutt_b2s (path)); + *tmp = buffy_new (path); #ifdef USE_SIDEBAR mutt_sb_notify_mailbox (*tmp, 1); #endif @@ -346,6 +351,20 @@ static void buffy_remove (BUFFY **pbuffy) *pbuffy = next; } +void mutt_buffy_remove (const char *path) +{ + BUFFY **pbuffy; + + if (!path || !*path) + return; + + dprint (3, (debugfile, "mutt_buffy_remove: %s\n", path)); + + pbuffy = find_buffy_slot (path); + if (*pbuffy) + buffy_remove (pbuffy); +} + int mutt_parse_mailboxes (BUFFER *path, BUFFER *s, union pointer_long_t udata, BUFFER *err) { @@ -400,7 +419,8 @@ int mutt_parse_mailboxes (BUFFER *path, BUFFER *s, union pointer_long_t udata, } } else - buffy_add (mailbox, label_set ? mutt_b2s (label) : NULL, nopoll); + mutt_buffy_add (mutt_b2s (mailbox), label_set ? mutt_b2s (label) : NULL, + nopoll); mutt_buffer_clear (mailbox); mutt_buffer_clear (label); @@ -50,6 +50,9 @@ WHERE short BuffyCheckStatsInterval INITVAL (60); extern time_t BuffyDoneTime; /* last time we knew for sure how much mail there was */ +void mutt_buffy_add (const char *path, const char *label, int nopoll); +void mutt_buffy_remove (const char *path); + void mutt_buffer_buffy (BUFFER *); void mutt_buffy (char *, size_t); diff --git a/imap/command.c b/imap/command.c index 1cf02257..5ca04bf0 100644 --- a/imap/command.c +++ b/imap/command.c @@ -1005,9 +1005,7 @@ static void cmd_parse_list (IMAP_DATA* idata, char* s) static void cmd_parse_lsub (IMAP_DATA* idata, char* s) { - char buf[STRING]; - char quoted_name[STRING]; - BUFFER err; + BUFFER *mailbox = NULL; ciss_url_t url; IMAP_LIST list; @@ -1031,23 +1029,16 @@ static void cmd_parse_lsub (IMAP_DATA* idata, char* s) dprint (3, (debugfile, "Subscribing to %s\n", list.name)); - strfcpy (buf, "mailboxes \"", sizeof (buf)); mutt_account_tourl (&idata->conn->account, &url); - /* escape \ and ". Also escape ` because the resulting - * string will be passed to mutt_parse_rc_line. */ - imap_quote_string_and_backquotes (quoted_name, sizeof (quoted_name), list.name); - url.path = quoted_name + 1; - url.path[strlen(url.path) - 1] = '\0'; + url.path = list.name; if (!mutt_strcmp (url.user, ImapUser)) url.user = NULL; - url_ciss_tostring (&url, buf + 11, sizeof (buf) - 11, 0); - safe_strcat (buf, sizeof (buf), "\""); - mutt_buffer_init (&err); - err.dsize = STRING; - err.data = safe_malloc (err.dsize); - if (mutt_parse_rc_line (buf, &err)) - dprint (1, (debugfile, "Error adding subscribed mailbox: %s\n", err.data)); - FREE (&err.data); + + mailbox = mutt_buffer_pool_get (); + url_ciss_tobuffer (&url, mailbox, 0); + + mutt_buffy_add (mutt_b2s (mailbox), NULL, -1); + mutt_buffer_pool_release (&mailbox); } /* cmd_parse_myrights: set rights bits according to MYRIGHTS response */ diff --git a/imap/imap.c b/imap/imap.c index fab91837..dcd2686f 100644 --- a/imap/imap.c +++ b/imap/imap.c @@ -2267,8 +2267,6 @@ int imap_subscribe (char *path, int subscribe) IMAP_DATA *idata; char buf[LONG_STRING*2]; char mbox[LONG_STRING]; - int mblen; - BUFFER err; IMAP_MBOX mx; if (!mx_is_imap (path) || imap_parse_path (path, &mx) || !mx.mbox) @@ -2285,16 +2283,10 @@ int imap_subscribe (char *path, int subscribe) if (option (OPTIMAPCHECKSUBSCRIBED)) { - mutt_buffer_init (&err); - err.dsize = STRING; - err.data = safe_malloc (err.dsize); - mblen = snprintf (mbox, sizeof (mbox), "%smailboxes ", - subscribe ? "" : "un"); - imap_quote_string_and_backquotes (mbox + mblen, sizeof(mbox) - mblen, - path); - if (mutt_parse_rc_line (mbox, &err)) - dprint (1, (debugfile, "Error adding subscribed mailbox: %s\n", err.data)); - FREE (&err.data); + if (subscribe) + mutt_buffy_add (path, NULL, -1); + else + mutt_buffy_remove (path); } if (subscribe) |