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