aboutsummaryrefslogtreecommitdiff
path: root/libsylph
diff options
context:
space:
mode:
authorhiro <hiro@ee746299-78ed-0310-b773-934348b2243d>2006-03-08 04:37:16 +0000
committerhiro <hiro@ee746299-78ed-0310-b773-934348b2243d>2006-03-08 04:37:16 +0000
commitf11888bfed0c495fc2c492e929bcfc122d9c71cb (patch)
tree29a1c264cc6a0b43cee9b609dcf782b0582d9f26 /libsylph
parent3dfde2b2ca388030038a65d6dba71a8571378997 (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
Diffstat (limited to 'libsylph')
-rw-r--r--libsylph/prefs_common.c10
-rw-r--r--libsylph/procmime.c99
-rw-r--r--libsylph/procmime.h13
3 files changed, 117 insertions, 5 deletions
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);