- if(!h || !*h) return;
- mutt_free_envelope (&(*h)->env);
- mutt_free_body (&(*h)->content);
- FREE (&(*h)->maildir_flags);
- FREE (&(*h)->tree);
- FREE (&(*h)->path);
-#ifdef MIXMASTER
- mutt_free_list (&(*h)->chain);
-#endif
-#if defined USE_POP || defined USE_IMAP || defined USE_NNTP
- FREE (&(*h)->data);
-#endif
- FREE (h);
-}
-
-/* returns true if the header contained in "s" is in list "t" */
-int mutt_matches_ignore (const char *s, LIST *t)
-{
- for (; t; t = t->next)
- {
- if (!ascii_strncasecmp (s, t->data, mutt_strlen (t->data)) || *t->data == '*')
- return 1;
- }
- return 0;
-}
-
-/* prepend the path part of *path to *link */
-void mutt_expand_link (char *newpath, const char *path, const char *link)
-{
- const char *lb = NULL;
- size_t len;
-
- /* link is full path */
- if (*link == '/')
- {
- strfcpy (newpath, link, _POSIX_PATH_MAX);
- return;
- }
-
- if ((lb = strrchr (path, '/')) == NULL)
- {
- /* no path in link */
- strfcpy (newpath, link, _POSIX_PATH_MAX);
- return;
- }
-
- len = lb - path + 1;
- memcpy (newpath, path, len);
- strfcpy (newpath + len, link, _POSIX_PATH_MAX - len);
-}
-
-char *mutt_expand_path (char *s, size_t slen)
-{
- return _mutt_expand_path (s, slen, 0);
-}
-
-char *_mutt_expand_path (char *s, size_t slen, int rx)
-{
- char p[_POSIX_PATH_MAX] = "";
- char q[_POSIX_PATH_MAX] = "";
- char tmp[_POSIX_PATH_MAX];
- char *t;
-
- char *tail = "";
-
- int recurse = 0;
-
- do
- {
- recurse = 0;
-
- switch (*s)
- {
- case '~':
- {
- if (*(s + 1) == '/' || *(s + 1) == 0)
- {
- strfcpy (p, NONULL(Homedir), sizeof (p));
- tail = s + 1;
- }
- else
- {
- struct passwd *pw;
- if ((t = strchr (s + 1, '/')))
- *t = 0;
-
- if ((pw = getpwnam (s + 1)))
- {
- strfcpy (p, pw->pw_dir, sizeof (p));
- if (t)
- {
- *t = '/';
- tail = t;
- }
- else
- tail = "";
- }
- else
- {
- /* user not found! */
- if (t)
- *t = '/';
- *p = '\0';
- tail = s;
- }
- }
- }
- break;
-
- case '=':
- case '+':
- {
-#ifdef USE_IMAP
- /* if folder = {host} or imap[s]://host/: don't append slash */
- if (mx_is_imap (NONULL (Maildir)) &&
- (Maildir[strlen (Maildir) - 1] == '}' ||
- Maildir[strlen (Maildir) - 1] == '/'))
- strfcpy (p, NONULL (Maildir), sizeof (p));
- else
-#endif
- snprintf (p, sizeof (p), "%s/", NONULL (Maildir));
-
- tail = s + 1;
- }
- break;
-
- /* elm compatibility, @ expands alias to user name */
-
- case '@':
- {
- HEADER *h;
- ADDRESS *alias;
-
- if ((alias = mutt_lookup_alias (s + 1)))
- {
- h = mutt_new_header();
- h->env = mutt_new_envelope();
- h->env->from = h->env->to = alias;
- mutt_default_save (p, sizeof (p), h);
- h->env->from = h->env->to = NULL;
- mutt_free_header (&h);
- /* Avoid infinite recursion if the resulting folder starts with '@' */
- if (*p != '@')
- recurse = 1;
-
- tail = "";
- }
- }
- break;
-
- case '>':
- {
- strfcpy (p, NONULL(Inbox), sizeof (p));
- tail = s + 1;
- }
- break;
-
- case '<':
- {
- strfcpy (p, NONULL(Outbox), sizeof (p));
- tail = s + 1;
- }
- break;
-
- case '!':
- {
- if (*(s+1) == '!')
- {
- strfcpy (p, NONULL(LastFolder), sizeof (p));
- tail = s + 2;
- }
- else
- {
- strfcpy (p, NONULL(Spoolfile), sizeof (p));
- tail = s + 1;
- }
- }
- break;
-
- case '-':
- {
- strfcpy (p, NONULL(LastFolder), sizeof (p));
- tail = s + 1;
- }
- break;
-
- default:
- {
- *p = '\0';
- tail = s;
- }
- }
-
- if (rx && *p && !recurse)
- {
- mutt_rx_sanitize_string (q, sizeof (q), p);
- snprintf (tmp, sizeof (tmp), "%s%s", q, tail);
- }
- else
- snprintf (tmp, sizeof (tmp), "%s%s", p, tail);
-
- strfcpy (s, tmp, slen);
- }
- while (recurse);
-
-#ifdef USE_IMAP
- /* Rewrite IMAP path in canonical form - aids in string comparisons of
- * folders. May possibly fail, in which case s should be the same. */
- if (mx_is_imap (s))
- imap_expand_path (s, slen);
-#endif
-
- return (s);
-}
-
-/* Extract the real name from /etc/passwd's GECOS field.
- * When set, honor the regular expression in GecosMask,
- * otherwise assume that the GECOS field is a
- * comma-separated list.
- * Replace "&" by a capitalized version of the user's login
- * name.
- */
-
-char *mutt_gecos_name (char *dest, size_t destlen, struct passwd *pw)
-{
- regmatch_t pat_match[1];
- size_t pwnl;
- int idx;
- char *p;
-
- if (!pw || !pw->pw_gecos)
- return NULL;
-
- memset (dest, 0, destlen);
-
- if (GecosMask.rx)
- {
- if (regexec (GecosMask.rx, pw->pw_gecos, 1, pat_match, 0) == 0)
- strfcpy (dest, pw->pw_gecos + pat_match[0].rm_so,
- MIN (pat_match[0].rm_eo - pat_match[0].rm_so + 1, destlen));
- }
- else if ((p = strchr (pw->pw_gecos, ',')))
- strfcpy (dest, pw->pw_gecos, MIN (destlen, p - pw->pw_gecos + 1));
- else
- strfcpy (dest, pw->pw_gecos, destlen);
-
- pwnl = strlen (pw->pw_name);
-
- for (idx = 0; dest[idx]; idx++)
- {
- if (dest[idx] == '&')
- {
- memmove (&dest[idx + pwnl], &dest[idx + 1],
- MAX(destlen - idx - pwnl - 1, 0));
- memcpy (&dest[idx], pw->pw_name, MIN(destlen - idx - 1, pwnl));
- dest[idx] = toupper ((unsigned char) dest[idx]);
- }
- }
-
- return dest;
-}
-
-
-char *mutt_get_parameter (const char *s, PARAMETER *p)
-{
- for (; p; p = p->next)
- if (ascii_strcasecmp (s, p->attribute) == 0)
- return (p->value);
-
- return NULL;
-}
-
-void mutt_set_parameter (const char *attribute, const char *value, PARAMETER **p)
-{
- PARAMETER *q;
-
- if (!value)
- {
- mutt_delete_parameter (attribute, p);
- return;
- }
-
- for(q = *p; q; q = q->next)
- {
- if (ascii_strcasecmp (attribute, q->attribute) == 0)
- {
- mutt_str_replace (&q->value, value);
- return;