(1) Last-minute sieve patch (updates to latest spec).
[exim.git] / src / src / demime.c
index 17adf74f4ace3c8619c7eabbdb107fb90e1b0fc3..961a2e046cf5b315ebae19f0697f968f239bac08 100644 (file)
@@ -1,4 +1,4 @@
-/* $Cambridge: exim/src/src/demime.c,v 1.3 2004/12/29 16:24:03 ph10 Exp $ */
+/* $Cambridge: exim/src/src/demime.c,v 1.4 2005/02/17 11:58:26 ph10 Exp $ */
 
 /*************************************************
 *     Exim - an Internet mail transport agent    *
@@ -26,15 +26,15 @@ int demime(uschar **listptr) {
   FILE *mbox_file;
   uschar defer_error_buffer[1024];
   int demime_rc = 0;
-  
+
   /* reset found_extension variable */
   found_extension = NULL;
-  
+
   /* try to find 1st option */
   if ((option = string_nextinlist(&list, &sep,
                                   option_buffer,
                                   sizeof(option_buffer))) != NULL) {
-    
+
     /* parse 1st option */
     if ( (Ustrcmp(option,"false") == 0) || (Ustrcmp(option,"0") == 0) ) {
       /* explicitly no demimeing */
@@ -45,37 +45,37 @@ int demime(uschar **listptr) {
     /* no options -> no demimeing */
     return FAIL;
   };
-  
+
   /* make sure the eml mbox file is spooled up */
   mbox_file = spool_mbox(&mbox_size);
-  
+
   if (mbox_file == NULL) {
     /* error while spooling */
     log_write(0, LOG_MAIN|LOG_PANIC,
            "demime acl condition: error while creating mbox spool file");
-    return DEFER;  
+    return DEFER;
   };
-  
+
   /* call demimer if not already done earlier */
   if (!demime_ok)
     demime_rc = mime_demux(mbox_file, defer_error_buffer);
-  
+
   fclose(mbox_file);
-  
+
   if (demime_rc == DEFER) {
     /* temporary failure (DEFER => DEFER) */
     log_write(0, LOG_MAIN,
         "demime acl condition: %s", defer_error_buffer);
     return DEFER;
   };
-  
+
   /* set demime_ok to avoid unpacking again */
   demime_ok = 1;
-  
+
   /* check for file extensions, if there */
   while (option != NULL) {
     struct file_extension *this_extension = file_extensions;
-    
+
     /* Look for the wildcard. If it is found, we always return true.
     The user must then use a custom condition to evaluate demime_errorlevel */
     if (Ustrcmp(option,"*") == 0) {
@@ -84,7 +84,7 @@ int demime(uschar **listptr) {
     };
 
     /* loop thru extension list */
-    while (this_extension != NULL) {   
+    while (this_extension != NULL) {
       if (strcmpic(option, this_extension->file_extension_string) == 0) {
         /* found one */
         found_extension = this_extension->file_extension_string;
@@ -92,13 +92,13 @@ int demime(uschar **listptr) {
       };
       this_extension = this_extension->next;
     };
-    
+
     /* grab next extension from option list */
     option = string_nextinlist(&list, &sep,
                                option_buffer,
                                sizeof(option_buffer));
   };
-  
+
   /* nothing found */
   return FAIL;
 }
@@ -113,14 +113,14 @@ int demime(uschar **listptr) {
 
 unsigned int mime_hstr_i(uschar *cptr) {
   unsigned int i, j = 0;
-  
+
   while (cptr && *cptr && isxdigit(*cptr)) {
     i = *cptr++ - '0';
     if (9 < i) i -= 7;
     j <<= 4;
     j |= (i & 0x0f);
   }
-  
+
   return(j);
 }
 
@@ -141,10 +141,10 @@ uschar *mime_decode_qp(uschar *qp_p,int *c) {
   uschar hex[] = {0,0,0};
   int nan = 0;
   uschar *initial_pos = qp_p;
-  
+
   /* advance one char */
   qp_p++;
-  
+
   REPEAT_FIRST:
   if ( (*qp_p == '\t') || (*qp_p == ' ') || (*qp_p == '\r') )  {
     /* tab or whitespace may follow
@@ -167,7 +167,7 @@ uschar *mime_decode_qp(uschar *qp_p,int *c) {
       qp_p++;
     };
   }
-  else if (*qp_p == '\n') {    
+  else if (*qp_p == '\n') {
     /* hit soft line break already, continue */
     *c = -1;
     return qp_p;
@@ -177,7 +177,7 @@ uschar *mime_decode_qp(uschar *qp_p,int *c) {
     *c = -2;
     return initial_pos;
   };
-  
+
   if ( (('0' <= *qp_p) && (*qp_p <= '9')) || (('A' <= *qp_p) && (*qp_p <= 'F')) || (('a' <= *qp_p) && (*qp_p <= 'f')) ) {
     if (hex[0] > 0) {
       hex[1] = *qp_p;
@@ -189,15 +189,15 @@ uschar *mime_decode_qp(uschar *qp_p,int *c) {
     else {
       /* huh ? */
       *c = -2;
-      return initial_pos;  
+      return initial_pos;
     };
   }
   else {
     /* illegal char */
     *c = -2;
-    return initial_pos;  
+    return initial_pos;
   };
-  
+
 }
 
 
@@ -216,35 +216,35 @@ int mime_get_dump_file(uschar *extension, FILE **f, uschar *info) {
   unsigned int file_nr;
   uschar default_extension[] = ".com";
   uschar *p;
-  
+
   if (extension == NULL)
     extension = default_extension;
-  
+
   /* scan the proposed extension.
      if it is longer than 4 chars, or
      contains exotic chars, use the default extension */
-  
+
 /*  if (Ustrlen(extension) > 4) {
     extension = default_extension;
   };
-*/  
-  
+*/
+
   p = extension+1;
-  
+
   while (*p != 0) {
     *p = (uschar)tolower((uschar)*p);
     if ( (*p < 97) || (*p > 122) ) {
       extension = default_extension;
-      break;  
+      break;
     };
     p++;
   };
-  
+
   /* find a new file to write to */
   file_nr = 0;
   do {
     struct stat mystat;
-    
+
     snprintf(CS file_name,1024,"%s/scan/%s/%s-%05u%s",spool_directory,message_id,message_id,file_nr,extension);
     file_nr++;
     if (file_nr >= MIME_SANITY_MAX_DUMP_FILES) {
@@ -255,14 +255,14 @@ int mime_get_dump_file(uschar *extension, FILE **f, uschar *info) {
     result = stat(CS file_name,&mystat);
   }
   while(result != -1);
-  
+
   *f = fopen(CS file_name,"w+");
   if (*f == NULL) {
     /* cannot open new dump file, disk full ? -> soft error */
     snprintf(CS info, 1024,"unable to open dump file");
     return -2;
   };
+
   return file_nr;
 }
 
@@ -273,7 +273,7 @@ int mime_get_dump_file(uschar *extension, FILE **f, uschar *info) {
 
 /* Find a string in a mime header, and optionally fill in
    the value associated with it into *value
+
    returns: 0 - nothing found
             1 - found param
             2 - found param + value
@@ -281,7 +281,7 @@ int mime_get_dump_file(uschar *extension, FILE **f, uschar *info) {
 
 int mime_header_find(uschar *header, uschar *param, uschar **value) {
   uschar *needle;
-  
+
   needle = strstric(header,param,FALSE);
   if (needle != NULL) {
     if (value != NULL) {
@@ -289,7 +289,7 @@ int mime_header_find(uschar *header, uschar *param, uschar **value) {
       if (*needle == '=') {
         uschar *value_start;
         uschar *value_end;
-        
+
         value_start = needle + 1;
         value_end = strstric(value_start,US";",FALSE);
         if (value_end != NULL) {
@@ -297,7 +297,7 @@ int mime_header_find(uschar *header, uschar *param, uschar **value) {
           *value = (uschar *)malloc((value_end - value_start)+1);
           if (*value == NULL)
             return 0;
-          
+
           Ustrncpy(*value,value_start,(value_end - value_start));
           (*value)[(value_end - value_start)] = '\0';
           return 2;
@@ -326,20 +326,20 @@ int mime_read_line(FILE *f, int mime_demux_mode, uschar *buffer, long *num_copie
   int done = 0;
   int header_value_mode = 0;
   int header_open_brackets = 0;
-  
+
   *num_copied = 0;
-  
+
   while(!done) {
-    
+
     c = fgetc(f);
     if (c == EOF) break;
-   
+
     /* --------- header mode -------------- */
     if (mime_demux_mode == MIME_DEMUX_MODE_MIME_HEADERS) {
-      
+
       /* always skip CRs */
       if (c == '\r') continue;
-      
+
       if (c == '\n') {
         if ((*num_copied) > 0) {
           /* look if next char is '\t' or ' ' */
@@ -352,10 +352,10 @@ int mime_read_line(FILE *f, int mime_demux_mode, uschar *buffer, long *num_copie
         c = ';';
         done = 1;
       };
-    
+
       /* skip control characters */
       if (c < 32) continue;
-    
+
       /* skip whitespace + tabs */
       if ( (c == ' ') || (c == '\t') )
         continue;
@@ -364,7 +364,7 @@ int mime_read_line(FILE *f, int mime_demux_mode, uschar *buffer, long *num_copie
         /* --------- value mode ----------- */
         /* skip quotes */
         if (c == '"') continue;
-        
+
         /* leave value mode on ';' */
         if (c == ';') {
           header_value_mode = 0;
@@ -389,9 +389,9 @@ int mime_read_line(FILE *f, int mime_demux_mode, uschar *buffer, long *num_copie
         }
         else if ( (c == '=') && !header_open_brackets ) {
           /* enter value mode */
-          header_value_mode = 1;          
+          header_value_mode = 1;
         };
-        
+
         /* skip chars while we are in a comment */
         if (header_open_brackets > 0)
           continue;
@@ -406,21 +406,21 @@ int mime_read_line(FILE *f, int mime_demux_mode, uschar *buffer, long *num_copie
         done = 1;
     /* ------------------------------------ */
     };
-    
+
     /* copy the char to the buffer */
     buffer[*num_copied] = (uschar)c;
     /* raise counter */
     (*num_copied)++;
-    
+
     /* break if buffer is full */
     if (*num_copied > MIME_SANITY_MAX_LINE_LENGTH-1) {
       done = 1;
     };
   }
-  
+
   /* 0-terminate */
   buffer[*num_copied] = '\0';
-  
+
   if (*num_copied > MIME_SANITY_MAX_LINE_LENGTH-1)
     return MIME_READ_LINE_OVERFLOW;
   else
@@ -444,10 +444,10 @@ int mime_check_boundary(uschar *line, struct boundary *boundaries) {
   struct boundary *thisboundary = boundaries;
   uschar workbuf[MIME_SANITY_MAX_LINE_LENGTH+1];
   unsigned int i,j=0;
-  
+
   /* check for '--' first */
   if (Ustrncmp(line,"--",2) == 0) {
-    
+
     /* strip tab and space */
     for (i = 2; i < Ustrlen(line); i++) {
       if ((line[i] != ' ') && (line[i] != '\t')) {
@@ -462,14 +462,14 @@ int mime_check_boundary(uschar *line, struct boundary *boundaries) {
         if (Ustrncmp(&workbuf[Ustrlen(thisboundary->boundary_string)],"--",2) == 0) {
           /* final boundary found */
           return 2;
-        };      
+        };
         return 1;
       };
       thisboundary = thisboundary->next;
     };
   };
-  
-  return 0;  
+
+  return 0;
 }
 
 
@@ -482,28 +482,28 @@ int mime_check_boundary(uschar *line, struct boundary *boundaries) {
 */
 
 int mime_check_uu_start(uschar *line, uschar *uu_file_extension, int *has_tnef) {
-  
+
   if ( (strncmpic(line,US"begin ",6) == 0)) {
     uschar *uu_filename = &line[6];
-    
+
     /* skip perms, if present */
     Ustrtoul(&line[6],&uu_filename,10);
-      
+
     /* advance one char */
     uu_filename++;
-    
+
     /* This should be the filename.
     Check if winmail.dat is present,
     which indicates TNEF. */
     if (strncmpic(uu_filename,US"winmail.dat",11) == 0) {
-      *has_tnef = 1;  
+      *has_tnef = 1;
     };
-    
+
     /* reverse to dot if present,
     copy up to 4 chars for the extension */
     if (Ustrrchr(uu_filename,'.') != NULL)
       uu_filename = Ustrrchr(uu_filename,'.');
+
     return sscanf(CS uu_filename, "%4[.0-9A-Za-z]",CS uu_file_extension);
   }
   else {
@@ -529,7 +529,7 @@ long uu_decode_line(uschar *line, uschar **data, long line_len, uschar *info) {
   uschar tmp_c;
   uschar *work;
   int uu_decoded_line_len, uu_encoded_line_len;
-  
+
   /* allocate memory for data and work buffer */
   *data = (uschar *)malloc(line_len);
   if (*data == NULL) {
@@ -542,9 +542,9 @@ long uu_decode_line(uschar *line, uschar **data, long line_len, uschar *info) {
     snprintf(CS info, 1024,"unable to allocate %lu bytes",line_len);
     return -2;
   };
-  
+
   memcpy(work,line,line_len);
-  
+
   /* First char is line length
   This is microsofts way of getting it. Scary. */
   if (work[0] < 32) {
@@ -554,7 +554,7 @@ long uu_decode_line(uschar *line, uschar **data, long line_len, uschar *info) {
   else {
     uu_decoded_line_len = uudec[work[0]];
   };
-  
+
   p = &work[1];
 
   while (*p > 32) {
@@ -564,7 +564,7 @@ long uu_decode_line(uschar *line, uschar **data, long line_len, uschar *info) {
 
   uu_encoded_line_len = (p - &work[1]);
   p = &work[1];
-          
+
   /* check that resulting line length is a multiple of 4 */
   if ( ( uu_encoded_line_len % 4 ) != 0) {
     if (!warned_about_uudec_line_sanity_1) {
@@ -584,52 +584,52 @@ long uu_decode_line(uschar *line, uschar **data, long line_len, uschar *info) {
   };
 
   while ( ((p - &work[1]) < uu_encoded_line_len) && (num_decoded < uu_decoded_line_len)) {
-           
+
     /* byte 0 ---------------------- */
     if ((p - &work[1] + 1) >= uu_encoded_line_len) {
       return 0;
     }
-    
+
     (*data)[num_decoded] = *p;
     (*data)[num_decoded] <<= 2;
-    
+
     tmp_c = *(p+1);
     tmp_c >>= 4;
     (*data)[num_decoded] |= tmp_c;
-    
+
     num_decoded++;
     p++;
-     
+
     /* byte 1 ---------------------- */
     if ((p - &work[1] + 1) >= uu_encoded_line_len) {
       return 0;
     }
-    
+
     (*data)[num_decoded] = *p;
     (*data)[num_decoded] <<= 4;
-    
+
     tmp_c = *(p+1);
     tmp_c >>= 2;
     (*data)[num_decoded] |= tmp_c;
-    
+
     num_decoded++;
     p++;
-   
+
     /* byte 2 ---------------------- */
     if ((p - &work[1] + 1) >= uu_encoded_line_len) {
       return 0;
     }
-    
+
     (*data)[num_decoded] = *p;
     (*data)[num_decoded] <<= 6;
-    
+
     (*data)[num_decoded] |= *(p+1);
-    
+
     num_decoded++;
     p+=2;
-   
+
   };
-  
+
   return uu_decoded_line_len;
 }
 
@@ -652,17 +652,17 @@ long mime_decode_line(int mime_demux_mode,uschar *line, uschar **data, long max_
   long num_decoded = 0;
   int offset = 0;
   uschar tmp_c;
-  
+
   /* allocate memory for data */
   *data = (uschar *)malloc(max_data_len);
   if (*data == NULL) {
     snprintf(CS info, 1024,"unable to allocate %lu bytes",max_data_len);
     return -2;
   };
-  
+
   if (mime_demux_mode == MIME_DEMUX_MODE_BASE64) {
     /* ---------------------------------------------- */
-    
+
     /* NULL out trailing '\r' and '\n' chars */
     while (Ustrrchr(line,'\r') != NULL) {
       *(Ustrrchr(line,'\r')) = '\0';
@@ -670,7 +670,7 @@ long mime_decode_line(int mime_demux_mode,uschar *line, uschar **data, long max_
     while (Ustrrchr(line,'\n') != NULL) {
       *(Ustrrchr(line,'\n')) = '\0';
     };
-    
+
     /* check maximum base 64 line length */
     if (Ustrlen(line) > MIME_SANITY_MAX_B64_LINE_LENGTH ) {
       if (!warned_about_b64_line_length) {
@@ -696,7 +696,7 @@ long mime_decode_line(int mime_demux_mode,uschar *line, uschar **data, long max_
       };
     };
     *p = 255;
-   
+
     /* check that resulting line length is a multiple of 4 */
     if ( ( (p - &line[0]) % 4 ) != 0) {
       if (!warned_about_b64_line_sanity) {
@@ -704,70 +704,70 @@ long mime_decode_line(int mime_demux_mode,uschar *line, uschar **data, long max_
         warned_about_b64_line_sanity = 1;
       };
     };
-          
+
     /* line is translated, start bit shifting */
     p = line;
     num_decoded = 0;
-          
+
     while(*p != 255) {
-    
+
       /* byte 0 ---------------------- */
       if (*(p+1) == 255) {
         break;
       }
-      
+
       (*data)[num_decoded] = *p;
       (*data)[num_decoded] <<= 2;
-      
+
       tmp_c = *(p+1);
       tmp_c >>= 4;
       (*data)[num_decoded] |= tmp_c;
-      
+
       num_decoded++;
       p++;
-       
+
       /* byte 1 ---------------------- */
       if (*(p+1) == 255) {
         break;
       }
-      
+
       (*data)[num_decoded] = *p;
       (*data)[num_decoded] <<= 4;
-      
+
       tmp_c = *(p+1);
       tmp_c >>= 2;
       (*data)[num_decoded] |= tmp_c;
-      
+
       num_decoded++;
       p++;
-      
+
       /* byte 2 ---------------------- */
       if (*(p+1) == 255) {
         break;
       }
-      
+
       (*data)[num_decoded] = *p;
       (*data)[num_decoded] <<= 6;
-      
+
       (*data)[num_decoded] |= *(p+1);
-      
+
       num_decoded++;
       p+=2;
-      
+
     };
-    return num_decoded;   
+    return num_decoded;
     /* ---------------------------------------------- */
   }
   else if (mime_demux_mode == MIME_DEMUX_MODE_QP) {
     /* ---------------------------------------------- */
     p = line;
-         
+
     while (*p != 0) {
       if (*p == '=') {
         int decode_qp_result;
-        
+
         p = mime_decode_qp(p,&decode_qp_result);
-              
+
         if (decode_qp_result == -2) {
           /* Error from decoder. p is unchanged. */
           if (!warned_about_qp_line_sanity) {
@@ -779,7 +779,7 @@ long mime_decode_line(int mime_demux_mode,uschar *line, uschar **data, long max_
           p++;
         }
         else if (decode_qp_result == -1) {
-          /* End of the line with soft line break. 
+          /* End of the line with soft line break.
           Bail out. */
           goto QP_RETURN;
         }
@@ -798,7 +798,7 @@ long mime_decode_line(int mime_demux_mode,uschar *line, uschar **data, long max_
     return num_decoded;
     /* ---------------------------------------------- */
   };
-  
+
   return 0;
 }
 
@@ -862,24 +862,24 @@ int mime_demux(FILE *f, uschar *info) {
   struct mime_part mime_part_p;
   int has_tnef = 0;
   int has_rfc822 = 0;
-  
+
   /* allocate room for our linebuffer */
   line = (uschar *)malloc(MIME_SANITY_MAX_LINE_LENGTH);
   if (line == NULL) {
     snprintf(CS info, 1024,"unable to allocate %u bytes",MIME_SANITY_MAX_LINE_LENGTH);
     return DEFER;
   };
-  
+
   /* clear MIME header structure */
   memset(&mime_part_p,0,sizeof(mime_part));
-  
+
   /* ----------------------- start demux loop --------------------- */
   while (mime_read_line_status == MIME_READ_LINE_OK) {
-  
+
     /* read a line of input. Depending on the mode we are in,
     the returned format will differ. */
     mime_read_line_status = mime_read_line(f,mime_demux_mode,line,&line_len);
-    
+
     if (mime_read_line_status == MIME_READ_LINE_OVERFLOW) {
       mime_trigger_error(MIME_ERRORLEVEL_LONG_LINE);
       /* despite the error, continue  .. */
@@ -892,13 +892,13 @@ int mime_demux(FILE *f, uschar *info) {
 
     if (mime_demux_mode == MIME_DEMUX_MODE_MIME_HEADERS) {
       /* -------------- header mode --------------------- */
-      
+
       /* Check for an empty line, which is the end of the headers.
        In HEADER mode, the line is returned "cooked", with the
        final '\n' replaced by a ';' */
       if (line_len == 1) {
         int tmp;
-        
+
         /* We have reached the end of the headers. Start decoding
         with the collected settings. */
         if (mime_part_p.seen_content_transfer_encoding > 1) {
@@ -908,7 +908,7 @@ int mime_demux(FILE *f, uschar *info) {
           /* default to plain mode if no specific encoding type found */
           mime_demux_mode = MIME_DEMUX_MODE_PLAIN;
         };
-        
+
         /* open new dump file */
         tmp = mime_get_dump_file(mime_part_p.extension, &mime_dump_file, info);
         if (tmp < 0) {
@@ -924,7 +924,7 @@ int mime_demux(FILE *f, uschar *info) {
         if (strncmpic(US"content-type:",line,Ustrlen("content-type:")) == 0) {
           /* ---------------------------- Content-Type header ------------------------------- */
           uschar *value = line;
-          
+
           /* check for message/partial MIME type and reject it */
           if (mime_header_find(line,US"message/partial",NULL) > 0)
             mime_trigger_error(MIME_ERRORLEVEL_MESSAGE_PARTIAL);
@@ -932,11 +932,11 @@ int mime_demux(FILE *f, uschar *info) {
           /* check for TNEF content type, remember to unpack TNEF later. */
           if (mime_header_find(line,US"application/ms-tnef",NULL) > 0)
             has_tnef = 1;
-          
+
           /* check for message/rfcxxx attachments */
           if (mime_header_find(line,US"message/rfc822",NULL) > 0)
             has_rfc822 = 1;
-          
+
           /* find the file extension, but do not fill it in
           it is already set, since content-disposition has
           precedence. */
@@ -944,7 +944,7 @@ int mime_demux(FILE *f, uschar *info) {
             if (mime_header_find(line,US"name",&value) == 2) {
               if (Ustrlen(value) > MIME_SANITY_MAX_FILENAME)
                 mime_trigger_error(MIME_ERRORLEVEL_FILENAME_LENGTH);
-              mime_part_p.extension = value;   
+              mime_part_p.extension = value;
               mime_part_p.extension = Ustrrchr(value,'.');
               if (mime_part_p.extension == NULL) {
                 /* file without extension, setting
@@ -954,8 +954,8 @@ int mime_demux(FILE *f, uschar *info) {
               else {
                 struct file_extension *this_extension =
                   (struct file_extension *)malloc(sizeof(file_extension));
-                
-                this_extension->file_extension_string = 
+
+                this_extension->file_extension_string =
                   (uschar *)malloc(Ustrlen(mime_part_p.extension)+1);
                 Ustrcpy(this_extension->file_extension_string,
                         mime_part_p.extension+1);
@@ -964,14 +964,14 @@ int mime_demux(FILE *f, uschar *info) {
               };
             };
           };
-        
+
           /* find a boundary and add it to the list, if present */
           value = line;
           if (mime_header_find(line,US"boundary",&value) == 2) {
             struct boundary *thisboundary;
 
             if (Ustrlen(value) > MIME_SANITY_MAX_BOUNDARY_LENGTH) {
-              mime_trigger_error(MIME_ERRORLEVEL_BOUNDARY_LENGTH); 
+              mime_trigger_error(MIME_ERRORLEVEL_BOUNDARY_LENGTH);
             }
             else {
               thisboundary = (struct boundary*)malloc(sizeof(boundary));
@@ -980,7 +980,7 @@ int mime_demux(FILE *f, uschar *info) {
               boundaries = thisboundary;
             };
           };
-        
+
           if (mime_part_p.seen_content_type == 0) {
             mime_part_p.seen_content_type = 1;
           }
@@ -991,7 +991,7 @@ int mime_demux(FILE *f, uschar *info) {
         }
         else if (strncmpic(US"content-transfer-encoding:",line,Ustrlen("content-transfer-encoding:")) == 0) {
           /* ---------------------------- Content-Transfer-Encoding header -------------- */
+
          if (mime_part_p.seen_content_transfer_encoding == 0) {
             if (mime_header_find(line,US"base64",NULL) > 0) {
               mime_part_p.seen_content_transfer_encoding = MIME_DEMUX_MODE_BASE64;
@@ -1011,10 +1011,10 @@ int mime_demux(FILE *f, uschar *info) {
         else if (strncmpic(US"content-disposition:",line,Ustrlen("content-disposition:")) == 0) {
           /* ---------------------------- Content-Disposition header -------------------- */
           uschar *value = line;
-          
+
           if (mime_part_p.seen_content_disposition == 0) {
             mime_part_p.seen_content_disposition = 1;
-          
+
             if (mime_header_find(line,US"filename",&value) == 2) {
               if (Ustrlen(value) > MIME_SANITY_MAX_FILENAME)
                 mime_trigger_error(MIME_ERRORLEVEL_FILENAME_LENGTH);
@@ -1028,8 +1028,8 @@ int mime_demux(FILE *f, uschar *info) {
               else {
                 struct file_extension *this_extension =
                   (struct file_extension *)malloc(sizeof(file_extension));
-                
-                this_extension->file_extension_string = 
+
+                this_extension->file_extension_string =
                   (uschar *)malloc(Ustrlen(mime_part_p.extension)+1);
                 Ustrcpy(this_extension->file_extension_string,
                         mime_part_p.extension+1);
@@ -1072,9 +1072,9 @@ int mime_demux(FILE *f, uschar *info) {
 
         if (uu_mode == MIME_UU_MODE_UNCONFIRMED) {
          /* We are in unconfirmed UUENCODE mode. */
-         
+
          data_len = uu_decode_line(line,&data,line_len,info);
-         
+
          if (data_len == -2) {
            /* temp error, turn off uudecode mode */
            if (uu_dump_file != NULL) {
@@ -1121,18 +1121,18 @@ int mime_demux(FILE *f, uschar *info) {
              };
           };
         };
-       
+
         /* write data to dump file, if available */
         if (data_len > 0) {
           if (fwrite(data,1,data_len,uu_dump_file) < data_len) {
             /* short write */
             snprintf(CS info, 1024,"short write on uudecode dump file");
             free(line);
-            return DEFER;            
+            return DEFER;
           };
         };
       };
-      
+
       if (mime_demux_mode != MIME_DEMUX_MODE_SCANNING) {
         /* Non-scanning and Non-header mode. That means
         we are currently decoding data to the dump
@@ -1151,7 +1151,7 @@ int mime_demux(FILE *f, uschar *info) {
               rewind(mime_dump_file);
               mime_demux(mime_dump_file,info);
             };
-            
+
             fclose(mime_dump_file); mime_dump_file = NULL;
           };
         }
@@ -1166,14 +1166,14 @@ int mime_demux(FILE *f, uschar *info) {
               rewind(mime_dump_file);
               mime_demux(mime_dump_file,info);
             };
-            
+
             fclose(mime_dump_file); mime_dump_file = NULL;
           };
         }
         else {
           uschar *data;
           long data_len = 0;
-          
+
           /* decode the line with the appropriate method */
           if (mime_demux_mode == MIME_DEMUX_MODE_PLAIN) {
             /* in plain mode, just dump the line */
@@ -1187,17 +1187,17 @@ int mime_demux(FILE *f, uschar *info) {
               data_len = 0;
             };
           };
-          
+
           /* write data to dump file */
           if (data_len > 0) {
             if (fwrite(data,1,data_len,mime_dump_file) < data_len) {
               /* short write */
               snprintf(CS info, 1024,"short write on dump file");
               free(line);
-              return DEFER;            
+              return DEFER;
             };
           };
-          
+
         };
       }
       else {
@@ -1209,31 +1209,31 @@ int mime_demux(FILE *f, uschar *info) {
         if (mime_check_boundary(line,boundaries) == 1) {
           mime_demux_mode = MIME_DEMUX_MODE_MIME_HEADERS;
         };
-        
+
       };
       /* ------------------------------------------------ */
     };
   };
   /* ----------------------- end demux loop ----------------------- */
-  
+
   /* close files, they could still be open */
   if (mime_dump_file != NULL)
     fclose(mime_dump_file);
   if (uu_dump_file != NULL)
     fclose(uu_dump_file);
-  
+
   /* release line buffer */
   free(line);
-  
+
   /* FIXME: release boundary buffers.
   Not too much of a problem since
   this instance of exim is not resident. */
-  
+
   if (has_tnef) {
     uschar file_name[1024];
     /* at least one file could be TNEF encoded.
     attempt to send all decoded files thru the TNEF decoder */
-    
+
     snprintf(CS file_name,1024,"%s/scan/%s",spool_directory,message_id);
     /* Removed FTTB. We need to decide on TNEF inclusion */
     /* mime_unpack_tnef(file_name); */