Adjust the timeout after interrupted select()
[exim.git] / src / src / mime.c
index aeab33d9c22ac62e2f57a424769fc2dcc82bb79f..618364a3ecbbde1bcc0de6e4e63518c08fdf86b1 100644 (file)
@@ -2,7 +2,7 @@
 *     Exim - an Internet mail transport agent    *
 *************************************************/
 
-/* Copyright (c) Tom Kistner <tom@duncanthrax.net> 2004 */
+/* Copyright (c) Tom Kistner <tom@duncanthrax.net> 2004, 2015 */
 /* License: GPL */
 
 #include "exim.h"
@@ -543,6 +543,32 @@ return s;
 }
 
 
+static uschar *
+rfc2231_to_2047(const uschar * fname, const uschar * charset, int * len)
+{
+int size = 0, ptr = 0;
+uschar * val = string_cat(NULL, &size, &ptr, US"=?", 2);
+uschar c;
+
+val = string_cat(val, &size, &ptr, charset, Ustrlen(charset));
+val = string_cat(val, &size, &ptr, US"?Q?", 3);
+
+while ((c = *fname))
+  if (c == '%' && isxdigit(fname[1]) && isxdigit(fname[2]))
+    {
+    val = string_cat(val, &size, &ptr, US"=", 1);
+    val = string_cat(val, &size, &ptr, ++fname, 2);
+    fname += 2;
+    }
+  else
+    val = string_cat(val, &size, &ptr, fname++, 1);
+
+val = string_cat(val, &size, &ptr, US"?=", 2);
+val[*len = ptr] = '\0';
+return val;
+}
+
+
 int
 mime_acl_check(uschar *acl, FILE *f, struct mime_boundary_context *context,
     uschar **user_msgptr, uschar **log_msgptr)
@@ -614,8 +640,6 @@ while(1)
         mh < mime_header_list + mime_header_list_size;
         mh++) if (strncmpic(mh->name, header, mh->namelen) == 0)
       {
-      uschar * header_value = NULL;
-      int header_value_len = 0;
       uschar * p = header + mh->namelen;
       uschar * q;
 
@@ -645,8 +669,8 @@ while(1)
          DEBUG(D_acl) debug_printf("  considering paramlist '%s'\n", p);
 
          if (  !mime_filename
-            && strncmpic("content-disposition:", header, 20) == 0
-            && strncmpic("filename*", p, 9) == 0
+            && strncmpic(CUS"content-disposition:", header, 20) == 0
+            && strncmpic(CUS"filename*", p, 9) == 0
             )
            {                                   /* RFC 2231 filename */
            uschar * q;
@@ -689,11 +713,7 @@ while(1)
                else
                  p = q;
 
-               temp_string = expand_string(string_sprintf(
-                 "=?%s?Q?${sg{%s}{\\N%%([\\dA-Fa-f]{2})\\N}{=\\$1}}?=",
-                 mime_filename_charset, p));
-               slen = Ustrlen(temp_string);
-
+               temp_string = rfc2231_to_2047(p, mime_filename_charset, &slen);
                temp_string = rfc2047_decode(temp_string, FALSE, NULL, 32,
                  NULL, &err_msg);
                size = Ustrlen(temp_string);
@@ -743,7 +763,7 @@ while(1)
          if (*p) p++;
          }                             /* param scan on line */
 
-       if (strncmpic("content-disposition:", header, 20) == 0)
+       if (strncmpic(CUS"content-disposition:", header, 20) == 0)
          {
          if (decoding_failed) mime_filename = mime_fname_rfc2231;