X-Git-Url: http://git.claws-mail.org/?p=claws.git;a=blobdiff_plain;f=src%2Fprocmime.c;h=c2b47ee25f56f85af306867ae355bb9e65f4c58f;hp=3ae9567a61f894bbc53d10cca55064eee9572552;hb=fbb47e2d533585188124588b1fbb3be8ba7d8812;hpb=7d43271511ad048fe6eaf81c26b4516f22a45b84 diff --git a/src/procmime.c b/src/procmime.c index 3ae9567a6..c2b47ee25 100644 --- a/src/procmime.c +++ b/src/procmime.c @@ -1,6 +1,6 @@ /* * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client - * Copyright (C) 1999,2000 Hiroyuki Yamamoto + * Copyright (C) 1999-2001 Hiroyuki Yamamoto * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -275,8 +275,7 @@ void procmime_scan_encoding(MimeInfo *mimeinfo, const gchar *encoding) { gchar *buf; - Xalloca(buf, strlen(encoding) + 1, return); - strcpy(buf, encoding); + Xstrdup_a(buf, encoding, return); g_free(mimeinfo->encoding); @@ -301,8 +300,14 @@ void procmime_scan_content_type(MimeInfo *mimeinfo, const gchar *content_type) gchar *delim, *p, *cnttype; gchar *buf; - Xalloca(buf, strlen(content_type) + 1, return); - strcpy(buf, content_type); + if (conv_get_current_charset() == C_EUC_JP && + strchr(content_type, '\033')) { + gint len; + len = strlen(content_type) * 2 + 1; + Xalloca(buf, len, return); + conv_jistoeuc(buf, len, content_type); + } else + Xstrdup_a(buf, content_type, return); g_free(mimeinfo->content_type); g_free(mimeinfo->charset); @@ -314,28 +319,7 @@ void procmime_scan_content_type(MimeInfo *mimeinfo, const gchar *content_type) if ((delim = strchr(buf, ';'))) *delim = '\0'; mimeinfo->content_type = cnttype = g_strdup(g_strstrip(buf)); - if (!strncasecmp(cnttype, "text/html", 9)) - mimeinfo->mime_type = MIME_TEXT_HTML; - else if (!strncasecmp(cnttype, "text/", 5)) - mimeinfo->mime_type = MIME_TEXT; - else if (!strncasecmp(cnttype, "message/rfc822", 14)) - mimeinfo->mime_type = MIME_MESSAGE_RFC822; - else if (!strncasecmp(cnttype, "message/", 8)) - mimeinfo->mime_type = MIME_TEXT; - else if (!strncasecmp(cnttype, "application/octet-stream", 24)) - mimeinfo->mime_type = MIME_APPLICATION_OCTET_STREAM; - else if (!strncasecmp(cnttype, "application/", 12)) - mimeinfo->mime_type = MIME_APPLICATION; - else if (!strncasecmp(cnttype, "multipart/", 10)) - mimeinfo->mime_type = MIME_MULTIPART; - else if (!strncasecmp(cnttype, "image/", 6)) - mimeinfo->mime_type = MIME_IMAGE; - else if (!strncasecmp(cnttype, "audio/", 6)) - mimeinfo->mime_type = MIME_AUDIO; - else if (!strcasecmp(cnttype, "text")) - mimeinfo->mime_type = MIME_TEXT; - else - mimeinfo->mime_type = MIME_UNKNOWN; + mimeinfo->mime_type = procmime_scan_mime_type(cnttype); if (!delim) return; p = delim + 1; @@ -390,8 +374,14 @@ void procmime_scan_content_disposition(MimeInfo *mimeinfo, gchar *delim, *p, *dispos; gchar *buf; - Xalloca(buf, strlen(content_disposition) + 1, return); - strcpy(buf, content_disposition); + if (conv_get_current_charset() == C_EUC_JP && + strchr(content_disposition, '\033')) { + gint len; + len = strlen(content_disposition) * 2 + 1; + Xalloca(buf, len, return); + conv_jistoeuc(buf, len, content_disposition); + } else + Xstrdup_a(buf, content_disposition, return); if ((delim = strchr(buf, ';'))) *delim = '\0'; mimeinfo->content_disposition = dispos = g_strdup(g_strstrip(buf)); @@ -482,6 +472,14 @@ MimeInfo *procmime_scan_mime_header(FILE *fp) } } + if (mimeinfo->mime_type == MIME_APPLICATION_OCTET_STREAM && + mimeinfo->name) { + const gchar *type; + type = procmime_get_mime_type(mimeinfo->name); + if (type) + mimeinfo->mime_type = procmime_scan_mime_type(type); + } + if (!mimeinfo->content_type) mimeinfo->content_type = g_strdup("text/plain"); @@ -719,6 +717,36 @@ gchar *procmime_get_tmp_file_name(MimeInfo *mimeinfo) return filename; } +ContentType procmime_scan_mime_type(const gchar *mime_type) +{ + ContentType type; + + if (!strncasecmp(mime_type, "text/html", 9)) + type = MIME_TEXT_HTML; + else if (!strncasecmp(mime_type, "text/", 5)) + type = MIME_TEXT; + else if (!strncasecmp(mime_type, "message/rfc822", 14)) + type = MIME_MESSAGE_RFC822; + else if (!strncasecmp(mime_type, "message/", 8)) + type = MIME_TEXT; + else if (!strncasecmp(mime_type, "application/octet-stream", 24)) + type = MIME_APPLICATION_OCTET_STREAM; + else if (!strncasecmp(mime_type, "application/", 12)) + type = MIME_APPLICATION; + else if (!strncasecmp(mime_type, "multipart/", 10)) + type = MIME_MULTIPART; + else if (!strncasecmp(mime_type, "image/", 6)) + type = MIME_IMAGE; + else if (!strncasecmp(mime_type, "audio/", 6)) + type = MIME_AUDIO; + else if (!strcasecmp(mime_type, "text")) + type = MIME_TEXT; + else + type = MIME_UNKNOWN; + + return type; +} + static GList *mime_type_list = NULL; gchar *procmime_get_mime_type(const gchar *filename) @@ -814,9 +842,11 @@ GList *procmime_get_mime_type_list(void) if (mime_type_list) return mime_type_list; - if ((fp = fopen(SYSCONFDIR "/mime.types", "r")) == NULL) { - FILE_OP_ERROR(SYSCONFDIR "/mime.types", "fopen"); - return NULL; + if ((fp = fopen("/etc/mime.types", "r")) == NULL) { + if ((fp = fopen(SYSCONFDIR "/mime.types", "r")) == NULL) { + FILE_OP_ERROR(SYSCONFDIR "/mime.types", "fopen"); + return NULL; + } } while (fgets(buf, sizeof(buf), fp) != NULL) {