aboutsummaryrefslogtreecommitdiffstats
path: root/camel/camel-search-private.c
diff options
context:
space:
mode:
authorNot Zed <NotZed@Ximian.com>2001-08-08 17:37:40 +0800
committerMichael Zucci <zucchi@src.gnome.org>2001-08-08 17:37:40 +0800
commit5dfe756f5f673429b6579600053e35047a2fa3cf (patch)
tree5e8cdf7d51726e26ba2385f390b422aa08e3e35a /camel/camel-search-private.c
parent3f704068b669debd2e5cedc9136d2196771b1e04 (diff)
downloadgsoc2013-evolution-5dfe756f5f673429b6579600053e35047a2fa3cf.tar
gsoc2013-evolution-5dfe756f5f673429b6579600053e35047a2fa3cf.tar.gz
gsoc2013-evolution-5dfe756f5f673429b6579600053e35047a2fa3cf.tar.bz2
gsoc2013-evolution-5dfe756f5f673429b6579600053e35047a2fa3cf.tar.lz
gsoc2013-evolution-5dfe756f5f673429b6579600053e35047a2fa3cf.tar.xz
gsoc2013-evolution-5dfe756f5f673429b6579600053e35047a2fa3cf.tar.zst
gsoc2013-evolution-5dfe756f5f673429b6579600053e35047a2fa3cf.zip
Properly determine match type to pass to header_match.
2001-08-08 Not Zed <NotZed@Ximian.com> * camel-filter-search.c (check_header): Properly determine match type to pass to header_match. (address_matches_exactly): Removed, effectively added to camel_search_header_match. * camel-folder-search.c (check_header): Properly determine the match type to pass to header_match. * camel-search-private.c (camel_search_header_match): Add a new parameter 'type' which is the type of header we're matching against. ASIS means utf8 format, ADDRESS means an internet address ('formatted'), ADDRESS_ENCODED means a raw address header, ENCODED means rfc 2047 encoded text. (header_match): Move original logic here, have search_header_match call it as appropriate for the 'type' of match. 2001-08-07 Not Zed <NotZed@Ximian.com> * camel-session.c (camel_session_class_init): Only init the vee provider struct once (if we're subclassed this will get called multiple times). * camel-object.c (obj_finalize): Removed a bit of a debug that crept in with jacob's poolv patch (?). svn path=/trunk/; revision=11772
Diffstat (limited to 'camel/camel-search-private.c')
-rw-r--r--camel/camel-search-private.c80
1 files changed, 61 insertions, 19 deletions
diff --git a/camel/camel-search-private.c b/camel/camel-search-private.c
index 65e5ede3f0..b769a03e33 100644
--- a/camel/camel-search-private.c
+++ b/camel/camel-search-private.c
@@ -335,23 +335,18 @@ camel_ustrncasecmp (const char *s1, const char *s2, size_t len)
return 0;
}
-
-/* searhces for match inside value, if match is mixed case, hten use case-sensitive,
- else insensitive */
-gboolean
-camel_search_header_match (const char *value, const char *match, camel_search_match_t how)
+/* value is the match value suitable for exact match if required */
+static int
+header_match(const char *value, const char *match, camel_search_match_t how)
{
const char *p;
int vlen, mlen;
- while (*value && isspace (*value))
- value++;
-
if (how == CAMEL_SEARCH_MATCH_SOUNDEX)
return header_soundex (value, match);
- vlen = strlen (value);
- mlen = strlen (match);
+ vlen = strlen(value);
+ mlen = strlen(match);
if (vlen < mlen)
return FALSE;
@@ -359,16 +354,16 @@ camel_search_header_match (const char *value, const char *match, camel_search_ma
otherwise not */
p = match;
while (*p) {
- if (isupper (*p)) {
+ if (isupper(*p)) {
switch (how) {
case CAMEL_SEARCH_MATCH_EXACT:
- return strcmp (value, match) == 0;
+ return strcmp(value, match) == 0;
case CAMEL_SEARCH_MATCH_CONTAINS:
- return strstr (value, match) != NULL;
+ return strstr(value, match) != NULL;
case CAMEL_SEARCH_MATCH_STARTS:
- return strncmp (value, match, mlen) == 0;
+ return strncmp(value, match, mlen) == 0;
case CAMEL_SEARCH_MATCH_ENDS:
- return strcmp (value + vlen - mlen, match) == 0;
+ return strcmp(value + vlen - mlen, match) == 0;
default:
break;
}
@@ -379,13 +374,13 @@ camel_search_header_match (const char *value, const char *match, camel_search_ma
switch (how) {
case CAMEL_SEARCH_MATCH_EXACT:
- return camel_ustrcasecmp (value, match) == 0;
+ return camel_ustrcasecmp(value, match) == 0;
case CAMEL_SEARCH_MATCH_CONTAINS:
- return camel_ustrstrcase (value, match) != NULL;
+ return camel_ustrstrcase(value, match) != NULL;
case CAMEL_SEARCH_MATCH_STARTS:
- return camel_ustrncasecmp (value, match, mlen) == 0;
+ return camel_ustrncasecmp(value, match, mlen) == 0;
case CAMEL_SEARCH_MATCH_ENDS:
- return camel_ustrcasecmp (value + vlen - mlen, match) == 0;
+ return camel_ustrcasecmp(value + vlen - mlen, match) == 0;
default:
break;
}
@@ -393,6 +388,53 @@ camel_search_header_match (const char *value, const char *match, camel_search_ma
return FALSE;
}
+/* searhces for match inside value, if match is mixed case, hten use case-sensitive,
+ else insensitive */
+gboolean
+camel_search_header_match (const char *value, const char *match, camel_search_match_t how, camel_search_t type)
+{
+ const char *name, *addr;
+ int truth = FALSE;
+ CamelInternetAddress *cia;
+ char *v;
+
+ while (*value && isspace (*value))
+ value++;
+
+ switch(type) {
+ case CAMEL_SEARCH_TYPE_ENCODED:
+ v = header_decode_string(value, camel_charset_locale_name());
+ truth = header_match(v, match, how);
+ g_free(v);
+ break;
+ case CAMEL_SEARCH_TYPE_ASIS:
+ truth = header_match(value, match, how);
+ break;
+ case CAMEL_SEARCH_TYPE_ADDRESS_ENCODED:
+ case CAMEL_SEARCH_TYPE_ADDRESS:
+ /* possible simple case to save some work if we can */
+ if (header_match(value, match, how))
+ return TRUE;
+
+ /* Now we decode any addresses, and try asis matches on name and address parts */
+ cia = camel_internet_address_new();
+ if (type == CAMEL_SEARCH_TYPE_ADDRESS_ENCODED)
+ camel_address_decode((CamelAddress *)cia, value);
+ else
+ camel_address_unformat((CamelAddress *)cia, value);
+
+ if (camel_address_length((CamelAddress *)cia) == 1) {
+ camel_internet_address_get(cia, 0, &name, &addr);
+ truth = header_match(name, match, how)
+ || header_match(addr, match, how);
+ }
+ camel_object_unref((CamelObject *)cia);
+ break;
+ }
+
+ return truth;
+}
+
/* performs a 'slow' content-based match */
/* there is also an identical copy of this in camel-filter-search.c */
gboolean