aboutsummaryrefslogtreecommitdiffstats
path: root/mail
diff options
context:
space:
mode:
authorJeffrey Stedfast <fejj@ximian.com>2004-02-24 03:09:58 +0800
committerJeffrey Stedfast <fejj@src.gnome.org>2004-02-24 03:09:58 +0800
commit82c5c5915254d42b1a3ab34aa9b1a841ea41b56e (patch)
tree84e487360dba4c7fb06cff929a4ecd204d512810 /mail
parent0343b45ce165c32278b41e8b371946526eca6f3a (diff)
downloadgsoc2013-evolution-82c5c5915254d42b1a3ab34aa9b1a841ea41b56e.tar
gsoc2013-evolution-82c5c5915254d42b1a3ab34aa9b1a841ea41b56e.tar.gz
gsoc2013-evolution-82c5c5915254d42b1a3ab34aa9b1a841ea41b56e.tar.bz2
gsoc2013-evolution-82c5c5915254d42b1a3ab34aa9b1a841ea41b56e.tar.lz
gsoc2013-evolution-82c5c5915254d42b1a3ab34aa9b1a841ea41b56e.tar.xz
gsoc2013-evolution-82c5c5915254d42b1a3ab34aa9b1a841ea41b56e.tar.zst
gsoc2013-evolution-82c5c5915254d42b1a3ab34aa9b1a841ea41b56e.zip
Print the headers when forwarding inline/quoted. Fixes bug #53916.
2004-02-23 Jeffrey Stedfast <fejj@ximian.com> * em-format-quote.c (emfq_format_message): Print the headers when forwarding inline/quoted. Fixes bug #53916. svn path=/trunk/; revision=24833
Diffstat (limited to 'mail')
-rw-r--r--mail/ChangeLog3
-rw-r--r--mail/em-format-quote.c214
2 files changed, 211 insertions, 6 deletions
diff --git a/mail/ChangeLog b/mail/ChangeLog
index 296a18bd7a..2e2e059c6f 100644
--- a/mail/ChangeLog
+++ b/mail/ChangeLog
@@ -1,5 +1,8 @@
2004-02-23 Jeffrey Stedfast <fejj@ximian.com>
+ * em-format-quote.c (emfq_format_message): Print the headers when
+ forwarding inline/quoted. Fixes bug #53916.
+
* em-folder-tree.c (tree_drag_motion): We want UID_LISTs to drop
with the MOVE action by default. Fixes a common complaint from
IRC.
diff --git a/mail/em-format-quote.c b/mail/em-format-quote.c
index 3d242c0956..c0b7855f58 100644
--- a/mail/em-format-quote.c
+++ b/mail/em-format-quote.c
@@ -30,6 +30,12 @@
#include <camel/camel-stream-filter.h>
#include <camel/camel-mime-filter-tohtml.h>
#include <camel/camel-mime-filter-enriched.h>
+#include <camel/camel-string-utils.h>
+#include <camel/camel-mime-message.h>
+#include <camel/camel-url.h>
+
+#include <gal/util/e-iconv.h>
+
#include "em-format-quote.h"
struct _EMFormatQuotePrivate {
@@ -147,6 +153,203 @@ emfq_format_error(EMFormat *emf, CamelStream *stream, const char *txt)
}
static void
+emfq_format_text_header (EMFormatQuote *emfq, CamelStream *stream, const char *label, const char *value, guint32 flags, int is_html)
+{
+ const char *fmt, *html;
+ char *mhtml = NULL;
+
+ if (value == NULL)
+ return;
+
+ while (*value == ' ')
+ value++;
+
+ if (!is_html)
+ html = mhtml = camel_text_to_html (value, 0, 0);
+ else
+ html = value;
+
+ if (flags & EM_FORMAT_HEADER_BOLD)
+ fmt = "<b>%s</b>: %s<br>";
+ else
+ fmt = "%s: %s<br>";
+
+ camel_stream_printf (stream, fmt, label, html);
+ g_free (mhtml);
+}
+
+static char *addrspec_hdrs[] = {
+ "sender", "from", "reply-to", "to", "cc", "bcc",
+ "resent-sender", "resent-from", "resent-reply-to",
+ "resent-to", "resent-cc", "resent-bcc", NULL
+};
+
+#if 0
+/* FIXME: include Sender and Resent-* headers too? */
+/* For Translators only: The following strings are used in the header table in the preview pane */
+static char *i18n_hdrs[] = {
+ N_("From"), N_("Reply-To"), N_("To"), N_("Cc"), N_("Bcc")
+};
+#endif
+
+static void
+emfq_format_address (GString *out, struct _camel_header_address *a)
+{
+ guint32 flags = CAMEL_MIME_FILTER_TOHTML_CONVERT_SPACES;
+ char *name, *mailto, *addr;
+
+ while (a) {
+ if (a->name)
+ name = camel_text_to_html (a->name, flags, 0);
+ else
+ name = NULL;
+
+ switch (a->type) {
+ case CAMEL_HEADER_ADDRESS_NAME:
+ if (name && *name) {
+ char *real, *mailaddr;
+
+ g_string_append_printf (out, "%s &lt;", name);
+ /* rfc2368 for mailto syntax and url encoding extras */
+ real = camel_header_encode_phrase (a->name);
+ mailaddr = g_strdup_printf ("%s <%s>", real, a->v.addr);
+ g_free (real);
+ mailto = camel_url_encode (mailaddr, "?=&()");
+ g_free (mailaddr);
+ } else {
+ mailto = camel_url_encode (a->v.addr, "?=&()");
+ }
+ addr = camel_text_to_html (a->v.addr, flags, 0);
+ g_string_append_printf (out, "<a href=\"mailto:%s\">%s</a>", mailto, addr);
+ g_free (mailto);
+ g_free (addr);
+
+ if (name && *name)
+ g_string_append (out, "&gt;");
+ break;
+ case CAMEL_HEADER_ADDRESS_GROUP:
+ g_string_append_printf (out, "%s: ", name);
+ emfq_format_address (out, a->v.members);
+ g_string_append_printf (out, ";");
+ break;
+ default:
+ g_warning ("Invalid address type");
+ break;
+ }
+
+ g_free (name);
+
+ a = a->next;
+ if (a)
+ g_string_append (out, ", ");
+ }
+}
+
+static void
+emfq_format_header (EMFormat *emf, CamelStream *stream, CamelMedium *part, const char *namein, guint32 flags, const char *charset)
+{
+ CamelMimeMessage *msg = (CamelMimeMessage *) part;
+ EMFormatQuote *emfq = (EMFormatQuote *) emf;
+ char *name, *value = NULL, *p;
+ const char *txt, *label;
+ int addrspec = 0, i;
+ int is_html = FALSE;
+
+ name = g_alloca (strlen (namein) + 1);
+ strcpy (name, namein);
+ camel_strdown (name);
+
+ for (i = 0; addrspec_hdrs[i]; i++) {
+ if (!strcmp (name, addrspec_hdrs[i])) {
+ addrspec = 1;
+ break;
+ }
+ }
+
+ if (addrspec) {
+ struct _camel_header_address *addrs;
+ GString *html;
+
+ if (!(txt = camel_medium_get_header (part, name)))
+ return;
+
+ if (!(addrs = camel_header_address_decode (txt, emf->charset ? emf->charset : emf->default_charset)))
+ return;
+
+ /* canonicalise the header name... first letter is
+ * capitalised and any letter following a '-' also gets
+ * capitalised */
+ p = name;
+ *p -= 0x20;
+ do {
+ p++;
+ if (p[-1] == '-' && *p >= 'a' && *p <= 'z')
+ *p -= 0x20;
+ } while (*p);
+
+ label = _(name);
+
+ html = g_string_new ("");
+ emfq_format_address (html, addrs);
+ camel_header_address_unref (addrs);
+ txt = value = html->str;
+ g_string_free (html, FALSE);
+ flags |= EM_FORMAT_HEADER_BOLD;
+ is_html = TRUE;
+ } else if (!strcmp (name, "subject")) {
+ txt = camel_mime_message_get_subject (msg);
+ label = _("Subject");
+ flags |= EM_FORMAT_HEADER_BOLD;
+ } else if (!strcmp (name, "x-evolution-mailer")) { /* pseudo-header */
+ if (!(txt = camel_medium_get_header (part, "x-mailer")))
+ if (!(txt = camel_medium_get_header (part, "user-agent")))
+ return;
+
+ label = _("Mailer");
+ flags |= EM_FORMAT_HEADER_BOLD;
+ } else if (!strcmp (name, "date") || !strcmp (name, "resent-date")) {
+ if (!(txt = camel_medium_get_header (part, name)))
+ return;
+
+ if (!strcmp (name, "date"))
+ label = _("Date");
+ else
+ label = "Resent-Date";
+
+ flags |= EM_FORMAT_HEADER_BOLD;
+ } else {
+ txt = camel_medium_get_header (part, name);
+ value = camel_header_decode_string (txt, charset);
+ txt = value;
+ label = namein;
+ }
+
+ emfq_format_text_header (emfq, stream, label, txt, flags, is_html);
+
+ g_free (value);
+}
+
+static void
+emfq_format_headers (EMFormatQuote *emfq, CamelStream *stream, CamelMedium *part)
+{
+ EMFormat *emf = (EMFormat *) emfq;
+ CamelContentType *ct;
+ const char *charset;
+ EMFormatHeader *h;
+
+ ct = camel_mime_part_get_content_type ((CamelMimePart *) part);
+ charset = camel_content_type_param (ct, "charset");
+ charset = e_iconv_charset_name (charset);
+
+ /* dump selected headers */
+ h = (EMFormatHeader *) emf->header_list.head;
+ while (h->next) {
+ emfq_format_header (emf, stream, part, h->name, h->flags, charset);
+ h = h->next;
+ }
+}
+
+static void
emfq_format_message(EMFormat *emf, CamelStream *stream, CamelMedium *part)
{
EMFormatQuote *emfq = (EMFormatQuote *) emf;
@@ -160,12 +363,11 @@ emfq_format_message(EMFormat *emf, CamelStream *stream, CamelMedium *part)
"<font color=\"#%06x\">\n",
emfq->citation_colour & 0xffffff);
- if (emfq->flags & EM_FORMAT_QUOTE_HEADERS) {
- camel_stream_printf(stream, "<b>To: </b> Header goes here<br>");
- }
-
- em_format_part(emf, stream, (CamelMimePart *)part);
-
+ if (emfq->flags & EM_FORMAT_QUOTE_HEADERS)
+ emfq_format_headers (emfq, stream, part);
+
+ em_format_part (emf, stream, (CamelMimePart *) part);
+
if (emfq->flags & EM_FORMAT_QUOTE_CITE)
camel_stream_write_string(stream, "</blockquote></font><!--+GtkHTML:<DATA class=\"ClueFlow\" clear=\"orig\">-->");
}