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; }
MimeInfo *tnef_parse_vcard(TNEFStruct tnef) { MimeInfo *sub_info = NULL; gchar *tmpfilename = NULL; FILE *fp = get_tmpfile_in_dir(get_mime_tmp_dir(), &tmpfilename); struct stat statbuf; gboolean result = FALSE; 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_TEXT; sub_info->subtype = g_strdup("x-vcard"); g_hash_table_insert(sub_info->typeparameters, g_strdup("filename"), g_strdup("contact.vcf")); result = SaveVCard(fp, tnef); fclose(fp); g_stat(tmpfilename, &statbuf); sub_info->tmp = TRUE; sub_info->length = statbuf.st_size; sub_info->encoding_type = ENC_BINARY; if (!result) { claws_unlink(tmpfilename); procmime_mimeinfo_free_all(sub_info); return tnef_broken_mimeinfo(_("Failed to parse VCard data.")); } return sub_info; }
MimeInfo *tnef_parse_vtask(TNEFStruct *tnef) { MimeInfo *sub_info = NULL; gchar *tmpfilename = NULL; FILE *fp = get_tmpfile_in_dir(get_mime_tmp_dir(), &tmpfilename); GStatBuf statbuf; gboolean result = FALSE; 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_TEXT; sub_info->subtype = g_strdup("calendar"); g_hash_table_insert(sub_info->typeparameters, g_strdup("filename"), g_strdup("task.ics")); result = SaveVTask(fp, tnef); claws_fclose(fp); if (g_stat(tmpfilename, &statbuf) < 0) { result = FALSE; } else { sub_info->tmp = TRUE; sub_info->length = statbuf.st_size; sub_info->encoding_type = ENC_BINARY; } if (!result) { claws_unlink(tmpfilename); procmime_mimeinfo_free_all(&sub_info); return tnef_broken_mimeinfo(_("Failed to parse VTask data.")); } return sub_info; }