* Updated to the new implementation of tny_camel_header_get_xxx methods
[modest] / src / modest-formatter.c
index 81af6dc..ddbd2e5 100644 (file)
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#include <gtk/gtk.h>
 #include <glib/gi18n.h>
 #include <string.h>
 #include <tny-header.h>
 #include <tny-gtk-text-buffer-stream.h>
 #include <tny-camel-stream.h>
-#include <tny-camel-msg.h>
 #include <camel/camel-stream-mem.h>
 #include "modest-formatter.h"
 #include "modest-text-utils.h"
+#include "modest-tny-platform-factory.h"
 
 typedef struct _ModestFormatterPrivate ModestFormatterPrivate;
 struct _ModestFormatterPrivate {
@@ -87,7 +86,8 @@ extract_text (ModestFormatter *self, TnyMimePart *body)
        if (strcmp (tny_mime_part_get_content_type (body), priv->content_type)) {
                if (!strcmp (priv->content_type, "text/html"))
                        converted_text = modest_text_utils_convert_to_html  (text);
-/*             else */
+               else
+                       converted_text = g_strdup (text);
 /*                     converted_text = modest_text_utils_convert_to_plain (text); */
 
                g_free (text);
@@ -124,12 +124,19 @@ modest_formatter_do (ModestFormatter *self,
                     TnyHeader *header,
                     FormatterFunc func)
 {
-       TnyMsg *new_msg;
+       TnyMsg *new_msg = NULL;
        gchar *body_text = NULL, *txt = NULL;
        ModestFormatterPrivate *priv;
+       TnyPlatformFactory *fact;
+
+       g_return_val_if_fail (self, NULL);
+       g_return_val_if_fail (body, NULL);
+       g_return_val_if_fail (header, NULL);
+       g_return_val_if_fail (func, NULL);
 
        /* Build new part */
-       new_msg = TNY_MSG (tny_camel_msg_new ());
+       fact = modest_tny_platform_factory_get_instance ();
+       new_msg = tny_platform_factory_new_msg (fact);
        body_text = extract_text (self, body);
        txt = (gchar *) func (self, (const gchar*) body_text, header);
        priv = MODEST_FORMATTER_GET_PRIVATE (self);
@@ -165,20 +172,24 @@ modest_formatter_attach (ModestFormatter *self, TnyMimePart *body, TnyHeader *he
 {
        TnyMsg *new_msg = NULL;
        gchar *attach_text = NULL;
+       const gchar *subject;
        TnyMimePart *body_part = NULL, *attach_part = NULL;
        ModestFormatterPrivate *priv;
+       TnyPlatformFactory *fact;
 
+       fact = modest_tny_platform_factory_get_instance ();
        /* Build new part */
-       new_msg     = TNY_MSG (tny_camel_msg_new ());
-       body_part   = TNY_MIME_PART (tny_camel_mime_part_new (camel_mime_part_new()));
-       attach_part = TNY_MIME_PART (tny_camel_mime_part_new (camel_mime_part_new()));
+       new_msg     = tny_platform_factory_new_msg (fact);
+       body_part   = tny_platform_factory_new_mime_part (fact);
+       attach_part = tny_platform_factory_new_mime_part (fact);
 
        /* Create the two parts */
        priv = MODEST_FORMATTER_GET_PRIVATE (self);
        attach_text = extract_text (self, body);
        construct_from_text (body_part, "", priv->content_type);
        construct_from_text (attach_part, (const gchar*) attach_text, priv->content_type);
-       tny_mime_part_set_filename (attach_part, tny_header_get_subject (header));
+       subject = tny_header_get_subject (header);
+       tny_mime_part_set_filename (attach_part, subject ? subject : _("No subject"));
 
        /* Add parts */
        tny_mime_part_add_part (TNY_MIME_PART (new_msg), body_part);