Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 208 lines (180 sloc) 4.835 kb
e577381 Initial revision
Thomas Roessler authored
1 /*
e8da501 Fix Mike's and my e-mail addresses in copyright lines.
Thomas Roessler authored
2 * Copyright (C) 1996-2000 Michael R. Elkins <me@mutt.org>
e577381 Initial revision
Thomas Roessler authored
3 *
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.
8 *
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.
13 *
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
62255b8 @bcully Gah, forgot the zip code when updating the FSF address...
bcully authored
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
e577381 Initial revision
Thomas Roessler authored
17 */
18
bd77e36 @bcully Add config.h to the top of every C file that could possibly want it.
bcully authored
19 #if HAVE_CONFIG_H
20 # include "config.h"
21 #endif
22
e577381 Initial revision
Thomas Roessler authored
23 #include "mutt.h"
4d4634a - To cleanup the pgp/smime code and prepare for other backends.
Werner Koch authored
24 #include "mutt_crypt.h"
17c0940 IDN support for e-mail messages. Things should work automagically
Thomas Roessler authored
25 #include "mutt_idna.h"
e577381 Initial revision
Thomas Roessler authored
26
27 #include <sys/stat.h>
28 #include <string.h>
29 #include <ctype.h>
30
31 void mutt_edit_headers (const char *editor,
32 const char *body,
33 HEADER *msg,
34 char *fcc,
35 size_t fcclen)
36 {
37 char path[_POSIX_PATH_MAX]; /* tempfile used to edit headers + body */
38 char buffer[LONG_STRING];
39 char *p;
40 FILE *ifp, *ofp;
41 int i, keep;
42 ENVELOPE *n;
43 time_t mtime;
44 struct stat st;
d0c1d60 Some code simplifications.
Thomas Roessler authored
45 LIST *cur, **last = NULL, *tmp;
e577381 Initial revision
Thomas Roessler authored
46
47 mutt_mktemp (path);
48 if ((ofp = safe_fopen (path, "w")) == NULL)
49 {
50 mutt_perror (path);
51 return;
52 }
17c0940 IDN support for e-mail messages. Things should work automagically
Thomas Roessler authored
53
54 mutt_env_to_local (msg->env);
0f14192 A first take at adding a mixmaster front-end to mutt. Don't worry,
Thomas Roessler authored
55 mutt_write_rfc822_header (ofp, msg->env, NULL, 1, 0);
e577381 Initial revision
Thomas Roessler authored
56 fputc ('\n', ofp); /* tie off the header. */
57
58 /* now copy the body of the message. */
59 if ((ifp = fopen (body, "r")) == NULL)
60 {
61 mutt_perror (body);
62 return;
63 }
64
65 mutt_copy_stream (ifp, ofp);
66
67 fclose (ifp);
68 fclose (ofp);
69
70 if (stat (path, &st) == -1)
71 {
72 mutt_perror (path);
73 return;
74 }
75
73bbb97 Byrial Jensen's mtime hack is needed at more than one place. Noted
Thomas Roessler authored
76 mtime = mutt_decrease_mtime (path, &st);
77
e577381 Initial revision
Thomas Roessler authored
78 mutt_edit_file (editor, path);
79 stat (path, &st);
80 if (mtime == st.st_mtime)
81 {
82 dprint (1, (debugfile, "ci_edit_headers(): temp file was not modified.\n"));
83 /* the file has not changed! */
84 mutt_unlink (path);
85 return;
86 }
87
88 mutt_unlink (body);
89 mutt_free_list (&msg->env->userhdrs);
90
91 /* Read the temp file back in */
fcaedd1 Catch some error conditions.
Thomas Roessler authored
92 if ((ifp = fopen (path, "r")) == NULL)
93 {
94 mutt_perror (path);
95 return;
96 }
97
98 if ((ofp = safe_fopen (body, "w")) == NULL)
99 {
100 /* intentionally leak a possible temporary file here */
101 fclose (ifp);
102 mutt_perror (body);
103 return;
104 }
105
1edd26c Add a resend-message function (similar to the _old_ edit-message),
Thomas Roessler authored
106 n = mutt_read_rfc822_header (ifp, NULL, 1, 0);
e577381 Initial revision
Thomas Roessler authored
107 while ((i = fread (buffer, 1, sizeof (buffer), ifp)) > 0)
108 fwrite (buffer, 1, i, ofp);
109 fclose (ofp);
110 fclose (ifp);
111 mutt_unlink (path);
112
113 /* restore old info. */
114 n->references = msg->env->references;
115 msg->env->references = NULL;
9d99562 Fix a memory leak in mutt_free_envelope(); avoid dangling pointers
Thomas Roessler authored
116
e577381 Initial revision
Thomas Roessler authored
117 mutt_free_envelope (&msg->env);
9d99562 Fix a memory leak in mutt_free_envelope(); avoid dangling pointers
Thomas Roessler authored
118 msg->env = n; n = NULL;
119
120 if (!msg->env->in_reply_to)
121 mutt_free_list (&msg->env->references);
e577381 Initial revision
Thomas Roessler authored
122
18a756f Unify alias expansion.
Thomas Roessler authored
123 mutt_expand_aliases_env (msg->env);
9d99562 Fix a memory leak in mutt_free_envelope(); avoid dangling pointers
Thomas Roessler authored
124
a448e8e Expand aliases on the From header.
Thomas Roessler authored
125 /* search through the user defined headers added to see if either a
126 * fcc: or attach-file: field was specified.
127 */
128
e577381 Initial revision
Thomas Roessler authored
129 cur = msg->env->userhdrs;
d0c1d60 Some code simplifications.
Thomas Roessler authored
130 last = &msg->env->userhdrs;
e577381 Initial revision
Thomas Roessler authored
131 while (cur)
132 {
133 keep = 1;
134
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.
138 */
5294e1c Fix header editing and references headers.
Thomas Roessler authored
139 if (fcc && ascii_strncasecmp ("fcc:", cur->data, 4) == 0)
e577381 Initial revision
Thomas Roessler authored
140 {
141 p = cur->data + 4;
142 SKIPWS (p);
143 if (*p)
144 {
145 strfcpy (fcc, p, fcclen);
db860dd Use realpath() in mutt_pretty_mailbox() for paths that may need it.
Rocco Rutte authored
146 mutt_pretty_mailbox (fcc, fcclen);
e577381 Initial revision
Thomas Roessler authored
147 }
148 keep = 0;
149 }
2957bb5 Add ascii_strcasecmp() and ascii_strncasecmp() functions which do
Thomas Roessler authored
150 else if (ascii_strncasecmp ("attach:", cur->data, 7) == 0)
e577381 Initial revision
Thomas Roessler authored
151 {
152 BODY *body;
153 BODY *parts;
154 char *q;
155
156 p = cur->data + 7;
157 SKIPWS (p);
158 if (*p)
159 {
160 if ((q = strpbrk (p, " \t")))
161 {
162 mutt_substrcpy (path, p, q, sizeof (path));
163 SKIPWS (q);
164 }
165 else
166 strfcpy (path, p, sizeof (path));
167 mutt_expand_path (path, sizeof (path));
d63919f CVS branch clean-up.
Thomas Roessler authored
168 if ((body = mutt_make_file_attach (path)))
e577381 Initial revision
Thomas Roessler authored
169 {
170 body->description = safe_strdup (q);
171 for (parts = msg->content; parts->next; parts = parts->next) ;
172 parts->next = body;
173 }
174 else
175 {
db860dd Use realpath() in mutt_pretty_mailbox() for paths that may need it.
Rocco Rutte authored
176 mutt_pretty_mailbox (path, sizeof (path));
c54b70e Adding gettext support, based on the patch by Marco d'Itri.
Thomas Roessler authored
177 mutt_error (_("%s: unable to attach file"), path);
e577381 Initial revision
Thomas Roessler authored
178 }
179 }
180 keep = 0;
181 }
182
183
4d4634a - To cleanup the pgp/smime code and prepare for other backends.
Werner Koch authored
184 else if ((WithCrypto & APPLICATION_PGP)
185 &&ascii_strncasecmp ("pgp:", cur->data, 4) == 0)
e577381 Initial revision
Thomas Roessler authored
186 {
4a39837 Make mutt_parse_crypt_hdr more SMIME-aware.
Moritz.Schulte@ruhr-uni-bochum.de authored
187 msg->security = mutt_parse_crypt_hdr (cur->data + 4, 0, APPLICATION_PGP);
49bc9e7 as of current cvs, setting "PGP: E" (or similar) when header-editing
Adeodato Simó authored
188 if (msg->security)
189 msg->security |= APPLICATION_PGP;
e577381 Initial revision
Thomas Roessler authored
190 keep = 0;
191 }
192
193 if (keep)
194 {
d0c1d60 Some code simplifications.
Thomas Roessler authored
195 last = &cur->next;
196 cur = cur->next;
e577381 Initial revision
Thomas Roessler authored
197 }
198 else
199 {
d0c1d60 Some code simplifications.
Thomas Roessler authored
200 tmp = cur;
201 *last = cur->next;
202 cur = cur->next;
e577381 Initial revision
Thomas Roessler authored
203 tmp->next = NULL;
204 mutt_free_list (&tmp);
205 }
206 }
207 }
Something went wrong with that request. Please try again.