X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=blobdiff_plain;f=imap%2Fbrowse.c;h=85a64b19acfc34cf77f44db30ad022a559a91270;hp=1410829459698a51823acbf6b6eea8b0fdfcec2c;hb=819c071fa7efc8dffb4dd92f36f0111227ff692f;hpb=be393b838c5e0b8dfe9bedcc7a4a63f05caae7c4 diff --git a/imap/browse.c b/imap/browse.c index 1410829..85a64b1 100644 --- a/imap/browse.c +++ b/imap/browse.c @@ -10,17 +10,7 @@ /* Mutt browser support routines */ -#if HAVE_CONFIG_H -# include "config.h" -#endif - -#include -#include - -#include "lib/mem.h" -#include "lib/str.h" -#include "lib/intl.h" -#include "lib/debug.h" +#include #include "mutt.h" #include "imap_private.h" @@ -70,8 +60,8 @@ int imap_browse (char *path, struct browser_state *state) save_lsub = option (OPTIMAPCHECKSUBSCRIBED); unset_option (OPTIMAPCHECKSUBSCRIBED); - strfcpy (list_cmd, option (OPTIMAPLSUB) ? "LSUB" : "LIST", - sizeof (list_cmd)); + m_strcpy(list_cmd, sizeof(list_cmd), + option(OPTIMAPLSUB) ? "LSUB" : "LIST"); if (!(idata = imap_conn_find (&(mx.account), 0))) goto fail; @@ -79,7 +69,6 @@ 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 = str_dup (ImapHomeNamespace); if (mutt_bit_isset (idata->capabilities, NAMESPACE)) { mutt_message _("Getting namespaces..."); @@ -98,11 +87,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 = str_len (mbox); - - debug_print (3, ("mbox: %s\n", mbox)); + m_strcpy(mbox, sizeof(mbox), buf); + n = m_strlen(mbox); /* if our target exists and has inferiors, enter it if we * aren't already going to */ @@ -118,13 +104,12 @@ int imap_browse (char *path, struct browser_state *state) imap_unmunge_mbox_name (cur_folder); if (!noinferiors && cur_folder[0] && - (n = str_len (mbox)) < LONG_STRING - 1) { + (n = m_strlen(mbox)) < LONG_STRING - 1) { mbox[n++] = idata->delim; mbox[n] = '\0'; } } - } - while (ascii_strncmp (idata->cmd.buf, idata->cmd.seq, SEQLEN)); + } while (m_strncmp(idata->cmd.buf.data, idata->cmd.seq, SEQLEN)); } /* if we're descending a folder, mark it as current in browser_state */ @@ -133,7 +118,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 = str_dup (buf); + state->folder = m_strdup(buf); n--; } @@ -151,7 +136,6 @@ int imap_browse (char *path, struct browser_state *state) mbox[n] = '\0'; if (showparents) { - debug_print (3, ("adding parent %s\n", mbox)); imap_add_folder (idata->delim, mbox, 1, 0, state, 1); } @@ -162,7 +146,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 = str_dup (buf); + state->folder = m_strdup(buf); } mbox[n] = ctmp; } @@ -176,7 +160,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 = str_dup (buf); + state->folder = m_strdup(buf); } } } @@ -184,24 +168,21 @@ 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 = str_dup (buf); + state->folder = m_strdup(buf); } if (home_namespace && mbox[0] != '\0') { /* Listing the home namespace, so INBOX should be included. Home * namespace is not "", so we have to list it explicitly. We ask the * server to see if it has descendants. */ - debug_print (3, ("adding INBOX\n")); if (browse_add_list_result (idata, "LIST \"\" \"INBOX\"", state, 0)) goto fail; } nsup = state->entrylen; - debug_print (3, ("Quoting mailbox scan: %s:\n", mbox)); snprintf (buf, sizeof (buf), "%s%%", mbox); imap_quote_string (buf2, sizeof (buf2), buf); - debug_print (3, ("%s\n", buf2)); snprintf (buf, sizeof (buf), "%s \"\" %s", list_cmd, buf2); if (browse_add_list_result (idata, buf, state, 0)) goto fail; @@ -222,20 +203,19 @@ int imap_browse (char *path, struct browser_state *state) if (nsi[i].listable && !nsi[i].home_namespace) { imap_add_folder (nsi[i].delim, nsi[i].prefix, nsi[i].noselect, nsi[i].noinferiors, state, 0); - debug_print (3, ("adding namespace: %s\n", nsi[i].prefix)); } } if (save_lsub) set_option (OPTIMAPCHECKSUBSCRIBED); - mem_free (&mx.mbox); + p_delete(&mx.mbox); return 0; fail: if (save_lsub) set_option (OPTIMAPCHECKSUBSCRIBED); - mem_free (&mx.mbox); + p_delete(&mx.mbox); return -1; } @@ -248,20 +228,18 @@ int imap_mailbox_create (const char *folder) short n; if (imap_parse_path (folder, &mx) < 0) { - debug_print (1, ("Bad starting path %s\n", folder)); return -1; } if (!(idata = imap_conn_find (&mx.account, M_IMAP_CONN_NONEW))) { - debug_print (1, ("Couldn't find open connection to %s\n", mx.account.host)); goto fail; } - strfcpy (buf, NONULL (mx.mbox), sizeof (buf)); + m_strcpy(buf, sizeof(buf), NONULL(mx.mbox)); /* append a delimiter if necessary */ - n = str_len (buf); - if (n && (n < sizeof (buf) - 1) && (buf[n - 1] != idata->delim)) { + n = m_strlen(buf); + if (n && (n < ssizeof (buf) - 1) && (buf[n - 1] != idata->delim)) { buf[n++] = idata->delim; buf[n] = '\0'; } @@ -269,7 +247,7 @@ int imap_mailbox_create (const char *folder) if (mutt_get_field (_("Create mailbox: "), buf, sizeof (buf), M_FILE) < 0) goto fail; - if (!str_len (buf)) { + if (!m_strlen(buf)) { mutt_error (_("Mailbox must have a name.")); mutt_sleep (1); goto fail; @@ -282,11 +260,11 @@ int imap_mailbox_create (const char *folder) mutt_sleep (0); - mem_free (&mx.mbox); + p_delete(&mx.mbox); return 0; fail: - mem_free (&mx.mbox); + p_delete(&mx.mbox); return -1; } @@ -295,15 +273,13 @@ int imap_mailbox_rename (const char *mailbox) IMAP_DATA *idata; IMAP_MBOX mx; char buf[LONG_STRING]; - char newname[SHORT_STRING]; + char newname[STRING]; if (imap_parse_path (mailbox, &mx) < 0) { - debug_print (1, ("Bad source mailbox %s\n", mailbox)); return -1; } if (!(idata = imap_conn_find (&mx.account, M_IMAP_CONN_NONEW))) { - debug_print (1, ("Couldn't find open connection to %s\n", mx.account.host)); goto fail; } @@ -312,14 +288,15 @@ int imap_mailbox_rename (const char *mailbox) if (mutt_get_field (buf, newname, sizeof (newname), M_FILE) < 0) goto fail; - if (!str_len (newname)) { + if (!m_strlen(newname)) { mutt_error (_("Mailbox must have a name.")); mutt_sleep (1); goto fail; } if (imap_rename_mailbox (idata, &mx, newname) < 0) { - mutt_error (_("Rename failed: %s"), imap_get_qualifier (idata->cmd.buf)); + mutt_error (_("Rename failed: %s"), + imap_get_qualifier(idata->cmd.buf.data)); mutt_sleep (1); goto fail; } @@ -327,11 +304,11 @@ int imap_mailbox_rename (const char *mailbox) mutt_message (_("Mailbox renamed.")); mutt_sleep (0); - mem_free (&mx.mbox); + p_delete(&mx.mbox); return 0; fail: - mem_free (&mx.mbox); + p_delete(&mx.mbox); return -1; } @@ -345,7 +322,6 @@ static int browse_add_list_result (IMAP_DATA * idata, const char *cmd, IMAP_MBOX mx; if (imap_parse_path (state->folder, &mx)) { - debug_print (2, ("current folder %s makes no sense\n", state->folder)); return -1; } @@ -354,7 +330,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) { - mem_free (&mx.mbox); + p_delete(&mx.mbox); return -1; } @@ -363,14 +339,13 @@ static int browse_add_list_result (IMAP_DATA * idata, const char *cmd, if (isparent) noselect = 1; /* prune current folder from output */ - if (isparent || str_ncmp (name, mx.mbox, str_len (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)); + } while ((m_strncmp(idata->cmd.buf.data, idata->cmd.seq, SEQLEN) != 0)); - mem_free (&mx.mbox); + p_delete(&mx.mbox); return 0; } @@ -390,40 +365,38 @@ static void imap_add_folder (char delim, char *folder, int noselect, imap_unmunge_mbox_name (folder); if (state->entrylen + 1 == state->entrymax) { - mem_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 (!str_ncmp (mx.mbox, folder, str_len (mx.mbox))) - strfcpy (relpath, folder + str_len (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)) { - mem_free (&mx.mbox); + if (!((regexec (Mask.rx, relpath, 0, NULL, 0) == 0) ^ Mask.neg)) { + p_delete(&mx.mbox); return; } imap_qualify_path (tmp, sizeof (tmp), &mx, folder); - (state->entry)[state->entrylen].name = str_dup (tmp); + (state->entry)[state->entrylen].name = m_strdup(tmp); /* mark desc with delim in browser if it can have subfolders */ - if (!isparent && !noinferiors && str_len (relpath) < sizeof (relpath) - 1) { - relpath[str_len (relpath) + 1] = '\0'; - relpath[str_len (relpath)] = delim; + if (!isparent && !noinferiors && m_strlen(relpath) < ssizeof (relpath) - 1) { + relpath[m_strlen(relpath) + 1] = '\0'; + relpath[m_strlen(relpath)] = delim; } - (state->entry)[state->entrylen].desc = str_dup (relpath); + (state->entry)[state->entrylen].desc = m_strdup(relpath); (state->entry)[state->entrylen].imap = 1; /* delimiter at the root is useless. */ @@ -434,12 +407,12 @@ static void imap_add_folder (char delim, char *folder, int noselect, (state->entry)[state->entrylen].inferiors = !noinferiors; (state->entrylen)++; - mem_free (&mx.mbox); + p_delete(&mx.mbox); } static int compare_names (struct folder_file *a, struct folder_file *b) { - return str_cmp (a->name, b->name); + return m_strcmp(a->name, b->name); } static int browse_get_namespace (IMAP_DATA * idata, char *nsbuf, int nsblen, @@ -463,7 +436,7 @@ static int browse_get_namespace (IMAP_DATA * idata, char *nsbuf, int nsblen, if ((rc = imap_cmd_step (idata)) != IMAP_CMD_CONTINUE) break; - s = imap_next_word (idata->cmd.buf); + s = imap_next_word (idata->cmd.buf.data); if (ascii_strncasecmp ("NAMESPACE", s, 9) == 0) { /* There are three sections to the response, User, Other, Shared, * and maybe more by extension */ @@ -506,7 +479,6 @@ static int browse_get_namespace (IMAP_DATA * idata, char *nsbuf, int nsblen, } /* skip "" namespaces, they are already listed at the root */ if ((ns[0] != '\0') && (nsbused < nsblen) && (*nns < nsilen)) { - debug_print (3, ("adding %s\n", ns)); nsi->type = type; /* Cyrus doesn't append the delimiter to the namespace, * but UW-IMAP does. We'll strip it here and add it back @@ -567,8 +539,7 @@ static int browse_verify_namespace (IMAP_DATA * idata, &nsi->noinferiors, &delim) != 0) return -1; nsi->listable |= (name != NULL); - } - while ((ascii_strncmp (idata->cmd.buf, idata->cmd.seq, SEQLEN) != 0)); + } while ((m_strncmp(idata->cmd.buf.data, idata->cmd.seq, SEQLEN) != 0)); } return 0;