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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24 #include "mutt_crypt.h"
25 #include "mutt_idna.h"
31 void mutt_edit_headers (const char *editor,
37 char path[_POSIX_PATH_MAX]; /* tempfile used to edit headers + body */
38 char buffer[LONG_STRING];
45 LIST *cur, **last = NULL, *tmp;
48 if ((ofp = safe_fopen (path, "w")) == NULL)
54 mutt_env_to_local (msg->env);
55 mutt_write_rfc822_header (ofp, msg->env, NULL, 1, 0);
56 fputc ('\n', ofp); /* tie off the header. */
58 /* now copy the body of the message. */
59 if ((ifp = fopen (body, "r")) == NULL)
65 mutt_copy_stream (ifp, ofp);
70 if (stat (path, &st) == -1)
76 mtime = mutt_decrease_mtime (path, &st);
78 mutt_edit_file (editor, path);
80 if (mtime == st.st_mtime)
82 dprint (1, (debugfile, "ci_edit_headers(): temp file was not modified.\n"));
83 /* the file has not changed! */
89 mutt_free_list (&msg->env->userhdrs);
91 /* Read the temp file back in */
92 if ((ifp = fopen (path, "r")) == NULL)
98 if ((ofp = safe_fopen (body, "w")) == NULL)
100 /* intentionally leak a possible temporary file here */
106 n = mutt_read_rfc822_header (ifp, NULL, 1, 0);
107 while ((i = fread (buffer, 1, sizeof (buffer), ifp)) > 0)
108 fwrite (buffer, 1, i, ofp);
113 /* restore old info. */
114 n->references = msg->env->references;
115 msg->env->references = NULL;
117 mutt_free_envelope (&msg->env);
118 msg->env = n; n = NULL;
120 if (!msg->env->in_reply_to)
121 mutt_free_list (&msg->env->references);
123 mutt_expand_aliases_env (msg->env);
125 /* search through the user defined headers added to see if either a
126 * fcc: or attach-file: field was specified.
129 cur = msg->env->userhdrs;
130 last = &msg->env->userhdrs;
135 /* keep track of whether or not we see the in-reply-to field. if we did
136 * not, remove the references: field later so that we can generate a new
137 * message based upon this one.
139 if (fcc && ascii_strncasecmp ("fcc:", cur->data, 4) == 0)
145 strfcpy (fcc, p, fcclen);
146 mutt_pretty_mailbox (fcc);
150 else if (ascii_strncasecmp ("attach:", cur->data, 7) == 0)
160 if ((q = strpbrk (p, " \t")))
162 mutt_substrcpy (path, p, q, sizeof (path));
166 strfcpy (path, p, sizeof (path));
167 mutt_expand_path (path, sizeof (path));
168 if ((body = mutt_make_file_attach (path)))
170 body->description = safe_strdup (q);
171 for (parts = msg->content; parts->next; parts = parts->next) ;
176 mutt_pretty_mailbox (path);
177 mutt_error (_("%s: unable to attach file"), path);
184 else if ((WithCrypto & APPLICATION_PGP)
185 &&ascii_strncasecmp ("pgp:", cur->data, 4) == 0)
187 msg->security = mutt_parse_crypt_hdr (cur->data + 4, 0, APPLICATION_PGP);
189 msg->security |= APPLICATION_PGP;
204 mutt_free_list (&tmp);