aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeffrey Stedfast <fejj@helixcode.com>2000-11-02 05:25:04 +0800
committerJeffrey Stedfast <fejj@src.gnome.org>2000-11-02 05:25:04 +0800
commit7362d3534bcc7a71fdc5d529f255ce9370b743eb (patch)
treed4bbf88970734fd3c5697277b87bb2f937286228
parenta6eeb1e1624c399b56b8e670be9a5c9cefd20745 (diff)
downloadgsoc2013-evolution-7362d3534bcc7a71fdc5d529f255ce9370b743eb.tar
gsoc2013-evolution-7362d3534bcc7a71fdc5d529f255ce9370b743eb.tar.gz
gsoc2013-evolution-7362d3534bcc7a71fdc5d529f255ce9370b743eb.tar.bz2
gsoc2013-evolution-7362d3534bcc7a71fdc5d529f255ce9370b743eb.tar.lz
gsoc2013-evolution-7362d3534bcc7a71fdc5d529f255ce9370b743eb.tar.xz
gsoc2013-evolution-7362d3534bcc7a71fdc5d529f255ce9370b743eb.tar.zst
gsoc2013-evolution-7362d3534bcc7a71fdc5d529f255ce9370b743eb.zip
If the name is NULL or empty, then set the title to "Mail from <address>".
2000-11-01 Jeffrey Stedfast <fejj@helixcode.com> * mail-autofilter.c (rule_from_message): If the name is NULL or empty, then set the title to "Mail from <address>". Closes bugzilla bug #777. Also when filtering on Subject, set the file name to "Subject is <subject>" rather than just "<subject>" - I think this is a bit more user-friendly. (strip_re): Use unsigned char when passing to is<type>() functions from ctype.h. (rule_add_subject): Use the "is" rule instead of "contains". svn path=/trunk/; revision=6321
-rw-r--r--mail/ChangeLog11
-rw-r--r--mail/mail-autofilter.c235
2 files changed, 132 insertions, 114 deletions
diff --git a/mail/ChangeLog b/mail/ChangeLog
index 1dfec8d9a8..073ff671b6 100644
--- a/mail/ChangeLog
+++ b/mail/ChangeLog
@@ -1,3 +1,14 @@
+2000-11-01 Jeffrey Stedfast <fejj@helixcode.com>
+
+ * mail-autofilter.c (rule_from_message): If the name is NULL or
+ empty, then set the title to "Mail from <address>". Closes
+ bugzilla bug #777. Also when filtering on Subject, set the file
+ name to "Subject is <subject>" rather than just "<subject>" - I
+ think this is a bit more user-friendly.
+ (strip_re): Use unsigned char when passing to is<type>()
+ functions from ctype.h.
+ (rule_add_subject): Use the "is" rule instead of "contains".
+
2000-11-01 Jesse Pavel <jpavel@helixcode.com>
* mail-display.c: added property bag support for Bonobo
diff --git a/mail/mail-autofilter.c b/mail/mail-autofilter.c
index fad586274c..30fb6fe1ce 100644
--- a/mail/mail-autofilter.c
+++ b/mail/mail-autofilter.c
@@ -56,59 +56,61 @@
#include "filter/filter-option.h"
static void
-rule_match_recipients(RuleContext *context, FilterRule *rule, CamelInternetAddress *iaddr)
+rule_match_recipients (RuleContext *context, FilterRule *rule, CamelInternetAddress *iaddr)
{
FilterPart *part;
FilterElement *element;
int i;
const char *real, *addr;
char *namestr;
-
+
/* address types etc should handle multiple values */
- for (i=0;camel_internet_address_get(iaddr, i, &real, &addr);i++) {
- part = rule_context_create_part(context, "to");
- filter_rule_add_part((FilterRule *)rule, part);
- element = filter_part_find_element(part, "recipient-type");
- filter_option_set_current((FilterOption *)element, "contains");
- element = filter_part_find_element(part, "recipient");
- filter_input_set_value((FilterInput *)element, addr);
-
- namestr = g_strdup_printf(_("Mail to %s"), real&&real[0]?real:addr);
- filter_rule_set_name(rule, namestr);
- g_free(namestr);
+ for (i = 0; camel_internet_address_get (iaddr, i, &real, &addr); i++) {
+ part = rule_context_create_part (context, "to");
+ filter_rule_add_part ((FilterRule *)rule, part);
+ element = filter_part_find_element (part, "recipient-type");
+ filter_option_set_current ((FilterOption *)element, "contains");
+ element = filter_part_find_element (part, "recipient");
+ filter_input_set_value ((FilterInput *)element, addr);
+
+ namestr = g_strdup_printf (_("Mail to %s"), real && real[0] ? real : addr);
+ filter_rule_set_name (rule, namestr);
+ g_free (namestr);
}
}
/* remove 're' part of a subject */
static const char *
-strip_re(const char *s)
+strip_re (const char *subject)
{
- const char *p;
-
+ const unsigned char *s, *p;
+
+ s = (unsigned char *) subject;
+
while (*s) {
- while (isspace(*s))
+ while (isspace (*s))
s++;
if (s[0] == 0)
break;
- if ((s[0] == 'r' || s[0]=='R')
- && (s[1] == 'e' || s[1]=='E')) {
+ if ((s[0] == 'r' || s[0] == 'R')
+ && (s[1] == 'e' || s[1] == 'E')) {
p = s+2;
- while (isdigit(*p) || (ispunct(*p) && (*p != ':')))
+ while (isdigit (*p) || (ispunct (*p) && (*p != ':')))
p++;
- if (*p==':') {
- s = p+1;
+ if (*p == ':') {
+ s = p + 1;
} else
break;
} else
break;
}
- return s;
+ return (char *) s;
}
#if 0
int
-reg_match(char *str, char *regstr)
+reg_match (char *str, char *regstr)
{
regex_t reg;
int error;
@@ -125,7 +127,7 @@ reg_match(char *str, char *regstr)
#endif
static void
-rule_add_subject(RuleContext *context, FilterRule *rule, const char *text)
+rule_add_subject (RuleContext *context, FilterRule *rule, const char *text)
{
FilterPart *part;
FilterElement *element;
@@ -133,125 +135,130 @@ rule_add_subject(RuleContext *context, FilterRule *rule, const char *text)
/* dont match on empty strings ever */
if (*text == 0)
return;
- part = rule_context_create_part(context, "subject");
- filter_rule_add_part((FilterRule *)rule, part);
- element = filter_part_find_element(part, "subject-type");
- filter_option_set_current((FilterOption *)element, "contains");
- element = filter_part_find_element(part, "subject");
- filter_input_set_value((FilterInput *)element, text);
+ part = rule_context_create_part (context, "subject");
+ filter_rule_add_part ((FilterRule *)rule, part);
+ element = filter_part_find_element (part, "subject-type");
+ filter_option_set_current ((FilterOption *)element, "is");
+ element = filter_part_find_element (part, "subject");
+ filter_input_set_value ((FilterInput *)element, text);
}
static void
-rule_add_sender(RuleContext *context, FilterRule *rule, const char *text)
+rule_add_sender (RuleContext *context, FilterRule *rule, const char *text)
{
FilterPart *part;
FilterElement *element;
-
+
/* dont match on empty strings ever */
if (*text == 0)
return;
- part = rule_context_create_part(context, "sender");
- filter_rule_add_part((FilterRule *)rule, part);
- element = filter_part_find_element(part, "sender-type");
- filter_option_set_current((FilterOption *)element, "contains");
- element = filter_part_find_element(part, "sender");
- filter_input_set_value((FilterInput *)element, text);
+ part = rule_context_create_part (context, "sender");
+ filter_rule_add_part ((FilterRule *)rule, part);
+ element = filter_part_find_element (part, "sender-type");
+ filter_option_set_current ((FilterOption *)element, "contains");
+ element = filter_part_find_element (part, "sender");
+ filter_input_set_value ((FilterInput *)element, text);
}
/* do a bunch of things on the subject to try and detect mailing lists, remove
unneeded stuff, etc */
static void
-rule_match_subject(RuleContext *context, FilterRule *rule, const char *subject)
+rule_match_subject (RuleContext *context, FilterRule *rule, const char *subject)
{
const char *s;
const char *s1, *s2;
char *tmp;
-
- s = strip_re(subject);
+
+ s = strip_re (subject);
/* dont match on empty subject */
if (*s == 0)
return;
-
+
/* [blahblah] is probably a mailing list, match on it separately */
- s1 = strchr(s, '[');
- s2 = strchr(s, ']');
- if (s1 && s2 && s1<s2) {
+ s1 = strchr (s, '[');
+ s2 = strchr (s, ']');
+ if (s1 && s2 && s1 < s2) {
/* probably a mailing list, match on the mailing list name */
- tmp = alloca(s2-s1+2);
- memcpy(tmp, s1, s2-s1+1);
- tmp[s2-s1+1] = 0;
- g_strstrip(tmp);
- rule_add_subject(context, rule, tmp);
- s = s2+1;
+ tmp = alloca (s2 - s1 + 2);
+ memcpy (tmp, s1, s2 - s1 + 1);
+ tmp[s2 - s1 + 1] = 0;
+ g_strstrip (tmp);
+ rule_add_subject (context, rule, tmp);
+ s = s2 + 1;
}
/* Froblah: at the start is probably something important (e.g. bug number) */
- s1 = strchr(s, ':');
+ s1 = strchr (s, ':');
if (s1) {
- tmp = alloca(s1-s+1);
- memcpy(tmp, s, s1-s);
- tmp[s1-s] = 0;
- g_strstrip(tmp);
- rule_add_subject(context, rule, tmp);
+ tmp = alloca (s1 - s + 1);
+ memcpy (tmp, s, s1-s);
+ tmp[s1 - s] = 0;
+ g_strstrip (tmp);
+ rule_add_subject (context, rule, tmp);
s = s1+1;
}
-
+
/* just lump the rest together */
- tmp = alloca(strlen(s)+1);
- strcpy(tmp, s);
- g_strstrip(tmp);
- rule_add_subject(context, rule, tmp);
+ tmp = alloca (strlen (s) + 1);
+ strcpy (tmp, s);
+ g_strstrip (tmp);
+ rule_add_subject (context, rule, tmp);
}
static void
-rule_from_message(FilterRule *rule, RuleContext *context, CamelMimeMessage *msg, int flags)
+rule_from_message (FilterRule *rule, RuleContext *context, CamelMimeMessage *msg, int flags)
{
CamelInternetAddress *addr;
-
+
rule->grouping = FILTER_GROUP_ANY;
-
+
if (flags & AUTO_SUBJECT) {
- rule_match_subject(context, rule, msg->subject);
- filter_rule_set_name(rule, strip_re(msg->subject));
+ char *namestr;
+
+ rule_match_subject (context, rule, msg->subject);
+
+ namestr = g_strdup_printf (_("Subject is %s"), strip_re (msg->subject));
+ filter_rule_set_name (rule, namestr);
+ g_free (namestr);
}
/* should parse the from address into an internet address? */
if (flags & AUTO_FROM) {
struct _header_address *haddr, *scan;
char *name, *namestr;
-
- haddr = header_address_decode(msg->from);
+
+ haddr = header_address_decode (msg->from);
scan = haddr;
while (scan) {
if (scan->type == HEADER_ADDRESS_NAME) {
- rule_add_sender(context, rule, scan->v.addr);
- if (scan->name)
+ rule_add_sender (context, rule, scan->v.addr);
+ if (scan->name && scan->name[0])
name = scan->name;
else
name = scan->v.addr;
- namestr = g_strdup_printf(_("Mail from %s"), name);
- filter_rule_set_name(rule, namestr);
- g_free(namestr);
+ namestr = g_strdup_printf (_("Mail from %s"), name);
+ filter_rule_set_name (rule, namestr);
+ g_free (namestr);
}
scan = scan->next;
}
- header_address_unref(haddr);
+ header_address_unref (haddr);
}
if (flags & AUTO_TO) {
- addr = (CamelInternetAddress *)camel_mime_message_get_recipients(msg, CAMEL_RECIPIENT_TYPE_TO);
- rule_match_recipients(context, rule, addr);
- addr = (CamelInternetAddress *)camel_mime_message_get_recipients(msg, CAMEL_RECIPIENT_TYPE_CC);
- rule_match_recipients(context, rule, addr);
+ addr = (CamelInternetAddress *)camel_mime_message_get_recipients (msg, CAMEL_RECIPIENT_TYPE_TO);
+ rule_match_recipients (context, rule, addr);
+ addr = (CamelInternetAddress *)camel_mime_message_get_recipients (msg, CAMEL_RECIPIENT_TYPE_CC);
+ rule_match_recipients (context, rule, addr);
}
}
FilterRule *
-vfolder_rule_from_message(VfolderContext *context, CamelMimeMessage *msg, int flags, const char *source)
+vfolder_rule_from_message (VfolderContext *context, CamelMimeMessage *msg, int flags, const char *source)
{
VfolderRule *rule;
-
- rule = vfolder_rule_new();
- vfolder_rule_add_source(rule, source);
- rule_from_message((FilterRule *)rule, (RuleContext *)context, msg, flags);
-
+
+ rule = vfolder_rule_new ();
+ vfolder_rule_add_source (rule, source);
+ rule_from_message ((FilterRule *)rule, (RuleContext *)context, msg, flags);
+
return (FilterRule *)rule;
}
@@ -259,12 +266,12 @@ FilterRule *
filter_rule_from_message(FilterContext *context, CamelMimeMessage *msg, int flags)
{
FilterFilter *rule;
-
- rule = filter_filter_new();
- rule_from_message((FilterRule *)rule, (RuleContext *)context, msg, flags);
-
+
+ rule = filter_filter_new ();
+ rule_from_message ((FilterRule *)rule, (RuleContext *)context, msg, flags);
+
/* should we define the default action? */
-
+
return (FilterRule *)rule;
}
@@ -303,39 +310,39 @@ filter_gui_add_for_mailing_list (CamelMimeMessage *msg,
char *userrules, *systemrules;
char *rule_name;
extern char *evolution_dir;
-
+
g_return_if_fail (msg != NULL);
g_return_if_fail (CAMEL_IS_MIME_MESSAGE (msg));
g_return_if_fail (list_name != NULL);
g_return_if_fail (header_name != NULL);
g_return_if_fail (header_value != NULL);
-
- fc = filter_context_new();
- userrules = g_strdup_printf("%s/filters.xml", evolution_dir);
- systemrules = g_strdup_printf("%s/evolution/filtertypes.xml", EVOLUTION_DATADIR);
- rule_context_load((RuleContext *)fc, systemrules, userrules);
-
+
+ fc = filter_context_new ();
+ userrules = g_strdup_printf ("%s/filters.xml", evolution_dir);
+ systemrules = g_strdup_printf ("%s/evolution/filtertypes.xml", EVOLUTION_DATADIR);
+ rule_context_load ((RuleContext *)fc, systemrules, userrules);
+
rule = (FilterRule *) filter_filter_new ();
-
- part = rule_context_create_part((RuleContext *)fc, "header");
- filter_rule_add_part((FilterRule *)rule, part);
-
- element = filter_part_find_element(part, "header-field");
- filter_input_set_value((FilterInput *)element, header_name);
-
- element = filter_part_find_element(part, "header-type");
- filter_option_set_current((FilterOption *)element, "is");
-
- element = filter_part_find_element(part, "word");
- filter_input_set_value((FilterInput *)element, header_value);
-
+
+ part = rule_context_create_part ((RuleContext *)fc, "header");
+ filter_rule_add_part ((FilterRule *)rule, part);
+
+ element = filter_part_find_element (part, "header-field");
+ filter_input_set_value ((FilterInput *)element, header_name);
+
+ element = filter_part_find_element (part, "header-type");
+ filter_option_set_current ((FilterOption *)element, "is");
+
+ element = filter_part_find_element (part, "word");
+ filter_input_set_value ((FilterInput *)element, header_value);
+
rule_name = g_strdup_printf (_("%s mailing list"), list_name);
filter_rule_set_name ((FilterRule *) rule, rule_name);
g_free (rule_name);
-
+
rule_context_add_rule_gui ((RuleContext *)fc, rule, _("Add Filter Rule"), userrules);
-
+
g_free (userrules);
g_free (systemrules);
- gtk_object_unref((GtkObject *)fc);
+ gtk_object_unref (GTK_OBJECT (fc));
}