/*
* Copyright (C) 1996-2000 Michael R. Elkins <me@cs.hmc.edu>
* Copyright (C) 2000 Thomas Roessler <roessler@does-not-exist.org>
*
* 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 "mutt_menu.h"
#include "mime.h"
#include "sort.h"
#include "mailbox.h"
#include "copy.h"
#include "mx.h"
#include "pager.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#ifdef USE_IMAP
#include "imap.h"
#endif
#ifdef BUFFY_SIZE
#include "buffy.h"
#endif
#ifdef HAVE_PGP
#include "pgp.h"
#endif
#ifdef HAVE_SMIME
#include "smime.h"
#endif
#include <errno.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <sys/wait.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <utime.h>
extern char *ReleaseDate;
/* The folder the user last saved to. Used by ci_save_message() */
static char LastSaveFolder[_POSIX_PATH_MAX] = "";
int mutt_display_message (HEADER *cur)
{
char tempfile[_POSIX_PATH_MAX], buf[LONG_STRING];
int rc = 0, builtin = 0;
int cmflags = M_CM_DECODE | M_CM_DISPLAY | M_CM_CHARCONV;
FILE *fpout = NULL;
FILE *fpfilterout = NULL;
pid_t filterpid = -1;
int res;
snprintf (buf, sizeof (buf), "%s/%s", TYPE (cur->content),
cur->content->subtype);
mutt_parse_mime_message (Context, cur);
mutt_message_hook (Context, cur, M_MESSAGEHOOK);
#if defined (HAVE_PGP) || defined (HAVE_SMIME)
/* see if PGP is needed for this message. if so, we should exit curses */
if (cur->security)
{
if (cur->security & ENCRYPT)
{
#ifdef HAVE_SMIME
if (cur->security & APPLICATION_SMIME)
smime_getkeys (cur->env);
#endif
if(!crypt_valid_passphrase(cur->security))
return 0;
cmflags |= M_CM_VERIFY;
}
else if (cur->security & SIGN)
{
/* find out whether or not the verify signature */
if (query_quadoption (OPT_VERIFYSIG, _("Verify PGP signature?")) == M_YES)
{
cmflags |= M_CM_VERIFY;
}
}
}
if (cmflags & M_CM_VERIFY || cur->security & ENCRYPT)
{
#ifdef HAVE_PGP
if (cur->security & APPLICATION_PGP)
{
if (cur->env->from)
pgp_invoke_getkeys (cur->env->from);
mutt_message _("Invoking PGP...");
}
#endif
#ifdef HAVE_SMIME
if (cur->security & APPLICATION_SMIME)
mutt_message _("Invoking OpenSSL...");
#endif
}
#endif /* defined (HAVE_PGP) || defined (HAVE_SMIME) */
mutt_mktemp (tempfile);
if ((fpout = safe_fopen (tempfile, "w")) == NULL)
{
mutt_error _("Could not create temporary file!");
return (0);
}
if (DisplayFilter && *DisplayFilter)
{
fpfilterout = fpout;
fpout = NULL;
/* mutt_endwin (NULL); */
filterpid = mutt_create_filter_fd (DisplayFilter, &fpout, NULL, NULL,
-1, fileno(fpfilterout), -1);
if (filterpid < 0)
{
mutt_error (_("Cannot create display filter"));
safe_fclose (&fpfilterout);
unlink (tempfile);
return 0;
}
}
if (!Pager || mutt_strcmp (Pager, "builtin") == 0)
builtin = 1;
else
{
mutt_make_string (buf, sizeof (buf), NONULL(PagerFmt), Context, cur);
fputs (buf, fpout);
fputs ("\n\n", fpout);
}
res = mutt_copy_message (fpout, Context, cur, cmflags,
(option (OPTWEED) ? (CH_WEED | CH_REORDER) : 0) | CH_DECODE | CH_FROM);
if ((safe_fclose (&fpout) != 0 && errno != EPIPE) || res == -1)
{
mutt_error (_("Could not copy message"));
if (fpfilterout != NULL)
{
mutt_wait_filter (filterpid);