/*
* Copyright (C) 1996-2000 Michael R. Elkins <me@mutt.org>
* Copyright (C) 2000-2004,2006 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#if HAVE_CONFIG_H
# include "config.h"
#endif
#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 "mutt_crypt.h"
#include "mutt_idna.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#ifdef USE_IMAP
#include "imap.h"
#endif
#include "buffy.h"
#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>
static const char *ExtPagerProgress = "all";
/* 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 = MUTT_CM_DECODE | MUTT_CM_DISPLAY | MUTT_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, MUTT_MESSAGEHOOK);
/* see if crypto is needed for this message. if so, we should exit curses */
if (WithCrypto && cur->security)
{
if (cur->security & ENCRYPT)
{
if (cur->security & APPLICATION_SMIME)
crypt_smime_getkeys (cur->env);
if(!crypt_valid_passphrase(cur->security))
return 0;
cmflags |= MUTT_CM_VERIFY;
}
else if (cur->security & SIGN)
{
/* find out whether or not the verify signature */
if (query_quadoption (OPT_VERIFYSIG, _("Verify PGP signature?")) == MUTT_YES)
{
cmflags |= MUTT_CM_VERIFY;
}
}
}
if (cmflags & MUTT_CM_VERIFY || cur->security & ENCRYPT)
{
if (cur->security & APPLICATION_PGP)
{
if (cur->env->from)
crypt_pgp_invoke_getkeys (cur->env->from);
crypt_invoke_message (APPLICATION_PGP);
}
if (cur->security & APPLICATION_SMIME)
crypt_invoke_message (APPLICATION_SMIME);
}
mutt_mktemp (tempfile, sizeof (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
{
struct hdr_format_info hfi;
hfi.ctx = Context;
hfi.pager_progress = ExtPagerProgress;
hfi.hdr = cur;
mutt_make_string_info (buf, sizeof (buf), MuttIndexWindow->cols, NONULL(PagerFmt), &hfi, MUTT_FORMAT_MAKEPRINT);
fputs (buf, fpout);
fputs ("\n\n", fpout);
}
res = mutt_copy_message (fpout, Context, cur, cmflags,
(option (OPTWEED)