X-Git-Url: http://git.maemo.org/git/?p=modest;a=blobdiff_plain;f=src%2Fmodest-tny-transport-actions.c;h=e55ac9726927e9391079f3ddecd99602509736d3;hp=72f4d98454501f4886007b9f9d90e34a29871186;hb=64d81bebf80d459f9800395a17b4ce8fa3099e2d;hpb=7132d15e9e6ed80b52f3c73ffe901888756acabc diff --git a/src/modest-tny-transport-actions.c b/src/modest-tny-transport-actions.c index 72f4d98..e55ac97 100644 --- a/src/modest-tny-transport-actions.c +++ b/src/modest-tny-transport-actions.c @@ -1,6 +1,34 @@ -/* modest-tny-transport-actions.c */ +/* Copyright (c) 2006, Nokia Corporation + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the Nokia Corporation nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + -/* insert (c)/licensing information) */ +/* modest-tny-transport-actions.c */ #include #include @@ -20,9 +48,8 @@ #include #include - - #include "modest-tny-transport-actions.h" +#include "modest-tny-attachment.h" /* include other impl specific header files */ /* 'private'/'protected' functions */ @@ -158,22 +185,21 @@ modest_tny_transport_actions_send_message (ModestTnyTransportActions *self, const GList *attachments_list) { TnyMsgIface *new_msg; - TnyMsgMimePartIface *text_body_part, *attachment_part; + TnyMsgMimePartIface *attachment_part, *text_body_part; TnyMsgHeaderIface *headers; TnyStreamIface *text_body_stream, *attachment_stream; - GList *attachment; - gchar *content_type, *attachment_content_type; - gchar *filename, *attachment_filename; - int file; - + ModestTnyAttachment *attachment; + GList *pos; + gchar *content_type; + const gchar *attachment_content_type; + const gchar *attachment_filename; + new_msg = TNY_MSG_IFACE(tny_msg_new ()); headers = TNY_MSG_HEADER_IFACE(tny_msg_header_new ()); text_body_stream = TNY_STREAM_IFACE (tny_stream_camel_new - (camel_stream_mem_new_with_buffer - (body, strlen(body)))); - text_body_part = TNY_MSG_MIME_PART_IFACE (tny_msg_mime_part_new - (camel_mime_part_new())); - + (camel_stream_mem_new_with_buffer + (body, strlen(body)))); + tny_msg_header_iface_set_from (TNY_MSG_HEADER_IFACE (headers), from); tny_msg_header_iface_set_to (TNY_MSG_HEADER_IFACE (headers), to); tny_msg_header_iface_set_cc (TNY_MSG_HEADER_IFACE (headers), cc); @@ -181,23 +207,37 @@ modest_tny_transport_actions_send_message (ModestTnyTransportActions *self, tny_msg_header_iface_set_subject (TNY_MSG_HEADER_IFACE (headers), subject); tny_msg_iface_set_header (new_msg, headers); + content_type = get_content_type(body); - tny_msg_mime_part_iface_construct_from_stream (text_body_part, text_body_stream, content_type); - tny_stream_iface_reset (text_body_stream); - tny_msg_iface_add_part(new_msg, text_body_part); - - for (attachment = (GList *)attachments_list; attachment; attachment = attachment->next) { - filename = attachment->data; - attachment_filename = g_path_get_basename(filename); - file = open(filename, O_RDONLY); - attachment_stream = TNY_STREAM_IFACE(tny_stream_camel_new( - camel_stream_fs_new_with_fd(file))); - + if (attachments_list == NULL) { + tny_stream_iface_reset (text_body_stream); + tny_msg_mime_part_iface_construct_from_stream (TNY_MSG_MIME_PART_IFACE(new_msg), + text_body_stream, content_type); + tny_stream_iface_reset (text_body_stream); + } else { + text_body_part = TNY_MSG_MIME_PART_IFACE (tny_msg_mime_part_new( + camel_mime_part_new())); + tny_stream_iface_reset (text_body_stream); + tny_msg_mime_part_iface_construct_from_stream (text_body_part, + text_body_stream, + content_type); + tny_stream_iface_reset (text_body_stream); + tny_msg_iface_add_part(new_msg, text_body_part); + //g_object_unref (G_OBJECT(text_body_part)); + } + + for ( pos = (GList *)attachments_list; + pos; + pos = pos->next ) { + attachment = pos->data; + attachment_filename = modest_tny_attachment_get_name(attachment); + attachment_stream = modest_tny_attachment_get_stream(attachment); attachment_part = TNY_MSG_MIME_PART_IFACE (tny_msg_mime_part_new ( camel_mime_part_new())); - attachment_content_type = "image/jpeg"; /* later... */ + attachment_content_type = modest_tny_attachment_get_mime_type(attachment); + tny_msg_mime_part_iface_construct_from_stream (attachment_part, attachment_stream, attachment_content_type); @@ -206,16 +246,13 @@ modest_tny_transport_actions_send_message (ModestTnyTransportActions *self, tny_msg_mime_part_iface_set_filename(attachment_part, attachment_filename); tny_msg_iface_add_part (new_msg, attachment_part); - g_object_unref(G_OBJECT(attachment_stream)); //g_object_unref(G_OBJECT(attachment_part)); - g_free(attachment_filename); //close(file); } tny_transport_account_iface_send (transport_account, new_msg); g_object_unref (G_OBJECT(text_body_stream)); - //g_object_unref (G_OBJECT(text_body_part)); g_object_unref (G_OBJECT(headers)); g_object_unref (G_OBJECT(new_msg)); g_free(content_type);