/*
* 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 "version.h"
#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] = "";
static void update_protected_headers (HEADER *cur)
{
ENVELOPE *prot_headers = NULL;
regmatch_t pmatch[1];
if (!option (OPTCRYPTPROTHDRSREAD))
return;
/* Grab protected headers to update in the index */
if (cur->security & SIGN)
{
/* Don't update on a bad signature.
*
* This is a simplification. It's possible the headers are in the
* encrypted part of a nested encrypt/signed. But properly handling that
* case would require more complexity in the decryption handlers, which
* I'm not sure is worth it. */
if (!(cur->security & GOODSIGN))
return;
if (mutt_is_multipart_signed (cur->content) &&
cur->content->parts)
{
prot_headers = cur->content->parts->mime_headers;
}
else if ((WithCrypto & APPLICATION_SMIME) &&
mutt_is_application_smime (cur->content))
{
prot_headers = cur->content->mime_headers;
}
}
if (!prot_headers && (cur->security & ENCRYPT))
{
if ((WithCrypto & APPLICATION_PGP) &&
(mutt_is_valid_multipart_pgp_encrypted (cur->content) ||
mutt_is_malformed_multipart_pgp_encrypted (cur->content)))
{
prot_headers = cur->content->mime_headers;
}
else if ((WithCrypto & APPLICATION_SMIME) &&
mutt_is_application_smime (cur->content))
{
prot_headers = cur->content->mime_headers;
}
}
/* Update protected headers in the index and header cache. */
if (prot_headers &&
prot_headers->subject &&
mutt_strcmp (cur->env->subject, prot_headers->subject))
{
if (Context->subj_hash && cur->env->real_subj)
hash_delete (Context->subj_hash, cur->env->real_subj, cur, NULL);
mutt_str_replace (&cur->env->subject, prot_headers->subject);
FREE (&cur->env->disp_subj);
if (regexec (ReplyRegexp.rx, cur->env->subject, 1, pmatch, 0) == 0)
cur->env->real_subj = cur->env->subject + pmatch[0].rm_eo;
else
cur->env->real_subj = cur->env->subject;
if (Context->subj_hash)
hash_insert (Context->subj_hash, cur->env->real_subj, cur);
mx_save_to_header_cache (Context, cur);
/* Also persist back to the message headers if this is set */
if (option (OPTCRYPTPROTHDRSSAVE))
{
cur->env->changed |= MUTT_ENV_CHANGED_SUBJECT;
cur->