Index: text.c =================================================================== RCS file: /cvs/gnome/pan/pan/text.c,v retrieving revision 1.251.2.5 diff -u -r1.251.2.5 pan/text.c --- pan/text.c 6 May 2002 04:12:11 -0000 1.251.2.5 +++ pan/text.c 17 Oct 2002 15:06:59 -0000 @@ -692,6 +691,36 @@ } } +char *Utf8ToStr(char *in) +{ + int i = 0; + unsigned int n; + char *result = NULL; + + if(in == NULL) + return ""; + result = (char *) malloc(strlen(in) + 1); + + /* convert a string from UTF-8 Format */ + for (n = 0; n < strlen(in); n++) { + unsigned char curchar = in[n]; + + if (curchar < 128) { + result[i++] = (char) curchar; + } + else { + unsigned char c1, c2; + c1 = curchar; + c2 = in[++n]; + c1 = c1<<6; + c2 = c2 & 63; + result[i++] = (char)(c1|c2); + } + } + result[i] = '\0'; + return result; +} + /** * Builds the body string, attachment tables, and the pixmap objects of any * attached images, and places them in the text container widget. @@ -717,6 +746,16 @@ if (current_mm!=NULL) g_mime_message_foreach_part (current_mm, extract_text_cb, body); + /* decode utf-8 (ugly-mode hack) */ + if(article != NULL && body != NULL) { + gchar *headers = article_get_headers (article); + if (pan_stristr (headers, "charset=utf8") + || pan_stristr (headers, "charset=utf-8")) { + g_string_sprintf(body,"%s",Utf8ToStr(body->str)); + } + g_free(headers); + } + /** *** Build the attachments table at the end of the body string **/ @@ -934,6 +973,8 @@ pan_unlock (); } + gui_page_set (MESSAGE_PAGE); + debug_exit ("set_current_article_mainthread"); return 0; } @@ -1055,8 +1096,6 @@ gui_queue_add (set_current_article_mem_mainthread, argset_new2 (article, g_strdup(text))); - gui_page_set (MESSAGE_PAGE); - debug_exit ("text_set_from_mem_article"); } @@ -1068,7 +1107,6 @@ g_return_if_fail (article!=NULL); g_return_if_fail (article_has_body(article)); set_current_article (article); - gui_page_set (MESSAGE_PAGE); debug_exit ("text_set_from_cached_article"); } @@ -1288,6 +1326,17 @@ gboolean is_html = FALSE; gchar * pch = NULL; replace_gstr (&body, g_mime_message_get_body (current_mm, FALSE, &is_html)); + /* decode utf-8 (ugly-mode hack) */ + if(body != NULL) { + gchar *headers = article_get_headers(current_article); + printf("headers=%s\n",headers); + if (pan_stristr (headers, "charset=utf8") + || pan_stristr (headers, "charset=utf-8")) { + body = g_strdup(Utf8ToStr(body)); + printf("body:%s\n",body); + } + g_free(headers); + } if (body != NULL) pch = pan_strstr (body, "\n-- \n"); if (pch != NULL)