-int mime_acl_check(uschar *acl, FILE *f, struct mime_boundary_context *context,
- uschar **user_msgptr, uschar **log_msgptr) {
- int rc = OK;
- uschar *header = NULL;
- struct mime_boundary_context nested_context;
-
- /* reserve a line buffer to work in */
- header = (uschar *)malloc(MIME_MAX_HEADER_SIZE+1);
- if (header == NULL) {
- log_write(0, LOG_PANIC,
- "MIME ACL: can't allocate %d bytes of memory.", MIME_MAX_HEADER_SIZE+1);
- return DEFER;
- };
-
- /* Not actually used at the moment, but will be vital to fixing
- * some RFC 2046 nonconformance later... */
- nested_context.parent = context;
-
- /* loop through parts */
- while(1) {
-
- /* reset all per-part mime variables */
- mime_anomaly_level = 0;
- mime_anomaly_text = NULL;
- mime_boundary = NULL;
- mime_charset = NULL;
- mime_decoded_filename = NULL;
- mime_filename = NULL;
- mime_content_description = NULL;
- mime_content_disposition = NULL;
- mime_content_id = NULL;
- mime_content_transfer_encoding = NULL;
- mime_content_type = NULL;
- mime_is_multipart = 0;
- mime_content_size = 0;
-
- /*
- If boundary is null, we assume that *f is positioned on the start of headers (for example,
- at the very beginning of a message.
- If a boundary is given, we must first advance to it to reach the start of the next header
- block.
- */
-
- /* NOTE -- there's an error here -- RFC2046 specifically says to
- * check for outer boundaries. This code doesn't do that, and
- * I haven't fixed this.
- *
- * (I have moved partway towards adding support, however, by adding
- * a "parent" field to my new boundary-context structure.)
- */
- if (context != NULL) {
- while(fgets(CS header, MIME_MAX_HEADER_SIZE, f) != NULL) {
- /* boundary line must start with 2 dashes */
- if (Ustrncmp(header,"--",2) == 0) {
- if (Ustrncmp((header+2),context->boundary,Ustrlen(context->boundary)) == 0) {
- /* found boundary */
- if (Ustrncmp((header+2+Ustrlen(context->boundary)),"--",2) == 0) {
- /* END boundary found */
- debug_printf("End boundary found %s\n", context->boundary);
- return rc;
- }
- else {
- debug_printf("Next part with boundary %s\n", context->boundary);
- };
- /* can't use break here */
- goto DECODE_HEADERS;
- }
- };
- }
- /* 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, check_rfc2047_length, 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++;
- };
- };
- };
- };