aboutsummaryrefslogtreecommitdiffstats
path: root/mail
diff options
context:
space:
mode:
authorDan Winship <danw@src.gnome.org>2000-04-26 08:36:31 +0800
committerDan Winship <danw@src.gnome.org>2000-04-26 08:36:31 +0800
commit23bcb0bbd8fefb952d751951b2bf3b19717e707d (patch)
tree8b27b8ce358c72809b301fbf7c61a7b83dae581a /mail
parentfba8692c75c362bc4fa2c0f872cfdf4fb80b1e5c (diff)
downloadgsoc2013-evolution-23bcb0bbd8fefb952d751951b2bf3b19717e707d.tar.gz
gsoc2013-evolution-23bcb0bbd8fefb952d751951b2bf3b19717e707d.tar.zst
gsoc2013-evolution-23bcb0bbd8fefb952d751951b2bf3b19717e707d.zip
add a convert_space_hack flag, which turns N spaces into N-1 &nbsp;s and a
* mail-format.c (text_to_html): add a convert_space_hack flag, which turns N spaces into N-1 &nbsp;s and a space. (handle_text_plain): Check for "format=flowed" in the Content-Type. (handle_text_plain_flowed): Spinoff of handle_text_plain to deal with RFC 2646 flowed text. (All the examples I can find of it are generated by Eudora, but it's a pretty cool idea that ought to be used more widely.) svn path=/trunk/; revision=2618
Diffstat (limited to 'mail')
-rw-r--r--mail/ChangeLog55
-rw-r--r--mail/mail-format.c111
2 files changed, 138 insertions, 28 deletions
diff --git a/mail/ChangeLog b/mail/ChangeLog
index 0edb047b14..f9b746de5e 100644
--- a/mail/ChangeLog
+++ b/mail/ChangeLog
@@ -1,17 +1,18 @@
2000-04-25 Dan Winship <danw@helixcode.com>
- * mail-format.c, mail-display.c: Now that we're not limited to
- a single GtkHTML for the display, there's no reason to embed
- Bonobo objects for unrecognized content-types in GtkHTML rather
- than embedded them into the vbox directly. So do that.
+ * mail-display.c, mail-format.c: Redo large chunks of this. The
+ mail display now consists of a vbox in a scrolled window, in which
+ we put multiple GtkHTML objects. This means broken HTML in one
+ part can't corrupt other parts. The headers now scroll with the
+ body. Unrecognized attachments look prettier, but still don't do
+ anything, and will probably be changed later. We can also now
+ display nested message/rfc822 parts and multipart/alternatives
+ with multipart subparts. Oh, and text/{richtext,enriched}, since
+ we had all these ancient sample messages that use it and the lack
+ of support annoyed me. :)
- Meanwhile, fix up the handler-selection code so that we can
- declare which built-in handlers are more desirable than external
- handlers and which are less. (Of course, eventually we'll want
- this to be customizable.) Add some cleverness to
- handle_multipart_alternative as well so it doesn't accept an
- alternative which we can display generically over one we can
- display specifically.
+ Bonobo embeddables are broken right now, but I don't think that's
+ my fault.
* mail-format.c (reply_body): Fix some bugs that crept into reply
generation. This needs a lot more work to deal correctly with
@@ -25,19 +26,27 @@
usually.
(reply_body): Make this deal better with multiparts.
- * mail-display.c, mail-format.c: Redo large chunks of this. The
- mail display now consists of a vbox in a scrolled window, in which
- we put multiple GtkHTML objects. This means broken HTML in one
- part can't corrupt other parts. The headers now scroll with the
- body. Unrecognized attachments look prettier, but still don't do
- anything, and will probably be changed later. We can also now
- display nested message/rfc822 parts and multipart/alternatives
- with multipart subparts. Oh, and text/{richtext,enriched}, since
- we had all these ancient sample messages that use it and the lack
- of support annoyed me. :)
+ * mail-format.c, mail-display.c: Now that we're not limited to
+ a single GtkHTML for the display, there's no reason to embed
+ Bonobo objects for unrecognized content-types in GtkHTML rather
+ than embedded them into the vbox directly. So do that.
- Bonobo embeddables are broken right now, but I don't think that's
- my fault.
+ Meanwhile, fix up the handler-selection code so that we can
+ declare which built-in handlers are more desirable than external
+ handlers and which are less. (Of course, eventually we'll want
+ this to be customizable.) Add some cleverness to
+ handle_multipart_alternative as well so it doesn't accept an
+ alternative which we can display generically over one we can
+ display specifically.
+
+ * mail-format.c (text_to_html): add a convert_space_hack flag,
+ which turns N spaces into N-1 &nbsp;s and a space.
+ (handle_text_plain): Check for "format=flowed" in the
+ Content-Type.
+ (handle_text_plain_flowed): Spinoff of handle_text_plain to deal
+ with RFC 2646 flowed text. (All the examples I can find of it
+ are generated by Eudora, but it's a pretty cool idea that ought
+ to be used more widely.)
2000-04-23 Dan Winship <danw@helixcode.com>
diff --git a/mail/mail-format.c b/mail/mail-format.c
index eaef1320a2..413145e6d2 100644
--- a/mail/mail-format.c
+++ b/mail/mail-format.c
@@ -39,6 +39,9 @@
static void handle_text_plain (CamelMimePart *part,
CamelMimeMessage *root,
GtkBox *box);
+static void handle_text_plain_flowed (CamelMimePart *part,
+ CamelMimeMessage *root,
+ GtkBox *box);
static void handle_text_enriched (CamelMimePart *part,
CamelMimeMessage *root,
GtkBox *box);
@@ -78,7 +81,8 @@ static void handle_via_bonobo (CamelMimePart *part,
* so '<' turns into '&lt;', and '"' turns into '&quot;' */
static gchar *text_to_html (const guchar *input, guint len,
guint *encoded_len_return, gboolean add_pre,
- gboolean convert_newlines_to_br);
+ gboolean convert_newlines_to_br,
+ gboolean convert_space_hack);
/* writes the header info for a mime message into an html stream */
static void write_headers (CamelMimeMessage *mime_message, GtkBox *box);
@@ -347,7 +351,8 @@ call_handler_function (CamelMimePart *part, CamelMimeMessage *root,
static gchar *
text_to_html (const guchar *input, guint len,
guint *encoded_len_return, gboolean add_pre,
- gboolean convert_newlines_to_br)
+ gboolean convert_newlines_to_br,
+ gboolean convert_space_hack)
{
const guchar *cur = input;
guchar *buffer = NULL;
@@ -400,6 +405,17 @@ text_to_html (const guchar *input, guint len,
}
break;
+ case ' ':
+ if (convert_space_hack) {
+ if (cur == input ||
+ (len > 0 && *(cur + 1) == ' ')) {
+ strcpy (out, "&nbsp;");
+ out += 6;
+ break;
+ }
+ }
+ /* otherwise, FALL THROUGH */
+
default:
if ((*cur >= 0x20 && *cur < 0x80) ||
(*cur == '\r' || *cur == '\t')) {
@@ -434,7 +450,7 @@ write_field_to_stream (const char *description, const char *value,
unsigned char *p;
encoded_value = text_to_html (value, strlen(value),
- NULL, FALSE, TRUE);
+ NULL, FALSE, TRUE, FALSE);
for (p = (unsigned char *)encoded_value; *p; p++) {
if (!isprint (*p))
*p = '?';
@@ -543,10 +559,20 @@ handle_text_plain (CamelMimePart *part, CamelMimeMessage *root, GtkBox *box)
gchar tmp_buffer[4096];
gint nb_bytes_read;
gboolean empty_text = TRUE;
+ GMimeContentField *type;
+ const char *format;
mail_html_new (&html, &stream, root, TRUE);
mail_html_write (html, stream, "\n<!-- text/plain -->\n<pre>\n");
+ /* Check for RFC 2646 flowed text. */
+ type = camel_mime_part_get_content_type (part);
+ format = gmime_content_field_get_parameter (type, "format");
+ if (format && !strcasecmp (format, "flowed")) {
+ handle_text_plain_flowed (part, root, box);
+ return;
+ }
+
/* Get the output stream of the data wrapper. */
wrapper_output_stream = camel_data_wrapper_get_output_stream (wrapper);
camel_stream_reset (wrapper_output_stream);
@@ -567,7 +593,7 @@ handle_text_plain (CamelMimePart *part, CamelMimeMessage *root, GtkBox *box)
text = text_to_html (tmp_buffer,
nb_bytes_read,
&returned_strlen,
- FALSE, FALSE);
+ FALSE, FALSE, FALSE);
gtk_html_write (html, stream, text,
returned_strlen);
g_free (text);
@@ -581,6 +607,81 @@ handle_text_plain (CamelMimePart *part, CamelMimeMessage *root, GtkBox *box)
mail_html_end (html, stream, TRUE, box);
}
+static void
+handle_text_plain_flowed (CamelMimePart *part, CamelMimeMessage *root,
+ GtkBox *box)
+{
+ GtkHTML *html;
+ GtkHTMLStreamHandle *stream;
+ CamelDataWrapper *wrapper =
+ camel_medium_get_content_object (CAMEL_MEDIUM (part));
+ char *text, *line, *p;
+ CamelStream *wrapper_output_stream, *buffer;
+ int prevquoting = 0, quoting, len, returned_strlen;
+ gboolean br_pending = FALSE;
+
+ mail_html_new (&html, &stream, root, TRUE);
+ mail_html_write (html, stream,
+ "\n<!-- text/plain, flowed -->\n<tt>\n");
+
+ /* Get the output stream of the data wrapper. */
+ wrapper_output_stream = camel_data_wrapper_get_output_stream (wrapper);
+ camel_stream_reset (wrapper_output_stream);
+ buffer = camel_stream_buffer_new (wrapper_output_stream,
+ CAMEL_STREAM_BUFFER_READ);
+
+ do {
+ /* Read next chunk of text. */
+ line = camel_stream_buffer_read_line (
+ CAMEL_STREAM_BUFFER (buffer));
+ if (!line)
+ break;
+
+ quoting = 0;
+ for (p = line; *p == '>'; p++)
+ quoting++;
+ if (quoting != prevquoting) {
+ mail_html_write (html, stream, "%s\n",
+ prevquoting == 0 ? "<i>\n" : "");
+ while (quoting > prevquoting) {
+ mail_html_write (html, stream, "<blockquote>");
+ prevquoting++;
+ }
+ while (quoting < prevquoting) {
+ mail_html_write (html, stream,
+ "</blockquote>");
+ prevquoting--;
+ }
+ mail_html_write (html, stream, "%s\n",
+ prevquoting == 0 ? "</i>\n" : "");
+ } else if (br_pending) {
+ mail_html_write (html, stream, "<br>\n");
+ br_pending = FALSE;
+ }
+
+ if (*p == ' ')
+ p++;
+
+ len = strlen (p);
+
+ /* replace '<' with '&lt;', etc. */
+ text = text_to_html (p, len, &returned_strlen,
+ FALSE, FALSE, TRUE);
+ if (returned_strlen)
+ gtk_html_write (html, stream, text, returned_strlen);
+ g_free (text);
+
+ if (len == 0 || p[len - 1] != ' ' || !strcmp (p, "-- "))
+ br_pending = TRUE;
+ g_free (line);
+ } while (!camel_stream_eos (buffer));
+
+ camel_stream_close (buffer);
+
+ mail_html_write (html, stream, "</tt>\n");
+ mail_html_end (html, stream, TRUE, box);
+}
+
/* text/enriched (RFC 1896) or text/richtext (included in RFC 1341) */
static void
handle_text_enriched (CamelMimePart *part, CamelMimeMessage *root, GtkBox *box)
@@ -1245,7 +1346,7 @@ mail_generate_reply (CamelMimeMessage *message, gboolean to_all)
/* Now convert that to HTML. */
repl_text = text_to_html (quoted_text,
strlen (quoted_text),
- &len, TRUE, FALSE);
+ &len, TRUE, FALSE, FALSE);
g_free (quoted_text);
}
e_msg_composer_set_body_text (composer, repl_text);