6a64b26b1f8f6e8a17ff645029f0740130726a45
[exim.git] / src / src / mime.c
1 /*************************************************
2 * Exim - an Internet mail transport agent *
3 *************************************************/
4
5 /* Copyright (c) Tom Kistner <tom@duncanthrax.net> 2004, 2015 */
6 /* License: GPL */
7
8 #include "exim.h"
9 #ifdef WITH_CONTENT_SCAN /* entire file */
10 #include "mime.h"
11 #include <sys/stat.h>
12
13 FILE *mime_stream = NULL;
14 uschar *mime_current_boundary = NULL;
15
16 static mime_header mime_header_list[] = {
17 { US"content-type:", 13, &mime_content_type },
18 { US"content-disposition:", 20, &mime_content_disposition },
19 { US"content-transfer-encoding:", 26, &mime_content_transfer_encoding },
20 { US"content-id:", 11, &mime_content_id },
21 { US"content-description:", 20, &mime_content_description }
22 };
23
24 static int mime_header_list_size = nelem(mime_header_list);
25
26 static mime_parameter mime_parameter_list[] = {
27 { US"name=", 5, &mime_filename },
28 { US"filename=", 9, &mime_filename },
29 { US"charset=", 8, &mime_charset },
30 { US"boundary=", 9, &mime_boundary }
31 };
32
33
34 /*************************************************
35 * set MIME anomaly level + text *
36 *************************************************/
37
38 /* Small wrapper to set the two expandables which
39 give info on detected "problems" in MIME
40 encodings. Indexes are defined in mime.h. */
41
42 void
43 mime_set_anomaly(int idx)
44 {
45 struct anom {
46 int level;
47 const uschar * text;
48 } anom[] = { {1, CUS"Broken Quoted-Printable encoding detected"},
49 {2, CUS"Broken BASE64 encoding detected"} };
50
51 mime_anomaly_level = anom[idx].level;
52 mime_anomaly_text = anom[idx].text;
53 }
54
55
56 /*************************************************
57 * decode quoted-printable chars *
58 *************************************************/
59
60 /* gets called when we hit a =
61 returns: new pointer position
62 result code in c:
63 -2 - decode error
64 -1 - soft line break, no char
65 0-255 - char to write
66 */
67
68 static uschar *
69 mime_decode_qp_char(uschar *qp_p, int *c)
70 {
71 uschar *initial_pos = qp_p;
72
73 /* advance one char */
74 qp_p++;
75
76 /* Check for two hex digits and decode them */
77 if (isxdigit(*qp_p) && isxdigit(qp_p[1]))
78 {
79 /* Do hex conversion */
80 *c = (isdigit(*qp_p) ? *qp_p - '0' : toupper(*qp_p) - 'A' + 10) <<4;
81 qp_p++;
82 *c |= isdigit(*qp_p) ? *qp_p - '0' : toupper(*qp_p) - 'A' + 10;
83 return qp_p + 1;
84 }
85
86 /* tab or whitespace may follow just ignore it if it precedes \n */
87 while (*qp_p == '\t' || *qp_p == ' ' || *qp_p == '\r')
88 qp_p++;
89
90 if (*qp_p == '\n') /* hit soft line break */
91 {
92 *c = -1;
93 return qp_p;
94 }
95
96 /* illegal char here */
97 *c = -2;
98 return initial_pos;
99 }
100
101
102 /* just dump MIME part without any decoding */
103 static ssize_t
104 mime_decode_asis(FILE* in, FILE* out, uschar* boundary)
105 {
106 ssize_t len, size = 0;
107 uschar buffer[MIME_MAX_LINE_LENGTH];
108
109 while(fgets(CS buffer, MIME_MAX_LINE_LENGTH, mime_stream) != NULL)
110 {
111 if (boundary != NULL
112 && Ustrncmp(buffer, "--", 2) == 0
113 && Ustrncmp((buffer+2), boundary, Ustrlen(boundary)) == 0
114 )
115 break;
116
117 len = Ustrlen(buffer);
118 if (fwrite(buffer, 1, (size_t)len, out) < len)
119 return -1;
120 size += len;
121 } /* while */
122 return size;
123 }
124
125
126
127 /* decode quoted-printable MIME part */
128 static ssize_t
129 mime_decode_qp(FILE* in, FILE* out, uschar* boundary)
130 {
131 uschar ibuf[MIME_MAX_LINE_LENGTH], obuf[MIME_MAX_LINE_LENGTH];
132 uschar *ipos, *opos;
133 ssize_t len, size = 0;
134
135 while (fgets(CS ibuf, MIME_MAX_LINE_LENGTH, in) != NULL)
136 {
137 if (boundary != NULL
138 && Ustrncmp(ibuf, "--", 2) == 0
139 && Ustrncmp((ibuf+2), boundary, Ustrlen(boundary)) == 0
140 )
141 break; /* todo: check for missing boundary */
142
143 ipos = ibuf;
144 opos = obuf;
145
146 while (*ipos != 0)
147 {
148 if (*ipos == '=')
149 {
150 int decode_qp_result;
151
152 ipos = mime_decode_qp_char(ipos, &decode_qp_result);
153
154 if (decode_qp_result == -2)
155 {
156 /* Error from decoder. ipos is unchanged. */
157 mime_set_anomaly(MIME_ANOMALY_BROKEN_QP);
158 *opos = '=';
159 ++opos;
160 ++ipos;
161 }
162 else if (decode_qp_result == -1)
163 break;
164 else if (decode_qp_result >= 0)
165 {
166 *opos = decode_qp_result;
167 ++opos;
168 }
169 }
170 else
171 {
172 *opos = *ipos;
173 ++opos;
174 ++ipos;
175 }
176 }
177 /* something to write? */
178 len = opos - obuf;
179 if (len > 0)
180 {
181 if (fwrite(obuf, 1, len, out) != len) return -1; /* error */
182 size += len;
183 }
184 }
185 return size;
186 }
187
188
189 static FILE *
190 mime_get_decode_file(uschar *pname, uschar *fname)
191 {
192 FILE *f = NULL;
193 uschar *filename;
194
195 filename = (uschar *)malloc(2048);
196
197 if (pname && fname)
198 {
199 (void)string_format(filename, 2048, "%s/%s", pname, fname);
200 f = modefopen(filename,"wb+",SPOOL_MODE);
201 }
202 else if (!pname)
203 f = modefopen(fname,"wb+",SPOOL_MODE);
204 else if (!fname)
205 {
206 int file_nr = 0;
207 int result = 0;
208
209 /* must find first free sequential filename */
210 do
211 {
212 struct stat mystat;
213 (void)string_format(filename, 2048,
214 "%s/%s-%05u", pname, message_id, file_nr++);
215 /* security break */
216 if (file_nr >= 1024)
217 break;
218 result = stat(CS filename, &mystat);
219 } while(result != -1);
220
221 f = modefopen(filename, "wb+", SPOOL_MODE);
222 }
223
224 /* set expansion variable */
225 mime_decoded_filename = filename;
226
227 return f;
228 }
229
230
231 int
232 mime_decode(const uschar **listptr)
233 {
234 int sep = 0;
235 const uschar *list = *listptr;
236 uschar *option;
237 uschar option_buffer[1024];
238 uschar decode_path[1024];
239 FILE *decode_file = NULL;
240 long f_pos = 0;
241 ssize_t size_counter = 0;
242 ssize_t (*decode_function)(FILE*, FILE*, uschar*);
243
244 if (mime_stream == NULL)
245 return FAIL;
246
247 f_pos = ftell(mime_stream);
248
249 /* build default decode path (will exist since MBOX must be spooled up) */
250 (void)string_format(decode_path,1024,"%s/scan/%s",spool_directory,message_id);
251
252 /* try to find 1st option */
253 if ((option = string_nextinlist(&list, &sep,
254 option_buffer,
255 sizeof(option_buffer))) != NULL)
256 {
257 /* parse 1st option */
258 if ( (Ustrcmp(option,"false") == 0) || (Ustrcmp(option,"0") == 0) )
259 /* explicitly no decoding */
260 return FAIL;
261
262 if (Ustrcmp(option,"default") == 0)
263 /* explicit default path + file names */
264 goto DEFAULT_PATH;
265
266 if (option[0] == '/')
267 {
268 struct stat statbuf;
269
270 memset(&statbuf,0,sizeof(statbuf));
271
272 /* assume either path or path+file name */
273 if ( (stat(CS option, &statbuf) == 0) && S_ISDIR(statbuf.st_mode) )
274 /* is directory, use it as decode_path */
275 decode_file = mime_get_decode_file(option, NULL);
276 else
277 /* does not exist or is a file, use as full file name */
278 decode_file = mime_get_decode_file(NULL, option);
279 }
280 else
281 /* assume file name only, use default path */
282 decode_file = mime_get_decode_file(decode_path, option);
283 }
284 else
285 {
286 /* no option? patch default path */
287 DEFAULT_PATH:
288 decode_file = mime_get_decode_file(decode_path, NULL);
289 }
290
291 if (!decode_file)
292 return DEFER;
293
294 /* decode according to mime type */
295 decode_function =
296 !mime_content_transfer_encoding
297 ? mime_decode_asis /* no encoding, dump as-is */
298 : Ustrcmp(mime_content_transfer_encoding, "base64") == 0
299 ? mime_decode_base64
300 : Ustrcmp(mime_content_transfer_encoding, "quoted-printable") == 0
301 ? mime_decode_qp
302 : mime_decode_asis; /* unknown encoding type, just dump as-is */
303
304 size_counter = decode_function(mime_stream, decode_file, mime_current_boundary);
305
306 clearerr(mime_stream);
307 fseek(mime_stream, f_pos, SEEK_SET);
308
309 if (fclose(decode_file) != 0 || size_counter < 0)
310 return DEFER;
311
312 /* round up to the next KiB */
313 mime_content_size = (size_counter + 1023) / 1024;
314
315 return OK;
316 }
317
318
319 static int
320 mime_get_header(FILE *f, uschar *header)
321 {
322 int c = EOF;
323 int done = 0;
324 int header_value_mode = 0;
325 int header_open_brackets = 0;
326 int num_copied = 0;
327
328 while(!done)
329 {
330 if ((c = fgetc(f)) == EOF) break;
331
332 /* always skip CRs */
333 if (c == '\r') continue;
334
335 if (c == '\n')
336 {
337 if (num_copied > 0)
338 {
339 /* look if next char is '\t' or ' ' */
340 if ((c = fgetc(f)) == EOF) break;
341 if ( (c == '\t') || (c == ' ') ) continue;
342 (void)ungetc(c,f);
343 }
344 /* end of the header, terminate with ';' */
345 c = ';';
346 done = 1;
347 }
348
349 /* skip control characters */
350 if (c < 32) continue;
351
352 if (header_value_mode)
353 {
354 /* --------- value mode ----------- */
355 /* skip leading whitespace */
356 if ( ((c == '\t') || (c == ' ')) && (header_value_mode == 1) )
357 continue;
358
359 /* we have hit a non-whitespace char, start copying value data */
360 header_value_mode = 2;
361
362 if (c == '"') /* flip "quoted" mode */
363 header_value_mode = header_value_mode==2 ? 3 : 2;
364
365 /* leave value mode on unquoted ';' */
366 if (header_value_mode == 2 && c == ';') {
367 header_value_mode = 0;
368 };
369 /* -------------------------------- */
370 }
371 else
372 {
373 /* -------- non-value mode -------- */
374 /* skip whitespace + tabs */
375 if ( (c == ' ') || (c == '\t') )
376 continue;
377 if (c == '\\')
378 {
379 /* quote next char. can be used
380 to escape brackets. */
381 if ((c = fgetc(f)) == EOF) break;
382 }
383 else if (c == '(')
384 {
385 header_open_brackets++;
386 continue;
387 }
388 else if ((c == ')') && header_open_brackets)
389 {
390 header_open_brackets--;
391 continue;
392 }
393 else if ( (c == '=') && !header_open_brackets ) /* enter value mode */
394 header_value_mode = 1;
395
396 /* skip chars while we are in a comment */
397 if (header_open_brackets > 0)
398 continue;
399 /* -------------------------------- */
400 }
401
402 /* copy the char to the buffer */
403 header[num_copied++] = (uschar)c;
404
405 /* break if header buffer is full */
406 if (num_copied > MIME_MAX_HEADER_SIZE-1)
407 done = 1;
408 }
409
410 if ((num_copied > 0) && (header[num_copied-1] != ';'))
411 header[num_copied-1] = ';';
412
413 /* 0-terminate */
414 header[num_copied] = '\0';
415
416 /* return 0 for EOF or empty line */
417 if ((c == EOF) || (num_copied == 1))
418 return 0;
419 else
420 return 1;
421 }
422
423
424 static void
425 mime_vars_reset(void)
426 {
427 mime_anomaly_level = 0;
428 mime_anomaly_text = NULL;
429 mime_boundary = NULL;
430 mime_charset = NULL;
431 mime_decoded_filename = NULL;
432 mime_filename = NULL;
433 mime_content_description = NULL;
434 mime_content_disposition = NULL;
435 mime_content_id = NULL;
436 mime_content_transfer_encoding = NULL;
437 mime_content_type = NULL;
438 mime_is_multipart = 0;
439 mime_content_size = 0;
440 }
441
442
443 /* Grab a parameter value, dealing with quoting.
444
445 Arguments:
446 str Input string. Updated on return to point to terminating ; or NUL
447
448 Return:
449 Allocated string with parameter value
450 */
451 static uschar *
452 mime_param_val(uschar ** sp)
453 {
454 uschar * s = *sp;
455 uschar * val = NULL;
456 int size = 0, ptr = 0;
457
458 /* debug_printf(" considering paramval '%s'\n", s); */
459
460 while (*s && *s != ';') /* ; terminates */
461 if (*s == '"')
462 {
463 s++; /* skip opening " */
464 while (*s && *s != '"') /* " protects ; */
465 val = string_cat(val, &size, &ptr, s++, 1);
466 if (*s) s++; /* skip closing " */
467 }
468 else
469 val = string_cat(val, &size, &ptr, s++, 1);
470 if (val) val[ptr] = '\0';
471 *sp = s;
472 return val;
473 }
474
475 static uschar *
476 mime_next_semicolon(uschar * s)
477 {
478 while (*s && *s != ';') /* ; terminates */
479 if (*s == '"')
480 {
481 s++; /* skip opening " */
482 while (*s && *s != '"') /* " protects ; */
483 s++;
484 if (*s) s++; /* skip closing " */
485 }
486 else
487 s++;
488 return s;
489 }
490
491
492 static uschar *
493 rfc2231_to_2047(const uschar * fname, const uschar * charset, int * len)
494 {
495 int size = 0, ptr = 0;
496 uschar * val = string_cat(NULL, &size, &ptr, US"=?", 2);
497 uschar c;
498
499 if (charset)
500 val = string_cat(val, &size, &ptr, charset, Ustrlen(charset));
501 val = string_cat(val, &size, &ptr, US"?Q?", 3);
502
503 while ((c = *fname))
504 if (c == '%' && isxdigit(fname[1]) && isxdigit(fname[2]))
505 {
506 val = string_cat(val, &size, &ptr, US"=", 1);
507 val = string_cat(val, &size, &ptr, ++fname, 2);
508 fname += 2;
509 }
510 else
511 val = string_cat(val, &size, &ptr, fname++, 1);
512
513 val = string_cat(val, &size, &ptr, US"?=", 2);
514 val[*len = ptr] = '\0';
515 return val;
516 }
517
518
519 int
520 mime_acl_check(uschar *acl, FILE *f, struct mime_boundary_context *context,
521 uschar **user_msgptr, uschar **log_msgptr)
522 {
523 int rc = OK;
524 uschar * header = NULL;
525 struct mime_boundary_context nested_context;
526
527 /* reserve a line buffer to work in */
528 header = store_get(MIME_MAX_HEADER_SIZE+1);
529
530 /* Not actually used at the moment, but will be vital to fixing
531 * some RFC 2046 nonconformance later... */
532 nested_context.parent = context;
533
534 /* loop through parts */
535 while(1)
536 {
537 /* reset all per-part mime variables */
538 mime_vars_reset();
539
540 /* If boundary is null, we assume that *f is positioned on the start of
541 headers (for example, at the very beginning of a message. If a boundary is
542 given, we must first advance to it to reach the start of the next header
543 block. */
544
545 /* NOTE -- there's an error here -- RFC2046 specifically says to
546 * check for outer boundaries. This code doesn't do that, and
547 * I haven't fixed this.
548 *
549 * (I have moved partway towards adding support, however, by adding
550 * a "parent" field to my new boundary-context structure.)
551 */
552 if (context) for (;;)
553 {
554 if (!fgets(CS header, MIME_MAX_HEADER_SIZE, f))
555 {
556 /* Hit EOF or read error. Ugh. */
557 DEBUG(D_acl) debug_printf("MIME: Hit EOF ...\n");
558 return rc;
559 }
560
561 /* boundary line must start with 2 dashes */
562 if ( Ustrncmp(header, "--", 2) == 0
563 && Ustrncmp(header+2, context->boundary, Ustrlen(context->boundary)) == 0
564 )
565 { /* found boundary */
566 if (Ustrncmp((header+2+Ustrlen(context->boundary)), "--", 2) == 0)
567 {
568 /* END boundary found */
569 DEBUG(D_acl) debug_printf("MIME: End boundary found %s\n",
570 context->boundary);
571 return rc;
572 }
573
574 DEBUG(D_acl) debug_printf("MIME: Next part with boundary %s\n",
575 context->boundary);
576 break;
577 }
578 }
579
580 /* parse headers, set up expansion variables */
581 while (mime_get_header(f, header))
582 {
583 struct mime_header * mh;
584
585 /* look for interesting headers */
586 for (mh = mime_header_list;
587 mh < mime_header_list + mime_header_list_size;
588 mh++) if (strncmpic(mh->name, header, mh->namelen) == 0)
589 {
590 uschar * p = header + mh->namelen;
591 uschar * q;
592
593 /* grab the value (normalize to lower case)
594 and copy to its corresponding expansion variable */
595
596 for (q = p; *q != ';' && *q; q++) ;
597 *mh->value = string_copynlc(p, q-p);
598 DEBUG(D_acl) debug_printf("MIME: found %s header, value is '%s'\n",
599 mh->name, *mh->value);
600
601 if (*(p = q)) p++; /* jump past the ; */
602
603 {
604 uschar * mime_fname = NULL;
605 uschar * mime_fname_rfc2231 = NULL;
606 uschar * mime_filename_charset = NULL;
607 BOOL decoding_failed = FALSE;
608
609 /* grab all param=value tags on the remaining line,
610 check if they are interesting */
611
612 while (*p)
613 {
614 mime_parameter * mp;
615
616 DEBUG(D_acl) debug_printf("MIME: considering paramlist '%s'\n", p);
617
618 if ( !mime_filename
619 && strncmpic(CUS"content-disposition:", header, 20) == 0
620 && strncmpic(CUS"filename*", p, 9) == 0
621 )
622 { /* RFC 2231 filename */
623 uschar * q;
624
625 /* find value of the filename */
626 p += 9;
627 while(*p != '=' && *p) p++;
628 if (*p) p++; /* p is filename or NUL */
629 q = mime_param_val(&p); /* p now trailing ; or NUL */
630
631 if (q && *q)
632 {
633 uschar * temp_string, * err_msg;
634 int slen;
635
636 /* build up an un-decoded filename over successive
637 filename*= parameters (for use when 2047 decode fails) */
638
639 mime_fname_rfc2231 = string_sprintf("%#s%s",
640 mime_fname_rfc2231, q);
641
642 if (!decoding_failed)
643 {
644 int size;
645 if (!mime_filename_charset)
646 {
647 uschar * s = q;
648
649 /* look for a ' in the "filename" */
650 while(*s != '\'' && *s) s++; /* s is 1st ' or NUL */
651
652 if ((size = s-q) > 0)
653 mime_filename_charset = string_copyn(q, size);
654
655 if (*(p = s)) p++;
656 while(*p == '\'') p++; /* p is after 2nd ' */
657 }
658 else
659 p = q;
660
661 DEBUG(D_acl) debug_printf("MIME: charset %s fname '%s'\n",
662 mime_filename_charset ? mime_filename_charset : US"<NULL>", p);
663
664 temp_string = rfc2231_to_2047(p, mime_filename_charset, &slen);
665 DEBUG(D_acl) debug_printf("MIME: 2047-name %s\n", temp_string);
666
667 temp_string = rfc2047_decode(temp_string, FALSE, NULL, ' ',
668 NULL, &err_msg);
669 DEBUG(D_acl) debug_printf("MIME: plain-name %s\n", temp_string);
670
671 size = Ustrlen(temp_string);
672
673 if (size == slen)
674 decoding_failed = TRUE;
675 else
676 /* build up a decoded filename over successive
677 filename*= parameters */
678
679 mime_filename = mime_fname = mime_fname
680 ? string_sprintf("%s%s", mime_fname, temp_string)
681 : temp_string;
682 }
683 }
684 }
685
686 else
687 /* look for interesting parameters */
688 for (mp = mime_parameter_list;
689 mp < mime_parameter_list + nelem(mime_parameter_list);
690 mp++
691 ) if (strncmpic(mp->name, p, mp->namelen) == 0)
692 {
693 uschar * q;
694 uschar * dummy_errstr;
695
696 /* grab the value and copy to its expansion variable */
697 p += mp->namelen;
698 q = mime_param_val(&p); /* p now trailing ; or NUL */
699
700 *mp->value = q && *q
701 ? rfc2047_decode(q, check_rfc2047_length, NULL, 32, NULL,
702 &dummy_errstr)
703 : NULL;
704 DEBUG(D_acl) debug_printf(
705 "MIME: found %s parameter in %s header, value '%s'\n",
706 mp->name, mh->name, *mp->value);
707
708 break; /* done matching param names */
709 }
710
711
712 /* There is something, but not one of our interesting parameters.
713 Advance past the next semicolon */
714 p = mime_next_semicolon(p);
715 if (*p) p++;
716 } /* param scan on line */
717
718 if (strncmpic(CUS"content-disposition:", header, 20) == 0)
719 {
720 if (decoding_failed) mime_filename = mime_fname_rfc2231;
721
722 DEBUG(D_acl) debug_printf(
723 "MIME: found %s parameter in %s header, value is '%s'\n",
724 "filename", mh->name, mime_filename);
725 }
726 }
727 }
728 }
729
730 /* set additional flag variables (easier access) */
731 if ( mime_content_type
732 && Ustrncmp(mime_content_type,"multipart",9) == 0
733 )
734 mime_is_multipart = 1;
735
736 /* Make a copy of the boundary pointer.
737 Required since mime_boundary is global
738 and can be overwritten further down in recursion */
739 nested_context.boundary = mime_boundary;
740
741 /* raise global counter */
742 mime_part_count++;
743
744 /* copy current file handle to global variable */
745 mime_stream = f;
746 mime_current_boundary = context ? context->boundary : 0;
747
748 /* Note the context */
749 mime_is_coverletter = !(context && context->context == MBC_ATTACHMENT);
750
751 /* call ACL handling function */
752 rc = acl_check(ACL_WHERE_MIME, NULL, acl, user_msgptr, log_msgptr);
753
754 mime_stream = NULL;
755 mime_current_boundary = NULL;
756
757 if (rc != OK) break;
758
759 /* If we have a multipart entity and a boundary, go recursive */
760 if ( (mime_content_type != NULL) &&
761 (nested_context.boundary != NULL) &&
762 (Ustrncmp(mime_content_type,"multipart",9) == 0) )
763 {
764 DEBUG(D_acl)
765 debug_printf("MIME: Entering multipart recursion, boundary '%s'\n",
766 nested_context.boundary);
767
768 nested_context.context =
769 context && context->context == MBC_ATTACHMENT
770 ? MBC_ATTACHMENT
771 : Ustrcmp(mime_content_type,"multipart/alternative") == 0
772 || Ustrcmp(mime_content_type,"multipart/related") == 0
773 ? MBC_COVERLETTER_ALL
774 : MBC_COVERLETTER_ONESHOT;
775
776 rc = mime_acl_check(acl, f, &nested_context, user_msgptr, log_msgptr);
777 if (rc != OK) break;
778 }
779 else if ( (mime_content_type != NULL) &&
780 (Ustrncmp(mime_content_type,"message/rfc822",14) == 0) )
781 {
782 const uschar *rfc822name = NULL;
783 uschar filename[2048];
784 int file_nr = 0;
785 int result = 0;
786
787 /* must find first free sequential filename */
788 do
789 {
790 struct stat mystat;
791 (void)string_format(filename, 2048,
792 "%s/scan/%s/__rfc822_%05u", spool_directory, message_id, file_nr++);
793 /* security break */
794 if (file_nr >= 128)
795 goto NO_RFC822;
796 result = stat(CS filename,&mystat);
797 } while (result != -1);
798
799 rfc822name = filename;
800
801 /* decode RFC822 attachment */
802 mime_decoded_filename = NULL;
803 mime_stream = f;
804 mime_current_boundary = context ? context->boundary : NULL;
805 mime_decode(&rfc822name);
806 mime_stream = NULL;
807 mime_current_boundary = NULL;
808 if (!mime_decoded_filename) /* decoding failed */
809 {
810 log_write(0, LOG_MAIN,
811 "mime_regex acl condition warning - could not decode RFC822 MIME part to file.");
812 rc = DEFER;
813 goto out;
814 }
815 mime_decoded_filename = NULL;
816 }
817
818 NO_RFC822:
819 /* If the boundary of this instance is NULL, we are finished here */
820 if (!context) break;
821
822 if (context->context == MBC_COVERLETTER_ONESHOT)
823 context->context = MBC_ATTACHMENT;
824 }
825
826 out:
827 mime_vars_reset();
828 return rc;
829 }
830
831 #endif /*WITH_CONTENT_SCAN*/
832
833 /* vi: sw ai sw=2
834 */