- /* Hit EOF or read error. Ugh. */
- debug_printf("Hit EOF ...\n");
- return rc;
- };
-
- DECODE_HEADERS:
- /* parse headers, set up expansion variables */
- while(mime_get_header(f,header)) {
- int i;
- /* loop through header list */
- for (i = 0; i < mime_header_list_size; i++) {
- uschar *header_value = NULL;
- int header_value_len = 0;
-
- /* found an interesting header? */
- if (strncmpic(mime_header_list[i].name,header,mime_header_list[i].namelen) == 0) {
- uschar *p = header + mime_header_list[i].namelen;
- /* yes, grab the value (normalize to lower case)
- and copy to its corresponding expansion variable */
- while(*p != ';') {
- *p = tolower(*p);
- p++;
- };
- header_value_len = (p - (header + mime_header_list[i].namelen));
- header_value = (uschar *)malloc(header_value_len+1);
- memset(header_value,0,header_value_len+1);
- p = header + mime_header_list[i].namelen;
- Ustrncpy(header_value, p, header_value_len);
- debug_printf("Found %s MIME header, value is '%s'\n", mime_header_list[i].name, header_value);
- *((uschar **)(mime_header_list[i].value)) = header_value;
-
- /* make p point to the next character after the closing ';' */
- p += (header_value_len+1);
-
- /* grab all param=value tags on the remaining line, check if they are interesting */
- NEXT_PARAM_SEARCH: while (*p != 0) {
- int j;
- for (j = 0; j < mime_parameter_list_size; j++) {
- uschar *param_value = NULL;
- int param_value_len = 0;
-
- /* found an interesting parameter? */
- if (strncmpic(mime_parameter_list[j].name,p,mime_parameter_list[j].namelen) == 0) {
- uschar *q = p + mime_parameter_list[j].namelen;
- /* yes, grab the value and copy to its corresponding expansion variable */
- while(*q != ';') q++;
- param_value_len = (q - (p + mime_parameter_list[j].namelen));
- param_value = (uschar *)malloc(param_value_len+1);
- memset(param_value,0,param_value_len+1);
- q = p + mime_parameter_list[j].namelen;
- Ustrncpy(param_value, q, param_value_len);
- param_value = rfc2047_decode(param_value, TRUE, NULL, 32, ¶m_value_len, &q);
- debug_printf("Found %s MIME parameter in %s header, value is '%s'\n", mime_parameter_list[j].name, mime_header_list[i].name, param_value);
- *((uschar **)(mime_parameter_list[j].value)) = param_value;
- p += (mime_parameter_list[j].namelen + param_value_len + 1);
- goto NEXT_PARAM_SEARCH;
- };
- }
- /* There is something, but not one of our interesting parameters.
- Advance to the next semicolon */
- while(*p != ';') p++;
- p++;
- };
- };
- };
- };
-
- /* set additional flag variables (easier access) */
- if ( (mime_content_type != NULL) &&
- (Ustrncmp(mime_content_type,"multipart",9) == 0) )
- mime_is_multipart = 1;
-
- /* Make a copy of the boundary pointer.
- Required since mime_boundary is global
- and can be overwritten further down in recursion */
- nested_context.boundary = mime_boundary;
-
- /* raise global counter */
- mime_part_count++;
-
- /* copy current file handle to global variable */
+ /* Hit EOF or read error. Ugh. */
+ debug_printf("Hit EOF ...\n");
+ return rc;
+ }
+
+DECODE_HEADERS:
+ /* parse headers, set up expansion variables */
+ while (mime_get_header(f,header))
+ {
+ int i;
+ /* loop through header list */
+ for (i = 0; i < mime_header_list_size; i++)
+ {
+ uschar *header_value = NULL;
+ int header_value_len = 0;
+
+ /* found an interesting header? */
+ if (strncmpic(mime_header_list[i].name,header,mime_header_list[i].namelen) == 0)
+ {
+ uschar *p = header + mime_header_list[i].namelen;
+ /* yes, grab the value (normalize to lower case)
+ and copy to its corresponding expansion variable */
+ while(*p != ';')
+ {
+ *p = tolower(*p);
+ p++;
+ }
+ header_value_len = (p - (header + mime_header_list[i].namelen));
+ header_value = (uschar *)malloc(header_value_len+1);
+ memset(header_value,0,header_value_len+1);
+ p = header + mime_header_list[i].namelen;
+ Ustrncpy(header_value, p, header_value_len);
+ debug_printf("Found %s MIME header, value is '%s'\n", mime_header_list[i].name, header_value);
+ *((uschar **)(mime_header_list[i].value)) = header_value;
+
+ /* make p point to the next character after the closing ';' */
+ p += (header_value_len+1);
+
+ /* grab all param=value tags on the remaining line, check if they are interesting */
+NEXT_PARAM_SEARCH:
+ while (*p != 0)
+ {
+ mime_parameter * mp;
+ for (mp = mime_parameter_list;
+ mp < &mime_parameter_list[mime_parameter_list_size];
+ mp++)
+ {
+ uschar *param_value = NULL;
+ int param_value_len = 0;
+
+ /* found an interesting parameter? */
+ if (strncmpic(mp->name, p, mp->namelen) == 0)
+ {
+ uschar *q = p + mp->namelen;
+ int size = 0;
+ int ptr = 0;
+
+ /* yes, grab the value and copy to its corresponding expansion variable */
+ while(*q && *q != ';') /* ; terminates */
+ {
+ if (*q == '"')
+ {
+ q++; /* skip leading " */
+ while(*q && *q != '"') /* which protects ; */
+ param_value = string_cat(param_value, &size, &ptr, q++, 1);
+ if (*q) q++; /* skip trailing " */
+ }
+ else
+ param_value = string_cat(param_value, &size, &ptr, q++, 1);
+ }
+ param_value[ptr++] = '\0';
+ param_value_len = ptr;
+
+ param_value = rfc2047_decode(param_value, check_rfc2047_length, NULL, 32, ¶m_value_len, &q);
+ debug_printf("Found %s MIME parameter in %s header, value is '%s'\n", mp->name, mime_header_list[i].name, param_value);
+ *((uschar **)(mp->value)) = param_value;
+ p += (mp->namelen + param_value_len + 1);
+ goto NEXT_PARAM_SEARCH;
+ }
+ }
+ /* There is something, but not one of our interesting parameters.
+ Advance to the next semicolon */
+ while(*p != ';') p++;
+ p++;
+ }
+ }
+ }
+ }
+
+ /* set additional flag variables (easier access) */
+ if ( (mime_content_type != NULL) &&
+ (Ustrncmp(mime_content_type,"multipart",9) == 0) )
+ mime_is_multipart = 1;
+
+ /* Make a copy of the boundary pointer.
+ Required since mime_boundary is global
+ and can be overwritten further down in recursion */
+ nested_context.boundary = mime_boundary;
+
+ /* raise global counter */
+ mime_part_count++;
+
+ /* copy current file handle to global variable */
+ mime_stream = f;
+ mime_current_boundary = context ? context->boundary : 0;
+
+ /* Note the context */
+ mime_is_coverletter = !(context && context->context == MBC_ATTACHMENT);
+
+ /* call ACL handling function */
+ rc = acl_check(ACL_WHERE_MIME, NULL, acl, user_msgptr, log_msgptr);
+
+ mime_stream = NULL;
+ mime_current_boundary = NULL;
+
+ if (rc != OK) break;
+
+ /* If we have a multipart entity and a boundary, go recursive */
+ if ( (mime_content_type != NULL) &&
+ (nested_context.boundary != NULL) &&
+ (Ustrncmp(mime_content_type,"multipart",9) == 0) )
+ {
+ debug_printf("Entering multipart recursion, boundary '%s'\n", nested_context.boundary);
+
+ nested_context.context =
+ context && context->context == MBC_ATTACHMENT
+ ? MBC_ATTACHMENT
+ : Ustrcmp(mime_content_type,"multipart/alternative") == 0
+ || Ustrcmp(mime_content_type,"multipart/related") == 0
+ ? MBC_COVERLETTER_ALL
+ : MBC_COVERLETTER_ONESHOT;
+
+ rc = mime_acl_check(acl, f, &nested_context, user_msgptr, log_msgptr);
+ if (rc != OK) break;
+ }
+ else if ( (mime_content_type != NULL) &&
+ (Ustrncmp(mime_content_type,"message/rfc822",14) == 0) )
+ {
+ uschar *rfc822name = NULL;
+ uschar filename[2048];
+ int file_nr = 0;
+ int result = 0;
+
+ /* must find first free sequential filename */
+ do
+ {
+ struct stat mystat;
+ (void)string_format(filename, 2048,
+ "%s/scan/%s/__rfc822_%05u", spool_directory, message_id, file_nr++);
+ /* security break */
+ if (file_nr >= 128)
+ goto NO_RFC822;
+ result = stat(CS filename,&mystat);
+ } while (result != -1);
+
+ rfc822name = filename;
+
+ /* decode RFC822 attachment */
+ mime_decoded_filename = NULL;