X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=blobdiff_plain;f=muttlib.c;h=539f7faaf699d73827a3e285f5a7c791a974c9cb;hp=caf5fd97915c5c9bbcc73161675212d97e647950;hb=031280cca515ce7949dfef0c6c8265c6112b1e34;hpb=ac1ea3143e61def7fc9000bee6d0d59d56c5b997 diff --git a/muttlib.c b/muttlib.c index caf5fd9..539f7fa 100644 --- a/muttlib.c +++ b/muttlib.c @@ -15,15 +15,13 @@ #include #include - #include #include - #include +#include #include "alias.h" #include "mutt.h" -#include "mx.h" #include "attach.h" #include "version.h" @@ -149,156 +147,113 @@ int mutt_matches_ignore (const char *s, string_list_t * t) return 0; } -char *mutt_expand_path (char *s, ssize_t slen) -{ - return _mutt_expand_path (s, slen, 0); -} - -char *_mutt_expand_path (char *s, ssize_t slen, int rx) +ssize_t _mutt_expand_path(char *s, ssize_t slen, int rx) { - char p[_POSIX_PATH_MAX] = ""; - char q[_POSIX_PATH_MAX] = ""; - char tmp[_POSIX_PATH_MAX]; - char *t; + char p[_POSIX_PATH_MAX] = ""; + char tmp[_POSIX_PATH_MAX]; + const char *tail = ""; + + do { + const address_t *alias; + + switch (*s) { + case '~': + if (s[1] == '/' || s[1] == '\0') { + m_strcpy(p, sizeof(p), Homedir); + tail = s + 1; + } else { + struct passwd *pw; + tail = m_strchrnul(s + 1, '/'); - const char *tail = ""; + m_strncpy(tmp, sizeof(tmp), s + 1, tail - s - 1); - int recurse = 0; + if ((pw = getpwnam(tmp))) { + m_strcpy(p, sizeof(p), pw->pw_dir); + } else { + /* user not found! */ + tail = s; + } + } + break; + + case '=': + case '+': + /* if folder = imap[s]://host/: don't append slash */ + if (imap_is_magic(NONULL(Maildir), NULL) == M_IMAP + && Maildir[m_strlen(Maildir) - 1] == '/') { + m_strcpy(p, sizeof(p), Maildir); + } else { + snprintf(p, sizeof(p), "%s/", NONULL(Maildir)); + } - do { - recurse = 0; + tail = s + 1; + break; + + /* elm compatibility, @ expands alias to user name */ + + case '@': + if ((alias = alias_lookup(s + 1))) { + HEADER h; + header_init(&h); + h.env = envelope_new(); + h.env->from = h.env->to = (address_t *)alias; + mutt_default_save(p, sizeof (p), &h); + h.env->from = h.env->to = NULL; + header_wipe(&h); + + if (*p != '@') { + /* recurse iff the result do not starts with '@' */ + m_strcpy(s, slen, p); + continue; + } + } + break; + + case '>': + m_strcpy(p, sizeof(p), Inbox); + tail = s + 1; + break; + + case '<': + m_strcpy(p, sizeof(p), Outbox); + tail = s + 1; + break; + + case '!': + if (s[1] == '!') { + m_strcpy(p, sizeof(p), LastFolder); + tail = s + 2; + } else { + m_strcpy(p, sizeof(p), Spoolfile); + tail = s + 1; + } + break; - switch (*s) { - case '~': - { - if (*(s + 1) == '/' || *(s + 1) == 0) { - m_strcpy(p, sizeof(p), NONULL(Homedir)); - tail = s + 1; - } - else { - struct passwd *pw; + case '-': + m_strcpy(p, sizeof(p), NONULL(LastFolder)); + tail = s + 1; + break; - if ((t = strchr (s + 1, '/'))) - *t = 0; + case '^': + m_strcpy(p, sizeof(p), NONULL(CurrentFolder)); + tail = s + 1; + break; - if ((pw = getpwnam (s + 1))) { - m_strcpy(p, sizeof(p), pw->pw_dir); - if (t) { - *t = '/'; - tail = t; - } - else - tail = ""; - } - else { - /* user not found! */ - if (t) - *t = '/'; + default: *p = '\0'; tail = s; - } } - } - break; - - case '=': - case '+': - { - /* if folder = imap[s]://host/: don't append slash */ - if (imap_is_magic (NONULL (Maildir), NULL) == M_IMAP && - Maildir[m_strlen(Maildir) - 1] == '/') - m_strcpy(p, sizeof(p), NONULL(Maildir)); - else - snprintf (p, sizeof (p), "%s/", NONULL (Maildir)); + } while (0); - tail = s + 1; - } - break; - - /* elm compatibility, @ expands alias to user name */ - - case '@': - { - HEADER *h; - /* FIXME: BUG ? */ - address_t *alias; - - if ((alias = alias_lookup(s + 1))) { - h = header_new(); - h->env = envelope_new(); - h->env->from = h->env->to = alias; - mutt_default_save (p, sizeof (p), h); - h->env->from = h->env->to = NULL; - header_delete(&h); - /* Avoid infinite recursion if the resulting folder starts with '@' */ - if (*p != '@') - recurse = 1; - - tail = ""; - } - } - break; - - case '>': - { - m_strcpy(p, sizeof(p), NONULL(Inbox)); - tail = s + 1; - } - break; - - case '<': - { - m_strcpy(p, sizeof(p), NONULL(Outbox)); - tail = s + 1; - } - break; - - case '!': - { - if (*(s + 1) == '!') { - m_strcpy(p, sizeof(p), NONULL(LastFolder)); - tail = s + 2; - } - else { - m_strcpy(p, sizeof(p), NONULL(Spoolfile)); - tail = s + 1; - } - } - break; - - case '-': - { - m_strcpy(p, sizeof(p), NONULL(LastFolder)); - tail = s + 1; - } - break; - - case '^': - { - m_strcpy(p, sizeof(p), NONULL(CurrentFolder)); - tail = s + 1; - } - break; - - default: - { - *p = '\0'; - tail = s; - } - } - - if (rx && *p && !recurse) { - rx_sanitize_string (q, sizeof (q), p); - snprintf (tmp, sizeof (tmp), "%s%s", q, tail); + if (rx) { + char q[_POSIX_PATH_MAX]; + rx_sanitize_string(q, sizeof(q), p); + snprintf(tmp, sizeof(tmp), "%s%s", q, tail); + } else { + snprintf(tmp, sizeof(tmp), "%s%s", p, tail); } - else - snprintf (tmp, sizeof (tmp), "%s%s", p, tail); - - m_strcpy(s, slen, tmp); - } - while (recurse); - return (s); + return m_strcpy(s, slen, tmp); } void mutt_mktemp (char *s)