aboutsummaryrefslogtreecommitdiffstats
path: root/mail
diff options
context:
space:
mode:
authorDan Winship <danw@src.gnome.org>2000-05-18 09:03:00 +0800
committerDan Winship <danw@src.gnome.org>2000-05-18 09:03:00 +0800
commit961fe94bb9cdc7fd753819521e1dc259a1ee7b4f (patch)
tree44428f9e1a639f24cf32647d336debb0e5945ff4 /mail
parent0cd1c1934c5a366a8d506c177c859d65075fb942 (diff)
downloadgsoc2013-evolution-961fe94bb9cdc7fd753819521e1dc259a1ee7b4f.tar.gz
gsoc2013-evolution-961fe94bb9cdc7fd753819521e1dc259a1ee7b4f.tar.zst
gsoc2013-evolution-961fe94bb9cdc7fd753819521e1dc259a1ee7b4f.zip
Use camel_data_wrapper_write_to_stream rather than
* mail-display.c (save_data_cb, save_data, on_url_requested): * mail-format.c (handle_text_plain_flowed, handle_text_html): Use camel_data_wrapper_write_to_stream rather than camel_data_wrapper_get_output_stream. svn path=/trunk/; revision=3113
Diffstat (limited to 'mail')
-rw-r--r--mail/ChangeLog7
-rw-r--r--mail/mail-display.c48
-rw-r--r--mail/mail-format.c57
3 files changed, 41 insertions, 71 deletions
diff --git a/mail/ChangeLog b/mail/ChangeLog
index 7bc59eba43..c899ed84eb 100644
--- a/mail/ChangeLog
+++ b/mail/ChangeLog
@@ -1,3 +1,10 @@
+2000-05-17 Dan Winship <danw@helixcode.com>
+
+ * mail-display.c (save_data_cb, save_data, on_url_requested):
+ * mail-format.c (handle_text_plain_flowed, handle_text_html):
+ Use camel_data_wrapper_write_to_stream rather than
+ camel_data_wrapper_get_output_stream.
+
2000-05-16 NotZed <NotZed@HelixCode.com>
* mail-ops.c (filter_edit): Function to bring up the filter editor.
diff --git a/mail/mail-display.c b/mail/mail-display.c
index 0dc919d307..5b455c0c5f 100644
--- a/mail/mail-display.c
+++ b/mail/mail-display.c
@@ -39,11 +39,12 @@ save_data_eexist_cb (int reply, gpointer user_data)
static void
save_data_cb (GtkWidget *widget, gpointer user_data)
{
- CamelStream *output = CAMEL_STREAM (user_data);
+ CamelDataWrapper *data = user_data;
+ CamelStream *stream_fs;
GtkFileSelection *file_select = (GtkFileSelection *)
gtk_widget_get_ancestor (widget, GTK_TYPE_FILE_SELECTION);
- char *name, buf[1024];
- int fd, nread;
+ char *name;
+ int fd;
CamelException *ex;
name = gtk_file_selection_get_filename (file_select);
@@ -70,14 +71,12 @@ save_data_cb (GtkWidget *widget, gpointer user_data)
return;
}
+ stream_fs = camel_stream_fs_new_with_fd (fd);
ex = camel_exception_new ();
- camel_stream_reset (output, ex);
- while (!camel_exception_is_set (ex) && !camel_stream_eos (output)) {
- nread = camel_stream_read (output, buf, sizeof (buf), ex);
- if (nread > 0)
- write (fd, buf, nread);
- }
- close (fd);
+ camel_data_wrapper_write_to_stream (data, stream_fs, ex);
+ if (!camel_exception_is_set (ex))
+ camel_stream_flush (stream_fs, ex);
+ gtk_object_unref (GTK_OBJECT (stream_fs));
if (camel_exception_is_set (ex)) {
char *msg;
@@ -95,15 +94,12 @@ static void
save_data (const char *cid, CamelMimeMessage *message)
{
CamelDataWrapper *data;
- CamelStream *output;
GtkFileSelection *file_select;
char *filename;
g_return_if_fail (CAMEL_IS_MIME_MESSAGE (message));
data = gtk_object_get_data (GTK_OBJECT (message), cid);
g_return_if_fail (CAMEL_IS_DATA_WRAPPER (data));
- output = camel_data_wrapper_get_output_stream (data);
- g_return_if_fail (CAMEL_IS_STREAM (output));
file_select = GTK_FILE_SELECTION (gtk_file_selection_new ("Save Attachment"));
filename = gtk_object_get_data (GTK_OBJECT (data), "filename");
@@ -115,7 +111,7 @@ save_data (const char *cid, CamelMimeMessage *message)
g_free (filename);
gtk_signal_connect (GTK_OBJECT (file_select->ok_button), "clicked",
- GTK_SIGNAL_FUNC (save_data_cb), output);
+ GTK_SIGNAL_FUNC (save_data_cb), data);
gtk_signal_connect_object (GTK_OBJECT (file_select->cancel_button),
"clicked",
GTK_SIGNAL_FUNC (gtk_widget_destroy),
@@ -142,8 +138,6 @@ static void
on_url_requested (GtkHTML *html, const char *url, GtkHTMLStreamHandle handle,
gpointer user_data)
{
- char buf[1024];
- int nread;
CamelMimeMessage *message = CAMEL_MIME_MESSAGE (user_data);
if (strncmp (url, "x-gnome-icon:", 13) == 0) {
@@ -153,8 +147,8 @@ on_url_requested (GtkHTML *html, const char *url, GtkHTMLStreamHandle handle,
* hack needs to be replaced with something more
* efficient anyway.
*/
- char *path = gnome_pixmap_file (name);
- int fd;
+ char *path = gnome_pixmap_file (name), buf[1024];
+ int fd, nread;
g_return_if_fail (path != NULL);
fd = open (path, O_RDONLY);
@@ -171,21 +165,17 @@ on_url_requested (GtkHTML *html, const char *url, GtkHTMLStreamHandle handle,
} else if (strncmp (url, "cid:", 4) == 0) {
const char *cid = url + 4;
CamelDataWrapper *data;
- CamelStream *output;
+ CamelStream *stream_mem;
+ GByteArray *ba;
data = gtk_object_get_data (GTK_OBJECT (message), cid);
g_return_if_fail (CAMEL_IS_DATA_WRAPPER (data));
- output = camel_data_wrapper_get_output_stream (data);
- g_return_if_fail (CAMEL_IS_STREAM (output));
-
- camel_stream_reset (output, NULL);
- do {
- nread = camel_stream_read (output, buf,
- sizeof (buf), NULL);
- if (nread > 0)
- gtk_html_write (html, handle, buf, nread);
- } while (!camel_stream_eos (output));
+ ba = g_byte_array_new ();
+ stream_mem = camel_stream_mem_new_with_byte_array (ba);
+ camel_data_wrapper_write_to_stream (data, stream_mem, NULL);
+ gtk_html_write (html, handle, ba->data, ba->len);
+ gtk_object_unref (GTK_OBJECT (stream_mem));
} else
return;
}
diff --git a/mail/mail-format.c b/mail/mail-format.c
index 8aafb4083b..f1a1f3e552 100644
--- a/mail/mail-format.c
+++ b/mail/mail-format.c
@@ -474,8 +474,7 @@ handle_text_plain_flowed (CamelMimePart *part, CamelMimeMessage *root,
GtkHTMLStreamHandle *stream;
CamelDataWrapper *wrapper =
camel_medium_get_content_object (CAMEL_MEDIUM (part));
- char *text, *line, *p;
- CamelStream *wrapper_output_stream, *buffer;
+ char *buf, *text, *line, *eol, *p;
int prevquoting = 0, quoting, len;
gboolean br_pending = FALSE;
@@ -483,18 +482,12 @@ handle_text_plain_flowed (CamelMimePart *part, CamelMimeMessage *root,
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, NULL);
- 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), NULL);
- if (!line)
- break;
+ buf = get_data_wrapper_text (wrapper);
+ for (line = buf; *line; line = eol + 1) {
+ /* Process next line */
+ eol = strchr (line, '\n');
+ if (eol)
+ *eol = '\0';
quoting = 0;
for (p = line; *p == '>'; p++)
@@ -531,10 +524,11 @@ handle_text_plain_flowed (CamelMimePart *part, CamelMimeMessage *root,
len = strlen (p);
if (len == 0 || p[len - 1] != ' ' || !strcmp (p, "-- "))
br_pending = TRUE;
- g_free (line);
- } while (!camel_stream_eos (buffer));
- gtk_object_unref (GTK_OBJECT (buffer));
+ if (!eol)
+ break;
+ }
+ g_free (buf);
mail_html_write (html, stream, "</tt>\n");
mail_html_end (html, stream, TRUE, box);
@@ -678,35 +672,14 @@ handle_text_html (CamelMimePart *part, CamelMimeMessage *root, GtkBox *box)
GtkHTMLStreamHandle *stream;
CamelDataWrapper *wrapper =
camel_medium_get_content_object (CAMEL_MEDIUM (part));
- CamelStream *wrapper_output_stream;
- gchar tmp_buffer[4096];
- gint nb_bytes_read;
- gboolean empty_text = TRUE;
+ char *text;
mail_html_new (&html, &stream, root, FALSE);
mail_html_write (html, stream, "\n<!-- text/html -->\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, NULL);
-
- do {
- /* Read next chunk of text. */
- nb_bytes_read = camel_stream_read (wrapper_output_stream,
- tmp_buffer, 4096, NULL);
-
- /* If there's any text, write it to the stream */
- if (nb_bytes_read > 0) {
- empty_text = FALSE;
-
- /* Write the buffer to the html stream */
- gtk_html_write (html, stream, tmp_buffer,
- nb_bytes_read);
- }
- } while (!camel_stream_eos (wrapper_output_stream));
-
- if (empty_text)
- mail_html_write (html, stream, "<b>(empty)</b>");
+ text = get_data_wrapper_text (wrapper);
+ mail_html_write (html, stream, text);
+ g_free (text);
mail_html_end (html, stream, FALSE, box);
}