2 * Copyright notice from original mutt:
3 * Copyright (C) 1996-2000 Michael R. Elkins <me@mutt.org>
5 * This file is part of mutt-ng, see http://www.muttng.org/.
6 * It's licensed under the GNU General Public License,
7 * please see the file GPL in the top level source directory.
14 #include <lib-lib/macros.h>
15 #include <lib-lib/ascii.h>
16 #include <lib-lib/file.h>
19 #include "mutt_crypt.h"
20 #include "mutt_idna.h"
22 #include "lib/debug.h"
28 void mutt_edit_headers (const char *editor,
30 HEADER * msg, char *fcc, size_t fcclen)
32 char path[_POSIX_PATH_MAX]; /* tempfile used to edit headers + body */
33 char buffer[LONG_STRING];
40 LIST *cur, **last = NULL, *tmp;
43 if ((ofp = safe_fopen (path, "w")) == NULL) {
48 mutt_env_to_local (msg->env);
49 mutt_write_rfc822_header (ofp, msg->env, NULL, 1, 0);
50 fputc ('\n', ofp); /* tie off the header. */
52 /* now copy the body of the message. */
53 if ((ifp = fopen (body, "r")) == NULL) {
58 mutt_copy_stream (ifp, ofp);
63 if (stat (path, &st) == -1) {
68 mtime = mutt_decrease_mtime (path, &st);
70 mutt_edit_file (editor, path);
72 if (mtime == st.st_mtime) {
73 debug_print (1, ("temp file was not modified.\n"));
74 /* the file has not changed! */
80 mutt_free_list (&msg->env->userhdrs);
82 /* Read the temp file back in */
83 if ((ifp = fopen (path, "r")) == NULL) {
88 if ((ofp = safe_fopen (body, "w")) == NULL) {
89 /* intentionally leak a possible temporary file here */
95 n = mutt_read_rfc822_header (ifp, NULL, 1, 0);
96 while ((i = fread (buffer, 1, sizeof (buffer), ifp)) > 0)
97 fwrite (buffer, 1, i, ofp);
102 /* restore old info. */
103 n->references = msg->env->references;
104 msg->env->references = NULL;
106 mutt_free_envelope (&msg->env);
110 if (!msg->env->in_reply_to)
112 if (!option (OPTNEWSSEND))
114 mutt_free_list (&msg->env->references);
116 mutt_expand_aliases_env (msg->env);
118 /* search through the user defined headers added to see if either a
119 * fcc: or attach-file: field was specified.
122 cur = msg->env->userhdrs;
123 last = &msg->env->userhdrs;
127 /* keep track of whether or not we see the in-reply-to field. if we did
128 * not, remove the references: field later so that we can generate a new
129 * message based upon this one.
131 if (fcc && ascii_strncasecmp ("fcc:", cur->data, 4) == 0) {
132 p = vskipspaces(cur->data + 4);
134 m_strcpy(fcc, fcclen, p);
135 mutt_pretty_mailbox (fcc);
139 else if (ascii_strncasecmp ("attach:", cur->data, 7) == 0) {
144 p = vskipspaces(cur->data + 7);
146 if ((q = strpbrk (p, " \t"))) {
147 str_substrcpy(path, p, q, sizeof(path));
151 m_strcpy(path, sizeof(path), p);
152 mutt_expand_path (path, sizeof (path));
153 if ((body = mutt_make_file_attach (path))) {
154 body->description = m_strdup(q);
155 for (parts = msg->content; parts->next; parts = parts->next);
159 mutt_pretty_mailbox (path);
160 mutt_error (_("%s: unable to attach file"), path);
167 else if ((WithCrypto & APPLICATION_PGP)
168 && ascii_strncasecmp ("pgp:", cur->data, 4) == 0) {
169 msg->security = mutt_parse_crypt_hdr (cur->data + 4, 0);
171 msg->security |= APPLICATION_PGP;
184 mutt_free_list (&tmp);