+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++)
+ if (strncmpic(mime_header_list[i].name,
+ header, mime_header_list[i].namelen) == 0)
+ { /* found an interesting header */
+ uschar * header_value;
+ int header_value_len;
+ uschar * p = header + mime_header_list[i].namelen;
+
+ /* 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);
+ p = header + mime_header_list[i].namelen;
+ header_value = string_copyn(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)
+ {
+ /* debug_printf(" considering paramlist '%s'\n", p); */
+ mime_parameter * mp;
+ for (mp = mime_parameter_list;
+ mp < &mime_parameter_list[mime_parameter_list_size];
+ mp++)
+ {
+ uschar * param_value = NULL;
+
+ /* found an interesting parameter? */
+ if (strncmpic(mp->name, p, mp->namelen) == 0)
+ {
+ int size = 0;
+ int ptr = 0;
+
+ /* yes, grab the value and copy to its corresponding expansion variable */
+ p += mp->namelen;
+ while(*p && *p != ';') /* ; terminates */
+ if (*p == '"')
+ {
+ p++; /* skip leading " */
+ while(*p && *p != '"') /* " protects ; */
+ param_value = string_cat(param_value, &size, &ptr, p++, 1);
+ if (*p) p++; /* skip trailing " */
+ }
+ else
+ param_value = string_cat(param_value, &size, &ptr, p++, 1);
+ if (*p) p++; /* skip trailing ; */
+
+ if (param_value)
+ {
+ uschar * dummy;
+ param_value[ptr++] = '\0';
+
+ param_value = rfc2047_decode(param_value,
+ check_rfc2047_length, NULL, 32, NULL, &dummy);
+ debug_printf(" Found %s MIME parameter in %s header, "
+ "value is '%s'\n", mp->name, mime_header_list[i].name,
+ param_value);
+ }
+ *mp->value = param_value;
+ goto NEXT_PARAM_SEARCH;
+ }
+ }
+ /* There is something, but not one of our interesting parameters.
+ Advance to the next unquoted semicolon */
+ while(*p && *p != ';')
+ if (*p == '"')
+ {
+ while(*++p && *p != '"') ;
+ if (*p) p++;
+ }
+ else
+ p++;
+ if (*p) p++;
+ }
+ }
+ }