-/* 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;
-
- p_clear(dest, destlen);
-
- if (GecosMask.rx) {
- if (regexec (GecosMask.rx, pw->pw_gecos, 1, pat_match, 0) == 0)
- m_strcpy(dest, MIN(pat_match[0].rm_eo - pat_match[0].rm_so + 1, destlen),
- pw->pw_gecos + pat_match[0].rm_so);
- }
- else if ((p = strchr (pw->pw_gecos, ',')))
- m_strcpy(dest, MIN(destlen, p - pw->pw_gecos + 1), pw->pw_gecos);
- else
- m_strcpy(dest, destlen, pw->pw_gecos);
-
- pwnl = m_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) {
- str_replace (&q->value, value);
- return;
- }
- }
-
- q = mutt_new_parameter ();
- q->attribute = m_strdup(attribute);
- q->value = m_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);
-
- p_delete(&(*p)->list_post);
- p_delete(&(*p)->subject);
- /* real_subj is just an offset to subject and shouldn't be freed */
- p_delete(&(*p)->message_id);
- p_delete(&(*p)->supersedes);
- p_delete(&(*p)->date);
- p_delete(&(*p)->x_label);
- p_delete(&(*p)->organization);
-#ifdef USE_NNTP
- p_delete(&(*p)->newsgroups);
- p_delete(&(*p)->xref);
- p_delete(&(*p)->followup_to);
- p_delete(&(*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);
- p_delete(p);
-}
-
-/* move all the headers from extra not present in base into base */
-void mutt_merge_envelopes(ENVELOPE* base, ENVELOPE** extra)
-{
- /* copies each existing element if necessary, and sets the element
- * to NULL in the source so that mutt_free_envelope doesn't leave us
- * with dangling pointers. */
-#define MOVE_ELEM(h) if (!base->h) { base->h = (*extra)->h; (*extra)->h = NULL; }
- MOVE_ELEM(return_path);
- MOVE_ELEM(from);
- MOVE_ELEM(to);
- MOVE_ELEM(cc);
- MOVE_ELEM(bcc);
- MOVE_ELEM(sender);
- MOVE_ELEM(reply_to);
- MOVE_ELEM(mail_followup_to);
- MOVE_ELEM(list_post);
- MOVE_ELEM(message_id);
- MOVE_ELEM(supersedes);
- MOVE_ELEM(date);
- MOVE_ELEM(x_label);
- if (!base->refs_changed) {
- MOVE_ELEM(references);
- }
- if (!base->irt_changed) {
- MOVE_ELEM(in_reply_to);
- }
- /* real_subj is subordinate to subject */
- if (!base->subject) {
- base->subject = (*extra)->subject;
- base->real_subj = (*extra)->real_subj;
- (*extra)->subject = NULL;
- (*extra)->real_subj = NULL;
- }
- /* spam and user headers should never be hashed, and the new envelope may
- * have better values. Use new versions regardless. */
- mutt_buffer_free (&base->spam);
- mutt_free_list (&base->userhdrs);
- MOVE_ELEM(spam);
- MOVE_ELEM(userhdrs);
-#undef MOVE_ELEM
-
- mutt_free_envelope(extra);
-}
-
-void _mutt_mktemp (char *s, const char *src, int line)