Fix printf formats for size_t and goffset arguments.
[claws.git] / src / plugins / tnef_parse / tnef_parse.c
index 4abd2c585e7741d39fd11ea9bf19367f4337b6ae..82a8f9e81ab5aaff737a9db3c9c975828e3bd4b5 100644 (file)
 #include <glib.h>
 #include <glib/gi18n.h>
 #include <gtk/gtk.h>
+
+#ifdef YTNEF_H_SUBDIR
+#include <libytnef/tnef-types.h>
+#include <libytnef/ytnef.h>
+#include <libytnef/mapi.h>
+#include <libytnef/mapidefs.h>
+#else
+#include <tnef-types.h>
+#include <ytnef.h>
+#include <mapi.h>
+#include <mapidefs.h>
+#endif
+
 #include "common/claws.h"
 #include "common/version.h"
 #include "main.h"
 #include "plugin.h"
 #include "procmime.h"
 #include "utils.h"
-
-#include <tnef-types.h>
-#include <ytnef.h>
-#include <mapi.h>
-#include <mapidefs.h>
+#include "file-utils.h"
 
 #include "tnef_dump.h"
 
@@ -66,10 +75,10 @@ static MimeInfo *tnef_broken_mimeinfo(const gchar *reason)
                        "Claws Mail TNEF parser:\n\n"
                        "%s\n"), reason?reason:_("Unknown error"));
 
-       fclose(fp);
+       claws_fclose(fp);
        if (g_stat(tmpfilename, &statbuf) < 0) {
                claws_unlink(tmpfilename);
-               procmime_mimeinfo_free_all(sub_info);
+               procmime_mimeinfo_free_all(&sub_info);
                return NULL;
 
        }
@@ -114,18 +123,18 @@ static MimeInfo *tnef_dump_file(const gchar *filename, char *data, size_t size)
                }
        } 
 
-       if (fwrite(data, 1, size, fp) < size) {
-               FILE_OP_ERROR(tmpfilename, "fwrite");
-               fclose(fp);
+       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);
+               procmime_mimeinfo_free_all(&sub_info);
                return tnef_broken_mimeinfo(_("Failed to write the part data."));
        }
-       fclose(fp);
+       claws_fclose(fp);
 
        if (g_stat(tmpfilename, &statbuf) < 0) {
                claws_unlink(tmpfilename);
-               procmime_mimeinfo_free_all(sub_info);
+               procmime_mimeinfo_free_all(&sub_info);
                return tnef_broken_mimeinfo(_("Failed to write the part data."));
        } else {
                sub_info->tmp = TRUE;
@@ -158,7 +167,7 @@ MimeInfo *tnef_parse_vcal(TNEFStruct *tnef)
 
        result = SaveVCalendar(fp, tnef);
 
-       fclose(fp);
+       claws_fclose(fp);
 
        if (g_stat(tmpfilename, &statbuf) < 0) {
                result = FALSE;
@@ -170,7 +179,7 @@ MimeInfo *tnef_parse_vcal(TNEFStruct *tnef)
 
        if (!result) {
                claws_unlink(tmpfilename);
-               procmime_mimeinfo_free_all(sub_info);
+               procmime_mimeinfo_free_all(&sub_info);
                return tnef_broken_mimeinfo(_("Failed to parse VCalendar data."));
        }
        return sub_info;
@@ -198,7 +207,7 @@ MimeInfo *tnef_parse_vtask(TNEFStruct *tnef)
 
        result = SaveVTask(fp, tnef);
 
-       fclose(fp);
+       claws_fclose(fp);
 
        if (g_stat(tmpfilename, &statbuf) < 0) {
                result = FALSE;
@@ -209,7 +218,7 @@ MimeInfo *tnef_parse_vtask(TNEFStruct *tnef)
        }
        if (!result) {
                claws_unlink(tmpfilename);
-               procmime_mimeinfo_free_all(sub_info);
+               procmime_mimeinfo_free_all(&sub_info);
                return tnef_broken_mimeinfo(_("Failed to parse VTask data."));
        }
        return sub_info;
@@ -236,6 +245,7 @@ MimeInfo *tnef_parse_vcard(TNEFStruct *tnef)
        FILE *fp = get_tmpfile_in_dir(get_mime_tmp_dir(), &tmpfilename);
        GStatBuf statbuf;
        gboolean result = FALSE;
+       gint ret;
        if (!fp) {
                g_free(tmpfilename);
                return NULL;
@@ -251,17 +261,22 @@ MimeInfo *tnef_parse_vcard(TNEFStruct *tnef)
        
        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_fclose(fp);
+
+       ret = g_stat(tmpfilename, &statbuf);
+       if (ret == -1) {
+               debug_print("couldn't stat tmpfilename '%s'\n", tmpfilename);
+       }
+
+       if ((ret == -1) || !result) {
                claws_unlink(tmpfilename);
-               procmime_mimeinfo_free_all(sub_info);
+               procmime_mimeinfo_free_all(&sub_info);
                return tnef_broken_mimeinfo(_("Failed to parse VCard data."));
        }
+
+       sub_info->tmp = TRUE;
+       sub_info->length = statbuf.st_size;
+       sub_info->encoding_type = ENC_BINARY;
        return sub_info;
 }
 
@@ -282,7 +297,7 @@ static gboolean tnef_parse (MimeParser *parser, MimeInfo *mimeinfo)
        if (mimeinfo->content == MIMECONTENT_FILE)
                debug_print("content: %s\n", mimeinfo->data.filename);
        else 
-               debug_print("contents in memory (len %zd)\n", 
+               debug_print("contents in memory (len %"G_GSIZE_FORMAT")\n", 
                        strlen(mimeinfo->data.mem));
        
        tnef = g_new0(TNEFStruct, 1);