From: Pierre Habouzit Date: Wed, 29 Nov 2006 23:44:50 +0000 (+0100) Subject: small detail in m_dirname. X-Git-Url: http://git.madism.org/?a=commitdiff_plain;h=6c9a7df6f0a909d987634888cbb7ccd9b17ecc09;p=apps%2Fmadmutt.git small detail in m_dirname. use m_dirname in recvattach.c rather than some cumbersome code. also fix the 'last used folder' semantics --- diff --git a/lib-lib/file.c b/lib-lib/file.c index 5e37996..4cd3b83 100644 --- a/lib-lib/file.c +++ b/lib-lib/file.c @@ -366,7 +366,7 @@ const char *mutt_basename(const char *f) ssize_t m_dirname(char *dst, ssize_t dlen, const char *path) { - int plen = m_strlen(path); + ssize_t plen = m_strlen(path); while (plen > 0 && path[plen - 1] == '/') plen--; diff --git a/recvattach.c b/recvattach.c index b76c43a..dc51b4d 100644 --- a/recvattach.c +++ b/recvattach.c @@ -11,33 +11,21 @@ #include #include +#include #include #include #include #include - -#include +#include #include "mutt.h" #include "handler.h" #include "recvattach.h" #include "attach.h" #include "copy.h" -#include - -static const char *Mailbox_is_read_only = N_("Mailbox is read-only."); -static char LastSaveFolder[_POSIX_PATH_MAX] = ""; - -#define CHECK_READONLY if (Context->readonly) \ -{\ - mutt_flushinp (); \ - mutt_error _(Mailbox_is_read_only); \ - break; \ -} - -#define SW (option(OPTMBOXPANE)?SidebarWidth:0) +#define SW (option(OPTMBOXPANE)?SidebarWidth:0) static struct mapping_t AttachHelp[] = { {N_("Exit"), OP_EXIT}, @@ -48,26 +36,6 @@ static struct mapping_t AttachHelp[] = { {NULL, OP_NULL} }; -static int mutt_extract_path (char *filename, char *path, ssize_t pathlen) -{ - char *tmp = p_new(char, _POSIX_PATH_MAX); - char *help_ptr; - - help_ptr = tmp; - - while (*filename != '\0') { - if (*filename == '/') { - *help_ptr++ = *filename++; - *help_ptr++ = '\0'; - m_strcat(path, pathlen, tmp); - help_ptr = tmp; - } - *help_ptr++ = *filename++; - } - p_delete(&tmp); - return 0; -} - void mutt_update_tree (ATTACHPTR ** idx, short idxlen) { char buf[STRING]; @@ -373,7 +341,6 @@ static int mutt_query_save_attachment (FILE * fp, BODY * body, HEADER * hdr, { char *prompt; char buf[_POSIX_PATH_MAX], tfile[_POSIX_PATH_MAX]; - char path[_POSIX_PATH_MAX] = ""; int is_message; int append = 0; int rc; @@ -396,29 +363,26 @@ static int mutt_query_save_attachment (FILE * fp, BODY * body, HEADER * hdr, prompt = _("Save to file ('#' for last used folder): "); while (prompt) { - ret = - mutt_get_field (prompt, buf, sizeof (buf), - M_FILE | M_CLEAR | M_LASTFOLDER); + static char LastSaveFolder[_POSIX_PATH_MAX] = "."; + + ret = mutt_get_field(prompt, buf, sizeof (buf), + M_FILE | M_CLEAR | M_LASTFOLDER); if (((ret != 0) && (ret != 2)) || (!buf[0] && ret != 2)) return -1; if (ret == 2) { char tmpbuf[_POSIX_PATH_MAX]; - snprintf (tmpbuf, sizeof (tmpbuf), "%s%s", LastSaveFolder, buf); + snprintf (tmpbuf, sizeof (tmpbuf), "%s/%s", LastSaveFolder, buf); m_strcpy(buf, sizeof(buf), tmpbuf); - ret = mutt_get_field (_("Save to file: ") - , buf, sizeof (buf), M_FILE); + ret = mutt_get_field(_("Save to file: "), buf, sizeof (buf), M_FILE); if ((ret != 0) || (!buf[0])) return -1; } - else { - mutt_extract_path (buf, path, sizeof(path)); - m_strcpy(LastSaveFolder, sizeof(LastSaveFolder), path); - } + m_dirname(LastSaveFolder, sizeof(LastSaveFolder), buf); prompt = NULL; - mutt_expand_path (buf, sizeof (buf)); + mutt_expand_path(buf, sizeof (buf)); is_message = (fp && body->hdr && @@ -941,6 +905,13 @@ void mutt_view_attachments (HEADER * hdr) attach_collapse (cur, 0, 1, 0); mutt_update_attach_index (cur, &idx, &idxlen, &idxmax, menu); +#define CHECK_READONLY \ + if (Context->readonly) { \ + mutt_flushinp (); \ + mutt_error _("Mailbox is read-only."); \ + break; \ + } + #define CHECK_ATTACH \ if (option(OPTATTACHMSG)) { \ mutt_flushinp (); \