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.
20 #include "mutt_crypt.h"
21 #include "mutt_idna.h"
27 void mutt_edit_headers (const char *editor,
33 char path[_POSIX_PATH_MAX]; /* tempfile used to edit headers + body */
34 char buffer[LONG_STRING];
41 LIST *cur, **last = NULL, *tmp;
44 if ((ofp = safe_fopen (path, "w")) == NULL)
50 mutt_env_to_local (msg->env);
51 mutt_write_rfc822_header (ofp, msg->env, NULL, 1, 0);
52 fputc ('\n', ofp); /* tie off the header. */
54 /* now copy the body of the message. */
55 if ((ifp = fopen (body, "r")) == NULL)
61 mutt_copy_stream (ifp, ofp);
66 if (stat (path, &st) == -1)
72 mtime = mutt_decrease_mtime (path, &st);
74 mutt_edit_file (editor, path);
76 if (mtime == st.st_mtime)
78 dprint (1, (debugfile, "ci_edit_headers(): temp file was not modified.\n"));
79 /* the file has not changed! */
85 mutt_free_list (&msg->env->userhdrs);
87 /* Read the temp file back in */
88 if ((ifp = fopen (path, "r")) == NULL)
94 if ((ofp = safe_fopen (body, "w")) == NULL)
96 /* intentionally leak a possible temporary file here */
102 n = mutt_read_rfc822_header (ifp, NULL, 1, 0);
103 while ((i = fread (buffer, 1, sizeof (buffer), ifp)) > 0)
104 fwrite (buffer, 1, i, ofp);
109 /* restore old info. */
110 n->references = msg->env->references;
111 msg->env->references = NULL;
113 mutt_free_envelope (&msg->env);
114 msg->env = n; n = NULL;
116 if (!msg->env->in_reply_to)
118 if (!option (OPTNEWSSEND))
120 mutt_free_list (&msg->env->references);
122 mutt_expand_aliases_env (msg->env);
124 /* search through the user defined headers added to see if either a
125 * fcc: or attach-file: field was specified.
128 cur = msg->env->userhdrs;
129 last = &msg->env->userhdrs;
134 /* keep track of whether or not we see the in-reply-to field. if we did
135 * not, remove the references: field later so that we can generate a new
136 * message based upon this one.
138 if (fcc && ascii_strncasecmp ("fcc:", cur->data, 4) == 0)
144 strfcpy (fcc, p, fcclen);
145 mutt_pretty_mailbox (fcc);
149 else if (ascii_strncasecmp ("attach:", cur->data, 7) == 0)
159 if ((q = strpbrk (p, " \t")))
161 mutt_substrcpy (path, p, q, sizeof (path));
165 strfcpy (path, p, sizeof (path));
166 mutt_expand_path (path, sizeof (path));
167 if ((body = mutt_make_file_attach (path)))
169 body->description = safe_strdup (q);
170 for (parts = msg->content; parts->next; parts = parts->next) ;
175 mutt_pretty_mailbox (path);
176 mutt_error (_("%s: unable to attach file"), path);
183 else if ((WithCrypto & APPLICATION_PGP)
184 &&ascii_strncasecmp ("pgp:", cur->data, 4) == 0)
186 msg->security = mutt_parse_crypt_hdr (cur->data + 4, 0);
201 mutt_free_list (&tmp);