/*
* Copyright (C) 1996-2000 Michael R. Elkins <me@cs.hmc.edu>
* Copyright (C) 1999-2000 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., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*/
#include "mutt.h"
#include "mutt_curses.h"
#include "mime.h"
#include "mailbox.h"
#include "mx.h"
#include "url.h"
#ifdef HAVE_PGP
#include "pgp.h"
#endif
#include <string.h>
#include <ctype.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/wait.h>
#include <errno.h>
#include <sys/stat.h>
#include <fcntl.h>
#define MIN(a,b) ((a) < (b) ? (a) : (b))
#define MAX(a,b) ((a) < (b) ? (b) : (a))
BODY *mutt_new_body (void)
{
BODY *p = (BODY *) safe_calloc (1, sizeof (BODY));
p->disposition = DISPATTACH;
p->use_disp = 1;
return (p);
}
/* Modified by blong to accept a "suggestion" for file name. If
* that file exists, then construct one with unique name but
* keep any extension. This might fail, I guess.
* Renamed to mutt_adv_mktemp so I only have to change where it's
* called, and not all possible cases.
*/
void mutt_adv_mktemp (char *s, size_t l)
{
char buf[_POSIX_PATH_MAX];
char tmp[_POSIX_PATH_MAX];
char *period;
size_t sl;
struct stat sb;
strfcpy (buf, NONULL (Tempdir), sizeof (buf));
mutt_expand_path (buf, sizeof (buf));
if (s[0] == '\0')
{
snprintf (s, l, "%s/muttXXXXXX", buf);
mktemp (s);
}
else
{
strfcpy (tmp, s, sizeof (tmp));
mutt_sanitize_filename (tmp, 1);
snprintf (s, l, "%s/%s", buf, tmp);
if (lstat (s, &sb) == -1 && errno == ENOENT)
return;
if ((period = strrchr (tmp, '.')) != NULL)
*period = 0;
snprintf (s, l, "%s/%s.XXXXXX", buf, tmp);
mktemp (s);
if (period != NULL)
{
*period = '.';
sl = mutt_strlen(s);
strfcpy(s + sl, period, l - sl);
}
}
}
/* create a send-mode duplicate from a receive-mode body */
int mutt_copy_body (FILE *fp, BODY **tgt, BODY *src)
{
char tmp[_POSIX_PATH_MAX];
BODY *b;
PARAMETER *par, **ppar;
short use_disp;
if (src->filename)
{
use_disp = 1;
strfcpy (tmp, src->filename, sizeof (tmp));
}
else
{
use_disp = 0;
tmp[0] = '\0';
}
mutt_adv_mktemp (tmp,