aboutsummaryrefslogtreecommitdiffstats
path: root/src/libserver/html.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2016-03-11 09:45:37 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2016-03-11 09:45:37 +0000
commitab85e7b66d095e8e1dbf3b535084709be380086c (patch)
treeac8aa18e329858e635c65268e91f4595035e0115 /src/libserver/html.c
parent90610262e1fa9d378db880cd1875e318a66edab7 (diff)
downloadrspamd-ab85e7b66d095e8e1dbf3b535084709be380086c.tar.gz
rspamd-ab85e7b66d095e8e1dbf3b535084709be380086c.zip
[Feature] Load images height and width from style attribute
Issue: #538 Submitted by: @moisseev
Diffstat (limited to 'src/libserver/html.c')
-rw-r--r--src/libserver/html.c50
1 files changed, 50 insertions, 0 deletions
diff --git a/src/libserver/html.c b/src/libserver/html.c
index 628616a77..a910520c5 100644
--- a/src/libserver/html.c
+++ b/src/libserver/html.c
@@ -830,6 +830,9 @@ rspamd_html_parse_tag_component (rspamd_mempool_t *pool,
else if (len == 6 && g_ascii_strncasecmp (begin, "height", len) == 0) {
NEW_COMPONENT (RSPAMD_HTML_COMPONENT_HEIGHT);
}
+ else if (g_ascii_strncasecmp (begin, "style", len) == 0) {
+ NEW_COMPONENT (RSPAMD_HTML_COMPONENT_STYLE);
+ }
}
else if (tag->flags & FL_BLOCK) {
if (len == 5){
@@ -1256,8 +1259,10 @@ rspamd_html_process_img_tag (rspamd_mempool_t *pool, struct html_tag *tag,
struct html_tag_component *comp;
struct html_image *img;
rspamd_ftok_t fstr;
+ const guchar *p;
GList *cur;
gulong val;
+ gboolean seen_width = FALSE, seen_height = FALSE;
cur = tag->params->head;
img = rspamd_mempool_alloc0 (pool, sizeof (*img));
@@ -1283,12 +1288,57 @@ rspamd_html_process_img_tag (rspamd_mempool_t *pool, struct html_tag *tag,
else if (comp->type == RSPAMD_HTML_COMPONENT_HEIGHT) {
rspamd_strtoul (comp->start, comp->len, &val);
img->height = val;
+ seen_height = TRUE;
}
else if (comp->type == RSPAMD_HTML_COMPONENT_WIDTH) {
rspamd_strtoul (comp->start, comp->len, &val);
img->width = val;
+ seen_width = TRUE;
}
+ else if (comp->type == RSPAMD_HTML_COMPONENT_STYLE) {
+ /* Try to search for height= or width= in style tag */
+ if (!seen_height) {
+ p = rspamd_strncasestr (comp->start, "height", comp->len);
+
+ if (p != NULL) {
+ p += sizeof ("height") - 1;
+
+ while (p < comp->start + comp->len) {
+ if (g_ascii_isdigit (*p)) {
+ rspamd_strtoul (p, comp->len - (p - comp->start), &val);
+ img->height = val;
+ break;
+ }
+ else if (!g_ascii_isspace (*p) && *p != '=' && *p != ':') {
+ /* Fallback */
+ break;
+ }
+ p ++;
+ }
+ }
+ }
+
+ if (!seen_width) {
+ p = rspamd_strncasestr (comp->start, "width", comp->len);
+ if (p != NULL) {
+ p += sizeof ("width") - 1;
+
+ while (p < comp->start + comp->len) {
+ if (g_ascii_isdigit (*p)) {
+ rspamd_strtoul (p, comp->len - (p - comp->start), &val);
+ img->width = val;
+ break;
+ }
+ else if (!g_ascii_isspace (*p) && *p != '=' && *p != ':') {
+ /* Fallback */
+ break;
+ }
+ p ++;
+ }
+ }
+ }
+ }
cur = g_list_next (cur);
}