/*
* e-mail-formatter.c
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with the program; if not, see
*
*/
#include "e-mail-formatter.h"
#include
#include "e-mail-formatter-extension.h"
#include "e-mail-formatter-utils.h"
#include "e-mail-part.h"
#include "e-mail-format-extensions.h"
#include
#include
#include
#include
#define d(x)
struct _EMailFormatterPrivate {
EMailImageLoadingPolicy image_loading_policy;
guint only_local_photos : 1;
guint show_sender_photo : 1;
guint show_real_date : 1;
guint animate_images : 1;
gchar *charset;
gchar *default_charset;
GQueue *header_list;
};
#define E_MAIL_FORMATTER_GET_PRIVATE(obj) \
(G_TYPE_INSTANCE_GET_PRIVATE \
((obj), E_TYPE_MAIL_FORMATTER, EMailFormatterPrivate))\
static gpointer e_mail_formatter_parent_class = 0;
enum {
PROP_0,
PROP_BODY_COLOR,
PROP_CITATION_COLOR,
PROP_CONTENT_COLOR,
PROP_FRAME_COLOR,
PROP_HEADER_COLOR,
PROP_TEXT_COLOR,
PROP_IMAGE_LOADING_POLICY,
PROP_FORCE_IMAGE_LOADING,
PROP_MARK_CITATIONS,
PROP_ONLY_LOCAL_PHOTOS,
PROP_SHOW_SENDER_PHOTO,
PROP_SHOW_REAL_DATE,
PROP_ANIMATE_IMAGES,
PROP_CHARSET,
PROP_DEFAULT_CHARSET
};
static void
mail_formatter_run (EMailFormatter *formatter,
EMailFormatterContext *context,
CamelStream *stream,
GCancellable *cancellable)
{
GSList *iter;
gchar *hdr;
hdr = e_mail_formatter_get_html_header (formatter);
camel_stream_write_string (stream, hdr, cancellable, NULL);
g_free (hdr);
for (iter = context->parts; iter; iter = iter->next) {
EMailPart *part;
gboolean ok;
if (g_cancellable_is_cancelled (cancellable))
break;
part = iter->data;
if (!part)
continue;
if (part->is_hidden && !part->is_error) {
if (g_str_has_suffix (part->id, ".rfc822")) {
iter = e_mail_formatter_find_rfc822_end_iter (iter);
}
if (!iter)
break;
continue;
}
/* Force formatting as source if needed */
if (context->mode != E_MAIL_FORMATTER_MODE_SOURCE) {
if (!part->mime_type)
continue;
ok = e_mail_formatter_format_as (
formatter, context, part, stream,
part->mime_type, cancellable);
/* If the written part was message/rfc822 then
* jump to the end of the message, because content
* of the whole message has been formatted by
* message_rfc822 formatter */
if (ok && g_str_has_suffix (part->id, ".rfc822")) {
iter = e_mail_formatter_find_rfc822_end_iter (iter);
if (!iter)
break;
continue;
}
} else {
ok = FALSE;
}
if (!ok) {
/* We don't want to source these */
if (g_str_has_suffix (part->id, ".headers") ||
g_str_has_suffix (part->id, "attachment-bar"))
continue;
e_mail_formatter_format_as (
formatter, context, part, stream,
"application/vnd.evolution.source", cancellable);
/* .message is the entire message. There's nothing more
* to be written. */
if (g_strcmp0 (part->id, ".message") == 0)
break;
/* If we just wrote source of a rfc822 message, then jump
* behind the message (otherwise source of all parts
* would be rendered twice) */
if (g_str_has_suffix (part->id, ".rfc822")) {
do {
part = iter->data;
if (part && g_str_has_suffix (part->id, ".rfc822.end"))
break;
iter = iter->next;
} while (iter);
}
}
}
camel_stream_write_string (stream, "