From 749d0bd1eb364a5efc52d2f0a0b4b7731c9332ba Mon Sep 17 00:00:00 2001 From: hiro Date: Tue, 25 Oct 2005 07:17:54 +0000 Subject: match the output header for printing to the message view. git-svn-id: svn://sylpheed.sraoss.jp/sylpheed/trunk@679 ee746299-78ed-0310-b773-934348b2243d --- libsylph/Makefile.am | 1 + libsylph/displayheader.c | 59 +++++++++++++++++++++++++++++++++++++++++++++ libsylph/displayheader.h | 37 ++++++++++++++++++++++++++++ libsylph/procheader.c | 47 ++++++++++++++++++++++++++++++++++++ libsylph/procheader.h | 3 +++ libsylph/procmsg.c | 63 +++++++++++++++++++++++++++++++++++------------- 6 files changed, 193 insertions(+), 17 deletions(-) create mode 100644 libsylph/displayheader.c create mode 100644 libsylph/displayheader.h (limited to 'libsylph') diff --git a/libsylph/Makefile.am b/libsylph/Makefile.am index f42d18a2..64c37b07 100644 --- a/libsylph/Makefile.am +++ b/libsylph/Makefile.am @@ -15,6 +15,7 @@ libsylph_la_SOURCES = \ base64.c base64.h \ codeconv.c codeconv.h \ customheader.c customheader.h \ + displayheader.c displayheader.h \ filter.c filter.h \ folder.c folder.h \ html.c html.h \ diff --git a/libsylph/displayheader.c b/libsylph/displayheader.c new file mode 100644 index 00000000..edafc5a7 --- /dev/null +++ b/libsylph/displayheader.c @@ -0,0 +1,59 @@ +/* + * LibSylph -- E-Mail client library + * Copyright (C) 1999-2005 Hiroyuki Yamamoto + * + * This library 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.1 of the License, or (at your option) any later version. + * + * This library 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 this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include + +#include "displayheader.h" + +gchar *display_header_prop_get_str(DisplayHeaderProp *dp) +{ + return g_strconcat(dp->hidden ? "-" : "", dp->name, NULL); +} + +DisplayHeaderProp *display_header_prop_read_str(gchar *buf) +{ + DisplayHeaderProp *dp; + + dp = g_new0(DisplayHeaderProp, 1); + + dp->hidden = FALSE; + if (*buf == '-') { + dp->hidden = TRUE; + buf++; + } + if (*buf == '\0') { + g_free(dp); + return NULL; + } + dp->name = g_strdup(buf); + + return dp; +} + +void display_header_prop_free(DisplayHeaderProp *dp) +{ + if (!dp) return; + + g_free(dp->name); + g_free(dp); +} diff --git a/libsylph/displayheader.h b/libsylph/displayheader.h new file mode 100644 index 00000000..4ca8e185 --- /dev/null +++ b/libsylph/displayheader.h @@ -0,0 +1,37 @@ +/* + * LibSylph -- E-Mail client library + * Copyright (C) 1999-2005 Hiroyuki Yamamoto + * + * This library 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.1 of the License, or (at your option) any later version. + * + * This library 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 this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef __DISPLAYHEADER_H__ +#define __DISPLAYHEADER_H__ + +#include + +typedef struct _DisplayHeaderProp DisplayHeaderProp; + +struct _DisplayHeaderProp +{ + gchar *name; + gboolean hidden; +}; + +gchar *display_header_prop_get_str (DisplayHeaderProp *dp); +DisplayHeaderProp *display_header_prop_read_str (gchar *buf); +void display_header_prop_free (DisplayHeaderProp *dp); + +#endif /* __DISPLAYHEADER_H__ */ diff --git a/libsylph/procheader.c b/libsylph/procheader.c index c972a83f..e175a8d6 100644 --- a/libsylph/procheader.c +++ b/libsylph/procheader.c @@ -32,6 +32,7 @@ #include "procheader.h" #include "procmsg.h" #include "codeconv.h" +#include "displayheader.h" #include "prefs_common.h" #include "utils.h" @@ -354,6 +355,52 @@ GPtrArray *procheader_get_header_array_asis(FILE *fp, const gchar *encoding) return headers; } +GPtrArray *procheader_get_header_array_for_display(FILE *fp, + const gchar *encoding) +{ + GPtrArray *headers, *sorted_headers; + GSList *disphdr_list; + Header *header; + gint i; + + g_return_val_if_fail(fp != NULL, NULL); + + headers = procheader_get_header_array_asis(fp, encoding); + + sorted_headers = g_ptr_array_new(); + + for (disphdr_list = prefs_common.disphdr_list; disphdr_list != NULL; + disphdr_list = disphdr_list->next) { + DisplayHeaderProp *dp = + (DisplayHeaderProp *)disphdr_list->data; + + for (i = 0; i < headers->len; i++) { + header = g_ptr_array_index(headers, i); + + if (!g_ascii_strcasecmp(header->name, dp->name)) { + if (dp->hidden) + procheader_header_free(header); + else + g_ptr_array_add(sorted_headers, header); + + g_ptr_array_remove_index(headers, i); + i--; + } + } + } + + if (prefs_common.show_other_header) { + for (i = 0; i < headers->len; i++) { + header = g_ptr_array_index(headers, i); + g_ptr_array_add(sorted_headers, header); + } + g_ptr_array_free(headers, TRUE); + } else + procheader_header_array_destroy(headers); + + return sorted_headers; +} + void procheader_header_list_destroy(GSList *hlist) { Header *header; diff --git a/libsylph/procheader.h b/libsylph/procheader.h index 532d21c5..d6c0a488 100644 --- a/libsylph/procheader.h +++ b/libsylph/procheader.h @@ -65,6 +65,9 @@ GPtrArray *procheader_get_header_array (FILE *fp, const gchar *encoding); GPtrArray *procheader_get_header_array_asis (FILE *fp, const gchar *encoding); +GPtrArray *procheader_get_header_array_for_display + (FILE *fp, + const gchar *encoding); void procheader_header_array_destroy (GPtrArray *harray); void procheader_header_free (Header *header); diff --git a/libsylph/procmsg.c b/libsylph/procmsg.c index 0dae602d..344b43f1 100644 --- a/libsylph/procmsg.c +++ b/libsylph/procmsg.c @@ -1153,15 +1153,17 @@ void procmsg_print_message(MsgInfo *msginfo, const gchar *cmdline) static const gchar *def_cmd = "lpr %s"; static guint id = 0; gchar *prtmp; - FILE *tmpfp, *prfp; + FILE *msgfp, *tmpfp, *prfp; + GPtrArray *headers; + gint i; gchar buf[1024]; gchar *p; - g_return_if_fail(msginfo); + g_return_if_fail(msginfo != NULL); if ((tmpfp = procmime_get_first_text_content (msginfo, conv_get_locale_charset_str())) == NULL) { - g_warning(_("Can't get text part\n")); + g_warning("Can't get text part\n"); return; } @@ -1175,23 +1177,50 @@ void procmsg_print_message(MsgInfo *msginfo, const gchar *cmdline) return; } -#define OUTPUT_HEADER(s, fmt) \ - if (s) { \ - gchar *locale_str; \ - locale_str = conv_codeset_strdup \ - (s, CS_INTERNAL, conv_get_locale_charset_str()); \ - fprintf(prfp, fmt, locale_str ? locale_str : s); \ - g_free(locale_str); \ + if ((msgfp = procmsg_open_message(msginfo)) == NULL) { + fclose(prfp); + g_free(prtmp); + fclose(tmpfp); + return; } - OUTPUT_HEADER(msginfo->date, "Date: %s\n"); - OUTPUT_HEADER(msginfo->from, "From: %s\n"); - OUTPUT_HEADER(msginfo->to, "To: %s\n"); - OUTPUT_HEADER(msginfo->newsgroups, "Newsgroups: %s\n"); - OUTPUT_HEADER(msginfo->subject, "Subject: %s\n"); - fputc('\n', prfp); + headers = procheader_get_header_array_for_display(msgfp, NULL); + fclose(msgfp); + + for (i = 0; i < headers->len; i++) { + Header *hdr; + gchar *locale_str; + const gchar *body; + + hdr = g_ptr_array_index(headers, i); + + if (!g_ascii_strcasecmp(hdr->name, "Subject")) + body = msginfo->subject; + else if (!g_ascii_strcasecmp(hdr->name, "From")) + body = msginfo->from; + else if (!g_ascii_strcasecmp(hdr->name, "To")) + body = msginfo->to; + else if (!g_ascii_strcasecmp(hdr->name, "Cc")) { + unfold_line(hdr->body); + body = hdr->body; + while (g_ascii_isspace(*body)) + body++; + } else { + body = hdr->body; + while (g_ascii_isspace(*body)) + body++; + } + + locale_str = conv_codeset_strdup + (body, CS_INTERNAL, conv_get_locale_charset_str()); + fprintf(prfp, "%s: %s\n", hdr->name, + locale_str ? locale_str : body); + g_free(locale_str); + } -#undef OUTPUT_HEADER + procheader_header_array_destroy(headers); + + fputc('\n', prfp); while (fgets(buf, sizeof(buf), tmpfp) != NULL) fputs(buf, prfp); -- cgit v1.2.3