return tbl_size;
}
+
+gboolean
+lua_push_internet_address (lua_State *L, InternetAddress *ia)
+{
+ const char *addr, *at;
+
+#ifndef GMIME24
+ if (internet_address_get_type (ia) == INTERNET_ADDRESS_NAME) {
+ lua_newtable (L);
+ addr = internet_address_get_addr (ia);
+ rspamd_lua_table_set (L, "name", internet_address_get_name (ia));
+ rspamd_lua_table_set (L, "addr", addr);
+
+ if (addr) {
+ at = strchr (addr, '@');
+ if (at != NULL) {
+ lua_pushstring(L, "user");
+ lua_pushlstring(L, addr, at - addr);
+ lua_settable (L, -3);
+ lua_pushstring (L, "domain");
+ lua_pushstring (L, at + 1);
+ lua_settable (L, -3);
+ }
+ }
+
+ return TRUE;
+ }
+ return FALSE;
+#else
+ InternetAddressMailbox *iamb;
+
+ if (ia && INTERNET_ADDRESS_IS_MAILBOX (ia)) {
+ lua_newtable (L);
+ iamb = INTERNET_ADDRESS_MAILBOX (ia);
+ addr = internet_address_mailbox_get_addr (iamb);
+
+ if (addr) {
+ rspamd_lua_table_set (L, "name", internet_address_get_name (ia));
+ rspamd_lua_table_set (L, "addr", addr);
+ /* Set optional fields */
+
+ at = strchr (addr, '@');
+ if (at != NULL) {
+ lua_pushstring(L, "user");
+ lua_pushlstring(L, addr, at - addr);
+ lua_settable (L, -3);
+ lua_pushstring (L, "domain");
+ lua_pushstring (L, at + 1);
+ lua_settable (L, -3);
+ }
+ return TRUE;
+ }
+ }
+
+ return FALSE;
+#endif
+}
+
+/*
+ * Push internet addresses to lua as a table
+ */
+void
+lua_push_internet_address_list (lua_State *L, InternetAddressList *addrs)
+{
+ InternetAddress *ia;
+ gint idx = 1;
+
+#ifndef GMIME24
+ /* Gmime 2.2 version */
+ InternetAddressList *cur;
+
+ lua_newtable (L);
+ cur = addrs;
+ while (cur) {
+ ia = internet_address_list_get_address (cur);
+ if (lua_push_internet_address (L, ia)) {
+ lua_rawseti (L, -2, idx++);
+ }
+ cur = internet_address_list_next (cur);
+ }
+#else
+ /* Gmime 2.4 version */
+ gsize len, i;
+
+ lua_newtable (L);
+ if (addrs != NULL) {
+ len = internet_address_list_length (addrs);
+ for (i = 0; i < len; i++) {
+ ia = internet_address_list_get_address (addrs, i);
+ if (lua_push_internet_address (L, ia)) {
+ lua_rawseti (L, -2, idx++);
+ }
+ }
+ }
+#endif
+}
* Returns size of table at position `tbl_pos`
*/
guint rspamd_lua_table_size (lua_State *L, gint tbl_pos);
+
+/**
+ * Pushes a single InternetAddress as lua table
+ * @param L
+ * @param addrs
+ */
+void lua_push_internet_address_list (lua_State *L, InternetAddressList *addrs);
+
+/**
+ * Pushes internet address list to Lua as table of tables
+ * @param L
+ * @param ia
+ * @return
+ */
+gboolean lua_push_internet_address (lua_State *L, InternetAddress *ia);
#endif /* WITH_LUA */
#endif /* RSPAMD_LUA_H */
return 0;
}
-static gboolean
-lua_push_internet_address (lua_State *L, InternetAddress *ia)
-{
-#ifndef GMIME24
- if (internet_address_get_type (ia) == INTERNET_ADDRESS_NAME) {
- lua_newtable (L);
- rspamd_lua_table_set (L, "name", internet_address_get_name (ia));
- rspamd_lua_table_set (L, "addr", internet_address_get_addr (ia));
- return TRUE;
- }
- return FALSE;
-#else
- InternetAddressMailbox *iamb;
- const char *addr, *at;
- if (ia && INTERNET_ADDRESS_IS_MAILBOX (ia)) {
- lua_newtable (L);
- iamb = INTERNET_ADDRESS_MAILBOX (ia);
- addr = internet_address_mailbox_get_addr (iamb);
- if (addr) {
- rspamd_lua_table_set (L, "name", internet_address_get_name (ia));
- rspamd_lua_table_set (L, "addr", addr);
- /* Set optional fields */
-
- at = strchr (addr, '@');
- if (at != NULL) {
- lua_pushstring(L, "user");
- lua_pushlstring(L, addr, at - addr);
- lua_settable (L, -3);
- lua_pushstring(L, "domain");
- lua_pushstring(L, at + 1);
- lua_settable (L, -3);
- }
- return TRUE;
- }
- }
-
- return FALSE;
-#endif
-}
-
-/*
- * Push internet addresses to lua as a table
- */
-static void
-lua_push_internet_address_list (lua_State *L, InternetAddressList *addrs)
-{
- InternetAddress *ia;
- gint idx = 1;
-
-#ifndef GMIME24
- /* Gmime 2.2 version */
- InternetAddressList *cur;
-
- lua_newtable (L);
- cur = addrs;
- while (cur) {
- ia = internet_address_list_get_address (cur);
- if (lua_push_internet_address (L, ia)) {
- lua_rawseti (L, -2, idx++);
- }
- cur = internet_address_list_next (cur);
- }
-#else
- /* Gmime 2.4 version */
- gsize len, i;
-
- lua_newtable (L);
- if (addrs != NULL) {
- len = internet_address_list_length (addrs);
- for (i = 0; i < len; i++) {
- ia = internet_address_list_get_address (addrs, i);
- if (lua_push_internet_address (L, ia)) {
- lua_rawseti (L, -2, idx++);
- }
- }
- }
-#endif
-}
-
/*
* Convert element at the specified position to the type
* for get_from/get_recipients