Hi! Am 27.04.08 19:27 schrieb(en) Ali49969:
I saw youe example page. this was true in "Firefox 2.0.0.12" and "Internet Explorer 7.0" Please note that Mmany of Iranian users, uses "Internet Explorer 6.0" and "Windows XP Pro" operating system.
Could you try the attached patch with the current svn, send a message with Persian (or other rtl) text, and check if it displays properly in the web mailer and the other mail apps you use?
The patch replaces the current text/plain with a text/html and (hopefully) includes the proper rtl and ltr tags. It does *not* yet encode highlighting and hyperlinks, and it does *not* create the multipart/alternative as indicated yesterday. This is simply a _very_ dumb check whether it is possible to compose a "proper" message in html, so the "real" code would be some further effort. I unfortunately cannot test it here, so if you can confirm that this way Balsa would work for the Persian community (and probably the Arab and Hebrew, too), it would /really/ be helpful!
Thanks, Albrecht.
Index: src/sendmsg-window.c =================================================================== --- src/sendmsg-window.c (Revision 7918) +++ src/sendmsg-window.c (Arbeitskopie) @@ -2453,7 +2453,6 @@ /* remove leading and trailing whitespaces */ uri = g_strchomp(g_strchug(g_strdup(instr))); - /* check that the string starts with ftp[s]:// or http[s]:// */ if (g_ascii_strncasecmp(uri, "ftp://", 6) && g_ascii_strncasecmp(uri, "ftps://", 7) && @@ -5465,6 +5464,87 @@ return charset; } +static void +body_to_html(LibBalsaMessageBody *body, const gchar * lang) +{ + GString * html_body = + g_string_new("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">\n"); + gchar * start = body->buffer; + gchar * html_lang; + gchar * p; + + /* set the html header, including the primary language */ + if (lang) { + html_lang = g_strdup(lang); + if ((p = strchr(html_lang, '_'))) + *p = '-'; + } else + html_lang = g_strdup("x-unknown"); + g_string_append_printf(html_body, + "<html lang=\"%s\"><head>\n" + "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=\"utf-8\">\n" + "</head>\n" + "<body>\n", html_lang); + g_free(html_lang); + + /* add the lines of the message body */ + while (*start) { + gchar * eol = strchr(start, '\n'); + gchar * p = start; + PangoDirection direction = PANGO_DIRECTION_NEUTRAL; + GString * html; + gsize idx; + + if (!eol) + eol = start + strlen(start); + + /* find the first real char to determine the paragraph direction */ + while (p < eol && direction == PANGO_DIRECTION_NEUTRAL) { + direction = pango_unichar_direction(g_utf8_get_char(p)); + p = g_utf8_next_char(p); + } + + /* html escape the line */ + html = g_string_new(g_markup_escape_text(start, eol - start)); + + /* TODO - replace highlighting by tags */ + /* TODO - encode hyperlinks */ + + /* replace a series of n spaces by (n - 1) and one space */ + idx = 0; + while (idx < html->len) { + if (html->str[idx] == ' ' && (idx == 0 || html->str[idx + 1] == ' ')) { + html->str[idx++] = '&'; + html = g_string_insert(html, idx, "nbsp;"); + idx += 5; + } else + idx = g_utf8_next_char(html->str + idx) - html->str; + } + + /* append the paragraph, always stating the proper direction */ + g_string_append_printf(html_body, "<p dir=\"%s\">%s</p>\n", + direction == PANGO_DIRECTION_RTL ? "rtl" : "ltr", + html->str); + g_string_free(html, TRUE); + + /* next line */ + start = eol; + if (*start) + start++; + } + + /* close the html context */ + html_body = g_string_append(html_body, "</body></html>\n"); + + /* replace the body by a utf-8 encoded text/html */ + g_free(body->buffer); + body->buffer = g_string_free(html_body, FALSE); + g_free(body->charset); + body->charset = g_strdup("UTF-8"); + g_free(body->content_type); + body->content_type = g_strdup("text/html"); +} + static LibBalsaMessage * bsmsg2message(BalsaSendmsg * bsmsg) { @@ -5549,16 +5629,19 @@ gtk_text_buffer_get_bounds(bsmsg->buffer2, &start, &end); body->buffer = gtk_text_iter_get_text(&start, &end); #endif /* HAVE_GTKSOURCEVIEW */ +#if 0 if (bsmsg->flow) body->buffer = libbalsa_wrap_rfc2646(body->buffer, balsa_app.wraplength, TRUE, FALSE, TRUE); +#endif #if !HAVE_GTKSOURCEVIEW /* Disable undo and redo, because buffer2 was changed. */ sw_buffer_set_undo(bsmsg, FALSE, FALSE); #endif /* HAVE_GTKSOURCEVIEW */ body->charset = g_strdup(sw_required_charset(bsmsg, body->buffer)); + body_to_html(body, bsmsg->spell_check_lang); libbalsa_message_append_part(message, body); /* add attachments */
Attachment:
pgp5umB4dcdsL.pgp
Description: PGP signature