aboutsummaryrefslogtreecommitdiffstats
path: root/camel
diff options
context:
space:
mode:
authorBertrand Guiheneuf <bertrand@src.gnome.org>1999-05-30 19:40:05 +0800
committerBertrand Guiheneuf <bertrand@src.gnome.org>1999-05-30 19:40:05 +0800
commit1d01c8dad13eeab68241617b0ca981a8582b8215 (patch)
treecbbdff38dc5bdf46f914b51d5849bd440aa45ecc /camel
parenta5cd99a2635e4d199ba06e94c01d628e35573a35 (diff)
downloadgsoc2013-evolution-1d01c8dad13eeab68241617b0ca981a8582b8215.tar
gsoc2013-evolution-1d01c8dad13eeab68241617b0ca981a8582b8215.tar.gz
gsoc2013-evolution-1d01c8dad13eeab68241617b0ca981a8582b8215.tar.bz2
gsoc2013-evolution-1d01c8dad13eeab68241617b0ca981a8582b8215.tar.lz
gsoc2013-evolution-1d01c8dad13eeab68241617b0ca981a8582b8215.tar.xz
gsoc2013-evolution-1d01c8dad13eeab68241617b0ca981a8582b8215.tar.zst
gsoc2013-evolution-1d01c8dad13eeab68241617b0ca981a8582b8215.zip
remove leading and trailing spaces in recipient addresses.
* camel/camel-mime-message.c (_set_recipient_list_from_string): remove leading and trailing spaces in recipient addresses. * camel/gmime-utils.c (_store_header_pair_from_gstring): remove leading and trailing spaces from header values. * camel/gstring-util.c (g_string_trim): new func: remove leading or trailng chars from a specified char set. (g_string_split): allow trimming of substrings. * tests/test1.c (main): remove gtk_main call svn path=/trunk/; revision=958
Diffstat (limited to 'camel')
-rw-r--r--camel/camel-folder.c2
-rw-r--r--camel/camel-mime-message.c2
-rw-r--r--camel/gmime-utils.c7
-rw-r--r--camel/gstring-util.c49
-rw-r--r--camel/gstring-util.h19
5 files changed, 63 insertions, 16 deletions
diff --git a/camel/camel-folder.c b/camel/camel-folder.c
index 26b051c4d7..d7b54075be 100644
--- a/camel/camel-folder.c
+++ b/camel/camel-folder.c
@@ -367,7 +367,7 @@ _create(CamelFolder *folder)
if (folder->parent_folder) camel_folder_create(folder->parent_folder);
else {
if (folder->full_name) {
- dich_result = g_string_dichotomy(folder->full_name, sep, &prefix, NULL, STRIP_TRAILING | RIGHT_DIR);
+ dich_result = g_string_dichotomy(folder->full_name, sep, &prefix, NULL, DICHOTOMY_STRIP_TRAILING | DICHOTOMY_RIGHT_DIR);
if (dich_result!='o') {
g_warning("I have to handle the case where the path is not OK\n");
return FALSE;
diff --git a/camel/camel-mime-message.c b/camel/camel-mime-message.c
index 2a4a9e8897..b0768d1aa7 100644
--- a/camel/camel-mime-message.c
+++ b/camel/camel-mime-message.c
@@ -558,7 +558,7 @@ _set_recipient_list_from_string (CamelMimeMessage *message, GString *recipient_t
{
GList *recipients_list;
CAMEL_LOG (FULL_DEBUG,"CamelMimeMessage::_set_recipient_list_from_string parsing ##%s##\n", recipients_string->str);
- recipients_list = g_string_split (recipients_string, ',');
+ recipients_list = g_string_split (recipients_string, ',', " ", TRIM_STRIP_TRAILING | TRIM_STRIP_LEADING);
g_hash_table_insert (message->recipients, recipient_type, recipients_list);
}
diff --git a/camel/gmime-utils.c b/camel/gmime-utils.c
index 9f489a257a..92d04d5bf8 100644
--- a/camel/gmime-utils.c
+++ b/camel/gmime-utils.c
@@ -99,14 +99,16 @@ _store_header_pair_from_gstring (GHashTable *header_table, GString *header_line)
g_assert (header_table);
if ( (header_line) && (header_line->str) ) {
- dich_result = g_string_dichotomy(header_line, ':', &header_name, &header_value, NONE);
+ dich_result = g_string_dichotomy(header_line, ':', &header_name, &header_value, DICHOTOMY_NONE);
if (dich_result != 'o')
camel_log(WARNING,
"store_header_pair_from_gstring : dichotomy result is %c"
"header line is :\n--\n%s\n--\n");
- else
+ else {
+ g_string_trim (header_value, " \t", TRIM_STRIP_LEADING | TRIM_STRIP_TRAILING);
g_hash_table_insert (header_table, header_name, header_value);
+ }
}
}
@@ -159,7 +161,6 @@ get_header_table_from_file (FILE *file)
if (!end_of_header_line) next_char = fgetc (file);
} while ( !end_of_header_line );
-
if ( strlen(header_line->str) )
_store_header_pair_from_gstring (header_table, header_line);
g_string_free (header_line, FALSE);
diff --git a/camel/gstring-util.c b/camel/gstring-util.c
index 32ecb9b031..b8a92ce10f 100644
--- a/camel/gstring-util.c
+++ b/camel/gstring-util.c
@@ -103,10 +103,10 @@ g_string_dichotomy (GString *string, gchar sep, GString **prefix, GString **suff
}
first = 0;
- if ( (options & STRIP_LEADING ) && (tmp[first] == sep) )
+ if ( (options & DICHOTOMY_STRIP_LEADING ) && (tmp[first] == sep) )
do {first++;} while ( (first<len) && (tmp[first] == sep) );
- if (options & STRIP_TRAILING )
+ if (options & DICHOTOMY_STRIP_TRAILING )
while (tmp[len-1] == sep)
len--;
@@ -117,7 +117,7 @@ g_string_dichotomy (GString *string, gchar sep, GString **prefix, GString **suff
return 'n';
}
- if (options & RIGHT_DIR) {
+ if (options & DICHOTOMY_RIGHT_DIR) {
pos = len;
do {
@@ -253,7 +253,7 @@ g_string_list_free (GList *string_list)
GList *
-g_string_split (GString *string, char sep)
+g_string_split (GString *string, char sep, gchar *trim_chars, TrimOption trim_options)
{
GList *result = NULL;
gint first, last, pos;
@@ -271,11 +271,11 @@ g_string_split (GString *string, char sep)
/* strip leading and trailing separators */
while ( (first<=last) && (str[first]==sep) )
first++;
-
while ( (first<=last) && (str[last]==sep) )
last--;
- CAMEL_LOG(FULL_DEBUG,"g_string_split:: stripping done\n");
+
+ CAMEL_LOG(FULL_DEBUG,"g_string_split:: trim options: %d\n", trim_options);
while (first<=last) {
pos = first;
@@ -285,6 +285,8 @@ g_string_split (GString *string, char sep)
new_str = g_strndup (str+first, pos-first);
new_gstring = g_string_new (new_str);
g_free (new_str);
+ /* could do trimming in line to speed up this code */
+ if (trim_chars) g_string_trim (new_gstring, trim_chars, trim_options);
result = g_list_append (result, new_gstring);
}
first = pos + 1;
@@ -292,3 +294,38 @@ g_string_split (GString *string, char sep)
return result;
}
+
+
+
+
+void
+g_string_trim (GString *string, gchar *chars, TrimOption options)
+{
+ gint first_ok;
+ gint last_ok;
+ guint length;
+ gchar *str;
+
+ CAMEL_LOG(FULL_DEBUG,"**\nentering g_string_trim::\n");
+
+ if ((!string) || (!string->str)) return;
+ str = string->str;
+ length = strlen (str);
+ if (!length) return;
+
+ first_ok = 0;
+ last_ok = length - 1;
+
+ CAMEL_LOG (FULL_DEBUG,"g_string_trim:: trim_options:%d\n", options);
+ if (options & TRIM_STRIP_LEADING)
+ while ( (first_ok <= last_ok) && (strchr (chars, str[first_ok]) != NULL) )
+ first_ok++;
+
+ if (options & TRIM_STRIP_TRAILING)
+ while ( (first_ok <= last_ok) && (strchr (chars, str[last_ok])) )
+ last_ok++;
+ CAMEL_LOG (FULL_DEBUG,"g_string_trim::\n\t\"%s\":first ok:%d last_ok:%d\n", string->str, first_ok, last_ok);
+ if (first_ok>0) g_string_erase (string, 0, first_ok);
+ if (last_ok<length-1) g_string_truncate (string, last_ok - first_ok +1);
+
+}
diff --git a/camel/gstring-util.h b/camel/gstring-util.h
index a29d760cc5..419895831c 100644
--- a/camel/gstring-util.h
+++ b/camel/gstring-util.h
@@ -35,13 +35,20 @@ extern "C" {
#include <glib.h>
typedef enum {
- NONE = 0,
- RIGHT_DIR = 1,
- STRIP_TRAILING = 2,
- STRIP_LEADING = 4,
+ DICHOTOMY_NONE = 0,
+ DICHOTOMY_RIGHT_DIR = 1,
+ DICHOTOMY_STRIP_TRAILING = 2,
+ DICHOTOMY_STRIP_LEADING = 4,
} DichotomyOption;
+typedef enum {
+ TRIM_NONE = 0,
+ TRIM_STRIP_TRAILING = 1,
+ TRIM_STRIP_LEADING = 2,
+
+} TrimOption;
+
gboolean g_string_equals(GString *string1, GString *string2);
GString *g_string_clone(GString *string);
@@ -52,7 +59,9 @@ gboolean g_string_equal_for_hash (gconstpointer v, gconstpointer v2);
gboolean g_string_equal_for_glist (gconstpointer v, gconstpointer v2);
guint g_string_hash (gconstpointer v);
void g_string_list_free (GList *string_list);
-GList *g_string_split (GString *string, char sep);
+
+GList *g_string_split (GString *string, char sep, gchar *trim_chars, TrimOption trim_options);
+void g_string_trim (GString *string, gchar *chars, TrimOption options);
#ifdef __cplusplus
}