gchar *temp_word;
const guchar *r;
guint i, nlen, total_len = 0, short_len = 0;
+ gdouble avg_len = 0;
#ifdef WITH_SNOWBALL
static GHashTable *stemmers = NULL;
#endif
if (w->len > 0 && (w->flags & RSPAMD_STAT_TOKEN_FLAG_TEXT)) {
+ avg_len = avg_len + (w->len - avg_len) / (double)i;
+
if (r != NULL) {
nlen = strlen (r);
nlen = MIN (nlen, w->len);
part->non_ascii_chars ++;
}
else {
+ if (g_ascii_isupper (*p)) {
+ part->capital_letters ++;
+ }
+ else if (g_ascii_isdigit (*p)) {
+ part->numeric_characters ++;
+ }
+
part->ascii_chars ++;
}
}
static gdouble
rspamd_chartable_process_word_utf (struct rspamd_task *task,
rspamd_stat_token_t *w,
- gboolean is_url)
+ gboolean is_url,
+ guint *ncap)
{
const gchar *p, *end;
gdouble badness = 0.0;
sc = UBLOCK_BASIC_LATIN;
}
+ if (sc != UBLOCK_BASIC_LATIN && u_isupper (uc)) {
+ if (ncap) {
+ (*ncap) ++;
+ }
+ }
+
if (state == got_digit) {
/* Penalize digit -> alpha translations */
if (!is_url && sc != UBLOCK_BASIC_LATIN &&
struct rspamd_mime_text_part *part)
{
rspamd_stat_token_t *w;
- guint i;
+ guint i, ncap = 0;
gdouble cur_score = 0.0;
if (part == NULL || part->normalized_words == NULL ||
if (w->len > 0 && (w->flags & RSPAMD_STAT_TOKEN_FLAG_TEXT)) {
if (IS_PART_UTF (part)) {
- cur_score += rspamd_chartable_process_word_utf (task, w, FALSE);
+ cur_score += rspamd_chartable_process_word_utf (task, w, FALSE,
+ &ncap);
}
else {
cur_score += rspamd_chartable_process_word_ascii (task, w, FALSE);
}
}
+ /*
+ * TODO: perhaps, we should do this analysis somewhere else and get
+ * something like: <SYM_SC><SYM_SC><SYM_SC> representing classes for all
+ * symbols in the text
+ */
+ part->capital_letters += ncap;
+
cur_score /= (gdouble)part->normalized_words->len;
if (cur_score > 2.0) {
if (words && words->len > 0) {
for (i = 0; i < words->len; i++) {
w = &g_array_index (words, rspamd_stat_token_t, i);
- cur_score += rspamd_chartable_process_word_utf (task, w, FALSE);
+ cur_score += rspamd_chartable_process_word_utf (task, w, FALSE,
+ NULL);
}
cur_score /= (gdouble)words->len;
w.len = u->hostlen;
if (g_utf8_validate (w.begin, w.len, NULL)) {
- cur_score += rspamd_chartable_process_word_utf (task, &w, TRUE);
+ cur_score += rspamd_chartable_process_word_utf (task, &w, TRUE, NULL);
}
else {
cur_score += rspamd_chartable_process_word_ascii (task, &w, TRUE);
w.len = u->hostlen;
if (g_utf8_validate (w.begin, w.len, NULL)) {
- cur_score += rspamd_chartable_process_word_utf (task, &w, TRUE);
+ cur_score += rspamd_chartable_process_word_utf (task, &w, TRUE, NULL);
}
else {
cur_score += rspamd_chartable_process_word_ascii (task, &w, TRUE);