X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=blobdiff_plain;f=imap%2Fbrowse.c;h=65f94f22262dfcbb7adf6553bf7a204f9d0632cc;hp=e5d009f4288a886c5e9f501907ebd24f3c23fd4b;hb=3e9a92ab72e04aecb0fc4098098a1b57c5101d84;hpb=93f817273e1c70071cd5471594600bc70f12f0ff diff --git a/imap/browse.c b/imap/browse.c index e5d009f..65f94f2 100644 --- a/imap/browse.c +++ b/imap/browse.c @@ -17,10 +17,14 @@ #include #include -#include "lib/mem.h" -#include "lib/str.h" -#include "lib/intl.h" -#include "lib/debug.h" +#include +#include +#include +#include +#include + +#include + #include "mutt.h" #include "imap_private.h" @@ -60,6 +64,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)) { @@ -67,8 +72,10 @@ int imap_browse (char *path, struct browser_state *state) return -1; } - strfcpy (list_cmd, option (OPTIMAPLSUB) ? "LSUB" : "LIST", - sizeof (list_cmd)); + save_lsub = option (OPTIMAPCHECKSUBSCRIBED); + unset_option (OPTIMAPCHECKSUBSCRIBED); + m_strcpy(list_cmd, sizeof(list_cmd), + option(OPTIMAPLSUB) ? "LSUB" : "LIST"); if (!(idata = imap_conn_find (&(mx.account), 0))) goto fail; @@ -76,8 +83,7 @@ int imap_browse (char *path, struct browser_state *state) if (!mx.mbox) { home_namespace = 1; mbox[0] = '\0'; /* Do not replace "" with "INBOX" here */ - mx.mbox = safe_strdup (ImapHomeNamespace); - nns = 0; + mx.mbox = m_strdup(ImapHomeNamespace); if (mutt_bit_isset (idata->capabilities, NAMESPACE)) { mutt_message _("Getting namespaces..."); @@ -96,9 +102,8 @@ int imap_browse (char *path, struct browser_state *state) imap_fix_path (idata, mx.mbox, mbox, sizeof (mbox)); imap_munge_mbox_name (buf, sizeof (buf), mbox); imap_unquote_string (buf); /* As kludgy as it gets */ - mbox[sizeof (mbox) - 1] = '\0'; - strncpy (mbox, buf, sizeof (mbox) - 1); - n = safe_strlen (mbox); + m_strcpy(mbox, sizeof(mbox), buf); + n = m_strlen(mbox); debug_print (3, ("mbox: %s\n", mbox)); @@ -116,7 +121,7 @@ int imap_browse (char *path, struct browser_state *state) imap_unmunge_mbox_name (cur_folder); if (!noinferiors && cur_folder[0] && - (n = safe_strlen (mbox)) < LONG_STRING - 1) { + (n = m_strlen(mbox)) < LONG_STRING - 1) { mbox[n++] = idata->delim; mbox[n] = '\0'; } @@ -131,7 +136,7 @@ int imap_browse (char *path, struct browser_state *state) if (!home_namespace) showparents = 1; imap_qualify_path (buf, sizeof (buf), &mx, mbox); - state->folder = safe_strdup (buf); + state->folder = m_strdup(buf); n--; } @@ -160,7 +165,7 @@ int imap_browse (char *path, struct browser_state *state) ctmp = mbox[n]; mbox[n] = '\0'; imap_qualify_path (buf, sizeof (buf), &mx, mbox); - state->folder = safe_strdup (buf); + state->folder = m_strdup(buf); } mbox[n] = ctmp; } @@ -174,7 +179,7 @@ int imap_browse (char *path, struct browser_state *state) imap_add_folder (idata->delim, relpath, 1, 0, state, 1); if (!state->folder) { imap_qualify_path (buf, sizeof (buf), &mx, relpath); - state->folder = safe_strdup (buf); + state->folder = m_strdup(buf); } } } @@ -182,7 +187,7 @@ int imap_browse (char *path, struct browser_state *state) /* no namespace, no folder: set folder to host only */ if (!state->folder) { imap_qualify_path (buf, sizeof (buf), &mx, NULL); - state->folder = safe_strdup (buf); + state->folder = m_strdup(buf); } if (home_namespace && mbox[0] != '\0') { @@ -224,11 +229,16 @@ int imap_browse (char *path, struct browser_state *state) } } - FREE (&mx.mbox); + if (save_lsub) + set_option (OPTIMAPCHECKSUBSCRIBED); + + p_delete(&mx.mbox); return 0; fail: - FREE (&mx.mbox); + if (save_lsub) + set_option (OPTIMAPCHECKSUBSCRIBED); + p_delete(&mx.mbox); return -1; } @@ -250,10 +260,10 @@ int imap_mailbox_create (const char *folder) goto fail; } - strfcpy (buf, NONULL (mx.mbox), sizeof (buf)); + m_strcpy(buf, sizeof(buf), NONULL(mx.mbox)); /* append a delimiter if necessary */ - n = safe_strlen (buf); + n = m_strlen(buf); if (n && (n < sizeof (buf) - 1) && (buf[n - 1] != idata->delim)) { buf[n++] = idata->delim; buf[n] = '\0'; @@ -262,7 +272,7 @@ int imap_mailbox_create (const char *folder) if (mutt_get_field (_("Create mailbox: "), buf, sizeof (buf), M_FILE) < 0) goto fail; - if (!safe_strlen (buf)) { + if (!m_strlen(buf)) { mutt_error (_("Mailbox must have a name.")); mutt_sleep (1); goto fail; @@ -275,11 +285,11 @@ int imap_mailbox_create (const char *folder) mutt_sleep (0); - FREE (&mx.mbox); + p_delete(&mx.mbox); return 0; fail: - FREE (&mx.mbox); + p_delete(&mx.mbox); return -1; } @@ -305,7 +315,7 @@ int imap_mailbox_rename (const char *mailbox) if (mutt_get_field (buf, newname, sizeof (newname), M_FILE) < 0) goto fail; - if (!safe_strlen (newname)) { + if (!m_strlen(newname)) { mutt_error (_("Mailbox must have a name.")); mutt_sleep (1); goto fail; @@ -320,11 +330,11 @@ int imap_mailbox_rename (const char *mailbox) mutt_message (_("Mailbox renamed.")); mutt_sleep (0); - FREE (&mx.mbox); + p_delete(&mx.mbox); return 0; fail: - FREE (&mx.mbox); + p_delete(&mx.mbox); return -1; } @@ -347,7 +357,7 @@ static int browse_add_list_result (IMAP_DATA * idata, const char *cmd, do { if (imap_parse_list_response (idata, &name, &noselect, &noinferiors, &idata->delim) != 0) { - FREE (&mx.mbox); + p_delete(&mx.mbox); return -1; } @@ -356,14 +366,14 @@ static int browse_add_list_result (IMAP_DATA * idata, const char *cmd, if (isparent) noselect = 1; /* prune current folder from output */ - if (isparent || safe_strncmp (name, mx.mbox, safe_strlen (name))) + if (isparent || m_strncmp(name, mx.mbox, m_strlen(name))) imap_add_folder (idata->delim, name, noselect, noinferiors, state, isparent); } } while ((ascii_strncmp (idata->cmd.buf, idata->cmd.seq, SEQLEN) != 0)); - FREE (&mx.mbox); + p_delete(&mx.mbox); return 0; } @@ -383,40 +393,38 @@ static void imap_add_folder (char delim, char *folder, int noselect, imap_unmunge_mbox_name (folder); if (state->entrylen + 1 == state->entrymax) { - safe_realloc (&state->entry, - sizeof (struct folder_file) * (state->entrymax += 256)); - memset (state->entry + state->entrylen, 0, - (sizeof (struct folder_file) * - (state->entrymax - state->entrylen))); + p_realloc(&state->entry, state->entrymax += 256); + p_clear(state->entry + state->entrylen, + state->entrymax - state->entrylen); } /* render superiors as unix-standard ".." */ if (isparent) - strfcpy (relpath, "../", sizeof (relpath)); + m_strcpy(relpath, sizeof(relpath), "../"); /* strip current folder from target, to render a relative path */ - else if (!safe_strncmp (mx.mbox, folder, safe_strlen (mx.mbox))) - strfcpy (relpath, folder + safe_strlen (mx.mbox), sizeof (relpath)); + else if (!m_strncmp(mx.mbox, folder, m_strlen(mx.mbox))) + m_strcpy(relpath, sizeof(relpath), folder + m_strlen(mx.mbox)); else - strfcpy (relpath, folder, sizeof (relpath)); + m_strcpy(relpath, sizeof(relpath), folder); /* apply filemask filter. This should really be done at menu setup rather * than at scan, since it's so expensive to scan. But that's big changes * to browser.c */ if (!((regexec (Mask.rx, relpath, 0, NULL, 0) == 0) ^ Mask.not)) { - FREE (&mx.mbox); + p_delete(&mx.mbox); return; } imap_qualify_path (tmp, sizeof (tmp), &mx, folder); - (state->entry)[state->entrylen].name = safe_strdup (tmp); + (state->entry)[state->entrylen].name = m_strdup(tmp); /* mark desc with delim in browser if it can have subfolders */ - if (!isparent && !noinferiors && safe_strlen (relpath) < sizeof (relpath) - 1) { - relpath[safe_strlen (relpath) + 1] = '\0'; - relpath[safe_strlen (relpath)] = delim; + if (!isparent && !noinferiors && m_strlen(relpath) < sizeof (relpath) - 1) { + relpath[m_strlen(relpath) + 1] = '\0'; + relpath[m_strlen(relpath)] = delim; } - (state->entry)[state->entrylen].desc = safe_strdup (relpath); + (state->entry)[state->entrylen].desc = m_strdup(relpath); (state->entry)[state->entrylen].imap = 1; /* delimiter at the root is useless. */ @@ -427,12 +435,12 @@ static void imap_add_folder (char delim, char *folder, int noselect, (state->entry)[state->entrylen].inferiors = !noinferiors; (state->entrylen)++; - FREE (&mx.mbox); + p_delete(&mx.mbox); } static int compare_names (struct folder_file *a, struct folder_file *b) { - return safe_strcmp (a->name, b->name); + return m_strcmp(a->name, b->name); } static int browse_get_namespace (IMAP_DATA * idata, char *nsbuf, int nsblen,