Added acl_not_smtp_mime. This involved a bit of refactoring of the
[exim.git] / src / src / mime.c
index 0a636720088b5ba1b96fb9e174fd19aa45bdfca6..05b6e3e2a00bcfe11b74f6dc98ce003bcfb93915 100644 (file)
@@ -1,4 +1,4 @@
-/* $Cambridge: exim/src/src/mime.c,v 1.4 2005/02/17 11:58:26 ph10 Exp $ */
+/* $Cambridge: exim/src/src/mime.c,v 1.7 2005/04/04 10:33:49 ph10 Exp $ */
 
 /*************************************************
 *     Exim - an Internet mail transport agent    *
@@ -115,10 +115,7 @@ uschar *mime_decode_qp_char(uschar *qp_p,int *c) {
 }
 
 
-uschar *mime_parse_line(uschar *buffer, uschar *encoding, int *num_decoded) {
-  uschar *data = NULL;
-
-  data = (uschar *)malloc(Ustrlen(buffer)+2);
+uschar *mime_parse_line(uschar *buffer, uschar *data, uschar *encoding, int *num_decoded) {
 
   if (encoding == NULL) {
     /* no encoding type at all */
@@ -285,6 +282,7 @@ int mime_decode(uschar **listptr) {
   uschar decode_path[1024];
   FILE *decode_file = NULL;
   uschar *buffer = NULL;
+  uschar *decode_buffer = NULL;
   long f_pos = 0;
   unsigned int size_counter = 0;
 
@@ -296,7 +294,7 @@ int mime_decode(uschar **listptr) {
   /* build default decode path (will exist since MBOX must be spooled up) */
   snprintf(CS decode_path,1024,"%s/scan/%s",spool_directory,message_id);
 
-  /* reserve a line buffer to work in */
+  /* reserve a line and decoder buffer to work in */
   buffer = (uschar *)malloc(MIME_MAX_LINE_LENGTH+1);
   if (buffer == NULL) {
     log_write(0, LOG_PANIC,
@@ -304,6 +302,13 @@ int mime_decode(uschar **listptr) {
     return DEFER;
   };
 
+  decode_buffer = (uschar *)malloc(MIME_MAX_LINE_LENGTH+1);
+  if (decode_buffer == NULL) {
+    log_write(0, LOG_PANIC,
+                 "decode ACL condition: can't allocate %d bytes of memory.", MIME_MAX_LINE_LENGTH+1);
+    return DEFER;
+  };
+
   /* try to find 1st option */
   if ((option = string_nextinlist(&list, &sep,
                                   option_buffer,
@@ -358,7 +363,8 @@ int mime_decode(uschar **listptr) {
       };
     };
 
-    decoded_line = mime_parse_line(buffer, mime_content_transfer_encoding, &decoded_line_length);
+    decoded_line = mime_parse_line(buffer, decode_buffer, mime_content_transfer_encoding, &decoded_line_length);
+
     /* write line to decode file */
     if (fwrite(decoded_line, 1, decoded_line_length, decode_file) < decoded_line_length) {
       /* error/short write */
@@ -376,7 +382,6 @@ int mime_decode(uschar **listptr) {
       size_counter = (size_counter % 1024);
     };
 
-    free(decoded_line);
   }
 
   fclose(decode_file);
@@ -497,8 +502,8 @@ int mime_get_header(FILE *f, uschar *header) {
 }
 
 
-int mime_acl_check(FILE *f, struct mime_boundary_context *context, uschar
-                   **user_msgptr, uschar **log_msgptr) {
+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;
@@ -507,7 +512,7 @@ int mime_acl_check(FILE *f, struct mime_boundary_context *context, uschar
   header = (uschar *)malloc(MIME_MAX_HEADER_SIZE+1);
   if (header == NULL) {
     log_write(0, LOG_PANIC,
-                 "acl_smtp_mime: can't allocate %d bytes of memory.", MIME_MAX_HEADER_SIZE+1);
+                 "MIME ACL: can't allocate %d bytes of memory.", MIME_MAX_HEADER_SIZE+1);
     return DEFER;
   };
 
@@ -654,7 +659,7 @@ int mime_acl_check(FILE *f, struct mime_boundary_context *context, uschar
     mime_is_coverletter = !(context && context->context == MBC_ATTACHMENT);
 
     /* call ACL handling function */
-    rc = acl_check(ACL_WHERE_MIME, NULL, acl_smtp_mime, user_msgptr, log_msgptr);
+    rc = acl_check(ACL_WHERE_MIME, NULL, acl, user_msgptr, log_msgptr);
 
     mime_stream = NULL;
     mime_current_boundary = NULL;
@@ -675,7 +680,7 @@ int mime_acl_check(FILE *f, struct mime_boundary_context *context, uschar
       else
         nested_context.context = MBC_COVERLETTER_ONESHOT;
 
-      rc = mime_acl_check(f, &nested_context, user_msgptr, log_msgptr);
+      rc = mime_acl_check(acl, f, &nested_context, user_msgptr, log_msgptr);
       if (rc != OK) break;
     }
     else if ( (mime_content_type != NULL) &&