aboutsummaryrefslogtreecommitdiffstats
path: root/camel/camel-mime-utils.c
diff options
context:
space:
mode:
authorJeffrey Stedfast <fejj@ximian.com>2001-06-22 03:53:47 +0800
committerJeffrey Stedfast <fejj@src.gnome.org>2001-06-22 03:53:47 +0800
commit34bc515362401bdb0c747b9d4e524e7c2430a9d1 (patch)
tree2778a3856f32ceceaf2fae57b28431d24ba8755e /camel/camel-mime-utils.c
parentf8db9032d6813046f468718d9d22545a1b519a73 (diff)
downloadgsoc2013-evolution-34bc515362401bdb0c747b9d4e524e7c2430a9d1.tar.gz
gsoc2013-evolution-34bc515362401bdb0c747b9d4e524e7c2430a9d1.tar.zst
gsoc2013-evolution-34bc515362401bdb0c747b9d4e524e7c2430a9d1.zip
New function that decides if 2 word types are mergeable. An atom and a
2001-06-21 Jeffrey Stedfast <fejj@ximian.com> * camel-mime-utils.c (word_types_compatable): New function that decides if 2 word types are mergeable. An atom and a qstring are mergeable; 2 qstrings are mergeable; and 2 encoded words are mergeable. (header_encode_phrase_merge_words): If 2 words are merged, the new word type is the MAX of the combined types. This means that if we merge a qstring and an atom, the resulting word type is a qstring. * camel-internet-address.c (internet_format): s/g_string_sprintfa/g_string_append since this makes more sense in this particular case. (internet_encode): Same here. svn path=/trunk/; revision=10377
Diffstat (limited to 'camel/camel-mime-utils.c')
-rw-r--r--camel/camel-mime-utils.c62
1 files changed, 37 insertions, 25 deletions
diff --git a/camel/camel-mime-utils.c b/camel/camel-mime-utils.c
index d787559710..5f66c08ab4 100644
--- a/camel/camel-mime-utils.c
+++ b/camel/camel-mime-utils.c
@@ -1405,12 +1405,23 @@ struct _phrase_word {
int encoding;
};
-/* split the input into words
- with info about each word
- merge common word types
- clean up
-*/
+static gboolean
+word_types_compatable (enum _phrase_word_t type1, enum _phrase_word_t type2)
+{
+ switch (type1) {
+ case WORD_ATOM:
+ return type2 == WORD_QSTRING;
+ case WORD_QSTRING:
+ return type2 != WORD_2047;
+ case WORD_2047:
+ return type2 == WORD_2047;
+ default:
+ return FALSE;
+ }
+}
+/* split the input into words with info about each word
+ * merge common word types clean up */
static GList *
header_encode_phrase_get_words (const unsigned char *in)
{
@@ -1431,14 +1442,13 @@ header_encode_phrase_get_words (const unsigned char *in)
newinptr = g_utf8_next_char (inptr);
c = g_utf8_get_char (inptr);
-
+
if (!g_unichar_validate (c)) {
w(g_warning ("Invalid UTF-8 sequence encountered (pos %d, char '%c'): %s",
(inptr - in), inptr[0], in));
inptr++;
continue;
}
-
inptr = newinptr;
if (g_unichar_isspace (c)) {
@@ -1494,29 +1504,31 @@ header_encode_phrase_merge_words (GList **wordsp)
wordl = words;
while (wordl) {
word = wordl->data;
- /* leave atoms as atoms (unless they're surrounded by quoted words??) */
- if (word->type != WORD_ATOM) {
- nextl = g_list_next (wordl);
- while (nextl) {
- next = nextl->data;
- /* merge nodes of the same type AND we are not creating too long a string */
- if (word->type == next->type) {
- if (next->end - word->start < CAMEL_FOLD_PREENCODED) {
- word->end = next->end;
- words = g_list_remove_link (words, nextl);
- g_free (next);
- nextl = g_list_next (wordl);
- } else {
- /* if it is going to be too long, make sure we include the
- separating whitespace */
- word->end = next->start;
- break;
- }
+ nextl = g_list_next (wordl);
+
+ while (nextl) {
+ next = nextl->data;
+ /* merge nodes of the same type AND we are not creating too long a string */
+ if (word_types_compatable (word->type, next->type)) {
+ if (next->end - word->start < CAMEL_FOLD_PREENCODED) {
+ /* the resulting word type is the MAX of the 2 types */
+ word->type = MAX(word->type, next->type);
+
+ word->end = next->end;
+ words = g_list_remove_link (words, nextl);
+ g_free (next);
+ nextl = g_list_next (wordl);
} else {
+ /* if it is going to be too long, make sure we include the
+ separating whitespace */
+ word->end = next->start;
break;
}
+ } else {
+ break;
}
}
+
wordl = g_list_next (wordl);
}