From: Thomas Roessler Date: Wed, 11 Dec 2002 15:20:21 +0000 (+0000) Subject: Herbert Martin Dietze notes X-Git-Tag: mutt-1-5-3-rel~18 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d557f81e5396dd46e80daabbe2488138a53e4cef;p=mutt Herbert Martin Dietze notes that mutt may currently build IMAP URLs like imap://exchange//herbert for FCCs. The fix in this patch is to include a function named mutt_concat_path which concatenates path elements, but avoids the creation of double slashes. (These don't create problems when you're just accessing the file system, but apparently thy do cause problems with IMAP.) --- diff --git a/browser.c b/browser.c index 7a03c8b5..b94ba653 100644 --- a/browser.c +++ b/browser.c @@ -127,7 +127,7 @@ static int link_is_dir (const char *folder, const char *path) struct stat st; char fullpath[_POSIX_PATH_MAX]; - snprintf (fullpath, sizeof (fullpath), "%s/%s", folder, path); + mutt_concat_path (fullpath, folder, path, sizeof (fullpath)); if (stat (fullpath, &st) == 0) return (S_ISDIR (st.st_mode)); @@ -398,7 +398,7 @@ static int examine_directory (MUTTMENU *menu, struct browser_state *state, if (!((regexec (Mask.rx, de->d_name, 0, NULL, 0) == 0) ^ Mask.not)) continue; - snprintf (buffer, sizeof (buffer), "%s/%s", d, de->d_name); + mutt_concat_path (buffer, d, de->d_name, sizeof (buffer)); if (lstat (buffer, &s) == -1) continue; @@ -673,8 +673,7 @@ void _mutt_select_file (char *f, size_t flen, int flags, char ***files, int *num } #endif else - snprintf (buf, sizeof (buf), "%s/%s", LastDir, - state.entry[menu->current].name); + mutt_concat_path (buf, LastDir, state.entry[menu->current].name, sizeof (buf)); if ((mx_get_magic (buf) <= 0) #ifdef USE_IMAP @@ -736,7 +735,7 @@ void _mutt_select_file (char *f, size_t flen, int flags, char ***files, int *num else { char tmp[_POSIX_PATH_MAX]; - snprintf (tmp, sizeof (tmp), "%s/%s", LastDir, state.entry[menu->current].name); + mutt_concat_path (tmp, LastDir, state.entry[menu->current].name, sizeof (tmp)); strfcpy (LastDir, tmp, sizeof (LastDir)); } @@ -784,7 +783,7 @@ void _mutt_select_file (char *f, size_t flen, int flags, char ***files, int *num strfcpy (f, state.entry[menu->current].name, flen); #endif else - snprintf (f, flen, "%s/%s", LastDir, state.entry[menu->current].name); + mutt_concat_path (f, LastDir, state.entry[menu->current].name, flen); /* Fall through to OP_EXIT */ @@ -805,7 +804,7 @@ void _mutt_select_file (char *f, size_t flen, int flags, char ***files, int *num char full[_POSIX_PATH_MAX]; if (ff.tagged) { - snprintf (full, sizeof (full), "%s/%s", LastDir, ff.name); + mutt_concat_path (full, LastDir, ff.name, sizeof (full)); mutt_expand_path (full, sizeof (full)); tfiles[j++] = safe_strdup (full); } @@ -1151,9 +1150,8 @@ void _mutt_select_file (char *f, size_t flen, int flags, char ***files, int *num { BODY *b; char buf[_POSIX_PATH_MAX]; - - snprintf (buf, sizeof (buf), "%s/%s", LastDir, - state.entry[menu->current].name); + + mutt_concat_path (buf, LastDir, state.entry[menu->current].name, sizeof (buf)); b = mutt_make_file_attach (buf); if (b != NULL) { diff --git a/complete.c b/complete.c index b34bb075..97e6ac10 100644 --- a/complete.c +++ b/complete.c @@ -54,17 +54,8 @@ int mutt_complete (char *s, size_t slen) p = NONULL (Spoolfile); else p = NONULL (Maildir); - if (s[1]) - { - /* don't append '/' if Maildir/Spoolfile is imap://host/ only */ - if (mx_is_imap (NONULL (p)) && p[strlen (p)-1] == '/') - snprintf (imap_path, sizeof (imap_path), "%s%s", p, s+1); - else - snprintf (imap_path, sizeof (imap_path), "%s/%s", NONULL (p), - s+1); - } - else - strfcpy (imap_path, NONULL(p), sizeof(imap_path)); + + mutt_concat_path (imap_path, p, s+1, sizeof (imap_path)); } else strfcpy (imap_path, s, sizeof(imap_path)); @@ -85,7 +76,7 @@ int mutt_complete (char *s, size_t slen) { char buf[_POSIX_PATH_MAX]; *p++ = 0; - snprintf (buf, sizeof (buf), "%s/%s", exp_dirpart, s+1); + mutt_concat_path (buf, exp_dirpart, s + 1, sizeof (buf)); strfcpy (exp_dirpart, buf, sizeof (exp_dirpart)); snprintf (buf, sizeof (buf), "%s%s/", dirpart, s+1); strfcpy (dirpart, buf, sizeof (dirpart)); diff --git a/hook.c b/hook.c index c1091219..7db8e999 100644 --- a/hook.c +++ b/hook.c @@ -411,7 +411,7 @@ void mutt_select_fcc (char *path, size_t pathlen, HEADER *hdr) { adr = env->to ? env->to : (env->cc ? env->cc : env->bcc); mutt_safe_path (buf, sizeof (buf), adr); - snprintf (path, pathlen, "%s/%s", NONULL (Maildir), buf); + mutt_concat_path (path, NONULL(Maildir), buf, pathlen); if (!option (OPTFORCENAME) && mx_access (path, W_OK) != 0) strfcpy (path, NONULL (Outbox), pathlen); } diff --git a/init.c b/init.c index 41710270..7b16aeec 100644 --- a/init.c +++ b/init.c @@ -1841,9 +1841,9 @@ void mutt_init (int skip_sys_rc, LIST *commands) else { #ifdef HOMESPOOL - snprintf (buffer, sizeof (buffer), "%s/%s", NONULL(Homedir), MAILPATH); + mutt_concat_path (buffer, NONULL (Homedir), MAILPATH, sizeof (buffer)); #else - snprintf (buffer, sizeof (buffer), "%s/%s", MAILPATH, NONULL(Username)); + mutt_concat_path (buffer, MAILPATH, NONULL(Username), sizeof (buffer)); #endif Spoolfile = safe_strdup (buffer); } diff --git a/lib.c b/lib.c index 6614ea37..e21f5612 100644 --- a/lib.c +++ b/lib.c @@ -622,3 +622,14 @@ void mutt_remove_trailing_ws (char *s) for (p = s + mutt_strlen (s) - 1 ; p >= s && ISSPACE (*p) ; p--) *p = 0; } + +char *mutt_concat_path (char *d, const char *dir, const char *fname, size_t l) +{ + const char *fmt = "%s/%s"; + + if (!*fname || (*dir && dir[strlen(dir)-1] == '/')) + fmt = "%s%s"; + + snprintf (d, sizeof (d), fmt, dir, fname); + return d; +} diff --git a/lib.h b/lib.h index 4d6df81c..d38a5f78 100644 --- a/lib.h +++ b/lib.h @@ -109,6 +109,7 @@ void mutt_exit (int); FILE *safe_fopen (const char *, const char *); +char *mutt_concat_path (char *, const char *, const char *, size_t); char *mutt_read_line (char *, size_t *, FILE *, int *); char *mutt_skip_whitespace (char *); char *mutt_strlower (char *);