Re: [exim] decoding base64

Αρχική Σελίδα
Delete this message
Reply to this message
Συντάκτης: Jasen Betts
Ημερομηνία:  
Προς: exim-users
Αντικείμενο: Re: [exim] decoding base64
On 2015-09-16, Bjørnar Ness <bjornar.ness@???> wrote:
> 2015-09-16 19:56 GMT+02:00 Bjørnar Ness <bjornar.ness@???>:
>> Is there no b642str function? I cant seem to find it.
>>
>> Also, When I insert a header in a mail using str2b64 I am unable
>> to read the decoded content of this header (decoded) using $bh_ or $h_
>> I only get the b64 encoded string. From what I understand from the
>> documentation, this is wrong?
>
> To answer this question myself:
>
>=?UTF-8?B?${str2b64:$acl_c_scfg}?=


That looks risky unless the length is constrained.

> general base64 decoding is still a question..



I'm pretty sure there's none in stock exim. this source patch
provides such a feature "b642str"
IIRC it's against 4.72 so some of the offsets have changed.


diff --git a/build/exim/src/expand.c b/build/exim/src/expand.c
index 84167b6..48cbfd6 100644
--- a/build/exim/src/expand.c
+++ b/build/exim/src/expand.c
@@ -11,6 +11,8 @@

#include "exim.h"

+#include "pdkim/base64.h"
+
/* Recursively called function */

 static uschar *expand_string_internal(uschar *, BOOL, uschar **, BOOL, BOOL);
@@ -169,6 +171,7 @@ enum {
 static uschar *op_table_main[] = {
   US"address",
   US"addresses",
+  US"b642str",
   US"base62",
   US"base62d",
   US"domain",
@@ -202,6 +205,7 @@ static uschar *op_table_main[] = {
 enum {
   EOP_ADDRESS =  sizeof(op_table_underscore)/sizeof(uschar *),
   EOP_ADDRESSES,
+  EOP_B642STR,
   EOP_BASE62,
   EOP_BASE62D,
   EOP_DOMAIN,
@@ -5767,6 +5771,26 @@ while (*s != 0)
         uschar *encstr = auth_b64encode(sub, Ustrlen(sub));
         yield = string_cat(yield, &size, &ptr, encstr, Ustrlen(encstr));
         continue;
+
+        }
+      /* Convert base64 encoding to string */
+
+      case EOP_B642STR:
+        {
+       int bufsz;
+       uschar *encstr = store_get(bufsz=(3*(Ustrlen(sub)/4) + 1));
+       if( base64_decode( encstr, &bufsz, sub,Ustrlen(sub)))
+          {
+          expand_string_message = string_sprintf("string \"%s\" is not valid "
+            "base64", sub);
+          goto EXPAND_FAILED;
+          }
+       else
+          {
+          encstr[bufsz]='\0';
+          yield = string_cat(yield, &size, &ptr, encstr, bufsz);
+          }
+        continue;
         }


       /* strlen returns the length of the string */




--
\_(ツ)_