mime_attach.c revision 1.16 1 1.16 christos /* $NetBSD: mime_attach.c,v 1.16 2013/01/04 01:54:55 christos Exp $ */
2 1.1 christos
3 1.1 christos /*-
4 1.1 christos * Copyright (c) 2006 The NetBSD Foundation, Inc.
5 1.1 christos * All rights reserved.
6 1.1 christos *
7 1.1 christos * This code is derived from software contributed to The NetBSD Foundation
8 1.1 christos * by Anon Ymous.
9 1.1 christos *
10 1.1 christos * Redistribution and use in source and binary forms, with or without
11 1.1 christos * modification, are permitted provided that the following conditions
12 1.1 christos * are met:
13 1.1 christos * 1. Redistributions of source code must retain the above copyright
14 1.1 christos * notice, this list of conditions and the following disclaimer.
15 1.1 christos * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 christos * notice, this list of conditions and the following disclaimer in the
17 1.1 christos * documentation and/or other materials provided with the distribution.
18 1.1 christos *
19 1.1 christos * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.1 christos * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.1 christos * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.1 christos * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.1 christos * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.1 christos * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.1 christos * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.1 christos * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.1 christos * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.1 christos * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.1 christos * POSSIBILITY OF SUCH DAMAGE.
30 1.1 christos */
31 1.1 christos
32 1.1 christos #ifdef MIME_SUPPORT
33 1.1 christos
34 1.1 christos #include <sys/cdefs.h>
35 1.1 christos #ifndef __lint__
36 1.16 christos __RCSID("$NetBSD: mime_attach.c,v 1.16 2013/01/04 01:54:55 christos Exp $");
37 1.1 christos #endif /* not __lint__ */
38 1.1 christos
39 1.1 christos #include <assert.h>
40 1.1 christos #include <err.h>
41 1.1 christos #include <fcntl.h>
42 1.1 christos #include <libgen.h>
43 1.1 christos #include <magic.h>
44 1.1 christos #include <signal.h>
45 1.1 christos #include <stdio.h>
46 1.1 christos #include <stdlib.h>
47 1.1 christos #include <string.h>
48 1.1 christos #include <unistd.h>
49 1.1 christos #include <util.h>
50 1.1 christos
51 1.1 christos #include "def.h"
52 1.1 christos #include "extern.h"
53 1.1 christos #ifdef USE_EDITLINE
54 1.1 christos #include "complete.h"
55 1.1 christos #endif
56 1.1 christos #ifdef MIME_SUPPORT
57 1.1 christos #include "mime.h"
58 1.1 christos #include "mime_codecs.h"
59 1.1 christos #include "mime_child.h"
60 1.1 christos #endif
61 1.1 christos #include "glob.h"
62 1.12 christos #include "sig.h"
63 1.1 christos
64 1.1 christos #if 0
65 1.1 christos /*
66 1.7 christos * XXX - This block is for debugging only and eventually should go away.
67 1.7 christos */
68 1.7 christos # define SHOW_ALIST(a,b) show_alist(a,b)
69 1.7 christos static void
70 1.7 christos show_alist(struct attachment *alist, struct attachment *ap)
71 1.7 christos {
72 1.7 christos (void)printf("alist=%p ap=%p\n", alist, ap);
73 1.7 christos for (ap = alist; ap; ap = ap->a_flink) {
74 1.7 christos (void)printf("ap=%p ap->a_flink=%p ap->a_blink=%p ap->a_name=%s\n",
75 1.7 christos ap, ap->a_flink, ap->a_blink, ap->a_name ? ap->a_name : "<null>");
76 1.7 christos }
77 1.7 christos }
78 1.7 christos #else
79 1.7 christos # define SHOW_ALIST(a,b)
80 1.7 christos #endif
81 1.7 christos
82 1.7 christos #if 0
83 1.7 christos #ifndef __lint__ /* Don't lint: the public routines may not be used. */
84 1.7 christos /*
85 1.7 christos * XXX - This block for is debugging only and eventually should go away.
86 1.1 christos */
87 1.1 christos static void
88 1.1 christos show_name(const char *prefix, struct name *np)
89 1.1 christos {
90 1.1 christos int i;
91 1.1 christos
92 1.1 christos i = 0;
93 1.5 christos for (/*EMPTY*/; np; np = np->n_flink) {
94 1.1 christos (void)printf("%s[%d]: %s\n", prefix, i, np->n_name);
95 1.1 christos i++;
96 1.1 christos }
97 1.1 christos }
98 1.1 christos
99 1.2 christos static void fput_mime_content(FILE *fp, struct Content *Cp);
100 1.2 christos
101 1.1 christos PUBLIC void
102 1.1 christos show_attach(const char *prefix, struct attachment *ap)
103 1.1 christos {
104 1.1 christos int i;
105 1.1 christos i = 1;
106 1.5 christos for (/*EMPTY*/; ap; ap = ap->a_flink) {
107 1.1 christos (void)printf("%s[%d]:\n", prefix, i);
108 1.1 christos fput_mime_content(stdout, &ap->a_Content);
109 1.1 christos i++;
110 1.1 christos }
111 1.1 christos }
112 1.1 christos
113 1.1 christos PUBLIC void
114 1.1 christos show_header(struct header *hp)
115 1.1 christos {
116 1.1 christos show_name("TO", hp->h_to);
117 1.1 christos (void)printf("SUBJECT: %s\n", hp->h_subject);
118 1.1 christos show_name("CC", hp->h_cc);
119 1.1 christos show_name("BCC", hp->h_bcc);
120 1.1 christos show_name("SMOPTS", hp->h_smopts);
121 1.1 christos show_attach("ATTACH", hp->h_attach);
122 1.1 christos }
123 1.1 christos #endif /* __lint__ */
124 1.1 christos #endif
125 1.1 christos
126 1.1 christos /***************************
127 1.1 christos * boundary string routines
128 1.1 christos */
129 1.1 christos static char *
130 1.1 christos getrandstring(size_t length)
131 1.1 christos {
132 1.1 christos void *vbin;
133 1.1 christos uint32_t *bin;
134 1.1 christos size_t binlen;
135 1.1 christos size_t i;
136 1.1 christos char *b64;
137 1.1 christos
138 1.1 christos /* XXX - check this stuff again!!! */
139 1.1 christos
140 1.1 christos binlen = 3 * roundup(length, 4) / 4; /* bytes of binary to encode base64 */
141 1.1 christos bin = vbin = salloc(roundup(binlen, 4));
142 1.1 christos for (i = 0; i < roundup(binlen, 4) / 4; i++)
143 1.1 christos bin[i] = arc4random();
144 1.1 christos
145 1.1 christos b64 = salloc(roundup(length, 4));
146 1.1 christos mime_bintob64(b64, vbin, binlen);
147 1.1 christos b64[length] = '\0';
148 1.1 christos
149 1.1 christos return b64;
150 1.1 christos }
151 1.1 christos
152 1.1 christos /*
153 1.1 christos * Generate a boundary for MIME multipart messages.
154 1.1 christos */
155 1.1 christos static char *
156 1.1 christos make_boundary(void)
157 1.1 christos {
158 1.1 christos #define BOUND_LEN 70 /* maximum length is 70 characters: RFC2046 sec 5.1.1 */
159 1.1 christos
160 1.1 christos char *bound;
161 1.1 christos time_t now;
162 1.1 christos
163 1.1 christos (void)time(&now);
164 1.1 christos bound = salloc(BOUND_LEN);
165 1.1 christos (void)snprintf(bound, BOUND_LEN, "=_%08lx.%s",
166 1.1 christos (long)now, getrandstring(BOUND_LEN - 12));
167 1.1 christos return bound;
168 1.1 christos
169 1.1 christos #undef BOUND_LEN
170 1.1 christos }
171 1.1 christos
172 1.1 christos /***************************
173 1.1 christos * Transfer coding routines
174 1.1 christos */
175 1.1 christos /*
176 1.1 christos * We determine the recommended transfer encoding type for a file as
177 1.1 christos * follows:
178 1.1 christos *
179 1.1 christos * 1) If there is a NULL byte or a stray CR (not in a CRLF
180 1.1 christos * combination) in the file, play it safe and use base64.
181 1.1 christos *
182 1.1 christos * 2) If any high bit is set, use quoted-printable if the content type
183 1.1 christos * is "text" and base64 otherwise.
184 1.1 christos *
185 1.1 christos * 3) Otherwise:
186 1.1 christos * a) use quoted-printable if there are any long lines, control
187 1.1 christos * chars (including CR), end-of-line blank space, or a missing
188 1.1 christos * terminating NL.
189 1.1 christos * b) use 7bit in all remaining case, including an empty file.
190 1.1 christos *
191 1.1 christos * NOTE: This means that CRLF text (MSDOS) files will be encoded
192 1.1 christos * quoted-printable.
193 1.5 christos */
194 1.1 christos /*
195 1.1 christos * RFC 821 imposes the following line length limit:
196 1.1 christos * The maximum total length of a text line including the
197 1.1 christos * <CRLF> is 1000 characters (but not counting the leading
198 1.1 christos * dot duplicated for transparency).
199 1.1 christos */
200 1.1 christos #define MIME_UNENCODED_LINE_MAX (1000 - 2)
201 1.1 christos static size_t
202 1.1 christos line_limit(void)
203 1.1 christos {
204 1.1 christos int limit;
205 1.1 christos const char *cp;
206 1.1 christos limit = -1;
207 1.1 christos
208 1.1 christos if ((cp = value(ENAME_MIME_UNENC_LINE_MAX)) != NULL)
209 1.1 christos limit = atoi(cp);
210 1.1 christos
211 1.1 christos if (limit < 0 || limit > MIME_UNENCODED_LINE_MAX)
212 1.1 christos limit = MIME_UNENCODED_LINE_MAX;
213 1.1 christos
214 1.1 christos return (size_t)limit;
215 1.1 christos }
216 1.1 christos
217 1.3 christos static inline int
218 1.3 christos is_text(const char *ctype)
219 1.1 christos {
220 1.1 christos return ctype &&
221 1.1 christos strncasecmp(ctype, "text/", sizeof("text/") - 1) == 0;
222 1.1 christos }
223 1.1 christos
224 1.1 christos static const char *
225 1.1 christos content_encoding_core(void *fh, const char *ctype)
226 1.1 christos {
227 1.16 christos #define MAILMSG_CLEAN 0x0
228 1.16 christos #define MAILMSG_ENDWS 0x1
229 1.16 christos #define MAILMSG_CTRLC 0x2
230 1.16 christos #define MAILMSG_8BIT 0x4
231 1.16 christos #define MAILMSG_LONGL 0x8
232 1.16 christos int c, lastc, state;
233 1.1 christos int ctrlchar, endwhite;
234 1.1 christos size_t curlen, maxlen;
235 1.5 christos
236 1.16 christos state = MAILMSG_CLEAN;
237 1.1 christos curlen = 0;
238 1.16 christos maxlen = line_limit();
239 1.1 christos ctrlchar = 0;
240 1.1 christos endwhite = 0;
241 1.1 christos lastc = EOF;
242 1.1 christos while ((c = fgetc(fh)) != EOF) {
243 1.1 christos curlen++;
244 1.5 christos
245 1.15 christos if (c == '\0')
246 1.1 christos return MIME_TRANSFER_BASE64;
247 1.1 christos
248 1.1 christos if (c > 0x7f) {
249 1.16 christos if (!is_text(ctype))
250 1.1 christos return MIME_TRANSFER_BASE64;
251 1.16 christos state |= MAILMSG_8BIT;
252 1.16 christos continue;
253 1.1 christos }
254 1.1 christos if (c == '\n') {
255 1.5 christos if (is_WSP(lastc))
256 1.16 christos state |= MAILMSG_ENDWS;
257 1.1 christos if (curlen > maxlen)
258 1.16 christos state |= MAILMSG_LONGL;
259 1.1 christos curlen = 0;
260 1.1 christos }
261 1.15 christos else if ((c < 0x20 && c != '\t') || c == 0x7f || lastc == '\r')
262 1.16 christos state |= MAILMSG_CTRLC;
263 1.1 christos lastc = c;
264 1.1 christos }
265 1.1 christos if (lastc == EOF) /* no characters read */
266 1.1 christos return MIME_TRANSFER_7BIT;
267 1.1 christos
268 1.16 christos if (lastc != '\n' || state != MAILMSG_CLEAN)
269 1.1 christos return MIME_TRANSFER_QUOTED;
270 1.1 christos
271 1.1 christos return MIME_TRANSFER_7BIT;
272 1.1 christos }
273 1.1 christos
274 1.1 christos static const char *
275 1.1 christos content_encoding_by_name(const char *filename, const char *ctype)
276 1.1 christos {
277 1.1 christos FILE *fp;
278 1.1 christos const char *enc;
279 1.14 christos fp = Fopen(filename, "re");
280 1.1 christos if (fp == NULL) {
281 1.1 christos warn("content_encoding_by_name: %s", filename);
282 1.1 christos return MIME_TRANSFER_BASE64; /* safe */
283 1.1 christos }
284 1.1 christos enc = content_encoding_core(fp, ctype);
285 1.8 christos (void)Fclose(fp);
286 1.1 christos return enc;
287 1.1 christos }
288 1.1 christos
289 1.1 christos static const char *
290 1.1 christos content_encoding_by_fileno(int fd, const char *ctype)
291 1.1 christos {
292 1.1 christos FILE *fp;
293 1.8 christos int fd2;
294 1.1 christos const char *encoding;
295 1.1 christos off_t cur_pos;
296 1.1 christos
297 1.1 christos cur_pos = lseek(fd, (off_t)0, SEEK_CUR);
298 1.8 christos if ((fd2 = dup(fd)) == -1 ||
299 1.14 christos (fp = Fdopen(fd2, "re")) == NULL) {
300 1.1 christos warn("content_encoding_by_fileno");
301 1.8 christos if (fd2 != -1)
302 1.8 christos (void)close(fd2);
303 1.1 christos return MIME_TRANSFER_BASE64;
304 1.1 christos }
305 1.1 christos encoding = content_encoding_core(fp, ctype);
306 1.9 christos (void)Fclose(fp);
307 1.1 christos (void)lseek(fd, cur_pos, SEEK_SET);
308 1.1 christos return encoding;
309 1.1 christos }
310 1.1 christos
311 1.1 christos static const char *
312 1.7 christos content_encoding(struct attachment *ap, const char *ctype)
313 1.1 christos {
314 1.7 christos switch (ap->a_type) {
315 1.1 christos case ATTACH_FNAME:
316 1.7 christos return content_encoding_by_name(ap->a_name, ctype);
317 1.1 christos case ATTACH_MSG:
318 1.7 christos return "7bit";
319 1.1 christos case ATTACH_FILENO:
320 1.7 christos return content_encoding_by_fileno(ap->a_fileno, ctype);
321 1.7 christos case ATTACH_INVALID:
322 1.1 christos default:
323 1.7 christos /* This is a coding error! */
324 1.7 christos assert(/* CONSTCOND */ 0);
325 1.7 christos errx(EXIT_FAILURE, "invalid attachment type: %d", ap->a_type);
326 1.7 christos /* NOTREACHED */
327 1.1 christos }
328 1.1 christos }
329 1.1 christos
330 1.1 christos /************************
331 1.1 christos * Content type routines
332 1.1 christos */
333 1.1 christos /*
334 1.1 christos * We use libmagic(3) to get the content type, except in the case of a
335 1.4 christos * 0 or 1 byte file where libmagic gives rather useless results.
336 1.1 christos */
337 1.1 christos static const char *
338 1.4 christos content_type_by_name(char *filename)
339 1.1 christos {
340 1.1 christos const char *cp;
341 1.4 christos char *cp2;
342 1.1 christos magic_t magic;
343 1.1 christos struct stat sb;
344 1.1 christos
345 1.13 christos #ifdef BROKEN_MAGIC
346 1.1 christos /*
347 1.13 christos * libmagic(3) produces annoying results on very short files.
348 1.13 christos * The common case is MIME encoding an empty message body.
349 1.13 christos * XXX - it would be better to fix libmagic(3)!
350 1.4 christos *
351 1.4 christos * Note: a 1-byte message body always consists of a newline,
352 1.4 christos * so size determines all there. However, 1-byte attachments
353 1.4 christos * (filename != NULL) could be anything, so check those.
354 1.1 christos */
355 1.1 christos if ((filename != NULL && stat(filename, &sb) == 0) ||
356 1.4 christos (filename == NULL && fstat(0, &sb) == 0)) {
357 1.4 christos if (sb.st_size < 2 && S_ISREG(sb.st_mode)) {
358 1.4 christos FILE *fp;
359 1.4 christos int ch;
360 1.13 christos
361 1.4 christos if (sb.st_size == 0 || filename == NULL ||
362 1.14 christos (fp = Fopen(filename, "re")) == NULL)
363 1.4 christos return "text/plain";
364 1.4 christos
365 1.4 christos ch = fgetc(fp);
366 1.8 christos (void)Fclose(fp);
367 1.4 christos
368 1.4 christos return isprint(ch) || isspace(ch) ?
369 1.4 christos "text/plain" : "application/octet-stream";
370 1.4 christos }
371 1.4 christos }
372 1.13 christos #endif
373 1.1 christos magic = magic_open(MAGIC_MIME);
374 1.1 christos if (magic == NULL) {
375 1.11 christos warnx("magic_open: %s", magic_error(magic));
376 1.1 christos return NULL;
377 1.1 christos }
378 1.1 christos if (magic_load(magic, NULL) != 0) {
379 1.11 christos warnx("magic_load: %s", magic_error(magic));
380 1.1 christos return NULL;
381 1.1 christos }
382 1.1 christos cp = magic_file(magic, filename);
383 1.1 christos if (cp == NULL) {
384 1.12 christos warnx("magic_load: %s", magic_error(magic));
385 1.1 christos return NULL;
386 1.1 christos }
387 1.4 christos if (filename &&
388 1.4 christos sasprintf(&cp2, "%s; name=\"%s\"", cp, basename(filename)) != -1)
389 1.4 christos cp = cp2;
390 1.4 christos else
391 1.4 christos cp = savestr(cp);
392 1.1 christos magic_close(magic);
393 1.1 christos return cp;
394 1.1 christos }
395 1.1 christos
396 1.1 christos static const char *
397 1.1 christos content_type_by_fileno(int fd)
398 1.1 christos {
399 1.1 christos const char *cp;
400 1.1 christos off_t cur_pos;
401 1.1 christos int ofd;
402 1.1 christos
403 1.1 christos cur_pos = lseek(fd, (off_t)0, SEEK_CUR);
404 1.1 christos
405 1.1 christos ofd = dup(0); /* save stdin */
406 1.1 christos if (dup2(fd, 0) == -1) /* become stdin */
407 1.1 christos warn("dup2");
408 1.1 christos
409 1.1 christos cp = content_type_by_name(NULL);
410 1.1 christos
411 1.1 christos if (dup2(ofd, 0) == -1) /* restore stdin */
412 1.1 christos warn("dup2");
413 1.1 christos (void)close(ofd); /* close the copy */
414 1.1 christos
415 1.5 christos (void)lseek(fd, cur_pos, SEEK_SET);
416 1.1 christos return cp;
417 1.1 christos }
418 1.1 christos
419 1.1 christos static const char *
420 1.7 christos content_type(struct attachment *ap)
421 1.1 christos {
422 1.7 christos switch (ap->a_type) {
423 1.1 christos case ATTACH_FNAME:
424 1.7 christos return content_type_by_name(ap->a_name);
425 1.1 christos case ATTACH_MSG:
426 1.7 christos /*
427 1.7 christos * Note: the encapusulated message header must include
428 1.7 christos * at least one of the "Date:", "From:", or "Subject:"
429 1.7 christos * fields. See rfc2046 Sec 5.2.1.
430 1.7 christos * XXX - Should we really test for this?
431 1.7 christos */
432 1.1 christos return "message/rfc822";
433 1.1 christos case ATTACH_FILENO:
434 1.7 christos return content_type_by_fileno(ap->a_fileno);
435 1.7 christos case ATTACH_INVALID:
436 1.1 christos default:
437 1.1 christos /* This is a coding error! */
438 1.1 christos assert(/* CONSTCOND */ 0);
439 1.7 christos errx(EXIT_FAILURE, "invalid attachment type: %d", ap->a_type);
440 1.7 christos /* NOTREACHED */
441 1.1 christos }
442 1.1 christos }
443 1.1 christos
444 1.1 christos /*************************
445 1.1 christos * Other content routines
446 1.1 christos */
447 1.1 christos
448 1.1 christos static const char *
449 1.1 christos content_disposition(struct attachment *ap)
450 1.1 christos {
451 1.1 christos switch (ap->a_type) {
452 1.1 christos case ATTACH_FNAME: {
453 1.1 christos char *disp;
454 1.7 christos (void)sasprintf(&disp, "attachment; filename=\"%s\"",
455 1.7 christos basename(ap->a_name));
456 1.1 christos return disp;
457 1.1 christos }
458 1.1 christos case ATTACH_MSG:
459 1.7 christos return NULL;
460 1.1 christos case ATTACH_FILENO:
461 1.1 christos return "inline";
462 1.5 christos
463 1.7 christos case ATTACH_INVALID:
464 1.1 christos default:
465 1.7 christos /* This is a coding error! */
466 1.7 christos assert(/* CONSTCOND */ 0);
467 1.7 christos errx(EXIT_FAILURE, "invalid attachment type: %d", ap->a_type);
468 1.7 christos /* NOTREACHED */
469 1.1 christos }
470 1.1 christos }
471 1.1 christos
472 1.5 christos /*ARGSUSED*/
473 1.1 christos static const char *
474 1.7 christos content_id(struct attachment *ap __unused)
475 1.1 christos {
476 1.1 christos /* XXX - to be written. */
477 1.5 christos
478 1.1 christos return NULL;
479 1.1 christos }
480 1.1 christos
481 1.1 christos static const char *
482 1.1 christos content_description(struct attachment *attach, int attach_num)
483 1.1 christos {
484 1.1 christos if (attach_num) {
485 1.1 christos char *description;
486 1.3 christos (void)sasprintf(&description, "attachment %d", attach_num);
487 1.1 christos return description;
488 1.1 christos }
489 1.1 christos else
490 1.1 christos return attach->a_Content.C_description;
491 1.1 christos }
492 1.1 christos
493 1.1 christos /*******************************************
494 1.1 christos * Routines to get the MIME content strings.
495 1.1 christos */
496 1.7 christos PUBLIC struct Content
497 1.1 christos get_mime_content(struct attachment *ap, int i)
498 1.1 christos {
499 1.1 christos struct Content Cp;
500 1.1 christos
501 1.1 christos Cp.C_type = content_type(ap);
502 1.1 christos Cp.C_encoding = content_encoding(ap, Cp.C_type);
503 1.1 christos Cp.C_disposition = content_disposition(ap);
504 1.1 christos Cp.C_id = content_id(ap);
505 1.1 christos Cp.C_description = content_description(ap, i);
506 1.1 christos
507 1.1 christos return Cp;
508 1.1 christos }
509 1.1 christos
510 1.1 christos /******************
511 1.1 christos * Output routines
512 1.1 christos */
513 1.1 christos static void
514 1.1 christos fput_mime_content(FILE *fp, struct Content *Cp)
515 1.1 christos {
516 1.1 christos (void)fprintf(fp, MIME_HDR_TYPE ": %s\n", Cp->C_type);
517 1.1 christos (void)fprintf(fp, MIME_HDR_ENCODING ": %s\n", Cp->C_encoding);
518 1.1 christos if (Cp->C_disposition)
519 1.1 christos (void)fprintf(fp, MIME_HDR_DISPOSITION ": %s\n",
520 1.1 christos Cp->C_disposition);
521 1.1 christos if (Cp->C_id)
522 1.1 christos (void)fprintf(fp, MIME_HDR_ID ": %s\n", Cp->C_id);
523 1.1 christos if (Cp->C_description)
524 1.1 christos (void)fprintf(fp, MIME_HDR_DESCRIPTION ": %s\n",
525 1.1 christos Cp->C_description);
526 1.1 christos }
527 1.1 christos
528 1.1 christos static void
529 1.1 christos fput_body(FILE *fi, FILE *fo, struct Content *Cp)
530 1.1 christos {
531 1.1 christos mime_codec_t enc;
532 1.1 christos
533 1.1 christos enc = mime_fio_encoder(Cp->C_encoding);
534 1.1 christos if (enc == NULL)
535 1.1 christos warnx("unknown transfer encoding type: %s\n", Cp->C_encoding);
536 1.1 christos else
537 1.1 christos enc(fi, fo, 0);
538 1.1 christos }
539 1.1 christos
540 1.1 christos static void
541 1.1 christos fput_attachment(FILE *fo, struct attachment *ap)
542 1.1 christos {
543 1.1 christos FILE *fi;
544 1.1 christos struct Content *Cp = &ap->a_Content;
545 1.1 christos
546 1.1 christos fput_mime_content(fo, &ap->a_Content);
547 1.1 christos (void)putc('\n', fo);
548 1.1 christos
549 1.1 christos switch (ap->a_type) {
550 1.1 christos case ATTACH_FNAME:
551 1.14 christos fi = Fopen(ap->a_name, "re");
552 1.1 christos if (fi == NULL)
553 1.8 christos err(EXIT_FAILURE, "Fopen: %s", ap->a_name);
554 1.1 christos break;
555 1.1 christos
556 1.1 christos case ATTACH_FILENO:
557 1.8 christos /*
558 1.8 christos * XXX - we should really dup(2) here, however we are
559 1.8 christos * finished with the attachment, so the Fclose() below
560 1.8 christos * is OK for now. This will be changed in the future.
561 1.8 christos */
562 1.14 christos fi = Fdopen(ap->a_fileno, "re");
563 1.1 christos if (fi == NULL)
564 1.8 christos err(EXIT_FAILURE, "Fdopen: %d", ap->a_fileno);
565 1.1 christos break;
566 1.1 christos
567 1.7 christos case ATTACH_MSG: {
568 1.7 christos char mailtempname[PATHSIZE];
569 1.7 christos int fd;
570 1.7 christos
571 1.7 christos fi = NULL; /* appease gcc */
572 1.7 christos (void)snprintf(mailtempname, sizeof(mailtempname),
573 1.7 christos "%s/mail.RsXXXXXXXXXX", tmpdir);
574 1.7 christos if ((fd = mkstemp(mailtempname)) == -1 ||
575 1.14 christos (fi = Fdopen(fd, "we+")) == NULL) {
576 1.7 christos if (fd != -1)
577 1.7 christos (void)close(fd);
578 1.7 christos err(EXIT_FAILURE, "%s", mailtempname);
579 1.7 christos }
580 1.7 christos (void)rm(mailtempname);
581 1.7 christos
582 1.7 christos /*
583 1.7 christos * This is only used for forwarding, so use the forwardtab[].
584 1.7 christos *
585 1.7 christos * XXX - sendmessage really needs a 'flags' argument
586 1.7 christos * so we don't have to play games.
587 1.7 christos */
588 1.7 christos ap->a_msg->m_size--; /* XXX - remove trailing newline */
589 1.7 christos (void)fputc('>', fi); /* XXX - hide the headerline */
590 1.7 christos if (sendmessage(ap->a_msg, fi, forwardtab, NULL, NULL))
591 1.7 christos (void)fprintf(stderr, ". . . forward failed, sorry.\n");
592 1.7 christos ap->a_msg->m_size++;
593 1.7 christos
594 1.7 christos rewind(fi);
595 1.7 christos break;
596 1.7 christos }
597 1.7 christos case ATTACH_INVALID:
598 1.1 christos default:
599 1.7 christos /* This is a coding error! */
600 1.7 christos assert(/* CONSTCOND */ 0);
601 1.7 christos errx(EXIT_FAILURE, "invalid attachment type: %d", ap->a_type);
602 1.1 christos }
603 1.1 christos
604 1.1 christos fput_body(fi, fo, Cp);
605 1.8 christos (void)Fclose(fi);
606 1.1 christos }
607 1.1 christos
608 1.1 christos /***********************************
609 1.1 christos * Higher level attachment routines.
610 1.1 christos */
611 1.1 christos
612 1.1 christos static int
613 1.1 christos mktemp_file(FILE **nfo, FILE **nfi, const char *hint)
614 1.1 christos {
615 1.1 christos char tempname[PATHSIZE];
616 1.1 christos int fd, fd2;
617 1.1 christos (void)snprintf(tempname, sizeof(tempname), "%s/%sXXXXXXXXXX",
618 1.1 christos tmpdir, hint);
619 1.1 christos if ((fd = mkstemp(tempname)) == -1 ||
620 1.14 christos (*nfo = Fdopen(fd, "we")) == NULL) {
621 1.1 christos if (fd != -1)
622 1.1 christos (void)close(fd);
623 1.1 christos warn("%s", tempname);
624 1.1 christos return -1;
625 1.1 christos }
626 1.1 christos (void)rm(tempname);
627 1.1 christos if ((fd2 = dup(fd)) == -1 ||
628 1.14 christos (*nfi = Fdopen(fd2, "re")) == NULL) {
629 1.1 christos warn("%s", tempname);
630 1.1 christos (void)Fclose(*nfo);
631 1.1 christos return -1;
632 1.1 christos }
633 1.1 christos return 0;
634 1.1 christos }
635 1.1 christos
636 1.1 christos /*
637 1.1 christos * Repackage the mail as a multipart MIME message. This should always
638 1.1 christos * be called whenever there are attachments, but might be called even
639 1.1 christos * if there are none if we want to wrap the message in a MIME package.
640 1.1 christos */
641 1.1 christos PUBLIC FILE *
642 1.1 christos mime_encode(FILE *fi, struct header *header)
643 1.1 christos {
644 1.1 christos struct attachment map; /* fake structure for the message body */
645 1.1 christos struct attachment *attach;
646 1.1 christos struct attachment *ap;
647 1.1 christos FILE *nfi, *nfo;
648 1.1 christos
649 1.1 christos attach = header->h_attach;
650 1.1 christos
651 1.1 christos /*
652 1.1 christos * Make new phantom temporary file with read and write file
653 1.1 christos * handles: nfi and nfo, resp.
654 1.1 christos */
655 1.1 christos if (mktemp_file(&nfo, &nfi, "mail.Rs") != 0)
656 1.1 christos return fi;
657 1.1 christos
658 1.1 christos (void)memset(&map, 0, sizeof(map));
659 1.1 christos map.a_type = ATTACH_FILENO;
660 1.1 christos map.a_fileno = fileno(fi);
661 1.1 christos
662 1.1 christos map.a_Content = get_mime_content(&map, 0);
663 1.1 christos
664 1.1 christos if (attach) {
665 1.1 christos /* Multi-part message:
666 1.1 christos * Make an attachment structure for the body message
667 1.1 christos * and make that the first element in the attach list.
668 1.1 christos */
669 1.1 christos if (fsize(fi)) {
670 1.1 christos map.a_flink = attach;
671 1.1 christos attach->a_blink = ↦
672 1.1 christos attach = ↦
673 1.1 christos }
674 1.1 christos
675 1.1 christos /* Construct our MIME boundary string - used by mime_putheader() */
676 1.1 christos header->h_mime_boundary = make_boundary();
677 1.5 christos
678 1.1 christos (void)fprintf(nfo, "This is a multi-part message in MIME format.\n");
679 1.5 christos
680 1.1 christos for (ap = attach; ap; ap = ap->a_flink) {
681 1.1 christos (void)fprintf(nfo, "\n--%s\n", header->h_mime_boundary);
682 1.1 christos fput_attachment(nfo, ap);
683 1.1 christos }
684 1.5 christos
685 1.1 christos /* the final boundary with two attached dashes */
686 1.1 christos (void)fprintf(nfo, "\n--%s--\n", header->h_mime_boundary);
687 1.1 christos }
688 1.1 christos else {
689 1.1 christos /* Single-part message (no attachments):
690 1.1 christos * Update header->h_Content (used by mime_putheader()).
691 1.1 christos * Output the body contents.
692 1.1 christos */
693 1.1 christos char *encoding;
694 1.1 christos
695 1.1 christos header->h_Content = map.a_Content;
696 1.5 christos
697 1.1 christos /* check for an encoding override */
698 1.1 christos if ((encoding = value(ENAME_MIME_ENCODE_MSG)) && *encoding)
699 1.1 christos header->h_Content.C_encoding = encoding;
700 1.1 christos
701 1.1 christos fput_body(fi, nfo, &header->h_Content);
702 1.1 christos }
703 1.1 christos (void)Fclose(fi);
704 1.1 christos (void)Fclose(nfo);
705 1.1 christos rewind(nfi);
706 1.3 christos return nfi;
707 1.1 christos }
708 1.1 christos
709 1.1 christos static char*
710 1.1 christos check_filename(char *filename, char *canon_name)
711 1.1 christos {
712 1.1 christos int fd;
713 1.1 christos struct stat sb;
714 1.1 christos char *fname = filename;
715 1.3 christos
716 1.2 christos /* We need to expand '~' if we got here from '~@'. The shell
717 1.2 christos * does this otherwise.
718 1.2 christos */
719 1.1 christos if (fname[0] == '~' && fname[1] == '/') {
720 1.2 christos if (homedir && homedir[0] != '~')
721 1.2 christos (void)easprintf(&fname, "%s/%s",
722 1.2 christos homedir, fname + 2);
723 1.1 christos }
724 1.1 christos if (realpath(fname, canon_name) == NULL) {
725 1.1 christos warn("realpath: %s", filename);
726 1.1 christos canon_name = NULL;
727 1.1 christos goto done;
728 1.1 christos }
729 1.1 christos fd = open(canon_name, O_RDONLY, 0);
730 1.1 christos if (fd == -1) {
731 1.1 christos warnx("open: cannot read %s", filename);
732 1.1 christos canon_name = NULL;
733 1.1 christos goto done;
734 1.1 christos }
735 1.1 christos if (fstat(fd, &sb) == -1) {
736 1.1 christos warn("stat: %s", canon_name);
737 1.1 christos canon_name = NULL;
738 1.1 christos goto do_close;
739 1.1 christos }
740 1.1 christos if (!S_ISREG(sb.st_mode)) {
741 1.1 christos warnx("stat: %s is not a file", filename);
742 1.1 christos canon_name = NULL;
743 1.2 christos /* goto do_close; */
744 1.1 christos }
745 1.1 christos do_close:
746 1.1 christos (void)close(fd);
747 1.1 christos done:
748 1.1 christos if (fname != filename)
749 1.1 christos free(fname);
750 1.1 christos
751 1.1 christos return canon_name;
752 1.1 christos }
753 1.1 christos
754 1.1 christos static struct attachment *
755 1.7 christos attach_one_file(struct attachment *ap, char *filename, int attach_num)
756 1.1 christos {
757 1.1 christos char canon_name[MAXPATHLEN];
758 1.7 christos struct attachment *nap;
759 1.1 christos
760 1.3 christos /*
761 1.7 christos * 1) check that filename is really a readable file; return NULL if not.
762 1.3 christos * 2) allocate an attachment structure.
763 1.3 christos * 3) save cananonical name for filename, so cd won't screw things later.
764 1.3 christos * 4) add the structure to the end of the chain.
765 1.7 christos * 5) return the new attachment structure.
766 1.3 christos */
767 1.1 christos if (check_filename(filename, canon_name) == NULL)
768 1.1 christos return NULL;
769 1.5 christos
770 1.1 christos nap = csalloc(1, sizeof(*nap));
771 1.1 christos nap->a_type = ATTACH_FNAME;
772 1.1 christos nap->a_name = savestr(canon_name);
773 1.1 christos
774 1.7 christos if (ap) {
775 1.7 christos for (/*EMPTY*/; ap->a_flink != NULL; ap = ap->a_flink)
776 1.1 christos continue;
777 1.1 christos ap->a_flink = nap;
778 1.1 christos nap->a_blink = ap;
779 1.1 christos }
780 1.1 christos
781 1.1 christos if (attach_num)
782 1.1 christos nap->a_Content = get_mime_content(nap, attach_num);
783 1.1 christos
784 1.7 christos return nap;
785 1.1 christos }
786 1.1 christos
787 1.1 christos static char *
788 1.1 christos get_line(el_mode_t *em, const char *pr, const char *str, int i)
789 1.1 christos {
790 1.3 christos char *prompt;
791 1.1 christos char *line;
792 1.1 christos
793 1.3 christos /*
794 1.3 christos * Don't use a '\t' in the format string here as completion
795 1.3 christos * seems to handle it badly.
796 1.3 christos */
797 1.7 christos (void)easprintf(&prompt, "#%-7d %s: ", i, pr);
798 1.12 christos line = my_gets(em, prompt, __UNCONST(str));
799 1.12 christos if (line != NULL) {
800 1.12 christos (void)strip_WSP(line); /* strip trailing whitespace */
801 1.12 christos line = skip_WSP(line); /* skip leading white space */
802 1.12 christos line = savestr(line); /* XXX - do we need this? */
803 1.12 christos }
804 1.12 christos else {
805 1.12 christos line = __UNCONST("");
806 1.12 christos }
807 1.1 christos free(prompt);
808 1.1 christos
809 1.3 christos return line;
810 1.1 christos }
811 1.1 christos
812 1.1 christos static void
813 1.1 christos sget_line(el_mode_t *em, const char *pr, const char **str, int i)
814 1.1 christos {
815 1.1 christos char *line;
816 1.1 christos line = get_line(em, pr, *str, i);
817 1.12 christos if (line != NULL && strcmp(line, *str) != 0)
818 1.12 christos *str = line;
819 1.1 christos }
820 1.1 christos
821 1.1 christos static void
822 1.1 christos sget_encoding(const char **str, const char *filename, const char *ctype, int num)
823 1.1 christos {
824 1.1 christos const char *ename;
825 1.1 christos const char *defename;
826 1.1 christos
827 1.1 christos defename = NULL;
828 1.1 christos ename = *str;
829 1.1 christos for (;;) {
830 1.1 christos ename = get_line(&elm.mime_enc, "encoding", ename, num);
831 1.1 christos
832 1.1 christos if (*ename == '\0') {
833 1.1 christos if (defename == NULL)
834 1.1 christos defename = content_encoding_by_name(filename, ctype);
835 1.1 christos ename = defename;
836 1.1 christos }
837 1.1 christos else if (mime_fio_encoder(ename) == NULL) {
838 1.1 christos const void *cookie;
839 1.1 christos (void)printf("Sorry: valid encoding modes are: ");
840 1.1 christos cookie = NULL;
841 1.1 christos ename = mime_next_encoding_name(&cookie);
842 1.1 christos for (;;) {
843 1.1 christos (void)printf("%s", ename);
844 1.1 christos ename = mime_next_encoding_name(&cookie);
845 1.1 christos if (ename == NULL)
846 1.1 christos break;
847 1.1 christos (void)fputc(',', stdout);
848 1.1 christos }
849 1.7 christos (void)putchar('\n');
850 1.1 christos ename = *str;
851 1.1 christos }
852 1.1 christos else {
853 1.1 christos if (strcmp(ename, *str) != 0)
854 1.1 christos *str = savestr(ename);
855 1.1 christos break;
856 1.1 christos }
857 1.1 christos }
858 1.1 christos }
859 1.1 christos
860 1.7 christos /*
861 1.7 christos * Edit an attachment list.
862 1.7 christos * Return the new attachment list.
863 1.7 christos */
864 1.1 christos static struct attachment *
865 1.7 christos edit_attachlist(struct attachment *alist)
866 1.1 christos {
867 1.1 christos struct attachment *ap;
868 1.1 christos char *line;
869 1.2 christos int attach_num;
870 1.1 christos
871 1.1 christos (void)printf("Attachments:\n");
872 1.1 christos
873 1.2 christos attach_num = 1;
874 1.7 christos ap = alist;
875 1.1 christos while (ap) {
876 1.7 christos SHOW_ALIST(alist, ap);
877 1.7 christos
878 1.7 christos switch(ap->a_type) {
879 1.7 christos case ATTACH_MSG:
880 1.7 christos (void)printf("#%-7d message: <not changeable>\n",
881 1.7 christos attach_num);
882 1.7 christos break;
883 1.7 christos case ATTACH_FNAME:
884 1.7 christos case ATTACH_FILENO:
885 1.7 christos line = get_line(&elm.filec, "filename", ap->a_name, attach_num);
886 1.7 christos if (*line == '\0') { /* omit this attachment */
887 1.7 christos if (ap->a_blink) {
888 1.7 christos struct attachment *next_ap;
889 1.7 christos next_ap = ap->a_flink;
890 1.7 christos ap = ap->a_blink;
891 1.7 christos ap->a_flink = next_ap;
892 1.7 christos if (next_ap)
893 1.7 christos next_ap->a_blink = ap;
894 1.7 christos else
895 1.7 christos goto done;
896 1.7 christos }
897 1.7 christos else {
898 1.7 christos alist = ap->a_flink;
899 1.7 christos if (alist)
900 1.7 christos alist->a_blink = NULL;
901 1.7 christos }
902 1.7 christos }
903 1.7 christos else {
904 1.7 christos char canon_name[MAXPATHLEN];
905 1.7 christos if (strcmp(line, ap->a_name) != 0) { /* new filename */
906 1.7 christos if (check_filename(line, canon_name) == NULL)
907 1.7 christos continue;
908 1.7 christos ap->a_name = savestr(canon_name);
909 1.7 christos ap->a_Content = get_mime_content(ap, 0);
910 1.7 christos }
911 1.7 christos sget_line(&elm.string, "description",
912 1.7 christos &ap->a_Content.C_description, attach_num);
913 1.7 christos sget_encoding(&ap->a_Content.C_encoding, ap->a_name,
914 1.7 christos ap->a_Content.C_type, attach_num);
915 1.1 christos }
916 1.7 christos break;
917 1.7 christos case ATTACH_INVALID:
918 1.7 christos default:
919 1.7 christos /* This is a coding error! */
920 1.7 christos assert(/* CONSTCOND */ 0);
921 1.7 christos errx(EXIT_FAILURE, "invalid attachment type: %d",
922 1.7 christos ap->a_type);
923 1.1 christos }
924 1.7 christos
925 1.2 christos attach_num++;
926 1.7 christos if (alist == NULL || ap->a_flink == NULL)
927 1.1 christos break;
928 1.1 christos
929 1.1 christos ap = ap->a_flink;
930 1.1 christos }
931 1.1 christos
932 1.7 christos ap = alist;
933 1.7 christos for (;;) {
934 1.1 christos struct attachment *nap;
935 1.1 christos
936 1.7 christos SHOW_ALIST(alist, ap);
937 1.7 christos
938 1.2 christos line = get_line(&elm.filec, "filename", "", attach_num);
939 1.1 christos if (*line == '\0')
940 1.1 christos break;
941 1.1 christos
942 1.2 christos nap = attach_one_file(ap, line, attach_num);
943 1.1 christos if (nap == NULL)
944 1.1 christos continue;
945 1.1 christos
946 1.7 christos if (alist == NULL)
947 1.7 christos alist = nap;
948 1.7 christos ap = nap;
949 1.1 christos
950 1.2 christos sget_line(&elm.string, "description",
951 1.2 christos &ap->a_Content.C_description, attach_num);
952 1.2 christos sget_encoding(&ap->a_Content.C_encoding, ap->a_name,
953 1.2 christos ap->a_Content.C_type, attach_num);
954 1.2 christos attach_num++;
955 1.7 christos }
956 1.7 christos done:
957 1.7 christos SHOW_ALIST(alist, ap);
958 1.1 christos
959 1.7 christos return alist;
960 1.1 christos }
961 1.1 christos
962 1.1 christos /*
963 1.2 christos * Hook used by the '~@' escape to attach files.
964 1.1 christos */
965 1.1 christos PUBLIC struct attachment*
966 1.12 christos mime_attach_files(struct attachment * volatile attach, char *linebuf)
967 1.1 christos {
968 1.1 christos struct attachment *ap;
969 1.1 christos char *argv[MAXARGC];
970 1.1 christos int argc;
971 1.1 christos int attach_num;
972 1.1 christos
973 1.12 christos argc = getrawlist(linebuf, argv, (int)__arraycount(argv));
974 1.2 christos attach_num = 1;
975 1.1 christos for (ap = attach; ap && ap->a_flink; ap = ap->a_flink)
976 1.1 christos attach_num++;
977 1.1 christos
978 1.1 christos if (argc) {
979 1.1 christos int i;
980 1.1 christos for (i = 0; i < argc; i++) {
981 1.2 christos struct attachment *ap2;
982 1.2 christos ap2 = attach_one_file(ap, argv[i], attach_num);
983 1.2 christos if (ap2 != NULL) {
984 1.2 christos ap = ap2;
985 1.2 christos if (attach == NULL)
986 1.2 christos attach = ap;
987 1.2 christos attach_num++;
988 1.2 christos }
989 1.1 christos }
990 1.1 christos }
991 1.1 christos else {
992 1.7 christos attach = edit_attachlist(attach);
993 1.1 christos (void)printf("--- end attachments ---\n");
994 1.1 christos }
995 1.1 christos
996 1.1 christos return attach;
997 1.1 christos }
998 1.1 christos
999 1.1 christos /*
1000 1.2 christos * Hook called in main() to attach files registered by the '-a' flag.
1001 1.2 christos */
1002 1.2 christos PUBLIC struct attachment *
1003 1.2 christos mime_attach_optargs(struct name *optargs)
1004 1.2 christos {
1005 1.2 christos struct attachment *attach;
1006 1.2 christos struct attachment *ap;
1007 1.2 christos struct name *np;
1008 1.2 christos char *expand_optargs;
1009 1.2 christos int attach_num;
1010 1.2 christos
1011 1.2 christos expand_optargs = value(ENAME_MIME_ATTACH_LIST);
1012 1.2 christos attach_num = 1;
1013 1.2 christos ap = NULL;
1014 1.2 christos attach = NULL;
1015 1.2 christos for (np = optargs; np; np = np->n_flink) {
1016 1.2 christos char *argv[MAXARGC];
1017 1.2 christos int argc;
1018 1.2 christos int i;
1019 1.2 christos
1020 1.2 christos if (expand_optargs != NULL)
1021 1.12 christos argc = getrawlist(np->n_name,
1022 1.12 christos argv, (int)__arraycount(argv));
1023 1.2 christos else {
1024 1.2 christos if (np->n_name == '\0')
1025 1.2 christos argc = 0;
1026 1.2 christos else {
1027 1.2 christos argc = 1;
1028 1.2 christos argv[0] = np->n_name;
1029 1.2 christos }
1030 1.2 christos argv[argc] = NULL;/* be consistent with getrawlist() */
1031 1.2 christos }
1032 1.2 christos for (i = 0; i < argc; i++) {
1033 1.2 christos struct attachment *ap2;
1034 1.2 christos char *filename;
1035 1.5 christos
1036 1.2 christos if (argv[i][0] == '/') /* an absolute path */
1037 1.2 christos (void)easprintf(&filename, "%s", argv[i]);
1038 1.2 christos else
1039 1.2 christos (void)easprintf(&filename, "%s/%s",
1040 1.2 christos origdir, argv[i]);
1041 1.2 christos
1042 1.2 christos ap2 = attach_one_file(ap, filename, attach_num);
1043 1.2 christos if (ap2 != NULL) {
1044 1.2 christos ap = ap2;
1045 1.2 christos if (attach == NULL)
1046 1.2 christos attach = ap;
1047 1.2 christos attach_num++;
1048 1.2 christos }
1049 1.7 christos free(filename);
1050 1.2 christos }
1051 1.2 christos }
1052 1.2 christos return attach;
1053 1.2 christos }
1054 1.2 christos
1055 1.2 christos /*
1056 1.1 christos * Output MIME header strings as specified in the header structure.
1057 1.1 christos */
1058 1.1 christos PUBLIC void
1059 1.1 christos mime_putheader(FILE *fp, struct header *header)
1060 1.1 christos {
1061 1.1 christos (void)fprintf(fp, MIME_HDR_VERSION ": " MIME_VERSION "\n");
1062 1.1 christos if (header->h_attach) {
1063 1.1 christos (void)fprintf(fp, MIME_HDR_TYPE ": multipart/mixed;\n");
1064 1.1 christos (void)fprintf(fp, "\tboundary=\"%s\"\n", header->h_mime_boundary);
1065 1.1 christos }
1066 1.1 christos else {
1067 1.1 christos fput_mime_content(fp, &header->h_Content);
1068 1.1 christos }
1069 1.1 christos }
1070 1.1 christos
1071 1.1 christos #endif /* MIME_SUPPORT */
1072