X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=blobdiff_plain;f=imap%2Fbrowse.c;h=e5d009f4288a886c5e9f501907ebd24f3c23fd4b;hp=b9d9220a17fd23b88f9881ea43b27fbd65e23508;hb=93f817273e1c70071cd5471594600bc70f12f0ff;hpb=c3e57678c8be193fc137854020f3a90887be97c9 diff --git a/imap/browse.c b/imap/browse.c index b9d9220..e5d009f 100644 --- a/imap/browse.c +++ b/imap/browse.c @@ -17,6 +17,11 @@ #include #include +#include "lib/mem.h" +#include "lib/str.h" +#include "lib/intl.h" +#include "lib/debug.h" + #include "mutt.h" #include "imap_private.h" @@ -50,7 +55,7 @@ int imap_browse (char *path, struct browser_state *state) int i; int nsup; char ctmp; - int nns; + int nns = 0; char *cur_folder; short showparents = 0; int noselect; @@ -93,9 +98,9 @@ int imap_browse (char *path, struct browser_state *state) imap_unquote_string (buf); /* As kludgy as it gets */ mbox[sizeof (mbox) - 1] = '\0'; strncpy (mbox, buf, sizeof (mbox) - 1); - n = mutt_strlen (mbox); + n = safe_strlen (mbox); - dprint (3, (debugfile, "imap_browse: mbox: %s\n", mbox)); + debug_print (3, ("mbox: %s\n", mbox)); /* if our target exists and has inferiors, enter it if we * aren't already going to */ @@ -111,7 +116,7 @@ int imap_browse (char *path, struct browser_state *state) imap_unmunge_mbox_name (cur_folder); if (!noinferiors && cur_folder[0] && - (n = strlen (mbox)) < LONG_STRING - 1) { + (n = safe_strlen (mbox)) < LONG_STRING - 1) { mbox[n++] = idata->delim; mbox[n] = '\0'; } @@ -144,7 +149,7 @@ int imap_browse (char *path, struct browser_state *state) mbox[n] = '\0'; if (showparents) { - dprint (3, (debugfile, "imap_init_browse: adding parent %s\n", mbox)); + debug_print (3, ("adding parent %s\n", mbox)); imap_add_folder (idata->delim, mbox, 1, 0, state, 1); } @@ -184,17 +189,17 @@ int imap_browse (char *path, struct browser_state *state) /* 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. */ - dprint (3, (debugfile, "imap_browse: adding INBOX\n")); + debug_print (3, ("adding INBOX\n")); if (browse_add_list_result (idata, "LIST \"\" \"INBOX\"", state, 0)) goto fail; } nsup = state->entrylen; - dprint (3, (debugfile, "imap_browse: Quoting mailbox scan: %s -> ", mbox)); + debug_print (3, ("Quoting mailbox scan: %s:\n", mbox)); snprintf (buf, sizeof (buf), "%s%%", mbox); imap_quote_string (buf2, sizeof (buf2), buf); - dprint (3, (debugfile, "%s\n", buf2)); + 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; @@ -215,8 +220,7 @@ 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); - dprint (3, (debugfile, "imap_browse: adding namespace: %s\n", - nsi[i].prefix)); + debug_print (3, ("adding namespace: %s\n", nsi[i].prefix)); } } @@ -237,23 +241,19 @@ int imap_mailbox_create (const char *folder) short n; if (imap_parse_path (folder, &mx) < 0) { - dprint (1, (debugfile, "imap_mailbox_create: Bad starting path %s\n", - folder)); + debug_print (1, ("Bad starting path %s\n", folder)); return -1; } if (!(idata = imap_conn_find (&mx.account, M_IMAP_CONN_NONEW))) { - dprint (1, - (debugfile, - "imap_mailbox_create: Couldn't find open connection to %s", - mx.account.host)); + debug_print (1, ("Couldn't find open connection to %s\n", mx.account.host)); goto fail; } strfcpy (buf, NONULL (mx.mbox), sizeof (buf)); /* append a delimiter if necessary */ - n = mutt_strlen (buf); + n = safe_strlen (buf); if (n && (n < sizeof (buf) - 1) && (buf[n - 1] != idata->delim)) { buf[n++] = idata->delim; buf[n] = '\0'; @@ -262,7 +262,7 @@ int imap_mailbox_create (const char *folder) if (mutt_get_field (_("Create mailbox: "), buf, sizeof (buf), M_FILE) < 0) goto fail; - if (!mutt_strlen (buf)) { + if (!safe_strlen (buf)) { mutt_error (_("Mailbox must have a name.")); mutt_sleep (1); goto fail; @@ -291,16 +291,12 @@ int imap_mailbox_rename (const char *mailbox) char newname[SHORT_STRING]; if (imap_parse_path (mailbox, &mx) < 0) { - dprint (1, (debugfile, "imap_mailbox_rename: Bad source mailbox %s\n", - mailbox)); + debug_print (1, ("Bad source mailbox %s\n", mailbox)); return -1; } if (!(idata = imap_conn_find (&mx.account, M_IMAP_CONN_NONEW))) { - dprint (1, - (debugfile, - "imap_mailbox_rename: Couldn't find open connection to %s", - mx.account.host)); + debug_print (1, ("Couldn't find open connection to %s\n", mx.account.host)); goto fail; } @@ -309,7 +305,7 @@ int imap_mailbox_rename (const char *mailbox) if (mutt_get_field (buf, newname, sizeof (newname), M_FILE) < 0) goto fail; - if (!mutt_strlen (newname)) { + if (!safe_strlen (newname)) { mutt_error (_("Mailbox must have a name.")); mutt_sleep (1); goto fail; @@ -342,9 +338,7 @@ static int browse_add_list_result (IMAP_DATA * idata, const char *cmd, IMAP_MBOX mx; if (imap_parse_path (state->folder, &mx)) { - dprint (2, (debugfile, - "browse_add_list_result: current folder %s makes no sense\n", - state->folder)); + debug_print (2, ("current folder %s makes no sense\n", state->folder)); return -1; } @@ -362,7 +356,7 @@ static int browse_add_list_result (IMAP_DATA * idata, const char *cmd, if (isparent) noselect = 1; /* prune current folder from output */ - if (isparent || mutt_strncmp (name, mx.mbox, strlen (name))) + if (isparent || safe_strncmp (name, mx.mbox, safe_strlen (name))) imap_add_folder (idata->delim, name, noselect, noinferiors, state, isparent); } @@ -400,8 +394,8 @@ static void imap_add_folder (char delim, char *folder, int noselect, if (isparent) strfcpy (relpath, "../", sizeof (relpath)); /* strip current folder from target, to render a relative path */ - else if (!mutt_strncmp (mx.mbox, folder, mutt_strlen (mx.mbox))) - strfcpy (relpath, folder + mutt_strlen (mx.mbox), sizeof (relpath)); + else if (!safe_strncmp (mx.mbox, folder, safe_strlen (mx.mbox))) + strfcpy (relpath, folder + safe_strlen (mx.mbox), sizeof (relpath)); else strfcpy (relpath, folder, sizeof (relpath)); @@ -417,9 +411,9 @@ static void imap_add_folder (char delim, char *folder, int noselect, (state->entry)[state->entrylen].name = safe_strdup (tmp); /* mark desc with delim in browser if it can have subfolders */ - if (!isparent && !noinferiors && strlen (relpath) < sizeof (relpath) - 1) { - relpath[strlen (relpath) + 1] = '\0'; - relpath[strlen (relpath)] = delim; + if (!isparent && !noinferiors && safe_strlen (relpath) < sizeof (relpath) - 1) { + relpath[safe_strlen (relpath) + 1] = '\0'; + relpath[safe_strlen (relpath)] = delim; } (state->entry)[state->entrylen].desc = safe_strdup (relpath); @@ -438,7 +432,7 @@ static void imap_add_folder (char delim, char *folder, int noselect, static int compare_names (struct folder_file *a, struct folder_file *b) { - return mutt_strcmp (a->name, b->name); + return safe_strcmp (a->name, b->name); } static int browse_get_namespace (IMAP_DATA * idata, char *nsbuf, int nsblen, @@ -505,8 +499,7 @@ 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)) { - dprint (3, - (debugfile, "browse_get_namespace: adding %s\n", ns)); + 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