/*
* Copyright (C) 1996-8 Michael R. Elkins <me@cs.hmc.edu>
* Copyright (C) 1999 Thomas Roessler <roessler@guug.de>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "mutt.h"
#include "mutt_curses.h"
#include "mime.h"
#include "mailbox.h"
#include "mx.h"
#ifdef _PGPPATH
#include "pgp.h"
#endif
#include <string.h>
#include <ctype.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/wait.h>
#include <errno.h>
#include <pwd.h>
#include <sys/stat.h>
#include <fcntl.h>
BODY *mutt_new_body (void)
{
BODY *p = (BODY *) safe_calloc (1, sizeof (BODY));
p->disposition = DISPATTACH;
p->use_disp = 1;
return (p);
}
BODY *mutt_dup_body (BODY *b)
{
BODY *bn;
bn = mutt_new_body();
memcpy(bn, b, sizeof (BODY));
return bn;
}
void mutt_free_body (BODY **p)
{
BODY *a = *p, *b;
while (a)
{
b = a;
a = a->next;
if (b->parameter)
mutt_free_parameter (&b->parameter);
if (b->unlink && b->filename)
unlink (b->filename);
safe_free ((void **) &b->filename);
safe_free ((void **) &b->content);
safe_free ((void **) &b->xtype);
safe_free ((void **) &b->subtype);
safe_free ((void **) &b->description);
safe_free ((void **) &b->form_name);
if (b->hdr)
{
/* Don't free twice (b->hdr->content = b->parts) */
b->hdr->content = NULL;
mutt_free_header(&b->hdr);
}
if (b->parts)
mutt_free_body (&b->parts);
safe_free ((void **) &b);
}
*p = 0;
}
void mutt_free_parameter (PARAMETER **p)
{
PARAMETER *t = *p;
PARAMETER *o;
while (t)
{
safe_free ((void **) &t->attribute);
safe_free ((void **) &t->value);
o = t;
t = t->next;
safe_free ((void **) &o);
}
*p = 0;
}
LIST *mutt_add_list (LIST *head, const char *data)
{
LIST *tmp;
for (tmp = head; tmp && tmp->next; tmp = tmp->next)
;
if (tmp)
{
tmp->next = safe_malloc (sizeof (LIST));
tmp = tmp->next;
}
else
head = tmp = safe_malloc (sizeof (LIST));
tmp->data = safe_strdup (data);
tmp->next = NULL;
return head;
}
void mutt_free_list (LIST **list)
{
LIST *p;
if (!list) return;
while (*list)
{
p = *list;
*list = (*list)->next;
safe_free ((void **) &p->data);
safe_free ((void **) &p);
}
}
HEADER *mutt_dup_header(HEADER *h)
{
HEADER *hnew;
hnew = mutt_new_header();
memcpy(hnew, h, sizeof (HEADER));
return hnew;
}
void mutt_free_header (HEADER **h)
{
if(!h || !*h) return;
mutt_free_envelope (&(*h)->env);
mutt_free_body (&(*h)->content);
safe_free ((void **) &(*h)->tree);
safe_free ((void **) &(*h)->path);
#ifdef MIXMASTER
mutt_free_list (&(*h)->chain);
#endif
safe_free ((void **) 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 (!mutt_strncasecmp (s, t->data, mutt_strlen (t->data))