diff options
author | hiro <hiro@ee746299-78ed-0310-b773-934348b2243d> | 2006-03-08 04:37:16 +0000 |
---|---|---|
committer | hiro <hiro@ee746299-78ed-0310-b773-934348b2243d> | 2006-03-08 04:37:16 +0000 |
commit | f11888bfed0c495fc2c492e929bcfc122d9c71cb (patch) | |
tree | 29a1c264cc6a0b43cee9b609dcf782b0582d9f26 | |
parent | 3dfde2b2ca388030038a65d6dba71a8571378997 (diff) |
removed metamail support and replaced it with the alternative implementation.
git-svn-id: svn://sylpheed.sraoss.jp/sylpheed/trunk@1032 ee746299-78ed-0310-b773-934348b2243d
-rw-r--r-- | ChangeLog | 9 | ||||
-rw-r--r-- | ChangeLog.ja | 7 | ||||
-rw-r--r-- | libsylph/prefs_common.c | 10 | ||||
-rw-r--r-- | libsylph/procmime.c | 99 | ||||
-rw-r--r-- | libsylph/procmime.h | 13 | ||||
-rw-r--r-- | src/mimeview.c | 63 |
6 files changed, 155 insertions, 46 deletions
@@ -1,3 +1,12 @@ +2006-03-08 + + * libsylph/procmime.[ch] + src/mimeview.c: removed metamail support and replaced it with + the alternative implementation. + * libsylph/prefs_common.c: leave "mime_image_viewer" and + "mime_audio_player" options for compatibility, but made them empty + by default. + 2006-03-07 * src/compose.c: compose_get_signature_str(): allow relative signature diff --git a/ChangeLog.ja b/ChangeLog.ja index 62bfb8cb..f3bcf223 100644 --- a/ChangeLog.ja +++ b/ChangeLog.ja @@ -1,3 +1,10 @@ +2006-03-08 + + * libsylph/procmime.[ch] + src/mimeview.c: metamail のサポートを削除し、別の実装で置き換えた。 + * libsylph/prefs_common.c: "mime_image_viewer" と "mime_audio_player" + のオプションを互換性のために残すが、デフォルトで空にした。 + 2006-03-07 * src/compose.c: compose_get_signature_str(): 相対署名パスを許可。 diff --git a/libsylph/prefs_common.c b/libsylph/prefs_common.c index a35fb2f7..292b40ba 100644 --- a/libsylph/prefs_common.c +++ b/libsylph/prefs_common.c @@ -259,11 +259,13 @@ static PrefParam param[] = { {"show_other_header", "FALSE", &prefs_common.show_other_header, P_BOOL}, /* MIME viewer */ - {"mime_image_viewer", "display '%s'", &prefs_common.mime_image_viewer, - P_STRING}, - {"mime_audio_player", "play '%s'", &prefs_common.mime_audio_player, - P_STRING}, + {"mime_image_viewer", NULL, &prefs_common.mime_image_viewer, P_STRING}, + {"mime_audio_player", NULL, &prefs_common.mime_audio_player, P_STRING}, +#ifdef G_OS_WIN32 + {"mime_open_command", "notepad '%s'", &prefs_common.mime_open_cmd, +#else {"mime_open_command", "gedit '%s'", &prefs_common.mime_open_cmd, +#endif P_STRING}, /* Junk mail */ diff --git a/libsylph/procmime.c b/libsylph/procmime.c index 5b6ed438..31089455 100644 --- a/libsylph/procmime.c +++ b/libsylph/procmime.c @@ -1195,6 +1195,105 @@ static GList *procmime_get_mime_type_list(const gchar *file) return list; } +static GList *mailcap_list = NULL; + +static GList *procmime_parse_mailcap(const gchar *file) +{ + GList *list = NULL; + FILE *fp; + gchar buf[BUFFSIZE]; + MailCap *mailcap; + + if ((fp = g_fopen(file, "rb")) == NULL) return NULL; + + while (fgets(buf, sizeof(buf), fp) != NULL) { + gint i; + gchar *p; + gchar **strv; + + p = strchr(buf, '#'); + if (p) *p = '\0'; + g_strstrip(buf); + + strv = strsplit_with_quote(buf, ";", 0); + if (!strv) + continue; + + for (i = 0; strv[i] != NULL; ++i) + g_strstrip(strv[i]); + + if (!strv[0] || *strv[0] == '\0' || + !strv[1] || *strv[1] == '\0') { + g_strfreev(strv); + continue; + } + + mailcap = g_new(MailCap, 1); + mailcap->mime_type = g_strdup(strv[0]); + mailcap->cmdline_fmt = g_strdup(strv[1]); + mailcap->needs_terminal = FALSE; + + for (i = 0; strv[i] != NULL; ++i) { + if (strcmp(strv[i], "needsterminal") == 0) + mailcap->needs_terminal = TRUE; + } + + g_strfreev(strv); + + list = g_list_append(list, mailcap); + } + + return list; +} + +gint procmime_execute_open_file(const gchar *file, const gchar *mime_type) +{ + gchar *mime_type_ = NULL; + GList *cur; + MailCap *mailcap; + gchar *cmdline, *p; + gint ret = -1; + + g_return_val_if_fail(file != NULL, -1); + + if (!mime_type || + g_ascii_strcasecmp(mime_type, "application/octet-stream") == 0) { + gchar *tmp; + tmp = procmime_get_mime_type(file); + if (!tmp) + return -1; + mime_type_ = g_ascii_strdown(tmp, -1); + g_free(tmp); + } else + mime_type_ = g_ascii_strdown(mime_type, -1); + + if (!mailcap_list) + mailcap_list = procmime_parse_mailcap("/etc/mailcap"); + + for (cur = mailcap_list; cur != NULL; cur = cur->next) { + mailcap = (MailCap *)cur->data; + + if (!g_pattern_match_simple(mailcap->mime_type, mime_type_)) + continue; + if (mailcap->needs_terminal) + continue; + + if ((p = strchr(mailcap->cmdline_fmt, '%')) && + *(p + 1) == 's' && !strchr(p + 2, '%')) + cmdline = g_strdup_printf(mailcap->cmdline_fmt, file); + else + cmdline = g_strconcat(mailcap->cmdline_fmt, " \"", file, + "\"", NULL); + ret = execute_command_line(cmdline, TRUE); + g_free(cmdline); + break; + } + + g_free(mime_type_); + + return ret; +} + EncodingType procmime_get_encoding_for_charset(const gchar *charset) { if (!charset) diff --git a/libsylph/procmime.h b/libsylph/procmime.h index 5fd3a3a4..ac86a63c 100644 --- a/libsylph/procmime.h +++ b/libsylph/procmime.h @@ -1,6 +1,6 @@ /* * LibSylph -- E-Mail client library - * Copyright (C) 1999-2005 Hiroyuki Yamamoto + * Copyright (C) 1999-2006 Hiroyuki Yamamoto * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -28,6 +28,7 @@ #include <stdio.h> typedef struct _MimeType MimeType; +typedef struct _MailCap MailCap; typedef struct _MimeInfo MimeInfo; #include "procmsg.h" @@ -65,6 +66,13 @@ struct _MimeType gchar *extension; }; +struct _MailCap +{ + gchar *mime_type; + gchar *cmdline_fmt; + gboolean needs_terminal; +}; + /* * An example of MimeInfo structure: * @@ -183,6 +191,9 @@ gchar *procmime_get_tmp_file_name (MimeInfo *mimeinfo); ContentType procmime_scan_mime_type (const gchar *mime_type); gchar *procmime_get_mime_type (const gchar *filename); +gint procmime_execute_open_file (const gchar *file, + const gchar *mime_type); + EncodingType procmime_get_encoding_for_charset (const gchar *charset); EncodingType procmime_get_encoding_for_text_file(const gchar *file); const gchar *procmime_get_encoding_str (EncodingType encoding); diff --git a/src/mimeview.c b/src/mimeview.c index f33f4d26..5f4774bd 100644 --- a/src/mimeview.c +++ b/src/mimeview.c @@ -1125,18 +1125,12 @@ static void mimeview_open_with(MimeView *mimeview) static void mimeview_view_file(const gchar *filename, MimeInfo *partinfo, const gchar *cmdline) { - static gchar *default_image_cmdline = "display '%s'"; - static gchar *default_audio_cmdline = "play '%s'"; - static gchar *default_html_cmdline = DEFAULT_BROWSER_CMD; - static gchar *mime_cmdline = "metamail -d -b -x -c %s '%s'"; - gchar buf[1024]; - gchar m_buf[1024]; - const gchar *cmd; - const gchar *def_cmd; + const gchar *cmd = NULL; const gchar *p; + gchar *cmdbuf; -#ifdef G_OS_WIN32 if (!cmdline) { +#ifdef G_OS_WIN32 DWORD dwtype; if (g_file_test(filename, G_FILE_TEST_IS_EXECUTABLE) || @@ -1153,42 +1147,29 @@ static void mimeview_view_file(const gchar *filename, MimeInfo *partinfo, } execute_open_file(filename, partinfo->content_type); return; - } +#else + if (MIME_IMAGE == partinfo->mime_type) + cmd = prefs_common.mime_image_viewer; + else if (MIME_AUDIO == partinfo->mime_type) + cmd = prefs_common.mime_audio_player; + else if (MIME_TEXT_HTML == partinfo->mime_type) + cmd = prefs_common.uri_cmd; + if (!cmd) { + procmime_execute_open_file + (filename, partinfo->content_type); + return; + } #endif - if (cmdline) { + } else cmd = cmdline; - def_cmd = NULL; - } else if (MIME_APPLICATION_OCTET_STREAM == partinfo->mime_type) { - return; - } else if (MIME_IMAGE == partinfo->mime_type) { - cmd = prefs_common.mime_image_viewer; - def_cmd = default_image_cmdline; - } else if (MIME_AUDIO == partinfo->mime_type) { - cmd = prefs_common.mime_audio_player; - def_cmd = default_audio_cmdline; - } else if (MIME_TEXT_HTML == partinfo->mime_type) { - cmd = prefs_common.uri_cmd; - def_cmd = default_html_cmdline; - } else { - g_snprintf(m_buf, sizeof(m_buf), mime_cmdline, - partinfo->content_type, "%s"); - cmd = m_buf; - def_cmd = NULL; - } if (cmd && (p = strchr(cmd, '%')) && *(p + 1) == 's' && - !strchr(p + 2, '%')) - g_snprintf(buf, sizeof(buf), cmd, filename); - else { - if (cmd) - g_warning(_("MIME viewer command line is invalid: `%s'"), cmd); - if (def_cmd) - g_snprintf(buf, sizeof(buf), def_cmd, filename); - else - return; - } - - execute_command_line(buf, TRUE); + !strchr(p + 2, '%')) { + cmdbuf = g_strdup_printf(cmd, filename); + execute_command_line(cmdbuf, TRUE); + g_free(cmdbuf); + } else if (cmd) + g_warning("MIME viewer command line is invalid: '%s'", cmd); } #if USE_GPGME |