return 0;
}
-char *mutt_expand_path (char *s, ssize_t slen)
+ssize_t _mutt_expand_path(char *s, ssize_t slen, int rx)
{
- return _mutt_expand_path (s, slen, 0);
-}
-
-char *_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;
+ } while (0);
- 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));
-
- 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)
const char *mutt_charset_hook (const char *);
const char *mutt_iconv_hook (const char *);
-char *mutt_expand_path (char *, ssize_t);
-char *_mutt_expand_path (char *, ssize_t, int);
+
+ssize_t _mutt_expand_path (char *, ssize_t, int);
+#define mutt_expand_path(s, n) _mutt_expand_path((s), (n), 0)
+
char *mutt_find_hook (int, const char *);
char *mutt_get_body_charset (char *, ssize_t, BODY *);
const char *mutt_get_name (address_t *);
void mutt_adv_mktemp (const char*, char*, ssize_t);
int mutt_bounce_message (FILE * fp, HEADER *, address_t *);
void mutt_check_rescore (CONTEXT *);
-void mutt_default_save (char *, ssize_t, HEADER *);
+void mutt_default_save (char *, ssize_t, const HEADER *);
void mutt_display_address (ENVELOPE *);
void mutt_edit_content_type (HEADER *, BODY *, FILE *);
void mutt_edit_headers (const char *, const char *, HEADER *, char *, ssize_t);