2007-10-07 [colin] 3.0.2cvs30
[claws.git] / src / mbox.c
index 6b903223bb3ab1cbbfb1c75961cd93a361e3d860..0e695a6ce8d5ddef91225752c05538c20abe3e26 100644 (file)
@@ -319,8 +319,12 @@ gint lock_mbox(const gchar *base, LockType type)
                        return -1;
                }
 
-               fprintf(lockfp, "%d\n", getpid());
-               fclose(lockfp);
+               if (fprintf(lockfp, "%d\n", getpid()) < 0 ||
+                   fclose(lockfp) == EOF) {
+                       FILE_OP_ERROR(lockfile, "fopen||fclose");
+                       g_free(lockfile);
+                       return -1;
+               }
 
                locklink = g_strconcat(base, ".lock", NULL);
                while (link(lockfile, locklink) < 0) {
@@ -528,6 +532,8 @@ gint export_list_to_mbox(GSList *mlist, const gchar *mbox)
        FILE *msg_fp;
        FILE *mbox_fp;
        gchar buf[BUFFSIZE];
+       int err = 0;
+
        gint msgs = 1, total = g_slist_length(mlist);
        if (g_file_test(mbox, G_FILE_TEST_EXISTS) == TRUE) {
                if (alertpanel_full(_("Overwrite mbox file"),
@@ -549,7 +555,7 @@ gint export_list_to_mbox(GSList *mlist, const gchar *mbox)
        flockfile(mbox_fp);
 #endif
 
-       statusbar_print_all(_("Exporting to mbox..."));
+       statuswindow_print_all(_("Exporting to mbox..."));
        for (cur = mlist; cur != NULL; cur = cur->next) {
                int len;
                gchar buft[BUFFSIZE];
@@ -570,8 +576,15 @@ gint export_list_to_mbox(GSList *mlist, const gchar *mbox)
                         sizeof(buf));
                extract_address(buf);
 
-               fprintf(mbox_fp, "From %s %s",
-                       buf, ctime_r(&msginfo->date_t, buft));
+               if (fprintf(mbox_fp, "From %s %s",
+                       buf, ctime_r(&msginfo->date_t, buft)) < 0) {
+                       err = -1;
+#ifdef HAVE_FGETS_UNLOCKED
+                       funlockfile(msg_fp);
+#endif
+                       fclose(msg_fp);
+                       goto out;
+               }
 
                buf[0] = '\0';
                
@@ -585,21 +598,51 @@ gint export_list_to_mbox(GSList *mlist, const gchar *mbox)
                        while ((buf[offset] == '>')) {
                                offset++;
                        }
-                       if (!strncmp(buf+offset, "From ", 5))
-                               SC_FPUTC('>', mbox_fp);
-                       SC_FPUTS(buf, mbox_fp);
+                       if (!strncmp(buf+offset, "From ", 5)) {
+                               if (SC_FPUTC('>', mbox_fp) == EOF) {
+                                       err = -1;
+#ifdef HAVE_FGETS_UNLOCKED
+                                       funlockfile(msg_fp);
+#endif
+                                       fclose(msg_fp);
+                                       goto out;
+                               }
+                       }
+                       if (SC_FPUTS(buf, mbox_fp) == EOF) {
+                               err = -1;
+#ifdef HAVE_FGETS_UNLOCKED
+                               funlockfile(msg_fp);
+#endif
+                               fclose(msg_fp);
+                               goto out;
+                       }
                }
 
                /* force last line to end w/ a newline */
                len = strlen(buf);
                if (len > 0) {
                        len--;
-                       if ((buf[len] != '\n') && (buf[len] != '\r'))
-                               SC_FPUTC('\n', mbox_fp);
+                       if ((buf[len] != '\n') && (buf[len] != '\r')) {
+                               if (SC_FPUTC('\n', mbox_fp) == EOF) {
+                                       err = -1;
+#ifdef HAVE_FGETS_UNLOCKED
+                                       funlockfile(msg_fp);
+#endif
+                                       fclose(msg_fp);
+                                       goto out;
+                               }
+                       }
                }
 
                /* add a trailing empty line */
-               SC_FPUTC('\n', mbox_fp);
+               if (SC_FPUTC('\n', mbox_fp) == EOF) {
+                       err = -1;
+#ifdef HAVE_FGETS_UNLOCKED
+                       funlockfile(msg_fp);
+#endif
+                       fclose(msg_fp);
+                       goto out;
+               }
 
 #ifdef HAVE_FGETS_UNLOCKED
                funlockfile(msg_fp);
@@ -609,15 +652,17 @@ gint export_list_to_mbox(GSList *mlist, const gchar *mbox)
                if (msgs%500 == 0)
                        GTK_EVENTS_FLUSH();
        }
+
+out:
        statusbar_progress_all(0,0,0);
-       statusbar_pop_all();
+       statuswindow_pop_all();
 
 #ifdef HAVE_FGETS_UNLOCKED
        funlockfile(mbox_fp);
 #endif
        fclose(mbox_fp);
 
-       return 0;
+       return err;
 }
 
 /* read all messages in SRC, and store them into one MBOX file. */