static MimeViewer *get_viewer_for_mimeinfo(MimeView *mimeview, MimeInfo *partinfo) { gchar *content_type = NULL; MimeViewer *viewer = NULL; if ((partinfo->type == MIMETYPE_APPLICATION) && (!g_strcasecmp(partinfo->subtype, "octet-stream"))) { const gchar *filename; filename = procmime_mimeinfo_get_parameter(partinfo, "filename"); if (filename == NULL) filename = procmime_mimeinfo_get_parameter(partinfo, "name"); if (filename != NULL) content_type = procmime_get_mime_type(filename); } else { content_type = procmime_get_content_type_str(partinfo->type, partinfo->subtype); } if (content_type != NULL) { viewer = get_viewer_for_content_type(mimeview, content_type); g_free(content_type); } return viewer; }
static MimeInfo *tnef_dump_file(const gchar *filename, char *data, size_t size) { MimeInfo *sub_info = NULL; gchar *tmpfilename = NULL; FILE *fp = get_tmpfile_in_dir(get_mime_tmp_dir(), &tmpfilename); GStatBuf statbuf; gchar *content_type = NULL; if (!fp) { g_free(tmpfilename); return NULL; } sub_info = procmime_mimeinfo_new(); sub_info->content = MIMECONTENT_FILE; sub_info->data.filename = tmpfilename; sub_info->type = MIMETYPE_APPLICATION; sub_info->subtype = g_strdup("octet-stream"); if (filename) { g_hash_table_insert(sub_info->typeparameters, g_strdup("filename"), g_strdup(filename)); content_type = procmime_get_mime_type(filename); if (content_type && strchr(content_type, '/')) { g_free(sub_info->subtype); sub_info->subtype = g_strdup(strchr(content_type, '/')+1); *(strchr(content_type, '/')) = '\0'; sub_info->type = procmime_get_media_type(content_type); g_free(content_type); } } if (claws_fwrite(data, 1, size, fp) < size) { FILE_OP_ERROR(tmpfilename, "claws_fwrite"); claws_fclose(fp); claws_unlink(tmpfilename); procmime_mimeinfo_free_all(&sub_info); return tnef_broken_mimeinfo(_("Failed to write the part data.")); } claws_fclose(fp); if (g_stat(tmpfilename, &statbuf) < 0) { claws_unlink(tmpfilename); procmime_mimeinfo_free_all(&sub_info); return tnef_broken_mimeinfo(_("Failed to write the part data.")); } else { sub_info->tmp = TRUE; sub_info->length = statbuf.st_size; sub_info->encoding_type = ENC_BINARY; } return sub_info; }