local parts = task:get_text_parts()
if parts then
--One text part--
- if table.maxn(parts) > 0 and parts[1]:get_content() then
- local part_text = trim1(parts[1]:get_content())
- local total_part_len = string.len(part_text)
- if total_part_len > 0 then
- local urls = task:get_urls()
- if urls then
- local total_url_len = 0
- for _,url in ipairs(urls) do
- total_url_len = total_url_len + string.len(url:get_text())
- end
- if total_url_len > 0 then
- if total_url_len + 7 > total_part_len then
- task:insert_result('HFILTER_URL_ONLY', 1.00)
- else
- if not string.find(part_text, "\n") then
- task:insert_result('HFILTER_URL_ONELINE', 1.00)
- end
- end
- end
- end
- end
- end
+ total_parts_len = 0
+ for _,p in ipairs(parts) do
+ total_parts_len = total_parts_len + p:get_length()
+ end
+ if total_parts_len > 0 then
+ local urls = task:get_urls()
+ if urls then
+ local total_url_len = 0
+ for _,url in ipairs(urls) do
+ total_url_len = total_url_len + url:get_length()
+ end
+ if total_url_len > 0 then
+ if total_url_len + 7 > total_part_len then
+ task:insert_result('HFILTER_URL_ONLY', 1.00)
+ end
+ end
+ end
+ end
end
return false
"HFILTER_FROMHOST_NORESOLVE_MX", "HFILTER_FROMHOST_NORES_A_OR_MX", "HFILTER_FROMHOST_NOT_FQDN",
"HFILTER_MID_NOT_FQDN",
"HFILTER_HOSTNAME_NOPTR",
-"HFILTER_URL_ONLY", "HFILTER_URL_ONELINE");
+"HFILTER_URL_ONLY");
/* Textpart methods */
LUA_FUNCTION_DEF (textpart, get_content);
+LUA_FUNCTION_DEF (textpart, get_length);
LUA_FUNCTION_DEF (textpart, is_empty);
LUA_FUNCTION_DEF (textpart, is_html);
LUA_FUNCTION_DEF (textpart, get_fuzzy);
static const struct luaL_reg textpartlib_m[] = {
LUA_INTERFACE_DEF (textpart, get_content),
+ LUA_INTERFACE_DEF (textpart, get_length),
LUA_INTERFACE_DEF (textpart, is_empty),
LUA_INTERFACE_DEF (textpart, is_html),
LUA_INTERFACE_DEF (textpart, get_fuzzy),
};
/* URL methods */
+LUA_FUNCTION_DEF (url, get_length);
LUA_FUNCTION_DEF (url, get_host);
LUA_FUNCTION_DEF (url, get_user);
LUA_FUNCTION_DEF (url, get_path);
LUA_FUNCTION_DEF (url, get_phished);
static const struct luaL_reg urllib_m[] = {
+ LUA_INTERFACE_DEF (url, get_length),
LUA_INTERFACE_DEF (url, get_host),
LUA_INTERFACE_DEF (url, get_user),
LUA_INTERFACE_DEF (url, get_path),
return 1;
}
+static gint
+lua_textpart_get_length (lua_State * L)
+{
+ struct mime_text_part *part = lua_check_textpart (L);
+
+ if (part == NULL) {
+ lua_pushnil (L);
+ return 1;
+ }
+
+ if (part->is_empty) {
+ lua_pushnumber (L, 0);
+ }
+ else {
+ lua_pushnumber (L, part->content->len);
+ }
+
+ return 1;
+}
+
static gint
lua_textpart_is_empty (lua_State * L)
{
}
/* URL part */
+static gint
+lua_url_get_length (lua_State *L)
+{
+ struct uri *url = lua_check_url (L);
+
+ if (url != NULL) {
+ lua_pushinteger (L, strlen (struri (url)));
+ }
+ else {
+ lua_pushnil (L);
+ }
+ return 1;
+}
+
static gint
lua_url_get_host (lua_State *L)
{