Changeset 50
- Timestamp:
- 02/12/06 16:48:01
- Files:
-
- trunk/libtinymail-camel/tny-camel-stream.c (modified) (2 diffs)
- trunk/libtinymail-camel/tny-camel-stream.h (modified) (1 diff)
- trunk/libtinymail-camel/tny-msg-priv.h (modified) (1 diff)
- trunk/libtinymail-camel/tny-msg.c (modified) (5 diffs)
- trunk/libtinymail/tny-msg-iface.c (modified) (1 diff)
- trunk/libtinymail/tny-msg-iface.h (modified) (2 diffs)
- trunk/libtinymail/tny-stream-iface.c (modified) (1 diff)
- trunk/libtinymail/tny-stream-iface.h (modified) (2 diffs)
- trunk/libtinymailui/Makefile.am (modified) (2 diffs)
- trunk/libtinymailui/tny-text-buffer-stream.c (added)
- trunk/libtinymailui/tny-text-buffer-stream.h (added)
- trunk/tinymail/tny-msg-window.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/libtinymail-camel/tny-camel-stream.c
r45 r50 50 50 51 51 52 53 void 54 tny_camel_stream_print (CamelStream *stream) 55 { 56 char tmp_buf[4096]; 57 ssize_t nb_read; 58 59 camel_stream_reset (stream); 60 61 while (!camel_stream_eos (stream)) 62 { 63 nb_read = camel_stream_read (stream, tmp_buf, sizeof (tmp_buf)); 64 g_print ("- (%d) -> %s", nb_read, tmp_buf); 65 } 66 67 g_print ("\n"); 68 69 return; 70 } 71 72 static ssize_t 73 tny_camel_stream_write_to_stream (TnyStreamIface *self, TnyStreamIface *output) 74 { 75 TnyCamelStreamPriv *priv = TNY_CAMEL_STREAM_GET_PRIVATE (self); 76 CamelStream *stream = priv->stream; 77 78 char tmp_buf[4096]; 79 ssize_t total = 0; 80 ssize_t nb_read; 81 ssize_t nb_written; 82 g_print ("1 %s\n", __FUNCTION__); 83 g_return_val_if_fail (CAMEL_IS_STREAM (stream), -1); 84 g_return_val_if_fail (TNY_IS_STREAM_IFACE (output), -1); 85 g_print ("2 %s\n", __FUNCTION__); 86 while (!camel_stream_eos (stream)) { 87 nb_read = camel_stream_read (stream, tmp_buf, sizeof (tmp_buf)); 88 if (nb_read < 0) 89 return -1; 90 else if (nb_read > 0) { 91 nb_written = 0; 92 93 while (nb_written < nb_read) { 94 ssize_t len = tny_stream_iface_write (output, tmp_buf + nb_written, 95 nb_read - nb_written); 96 if (len < 0) 97 return -1; 98 nb_written += len; 99 } 100 total += nb_written; 101 } 102 } 103 return total; 104 } 105 52 106 static ssize_t 53 107 tny_camel_stream_read (TnyStreamIface *self, char *buffer, size_t n) … … 159 213 klass->eos_func = tny_camel_stream_eos; 160 214 klass->reset_func = tny_camel_stream_reset; 215 klass->write_to_stream_func = tny_camel_stream_write_to_stream; 161 216 162 217 return; trunk/libtinymail-camel/tny-camel-stream.h
r45 r50 53 53 54 54 void tny_camel_stream_set_stream (TnyCamelStream *self, CamelStream *stream); 55 void tny_camel_stream_print (CamelStream *stream); 55 56 56 57 G_END_DECLS trunk/libtinymail-camel/tny-msg-priv.h
r48 r50 30 30 31 31 TnyMsgHeaderIface *header; 32 TnyStreamIface * stream;32 TnyStreamIface *body_stream; 33 33 34 34 GList *attachments; trunk/libtinymail-camel/tny-msg.c
r48 r50 35 35 (G_TYPE_INSTANCE_GET_PRIVATE ((o), TNY_MSG_TYPE, TnyMsgPriv)) 36 36 37 typedef gboolean (*CamelPartFunc)(CamelMimeMessage *, CamelMimePart *, void *data); 38 39 static gboolean 40 message_foreach_part_rec (CamelMimeMessage *msg, CamelMimePart *part, CamelPartFunc callback, void *data) 41 { 42 CamelDataWrapper *containee; 43 int parts, i; 44 int go = TRUE; 45 46 if (callback (msg, part, data) == FALSE) 47 return FALSE; 48 49 containee = camel_medium_get_content_object (CAMEL_MEDIUM (part)); 50 51 if (containee == NULL) 52 return go; 53 54 /* using the object types is more accurate than using the mime/types */ 55 if (CAMEL_IS_MULTIPART (containee)) { 56 parts = camel_multipart_get_number (CAMEL_MULTIPART (containee)); 57 for (i = 0; go && i < parts; i++) { 58 CamelMimePart *part = camel_multipart_get_part (CAMEL_MULTIPART (containee), i); 59 60 go = message_foreach_part_rec (msg, part, callback, data); 61 } 62 } else if (CAMEL_IS_MIME_MESSAGE (containee)) { 63 go = message_foreach_part_rec (msg, (CamelMimePart *)containee, callback, data); 64 } 65 66 return go; 67 } 68 69 70 static gboolean 71 received_a_part (CamelMimeMessage *message, CamelMimePart *part, void *data) 72 { 73 TnyMsgPriv *priv = data; 74 CamelTransferEncoding encoding = camel_mime_part_get_encoding (part); 75 76 switch (encoding) 77 { 78 case CAMEL_TRANSFER_ENCODING_DEFAULT: 79 case CAMEL_TRANSFER_ENCODING_7BIT: 80 case CAMEL_TRANSFER_ENCODING_8BIT: 81 case CAMEL_TRANSFER_ENCODING_QUOTEDPRINTABLE: 82 { 83 CamelDataWrapper *wrapper; 84 CamelMedium *medium = CAMEL_MEDIUM (part); 85 CamelStream *stream = camel_stream_mem_new (); 86 wrapper = camel_medium_get_content_object (medium); 87 camel_data_wrapper_write_to_stream (wrapper, stream); 88 89 tny_camel_stream_print (stream); 90 91 priv->body_stream = TNY_STREAM_IFACE 92 (tny_camel_stream_new (stream)); 93 94 /* Loose my own ref (tnycamelstream keeps one) */ 95 camel_object_unref (CAMEL_OBJECT (stream)); 96 } break; 97 98 case CAMEL_TRANSFER_ENCODING_BASE64: 99 case CAMEL_TRANSFER_ENCODING_BINARY: 100 case CAMEL_TRANSFER_ENCODING_UUENCODE: 101 /* Handle attachments */ 102 break; 103 104 case CAMEL_TRANSFER_NUM_ENCODINGS: 105 default: 106 /* Huh? */ 107 break; 108 } 109 110 return TRUE; 111 } 112 113 37 114 void 38 115 _tny_msg_set_camel_mime_message (TnyMsg *self, CamelMimeMessage *message) 39 116 { 40 117 TnyMsgPriv *priv = TNY_MSG_GET_PRIVATE (self); 41 42 /* TODO: Play with priv->stream here */ 118 CamelDataWrapper *wrapper; 119 CamelMimePart *part; 120 121 message_foreach_part_rec (message, (CamelMimePart *)message, received_a_part, priv); 122 123 if (!priv->body_stream) 124 { 125 g_print ("Message has no body?!\n"); 126 } 43 127 44 128 return; … … 73 157 74 158 static const TnyStreamIface* 75 tny_msg_get_ stream (TnyMsgIface *self)76 { 77 TnyMsgPriv *priv = TNY_MSG_GET_PRIVATE (TNY_MSG (self)); 78 79 return priv-> stream;159 tny_msg_get_body_stream (TnyMsgIface *self) 160 { 161 TnyMsgPriv *priv = TNY_MSG_GET_PRIVATE (TNY_MSG (self)); 162 163 return priv->body_stream; 80 164 } 81 165 … … 182 266 g_object_unref (G_OBJECT (priv->header)); 183 267 184 if (priv-> stream)185 g_object_unref (G_OBJECT (priv-> stream));268 if (priv->body_stream) 269 g_object_unref (G_OBJECT (priv->body_stream)); 186 270 187 271 if (priv->attachments) … … 214 298 215 299 klass->get_attachments_func = tny_msg_get_attachments; 216 klass->get_ stream_func = tny_msg_get_stream;300 klass->get_body_stream_func = tny_msg_get_body_stream; 217 301 klass->get_header_func = tny_msg_get_header; 218 302 klass->set_header_func = tny_msg_set_header; … … 250 334 251 335 priv->message = NULL; 252 priv-> stream = NULL;336 priv->body_stream = NULL; 253 337 priv->attachments = NULL; 254 338 priv->header = NULL; trunk/libtinymail/tny-msg-iface.c
r48 r50 30 30 **/ 31 31 const TnyStreamIface* 32 tny_msg_iface_get_ stream (TnyMsgIface *self)32 tny_msg_iface_get_body_stream (TnyMsgIface *self) 33 33 { 34 return TNY_MSG_IFACE_GET_CLASS (self)->get_ stream_func (self);34 return TNY_MSG_IFACE_GET_CLASS (self)->get_body_stream_func (self); 35 35 } 36 36 trunk/libtinymail/tny-msg-iface.h
r48 r50 41 41 42 42 const GList* (*get_attachments_func) (TnyMsgIface *self); 43 const TnyStreamIface* (*get_ stream_func)(TnyMsgIface *self);43 const TnyStreamIface* (*get_body_stream_func) (TnyMsgIface *self); 44 44 const TnyMsgHeaderIface* (*get_header_func) (TnyMsgIface *self); 45 45 … … 57 57 58 58 const GList* tny_msg_iface_get_attachments (TnyMsgIface *self); 59 const TnyStreamIface* tny_msg_iface_get_ stream(TnyMsgIface *self);59 const TnyStreamIface* tny_msg_iface_get_body_stream (TnyMsgIface *self); 60 60 const TnyMsgHeaderIface* tny_msg_iface_get_header (TnyMsgIface *self); 61 61 trunk/libtinymail/tny-stream-iface.c
r45 r50 20 20 #include <tny-stream-iface.h> 21 21 22 ssize_t 23 tny_stream_iface_write_to_stream (TnyStreamIface *self, TnyStreamIface *output) 24 { 25 return TNY_STREAM_IFACE_GET_CLASS (self)->write_to_stream_func (self, output); 26 } 22 27 23 28 ssize_t trunk/libtinymail/tny-stream-iface.h
r45 r50 46 46 gboolean (*eos_func) (TnyStreamIface *self); 47 47 gint (*reset_func) (TnyStreamIface *self); 48 ssize_t (*write_to_stream_func) (TnyStreamIface *self, TnyStreamIface *output); 48 49 }; 49 50 … … 58 59 gboolean tny_stream_iface_eos (TnyStreamIface *self); 59 60 gint tny_stream_iface_reset (TnyStreamIface *self); 61 ssize_t tny_stream_iface_write_to_stream (TnyStreamIface *self, TnyStreamIface *output); 60 62 61 63 G_END_DECLS trunk/libtinymailui/Makefile.am
r32 r50 9 9 tny-account-tree-model.h \ 10 10 tny-summary-window-iface.h \ 11 tny-text-buffer-stream.h \ 11 12 tny-msg-window-iface.h 12 13 … … 16 17 tny-account-tree-model.c \ 17 18 tny-summary-window-iface.c \ 19 tny-text-buffer-stream.c \ 18 20 tny-msg-window-iface.c 19 21 trunk/tinymail/tny-msg-window.c
r48 r50 21 21 #include <gtk/gtk.h> 22 22 #include <tny-msg-window.h> 23 #include <tny-text-buffer-stream.h> 23 24 24 25 static GObjectClass *parent_class = NULL; … … 41 42 TnyMsgWindowPriv *priv = TNY_MSG_WINDOW_GET_PRIVATE (self); 42 43 GtkTextBuffer *buffer = gtk_text_view_get_buffer (priv->textview); 43 44 TnyStreamIface *dest = TNY_STREAM_IFACE (tny_text_buffer_stream_new (buffer)); 45 TnyStreamIface *source; 44 46 TnyMsgHeaderIface *header; 45 47 GList *attachments; 46 const gchar *text;47 48 48 49 header = TNY_MSG_HEADER_IFACE (tny_msg_iface_get_header (priv->msg)); 50 source = (TnyStreamIface*)tny_msg_iface_get_body_stream (priv->msg); 49 51 attachments = (GList*)tny_msg_iface_get_attachments (priv->msg); 50 52 51 53 gtk_window_set_title (GTK_WINDOW (self), tny_msg_header_iface_get_subject (header)); 52 54 53 /* TODO: Use stream */ 54 gtk_text_buffer_set_text (buffer, tny_msg_header_iface_get_subject (header), strlen(tny_msg_header_iface_get_subject (header))); 55 tny_stream_iface_reset (source); 56 tny_stream_iface_reset (dest); 57 58 tny_stream_iface_write_to_stream (source, dest); 55 59 56 60 return;
