]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Feature] extend lua api 3344/head
authorJan Smutny <js@excello.cz>
Sun, 19 Apr 2020 21:32:30 +0000 (23:32 +0200)
committerJan Smutny <js@excello.cz>
Mon, 20 Apr 2020 20:57:05 +0000 (22:57 +0200)
add new value accessible by key 'raw' to the table returned by util:parse_mail_address and task:get_from

src/lua/lua_task.c
src/lua/lua_util.c

index b891d7d99a1ed65203ca1eea6e6d208869e9f0eb..8bd7077c8613d87423e59edb3bac1b866fdb777f 100644 (file)
@@ -515,6 +515,7 @@ LUA_FUNCTION_DEF (task, has_from);
  * @method task:get_from([type])
  * Return SMTP or MIME sender for a task. This function returns an internet address which one is a table with the following structure:
  *
+ * - `raw` - the original value without any processing
  * - `name` - name of internet address in UTF8, e.g. for `Vsevolod Stakhov <blah@foo.com>` it returns `Vsevolod Stakhov`
  * - `addr` - address part of the address
  * - `user` - user part (if present) of the address, e.g. `blah`
@@ -3310,8 +3311,18 @@ static void
 lua_push_email_address (lua_State *L, struct rspamd_email_address *addr)
 {
        if (addr) {
-               lua_createtable (L, 0, 4);
+               lua_createtable (L, 0, 5);
 
+               if (addr->raw_len > 0) {
+                       lua_pushstring (L, "raw");
+                       lua_pushlstring (L, addr->raw, addr->raw_len);
+                       lua_settable (L, -3);
+               }
+               else {
+                       lua_pushstring (L, "raw");
+                       lua_pushstring (L, "");
+                       lua_settable (L, -3);
+               }
                if (addr->addr_len > 0) {
                        lua_pushstring (L, "addr");
                        lua_pushlstring (L, addr->addr, addr->addr_len);
index 7f9918c6159936c583d8ff128177d7bb1ca13b75..5948f4b4b8a6bf1f83f1c883c2dbd0262ecae500 100644 (file)
@@ -204,6 +204,7 @@ LUA_FUNCTION_DEF (util, glob);
  * @function util.parse_mail_address(str, [pool])
  * Parses email address and returns a table of tables in the following format:
  *
+ * - `raw` - the original value without any processing
  * - `name` - name of internet address in UTF8, e.g. for `Vsevolod Stakhov <blah@foo.com>` it returns `Vsevolod Stakhov`
  * - `addr` - address part of the address
  * - `user` - user part (if present) of the address, e.g. `blah`