Modified webpage: now tinymail repository is in gitorious.
[modest] / src / modest-stream-text-to-html.c
index 4eee0f0..bd43e00 100644 (file)
@@ -38,8 +38,8 @@
 #define HTML_PREFIX "<html><head>" \
        "<meta http-equiv=\"content-type\" content=\"text/html; charset=utf8\">" \
        "</head>" \
-       "<body>"
-#define HTML_SUFFIX "</body></html>"
+       "<body><p>"
+#define HTML_SUFFIX "</p></body></html>"
 
 
 /* 'private'/'protected' functions */
@@ -58,7 +58,9 @@ struct _ModestStreamTextToHtmlPrivate {
        gboolean written_prefix;
        gsize linkify_limit;
        gsize full_limit;
+       gsize line_limit;
        gsize total_output;
+       gsize total_lines_output;
 };
 #define MODEST_STREAM_TEXT_TO_HTML_GET_PRIVATE(o)      (G_TYPE_INSTANCE_GET_PRIVATE((o), \
                                                        MODEST_TYPE_STREAM_TEXT_TO_HTML, \
@@ -125,6 +127,8 @@ modest_stream_text_to_html_init (ModestStreamTextToHtml *obj)
        priv->linkify_limit = 0;
        priv->full_limit = 0;
        priv->total_output = 0;
+       priv->total_lines_output = 0;
+       modest_text_utils_hyperlinkify_begin ();
 }
 
 static void
@@ -139,6 +143,7 @@ modest_stream_text_to_html_finalize (GObject *obj)
        if (priv->line_buffer != NULL) {
                g_string_free (priv->line_buffer, TRUE);
        }
+       modest_text_utils_hyperlinkify_end ();
 }
 
 GObject*
@@ -158,6 +163,13 @@ modest_stream_text_to_html_new (TnyStream *out_stream)
 }
 
 void        
+modest_stream_text_to_html_set_line_limit (ModestStreamTextToHtml *self, gssize limit)
+{
+       ModestStreamTextToHtmlPrivate *priv = MODEST_STREAM_TEXT_TO_HTML_GET_PRIVATE (self);
+       priv->line_limit = limit;
+}
+
+void        
 modest_stream_text_to_html_set_linkify_limit (ModestStreamTextToHtml *self, gssize limit)
 {
        ModestStreamTextToHtmlPrivate *priv = MODEST_STREAM_TEXT_TO_HTML_GET_PRIVATE (self);
@@ -171,6 +183,16 @@ modest_stream_text_to_html_set_full_limit (ModestStreamTextToHtml *self, gssize
        priv->full_limit = limit;
 }
 
+gboolean
+modest_stream_text_to_html_limit_reached (ModestStreamTextToHtml *self)
+{
+       ModestStreamTextToHtmlPrivate *priv = MODEST_STREAM_TEXT_TO_HTML_GET_PRIVATE (self);
+
+       return (priv->full_limit > 0 && priv->total_output > priv->full_limit) ||
+               (priv->line_limit > 0 && priv->total_lines_output > priv->line_limit);
+       
+}
+
 /* the rest are interface functions */
 
 
@@ -193,6 +215,8 @@ write_line (TnyStream *self, const gchar *str, gboolean convert_to_html)
           preserve the prefix and suffix */
        if (convert_to_html && (priv->full_limit > 0) &&(priv->total_output > priv->full_limit))
                return TRUE;
+       if (convert_to_html && (priv->line_limit > 0) && (priv->total_lines_output > priv->line_limit))
+               return TRUE;
        if ((priv->linkify_limit > 0) && (priv->total_output > priv->linkify_limit))
                hyperlinkify = FALSE;
        if (convert_to_html) {
@@ -203,6 +227,7 @@ write_line (TnyStream *self, const gchar *str, gboolean convert_to_html)
 
        pending_bytes = strlen (html_buffer);
        priv->total_output += pending_bytes;
+       priv->total_lines_output ++;
        offset = html_buffer;
 
        while (pending_bytes > 0) {
@@ -240,6 +265,12 @@ text_to_html_write (TnyStream *self, const char *buffer, size_t n)
 
        while (n > 0) {
                gchar c = *buffer;
+
+               if ((priv->full_limit > 0) && (priv->total_output > priv->full_limit))
+                       return n;
+               if ((priv->line_limit > 0) && (priv->total_lines_output > priv->line_limit))
+                       return n;
+
                if (priv->line_buffer == NULL)
                        priv->line_buffer = g_string_new (NULL);
 
@@ -323,11 +354,11 @@ modest_stream_text_to_html_iface_init (gpointer g_iface, gpointer iface_data)
 
        klass = (TnyStreamIface*) g_iface;
        
-        klass->read_func            = text_to_html_read;
-        klass->write_func           = text_to_html_write;
-        klass->flush_func           = text_to_html_flush;
-        klass->close_func           = text_to_html_close;
-       klass->is_eos_func          = text_to_html_is_eos;
-       klass->reset_func           = text_to_html_reset;
-       klass->write_to_stream_func = text_to_html_write_to_stream;
+        klass->read            = text_to_html_read;
+        klass->write           = text_to_html_write;
+        klass->flush           = text_to_html_flush;
+        klass->close           = text_to_html_close;
+       klass->is_eos          = text_to_html_is_eos;
+       klass->reset           = text_to_html_reset;
+       klass->write_to_stream = text_to_html_write_to_stream;
 }