* Reworked the quote code to add attachmetns list.
This should make attachments be shown on replying
messages (fixes NB#58194).
* Reworked the quote methods, to be more compliant
to specs.
* src/modest-tny-msg.c, src/modest-formatter.[ch]:
* Proper changes to pass the attachments list to the
code that creates the quoted messages. It's used
for showing the attachments names in replies including
the original message.
pmo-trunk-r2241
static GObjectClass *parent_class = NULL;
-typedef gchar* FormatterFunc (ModestFormatter *self, const gchar *text, TnyHeader *header);
+typedef gchar* FormatterFunc (ModestFormatter *self, const gchar *text, TnyHeader *header, GList *attachments);
static TnyMsg *modest_formatter_do (ModestFormatter *self, TnyMimePart *body, TnyHeader *header,
- FormatterFunc func, gboolean has_attachments);
+ FormatterFunc func, GList *attachments);
-static gchar* modest_formatter_wrapper_cite (ModestFormatter *self, const gchar *text, TnyHeader *header);
-static gchar* modest_formatter_wrapper_quote (ModestFormatter *self, const gchar *text, TnyHeader *header);
-static gchar* modest_formatter_wrapper_inline (ModestFormatter *self, const gchar *text, TnyHeader *header);
+static gchar* modest_formatter_wrapper_cite (ModestFormatter *self, const gchar *text, TnyHeader *header, GList *attachments);
+static gchar* modest_formatter_wrapper_quote (ModestFormatter *self, const gchar *text, TnyHeader *header, GList *attachments);
+static gchar* modest_formatter_wrapper_inline (ModestFormatter *self, const gchar *text, TnyHeader *header, GList *attachments);
static gchar *
extract_text (ModestFormatter *self, TnyMimePart *body)
}
static TnyMsg *
-modest_formatter_do (ModestFormatter *self, TnyMimePart *body, TnyHeader *header, FormatterFunc func, gboolean has_attachments)
+modest_formatter_do (ModestFormatter *self, TnyMimePart *body, TnyHeader *header, FormatterFunc func, GList *attachments)
{
TnyMsg *new_msg = NULL;
gchar *body_text = NULL, *txt = NULL;
g_return_val_if_fail (func, NULL);
/* Build new part */
- new_msg = modest_formatter_create_message (self, TRUE, has_attachments);
+ new_msg = modest_formatter_create_message (self, TRUE, attachments != NULL);
body_part = modest_formatter_create_body_part (self, new_msg);
if (body)
else
body_text = g_strdup ("");
- txt = (gchar *) func (self, (const gchar*) body_text, header);
+ txt = (gchar *) func (self, (const gchar*) body_text, header, attachments);
priv = MODEST_FORMATTER_GET_PRIVATE (self);
construct_from_text (TNY_MIME_PART (body_part), (const gchar*) txt, priv->content_type);
g_object_unref (body_part);
TnyMsg *
modest_formatter_cite (ModestFormatter *self, TnyMimePart *body, TnyHeader *header)
{
- return modest_formatter_do (self, body, header, modest_formatter_wrapper_cite, FALSE);
+ return modest_formatter_do (self, body, header, modest_formatter_wrapper_cite, NULL);
}
TnyMsg *
-modest_formatter_quote (ModestFormatter *self, TnyMimePart *body, TnyHeader *header)
+modest_formatter_quote (ModestFormatter *self, TnyMimePart *body, TnyHeader *header, GList *attachments)
{
- return modest_formatter_do (self, body, header, modest_formatter_wrapper_quote, FALSE);
+ return modest_formatter_do (self, body, header, modest_formatter_wrapper_quote, attachments);
}
TnyMsg *
-modest_formatter_inline (ModestFormatter *self, TnyMimePart *body, TnyHeader *header, gboolean has_attachments)
+modest_formatter_inline (ModestFormatter *self, TnyMimePart *body, TnyHeader *header, GList *attachments)
{
- return modest_formatter_do (self, body, header, modest_formatter_wrapper_inline, has_attachments);
+ return modest_formatter_do (self, body, header, modest_formatter_wrapper_inline, attachments);
}
TnyMsg *
/****************/
static gchar *
-modest_formatter_wrapper_cite (ModestFormatter *self, const gchar *text, TnyHeader *header)
+modest_formatter_wrapper_cite (ModestFormatter *self, const gchar *text, TnyHeader *header, GList *attachments)
{
ModestFormatterPrivate *priv = MODEST_FORMATTER_GET_PRIVATE (self);
}
static gchar *
-modest_formatter_wrapper_inline (ModestFormatter *self, const gchar *text, TnyHeader *header)
+modest_formatter_wrapper_inline (ModestFormatter *self, const gchar *text, TnyHeader *header, GList *attachments)
{
ModestFormatterPrivate *priv = MODEST_FORMATTER_GET_PRIVATE (self);
}
static gchar *
-modest_formatter_wrapper_quote (ModestFormatter *self, const gchar *text, TnyHeader *header)
+modest_formatter_wrapper_quote (ModestFormatter *self, const gchar *text, TnyHeader *header, GList *attachments)
{
ModestFormatterPrivate *priv = MODEST_FORMATTER_GET_PRIVATE (self);
+ GList *filenames = NULL;
+ GList *node = NULL;
+ gchar *result = NULL;
+
+ /* First we need a GList of attachments filenames */
+ for (node = attachments; node != NULL; node = g_list_next (node)) {
+ TnyMimePart *part = (TnyMimePart *) node->data;
+ gchar *filename = NULL;
+ if (TNY_IS_MSG (part)) {
+ TnyHeader *header = tny_msg_get_header (TNY_MSG (part));
+ filename = g_strdup (tny_header_get_subject (header));
+ if ((filename == NULL)||(filename[0] == '\0')) {
+ g_free (filename);
+ filename = g_strdup (_("mail_va_no_subject"));
+ }
+ g_object_unref (header);
+ } else {
+ filename = g_strdup (tny_mime_part_get_filename (part));
+ if ((filename == NULL)||(filename[0] == '\0'))
+ filename = g_strdup ("");
+ }
+ filenames = g_list_append (filenames, filename);
+ }
+ filenames = g_list_reverse (filenames);
/* TODO: get 80 from the configuration */
- return modest_text_utils_quote (text,
- priv->content_type,
- priv->signature,
- tny_header_get_from (header),
- tny_header_get_date_sent (header),
- 80);
+ result = modest_text_utils_quote (text,
+ priv->content_type,
+ priv->signature,
+ tny_header_get_from (header),
+ tny_header_get_date_sent (header),
+ filenames,
+ 80);
+
+ g_list_foreach (filenames, (GFunc) g_free, NULL);
+ g_list_free (filenames);
+ return result;
}
TnyMsg *
* @self: a #ModestFormatter
* @part: a non-NULL #TnyMimePart with the body of the original message
* @header: a non-NULL #TnyHeader of the original message
+ * @attachments: a #GList of attachments in original message
*
* Creates a new message with a text body made from the body of the
* original message quoted. This function is locale-sensitive.
* Quoted message
* -------------
* Body:
- * On 1970/01/01 somemailATmodest.org wrote:
+ * ------ Original message -----
* > This is the body of the text
+ * > Attachment: file1.txt
* </para></programlisting>
*
* Returns: a newly formatted #TnyMsg or NULL in case of error
**/
-TnyMsg * modest_formatter_quote (ModestFormatter *self, TnyMimePart *part, TnyHeader *header);
+TnyMsg * modest_formatter_quote (ModestFormatter *self, TnyMimePart *part, TnyHeader *header, GList *attachments);
/**
* @self: a #ModestFormatter
* @part: a non-NULL #TnyMimePart with the body of the original message
* @header: a non-NULL #TnyHeader of the original message
+ * @attachments: a #GList of attachments
*
* Creates a new message with a text body made from the body of the
* original message inlined ready to be forwarded. This function is
*
* Returns: a newly formatted #TnyMsg or NULL in case of error
**/
-TnyMsg * modest_formatter_inline (ModestFormatter *self, TnyMimePart *part, TnyHeader *header, gboolean has_attachments);
+TnyMsg * modest_formatter_inline (ModestFormatter *self, TnyMimePart *part, TnyHeader *header, GList *attachments);
/**
* modest_formatter_attach:
static gchar* modest_text_utils_quote_plain_text (const gchar *text,
const gchar *cite,
const gchar *signature,
+ GList *attachments,
int limit);
static gchar* modest_text_utils_quote_html (const gchar *text,
const gchar *cite,
const gchar *signature,
+ GList *attachments,
int limit);
static gchar* get_email_from_address (const gchar *address);
const gchar *signature,
const gchar *from,
const time_t sent_date,
+ GList *attachments,
int limit)
{
gchar *retval, *cited;
if (content_type && strcmp (content_type, "text/html") == 0)
/* TODO: extract the <body> of the HTML and pass it to
the function */
- retval = modest_text_utils_quote_html (text, cited, signature, limit);
+ retval = modest_text_utils_quote_html (text, cited, signature, attachments, limit);
else
- retval = modest_text_utils_quote_plain_text (text, cited, signature, limit);
+ retval = modest_text_utils_quote_plain_text (text, cited, signature, attachments, limit);
g_free (cited);
case '\t' : g_string_append (html, " "); break; /* note the space at the end*/
case ' ':
if (space_seen) { /* second space in a row */
- g_string_append (html, "  ");
+ g_string_append (html, " ");
space_seen = FALSE;
} else
space_seen = TRUE;
static gchar *
cite (const time_t sent_date, const gchar *from)
{
- gchar sent_str[101];
-
- /* format sent_date */
- modest_text_utils_strftime (sent_str, 100, "%c", sent_date);
- return g_strdup_printf (N_("On %s, %s wrote:\n"),
- sent_str,
- (from) ? from : EMPTY_STRING);
+ return g_strdup (_("mcen_ia_editor_original_message"));
}
+static gchar *
+quoted_attachments (GList *attachments)
+{
+ GList *node = NULL;
+ GString *result = g_string_new ("");
+ for (node = attachments; node != NULL; node = g_list_next (node)) {
+ gchar *filename = (gchar *) node->data;
+ g_string_append_printf ( result, "%s %s\n", _("mcen_ia_editor_attach_filename"), filename);
+ }
+
+ return g_string_free (result, FALSE);
+
+}
static gchar *
modest_text_utils_quote_plain_text (const gchar *text,
const gchar *cite,
const gchar *signature,
+ GList *attachments,
int limit)
{
const gchar *iter;
gint indent, breakpoint, rem_indent = 0;
GString *q, *l, *remaining;
gsize len;
+ gchar *attachments_string = NULL;
/* remaining will store the rest of the line if we have to break it */
- q = g_string_new (cite);
+ q = g_string_new ("\n");
+ q = g_string_append (q, cite);
+ q = g_string_append_c (q, '\n');
remaining = g_string_new ("");
iter = text;
g_string_free (l, TRUE);
} while ((iter < text + len) || (remaining->str[0]));
+ attachments_string = quoted_attachments (attachments);
+ q = g_string_append (q, attachments_string);
+ g_free (attachments_string);
+
if (signature != NULL) {
q = g_string_append_c (q, '\n');
q = g_string_append (q, signature);
modest_text_utils_quote_html (const gchar *text,
const gchar *cite,
const gchar *signature,
+ GList *attachments,
int limit)
{
gchar *result = NULL;
"<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n" \
"<html>\n" \
"<body>\n" \
- "%s" \
- "<blockquote type=\"cite\">\n%s\n</blockquote>\n" \
- "%s" \
+ "<br/>%s<br/>" \
+ "<pre>%s<br/>%s<br/>%s</pre>\n" \
"</body>\n" \
"</html>\n";
- const gchar *signature_format = \
- "<pre>\n" \
- "%s\n" \
- "</pre>";
+ gchar *attachments_string = NULL;
+ gchar *q_attachments_string = NULL;
+ gchar *html_text = NULL;
if (signature == NULL)
signature_result = g_strdup ("");
else
- signature_result = g_strdup_printf (signature_format, signature);
-
- result = g_strdup_printf (format, cite, text, signature_result);
+ signature_result = modest_text_utils_convert_to_html_body (signature);
+
+ attachments_string = quoted_attachments (attachments);
+ q_attachments_string = modest_text_utils_convert_to_html_body (attachments_string);
+ html_text = modest_text_utils_convert_to_html_body (text);
+ result = g_strdup_printf (format, signature_result, cite, html_text, q_attachments_string);
+ g_free (html_text);
+ g_free (attachments_string);
+ g_free (q_attachments_string);
g_free (signature_result);
return result;
}
* @content_type: the non-NULL content type for the quoting, e.g. "text/html"
* @signature: NULL or the signature to add
* @sent_date: sent date/time of the original message
+ * @attachments: a #GList of the attachments
* @limit: specifies the maximum characters per line in the quoted text
*
* quote an existing message
const gchar *signature,
const gchar *from,
const time_t sent_date,
+ GList *attachments,
int limit);
static TnyMsg *
create_reply_forward_mail (TnyMsg *msg, const gchar *from, const gchar *signature,
- gboolean is_reply, guint type, gboolean has_attachments)
+ gboolean is_reply, guint type, GList *attachments)
{
TnyMsg *new_msg;
TnyHeader *new_header, *header;
new_msg = modest_formatter_cite (formatter, body, header);
break;
case MODEST_TNY_MSG_REPLY_TYPE_QUOTE:
- new_msg = modest_formatter_quote (formatter, body, header);
+ new_msg = modest_formatter_quote (formatter, body, header, attachments);
break;
}
} else {
switch (type) {
case MODEST_TNY_MSG_FORWARD_TYPE_INLINE:
default:
- new_msg = modest_formatter_inline (formatter, body, header, has_attachments);
+ new_msg = modest_formatter_inline (formatter, body, header, attachments);
break;
case MODEST_TNY_MSG_FORWARD_TYPE_ATTACHMENT:
new_msg = modest_formatter_attach (formatter, body, header);
TnyList *parts = NULL;
GList *attachments_list = NULL;
-
/* Add attachments */
parts = TNY_LIST (tny_simple_list_new());
tny_mime_part_get_parts (TNY_MIME_PART (msg), parts);
tny_list_foreach (parts, add_if_attachment, &attachments_list);
- new_msg = create_reply_forward_mail (msg, from, signature, FALSE, forward_type, (attachments_list != NULL));
+ new_msg = create_reply_forward_mail (msg, from, signature, FALSE, forward_type, attachments_list);
add_attachments (new_msg, attachments_list);
/* Clean */
gchar *new_cc = NULL;
const gchar *cc = NULL, *bcc = NULL;
GString *tmp = NULL;
+ TnyList *parts = NULL;
+ GList *attachments_list = NULL;
- new_msg = create_reply_forward_mail (msg, from, signature, TRUE, reply_type, FALSE);
+ /* Add attachments */
+ parts = TNY_LIST (tny_simple_list_new());
+ tny_mime_part_get_parts (TNY_MIME_PART (msg), parts);
+ tny_list_foreach (parts, add_if_attachment, &attachments_list);
+
+ new_msg = create_reply_forward_mail (msg, from, signature, TRUE, reply_type, attachments_list);
+ if (attachments_list) {
+ g_list_foreach (attachments_list, (GFunc) g_object_unref, NULL);
+ g_list_free (attachments_list);
+ }
+ g_object_unref (G_OBJECT (parts));
/* Fill the header */
header = tny_msg_get_header (msg);