X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=blobdiff_plain;f=browser.c;h=3ed8a11ca10d3b089eace9dd370bf35c6e38d5f5;hp=f509f0292b01b01ee2c3aa90286e4a01f1d0992e;hb=841a368ddea400022328f35dd8c7a3eb6f543892;hpb=0f44dc85fc1280372ffab911d701e703d803fb4b diff --git a/browser.c b/browser.c index f509f02..3ed8a11 100644 --- a/browser.c +++ b/browser.c @@ -12,15 +12,18 @@ #endif #include "mutt.h" +#include "mx.h" #include "mutt_curses.h" #include "mutt_menu.h" #include "buffy.h" #include "mapping.h" #include "sort.h" -#include "mailbox.h" #include "browser.h" +#include "attach.h" + #ifdef USE_IMAP #include "imap.h" +#include "imap/mx_imap.h" #endif #ifdef USE_NNTP #include "nntp.h" @@ -75,14 +78,14 @@ static void destroy_state (struct browser_state *state) int c; for (c = 0; c < state->entrylen; c++) { - FREE (&((state->entry)[c].name)); - FREE (&((state->entry)[c].desc)); - FREE (&((state->entry)[c].st)); + mem_free (&((state->entry)[c].name)); + mem_free (&((state->entry)[c].desc)); + mem_free (&((state->entry)[c].st)); } #ifdef USE_IMAP - FREE (&state->folder); + mem_free (&state->folder); #endif - FREE (&state->entry); + mem_free (&state->entry); } static int browser_compare_subject (const void *a, const void *b) @@ -90,7 +93,7 @@ static int browser_compare_subject (const void *a, const void *b) struct folder_file *pa = (struct folder_file *) a; struct folder_file *pb = (struct folder_file *) b; - int r = safe_strcoll (pa->name, pb->name); + int r = str_coll (pa->name, pb->name); return ((BrowserSort & SORT_REVERSE) ? -r : r); } @@ -271,7 +274,7 @@ static const char *folder_format_str (char *dest, size_t destlen, char op, case 'N': #ifdef USE_IMAP - if (mx_is_imap (folder->ff->desc)) { + if (imap_is_magic (folder->ff->desc, NULL) == M_IMAP) { if (!optional) { snprintf (tmp, sizeof (tmp), "%%%sd", fmt); snprintf (dest, destlen, tmp, folder->ff->new); @@ -423,7 +426,7 @@ static void add_folder (MUTTMENU * m, struct browser_state *state, { if (state->entrylen == state->entrymax) { /* need to allocate more space */ - safe_realloc (&state->entry, + mem_realloc (&state->entry, sizeof (struct folder_file) * (state->entrymax += 256)); memset (&state->entry[state->entrylen], 0, sizeof (struct folder_file) * 256); @@ -436,13 +439,13 @@ static void add_folder (MUTTMENU * m, struct browser_state *state, (state->entry)[state->entrylen].mtime = s->st_mtime; (state->entry)[state->entrylen].size = s->st_size; - (state->entry)[state->entrylen].st = safe_malloc (sizeof (struct stat)); + (state->entry)[state->entrylen].st = mem_malloc (sizeof (struct stat)); memcpy ((state->entry)[state->entrylen].st, s, sizeof (struct stat)); } (state->entry)[state->entrylen].new = new; - (state->entry)[state->entrylen].name = safe_strdup (name); - (state->entry)[state->entrylen].desc = safe_strdup (name); + (state->entry)[state->entrylen].name = str_dup (name); + (state->entry)[state->entrylen].desc = str_dup (name); #ifdef USE_IMAP (state->entry)[state->entrylen].imap = 0; #endif @@ -458,7 +461,7 @@ static void init_state (struct browser_state *state, MUTTMENU * menu) state->entrylen = 0; state->entrymax = 256; state->entry = - (struct folder_file *) safe_calloc (state->entrymax, + (struct folder_file *) mem_calloc (state->entrymax, sizeof (struct folder_file)); #ifdef USE_IMAP state->imap_browse = 0; @@ -477,14 +480,14 @@ static int examine_directory (MUTTMENU * menu, struct browser_state *state, NNTP_DATA *data; NNTP_SERVER *news = CurrentNewsSrv; -/* mutt_buffy_check (0); */ +/* buffy_check (0); */ init_state (state, menu); for (tmp = news->list; tmp; tmp = tmp->next) { if (!(data = (NNTP_DATA *) tmp->data)) continue; if (prefix && *prefix && strncmp (prefix, data->group, - safe_strlen (prefix)) != 0) + str_len (prefix)) != 0) continue; if (!((regexec (Mask.rx, data->group, 0, NULL, 0) == 0) ^ Mask.not)) continue; @@ -519,7 +522,7 @@ static int examine_directory (MUTTMENU * menu, struct browser_state *state, return (-1); } - mutt_buffy_check (0); + buffy_check (0); if ((dp = opendir (d)) == NULL) { mutt_perror (d); @@ -529,11 +532,11 @@ static int examine_directory (MUTTMENU * menu, struct browser_state *state, init_state (state, menu); while ((de = readdir (dp)) != NULL) { - if (safe_strcmp (de->d_name, ".") == 0) + if (str_cmp (de->d_name, ".") == 0) continue; /* we don't need . */ if (prefix && *prefix - && safe_strncmp (prefix, de->d_name, safe_strlen (prefix)) != 0) + && str_ncmp (prefix, de->d_name, str_len (prefix)) != 0) continue; if (!((regexec (Mask.rx, de->d_name, 0, NULL, 0) == 0) ^ Mask.not)) continue; @@ -568,7 +571,7 @@ static int examine_mailboxes (MUTTMENU * menu, struct browser_state *state) NNTP_DATA *data; NNTP_SERVER *news = CurrentNewsSrv; -/* mutt_buffy_check (0); */ +/* buffy_check (0); */ init_state (state, menu); for (tmp = news->list; tmp; tmp = tmp->next) { @@ -589,26 +592,27 @@ static int examine_mailboxes (MUTTMENU * menu, struct browser_state *state) if (!Incoming) return (-1); - mutt_buffy_check (0); + buffy_check (0); init_state (state, menu); for (i = 0; i < Incoming->length; i++) { tmp = (BUFFY*) Incoming->data[i]; + tmp->magic = mx_get_magic (tmp->path); #ifdef USE_IMAP - if (mx_is_imap (tmp->path)) { + if (tmp->magic == M_IMAP) { add_folder (menu, state, tmp->path, NULL, NULL, tmp->new); continue; } #endif #ifdef USE_POP - if (mx_is_pop (tmp->path)) { + if (tmp->magic == M_POP) { add_folder (menu, state, tmp->path, NULL, NULL, tmp->new); continue; } #endif #ifdef USE_NNTP - if (mx_is_nntp (tmp->path)) { + if (tmp->magic == M_NNTP) { add_folder (menu, state, tmp->path, NULL, NULL, tmp->new); continue; } @@ -685,7 +689,7 @@ static void init_menu (struct browser_state *state, MUTTMENU * menu, else #endif if (buffy) - snprintf (title, titlelen, _("Mailboxes [%d]"), mutt_buffy_check (0)); + snprintf (title, titlelen, _("Mailboxes [%d]"), buffy_check (0)); else { strfcpy (path, LastDir, sizeof (path)); mutt_pretty_mailbox (path); @@ -765,15 +769,15 @@ void _mutt_select_file (char *f, size_t flen, int flags, char ***files, if (*f) { mutt_expand_path (f, flen); #ifdef USE_IMAP - if (mx_is_imap (f)) { + if (imap_is_magic (f, NULL) == M_IMAP) { init_state (&state, NULL); state.imap_browse = 1; - imap_browse (f, &state); - strfcpy (LastDir, state.folder, sizeof (LastDir)); + if (!imap_browse (f, &state)) + strfcpy (LastDir, state.folder, sizeof (LastDir)); } else { #endif - for (i = safe_strlen (f) - 1; i > 0 && f[i] != '/'; i--); + for (i = str_len (f) - 1; i > 0 && f[i] != '/'; i--); if (i > 0) { if (f[0] == '/') { if (i > sizeof (LastDir) - 1) @@ -783,8 +787,8 @@ void _mutt_select_file (char *f, size_t flen, int flags, char ***files, } else { getcwd (LastDir, sizeof (LastDir)); - safe_strcat (LastDir, sizeof (LastDir), "/"); - safe_strncat (LastDir, sizeof (LastDir), f, i); + str_cat (LastDir, sizeof (LastDir), "/"); + str_ncat (LastDir, sizeof (LastDir), f, i); } } else { @@ -810,7 +814,7 @@ void _mutt_select_file (char *f, size_t flen, int flags, char ***files, strfcpy (LastDir, NONULL (Maildir), sizeof (LastDir)); #ifdef USE_IMAP - if (!buffy && mx_is_imap (LastDir)) { + if (!buffy && imap_is_magic (LastDir, NULL) == M_IMAP) { init_state (&state, NULL); state.imap_browse = 1; imap_browse (LastDir, &state); @@ -889,8 +893,8 @@ void _mutt_select_file (char *f, size_t flen, int flags, char ***files, /* save the old directory */ strfcpy (OldLastDir, LastDir, sizeof (OldLastDir)); - if (safe_strcmp (state.entry[menu->current].name, "..") == 0) { - if (safe_strcmp ("..", LastDir + safe_strlen (LastDir) - 2) == 0) + if (str_cmp (state.entry[menu->current].name, "..") == 0) { + if (str_cmp ("..", LastDir + str_len (LastDir) - 2) == 0) strcat (LastDir, "/.."); /* __STRCAT_CHECKED__ */ else { char *p = strrchr (LastDir + 1, '/'); @@ -918,7 +922,7 @@ void _mutt_select_file (char *f, size_t flen, int flags, char ***files, strfcpy (LastDir, state.entry[menu->current].name, sizeof (LastDir)); /* tack on delimiter here */ - n = safe_strlen (LastDir) + 1; + n = str_len (LastDir) + 1; /* special case "" needs no delimiter */ url_parse_ciss (&url, state.entry[menu->current].name); @@ -994,7 +998,7 @@ void _mutt_select_file (char *f, size_t flen, int flags, char ***files, if (menu->tagged) { *numfiles = menu->tagged; - tfiles = safe_calloc (*numfiles, sizeof (char *)); + tfiles = mem_calloc (*numfiles, sizeof (char *)); for (i = 0, j = 0; i < state.entrylen; i++) { struct folder_file ff = state.entry[i]; char full[_POSIX_PATH_MAX]; @@ -1002,16 +1006,16 @@ void _mutt_select_file (char *f, size_t flen, int flags, char ***files, if (ff.tagged) { mutt_concat_path (full, LastDir, ff.name, sizeof (full)); mutt_expand_path (full, sizeof (full)); - tfiles[j++] = safe_strdup (full); + tfiles[j++] = str_dup (full); } } *files = tfiles; } else if (f[0]) { /* no tagged entries. return selected entry */ *numfiles = 1; - tfiles = safe_calloc (*numfiles, sizeof (char *)); + tfiles = mem_calloc (*numfiles, sizeof (char *)); mutt_expand_path (f, flen); - tfiles[0] = safe_strdup (f); + tfiles[0] = str_dup (f); *files = tfiles; } } @@ -1089,8 +1093,8 @@ void _mutt_select_file (char *f, size_t flen, int flags, char ***files, if (mutt_yesorno (msg, M_NO) == M_YES) { if (!imap_delete_mailbox (Context, mx)) { /* free the mailbox from the browser */ - FREE (&((state.entry)[nentry].name)); - FREE (&((state.entry)[nentry].desc)); + mem_free (&((state.entry)[nentry].name)); + mem_free (&((state.entry)[nentry].desc)); /* and move all other entries up */ if (nentry + 1 < state.entrylen) memmove (state.entry + nentry, state.entry + nentry + 1, @@ -1105,7 +1109,7 @@ void _mutt_select_file (char *f, size_t flen, int flags, char ***files, } else mutt_message _("Mailbox not deleted."); - FREE (&mx.mbox); + mem_free (&mx.mbox); } break; #endif @@ -1123,7 +1127,7 @@ void _mutt_select_file (char *f, size_t flen, int flags, char ***files, #endif { /* add '/' at the end of the directory name if not already there */ - int len = safe_strlen (LastDir); + int len = str_len (LastDir); if (len && LastDir[len - 1] != '/' && sizeof (buf) > len) buf[len] = '/'; @@ -1134,7 +1138,7 @@ void _mutt_select_file (char *f, size_t flen, int flags, char ***files, buffy = 0; mutt_expand_path (buf, sizeof (buf)); #ifdef USE_IMAP - if (mx_is_imap (buf)) { + if (imap_is_magic (buf, NULL) == M_IMAP) { strfcpy (LastDir, buf, sizeof (LastDir)); destroy_state (&state); init_state (&state, NULL); @@ -1177,7 +1181,7 @@ void _mutt_select_file (char *f, size_t flen, int flags, char ***files, strfcpy (buf, NONULL (Mask.pattern), sizeof (buf)); if (mutt_get_field (_("File Mask: "), buf, sizeof (buf), 0) == 0) { - regex_t *rx = (regex_t *) safe_malloc (sizeof (regex_t)); + regex_t *rx = (regex_t *) mem_malloc (sizeof (regex_t)); char *s = buf; int not = 0, err; @@ -1195,13 +1199,13 @@ void _mutt_select_file (char *f, size_t flen, int flags, char ***files, if ((err = REGCOMP (rx, s, REG_NOSUB)) != 0) { regerror (err, rx, buf, sizeof (buf)); regfree (rx); - FREE (&rx); + mem_free (&rx); mutt_error ("%s", buf); } else { str_replace (&Mask.pattern, buf); regfree (Mask.rx); - FREE (&Mask.rx); + mem_free (&Mask.rx); Mask.rx = rx; Mask.not = not; @@ -1291,7 +1295,7 @@ void _mutt_select_file (char *f, size_t flen, int flags, char ***files, goto bail; } #ifdef USE_IMAP - else if (mx_is_imap (LastDir)) { + else if (imap_is_magic (LastDir, NULL) == M_IMAP) { init_state (&state, NULL); state.imap_browse = 1; imap_browse (LastDir, &state); @@ -1304,7 +1308,7 @@ void _mutt_select_file (char *f, size_t flen, int flags, char ***files, break; case OP_BUFFY_LIST: - mutt_buffy_list (); + buffy_list (); break; case OP_BROWSER_NEW_FILE: @@ -1382,11 +1386,11 @@ void _mutt_select_file (char *f, size_t flen, int flags, char ***files, folder.ff->st = NULL; folder.ff->is_new = nd->new; folder.ff->nd = nd; - FREE (&f->desc); + mem_free (&f->desc); mutt_FormatString (buffer, sizeof (buffer), NONULL(GroupFormat), newsgroup_format_str, (unsigned long) &folder, M_FORMAT_ARROWCURSOR); - f->desc = safe_strdup (buffer); */ + f->desc = str_dup (buffer); */ if (menu->current + 1 < menu->max) menu->current++; menu->redraw = REDRAW_MOTION_RESYNCH; @@ -1426,7 +1430,7 @@ void _mutt_select_file (char *f, size_t flen, int flags, char ***files, case OP_SUBSCRIBE_PATTERN: case OP_UNSUBSCRIBE_PATTERN: if (option (OPTNEWS)) { - regex_t *rx = (regex_t *) safe_malloc (sizeof (regex_t)); + regex_t *rx = (regex_t *) mem_malloc (sizeof (regex_t)); char *s = buf; int j = menu->current; NNTP_DATA *nd; @@ -1442,14 +1446,14 @@ void _mutt_select_file (char *f, size_t flen, int flags, char ***files, else snprintf (tmp, sizeof (tmp), _("Unsubscribe pattern: ")); if (mutt_get_field (tmp, buf, sizeof (buf), 0) != 0 || !buf[0]) { - FREE (&rx); + mem_free (&rx); break; } if ((err = REGCOMP (rx, s, REG_NOSUB)) != 0) { regerror (err, rx, buf, sizeof (buf)); regfree (rx); - FREE (&rx); + mem_free (&rx); mutt_error ("%s", buf); break; } @@ -1480,11 +1484,11 @@ void _mutt_select_file (char *f, size_t flen, int flags, char ***files, folder.f = NULL; folder.new = nd->new; folder.nd = nd; - FREE (&f->desc); + mem_free (&f->desc); mutt_FormatString (buffer, sizeof (buffer), NONULL(GroupFormat), newsgroup_format_str, (unsigned long) &folder, M_FORMAT_ARROWCURSOR); - f->desc = safe_strdup (buffer); + f->desc = str_dup (buffer); } */ } if (i == OP_BROWSER_SUBSCRIBE || i == OP_BROWSER_UNSUBSCRIBE) { @@ -1514,7 +1518,7 @@ void _mutt_select_file (char *f, size_t flen, int flags, char ***files, nntp_clear_cacheindex (news); if (i != OP_BROWSER_SUBSCRIBE && i != OP_BROWSER_UNSUBSCRIBE) regfree (rx); - FREE (&rx); + mem_free (&rx); } #ifdef USE_IMAP else