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