2 * Copyright (C) 1996-2000 Michael R. Elkins <me@mutt.org>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
24 #include "mutt_crypt.h"
25 #include "mutt_idna.h"
31 void mutt_edit_headers (const char *editor,
33 HEADER * msg, char *fcc, size_t fcclen)
35 char path[_POSIX_PATH_MAX]; /* tempfile used to edit headers + body */
36 char buffer[LONG_STRING];
43 LIST *cur, **last = NULL, *tmp;
46 if ((ofp = safe_fopen (path, "w")) == NULL) {
51 mutt_env_to_local (msg->env);
52 mutt_write_rfc822_header (ofp, msg->env, NULL, 1, 0);
53 fputc ('\n', ofp); /* tie off the header. */
55 /* now copy the body of the message. */
56 if ((ifp = fopen (body, "r")) == NULL) {
61 mutt_copy_stream (ifp, ofp);
66 if (stat (path, &st) == -1) {
71 mtime = mutt_decrease_mtime (path, &st);
73 mutt_edit_file (editor, path);
75 if (mtime == st.st_mtime) {
77 (debugfile, "ci_edit_headers(): temp file was not modified.\n"));
78 /* the file has not changed! */
84 mutt_free_list (&msg->env->userhdrs);
86 /* Read the temp file back in */
87 if ((ifp = fopen (path, "r")) == NULL) {
92 if ((ofp = safe_fopen (body, "w")) == NULL) {
93 /* intentionally leak a possible temporary file here */
99 n = mutt_read_rfc822_header (ifp, NULL, 1, 0);
100 while ((i = fread (buffer, 1, sizeof (buffer), ifp)) > 0)
101 fwrite (buffer, 1, i, ofp);
106 /* restore old info. */
107 n->references = msg->env->references;
108 msg->env->references = NULL;
110 mutt_free_envelope (&msg->env);
114 if (!msg->env->in_reply_to)
116 if (!option (OPTNEWSSEND))
118 mutt_free_list (&msg->env->references);
120 mutt_expand_aliases_env (msg->env);
122 /* search through the user defined headers added to see if either a
123 * fcc: or attach-file: field was specified.
126 cur = msg->env->userhdrs;
127 last = &msg->env->userhdrs;
131 /* keep track of whether or not we see the in-reply-to field. if we did
132 * not, remove the references: field later so that we can generate a new
133 * message based upon this one.
135 if (fcc && ascii_strncasecmp ("fcc:", cur->data, 4) == 0) {
139 strfcpy (fcc, p, fcclen);
140 mutt_pretty_mailbox (fcc);
144 else if (ascii_strncasecmp ("attach:", cur->data, 7) == 0) {
152 if ((q = strpbrk (p, " \t"))) {
153 mutt_substrcpy (path, p, q, sizeof (path));
157 strfcpy (path, p, sizeof (path));
158 mutt_expand_path (path, sizeof (path));
159 if ((body = mutt_make_file_attach (path))) {
160 body->description = safe_strdup (q);
161 for (parts = msg->content; parts->next; parts = parts->next);
165 mutt_pretty_mailbox (path);
166 mutt_error (_("%s: unable to attach file"), path);
173 else if ((WithCrypto & APPLICATION_PGP)
174 && ascii_strncasecmp ("pgp:", cur->data, 4) == 0) {
175 msg->security = mutt_parse_crypt_hdr (cur->data + 4, 0);
177 msg->security |= APPLICATION_PGP;
190 mutt_free_list (&tmp);