Rename claws_io to file-utils, and move file-related functions
authorColin Leroy <colin@colino.net>
Sun, 7 Oct 2018 12:46:02 +0000 (14:46 +0200)
committerColin Leroy <colin@colino.net>
Sun, 7 Oct 2018 13:09:10 +0000 (15:09 +0200)
from utils.c to file-utils.c

105 files changed:
src/account.c
src/addrbook.c
src/addrclip.c
src/addressbook.c
src/addrharvest.c
src/addrindex.c
src/addritem.c
src/addrmerge.c
src/autofaces.c
src/common/Makefile.am
src/common/claws_io.c [deleted file]
src/common/file-utils.c [new file with mode: 0644]
src/common/file-utils.h [moved from src/common/claws_io.h with 50% similarity]
src/common/log.c
src/common/plugin.c
src/common/prefs.c
src/common/ssl_certificate.c
src/common/tags.c
src/common/template.c
src/common/utils.c
src/common/utils.h
src/common/xml.c
src/common/xmlprops.c
src/compose.c
src/editaddress.c
src/enriched.c
src/etpan/imap-thread.c
src/exporthtml.c
src/exportldif.c
src/file_checker.c
src/folder.c
src/gtk/about.c
src/html.c
src/image_viewer.c
src/imap.c
src/inc.c
src/jpilot.c
src/ldapquery.c
src/ldif.c
src/main.c
src/matcher.c
src/mbox.c
src/messageview.c
src/mh.c
src/mimeview.c
src/msgcache.c
src/mutt.c
src/news.c
src/partial_download.c
src/passwordstore.c
src/pine.c
src/plugins/acpi_notifier/acpi_notifier.c
src/plugins/archive/archiver_gtk.c
src/plugins/bogofilter/bogofilter.c
src/plugins/clamd/libclamd/clamd-plugin.c
src/plugins/dillo/dillo_viewer.c
src/plugins/fancy/fancy_prefs.c
src/plugins/fancy/fancy_viewer.c
src/plugins/libravatar/libravatar_cache.c
src/plugins/libravatar/libravatar_image.c
src/plugins/libravatar/libravatar_missing.c
src/plugins/mailmbox/mailimf.c
src/plugins/mailmbox/mailimf_write.c
src/plugins/mailmbox/mailmbox.c
src/plugins/mailmbox/mailmbox_folder.c
src/plugins/newmail/newmail.c
src/plugins/pdf_viewer/poppler_viewer.c
src/plugins/perl/perl_plugin.c
src/plugins/pgpcore/pgp_utils.c
src/plugins/pgpcore/sgpgme.c
src/plugins/pgpinline/pgpinline.c
src/plugins/pgpmime/pgpmime.c
src/plugins/python/python_plugin.c
src/plugins/rssyl/opml_export.c
src/plugins/rssyl/rssyl.c
src/plugins/rssyl/rssyl_add_item.c
src/plugins/rssyl/rssyl_deleted.c
src/plugins/rssyl/rssyl_update_format.c
src/plugins/smime/smime.c
src/plugins/spam_report/spam_report.c
src/plugins/spamassassin/libspamc.c
src/plugins/spamassassin/spamassassin.c
src/plugins/tnef_parse/tnef_parse.c
src/plugins/vcalendar/vcal_folder.c
src/plugins/vcalendar/vcal_manager.c
src/plugins/vcalendar/vcal_meeting_gtk.c
src/plugins/vcalendar/vcalendar.c
src/pop.c
src/prefs_account.c
src/prefs_actions.c
src/prefs_common.c
src/prefs_customheader.c
src/prefs_display_header.c
src/prefs_gtk.c
src/prefs_themes.c
src/procheader.c
src/procmime.c
src/procmsg.c
src/quote_fmt_parse.y
src/send_message.c
src/sourcewindow.c
src/summaryview.c
src/textview.c
src/vcard.c
src/wizard.c

index 285257b..6f8521e 100644 (file)
@@ -55,7 +55,7 @@
 #include "prefs_actions.h"
 #include "hooks.h"
 #include "passwordstore.h"
-#include "claws_io.h"
+#include "file-utils.h"
 
 enum {
        ACCOUNT_IS_DEFAULT,
index 64a3645..8087996 100644 (file)
@@ -38,7 +38,7 @@
 #include "addrcache.h"
 #include "addrbook.h"
 #include "adbookbase.h"
-#include "claws_io.h"
+#include "file-utils.h"
 
 #ifndef DEV_STANDALONE
 #include "prefs_gtk.h"
index 90180c9..58d5947 100644 (file)
@@ -56,6 +56,7 @@
 #include "addrclip.h"
 #include "alertpanel.h"
 #include "defs.h"
+#include "file-utils.h"
 
 /*
 * Create a clipboard.
index a5a0eba..342163e 100644 (file)
@@ -44,6 +44,7 @@
 #include "xml.h"
 #include "prefs_gtk.h"
 #include "procmime.h"
+#include "file-utils.h"
 #include "utils.h"
 #include "gtkutils.h"
 #include "codeconv.h"
index 1d94633..d837293 100644 (file)
@@ -40,7 +40,7 @@
 #ifdef USE_ALT_ADDRBOOK
        #include "addressbook-dbus.h"
 #endif
-#include "claws_io.h"
+#include "file-utils.h"
 
 /* Mail header names of interest */
 static gchar *_headerFrom_     = HEADER_FROM;
index bad1fa5..82c2fed 100644 (file)
@@ -43,7 +43,7 @@
 #include "utils.h"
 #include "alertpanel.h"
 #include "passwordstore.h"
-#include "claws_io.h"
+#include "file-utils.h"
 
 #ifndef DEV_STANDALONE
 #include "prefs_gtk.h"
index 3a81826..cb76257 100644 (file)
@@ -25,6 +25,7 @@
 #include <string.h>
 
 #include "defs.h"
+#include "file-utils.h"
 #include "utils.h"
 #include "addritem.h"
 #include "mgutils.h"
index 363bab7..6aa8315 100644 (file)
@@ -38,6 +38,7 @@
 #include "addrmerge.h"
 #include "alertpanel.h"
 #include "gtkutils.h"
+#include "file-utils.h"
 #include "utils.h"
 #include "prefs_common.h"
 
index d12c975..300435c 100644 (file)
@@ -27,7 +27,7 @@
 
 #include "utils.h"
 #include "autofaces.h"
-#include "claws_io.h"
+#include "file-utils.h"
 
 static gint get_content_for_any_face(gchar *buf, gint len, gchar *anyname, gint maxlen)
 {
index aa307ae..805db4d 100644 (file)
@@ -25,6 +25,7 @@ endif
 
 libclawscommon_la_SOURCES = $(arch_sources) \
        codeconv.c \
+       file-utils.c \
        hooks.c \
        log.c \
        md5.c \
@@ -43,7 +44,6 @@ libclawscommon_la_SOURCES = $(arch_sources) \
        string_match.c \
        stringtable.c \
        claws.c \
-       claws_io.c \
        tags.c \
        template.c \
        utils.c \
@@ -56,6 +56,7 @@ libclawscommon_la_SOURCES = $(arch_sources) \
 clawscommonincludedir = $(pkgincludedir)/common
 clawscommoninclude_HEADERS = $(arch_headers) \
        codeconv.h \
+       file-utils.h \
        defs.h \
        hooks.h \
        log.h \
@@ -75,7 +76,6 @@ clawscommoninclude_HEADERS = $(arch_headers) \
        string_match.h \
        stringtable.h \
        claws.h \
-       claws_io.h \
        tags.h \
        template.h \
        timing.h \
diff --git a/src/common/claws_io.c b/src/common/claws_io.c
deleted file mode 100644 (file)
index 6268978..0000000
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2018 Colin Leroy and the Claws Mail team
- *
- * 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
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifdef HAVE_CONFIG_H
-#  include "config.h"
-#include "claws-features.h"
-#endif
-
-#include <stdio.h>
-#include <unistd.h>
-
-#include "timing.h"
-#include "claws_io.h"
-
-gboolean prefs_common_get_flush_metadata(void);
-
-/* FIXME make static once every file I/O is done using claws_* wrappers */
-int safe_fclose(FILE *fp)
-{
-       int r;
-       START_TIMING("");
-
-       if (fflush(fp) != 0) {
-               return EOF;
-       }
-       if (prefs_common_get_flush_metadata() && fsync(fileno(fp)) != 0) {
-               return EOF;
-       }
-
-       r = fclose(fp);
-       END_TIMING();
-
-       return r;
-}
-
-#if HAVE_FGETS_UNLOCKED
-
-/* Open a file and locks it once
- * so subsequent I/O is faster
- */
-FILE *claws_fopen(const char *file, const char *mode)
-{
-       FILE *fp = fopen(file, mode);
-       if (!fp)
-               return NULL;
-       flockfile(fp);
-       return fp;
-}
-
-FILE *claws_fdopen(int fd, const char *mode)
-{
-       FILE *fp = fdopen(fd, mode);
-       if (!fp)
-               return NULL;
-       flockfile(fp);
-       return fp;
-}
-
-/* Unlocks and close a file pointer
- */
-
-int claws_fclose(FILE *fp)
-{
-       funlockfile(fp);
-       return fclose(fp);
-}
-
-/* Unlock, then safe-close a file pointer
- * Safe close is done using fflush + fsync
- * if the according preference says so.
- */
-int claws_safe_fclose(FILE *fp)
-{
-       funlockfile(fp);
-       return safe_fclose(fp);
-}
-
-#endif
diff --git a/src/common/file-utils.c b/src/common/file-utils.c
new file mode 100644 (file)
index 0000000..8157de5
--- /dev/null
@@ -0,0 +1,857 @@
+/*
+ * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
+ * Copyright (C) 1999-2018 Colin Leroy and the Claws Mail team
+ *
+ * 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
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifdef HAVE_CONFIG_H
+#  include "config.h"
+#include "claws-features.h"
+#endif
+
+#include <errno.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <fcntl.h>
+
+#include "defs.h"
+#include "codeconv.h"
+#include "timing.h"
+#include "file-utils.h"
+
+gboolean prefs_common_get_flush_metadata(void);
+gboolean prefs_common_get_use_shred(void);
+
+/* FIXME make static once every file I/O is done using claws_* wrappers */
+int safe_fclose(FILE *fp)
+{
+       int r;
+       START_TIMING("");
+
+       if (fflush(fp) != 0) {
+               return EOF;
+       }
+       if (prefs_common_get_flush_metadata() && fsync(fileno(fp)) != 0) {
+               return EOF;
+       }
+
+       r = fclose(fp);
+       END_TIMING();
+
+       return r;
+}
+
+#if HAVE_FGETS_UNLOCKED
+
+/* Open a file and locks it once
+ * so subsequent I/O is faster
+ */
+FILE *claws_fopen(const char *file, const char *mode)
+{
+       FILE *fp = fopen(file, mode);
+       if (!fp)
+               return NULL;
+       flockfile(fp);
+       return fp;
+}
+
+FILE *claws_fdopen(int fd, const char *mode)
+{
+       FILE *fp = fdopen(fd, mode);
+       if (!fp)
+               return NULL;
+       flockfile(fp);
+       return fp;
+}
+
+/* Unlocks and close a file pointer
+ */
+
+int claws_fclose(FILE *fp)
+{
+       funlockfile(fp);
+       return fclose(fp);
+}
+
+/* Unlock, then safe-close a file pointer
+ * Safe close is done using fflush + fsync
+ * if the according preference says so.
+ */
+int claws_safe_fclose(FILE *fp)
+{
+       funlockfile(fp);
+       return safe_fclose(fp);
+}
+
+#ifdef G_OS_WIN32
+#define WEXITSTATUS(x) (x)
+#endif
+
+int claws_unlink(const char *filename) 
+{
+       GStatBuf s;
+       static int found_shred = -1;
+       static const gchar *args[4];
+
+       if (filename == NULL)
+               return 0;
+
+       if (prefs_common_get_use_shred()) {
+               if (found_shred == -1) {
+                       /* init */
+                       args[0] = g_find_program_in_path("shred");
+                       debug_print("found shred: %s\n", args[0]);
+                       found_shred = (args[0] != NULL) ? 1:0;
+                       args[1] = "-f";
+                       args[3] = NULL;
+               }
+               if (found_shred == 1) {
+                       if (g_stat(filename, &s) == 0 && S_ISREG(s.st_mode)) {
+                               if (s.st_nlink == 1) {
+                                       gint status=0;
+                                       args[2] = filename;
+                                       g_spawn_sync(NULL, (gchar **)args, NULL, 0,
+                                        NULL, NULL, NULL, NULL, &status, NULL);
+                                       debug_print("%s %s exited with status %d\n",
+                                               args[0], filename, WEXITSTATUS(status));
+                                       if (truncate(filename, 0) < 0)
+                                               g_warning("couln't truncate: %s", filename);
+                               }
+                       }
+               }
+       }
+       return g_unlink(filename);
+}
+
+gint file_strip_crs(const gchar *file)
+{
+       FILE *fp = NULL, *outfp = NULL;
+       gchar buf[4096];
+       gchar *out = get_tmp_file();
+       if (file == NULL)
+               goto freeout;
+
+       fp = claws_fopen(file, "rb");
+       if (!fp)
+               goto freeout;
+
+       outfp = claws_fopen(out, "wb");
+       if (!outfp) {
+               claws_fclose(fp);
+               goto freeout;
+       }
+
+       while (claws_fgets(buf, sizeof (buf), fp) != NULL) {
+               strcrchomp(buf);
+               if (claws_fputs(buf, outfp) == EOF) {
+                       claws_fclose(fp);
+                       claws_fclose(outfp);
+                       goto unlinkout;
+               }
+       }
+
+       claws_fclose(fp);
+       if (claws_safe_fclose(outfp) == EOF) {
+               goto unlinkout;
+       }
+       
+       if (move_file(out, file, TRUE) < 0)
+               goto unlinkout;
+       
+       g_free(out);
+       return 0;
+unlinkout:
+       claws_unlink(out);
+freeout:
+       g_free(out);
+       return -1;
+}
+
+/*
+ * Append src file body to the tail of dest file.
+ * Now keep_backup has no effects.
+ */
+gint append_file(const gchar *src, const gchar *dest, gboolean keep_backup)
+{
+       FILE *src_fp, *dest_fp;
+       gint n_read;
+       gchar buf[BUFSIZ];
+
+       gboolean err = FALSE;
+
+       if ((src_fp = claws_fopen(src, "rb")) == NULL) {
+               FILE_OP_ERROR(src, "claws_fopen");
+               return -1;
+       }
+
+       if ((dest_fp = claws_fopen(dest, "ab")) == NULL) {
+               FILE_OP_ERROR(dest, "claws_fopen");
+               claws_fclose(src_fp);
+               return -1;
+       }
+
+       if (change_file_mode_rw(dest_fp, dest) < 0) {
+               FILE_OP_ERROR(dest, "chmod");
+               g_warning("can't change file mode: %s", dest);
+       }
+
+       while ((n_read = claws_fread(buf, sizeof(gchar), sizeof(buf), src_fp)) > 0) {
+               if (n_read < sizeof(buf) && claws_ferror(src_fp))
+                       break;
+               if (claws_fwrite(buf, 1, n_read, dest_fp) < n_read) {
+                       g_warning("writing to %s failed.", dest);
+                       claws_fclose(dest_fp);
+                       claws_fclose(src_fp);
+                       claws_unlink(dest);
+                       return -1;
+               }
+       }
+
+       if (claws_ferror(src_fp)) {
+               FILE_OP_ERROR(src, "claws_fread");
+               err = TRUE;
+       }
+       claws_fclose(src_fp);
+       if (claws_fclose(dest_fp) == EOF) {
+               FILE_OP_ERROR(dest, "claws_fclose");
+               err = TRUE;
+       }
+
+       if (err) {
+               claws_unlink(dest);
+               return -1;
+       }
+
+       return 0;
+}
+
+gint copy_file(const gchar *src, const gchar *dest, gboolean keep_backup)
+{
+       FILE *src_fp, *dest_fp;
+       gint n_read;
+       gchar buf[BUFSIZ];
+       gchar *dest_bak = NULL;
+       gboolean err = FALSE;
+
+       if ((src_fp = claws_fopen(src, "rb")) == NULL) {
+               FILE_OP_ERROR(src, "claws_fopen");
+               return -1;
+       }
+       if (is_file_exist(dest)) {
+               dest_bak = g_strconcat(dest, ".bak", NULL);
+               if (rename_force(dest, dest_bak) < 0) {
+                       FILE_OP_ERROR(dest, "rename");
+                       claws_fclose(src_fp);
+                       g_free(dest_bak);
+                       return -1;
+               }
+       }
+
+       if ((dest_fp = claws_fopen(dest, "wb")) == NULL) {
+               FILE_OP_ERROR(dest, "claws_fopen");
+               claws_fclose(src_fp);
+               if (dest_bak) {
+                       if (rename_force(dest_bak, dest) < 0)
+                               FILE_OP_ERROR(dest_bak, "rename");
+                       g_free(dest_bak);
+               }
+               return -1;
+       }
+
+       if (change_file_mode_rw(dest_fp, dest) < 0) {
+               FILE_OP_ERROR(dest, "chmod");
+               g_warning("can't change file mode: %s", dest);
+       }
+
+       while ((n_read = claws_fread(buf, sizeof(gchar), sizeof(buf), src_fp)) > 0) {
+               if (n_read < sizeof(buf) && claws_ferror(src_fp))
+                       break;
+               if (claws_fwrite(buf, 1, n_read, dest_fp) < n_read) {
+                       g_warning("writing to %s failed.", dest);
+                       claws_fclose(dest_fp);
+                       claws_fclose(src_fp);
+                       claws_unlink(dest);
+                       if (dest_bak) {
+                               if (rename_force(dest_bak, dest) < 0)
+                                       FILE_OP_ERROR(dest_bak, "rename");
+                               g_free(dest_bak);
+                       }
+                       return -1;
+               }
+       }
+
+       if (claws_ferror(src_fp)) {
+               FILE_OP_ERROR(src, "claws_fread");
+               err = TRUE;
+       }
+       claws_fclose(src_fp);
+       if (claws_safe_fclose(dest_fp) == EOF) {
+               FILE_OP_ERROR(dest, "claws_fclose");
+               err = TRUE;
+       }
+
+       if (err) {
+               claws_unlink(dest);
+               if (dest_bak) {
+                       if (rename_force(dest_bak, dest) < 0)
+                               FILE_OP_ERROR(dest_bak, "rename");
+                       g_free(dest_bak);
+               }
+               return -1;
+       }
+
+       if (keep_backup == FALSE && dest_bak)
+               claws_unlink(dest_bak);
+
+       g_free(dest_bak);
+
+       return 0;
+}
+
+gint move_file(const gchar *src, const gchar *dest, gboolean overwrite)
+{
+       if (overwrite == FALSE && is_file_exist(dest)) {
+               g_warning("move_file(): file %s already exists.", dest);
+               return -1;
+       }
+
+       if (rename_force(src, dest) == 0) return 0;
+
+       if (EXDEV != errno) {
+               FILE_OP_ERROR(src, "rename");
+               return -1;
+       }
+
+       if (copy_file(src, dest, FALSE) < 0) return -1;
+
+       claws_unlink(src);
+
+       return 0;
+}
+
+gint copy_file_part_to_fp(FILE *fp, off_t offset, size_t length, FILE *dest_fp)
+{
+       gint n_read;
+       gint bytes_left, to_read;
+       gchar buf[BUFSIZ];
+
+       if (fseek(fp, offset, SEEK_SET) < 0) {
+               perror("fseek");
+               return -1;
+       }
+
+       bytes_left = length;
+       to_read = MIN(bytes_left, sizeof(buf));
+
+       while ((n_read = claws_fread(buf, sizeof(gchar), to_read, fp)) > 0) {
+               if (n_read < to_read && claws_ferror(fp))
+                       break;
+               if (claws_fwrite(buf, 1, n_read, dest_fp) < n_read) {
+                       return -1;
+               }
+               bytes_left -= n_read;
+               if (bytes_left == 0)
+                       break;
+               to_read = MIN(bytes_left, sizeof(buf));
+       }
+
+       if (claws_ferror(fp)) {
+               perror("claws_fread");
+               return -1;
+       }
+
+       return 0;
+}
+
+gint copy_file_part(FILE *fp, off_t offset, size_t length, const gchar *dest)
+{
+       FILE *dest_fp;
+       gboolean err = FALSE;
+
+       if ((dest_fp = claws_fopen(dest, "wb")) == NULL) {
+               FILE_OP_ERROR(dest, "claws_fopen");
+               return -1;
+       }
+
+       if (change_file_mode_rw(dest_fp, dest) < 0) {
+               FILE_OP_ERROR(dest, "chmod");
+               g_warning("can't change file mode: %s", dest);
+       }
+
+       if (copy_file_part_to_fp(fp, offset, length, dest_fp) < 0)
+               err = TRUE;
+
+       if (claws_safe_fclose(dest_fp) == EOF) {
+               FILE_OP_ERROR(dest, "claws_fclose");
+               err = TRUE;
+       }
+
+       if (err) {
+               g_warning("writing to %s failed.", dest);
+               claws_unlink(dest);
+               return -1;
+       }
+
+       return 0;
+}
+
+gint canonicalize_file(const gchar *src, const gchar *dest)
+{
+       FILE *src_fp, *dest_fp;
+       gchar buf[BUFFSIZE];
+       gint len;
+       gboolean err = FALSE;
+       gboolean last_linebreak = FALSE;
+
+       if (src == NULL || dest == NULL)
+               return -1;
+
+       if ((src_fp = claws_fopen(src, "rb")) == NULL) {
+               FILE_OP_ERROR(src, "claws_fopen");
+               return -1;
+       }
+
+       if ((dest_fp = claws_fopen(dest, "wb")) == NULL) {
+               FILE_OP_ERROR(dest, "claws_fopen");
+               claws_fclose(src_fp);
+               return -1;
+       }
+
+       if (change_file_mode_rw(dest_fp, dest) < 0) {
+               FILE_OP_ERROR(dest, "chmod");
+               g_warning("can't change file mode: %s", dest);
+       }
+
+       while (claws_fgets(buf, sizeof(buf), src_fp) != NULL) {
+               gint r = 0;
+
+               len = strlen(buf);
+               if (len == 0) break;
+               last_linebreak = FALSE;
+
+               if (buf[len - 1] != '\n') {
+                       last_linebreak = TRUE;
+                       r = claws_fputs(buf, dest_fp);
+               } else if (len > 1 && buf[len - 1] == '\n' && buf[len - 2] == '\r') {
+                       r = claws_fputs(buf, dest_fp);
+               } else {
+                       if (len > 1) {
+                               r = claws_fwrite(buf, 1, len - 1, dest_fp);
+                               if (r != (len -1))
+                                       r = EOF;
+                       }
+                       if (r != EOF)
+                               r = claws_fputs("\r\n", dest_fp);
+               }
+
+               if (r == EOF) {
+                       g_warning("writing to %s failed.", dest);
+                       claws_fclose(dest_fp);
+                       claws_fclose(src_fp);
+                       claws_unlink(dest);
+                       return -1;
+               }
+       }
+
+       if (last_linebreak == TRUE) {
+               if (claws_fputs("\r\n", dest_fp) == EOF)
+                       err = TRUE;
+       }
+
+       if (claws_ferror(src_fp)) {
+               FILE_OP_ERROR(src, "claws_fgets");
+               err = TRUE;
+       }
+       claws_fclose(src_fp);
+       if (claws_safe_fclose(dest_fp) == EOF) {
+               FILE_OP_ERROR(dest, "claws_fclose");
+               err = TRUE;
+       }
+
+       if (err) {
+               claws_unlink(dest);
+               return -1;
+       }
+
+       return 0;
+}
+
+gint canonicalize_file_replace(const gchar *file)
+{
+       gchar *tmp_file;
+
+       tmp_file = get_tmp_file();
+
+       if (canonicalize_file(file, tmp_file) < 0) {
+               g_free(tmp_file);
+               return -1;
+       }
+
+       if (move_file(tmp_file, file, TRUE) < 0) {
+               g_warning("can't replace file: %s", file);
+               claws_unlink(tmp_file);
+               g_free(tmp_file);
+               return -1;
+       }
+
+       g_free(tmp_file);
+       return 0;
+}
+
+
+gint str_write_to_file(const gchar *str, const gchar *file)
+{
+       FILE *fp;
+       size_t len;
+
+       cm_return_val_if_fail(str != NULL, -1);
+       cm_return_val_if_fail(file != NULL, -1);
+
+       if ((fp = claws_fopen(file, "wb")) == NULL) {
+               FILE_OP_ERROR(file, "claws_fopen");
+               return -1;
+       }
+
+       len = strlen(str);
+       if (len == 0) {
+               claws_fclose(fp);
+               return 0;
+       }
+
+       if (claws_fwrite(str, 1, len, fp) != len) {
+               FILE_OP_ERROR(file, "claws_fwrite");
+               claws_fclose(fp);
+               claws_unlink(file);
+               return -1;
+       }
+
+       if (claws_safe_fclose(fp) == EOF) {
+               FILE_OP_ERROR(file, "claws_fclose");
+               claws_unlink(file);
+               return -1;
+       }
+
+       return 0;
+}
+
+static gchar *file_read_stream_to_str_full(FILE *fp, gboolean recode)
+{
+       GByteArray *array;
+       guchar buf[BUFSIZ];
+       gint n_read;
+       gchar *str;
+
+       cm_return_val_if_fail(fp != NULL, NULL);
+
+       array = g_byte_array_new();
+
+       while ((n_read = claws_fread(buf, sizeof(gchar), sizeof(buf), fp)) > 0) {
+               if (n_read < sizeof(buf) && claws_ferror(fp))
+                       break;
+               g_byte_array_append(array, buf, n_read);
+       }
+
+       if (claws_ferror(fp)) {
+               FILE_OP_ERROR("file stream", "claws_fread");
+               g_byte_array_free(array, TRUE);
+               return NULL;
+       }
+
+       buf[0] = '\0';
+       g_byte_array_append(array, buf, 1);
+       str = (gchar *)array->data;
+       g_byte_array_free(array, FALSE);
+
+       if (recode && !g_utf8_validate(str, -1, NULL)) {
+               const gchar *src_codeset, *dest_codeset;
+               gchar *tmp = NULL;
+               src_codeset = conv_get_locale_charset_str();
+               dest_codeset = CS_UTF_8;
+               tmp = conv_codeset_strdup(str, src_codeset, dest_codeset);
+               g_free(str);
+               str = tmp;
+       }
+
+       return str;
+}
+
+static gchar *file_read_to_str_full(const gchar *file, gboolean recode)
+{
+       FILE *fp;
+       gchar *str;
+       GStatBuf s;
+#ifndef G_OS_WIN32
+       gint fd, err;
+       struct timeval timeout = {1, 0};
+       fd_set fds;
+       int fflags = 0;
+#endif
+
+       cm_return_val_if_fail(file != NULL, NULL);
+
+       if (g_stat(file, &s) != 0) {
+               FILE_OP_ERROR(file, "stat");
+               return NULL;
+       }
+       if (S_ISDIR(s.st_mode)) {
+               g_warning("%s: is a directory", file);
+               return NULL;
+       }
+
+#ifdef G_OS_WIN32
+       fp = claws_fopen (file, "rb");
+       if (fp == NULL) {
+               FILE_OP_ERROR(file, "open");
+               return NULL;
+       }
+#else    
+       /* test whether the file is readable without blocking */
+       fd = g_open(file, O_RDONLY | O_NONBLOCK, 0);
+       if (fd == -1) {
+               FILE_OP_ERROR(file, "open");
+               return NULL;
+       }
+
+       FD_ZERO(&fds);
+       FD_SET(fd, &fds);
+
+       /* allow for one second */
+       err = select(fd+1, &fds, NULL, NULL, &timeout);
+       if (err <= 0 || !FD_ISSET(fd, &fds)) {
+               if (err < 0) {
+                       FILE_OP_ERROR(file, "select");
+               } else {
+                       g_warning("%s: doesn't seem readable", file);
+               }
+               close(fd);
+               return NULL;
+       }
+       
+       /* Now clear O_NONBLOCK */
+       if ((fflags = fcntl(fd, F_GETFL)) < 0) {
+               FILE_OP_ERROR(file, "fcntl (F_GETFL)");
+               close(fd);
+               return NULL;
+       }
+       if (fcntl(fd, F_SETFL, (fflags & ~O_NONBLOCK)) < 0) {
+               FILE_OP_ERROR(file, "fcntl (F_SETFL)");
+               close(fd);
+               return NULL;
+       }
+       
+       /* get the FILE pointer */
+       fp = claws_fdopen(fd, "rb");
+
+       if (fp == NULL) {
+               FILE_OP_ERROR(file, "claws_fdopen");
+               close(fd); /* if fp isn't NULL, we'll use claws_fclose instead! */
+               return NULL;
+       }
+#endif
+
+       str = file_read_stream_to_str_full(fp, recode);
+
+       claws_fclose(fp);
+
+       return str;
+}
+
+gchar *file_read_to_str(const gchar *file)
+{
+       return file_read_to_str_full(file, TRUE);
+}
+gchar *file_read_stream_to_str(FILE *fp)
+{
+       return file_read_stream_to_str_full(fp, TRUE);
+}
+
+gchar *file_read_to_str_no_recode(const gchar *file)
+{
+       return file_read_to_str_full(file, FALSE);
+}
+gchar *file_read_stream_to_str_no_recode(FILE *fp)
+{
+       return file_read_stream_to_str_full(fp, FALSE);
+}
+
+gint rename_force(const gchar *oldpath, const gchar *newpath)
+{
+#ifndef G_OS_UNIX
+       if (!is_file_entry_exist(oldpath)) {
+               errno = ENOENT;
+               return -1;
+       }
+       if (is_file_exist(newpath)) {
+               if (claws_unlink(newpath) < 0)
+                       FILE_OP_ERROR(newpath, "unlink");
+       }
+#endif
+       return g_rename(oldpath, newpath);
+}
+
+gint copy_dir(const gchar *src, const gchar *dst)
+{
+       GDir *dir;
+       const gchar *name;
+
+       if ((dir = g_dir_open(src, 0, NULL)) == NULL) {
+               g_warning("failed to open directory: %s", src);
+               return -1;
+       }
+
+       if (make_dir(dst) < 0)
+               return -1;
+
+       while ((name = g_dir_read_name(dir)) != NULL) {
+               gchar *old_file, *new_file;
+               old_file = g_strconcat(src, G_DIR_SEPARATOR_S, name, NULL);
+               new_file = g_strconcat(dst, G_DIR_SEPARATOR_S, name, NULL);
+               debug_print("copying: %s -> %s\n", old_file, new_file);
+               if (g_file_test(old_file, G_FILE_TEST_IS_REGULAR)) {
+                       gint r = copy_file(old_file, new_file, TRUE);
+                       if (r < 0) {
+                               g_dir_close(dir);
+                               return r;
+                       }
+                }
+#ifndef G_OS_WIN32
+                /* Windows has no symlinks.  Or well, Vista seems to
+                   have something like this but the semantics might be
+                   different.  Thus we don't use it under Windows. */
+                else if (g_file_test(old_file, G_FILE_TEST_IS_SYMLINK)) {
+                       GError *error = NULL;
+                       gint r = 0;
+                       gchar *target = g_file_read_link(old_file, &error);
+                       if (target)
+                               r = symlink(target, new_file);
+                       g_free(target);
+                       if (r < 0) {
+                               g_dir_close(dir);
+                               return r;
+                       }
+                 }
+#endif /*G_OS_WIN32*/
+               else if (g_file_test(old_file, G_FILE_TEST_IS_DIR)) {
+                       gint r = copy_dir(old_file, new_file);
+                       if (r < 0) {
+                               g_dir_close(dir);
+                               return r;
+                       }
+               }
+       }
+       g_dir_close(dir);
+       return 0;
+}
+
+gint change_file_mode_rw(FILE *fp, const gchar *file)
+{
+#if HAVE_FCHMOD
+       return fchmod(fileno(fp), S_IRUSR|S_IWUSR);
+#else
+       return g_chmod(file, S_IRUSR|S_IWUSR);
+#endif
+}
+
+FILE *my_tmpfile(void)
+{
+       const gchar suffix[] = ".XXXXXX";
+       const gchar *tmpdir;
+       guint tmplen;
+       const gchar *progname;
+       guint proglen;
+       gchar *fname;
+       gint fd;
+       FILE *fp;
+#ifndef G_OS_WIN32
+       gchar buf[2]="\0";
+#endif
+
+       tmpdir = get_tmp_dir();
+       tmplen = strlen(tmpdir);
+       progname = g_get_prgname();
+       if (progname == NULL)
+               progname = "claws-mail";
+       proglen = strlen(progname);
+       Xalloca(fname, tmplen + 1 + proglen + sizeof(suffix),
+               return tmpfile());
+
+       memcpy(fname, tmpdir, tmplen);
+       fname[tmplen] = G_DIR_SEPARATOR;
+       memcpy(fname + tmplen + 1, progname, proglen);
+       memcpy(fname + tmplen + 1 + proglen, suffix, sizeof(suffix));
+
+       fd = g_mkstemp(fname);
+       if (fd < 0)
+               return tmpfile();
+
+#ifndef G_OS_WIN32
+       claws_unlink(fname);
+       
+       /* verify that we can write in the file after unlinking */
+       if (write(fd, buf, 1) < 0) {
+               close(fd);
+               return tmpfile();
+       }
+       
+#endif
+
+       fp = claws_fdopen(fd, "w+b");
+       if (!fp)
+               close(fd);
+       else {
+               rewind(fp);
+               return fp;
+       }
+
+       return tmpfile();
+}
+
+FILE *get_tmpfile_in_dir(const gchar *dir, gchar **filename)
+{
+       int fd;
+       *filename = g_strdup_printf("%s%cclaws.XXXXXX", dir, G_DIR_SEPARATOR);
+       fd = g_mkstemp(*filename);
+       if (fd < 0)
+               return NULL;
+       return claws_fdopen(fd, "w+");
+}
+
+FILE *str_open_as_stream(const gchar *str)
+{
+       FILE *fp;
+       size_t len;
+
+       cm_return_val_if_fail(str != NULL, NULL);
+
+       fp = my_tmpfile();
+       if (!fp) {
+               FILE_OP_ERROR("str_open_as_stream", "my_tmpfile");
+               return NULL;
+       }
+
+       len = strlen(str);
+       if (len == 0) return fp;
+
+       if (claws_fwrite(str, 1, len, fp) != len) {
+               FILE_OP_ERROR("str_open_as_stream", "claws_fwrite");
+               claws_fclose(fp);
+               return NULL;
+       }
+
+       rewind(fp);
+       return fp;
+}
+
+#endif
similarity index 50%
rename from src/common/claws_io.h
rename to src/common/file-utils.h
index 35edae3..6c5ad17 100644 (file)
@@ -25,6 +25,7 @@
 #endif
 
 #include <stdio.h>
+#include <glib.h>
 
 #if HAVE_FGETS_UNLOCKED
 #define claws_fgets fgets_unlocked
 #define claws_feof feof_unlocked
 #define claws_ferror ferror_unlocked
 
-FILE *claws_fopen(const char *file, const char *mode);
-FILE *claws_fdopen(int fd, const char *mode);
-int claws_fclose(FILE *fp);
-int claws_safe_fclose(FILE *fp);
+FILE *claws_fopen              (const char *file,
+                                const char *mode);
+FILE *claws_fdopen             (int fd,
+                                const char *mode);
+int claws_fclose               (FILE *fp);
+int claws_safe_fclose          (FILE *fp);
 
 #else
 
@@ -57,6 +60,48 @@ int claws_safe_fclose(FILE *fp);
 #define claws_safe_fclose safe_fclose
 #endif
 
-int safe_fclose(FILE *fp);
+int safe_fclose                        (FILE *fp);
+int claws_unlink               (const char     *filename);
+
+gint file_strip_crs            (const gchar    *file);
+gint append_file               (const gchar    *src,
+                                const gchar    *dest,
+                                gboolean        keep_backup);
+gint copy_file                 (const gchar    *src,
+                                const gchar    *dest,
+                                gboolean        keep_backup);
+gint move_file                 (const gchar    *src,
+                                const gchar    *dest,
+                                gboolean        overwrite);
+gint copy_file_part_to_fp      (FILE           *fp,
+                                off_t           offset,
+                                size_t          length,
+                                FILE           *dest_fp);
+gint copy_file_part            (FILE           *fp,
+                                off_t           offset,
+                                size_t          length,
+                                const gchar    *dest);
+gint canonicalize_file         (const gchar    *src,
+                                const gchar    *dest);
+gint canonicalize_file_replace (const gchar    *file);
+gint str_write_to_file         (const gchar    *str,
+                                const gchar    *file);
+gchar *file_read_to_str                (const gchar    *file);
+gchar *file_read_to_str_no_recode(const gchar  *file);
+gchar *file_read_stream_to_str (FILE           *fp);
+gchar *file_read_stream_to_str_no_recode(FILE  *fp);
+
+gint rename_force              (const gchar    *oldpath,
+                                const gchar    *newpath);
+gint copy_dir                  (const gchar    *src,
+                                const gchar    *dest);
+gint change_file_mode_rw       (FILE           *fp,
+                                const gchar    *file);
+FILE *my_tmpfile               (void);
+FILE *get_tmpfile_in_dir       (const gchar    *dir,
+                                gchar         **filename);
+FILE *str_open_as_stream       (const gchar    *str);
+gint str_write_to_file         (const gchar    *str,
+                                const gchar    *file);
 
 #endif
index 15a852b..83b023e 100644 (file)
@@ -34,7 +34,7 @@
 #include "utils.h"
 #include "log.h"
 #include "hooks.h"
-#include "claws_io.h"
+#include "file-utils.h"
 
 #define FWRITE(_b,_s,_n,_f)    if (claws_fwrite(_b,_s,_n,_f) != _n) { \
                                        g_message("log claws_fwrite failed!\n"); \
index 963b16d..39679e8 100644 (file)
@@ -41,7 +41,7 @@
 #include "prefs.h"
 #include "claws.h"
 #include "timing.h"
-#include "claws_io.h"
+#include "file-utils.h"
 
 #ifdef G_OS_WIN32
 #define PLUGINS_BLOCK_PREFIX "PluginsWin32_"
index 971193e..7489507 100644 (file)
@@ -30,7 +30,7 @@
 
 #include "prefs.h"
 #include "utils.h"
-#include "claws_io.h"
+#include "file-utils.h"
 
 static gboolean prefs_is_readonly      (const gchar    *path);
 
index 8afe4da..6db05f5 100644 (file)
@@ -46,7 +46,7 @@
 #include "socket.h"
 #include "hooks.h"
 #include "defs.h"
-#include "claws_io.h"
+#include "file-utils.h"
 
 static GHashTable *warned_expired = NULL;
 
index 4086323..7c8bf4d 100644 (file)
@@ -40,7 +40,7 @@
 #include "defs.h"
 #include "utils.h"
 #include "tags.h"
-#include "claws_io.h"
+#include "file-utils.h"
 
 static GHashTable *tags_table = NULL;
 static GHashTable *tags_reverse_table = NULL;
index 8ae5fde..a7f9ea1 100644 (file)
@@ -29,7 +29,7 @@
 #include "utils.h"
 #include "template.h"
 #include "codeconv.h"
-#include "claws_io.h"
+#include "file-utils.h"
 
 static GSList *template_list;
 
index aaae7b2..f288888 100644 (file)
@@ -86,7 +86,7 @@
 #include "codeconv.h"
 #include "tlds.h"
 #include "timing.h"
-#include "claws_io.h"
+#include "file-utils.h"
 
 #define BUFFSIZE       8192
 
@@ -314,50 +314,6 @@ gchar *strcrchomp(gchar *str)
        return str;
 }
 
-gint file_strip_crs(const gchar *file)
-{
-       FILE *fp = NULL, *outfp = NULL;
-       gchar buf[4096];
-       gchar *out = get_tmp_file();
-       if (file == NULL)
-               goto freeout;
-
-       fp = claws_fopen(file, "rb");
-       if (!fp)
-               goto freeout;
-
-       outfp = claws_fopen(out, "wb");
-       if (!outfp) {
-               claws_fclose(fp);
-               goto freeout;
-       }
-
-       while (claws_fgets(buf, sizeof (buf), fp) != NULL) {
-               strcrchomp(buf);
-               if (claws_fputs(buf, outfp) == EOF) {
-                       claws_fclose(fp);
-                       claws_fclose(outfp);
-                       goto unlinkout;
-               }
-       }
-
-       claws_fclose(fp);
-       if (claws_safe_fclose(outfp) == EOF) {
-               goto unlinkout;
-       }
-       
-       if (move_file(out, file, TRUE) < 0)
-               goto unlinkout;
-       
-       g_free(out);
-       return 0;
-unlinkout:
-       claws_unlink(out);
-freeout:
-       g_free(out);
-       return -1;
-}
-
 /* Similar to `strstr' but this function ignores the case of both strings.  */
 gchar *strcasestr(const gchar *haystack, const gchar *needle)
 {
@@ -2392,249 +2348,6 @@ gint remove_dir_recursive(const gchar *dir)
        return 0;
 }
 
-gint rename_force(const gchar *oldpath, const gchar *newpath)
-{
-#ifndef G_OS_UNIX
-       if (!is_file_entry_exist(oldpath)) {
-               errno = ENOENT;
-               return -1;
-       }
-       if (is_file_exist(newpath)) {
-               if (claws_unlink(newpath) < 0)
-                       FILE_OP_ERROR(newpath, "unlink");
-       }
-#endif
-       return g_rename(oldpath, newpath);
-}
-
-/*
- * Append src file body to the tail of dest file.
- * Now keep_backup has no effects.
- */
-gint append_file(const gchar *src, const gchar *dest, gboolean keep_backup)
-{
-       FILE *src_fp, *dest_fp;
-       gint n_read;
-       gchar buf[BUFSIZ];
-
-       gboolean err = FALSE;
-
-       if ((src_fp = claws_fopen(src, "rb")) == NULL) {
-               FILE_OP_ERROR(src, "claws_fopen");
-               return -1;
-       }
-
-       if ((dest_fp = claws_fopen(dest, "ab")) == NULL) {
-               FILE_OP_ERROR(dest, "claws_fopen");
-               claws_fclose(src_fp);
-               return -1;
-       }
-
-       if (change_file_mode_rw(dest_fp, dest) < 0) {
-               FILE_OP_ERROR(dest, "chmod");
-               g_warning("can't change file mode: %s", dest);
-       }
-
-       while ((n_read = claws_fread(buf, sizeof(gchar), sizeof(buf), src_fp)) > 0) {
-               if (n_read < sizeof(buf) && claws_ferror(src_fp))
-                       break;
-               if (claws_fwrite(buf, 1, n_read, dest_fp) < n_read) {
-                       g_warning("writing to %s failed.", dest);
-                       claws_fclose(dest_fp);
-                       claws_fclose(src_fp);
-                       claws_unlink(dest);
-                       return -1;
-               }
-       }
-
-       if (claws_ferror(src_fp)) {
-               FILE_OP_ERROR(src, "claws_fread");
-               err = TRUE;
-       }
-       claws_fclose(src_fp);
-       if (claws_fclose(dest_fp) == EOF) {
-               FILE_OP_ERROR(dest, "claws_fclose");
-               err = TRUE;
-       }
-
-       if (err) {
-               claws_unlink(dest);
-               return -1;
-       }
-
-       return 0;
-}
-
-gint copy_file(const gchar *src, const gchar *dest, gboolean keep_backup)
-{
-       FILE *src_fp, *dest_fp;
-       gint n_read;
-       gchar buf[BUFSIZ];
-       gchar *dest_bak = NULL;
-       gboolean err = FALSE;
-
-       if ((src_fp = claws_fopen(src, "rb")) == NULL) {
-               FILE_OP_ERROR(src, "claws_fopen");
-               return -1;
-       }
-       if (is_file_exist(dest)) {
-               dest_bak = g_strconcat(dest, ".bak", NULL);
-               if (rename_force(dest, dest_bak) < 0) {
-                       FILE_OP_ERROR(dest, "rename");
-                       claws_fclose(src_fp);
-                       g_free(dest_bak);
-                       return -1;
-               }
-       }
-
-       if ((dest_fp = claws_fopen(dest, "wb")) == NULL) {
-               FILE_OP_ERROR(dest, "claws_fopen");
-               claws_fclose(src_fp);
-               if (dest_bak) {
-                       if (rename_force(dest_bak, dest) < 0)
-                               FILE_OP_ERROR(dest_bak, "rename");
-                       g_free(dest_bak);
-               }
-               return -1;
-       }
-
-       if (change_file_mode_rw(dest_fp, dest) < 0) {
-               FILE_OP_ERROR(dest, "chmod");
-               g_warning("can't change file mode: %s", dest);
-       }
-
-       while ((n_read = claws_fread(buf, sizeof(gchar), sizeof(buf), src_fp)) > 0) {
-               if (n_read < sizeof(buf) && claws_ferror(src_fp))
-                       break;
-               if (claws_fwrite(buf, 1, n_read, dest_fp) < n_read) {
-                       g_warning("writing to %s failed.", dest);
-                       claws_fclose(dest_fp);
-                       claws_fclose(src_fp);
-                       claws_unlink(dest);
-                       if (dest_bak) {
-                               if (rename_force(dest_bak, dest) < 0)
-                                       FILE_OP_ERROR(dest_bak, "rename");
-                               g_free(dest_bak);
-                       }
-                       return -1;
-               }
-       }
-
-       if (claws_ferror(src_fp)) {
-               FILE_OP_ERROR(src, "claws_fread");
-               err = TRUE;
-       }
-       claws_fclose(src_fp);
-       if (claws_safe_fclose(dest_fp) == EOF) {
-               FILE_OP_ERROR(dest, "claws_fclose");
-               err = TRUE;
-       }
-
-       if (err) {
-               claws_unlink(dest);
-               if (dest_bak) {
-                       if (rename_force(dest_bak, dest) < 0)
-                               FILE_OP_ERROR(dest_bak, "rename");
-                       g_free(dest_bak);
-               }
-               return -1;
-       }
-
-       if (keep_backup == FALSE && dest_bak)
-               claws_unlink(dest_bak);
-
-       g_free(dest_bak);
-
-       return 0;
-}
-
-gint move_file(const gchar *src, const gchar *dest, gboolean overwrite)
-{
-       if (overwrite == FALSE && is_file_exist(dest)) {
-               g_warning("move_file(): file %s already exists.", dest);
-               return -1;
-       }
-
-       if (rename_force(src, dest) == 0) return 0;
-
-       if (EXDEV != errno) {
-               FILE_OP_ERROR(src, "rename");
-               return -1;
-       }
-
-       if (copy_file(src, dest, FALSE) < 0) return -1;
-
-       claws_unlink(src);
-
-       return 0;
-}
-
-gint copy_file_part_to_fp(FILE *fp, off_t offset, size_t length, FILE *dest_fp)
-{
-       gint n_read;
-       gint bytes_left, to_read;
-       gchar buf[BUFSIZ];
-
-       if (fseek(fp, offset, SEEK_SET) < 0) {
-               perror("fseek");
-               return -1;
-       }
-
-       bytes_left = length;
-       to_read = MIN(bytes_left, sizeof(buf));
-
-       while ((n_read = claws_fread(buf, sizeof(gchar), to_read, fp)) > 0) {
-               if (n_read < to_read && claws_ferror(fp))
-                       break;
-               if (claws_fwrite(buf, 1, n_read, dest_fp) < n_read) {
-                       return -1;
-               }
-               bytes_left -= n_read;
-               if (bytes_left == 0)
-                       break;
-               to_read = MIN(bytes_left, sizeof(buf));
-       }
-
-       if (claws_ferror(fp)) {
-               perror("claws_fread");
-               return -1;
-       }
-
-       return 0;
-}
-
-gint copy_file_part(FILE *fp, off_t offset, size_t length, const gchar *dest)
-{
-       FILE *dest_fp;
-       gboolean err = FALSE;
-
-       if ((dest_fp = claws_fopen(dest, "wb")) == NULL) {
-               FILE_OP_ERROR(dest, "claws_fopen");
-               return -1;
-       }
-
-       if (change_file_mode_rw(dest_fp, dest) < 0) {
-               FILE_OP_ERROR(dest, "chmod");
-               g_warning("can't change file mode: %s", dest);
-       }
-
-       if (copy_file_part_to_fp(fp, offset, length, dest_fp) < 0)
-               err = TRUE;
-
-       if (claws_safe_fclose(dest_fp) == EOF) {
-               FILE_OP_ERROR(dest, "claws_fclose");
-               err = TRUE;
-       }
-
-       if (err) {
-               g_warning("writing to %s failed.", dest);
-               claws_unlink(dest);
-               return -1;
-       }
-
-       return 0;
-}
-
 /* convert line endings into CRLF. If the last line doesn't end with
  * linebreak, add it.
  */
@@ -2671,109 +2384,6 @@ gchar *canonicalize_str(const gchar *str)
        return out;
 }
 
-gint canonicalize_file(const gchar *src, const gchar *dest)
-{
-       FILE *src_fp, *dest_fp;
-       gchar buf[BUFFSIZE];
-       gint len;
-       gboolean err = FALSE;
-       gboolean last_linebreak = FALSE;
-
-       if (src == NULL || dest == NULL)
-               return -1;
-
-       if ((src_fp = claws_fopen(src, "rb")) == NULL) {
-               FILE_OP_ERROR(src, "claws_fopen");
-               return -1;
-       }
-
-       if ((dest_fp = claws_fopen(dest, "wb")) == NULL) {
-               FILE_OP_ERROR(dest, "claws_fopen");
-               claws_fclose(src_fp);
-               return -1;
-       }
-
-       if (change_file_mode_rw(dest_fp, dest) < 0) {
-               FILE_OP_ERROR(dest, "chmod");
-               g_warning("can't change file mode: %s", dest);
-       }
-
-       while (claws_fgets(buf, sizeof(buf), src_fp) != NULL) {
-               gint r = 0;
-
-               len = strlen(buf);
-               if (len == 0) break;
-               last_linebreak = FALSE;
-
-               if (buf[len - 1] != '\n') {
-                       last_linebreak = TRUE;
-                       r = claws_fputs(buf, dest_fp);
-               } else if (len > 1 && buf[len - 1] == '\n' && buf[len - 2] == '\r') {
-                       r = claws_fputs(buf, dest_fp);
-               } else {
-                       if (len > 1) {
-                               r = claws_fwrite(buf, 1, len - 1, dest_fp);
-                               if (r != (len -1))
-                                       r = EOF;
-                       }
-                       if (r != EOF)
-                               r = claws_fputs("\r\n", dest_fp);
-               }
-
-               if (r == EOF) {
-                       g_warning("writing to %s failed.", dest);
-                       claws_fclose(dest_fp);
-                       claws_fclose(src_fp);
-                       claws_unlink(dest);
-                       return -1;
-               }
-       }
-
-       if (last_linebreak == TRUE) {
-               if (claws_fputs("\r\n", dest_fp) == EOF)
-                       err = TRUE;
-       }
-
-       if (claws_ferror(src_fp)) {
-               FILE_OP_ERROR(src, "claws_fgets");
-               err = TRUE;
-       }
-       claws_fclose(src_fp);
-       if (claws_safe_fclose(dest_fp) == EOF) {
-               FILE_OP_ERROR(dest, "claws_fclose");
-               err = TRUE;
-       }
-
-       if (err) {
-               claws_unlink(dest);
-               return -1;
-       }
-
-       return 0;
-}
-
-gint canonicalize_file_replace(const gchar *file)
-{
-       gchar *tmp_file;
-
-       tmp_file = get_tmp_file();
-
-       if (canonicalize_file(file, tmp_file) < 0) {
-               g_free(tmp_file);
-               return -1;
-       }
-
-       if (move_file(tmp_file, file, TRUE) < 0) {
-               g_warning("can't replace file: %s", file);
-               claws_unlink(tmp_file);
-               g_free(tmp_file);
-               return -1;
-       }
-
-       g_free(tmp_file);
-       return 0;
-}
-
 gchar *normalize_newlines(const gchar *str)
 {
        const gchar *p;
@@ -2874,280 +2484,6 @@ gchar *generate_mime_boundary(const gchar *prefix)
                               buf_uniq);
 }
 
-gint change_file_mode_rw(FILE *fp, const gchar *file)
-{
-#if HAVE_FCHMOD
-       return fchmod(fileno(fp), S_IRUSR|S_IWUSR);
-#else
-       return g_chmod(file, S_IRUSR|S_IWUSR);
-#endif
-}
-
-FILE *my_tmpfile(void)
-{
-       const gchar suffix[] = ".XXXXXX";
-       const gchar *tmpdir;
-       guint tmplen;
-       const gchar *progname;
-       guint proglen;
-       gchar *fname;
-       gint fd;
-       FILE *fp;
-#ifndef G_OS_WIN32
-       gchar buf[2]="\0";
-#endif
-
-       tmpdir = get_tmp_dir();
-       tmplen = strlen(tmpdir);
-       progname = g_get_prgname();
-       if (progname == NULL)
-               progname = "claws-mail";
-       proglen = strlen(progname);
-       Xalloca(fname, tmplen + 1 + proglen + sizeof(suffix),
-               return tmpfile());
-
-       memcpy(fname, tmpdir, tmplen);
-       fname[tmplen] = G_DIR_SEPARATOR;
-       memcpy(fname + tmplen + 1, progname, proglen);
-       memcpy(fname + tmplen + 1 + proglen, suffix, sizeof(suffix));
-
-       fd = g_mkstemp(fname);
-       if (fd < 0)
-               return tmpfile();
-
-#ifndef G_OS_WIN32
-       claws_unlink(fname);
-       
-       /* verify that we can write in the file after unlinking */
-       if (write(fd, buf, 1) < 0) {
-               close(fd);
-               return tmpfile();
-       }
-       
-#endif
-
-       fp = claws_fdopen(fd, "w+b");
-       if (!fp)
-               close(fd);
-       else {
-               rewind(fp);
-               return fp;
-       }
-
-       return tmpfile();
-}
-
-FILE *get_tmpfile_in_dir(const gchar *dir, gchar **filename)
-{
-       int fd;
-       *filename = g_strdup_printf("%s%cclaws.XXXXXX", dir, G_DIR_SEPARATOR);
-       fd = g_mkstemp(*filename);
-       if (fd < 0)
-               return NULL;
-       return claws_fdopen(fd, "w+");
-}
-
-FILE *str_open_as_stream(const gchar *str)
-{
-       FILE *fp;
-       size_t len;
-
-       cm_return_val_if_fail(str != NULL, NULL);
-
-       fp = my_tmpfile();
-       if (!fp) {
-               FILE_OP_ERROR("str_open_as_stream", "my_tmpfile");
-               return NULL;
-       }
-
-       len = strlen(str);
-       if (len == 0) return fp;
-
-       if (claws_fwrite(str, 1, len, fp) != len) {
-               FILE_OP_ERROR("str_open_as_stream", "claws_fwrite");
-               claws_fclose(fp);
-               return NULL;
-       }
-
-       rewind(fp);
-       return fp;
-}
-
-gint str_write_to_file(const gchar *str, const gchar *file)
-{
-       FILE *fp;
-       size_t len;
-
-       cm_return_val_if_fail(str != NULL, -1);
-       cm_return_val_if_fail(file != NULL, -1);
-
-       if ((fp = claws_fopen(file, "wb")) == NULL) {
-               FILE_OP_ERROR(file, "claws_fopen");
-               return -1;
-       }
-
-       len = strlen(str);
-       if (len == 0) {
-               claws_fclose(fp);
-               return 0;
-       }
-
-       if (claws_fwrite(str, 1, len, fp) != len) {
-               FILE_OP_ERROR(file, "claws_fwrite");
-               claws_fclose(fp);
-               claws_unlink(file);
-               return -1;
-       }
-
-       if (claws_safe_fclose(fp) == EOF) {
-               FILE_OP_ERROR(file, "claws_fclose");
-               claws_unlink(file);
-               return -1;
-       }
-
-       return 0;
-}
-
-static gchar *file_read_stream_to_str_full(FILE *fp, gboolean recode)
-{
-       GByteArray *array;
-       guchar buf[BUFSIZ];
-       gint n_read;
-       gchar *str;
-
-       cm_return_val_if_fail(fp != NULL, NULL);
-
-       array = g_byte_array_new();
-
-       while ((n_read = claws_fread(buf, sizeof(gchar), sizeof(buf), fp)) > 0) {
-               if (n_read < sizeof(buf) && claws_ferror(fp))
-                       break;
-               g_byte_array_append(array, buf, n_read);
-       }
-
-       if (claws_ferror(fp)) {
-               FILE_OP_ERROR("file stream", "claws_fread");
-               g_byte_array_free(array, TRUE);
-               return NULL;
-       }
-
-       buf[0] = '\0';
-       g_byte_array_append(array, buf, 1);
-       str = (gchar *)array->data;
-       g_byte_array_free(array, FALSE);
-
-       if (recode && !g_utf8_validate(str, -1, NULL)) {
-               const gchar *src_codeset, *dest_codeset;
-               gchar *tmp = NULL;
-               src_codeset = conv_get_locale_charset_str();
-               dest_codeset = CS_UTF_8;
-               tmp = conv_codeset_strdup(str, src_codeset, dest_codeset);
-               g_free(str);
-               str = tmp;
-       }
-
-       return str;
-}
-
-static gchar *file_read_to_str_full(const gchar *file, gboolean recode)
-{
-       FILE *fp;
-       gchar *str;
-       GStatBuf s;
-#ifndef G_OS_WIN32
-       gint fd, err;
-       struct timeval timeout = {1, 0};
-       fd_set fds;
-       int fflags = 0;
-#endif
-
-       cm_return_val_if_fail(file != NULL, NULL);
-
-       if (g_stat(file, &s) != 0) {
-               FILE_OP_ERROR(file, "stat");
-               return NULL;
-       }
-       if (S_ISDIR(s.st_mode)) {
-               g_warning("%s: is a directory", file);
-               return NULL;
-       }
-
-#ifdef G_OS_WIN32
-       fp = claws_fopen (file, "rb");
-       if (fp == NULL) {
-               FILE_OP_ERROR(file, "open");
-               return NULL;
-       }
-#else    
-       /* test whether the file is readable without blocking */
-       fd = g_open(file, O_RDONLY | O_NONBLOCK, 0);
-       if (fd == -1) {
-               FILE_OP_ERROR(file, "open");
-               return NULL;
-       }
-
-       FD_ZERO(&fds);
-       FD_SET(fd, &fds);
-
-       /* allow for one second */
-       err = select(fd+1, &fds, NULL, NULL, &timeout);
-       if (err <= 0 || !FD_ISSET(fd, &fds)) {
-               if (err < 0) {
-                       FILE_OP_ERROR(file, "select");
-               } else {
-                       g_warning("%s: doesn't seem readable", file);
-               }
-               close(fd);
-               return NULL;
-       }
-       
-       /* Now clear O_NONBLOCK */
-       if ((fflags = fcntl(fd, F_GETFL)) < 0) {
-               FILE_OP_ERROR(file, "fcntl (F_GETFL)");
-               close(fd);
-               return NULL;
-       }
-       if (fcntl(fd, F_SETFL, (fflags & ~O_NONBLOCK)) < 0) {
-               FILE_OP_ERROR(file, "fcntl (F_SETFL)");
-               close(fd);
-               return NULL;
-       }
-       
-       /* get the FILE pointer */
-       fp = claws_fdopen(fd, "rb");
-
-       if (fp == NULL) {
-               FILE_OP_ERROR(file, "claws_fdopen");
-               close(fd); /* if fp isn't NULL, we'll use claws_fclose instead! */
-               return NULL;
-       }
-#endif
-
-       str = file_read_stream_to_str_full(fp, recode);
-
-       claws_fclose(fp);
-
-       return str;
-}
-
-gchar *file_read_to_str(const gchar *file)
-{
-       return file_read_to_str_full(file, TRUE);
-}
-gchar *file_read_stream_to_str(FILE *fp)
-{
-       return file_read_stream_to_str_full(fp, TRUE);
-}
-
-gchar *file_read_to_str_no_recode(const gchar *file)
-{
-       return file_read_to_str_full(file, FALSE);
-}
-gchar *file_read_stream_to_str_no_recode(FILE *fp)
-{
-       return file_read_stream_to_str_full(fp, FALSE);
-}
-
 char *fgets_crlf(char *buf, int size, FILE *stream)
 {
        gboolean is_cr = FALSE;
@@ -4592,60 +3928,6 @@ void mailcap_update_default(const gchar *type, const gchar *command)
        g_free(outpath);
 }
 
-gint copy_dir(const gchar *src, const gchar *dst)
-{
-       GDir *dir;
-       const gchar *name;
-
-       if ((dir = g_dir_open(src, 0, NULL)) == NULL) {
-               g_warning("failed to open directory: %s", src);
-               return -1;
-       }
-
-       if (make_dir(dst) < 0)
-               return -1;
-
-       while ((name = g_dir_read_name(dir)) != NULL) {
-               gchar *old_file, *new_file;
-               old_file = g_strconcat(src, G_DIR_SEPARATOR_S, name, NULL);
-               new_file = g_strconcat(dst, G_DIR_SEPARATOR_S, name, NULL);
-               debug_print("copying: %s -> %s\n", old_file, new_file);
-               if (g_file_test(old_file, G_FILE_TEST_IS_REGULAR)) {
-                       gint r = copy_file(old_file, new_file, TRUE);
-                       if (r < 0) {
-                               g_dir_close(dir);
-                               return r;
-                       }
-                }
-#ifndef G_OS_WIN32
-                /* Windows has no symlinks.  Or well, Vista seems to
-                   have something like this but the semantics might be
-                   different.  Thus we don't use it under Windows. */
-                else if (g_file_test(old_file, G_FILE_TEST_IS_SYMLINK)) {
-                       GError *error = NULL;
-                       gint r = 0;
-                       gchar *target = g_file_read_link(old_file, &error);
-                       if (target)
-                               r = symlink(target, new_file);
-                       g_free(target);
-                       if (r < 0) {
-                               g_dir_close(dir);
-                               return r;
-                       }
-                 }
-#endif /*G_OS_WIN32*/
-               else if (g_file_test(old_file, G_FILE_TEST_IS_DIR)) {
-                       gint r = copy_dir(old_file, new_file);
-                       if (r < 0) {
-                               g_dir_close(dir);
-                               return r;
-                       }
-               }
-       }
-       g_dir_close(dir);
-       return 0;
-}
-
 /* crude test to see if a file is an email. */
 gboolean file_is_email (const gchar *filename)
 {
@@ -5046,49 +4328,10 @@ size_t fast_strftime(gchar *buf, gint buflen, const gchar *format, struct tm *lt
        return total_done;
 }
 
-gboolean prefs_common_get_use_shred(void);
-
-
 #ifdef G_OS_WIN32
 #define WEXITSTATUS(x) (x)
 #endif
 
-int claws_unlink(const gchar *filename) 
-{
-       GStatBuf s;
-       static int found_shred = -1;
-       static const gchar *args[4];
-
-       if (filename == NULL)
-               return 0;
-
-       if (prefs_common_get_use_shred()) {
-               if (found_shred == -1) {
-                       /* init */
-                       args[0] = g_find_program_in_path("shred");
-                       debug_print("found shred: %s\n", args[0]);
-                       found_shred = (args[0] != NULL) ? 1:0;
-                       args[1] = "-f";
-                       args[3] = NULL;
-               }
-               if (found_shred == 1) {
-                       if (g_stat(filename, &s) == 0 && S_ISREG(s.st_mode)) {
-                               if (s.st_nlink == 1) {
-                                       gint status=0;
-                                       args[2] = filename;
-                                       g_spawn_sync(NULL, (gchar **)args, NULL, 0,
-                                        NULL, NULL, NULL, NULL, &status, NULL);
-                                       debug_print("%s %s exited with status %d\n",
-                                               args[0], filename, WEXITSTATUS(status));
-                                       if (truncate(filename, 0) < 0)
-                                               g_warning("couln't truncate: %s", filename);
-                               }
-                       }
-               }
-       }
-       return g_unlink(filename);
-}
-
 GMutex *cm_mutex_new(void) {
 #if GLIB_CHECK_VERSION(2,32,0)
        GMutex *m = g_new0(GMutex, 1);
index 96c4dc2..dfb327f 100644 (file)
@@ -281,7 +281,6 @@ gchar *strretchomp  (gchar          *str);
 gchar *strtailchomp    (gchar          *str,
                         gchar           tail_char);
 gchar *strcrchomp      (gchar          *str);
-gint file_strip_crs    (const gchar    *file);
 gchar *strcasestr      (const gchar    *haystack,
                         const gchar    *needle);
 gchar *strncasestr     (const gchar    *haystack,
@@ -427,50 +426,11 @@ gint remove_numbered_files_not_in_list(const gchar *dir,
                                       GSList *numberlist);
 gint remove_all_numbered_files (const gchar    *dir);
 gint remove_dir_recursive      (const gchar    *dir);
-gint append_file               (const gchar    *src,
-                                const gchar    *dest,
-                                gboolean        keep_backup);
-gint rename_force              (const gchar    *oldpath,
-                                const gchar    *newpath);
-gint copy_file                 (const gchar    *src,
-                                const gchar    *dest,
-                                gboolean        keep_backup);
-gint move_file                 (const gchar    *src,
-                                const gchar    *dest,
-                                gboolean        overwrite);
-gint copy_dir                  (const gchar    *src,
-                                const gchar    *dest);
-gint copy_file_part_to_fp      (FILE           *fp,
-                                off_t           offset,
-                                size_t          length,
-                                FILE           *dest_fp);
-gint copy_file_part            (FILE           *fp,
-                                off_t           offset,
-                                size_t          length,
-                                const gchar    *dest);
-
 gchar *canonicalize_str                (const gchar    *str);
-gint canonicalize_file         (const gchar    *src,
-                                const gchar    *dest);
-gint canonicalize_file_replace (const gchar    *file);
-
 gchar *normalize_newlines      (const gchar    *str);
 
 gchar *get_outgoing_rfc2822_str        (FILE           *fp);
 
-gint change_file_mode_rw       (FILE           *fp,
-                                const gchar    *file);
-FILE *my_tmpfile               (void);
-FILE *get_tmpfile_in_dir       (const gchar    *dir,
-                                gchar         **filename);
-FILE *str_open_as_stream       (const gchar    *str);
-gint str_write_to_file         (const gchar    *str,
-                                const gchar    *file);
-gchar *file_read_to_str                (const gchar    *file);
-gchar *file_read_stream_to_str (FILE           *fp);
-gchar *file_read_to_str_no_recode(const gchar *file);
-gchar *file_read_stream_to_str_no_recode(FILE *fp);
-
 char *fgets_crlf(char *buf, int size, FILE *stream);
 
 /* process execution */
@@ -563,8 +523,6 @@ gboolean file_is_email(const gchar *filename);
 gboolean sc_g_list_bigger(GList *list, gint max);
 gboolean sc_g_slist_bigger(GSList *list, gint max);
 
-int claws_unlink(const gchar *filename);
-
 GMutex *cm_mutex_new(void);
 void cm_mutex_free(GMutex *mutex);
 
index 50cc9a5..874db1f 100644 (file)
@@ -30,7 +30,7 @@
 #include "xml.h"
 #include "utils.h"
 #include "codeconv.h"
-#include "claws_io.h"
+#include "file-utils.h"
 
 #define SPARSE_MEMORY
 /* if this is defined all attr.names and tag.names are stored
index 1fc1c28..0557bd2 100644 (file)
@@ -45,7 +45,7 @@
 #include "mgutils.h"
 #include "xmlprops.h"
 #include "utils.h"
-#include "claws_io.h"
+#include "file-utils.h"
 
 /* Element tag names */
 #define XMLS_ELTAG_PROP_LIST     "property-list"
index 1344b2b..bf33007 100644 (file)
 #include "autofaces.h"
 #include "spell_entry.h"
 #include "headers.h"
-#include "claws_io.h"
+#include "file-utils.h"
 
 #ifdef USE_LDAP
 #include "password.h"
index ef50ca8..8fcdce6 100644 (file)
@@ -44,6 +44,7 @@
 #include "prefs_common.h"
 #include "menu.h"
 #include "combobox.h"
+#include "file-utils.h"
 
 /* transient data */
 static struct _PersonEdit_dlg personeditdlg;
index b8b0eb3..c29affa 100644 (file)
@@ -29,7 +29,7 @@
 
 #include "enriched.h"
 #include "utils.h"
-#include "claws_io.h"
+#include "file-utils.h"
 
 #define ERTFBUFSIZE    8192
 
index 4a11f4f..c6dd801 100644 (file)
@@ -44,7 +44,7 @@
 #include "utils.h"
 #include "mainwindow.h"
 #include "proxy.h"
-#include "claws_io.h"
+#include "file-utils.h"
 #include "ssl.h"
 #include "ssl_certificate.h"
 #include "socket.h"
index 5dbec5b..86bfdfe 100644 (file)
@@ -46,7 +46,7 @@
 #include "utils.h"
 #include "exporthtml.h"
 #include "xmlprops.h"
-#include "claws_io.h"
+#include "file-utils.h"
 
 #ifdef MKDIR_TAKES_ONE_ARG
 #undef mkdir
index 54e6bd0..c35d6de 100644 (file)
@@ -38,7 +38,7 @@
 #include "exportldif.h"
 #include "xmlprops.h"
 #include "ldif.h"
-#include "claws_io.h"
+#include "file-utils.h"
 
 
 #ifdef MKDIR_TAKES_ONE_ARG
index d458a83..ccf8d54 100644 (file)
@@ -35,6 +35,7 @@
 #include <string.h>
 #include <ctype.h>
 
+#include "file-utils.h"
 #include "utils.h"
 #include "alertpanel.h"
 #include "folder.h"
index 97c5d01..abe8072 100644 (file)
@@ -63,7 +63,7 @@
 #include "privacy.h"
 #include "prefs_common.h"
 #include "prefs_migration.h"
-#include "claws_io.h"
+#include "file-utils.h"
 
 /* Dependecies to be removed ?! */
 #include "prefs_account.h"
index b86de3a..d442387 100644 (file)
@@ -43,7 +43,7 @@
 #include "menu.h"
 #include "textview.h"
 #include "main.h"
-#include "claws_io.h"
+#include "file-utils.h"
 
 extern SessionStats session_stats;
 static GtkTextBuffer *stats_text_buffer;
index 190b467..b702404 100644 (file)
@@ -30,7 +30,7 @@
 #include "codeconv.h"
 #include "utils.h"
 #include "entity.h"
-#include "claws_io.h"
+#include "file-utils.h"
 
 #define SC_HTMLBUFSIZE 8192
 #define HR_STR         "────────────────────────────────────────────────"
index d56e2c1..09fd79c 100644 (file)
@@ -27,6 +27,7 @@
 #include <gtk/gtk.h>
 
 #include "procmime.h"
+#include "file-utils.h"
 #include "utils.h"
 #include "mimeview.h"
 
index 5871b79..1e98aac 100644 (file)
@@ -71,7 +71,7 @@
 #include "tags.h"
 #include "main.h"
 #include "passwordstore.h"
-#include "claws_io.h"
+#include "file-utils.h"
 
 typedef struct _IMAPFolder     IMAPFolder;
 typedef struct _IMAPSession    IMAPSession;
index ed681fb..78fc240 100644 (file)
--- a/src/inc.c
+++ b/src/inc.c
@@ -45,6 +45,7 @@
 #include "pop.h"
 #include "recv.h"
 #include "mbox.h"
+#include "file-utils.h"
 #include "utils.h"
 #include "gtkutils.h"
 #include "statusbar.h"
index a29b02b..7b37c37 100644 (file)
@@ -56,7 +56,7 @@
 #include "codeconv.h"
 #include "adbookbase.h"
 #include "utils.h"
-#include "claws_io.h"
+#include "file-utils.h"
 
 #define JPILOT_DBHOME_DIR   ".jpilot"
 #define JPILOT_DBHOME_FILE  "AddressDB.pdb"
index 16a20d7..2e96831 100644 (file)
@@ -38,7 +38,7 @@
 #include "ldapctrl.h"
 #include "ldapserver.h"
 #include "mgutils.h"
-#include "claws_io.h"
+#include "file-utils.h"
 
 #include "addritem.h"
 #include "addrcache.h"
index a632123..d2b19ef 100644 (file)
@@ -32,7 +32,7 @@
 #include "addrcache.h"
 
 #include "utils.h"
-#include "claws_io.h"
+#include "file-utils.h"
 
 #define        LDIF_SEP_TAG    ':'
 #define        LDIF_LANG_TAG   ';'
index 631e366..65a3ec1 100644 (file)
 #include "advsearch.h"
 #include "avatars.h"
 #include "passwordstore.h"
-#include "claws_io.h"
+#include "file-utils.h"
 
 #ifdef HAVE_LIBETPAN
 #include "imap-thread.h"
index c87c897..1186dba 100644 (file)
@@ -49,7 +49,7 @@
 #include "tags.h"
 #include "folder_item_prefs.h"
 #include "procmsg.h"
-#include "claws_io.h"
+#include "file-utils.h"
 
 /*!
  *\brief       Keyword lookup element
index 2f7db0d..9047fbb 100644 (file)
@@ -55,7 +55,7 @@
 #include "filtering.h"
 #include "alertpanel.h"
 #include "statusbar.h"
-#include "claws_io.h"
+#include "file-utils.h"
 
 #define MESSAGEBUFSIZE 8192
 
index 409e864..829f158 100644 (file)
@@ -67,7 +67,7 @@
 #include "statusbar.h"
 #include "folder_item_prefs.h"
 #include "avatars.h"
-#include "claws_io.h"
+#include "file-utils.h"
 
 #ifndef USE_ALT_ADDRBOOK
        #include "addressbook.h"
index b0967a8..e7d0d6c 100644 (file)
--- a/src/mh.c
+++ b/src/mh.c
@@ -44,7 +44,7 @@
 #include "gtkutils.h"
 #include "timing.h"
 #include "msgcache.h"
-#include "claws_io.h"
+#include "file-utils.h"
 
 /* Define possible missing constants for Windows. */
 #ifdef G_OS_WIN32
index f6eac4c..e1598f3 100644 (file)
@@ -55,7 +55,7 @@
 #include "timing.h"
 #include "manage_window.h"
 #include "privacy.h"
-#include "claws_io.h"
+#include "file-utils.h"
 
 typedef enum
 {
index ca9d965..3910255 100644 (file)
@@ -46,7 +46,7 @@
 #include "timing.h"
 #include "tags.h"
 #include "prefs_common.h"
-#include "claws_io.h"
+#include "file-utils.h"
 
 #if G_BYTE_ORDER == G_BIG_ENDIAN
 #define bswap_32(x) \
index 8ae8508..c6224c8 100644 (file)
@@ -31,7 +31,7 @@
 #include "mutt.h"
 #include "addritem.h"
 #include "addrcache.h"
-#include "claws_io.h"
+#include "file-utils.h"
 
 #define MUTT_HOME_FILE  ".muttrc"
 #define MUTTBUFSIZE     2048
index c963ac1..70eb4d6 100644 (file)
@@ -62,7 +62,7 @@
 #  include "ssl.h"
 #endif
 #include "main.h"
-#include "claws_io.h"
+#include "file-utils.h"
 
 #define NNTP_PORT      119
 #ifdef USE_GNUTLS
index 76b25fc..3edb635 100644 (file)
@@ -63,7 +63,7 @@
 #include "folder.h"
 #include "procheader.h"
 #include "msgcache.h"
-#include "claws_io.h"
+#include "file-utils.h"
 
 int partial_msg_in_uidl_list(MsgInfo *msginfo)
 {
index ddf6f95..f67048c 100644 (file)
@@ -37,7 +37,7 @@
 #include "prefs_common.h"
 #include "prefs_gtk.h"
 #include "prefs_migration.h"
-#include "claws_io.h"
+#include "file-utils.h"
 
 static GSList *_password_store;
 
index d4b11d1..20944d0 100644 (file)
@@ -30,7 +30,7 @@
 #include "pine.h"
 #include "addritem.h"
 #include "addrcache.h"
-#include "claws_io.h"
+#include "file-utils.h"
 
 #define PINE_HOME_FILE  ".addressbook"
 #define PINEBUFSIZE     2048
index e32b65c..37abea3 100644 (file)
@@ -47,7 +47,7 @@
 #include "utils.h"
 #include "folder_item_prefs.h"
 #include "gtkcmoptionmenu.h"
-#include "claws_io.h"
+#include "file-utils.h"
 
 #define PREFS_BLOCK_NAME "AcpiNotifier"
 #define PLUGIN_NAME _("Acpi Notifier")
index 27ff539..452be92 100644 (file)
@@ -41,6 +41,7 @@
 #include "common/md5.h"
 #include "plugin.h"
 #include "mainwindow.h"
+#include "file-utils.h"
 #include "utils.h"
 #include "prefs.h"
 #include "folder.h"
index 590d392..ffd620a 100644 (file)
@@ -52,7 +52,7 @@
 #include "prefs_common.h"
 #include "alertpanel.h"
 #include "addr_compl.h"
-#include "claws_io.h"
+#include "file-utils.h"
 
 #ifdef HAVE_SYSEXITS_H
 #include <sysexits.h>
index 831e035..95fa8f3 100644 (file)
@@ -55,7 +55,7 @@
 #include "statusbar.h"
 #include "alertpanel.h"
 #include "clamd-plugin.h"
-#include "claws_io.h"
+#include "file-utils.h"
 
 #ifndef UNIX_PATH_MAX
 #define UNIX_PATH_MAX 108
index d5eae61..24411cf 100644 (file)
@@ -35,6 +35,7 @@
 #include "common/claws.h"
 #include "common/version.h"
 #include "plugin.h"
+#include "file-utils.h"
 #include "utils.h"
 #include "mimeview.h"
 #include "addr_compl.h"
index 6e930e1..ce677ee 100644 (file)
@@ -30,6 +30,7 @@
 #include "claws.h"
 #include "plugin.h"
 #include "gtkutils.h"
+#include "file-utils.h"
 #include "utils.h"
 #include "prefs.h"
 #include "prefs_common.h"
index b4933c3..a10f6bc 100644 (file)
@@ -28,7 +28,7 @@
 #include <fancy_viewer.h>
 #include <fancy_prefs.h>
 #include <alertpanel.h>
-#include <claws_io.h>
+#include <file-utils.h>
 
 #include <printing.h>
 #include <webkit/webkithittestresult.h>
index 7f01620..22fa9cd 100644 (file)
@@ -19,6 +19,7 @@
 #include <sys/stat.h>
 
 #include "libravatar_cache.h"
+#include "file-utils.h"
 #include "utils.h"
 
 gchar *libravatar_cache_init(const char *dirs[], gint start, gint end)
index 20bc3b2..d36408e 100644 (file)
@@ -27,7 +27,7 @@
 
 #include <common/claws.h>
 #include <prefs_common.h>
-#include <claws_io.h>
+#include <file-utils.h>
 
 #include "libravatar.h"
 #include "libravatar_prefs.h"
index dc2d81f..0ff67f0 100644 (file)
@@ -21,7 +21,7 @@
 #include "libravatar_missing.h"
 #include "libravatar_prefs.h"
 #include "utils.h"
-#include "claws_io.h"
+#include "file-utils.h"
 
 /**
  * Loads the hash table of md5sum → time from the given filename.
index e932ca7..19b3b29 100644 (file)
@@ -39,7 +39,7 @@
 #endif
 
 #include "mailimf.h"
-#include "claws_io.h"
+#include "file-utils.h"
 
 /*
   RFC 2822
index 27352b5..cb5b953 100644 (file)
@@ -43,7 +43,7 @@
 #include <time.h>
 #include <string.h>
 #include <ctype.h>
-#include "claws_io.h"
+#include "file-utils.h"
 
 #define MAX_MAIL_COL 72
 
index b32af40..dda0070 100644 (file)
@@ -58,8 +58,8 @@
 #include "mmapstring.h"
 #include "mailmbox_parse.h"
 #include "maillock.h"
+#include "file-utils.h"
 #include "utils.h"
-#include "claws_io.h"
 
 /*
   http://www.qmail.org/qmail-manual-html/man5/mbox.html
index 569d9b7..632fa3d 100644 (file)
@@ -56,7 +56,7 @@
 #include "mailmbox.h"
 #include "mailmbox_folder.h"
 #include "mailmbox_parse.h"
-#include "claws_io.h"
+#include "file-utils.h"
 
 #define MAILMBOX_CACHE_DIR           "mailmboxcache"
 
index b8c483c..9a925e7 100644 (file)
@@ -31,7 +31,7 @@
 #include <inttypes.h>
 
 #include "plugin.h"
-#include "claws_io.h"
+#include "file-utils.h"
 
 #define LOG_NAME       "NewLog"
 #define DEFAULT_DIR    "Mail"
index 737837d..ae001be 100644 (file)
@@ -31,6 +31,7 @@
 #include "gtk/inputdialog.h"
 #include "mimeview.h"
 #include "summaryview.h"
+#include "file-utils.h"
 #ifndef POPPLER_WITH_GDK
 #include "stdbool.h"
 #endif
index a4bdda0..106387d 100644 (file)
@@ -45,7 +45,7 @@
 #include "common/log.h"
 #include "common/plugin.h"
 #include "common/tags.h"
-#include "claws_io.h"
+#include "file-utils.h"
 
 #include <EXTERN.h>
 #include <perl.h>
index 8d3e95c..f7b2793 100644 (file)
@@ -30,7 +30,7 @@
 
 #include "pgp_utils.h"
 #include "codeconv.h"
-#include "claws_io.h"
+#include "file-utils.h"
 
 gchar *fp_read_noconv(FILE *fp)
 {
index 6586295..b037ef7 100644 (file)
@@ -59,7 +59,7 @@
 #include "account.h"
 #include "select-keys.h"
 #include "claws.h"
-#include "claws_io.h"
+#include "file-utils.h"
 
 static void sgpgme_disable_all(void)
 {
index d4bee07..b284e64 100644 (file)
@@ -28,7 +28,7 @@
 #include <glib/gi18n.h>
 #include <errno.h>
 #include <gpgme.h>
-#include <claws_io.h>
+#include <file-utils.h>
 
 #include "utils.h"
 #include "privacy.h"
index d768de4..4ee1898 100644 (file)
@@ -42,7 +42,7 @@
 #include <plugins/pgpcore/pgp_utils.h>
 
 #include "prefs_common.h"
-#include "claws_io.h"
+#include "file-utils.h"
 
 typedef struct _PrivacyDataPGP PrivacyDataPGP;
 
index 69c4e06..e9fcd6e 100644 (file)
@@ -39,7 +39,7 @@
 #include "python-shell.h"
 #include "python-hooks.h"
 #include "clawsmailmodule.h"
-#include "claws_io.h"
+#include "file-utils.h"
 
 #define PYTHON_SCRIPTS_BASE_DIR "python-scripts"
 #define PYTHON_SCRIPTS_MAIN_DIR "main"
index d87169b..f6202b8 100644 (file)
@@ -32,7 +32,7 @@
 #include <log.h>
 #include <folder.h>
 #include <common/utils.h>
-#include <claws_io.h>
+#include <file-utils.h>
 
 /* Local includes */
 #include "libfeed/date.h"
index c98590e..b246a74 100644 (file)
@@ -33,7 +33,6 @@
 #include <folder.h>
 #include <procmsg.h>
 #include <localfolder.h>
-#include <common/utils.h>
 #include <main.h>
 #include <mh.h>
 #include <xml.h>
@@ -41,6 +40,7 @@
 #include <prefs_common.h>
 #include <prefs_toolbar.h>
 #include <utils.h>
+#include <file-utils.h>
 
 /* Local includes */
 #include "libfeed/feeditem.h"
index cc9d8dd..5e74276 100644 (file)
@@ -34,7 +34,7 @@
 #include <codeconv.h>
 #include <procmsg.h>
 #include <common/utils.h>
-#include <claws_io.h>
+#include <file-utils.h>
 
 /* Local includes */
 #include "libfeed/date.h"
index c8c6395..4a7569a 100644 (file)
@@ -31,7 +31,7 @@
 /* Claws Mail includes */
 #include <codeconv.h>
 #include <common/utils.h>
-#include <claws_io.h>
+#include <file-utils.h>
 
 /* Local includes */
 #include "rssyl.h"
index 184dee3..4480429 100644 (file)
@@ -38,6 +38,7 @@
 #include "rssyl.h"
 #include "rssyl_feed.h"
 #include "strutils.h"
+#include "file-utils.h"
 
 struct _RUpdateFormatCtx {
        FolderItem *o_prev;
index 82edd92..ea999c1 100644 (file)
@@ -43,7 +43,7 @@
 #include "prefs_common.h"
 #include "procmime.h"
 #include "plugin.h"
-#include "claws_io.h"
+#include "file-utils.h"
 
 typedef struct _PrivacyDataPGP PrivacyDataPGP;
 
index 826281d..21c96cc 100644 (file)
@@ -35,6 +35,7 @@
 #include "password.h"
 #include "plugin.h"
 #include "prefs_common.h"
+#include "file-utils.h"
 #include "utils.h"
 #include "spam_report_prefs.h"
 #include "statusbar.h"
index 09e52b0..5f9836b 100644 (file)
@@ -70,6 +70,7 @@
 #endif
 
 /* must load *after* errno.h, Bug 6697 */
+#include "file-utils.h"
 #include "utils.h"
 
 /* RedHat 5.2 doesn't define Shutdown 2nd Parameter Constants */
index 5c0632c..0cd725a 100644 (file)
@@ -51,7 +51,7 @@
 #include "prefs_common.h"
 #include "alertpanel.h"
 #include "addr_compl.h"
-#include "claws_io.h"
+#include "file-utils.h"
 
 #ifdef HAVE_SYSEXITS_H
 #include <sysexits.h>
index 93ef632..be8812d 100644 (file)
@@ -48,7 +48,7 @@
 #include "plugin.h"
 #include "procmime.h"
 #include "utils.h"
-#include "claws_io.h"
+#include "file-utils.h"
 
 #include "tnef_dump.h"
 
index 4cde1bc..21a9227 100644 (file)
@@ -37,6 +37,7 @@
 #include <ctype.h>
 
 #include "account.h"
+#include "file-utils.h"
 #include "utils.h"
 #include "procmsg.h"
 #include "procheader.h"
index 52bfd81..009cdbd 100644 (file)
@@ -49,6 +49,7 @@
 #include <time.h>
 #include "folder.h"
 #include "quoted-printable.h"
+#include "file-utils.h"
 #include "utils.h"
 #include "defs.h"
 
index befe163..8e7dff1 100644 (file)
@@ -54,7 +54,7 @@
 #include "gtkutils.h"
 #include "log.h"
 #include "utils.h"
-#include "claws_io.h"
+#include "file-utils.h"
 
 struct _VCalMeeting
 {
index 386a48a..7dcfd9f 100644 (file)
@@ -36,6 +36,7 @@
 #include "folder.h"
 #include "folder_item_prefs.h"
 #include "mimeview.h"
+#include "file-utils.h"
 #include "utils.h"
 #include "vcalendar.h"
 #include "vcal_manager.h"
@@ -54,7 +55,6 @@
 #include "statusbar.h"
 #include "timing.h"
 #include "inc.h"
-#include "claws_io.h"
 
 MimeViewerFactory vcal_viewer_factory;
 
index 4c5f521..6de10c6 100644 (file)
--- a/src/pop.c
+++ b/src/pop.c
@@ -40,7 +40,7 @@
 #include "partial_download.h"
 #include "log.h"
 #include "hooks.h"
-#include "claws_io.h"
+#include "file-utils.h"
 
 static gint pop3_greeting_recv         (Pop3Session *session,
                                         const gchar *msg);
index 1821ef3..1eb6cee 100644 (file)
@@ -65,7 +65,7 @@
 #include "inputdialog.h"
 #include "ssl_certificate.h"
 #include "passwordstore.h"
-#include "claws_io.h"
+#include "file-utils.h"
 
 static gboolean cancelled;
 static gboolean new_account;
index 9db536e..25e0b4d 100644 (file)
@@ -51,7 +51,7 @@
 #include "prefs_filtering_action.h"
 #include "matcher_parser.h"
 #include "prefs_toolbar.h"
-#include "claws_io.h"
+#include "file-utils.h"
 
 enum {
        PREFS_ACTIONS_STRING,   /*!< string pointer managed by list store, 
index 30fbb7a..bdca614 100644 (file)
@@ -61,7 +61,7 @@
 #include "prefswindow.h"
 #include "colorlabel.h"
 #include "passwordstore.h"
-#include "claws_io.h"
+#include "file-utils.h"
 
 #ifndef USE_ALT_ADDRBOOK
        #include "addrcustomattr.h"
index 04b09e7..8ed91f8 100644 (file)
@@ -48,7 +48,7 @@
 #include "alertpanel.h"
 #include "filesel.h"
 #include "combobox.h"
-#include "claws_io.h"
+#include "file-utils.h"
 
 enum {
        CUSTHDR_STRING,         /*!< display string managed by list store */
index bd70f4f..3c43ebe 100644 (file)
@@ -41,7 +41,7 @@
 #include "displayheader.h"
 #include "utils.h"
 #include "gtkutils.h"
-#include "claws_io.h"
+#include "file-utils.h"
 
 enum {
        PREFS_HDR_HEADER,
index fedffcc..b39bcbd 100644 (file)
@@ -41,7 +41,7 @@
 #include "gtkutils.h"
 #include "password.h"
 #include "codeconv.h"
-#include "claws_io.h"
+#include "file-utils.h"
 
 #define CL(x)  (((gulong) (x) >> (gulong) 8) & 0xFFUL)
 #define RGB_FROM_GDK_COLOR(c) \
index b6f7336..b045013 100644 (file)
@@ -48,7 +48,7 @@
 #include "compose.h"
 #include "alertpanel.h"
 #include "addr_compl.h"
-#include "claws_io.h"
+#include "file-utils.h"
 
 #define IS_CURRENT_THEME(path)  (strcmp(prefs_common.pixmap_theme_path, path) == 0)
 #define IS_INTERNAL_THEME(path) (strcmp(DEFAULT_PIXMAP_THEME, path) == 0)
index 9431841..d384db0 100644 (file)
@@ -41,7 +41,7 @@
 #include "hooks.h"
 #include "utils.h"
 #include "defs.h"
-#include "claws_io.h"
+#include "file-utils.h"
 
 #define BUFFSIZE       8192
 
index bcf68e2..9bd6ef2 100644 (file)
@@ -52,7 +52,7 @@
 #include "timing.h"
 #include "privacy.h"
 #include "account.h"
-#include "claws_io.h"
+#include "file-utils.h"
 
 static GHashTable *procmime_get_mime_type_table        (void);
 static MimeInfo *procmime_scan_file_short(const gchar *filename);
index 34eff51..ee98e09 100644 (file)
@@ -49,7 +49,7 @@
 #include "timing.h"
 #include "inc.h"
 #include "privacy.h"
-#include "claws_io.h"
+#include "file-utils.h"
 
 extern SessionStats session_stats;
 
index 515d910..7e29f34 100644 (file)
@@ -37,7 +37,7 @@
 #include "quote_fmt.h"
 #include "quote_fmt_lex.h"
 #include "account.h"
-#include "claws_io.h"
+#include "file-utils.h"
 
 /* decl */
 /*
index d0a2160..ce8b125 100644 (file)
@@ -56,7 +56,7 @@
 #include "inc.h"
 #include "log.h"
 #include "passwordstore.h"
-#include "claws_io.h"
+#include "file-utils.h"
 
 typedef struct _SendProgressDialog     SendProgressDialog;
 
index a16ce86..f3465b7 100644 (file)
@@ -30,7 +30,7 @@
 #include "utils.h"
 #include "gtkutils.h"
 #include "prefs_common.h"
-#include "claws_io.h"
+#include "file-utils.h"
 
 static void source_window_size_alloc_cb        (GtkWidget      *widget,
                                         GtkAllocation  *allocation);
index 1bba495..4be1f61 100644 (file)
@@ -46,6 +46,7 @@
 #include "prefs_filtering.h"
 #include "account.h"
 #include "compose.h"
+#include "file-utils.h"
 #include "utils.h"
 #include "gtkutils.h"
 #include "stock_pixmap.h"
index e4d2b51..5c8710c 100644 (file)
@@ -69,7 +69,7 @@
 #include "folder_item_prefs.h"
 #include "hooks.h"
 #include "avatars.h"
-#include "claws_io.h"
+#include "file-utils.h"
 
 static GdkColor quote_colors[3] = {
        {(gulong)0, (gushort)0, (gushort)0, (gushort)0},
index deb083d..df417a8 100644 (file)
@@ -40,7 +40,7 @@
 #include "utils.h"
 #include "codeconv.h"
 #include "quoted-printable.h"
-#include "claws_io.h"
+#include "file-utils.h"
 
 #define GNOMECARD_DIR     ".gnome"
 #define GNOMECARD_FILE    "GnomeCard"
index 68da688..a942347 100644 (file)
@@ -34,6 +34,7 @@
 #include <string.h>
 #include <ctype.h>
 
+#include "file-utils.h"
 #include "utils.h"
 #include "gtk/menu.h"
 #include "plugin.h"