summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/doc-docbook/spec.xfpt20
-rw-r--r--doc/doc-txt/NewStuff3
-rw-r--r--src/src/expand.c19
-rw-r--r--test/scripts/0000-Basic/00024
-rw-r--r--test/stdout/00025
5 files changed, 48 insertions, 3 deletions
diff --git a/doc/doc-docbook/spec.xfpt b/doc/doc-docbook/spec.xfpt
index 7e59c304d..6f6ee4557 100644
--- a/doc/doc-docbook/spec.xfpt
+++ b/doc/doc-docbook/spec.xfpt
@@ -10033,6 +10033,20 @@ environments where Exim uses base 36 instead of base 62 for its message
identifiers, base-36 digits. The number is converted to decimal and output as a
string.
+.new
+.vitem &*${base64:*&<&'string'&>&*}*&
+.cindex "expansion" "base64 encoding"
+.cindex "base64 encoding" "in string expansion"
+.cindex "&%base64%& expansion item"
+This operator converts a string into one that is base64 encoded.
+
+.vitem &*${base64d:*&<&'string'&>&*}*&
+.cindex "expansion" "base64 decoding"
+.cindex "base64 decoding" "in string expansion"
+.cindex "&%base64d%& expansion item"
+This operator converts a base64-encoded string into the un-coded form.
+.wen
+
.vitem &*${domain:*&<&'string'&>&*}*&
.cindex "domain" "extraction"
@@ -10463,10 +10477,10 @@ the system administrator. &*Warning*&: The file size may be incorrect on 32-bit
systems for files larger than 2GB.
.vitem &*${str2b64:*&<&'string'&>&*}*&
-.cindex "expansion" "base64 encoding"
-.cindex "base64 encoding" "in string expansion"
.cindex "&%str2b64%& expansion item"
-This operator converts a string into one that is base64 encoded.
+.new
+Now deprecated, a synonym for the &%base64%& expansion operator.
+.wen
diff --git a/doc/doc-txt/NewStuff b/doc/doc-txt/NewStuff
index 7385212cc..e82feffcc 100644
--- a/doc/doc-txt/NewStuff
+++ b/doc/doc-txt/NewStuff
@@ -28,6 +28,9 @@ Version 4.87
6. New $dkim_key_length variable.
+ 7. New base64d and base64 expansion items (the existing str2b64 being a
+ synonym of the latter).
+
Version 4.86
------------
diff --git a/src/src/expand.c b/src/src/expand.c
index d707c2cdb..fad8cc7c7 100644
--- a/src/src/expand.c
+++ b/src/src/expand.c
@@ -201,6 +201,8 @@ static uschar *op_table_main[] = {
US"addresses",
US"base62",
US"base62d",
+ US"base64",
+ US"base64d",
US"domain",
US"escape",
US"eval",
@@ -241,6 +243,8 @@ enum {
EOP_ADDRESSES,
EOP_BASE62,
EOP_BASE62D,
+ EOP_BASE64,
+ EOP_BASE64D,
EOP_DOMAIN,
EOP_ESCAPE,
EOP_EVAL,
@@ -6883,12 +6887,27 @@ while (*s != 0)
/* Convert string to base64 encoding */
case EOP_STR2B64:
+ case EOP_BASE64:
{
uschar *encstr = b64encode(sub, Ustrlen(sub));
yield = string_cat(yield, &size, &ptr, encstr, Ustrlen(encstr));
continue;
}
+ case EOP_BASE64D:
+ {
+ uschar *s;
+ int len = b64decode(sub, &s);
+ if (len < 0)
+ {
+ expand_string_message = string_sprintf("string \"%s\" is not "
+ "well-formed for \"%s\" operator", sub, name);
+ goto EXPAND_FAILED;
+ }
+ yield = string_cat(yield, &size, &ptr, s, Ustrlen(s));
+ continue;
+ }
+
/* strlen returns the length of the string */
case EOP_STRLEN:
diff --git a/test/scripts/0000-Basic/0002 b/test/scripts/0000-Basic/0002
index bf2c1068c..105134da3 100644
--- a/test/scripts/0000-Basic/0002
+++ b/test/scripts/0000-Basic/0002
@@ -258,6 +258,10 @@ substr: ${s_1:}
substr: ${substr_10:abc}
str2b64:${str2b64:abcd}
str2b64:${str2b64:The quick brown \n fox}
+base64: ${base64:abcd}
+base64: ${base64:The quick brown \n fox}
+base64d:${base64d:YWJjZA==}
+base64d:${base64d:VGhlIHF1aWNrIGJyb3duIAogZm94}
strlen: ${strlen:}
strlen: ${strlen:a}
strlen: ${strlen:abcdefgh}
diff --git a/test/stdout/0002 b/test/stdout/0002
index 3018dce1f..5293d2587 100644
--- a/test/stdout/0002
+++ b/test/stdout/0002
@@ -231,6 +231,11 @@
> substr:
> str2b64:YWJjZA==
> str2b64:VGhlIHF1aWNrIGJyb3duIAogZm94
+> base64: YWJjZA==
+> base64: VGhlIHF1aWNrIGJyb3duIAogZm94
+> base64d:abcd
+> base64d:The quick brown
+ fox
> strlen: 0
> strlen: 1
> strlen: 8