/*
* Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2003 Hiroyuki Yamamoto
+ * Copyright (C) 1999-2005 Hiroyuki Yamamoto
*
* 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
#include "defs.h"
#include <glib.h>
+#include <glib/gi18n.h>
#include <dirent.h>
#include <sys/stat.h>
#include <unistd.h>
# include <sys/time.h>
#endif
-#include "intl.h"
#include "folder.h"
#include "mh.h"
#include "procmsg.h"
static gchar *mh_item_get_path (Folder *folder,
FolderItem *item);
+static gboolean mh_scan_required (Folder *folder,
+ FolderItem *item);
+
static FolderClass mh_class;
FolderClass *mh_get_class(void)
mh_class.rename_folder = mh_rename_folder;
mh_class.remove_folder = mh_remove_folder;
mh_class.get_num_list = mh_get_num_list;
+ mh_class.scan_required = mh_scan_required;
/* Message functions */
mh_class.get_msginfo = mh_get_msginfo;
}
+gboolean mh_scan_required(Folder *folder, FolderItem *item)
+{
+ gchar *path;
+ struct stat s;
+
+ path = folder_item_get_path(item);
+ g_return_val_if_fail(path != NULL, FALSE);
+
+ if (stat(path, &s) < 0) {
+ FILE_OP_ERROR(path, "stat");
+ g_free(path);
+ return FALSE;
+ }
+
+ if ((s.st_mtime > item->mtime) &&
+ (s.st_mtime - 3600 != item->mtime)) {
+ debug_print("MH scan required, folder updated: %s (%ld > %ld)\n",
+ path,
+ s.st_mtime,
+ item->mtime);
+ g_free(path);
+ return TRUE;
+ }
+
+ debug_print("MH scan not required: %s (%ld <= %ld)\n",
+ path,
+ s.st_mtime,
+ item->mtime);
+ g_free(path);
+ return FALSE;
+}
+
void mh_get_last_num(Folder *folder, FolderItem *item)
{
gchar *path;
}
while ((d = readdir(dp)) != NULL) {
- if ((num = to_number(d->d_name)) >= 0 &&
+ if ((num = to_number(d->d_name)) > 0 &&
dirent_is_regular_file(d)) {
if (max < num)
max = num;
g_return_val_if_fail(item != NULL, -1);
- debug_print("mh_get_last_num(): Scanning %s ...\n", item->path);
+ debug_print("mh_get_num_list(): Scanning %s ...\n", item->path);
*old_uids_valid = TRUE;
}
while ((d = readdir(dp)) != NULL) {
- if ((num = to_number(d->d_name)) >= 0) {
+ if ((num = to_number(d->d_name)) > 0) {
*list = g_slist_prepend(*list, GINT_TO_POINTER(num));
nummsgs++;
}
}
closedir(dp);
+ item->mtime = time(NULL);
return nummsgs;
}
if (!is_file_exist(file)) {
g_free(file);
+ g_free(path);
return NULL;
}
-
+ g_free(path);
return file;
}
static gint mh_copy_msg(Folder *folder, FolderItem *dest, MsgInfo *msginfo)
{
+ gboolean dest_need_scan = FALSE;
gchar *srcfile;
gchar *destfile;
gint filemode = 0;
return -1;
}
+ dest_need_scan = mh_scan_required(dest->folder, dest);
+ if (!dest_need_scan)
+ dest->mtime = time(NULL);
+
if (prefs && prefs->enable_folder_chmod && prefs->folder_chmod) {
if (chmod(destfile, prefs->folder_chmod) < 0)
static gint mh_remove_msg(Folder *folder, FolderItem *item, gint num)
{
+ gboolean need_scan = FALSE;
gchar *file;
g_return_val_if_fail(item != NULL, -1);
file = mh_fetch_msg(folder, item, num);
g_return_val_if_fail(file != NULL, -1);
+ need_scan = mh_scan_required(folder, item);
+
if (unlink(file) < 0) {
FILE_OP_ERROR(file, "unlink");
g_free(file);
return -1;
}
+ if (!need_scan)
+ item->mtime = time(NULL);
+
g_free(file);
return 0;
}
struct stat s;
if (stat(itos(msginfo->msgnum), &s) < 0 ||
- msginfo->size != s.st_size ||
- msginfo->mtime != s.st_mtime)
+ msginfo->size != s.st_size || (
+ (msginfo->mtime - s.st_mtime != 0) &&
+ (msginfo->mtime - s.st_mtime != 3600) &&
+ (msginfo->mtime - s.st_mtime != -3600)))
return TRUE;
return FALSE;
if (!is_dir_exist(oldpath))
make_dir_hier(oldpath);
- dirname = g_dirname(oldpath);
+ dirname = g_path_get_dirname(oldpath);
real_name = mh_filename_from_utf8(name);
newpath = g_strconcat(dirname, G_DIR_SEPARATOR_S, real_name, NULL);
g_free(real_name);
g_free(newpath);
if (strchr(item->path, G_DIR_SEPARATOR) != NULL) {
- dirname = g_dirname(item->path);
+ dirname = g_path_get_dirname(item->path);
utf8newpath = g_strconcat(dirname, G_DIR_SEPARATOR_S,
name, NULL);
g_free(dirname);
closedir(dp);
+ item->mtime = time(NULL);
+
/*
if (item->path) {
gint new, unread, total, min, max;
return FALSE;
}
-#warning FIXME_GTK2 /* should we use g_filename_from_utf8()? */
static gchar *mh_filename_from_utf8(const gchar *path)
{
const gchar *src_codeset = CS_UTF_8;
- const gchar *dest_codeset = conv_get_current_charset_str();
+ const gchar *dest_codeset = conv_get_locale_charset_str();
gchar *real_path;
real_path = conv_codeset_strdup(path, src_codeset, dest_codeset);
return real_path;
}
-#warning FIXME_GTK2 /* should we use g_filename_to_utf8()? */
static gchar *mh_filename_to_utf8(const gchar *path)
{
- const gchar *src_codeset = conv_get_current_charset_str();
+ const gchar *src_codeset = conv_get_locale_charset_str();
const gchar *dest_codeset = CS_UTF_8;
gchar *utf8path;