Bug #722951 - Check for empty rule values

This commit is contained in:
Milan Crha
2014-01-28 17:26:14 +01:00
parent 64b2c69bd6
commit 6c0dfdc7c0
7 changed files with 101 additions and 50 deletions

View File

@ -106,6 +106,28 @@ filter_input_validate (EFilterElement *element,
}
regfree (&regexpat);
} else if (!input->allow_empty && (!input->values || !input->values->next)) {
const gchar *value = input->values->data;
gboolean is_empty = value == NULL;
if (value) {
gint ii;
is_empty = TRUE;
for (ii = 0; value[ii]; ii++) {
if (!g_ascii_isspace (value[ii])) {
is_empty = FALSE;
break;
}
}
}
if (is_empty) {
valid = FALSE;
if (alert)
*alert = e_alert_new ("filter:not-allow-empty", NULL);
}
}
return valid;
@ -142,7 +164,23 @@ filter_input_eq (EFilterElement *element_a,
if (link_a != NULL || link_b != NULL)
return FALSE;
return TRUE;
return input_a->allow_empty == input_b->allow_empty;
}
static void
filter_input_xml_create (EFilterElement *element,
xmlNodePtr node)
{
EFilterInput *input = E_FILTER_INPUT (element);
gchar *allow_empty;
/* Chain up to parent's method. */
E_FILTER_ELEMENT_CLASS (e_filter_input_parent_class)->xml_create (element, node);
allow_empty = (gchar *) xmlGetProp (node, (xmlChar *) "allow-empty");
input->allow_empty = !allow_empty || g_strcmp0 (allow_empty, "true") == 0;
xmlFree (allow_empty);
}
static xmlNodePtr
@ -158,6 +196,7 @@ filter_input_xml_encode (EFilterElement *element)
value = xmlNewNode (NULL, (xmlChar *) "value");
xmlSetProp (value, (xmlChar *) "name", (xmlChar *) element->name);
xmlSetProp (value, (xmlChar *) "type", (xmlChar *) type);
xmlSetProp (value, (xmlChar *) "allow-empty", (xmlChar *) (input->allow_empty ? "true" : "false"));
for (link = input->values; link != NULL; link = g_list_next (link)) {
xmlChar *str = link->data;
@ -178,7 +217,7 @@ filter_input_xml_decode (EFilterElement *element,
xmlNodePtr node)
{
EFilterInput *input = (EFilterInput *) element;
gchar *name, *str, *type;
gchar *name, *str, *type, *allow_empty;
xmlNodePtr child;
g_list_foreach (input->values, (GFunc) g_free, NULL);
@ -187,6 +226,7 @@ filter_input_xml_decode (EFilterElement *element,
name = (gchar *) xmlGetProp (node, (xmlChar *) "name");
type = (gchar *) xmlGetProp (node, (xmlChar *) "type");
allow_empty = (gchar *) xmlGetProp (node, (xmlChar *) "allow-empty");
xmlFree (element->name);
element->name = name;
@ -194,6 +234,9 @@ filter_input_xml_decode (EFilterElement *element,
xmlFree (input->type);
input->type = type;
input->allow_empty = !allow_empty || g_strcmp0 (allow_empty, "true") == 0;
xmlFree (allow_empty);
child = node->children;
while (child != NULL) {
if (!strcmp ((gchar *) child->name, type)) {
@ -254,6 +297,7 @@ e_filter_input_class_init (EFilterInputClass *class)
filter_element_class = E_FILTER_ELEMENT_CLASS (class);
filter_element_class->validate = filter_input_validate;
filter_element_class->eq = filter_input_eq;
filter_element_class->xml_create = filter_input_xml_create;
filter_element_class->xml_encode = filter_input_xml_encode;
filter_element_class->xml_decode = filter_input_xml_decode;
filter_element_class->get_widget = filter_input_get_widget;
@ -264,6 +308,7 @@ static void
e_filter_input_init (EFilterInput *input)
{
input->values = g_list_prepend (NULL, g_strdup (""));
input->allow_empty = TRUE;
}
/**

View File

@ -60,6 +60,7 @@ struct _EFilterInput {
gchar *type; /* name of type */
GList *values; /* strings */
gboolean allow_empty; /* whether can have empty value */
};
struct _EFilterInputClass {

View File

@ -400,7 +400,7 @@ filter_rule_validate (EFilterRule *rule,
parts = parts->next;
}
if (!valid && !parts && alert)
if (!valid && !rule->parts && alert)
*alert = e_alert_new ("filter:no-condition", NULL);
return valid;

View File

@ -36,4 +36,9 @@
<_secondary>Filter should have at least one condition.</_secondary>
</error>
<error id="not-allow-empty" type="error">
<_primary>Missing value.</_primary>
<_secondary>One or more values cannot be empty.</_secondary>
</error>
</error-list>

View File

@ -8,49 +8,28 @@ gchar *s = N_("BCC");
gchar *s = N_("Beep");
gchar *s = N_("CC");
gchar *s = N_("Completed On");
gchar *s = N_("contains");
gchar *s = N_("Copy to Folder");
gchar *s = N_("Date received");
gchar *s = N_("Date sent");
gchar *s = N_("Delete");
gchar *s = N_("Deleted");
gchar *s = N_("does not contain");
gchar *s = N_("does not end with");
gchar *s = N_("does not exist");
gchar *s = N_("does not have words");
gchar *s = N_("does not return");
gchar *s = N_("does not sound like");
gchar *s = N_("does not start with");
gchar *s = N_("Do Not Exist");
gchar *s = N_("Draft");
gchar *s = N_("ends with");
gchar *s = N_("Exist");
gchar *s = N_("exists");
gchar *s = N_("Expression");
gchar *s = N_("Follow Up");
gchar *s = N_("Forward to");
gchar *s = N_("has words");
gchar *s = N_("Important");
gchar *s = N_("is");
gchar *s = N_("is after");
gchar *s = N_("is before");
gchar *s = N_("is Flagged");
gchar *s = N_("is greater than");
gchar *s = N_("is less than");
gchar *s = N_("is not");
gchar *s = N_("is not Flagged");
gchar *s = N_("is not set");
gchar *s = N_("is set");
gchar *s = N_("Junk");
gchar *s = N_("Junk Test");
gchar *s = N_("Junk");
gchar *s = N_("Label");
gchar *s = N_("Mailing list");
gchar *s = N_("Match All");
gchar *s = N_("Message Body");
gchar *s = N_("Message Header");
gchar *s = N_("Message Location");
gchar *s = N_("Message is Junk");
gchar *s = N_("Message is not Junk");
gchar *s = N_("Message Location");
gchar *s = N_("Move to Folder");
gchar *s = N_("Pipe to Program");
gchar *s = N_("Play Sound");
@ -58,23 +37,44 @@ gchar *s = N_("Read");
gchar *s = N_("Recipients");
gchar *s = N_("Regex Match");
gchar *s = N_("Replied to");
gchar *s = N_("returns");
gchar *s = N_("returns greater than");
gchar *s = N_("returns less than");
gchar *s = N_("Run Program");
gchar *s = N_("Score");
gchar *s = N_("Sender");
gchar *s = N_("Sender or Recipients");
gchar *s = N_("Sender");
gchar *s = N_("Set Label");
gchar *s = N_("Set Status");
gchar *s = N_("Size (kB)");
gchar *s = N_("sounds like");
gchar *s = N_("Source Account");
gchar *s = N_("Specific header");
gchar *s = N_("starts with");
gchar *s = N_("Status");
gchar *s = N_("Stop Processing");
gchar *s = N_("Subject");
gchar *s = N_("To");
gchar *s = N_("Unset Color");
gchar *s = N_("Unset Status");
gchar *s = N_("contains");
gchar *s = N_("does not contain");
gchar *s = N_("does not end with");
gchar *s = N_("does not exist");
gchar *s = N_("does not have words");
gchar *s = N_("does not return");
gchar *s = N_("does not sound like");
gchar *s = N_("does not start with");
gchar *s = N_("ends with");
gchar *s = N_("exists");
gchar *s = N_("has words");
gchar *s = N_("is Flagged");
gchar *s = N_("is after");
gchar *s = N_("is before");
gchar *s = N_("is greater than");
gchar *s = N_("is less than");
gchar *s = N_("is not Flagged");
gchar *s = N_("is not set");
gchar *s = N_("is not");
gchar *s = N_("is set");
gchar *s = N_("is");
gchar *s = N_("returns greater than");
gchar *s = N_("returns less than");
gchar *s = N_("returns");
gchar *s = N_("sounds like");
gchar *s = N_("starts with");

View File

@ -65,7 +65,7 @@
</code>
</option>
</input>
<input type="string" name="sender"/>
<input type="string" name="sender" allow-empty="false"/>
</part>
<part name="to">
@ -147,7 +147,7 @@
</code>
</option>
</input>
<input type="address" name="recipient"/>
<input type="address" name="recipient" allow-empty="false"/>
</part>
<part name="cc">
@ -214,7 +214,7 @@
</code>
</option>
</input>
<input type="address" name="recipient"/>
<input type="address" name="recipient" allow-empty="false"/>
</part>
<part name="bcc">
@ -281,7 +281,7 @@
</code>
</option>
</input>
<input type="address" name="recipient"/>
<input type="address" name="recipient" allow-empty="false"/>
</part>
<part name="senderto">
@ -383,7 +383,7 @@
</code>
</option>
</input>
<input type="address" name="recipient"/>
<input type="address" name="recipient" allow-empty="false"/>
</part>
<part name="subject">
@ -467,7 +467,7 @@
<part name="header">
<title>Specific header</title>
<input type="string" name="header-field"/>
<input type="string" name="header-field" allow-empty="false"/>
<input type="optionlist" name="header-type">
<option value="contains">
<title>contains</title>
@ -573,7 +573,7 @@
</code>
</option>
</input>
<input type="string" name="word"/>
<input type="string" name="word" allow-empty="false"/>
</part>
<part name="sexp">
@ -819,7 +819,7 @@
<code>(match-all (not (header-contains "x-camel-mlist" ${mlist})))</code>
</option>
</input>
<input type="string" name="mlist"/>
<input type="string" name="mlist" allow-empty="false"/>
</part>
<part name="regex">
@ -1040,7 +1040,7 @@
<part name="forward">
<title>Forward to</title>
<code>(forward-to ${address})</code>
<input type="address" name="address"/>
<input type="address" name="address" allow-empty="false"/>
</part>
</actionset>
</filterdescription>

View File

@ -45,7 +45,7 @@
</code>
</option>
</input>
<input type="string" name="sender"/>
<input type="string" name="sender" allow-empty="false"/>
</part>
<part name="to">
@ -112,7 +112,7 @@
</code>
</option>
</input>
<input type="address" name="recipient"/>
<input type="address" name="recipient" allow-empty="false"/>
</part>
<part name="toonly">
@ -179,7 +179,7 @@
</code>
</option>
</input>
<input type="address" name="recipient"/>
<input type="address" name="recipient" allow-empty="false"/>
</part>
<part name="cc">
@ -246,7 +246,7 @@
</code>
</option>
</input>
<input type="address" name="recipient"/>
<input type="address" name="recipient" allow-empty="false"/>
</part>
<part name="bcc">
@ -313,7 +313,7 @@
</code>
</option>
</input>
<input type="address" name="recipient"/>
<input type="address" name="recipient" allow-empty="false"/>
</part>
<part name="senderto">
@ -388,7 +388,7 @@
</code>
</option>
</input>
<input type="address" name="recipient"/>
<input type="address" name="recipient" allow-empty="false"/>
</part>
<part name="subject">
@ -460,7 +460,7 @@
<part name="header">
<title>Specific header</title>
<input type="string" name="header-field"/>
<input type="string" name="header-field" allow-empty="false"/>
<input type="optionlist" name="header-type">
<option value="contains">
<title>contains</title>
@ -645,7 +645,7 @@
</code>
</option>
</input>
<input type="string" name="word"/>
<input type="string" name="word" allow-empty="false"/>
</part>
<part name="sexp">
<title>Expression</title>
@ -893,7 +893,7 @@
<code>(match-all (not (header-contains "x-camel-mlist" ${mlist})))</code>
</option>
</input>
<input type="string" name="mlist"/>
<input type="string" name="mlist" allow-empty="false"/>
</part>
<part name="regex">