#include "camel-mime-filter-enriched.h"
#include "camel-string-utils.h"
+#define CAMEL_MIME_FILTER_ENRICHED_GET_PRIVATE(obj) \
+ (G_TYPE_INSTANCE_GET_PRIVATE \
+ ((obj), CAMEL_TYPE_MIME_FILTER_ENRICHED, CamelMimeFilterEnrichedPrivate))
+
+struct _CamelMimeFilterEnrichedPrivate {
+ guint32 flags;
+ gint nofill;
+};
+
/* text/enriched is rfc1896 */
typedef gchar * (*EnrichedParamParser) (const gchar *inptr, gint inlen);
const gchar *enriched;
const gchar *html;
gboolean needs_param;
- EnrichedParamParser parse_param; /* parses *and* validates the input */
+ EnrichedParamParser parse_param; /* parses *and * validates the input */
} enriched_tags[] = {
{ "bold", "<b>", FALSE, NULL },
{ "/bold", "</b>", FALSE, NULL },
static GHashTable *enriched_hash = NULL;
-static void camel_mime_filter_enriched_class_init (CamelMimeFilterEnrichedClass *klass);
-static void camel_mime_filter_enriched_init (CamelMimeFilterEnriched *filter);
-static void camel_mime_filter_enriched_finalize (CamelObject *obj);
-
-static void filter_filter (CamelMimeFilter *filter, const gchar *in, gsize len, gsize prespace,
- gchar **out, gsize *outlen, gsize *outprespace);
-static void filter_complete (CamelMimeFilter *filter, const gchar *in, gsize len, gsize prespace,
- gchar **out, gsize *outlen, gsize *outprespace);
-static void filter_reset (CamelMimeFilter *filter);
-
-static CamelMimeFilterClass *parent_class = NULL;
-
-CamelType
-camel_mime_filter_enriched_get_type (void)
-{
- static CamelType type = CAMEL_INVALID_TYPE;
-
- if (type == CAMEL_INVALID_TYPE) {
- type = camel_type_register (camel_mime_filter_get_type (),
- "CamelMimeFilterEnriched",
- sizeof (CamelMimeFilterEnriched),
- sizeof (CamelMimeFilterEnrichedClass),
- (CamelObjectClassInitFunc) camel_mime_filter_enriched_class_init,
- NULL,
- (CamelObjectInitFunc) camel_mime_filter_enriched_init,
- (CamelObjectFinalizeFunc) camel_mime_filter_enriched_finalize);
- }
-
- return type;
-}
-
-static void
-camel_mime_filter_enriched_class_init (CamelMimeFilterEnrichedClass *klass)
-{
- CamelMimeFilterClass *filter_class = (CamelMimeFilterClass *) klass;
- gint i;
-
- parent_class = CAMEL_MIME_FILTER_CLASS (camel_mime_filter_get_type ());
-
- filter_class->reset = filter_reset;
- filter_class->filter = filter_filter;
- filter_class->complete = filter_complete;
-
- if (!enriched_hash) {
- enriched_hash = g_hash_table_new (camel_strcase_hash, camel_strcase_equal);
- for (i = 0; i < G_N_ELEMENTS (enriched_tags); i++)
- g_hash_table_insert (
- enriched_hash,
- (gpointer) enriched_tags[i].enriched,
- (gpointer) enriched_tags[i].html);
- }
-}
-
-static void
-camel_mime_filter_enriched_finalize (CamelObject *obj)
-{
- ;
-}
-
-static void
-camel_mime_filter_enriched_init (CamelMimeFilterEnriched *filter)
-{
- filter->flags = 0;
- filter->nofill = 0;
-}
+G_DEFINE_TYPE (CamelMimeFilterEnriched, camel_mime_filter_enriched, CAMEL_TYPE_MIME_FILTER)
#if 0
static gboolean
};
static gchar *
-param_parse_color (const gchar *inptr, gint inlen)
+param_parse_color (const gchar *inptr,
+ gint inlen)
{
const gchar *inend, *end;
guint32 rgb = 0;
}
static gchar *
-param_parse_font (const gchar *fontfamily, gint inlen)
+param_parse_font (const gchar *fontfamily,
+ gint inlen)
{
register const gchar *inptr = fontfamily;
const gchar *inend = inptr + inlen;
}
static gchar *
-param_parse_lang (const gchar *lang, gint inlen)
+param_parse_lang (const gchar *lang,
+ gint inlen)
{
register const gchar *inptr = lang;
const gchar *inend = inptr + inlen;
}
static gchar *
-param_parse (const gchar *enriched, const gchar *inptr, gint inlen)
+param_parse (const gchar *enriched,
+ const gchar *inptr,
+ gint inlen)
{
gint i;
#define IS_RICHTEXT CAMEL_MIME_FILTER_ENRICHED_IS_RICHTEXT
static void
-enriched_to_html (CamelMimeFilter *filter, const gchar *in, gsize inlen, gsize prespace,
- gchar **out, gsize *outlen, gsize *outprespace, gboolean flush)
+enriched_to_html (CamelMimeFilter *mime_filter,
+ const gchar *in,
+ gsize inlen,
+ gsize prespace,
+ gchar **out,
+ gsize *outlen,
+ gsize *outprespace,
+ gboolean flush)
{
- CamelMimeFilterEnriched *enriched = (CamelMimeFilterEnriched *) filter;
+ CamelMimeFilterEnrichedPrivate *priv;
const gchar *tag, *inend, *outend;
register const gchar *inptr;
register gchar *outptr;
- camel_mime_filter_set_size (filter, inlen * 2 + 6, FALSE);
+ priv = CAMEL_MIME_FILTER_ENRICHED_GET_PRIVATE (mime_filter);
+
+ camel_mime_filter_set_size (mime_filter, inlen * 2 + 6, FALSE);
inptr = in;
inend = in + inlen;
- outptr = filter->outbuf;
- outend = filter->outbuf + filter->outsize;
+ outptr = mime_filter->outbuf;
+ outend = mime_filter->outbuf + mime_filter->outsize;
retry:
do {
break;
case '\n':
- if (!(enriched->flags & IS_RICHTEXT)) {
+ if (!(priv->flags & IS_RICHTEXT)) {
/* text/enriched */
- if (enriched->nofill > 0) {
+ if (priv->nofill > 0) {
if ((outptr + 4) < outend) {
memcpy (outptr, "<br>", 4);
outptr += 4;
}
break;
case '<':
- if (!(enriched->flags & IS_RICHTEXT)) {
+ if (!(priv->flags & IS_RICHTEXT)) {
/* text/enriched */
if (*inptr == '<') {
if ((outptr + 4) < outend) {
if (!g_ascii_strncasecmp (tag, "nofill>", 7)) {
if ((outptr + 5) < outend) {
- enriched->nofill++;
+ priv->nofill++;
} else {
inptr = tag - 1;
goto backup;
}
} else if (!g_ascii_strncasecmp (tag, "/nofill>", 8)) {
if ((outptr + 6) < outend) {
- enriched->nofill--;
+ priv->nofill--;
} else {
inptr = tag - 1;
goto backup;
need_input:
/* the reason we ignore @flush here is because if there isn't
- enough input to parse a tag, then there's nothing we can
- do. */
+ * enough input to parse a tag, then there's nothing we can
+ * do. */
if (inptr < inend)
- camel_mime_filter_backup (filter, inptr, (unsigned) (inend - inptr));
+ camel_mime_filter_backup (mime_filter, inptr, (unsigned) (inend - inptr));
- *out = filter->outbuf;
- *outlen = outptr - filter->outbuf;
- *outprespace = filter->outpre;
+ *out = mime_filter->outbuf;
+ *outlen = outptr - mime_filter->outbuf;
+ *outprespace = mime_filter->outpre;
return;
gsize offset, grow;
grow = (inend - inptr) * 2 + 20;
- offset = outptr - filter->outbuf;
- camel_mime_filter_set_size (filter, filter->outsize + grow, TRUE);
- outend = filter->outbuf + filter->outsize;
- outptr = filter->outbuf + offset;
+ offset = outptr - mime_filter->outbuf;
+ camel_mime_filter_set_size (mime_filter, mime_filter->outsize + grow, TRUE);
+ outend = mime_filter->outbuf + mime_filter->outsize;
+ outptr = mime_filter->outbuf + offset;
goto retry;
} else {
- camel_mime_filter_backup (filter, inptr, (unsigned) (inend - inptr));
+ camel_mime_filter_backup (mime_filter, inptr, (unsigned) (inend - inptr));
}
- *out = filter->outbuf;
- *outlen = outptr - filter->outbuf;
- *outprespace = filter->outpre;
+ *out = mime_filter->outbuf;
+ *outlen = outptr - mime_filter->outbuf;
+ *outprespace = mime_filter->outpre;
}
static void
-filter_filter (CamelMimeFilter *filter, const gchar *in, gsize len, gsize prespace,
- gchar **out, gsize *outlen, gsize *outprespace)
+mime_filter_enriched_filter (CamelMimeFilter *mime_filter,
+ const gchar *in,
+ gsize len,
+ gsize prespace,
+ gchar **out,
+ gsize *outlen,
+ gsize *outprespace)
{
- enriched_to_html (filter, in, len, prespace, out, outlen, outprespace, FALSE);
+ enriched_to_html (
+ mime_filter, in, len, prespace,
+ out, outlen, outprespace, FALSE);
}
static void
-filter_complete (CamelMimeFilter *filter, const gchar *in, gsize len, gsize prespace,
- gchar **out, gsize *outlen, gsize *outprespace)
+mime_filter_enriched_complete (CamelMimeFilter *mime_filter,
+ const gchar *in,
+ gsize len,
+ gsize prespace,
+ gchar **out,
+ gsize *outlen,
+ gsize *outprespace)
{
- enriched_to_html (filter, in, len, prespace, out, outlen, outprespace, TRUE);
+ enriched_to_html (
+ mime_filter, in, len, prespace,
+ out, outlen, outprespace, TRUE);
+}
+
+static void
+mime_filter_enriched_reset (CamelMimeFilter *mime_filter)
+{
+ CamelMimeFilterEnrichedPrivate *priv;
+
+ priv = CAMEL_MIME_FILTER_ENRICHED_GET_PRIVATE (mime_filter);
+
+ priv->nofill = 0;
}
static void
-filter_reset (CamelMimeFilter *filter)
+camel_mime_filter_enriched_class_init (CamelMimeFilterEnrichedClass *class)
{
- CamelMimeFilterEnriched *enriched = (CamelMimeFilterEnriched *) filter;
+ CamelMimeFilterClass *mime_filter_class;
+ gint i;
+
+ g_type_class_add_private (class, sizeof (CamelMimeFilterEnrichedPrivate));
- enriched->nofill = 0;
+ mime_filter_class = CAMEL_MIME_FILTER_CLASS (class);
+ mime_filter_class->filter = mime_filter_enriched_filter;
+ mime_filter_class->complete = mime_filter_enriched_complete;
+ mime_filter_class->reset = mime_filter_enriched_reset;
+
+ enriched_hash = g_hash_table_new (
+ camel_strcase_hash, camel_strcase_equal);
+ for (i = 0; i < G_N_ELEMENTS (enriched_tags); i++)
+ g_hash_table_insert (
+ enriched_hash,
+ (gpointer) enriched_tags[i].enriched,
+ (gpointer) enriched_tags[i].html);
+}
+
+static void
+camel_mime_filter_enriched_init (CamelMimeFilterEnriched *filter)
+{
+ filter->priv = CAMEL_MIME_FILTER_ENRICHED_GET_PRIVATE (filter);
}
/**
CamelMimeFilter *
camel_mime_filter_enriched_new (guint32 flags)
{
- CamelMimeFilterEnriched *new;
+ CamelMimeFilter *new;
+ CamelMimeFilterEnrichedPrivate *priv;
+
+ new = g_object_new (CAMEL_TYPE_MIME_FILTER_ENRICHED, NULL);
+ priv = CAMEL_MIME_FILTER_ENRICHED_GET_PRIVATE (new);
- new = (CamelMimeFilterEnriched *) camel_object_new (CAMEL_TYPE_MIME_FILTER_ENRICHED);
- new->flags = flags;
+ priv->flags = flags;
- return CAMEL_MIME_FILTER (new);
+ return new;
}
/**
* richtext version of @in.
**/
gchar *
-camel_enriched_to_html(const gchar *in, guint32 flags)
+camel_enriched_to_html (const gchar *in,
+ guint32 flags)
{
CamelMimeFilter *filter;
gsize outlen, outpre;
if (in == NULL)
return NULL;
- filter = camel_mime_filter_enriched_new(flags);
+ filter = camel_mime_filter_enriched_new (flags);
- camel_mime_filter_complete(filter, (gchar *)in, strlen(in), 0, &outbuf, &outlen, &outpre);
+ camel_mime_filter_complete (filter, (gchar *) in, strlen (in), 0, &outbuf, &outlen, &outpre);
outbuf = g_strndup (outbuf, outlen);
- camel_object_unref (filter);
+ g_object_unref (filter);
return outbuf;
}