- 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 = mutt_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;
- }
- }
-
- q = mutt_new_parameter ();
- q->attribute = safe_strdup (attribute);
- q->value = safe_strdup (value);
- q->next = *p;
- *p = q;
-}
-
-void mutt_delete_parameter (const char *attribute, PARAMETER ** p)
-{
- PARAMETER *q;
-
- for (q = *p; q; p = &q->next, q = q->next) {
- if (ascii_strcasecmp (attribute, q->attribute) == 0) {
- *p = q->next;
- q->next = NULL;
- mutt_free_parameter (&q);
- return;
- }
- }
-}
-
-/* returns 1 if Mutt can't display this type of data, 0 otherwise */
-int mutt_needs_mailcap (BODY * m)
-{
- switch (m->type) {
- case TYPETEXT:
-
- if (!ascii_strcasecmp ("plain", m->subtype) ||
- !ascii_strcasecmp ("rfc822-headers", m->subtype) ||
- !ascii_strcasecmp ("enriched", m->subtype))
- return 0;
- break;
-
- case TYPEAPPLICATION:
- if ((WithCrypto & APPLICATION_PGP) && mutt_is_application_pgp (m))
- return 0;
- if ((WithCrypto & APPLICATION_SMIME) && mutt_is_application_smime (m))
- return 0;
- break;
-
- case TYPEMULTIPART:
- case TYPEMESSAGE:
- return 0;
- }
-
- return 1;
-}
-
-int mutt_is_text_part (BODY * b)
-{
- int t = b->type;
- char *s = b->subtype;
-
- if ((WithCrypto & APPLICATION_PGP) && mutt_is_application_pgp (b))
- return 0;
-
- if (t == TYPETEXT)
- return 1;
-
- if (t == TYPEMESSAGE) {
- if (!ascii_strcasecmp ("delivery-status", s))
- return 1;
- }
-
- if ((WithCrypto & APPLICATION_PGP) && t == TYPEAPPLICATION) {
- if (!ascii_strcasecmp ("pgp-keys", s))
- return 1;
- }
-
- return 0;
-}
-
-void mutt_free_envelope (ENVELOPE ** p)
-{
- if (!*p)
- return;
- rfc822_free_address (&(*p)->return_path);
- rfc822_free_address (&(*p)->from);
- rfc822_free_address (&(*p)->to);
- rfc822_free_address (&(*p)->cc);
- rfc822_free_address (&(*p)->bcc);
- rfc822_free_address (&(*p)->sender);
- rfc822_free_address (&(*p)->reply_to);
- rfc822_free_address (&(*p)->mail_followup_to);
-
- FREE (&(*p)->list_post);
- FREE (&(*p)->subject);
- /* real_subj is just an offset to subject and shouldn't be freed */
- FREE (&(*p)->message_id);
- FREE (&(*p)->supersedes);
- FREE (&(*p)->date);
- FREE (&(*p)->x_label);
- FREE (&(*p)->organization);
-#ifdef USE_NNTP
- FREE (&(*p)->newsgroups);
- FREE (&(*p)->xref);
- FREE (&(*p)->followup_to);
- FREE (&(*p)->x_comment_to);
-#endif
-
- mutt_buffer_free (&(*p)->spam);
- mutt_free_list (&(*p)->references);
- mutt_free_list (&(*p)->in_reply_to);
- mutt_free_list (&(*p)->userhdrs);
- FREE (p);
-}
-
-void _mutt_mktemp (char *s, const char *src, int line)
-{
- snprintf (s, _POSIX_PATH_MAX, "%s/mutt-%s-%d-%d-%d", NONULL (Tempdir),
- NONULL (Hostname), (int) getuid (), (int) getpid (), Counter++);
- dprint (1,
- (debugfile, "%s:%d: mutt_mktemp returns \"%s\".\n", src, line, s));
- unlink (s);
-}
-
-void mutt_free_alias (ALIAS ** p)
-{
- ALIAS *t;
-
- while (*p) {
- t = *p;
- *p = (*p)->next;
- FREE (&t->name);
- rfc822_free_address (&t->addr);
- FREE (&t);
- }