aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeffrey Stedfast <fejj@ximian.com>2001-10-23 09:48:05 +0800
committerJeffrey Stedfast <fejj@src.gnome.org>2001-10-23 09:48:05 +0800
commit113bb17ac1b2e89c64bbcd768d5688cb776cfb3f (patch)
treeeec29dd433e5eee24a5f8568d8190a79e1ede12b
parentd012fd43ca8746ba12919ba5b3111ba9bab352e0 (diff)
downloadgsoc2013-evolution-113bb17ac1b2e89c64bbcd768d5688cb776cfb3f.tar.gz
gsoc2013-evolution-113bb17ac1b2e89c64bbcd768d5688cb776cfb3f.tar.zst
gsoc2013-evolution-113bb17ac1b2e89c64bbcd768d5688cb776cfb3f.zip
New fun macro.
2001-10-22 Jeffrey Stedfast <fejj@ximian.com> * mail-display.h (mail_html_write_string): New fun macro. * mail-format.c (write_one_text_plain_chunk): Use gtk_html_write instead of mail_html_write so we avoid strdup'ing the text. (handle_text_plain_flowed): Use the mail_html_write_string macro. (handle_message_rfc822): Here too. (mail_format_raw_message): We can do it here also... (attachment_header): We can do it a little bit here... (write_address): A microscopic bit here... (write_hr): same. svn path=/trunk/; revision=13925
-rw-r--r--mail/ChangeLog14
-rw-r--r--mail/mail-display.c42
-rw-r--r--mail/mail-display.h2
-rw-r--r--mail/mail-format.c117
4 files changed, 93 insertions, 82 deletions
diff --git a/mail/ChangeLog b/mail/ChangeLog
index bf83c70308..f40d824709 100644
--- a/mail/ChangeLog
+++ b/mail/ChangeLog
@@ -1,3 +1,16 @@
+2001-10-22 Jeffrey Stedfast <fejj@ximian.com>
+
+ * mail-display.h (mail_html_write_string): New fun macro.
+
+ * mail-format.c (write_one_text_plain_chunk): Use gtk_html_write
+ instead of mail_html_write so we avoid strdup'ing the text.
+ (handle_text_plain_flowed): Use the mail_html_write_string macro.
+ (handle_message_rfc822): Here too.
+ (mail_format_raw_message): We can do it here also...
+ (attachment_header): We can do it a little bit here...
+ (write_address): A microscopic bit here...
+ (write_hr): same.
+
2001-10-22 Anna Marie Dirks <anna@ximian.com>
* mail-config.glade: Added several new accelerators to the edit account
@@ -20,6 +33,7 @@
* mail-display.c (on_url_requested): Use the new Camel->GtkHTML
stream - this means we don't have to chew up nearly as much
memory...yay!
+ (try_part_urls): Here too.
2001-10-22 Ettore Perazzoli <ettore@ximian.com>
diff --git a/mail/mail-display.c b/mail/mail-display.c
index 7e038d0b99..73c0c9a1ab 100644
--- a/mail/mail-display.c
+++ b/mail/mail-display.c
@@ -1145,7 +1145,6 @@ try_part_urls (struct _load_content_msg *m)
{
GHashTable *urls;
CamelMedium *medium;
- GByteArray *ba;
urls = g_datalist_get_data (m->display->data, "part_urls");
g_return_val_if_fail (urls != NULL, FALSE);
@@ -1154,24 +1153,19 @@ try_part_urls (struct _load_content_msg *m)
medium = g_hash_table_lookup (urls, m->url);
if (medium) {
CamelDataWrapper *data;
- CamelStream *stream_mem;
-
+ CamelStream *html_stream;
+
g_return_val_if_fail (CAMEL_IS_MEDIUM (medium), FALSE);
-
+
data = camel_medium_get_content_object (medium);
if (!mail_content_loaded (data, m->display, FALSE, m->url, m->handle)) {
g_warning ("This code should not be reached\n");
return TRUE;
}
-
- ba = g_byte_array_new ();
- stream_mem = camel_stream_mem_new_with_byte_array (ba);
- camel_data_wrapper_write_to_stream (data, stream_mem);
- /* printf ("-- begin --\n");
- printf (ba->data);
- printf ("-- end --\n"); */
- gtk_html_write (m->display->html, m->handle, ba->data, ba->len);
- camel_object_unref (CAMEL_OBJECT (stream_mem));
+
+ html_stream = mail_stream_gtkhtml_new (m->display->html, m->handle);
+ camel_data_wrapper_write_to_stream (data, html_stream);
+ camel_object_unref (CAMEL_OBJECT (html_stream));
gtk_html_end (m->display->html, m->handle, GTK_HTML_STREAM_OK);
return TRUE;
@@ -1301,7 +1295,7 @@ mail_html_write (GtkHTML *html, GtkHTMLStream *stream,
{
char *buf;
va_list ap;
-
+
va_start (ap, format);
buf = g_strdup_vprintf (format, ap);
va_end (ap);
@@ -1316,24 +1310,24 @@ mail_text_write (GtkHTML *html, GtkHTMLStream *stream,
{
char *buf, *htmltext;
va_list ap;
-
+
va_start (ap, format);
buf = g_strdup_vprintf (format, ap);
va_end (ap);
-
- htmltext = e_text_to_html_full (buf,
- E_TEXT_TO_HTML_CONVERT_URLS |
+
+ htmltext = e_text_to_html_full (buf, E_TEXT_TO_HTML_CONVERT_URLS |
E_TEXT_TO_HTML_CONVERT_ADDRESSES |
E_TEXT_TO_HTML_CONVERT_NL |
E_TEXT_TO_HTML_CONVERT_SPACES |
(mail_config_get_citation_highlight () ? E_TEXT_TO_HTML_MARK_CITATION : 0),
mail_config_get_citation_color ());
-
+
+ g_free (buf);
+
gtk_html_write (html, stream, "<tt>", 4);
gtk_html_write (html, stream, htmltext, strlen (htmltext));
gtk_html_write (html, stream, "</tt>", 5);
g_free (htmltext);
- g_free (buf);
}
void
@@ -1342,18 +1336,18 @@ mail_error_write (GtkHTML *html, GtkHTMLStream *stream,
{
char *buf, *htmltext;
va_list ap;
-
+
va_start (ap, format);
buf = g_strdup_vprintf (format, ap);
va_end (ap);
-
+
htmltext = e_text_to_html (buf, E_TEXT_TO_HTML_CONVERT_NL | E_TEXT_TO_HTML_CONVERT_URLS);
g_free (buf);
-
+
gtk_html_stream_printf (stream, "<em><font color=red>");
gtk_html_stream_write (stream, htmltext, strlen (htmltext));
gtk_html_stream_printf (stream, "</font></em>");
-
+
g_free (htmltext);
}
diff --git a/mail/mail-display.h b/mail/mail-display.h
index 61dd4f0579..a44d2483e8 100644
--- a/mail/mail-display.h
+++ b/mail/mail-display.h
@@ -74,6 +74,8 @@ void mail_display_set_charset (MailDisplay *mail_display,
void mail_display_load_images (MailDisplay *mail_display);
+#define mail_html_write_string(html, stream, string) gtk_html_write (html, stream, string, strlen (string))
+
void mail_html_write (GtkHTML *html,
GtkHTMLStream *stream,
const char *format, ...);
diff --git a/mail/mail-format.c b/mail/mail-format.c
index 999e70d602..8f9950cdd3 100644
--- a/mail/mail-format.c
+++ b/mail/mail-format.c
@@ -210,8 +210,8 @@ mail_format_raw_message (CamelMimeMessage *mime_message, MailDisplay *md)
TRUE, NULL, NULL))
return;
- mail_html_write (md->html, md->stream,
- "<table cellspacing=0 cellpadding=10 width=\"100%%\"><tr><td><tt>\n");
+ mail_html_write_string (md->html, md->stream,
+ "<table cellspacing=0 cellpadding=10 width=\"100%\"><tr><td><tt>\n");
bytes = mail_format_get_data_wrapper_text (CAMEL_DATA_WRAPPER (mime_message), md);
if (bytes) {
@@ -220,11 +220,11 @@ mail_format_raw_message (CamelMimeMessage *mime_message, MailDisplay *md)
E_TEXT_TO_HTML_CONVERT_SPACES | E_TEXT_TO_HTML_ESCAPE_8BIT);
g_byte_array_free (bytes, TRUE);
- gtk_html_write (md->html, md->stream, html, strlen (html));
+ mail_html_write_string (md->html, md->stream, html);
g_free (html);
}
- mail_html_write (md->html, md->stream, "</tt></td></tr></table>");
+ mail_html_write_string (md->html, md->stream, "</tt></td></tr></table>");
}
static const char *
@@ -649,9 +649,9 @@ attachment_header (CamelMimePart *part, const char *mime_type, MailDisplay *md)
g_free (htmlinfo);
}
- mail_html_write (md->html, md->stream,
- "</font></td></tr><tr><td height=10><table height=10 cellspacing=0 cellpadding=0>"
- "<tr><td></td></tr></table></td></tr></table>\n");
+ mail_html_write_string (md->html, md->stream, "</font></td></tr><tr>"
+ "<td height=10><table height=10 cellspacing=0 cellpadding=0>"
+ "<tr><td></td></tr></table></td></tr></table>\n");
}
static gboolean
@@ -838,7 +838,7 @@ write_address (MailDisplay *md, const CamelInternetAddress *addr, const char *fi
}
if (i)
- mail_html_write (md->html, md->stream, ", ");
+ mail_html_write_string (md->html, md->stream, ", ");
if (have_email || have_name) {
if (!have_email) {
@@ -873,7 +873,8 @@ write_address (MailDisplay *md, const CamelInternetAddress *addr, const char *fi
i++;
}
- mail_html_write (md->html, md->stream, "</td></tr>");
+
+ mail_html_write_string (md->html, md->stream, "</td></tr>");
}
/* order of these must match write_header code */
@@ -1008,10 +1009,10 @@ write_headers (CamelMimeMessage *message, MailDisplay *md)
write_default_header(message, md, i, 0);
}
- mail_html_write (md->html, md->stream,
- "</table></td></tr></table></td></tr></table></font></td>"
- "<td><table width=10 cellpadding=0 cellspacing=0><tr><td></td></tr></table></td></tr>"
- "</table>\n");
+ mail_html_write_string (md->html, md->stream,
+ "</table></td></tr></table></td></tr></table></font></td>"
+ "<td><table width=10 cellpadding=0 cellspacing=0><tr><td>"
+ "</td></tr></table></td></tr></table>\n");
}
static void
@@ -1095,9 +1096,9 @@ mail_format_get_data_wrapper_text (CamelDataWrapper *wrapper, MailDisplay *mail_
static void
write_hr (MailDisplay *md)
{
- mail_html_write (md->html, md->stream,
- "<table cellspacing=0 cellpadding=10 width=\"100%%\"><tr><td width=\"100%%\">"
- "<hr noshadow size=1></td></tr></table>\n");
+ mail_html_write_string (md->html, md->stream,
+ "<table cellspacing=0 cellpadding=10 width=\"100%\"><tr><td width=\"100%\">"
+ "<hr noshadow size=1></td></tr></table>\n");
}
/*----------------------------------------------------------------------*
@@ -1119,10 +1120,11 @@ struct {
static void
write_one_text_plain_chunk (const char *text, int len, MailDisplay *md)
{
- mail_html_write (md->html, md->stream, "<table cellspacing=0 cellpadding=10 width=\"100%%\"><tr><td>\n");
- mail_text_write (md->html, md->stream, "%.*s", len, text);
- mail_html_write (md->html, md->stream, "</td></tr></table>\n");
-}
+ mail_html_write_string (md->html, md->stream,
+ "<table cellspacing=0 cellpadding=10 width=\"100%\"><tr><td>\n");
+ gtk_html_write (md->html, md->stream, text, len);
+ mail_html_write_string (md->html, md->stream, "</td></tr></table>\n");
+}
static gboolean
handle_text_plain (CamelMimePart *part, const char *mime_type,
@@ -1204,11 +1206,11 @@ handle_text_plain_flowed (char *buf, MailDisplay *md)
char *text, *line, *eol, *p;
int prevquoting = 0, quoting, len, br_pending = 0;
guint32 citation_color = mail_config_get_citation_color ();
-
- mail_html_write (md->html, md->stream,
- "\n<!-- text/plain, flowed -->\n"
- "<table cellspacing=0 cellpadding=10 width=\"100%%\"><tr><td>\n<tt>\n");
-
+
+ mail_html_write_string (md->html, md->stream,
+ "\n<!-- text/plain, flowed -->\n"
+ "<table cellspacing=0 cellpadding=10 width=\"100%\"><tr><td>\n<tt>\n");
+
for (line = buf; *line; line = eol + 1) {
/* Process next line */
eol = strchr (line, '\n');
@@ -1227,23 +1229,23 @@ handle_text_plain_flowed (char *buf, MailDisplay *md)
br_pending--;
}
while (quoting > prevquoting) {
- mail_html_write (md->html, md->stream,
- "<blockquote>");
+ mail_html_write_string (md->html, md->stream,
+ "<blockquote>");
prevquoting++;
}
while (quoting < prevquoting) {
- mail_html_write (md->html, md->stream,
- "</blockquote>");
+ mail_html_write_string (md->html, md->stream,
+ "</blockquote>");
prevquoting--;
}
if (quoting == 0) {
- mail_html_write (md->html, md->stream,
- "</font>\n");
+ mail_html_write_string (md->html, md->stream,
+ "</font>\n");
if (br_pending)
br_pending--;
}
}
-
+
if (*p == ' ')
p++;
len = strlen (p);
@@ -1251,28 +1253,28 @@ handle_text_plain_flowed (char *buf, MailDisplay *md)
br_pending++;
continue;
}
-
+
while (br_pending) {
- mail_html_write (md->html, md->stream, "<br>\n");
+ mail_html_write_string (md->html, md->stream, "<br>\n");
br_pending--;
}
-
+
/* replace '<' with '&lt;', etc. */
text = e_text_to_html (p, E_TEXT_TO_HTML_CONVERT_SPACES |
E_TEXT_TO_HTML_CONVERT_URLS);
if (text && *text)
- mail_html_write (md->html, md->stream, "%s", text);
+ mail_html_write_string (md->html, md->stream, text);
g_free (text);
-
+
if (p[len - 1] != ' ' || !strcmp (p, "-- "))
br_pending++;
-
+
if (!eol)
break;
}
g_free (buf);
- mail_html_write (md->html, md->stream, "</tt>\n</td></tr></table>\n");
+ mail_html_write_string (md->html, md->stream, "</tt>\n</td></tr></table>\n");
return TRUE;
}
@@ -1549,12 +1551,12 @@ handle_text_enriched (CamelMimePart *part, const char *mime_type,
if (!g_strcasecmp (mime_type, "text/richtext")) {
enriched = FALSE;
- mail_html_write (md->html, md->stream,
- "\n<!-- text/richtext -->\n");
+ mail_html_write_string (md->html, md->stream,
+ "\n<!-- text/richtext -->\n");
} else {
enriched = TRUE;
- mail_html_write (md->html, md->stream,
- "\n<!-- text/enriched -->\n");
+ mail_html_write_string (md->html, md->stream,
+ "\n<!-- text/enriched -->\n");
}
/* This is not great code, but I don't feel like fixing it right
@@ -1661,7 +1663,7 @@ handle_text_html (CamelMimePart *part, const char *mime_type,
{
const char *location;
- mail_html_write (md->html, md->stream, "\n<!-- text/html -->\n");
+ mail_html_write_string (md->html, md->stream, "\n<!-- text/html -->\n");
/* FIXME: deal with relative URLs */
location = get_location (part, md);
@@ -1793,13 +1795,13 @@ handle_multipart_signed (CamelMimePart *part, const char *mime_type,
"<td><table width=3 cellspacing=0 cellpadding=0><tr><td></td></tr></table></td>"
"<td><font size=-1>", url);
- mail_html_write (md->html, md->stream, "%s",
- U_("This message is digitally signed. "
- "Click the lock icon for more information."));
-
- mail_html_write (md->html, md->stream,
- "</font></td></tr><tr><td height=10><table height=10 cellspacing=0 cellpadding=0>"
- "<tr><td></td></tr></table></td></tr></table>\n");
+ mail_html_write_string (md->html, md->stream,
+ U_("This message is digitally signed. "
+ "Click the lock icon for more information."));
+
+ mail_html_write_string (md->html, md->stream,
+ "</font></td></tr><tr><td height=10><table height=10 cellspacing=0 cellpadding=0>"
+ "<tr><td></td></tr></table></td></tr></table>\n");
} else {
CamelCipherValidity *valid = NULL;
CamelException ex;
@@ -1838,14 +1840,13 @@ handle_multipart_signed (CamelMimePart *part, const char *mime_type,
}
if (message) {
- mail_html_write (md->html, md->stream,
- "<font size=-1 %s>",
+ mail_html_write (md->html, md->stream, "<font size=-1 %s>",
good ? "" : "color=red");
mail_text_write (md->html, md->stream, "%s", message);
- mail_html_write (md->html, md->stream, "</font>");
+ mail_html_write_string (md->html, md->stream, "</font>");
}
- mail_html_write (md->html, md->stream, "</td></tr></table>");
+ mail_html_write_string (md->html, md->stream, "</td></tr></table>");
camel_exception_clear (&ex);
camel_cipher_validity_free (valid);
}
@@ -1993,10 +1994,10 @@ handle_message_rfc822 (CamelMimePart *part, const char *mime_type,
g_return_val_if_fail (CAMEL_IS_MIME_MESSAGE (wrapper), FALSE);
- mail_html_write (md->html, md->stream, "<blockquote>");
+ mail_html_write_string (md->html, md->stream, "<blockquote>");
mail_format_mime_message (CAMEL_MIME_MESSAGE (wrapper), md);
- mail_html_write (md->html, md->stream, "</blockquote>");
-
+ mail_html_write_string (md->html, md->stream, "</blockquote>");
+
return TRUE;
}