2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2001 Hiroyuki Yamamoto & The Sylpheed Claws Team
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 #include <sys/types.h>
29 #include "mbox_folder.h"
32 #include "procheader.h"
36 #define MSGBUFSIZE 8192
38 static void mbox_folder_init (Folder *folder,
42 static gboolean mbox_write_data(FILE * mbox_fp, FILE * new_fp,
43 gchar * new_filename, gint size);
44 static gboolean mbox_rewrite(gchar * mbox);
45 static gboolean mbox_purge_deleted(gchar * mbox);
46 static gchar * mbox_get_new_path(FolderItem * parent, gchar * name);
47 static gchar * mbox_get_folderitem_name(gchar * name);
49 MsgInfo *mbox_fetch_msginfo(Folder *folder, FolderItem *item, gint num);
50 GSList *mbox_get_num_list(Folder *folder, FolderItem *item);
51 gboolean mbox_check_msgnum_validity(Folder *folder, FolderItem *item);
53 Folder *mbox_folder_new(const gchar *name, const gchar *path)
57 folder = (Folder *)g_new0(MBOXFolder, 1);
58 mbox_folder_init(folder, name, path);
63 void mbox_folder_destroy(MBOXFolder *folder)
65 folder_local_folder_destroy(LOCAL_FOLDER(folder));
68 static void mbox_folder_init(Folder *folder, const gchar *name, const gchar *path)
70 folder->type = F_MBOX;
72 folder_local_folder_init(folder, name, path);
75 folder->get_msg_list = mbox_get_msg_list;
77 folder->fetch_msg = mbox_fetch_msg;
78 folder->fetch_msginfo = mbox_fetch_msginfo;
79 folder->add_msg = mbox_add_msg;
80 folder->copy_msg = mbox_copy_msg;
81 folder->remove_msg = mbox_remove_msg;
82 folder->remove_all_msg = mbox_remove_all_msg;
84 folder->scan = mbox_scan_folder;
86 folder->get_num_list = mbox_get_num_list;
87 folder->create_tree = mbox_create_tree;
88 folder->create_folder = mbox_create_folder;
89 folder->rename_folder = mbox_rename_folder;
90 folder->remove_folder = mbox_remove_folder;
91 folder->check_msgnum_validity
92 = mbox_check_msgnum_validity;
95 static void mbox_folder_create_parent(const gchar * path)
97 if (!is_file_exist(path)) {
100 new_path = g_dirname(path);
101 if (new_path[strlen(new_path) - 1] == G_DIR_SEPARATOR)
102 new_path[strlen(new_path) - 1] = '\0';
104 if (!is_dir_exist(new_path))
105 make_dir_hier(new_path);
112 static gchar *mbox_folder_get_path(FolderItem *item)
117 g_return_val_if_fail(item != NULL, NULL);
119 if (item->path && item->path[0] == G_DIR_SEPARATOR) {
120 mbox_folder_create_parent(item->path);
121 return g_strdup(item->path);
124 folder_path = g_strdup(LOCAL_FOLDER(item->folder)->rootpath);
125 g_return_val_if_fail(folder_path != NULL, NULL);
127 if (folder_path[0] == G_DIR_SEPARATOR) {
129 path = g_strconcat(folder_path, G_DIR_SEPARATOR_S,
133 path = g_strdup(folder_path);
136 path = g_strconcat(get_home_dir(), G_DIR_SEPARATOR_S,
137 folder_path, G_DIR_SEPARATOR_S,
140 path = g_strconcat(get_home_dir(), G_DIR_SEPARATOR_S,
146 mbox_folder_create_parent(path);
152 /**********************************************************/
156 /**********************************************************/
159 static GSList * file_lock = NULL;
161 static gboolean mbox_file_lock_file(gchar * base)
163 gchar *lockfile, *locklink;
167 lockfile = g_strdup_printf("%s.%d", base, getpid());
168 if ((lockfp = fopen(lockfile, "wb")) == NULL) {
169 FILE_OP_ERROR(lockfile, "fopen");
170 g_warning(_("can't create lock file %s\n"), lockfile);
171 g_warning(_("use 'flock' instead of 'file' if possible.\n"));
176 fprintf(lockfp, "%d\n", getpid());
179 locklink = g_strconcat(base, ".lock", NULL);
180 while (link(lockfile, locklink) < 0) {
181 FILE_OP_ERROR(lockfile, "link");
183 g_warning(_("can't create %s\n"), lockfile);
189 g_warning(_("mailbox is owned by another"
190 " process, waiting...\n"));
200 static gboolean mbox_fcntl_lockwrite_file(FILE * fp)
204 lck.l_type = F_WRLCK;
209 if (fcntl(fileno(fp), F_SETLK, &lck) < 0)
215 static gboolean mbox_fcntl_lockread_file(FILE * fp)
219 lck.l_type = F_RDLCK;
224 if (fcntl(fileno(fp), F_SETLK, &lck) < 0)
230 static gboolean mbox_fcntl_unlock_file(FILE * fp)
234 lck.l_type = F_UNLCK;
239 if (fcntl(fileno(fp), F_SETLK, &lck) < 0)
245 static gboolean mbox_file_unlock_file(gchar * base)
249 lockfile = g_strdup_printf("%s.lock", base);
256 static gboolean mbox_lockread_file(FILE * fp, gchar * base)
260 result = mbox_fcntl_lockread_file(fp);
262 if ((result = mbox_file_lock_file(base)) == TRUE) {
263 file_lock = g_slist_append(file_lock, g_strdup(base));
264 debug_print("lockfile lock %s.\n", base);
267 g_warning(_("could not lock read file %s\n"), base);
270 debug_print("fcntl lock %s.\n", base);
275 static gboolean mbox_lockwrite_file(FILE * fp, gchar * base)
279 result = mbox_fcntl_lockwrite_file(fp);
281 if ((result = mbox_file_lock_file(base)) == TRUE) {
282 file_lock = g_slist_append(file_lock, g_strdup(base));
283 debug_print("lockfile lock %s.\n", base);
286 g_warning(_("could not lock write file %s\n"), base);
289 debug_print("fcntl lock %s.\n", base);
294 static gboolean mbox_unlock_file(FILE * fp, gchar * base)
296 gboolean result = FALSE;
298 gboolean unlocked = FALSE;
300 for(l = file_lock ; l != NULL ; l = g_slist_next(l)) {
301 gchar * data = l->data;
303 if (strcmp(data, base) == 0) {
304 file_lock = g_slist_remove(file_lock, data);
306 result = mbox_file_unlock_file(base);
308 debug_print("lockfile unlock - %s.\n", base);
314 result = mbox_fcntl_unlock_file(fp);
315 debug_print("fcntl unlock - %s.\n", base);
321 /**********************************************************/
325 /**********************************************************/
327 #define MAILFILE_ERROR_NO_ERROR 0x000
328 #define MAILFILE_ERROR_FILE_NOT_FOUND 0x001
329 #define MAILFILE_ERROR_MEMORY 0x002
330 #define MAILFILE_ERROR_MESSAGE_NOT_FOUND 0x003
332 static int mailfile_error = MAILFILE_ERROR_NO_ERROR;
334 #define STATE_BEGIN 0x000
335 #define STATE_TEXT_READ 0x001
336 #define STATE_FROM_READ 0x002
337 #define STATE_FIELD_READ 0x003
338 #define STATE_END 0x004
339 #define STATE_END_OF_FILE 0x005
340 #define STATE_MEM_ERROR 0x006
341 #define STATE_TEXT_BEGIN 0x007
343 #define STATE_MASK 0x0FF /* filter state from functions */
345 #define STATE_RESTORE_POS 0x100 /* go back while reading */
347 typedef struct _mailfile mailfile;
371 #define MSG_IS_INVALID(msg) \
372 ((msg).perm_flags == (msg).tmp_flags && (msg).tmp_flags == -1)
374 #define MSG_SET_INVALID(msg) \
375 ((msg).perm_flags = (msg).tmp_flags = -1)
377 static int startFrom(char * s)
379 return (strncmp(s, "From ", 5) == 0);
382 static int startSpace(char * s)
384 return ((*s == ' ') || (*s == '\t'));
387 static int startEmpty(char * s)
392 static void free_msg_list(GList * l)
394 GList * elt = g_list_first(l);
399 elt = g_list_next(elt);
406 static mailfile * mailfile_init_from_file(FILE * f, gchar * filename)
409 GList * msg_list = NULL;
416 struct _message * data = NULL;
422 while (state != STATE_END_OF_FILE) {
423 if ((state & STATE_RESTORE_POS) == 0) {
424 former_pos = lastpos;
427 r = fgets(s, 256, f);
430 ignore_next = (s[strlen(s) - 1] != '\n');
435 switch(state & 0x0F) {
438 state = STATE_END_OF_FILE;
439 else if (startFrom(s)) {
440 state = STATE_FROM_READ;
442 data = g_new0(struct _message, 1);
444 free_msg_list(msg_list);
449 data->msgnum = msgnum;
450 data->offset = lastpos;
451 data->header = lastpos;
454 data->messageid = NULL;
455 data->fromspace = NULL;
456 MSG_SET_INVALID(data->flags);
457 MSG_SET_INVALID(data->old_flags);
458 data->fetched = FALSE;
459 msg_list = g_list_append(msg_list,
467 case STATE_TEXT_READ:
470 else if (startFrom(s))
471 state = STATE_END | STATE_RESTORE_POS;
473 state = STATE_TEXT_READ;
476 case STATE_TEXT_BEGIN:
477 data->content = lastpos;
480 else if (startFrom(s)) {
481 state = STATE_END | STATE_RESTORE_POS;
484 state = STATE_TEXT_READ;
488 case STATE_FROM_READ:
489 data->content = lastpos;
492 else if (startSpace(s))
493 state = STATE_FROM_READ;
494 else if (startEmpty(s))
495 state = STATE_TEXT_READ;
497 state = STATE_FIELD_READ;
500 case STATE_FIELD_READ:
501 data->content = lastpos;
504 else if (startSpace(s))
505 state = STATE_FIELD_READ;
506 else if (startEmpty(s)) {
507 state = STATE_TEXT_BEGIN;
510 state = STATE_FIELD_READ;
514 if ((state & STATE_MASK) == STATE_END) {
515 state = STATE_BEGIN | (state & STATE_RESTORE_POS);
521 r = fgets(s, 256, f);
522 if (r == NULL || *r == '\0')
525 while (s[strlen(s) - 1] != '\n');
529 mf = (mailfile *) g_new0(struct _mailfile, 1);
531 free_msg_list(msg_list);
532 mailfile_error = MAILFILE_ERROR_MEMORY;
536 mf->msg_list = g_list_first(msg_list);
538 mf->filename = g_strdup(filename);
541 mailfile_error = MAILFILE_ERROR_NO_ERROR;
546 static mailfile * mailfile_init(char * filename)
552 f = fopen(filename, "rb");
555 mailfile_error = MAILFILE_ERROR_FILE_NOT_FOUND;
559 mbox_lockread_file(f, filename);
561 mf = mailfile_init_from_file(f, filename);
563 mbox_unlock_file(f, filename);
570 static void mailfile_done(mailfile * f)
572 free_msg_list(f->msg_list);
579 #define MAX_READ 4096
581 static char * readfile(char * filename, int offset, int max_offset)
590 handle = fopen(filename, "rb");
592 if (handle == NULL) {
593 mailfile_error = MAILFILE_ERROR_FILE_NOT_FOUND;
597 size = max_offset - offset;
599 message = (char *) malloc(size + 1);
600 if (message == NULL) {
602 mailfile_error = MAILFILE_ERROR_MEMORY;
606 fseek(handle, offset, SEEK_SET);
610 if ((size - pos) > MAX_READ)
615 bread = fread(message + pos, 1, max, handle);
631 static char * mailfile_readmsg(mailfile f, int index)
637 struct _message * msginfo;
639 nth = g_list_nth(f->msg_list, index);
642 mailfile_error = MAILFILE_ERROR_MESSAGE_NOT_FOUND;
646 msginfo = (struct _message *)nth->data;
648 offset = msginfo->offset;
649 max_offset = msginfo->end;
650 message = readfile(f->filename, offset, max_offset);
652 mailfile_error = MAILFILE_ERROR_NO_ERROR;
657 static char * mailfile_readheader(mailfile f, int index)
663 struct _message * msginfo;
665 nth = g_list_nth(f->msg_list, index);
668 mailfile_error = MAILFILE_ERROR_MESSAGE_NOT_FOUND;
672 msginfo = (struct _message *)nth->data;
674 offset = msginfo->offset;
675 max_offset = msginfo->content;
676 message = readfile(f->filename, offset, max_offset);
678 mailfile_error = MAILFILE_ERROR_NO_ERROR;
683 static int mailfile_count(mailfile * f)
685 return g_list_length(f->msg_list);
688 static int mailfile_find_deleted(mailfile f, char * filename)
692 handle = fopen(filename, "rb");
695 struct _message m = elt->data;
696 n = fread(&m.deleted, sizeof(int), 1, handle);
699 elt = g_list_next(elt);
708 /**********************************************************/
710 /* mbox cache operations */
712 /**********************************************************/
719 gboolean modification;
722 typedef struct _mboxcache mboxcache;
724 static GHashTable * mbox_cache_table = NULL;
726 static MsgInfo *mbox_parse_msg(FILE * fp, struct _message * msg,
730 MsgFlags flags = { 0, 0 };
732 MSG_SET_PERM_FLAGS(flags, MSG_NEW | MSG_UNREAD);
734 g_return_val_if_fail(fp != NULL, NULL);
737 if (item->stype == F_QUEUE) {
738 MSG_SET_TMP_FLAGS(flags, MSG_QUEUED);
739 } else if (item->stype == F_DRAFT) {
740 MSG_SET_TMP_FLAGS(flags, MSG_DRAFT);
744 msginfo = procheader_parse_stream(fp, flags, FALSE, FALSE);
746 if (!msginfo) return NULL;
749 msginfo->msgnum = msg->msgnum;
750 msginfo->folder = item;
756 static void mbox_cache_init()
758 mbox_cache_table = g_hash_table_new(g_str_hash, g_str_equal);
761 static void mbox_cache_free_mbox(mboxcache * cache)
763 g_hash_table_remove(mbox_cache_table, cache->filename);
766 mailfile_done(cache->mf);
768 g_ptr_array_free(cache->tab_mf, FALSE);
770 g_free(cache->filename);
774 static void mbox_cache_get_msginfo_from_file(FILE * fp, GList * msg_list)
779 for(l = msg_list ; l != NULL ; l = g_list_next(l)) {
780 struct _message * msg;
782 msg = (struct _message *) l->data;
784 fseek(fp, msg->header, SEEK_SET);
785 msginfo = mbox_parse_msg(fp, msg, NULL);
789 g_strdup(msginfo->msgid);
790 if (msginfo->fromspace)
792 g_strdup(msginfo->fromspace);
793 msg->flags = msginfo->flags;
794 msg->old_flags = msginfo->flags;
796 procmsg_msginfo_free(msginfo);
801 static void mbox_cache_get_msginfo(gchar * filename, GList * msg_list)
805 fp = fopen(filename, "rb");
809 mbox_cache_get_msginfo_from_file(fp, msg_list);
813 static mboxcache * mbox_cache_read_mbox(gchar * filename)
820 if (stat(filename, &s) < 0)
823 mf = mailfile_init(filename);
827 cache = g_new0(mboxcache, 1);
829 cache->mtime = s.st_mtime;
831 cache->filename = g_strdup(filename);
832 cache->modification = FALSE;
834 cache->tab_mf = g_ptr_array_new();
835 for(l = mf->msg_list ; l != NULL ; l = g_list_next(l))
836 g_ptr_array_add(cache->tab_mf, l->data);
838 mbox_cache_get_msginfo(filename, mf->msg_list);
840 debug_print("read mbox - %s\n", filename);
845 static mboxcache * mbox_cache_read_mbox_from_file(FILE * fp, gchar * filename)
852 if (stat(filename, &s) < 0)
855 mf = mailfile_init_from_file(fp, filename);
859 cache = g_new0(mboxcache, 1);
861 cache->mtime = s.st_mtime;
863 cache->filename = g_strdup(filename);
865 cache->tab_mf = g_ptr_array_new();
866 for(l = mf->msg_list ; l != NULL ; l = g_list_next(l))
867 g_ptr_array_add(cache->tab_mf, l->data);
869 mbox_cache_get_msginfo_from_file(fp, mf->msg_list);
871 debug_print("read mbox from file - %s\n", filename);
876 static void mbox_cache_insert_mbox(mboxcache * data)
878 if (mbox_cache_table == NULL)
881 g_hash_table_insert(mbox_cache_table, data->filename, data);
884 static mboxcache * mbox_cache_get_mbox(gchar * filename)
886 if (mbox_cache_table == NULL)
889 return g_hash_table_lookup(mbox_cache_table, filename);
893 static gint mbox_cache_get_count(gchar * filename)
897 cache = mbox_cache_get_mbox(filename);
900 if (cache->mf == NULL)
902 return cache->mf->count;
905 static GList * mbox_cache_get_msg_list(gchar * filename)
909 cache = mbox_cache_get_mbox(filename);
914 if (cache->mf == NULL)
917 return cache->mf->msg_list;
920 static void mbox_cache_synchronize_lists(GList * old_msg_list,
921 GList * new_msg_list)
926 for(l2 = old_msg_list ; l2 != NULL ; l2 = g_list_next(l2)) {
927 struct _message * msg2 = l2->data;
929 if ((msg2->messageid == NULL) ||
930 (msg2->fromspace == NULL))
933 for(l = new_msg_list ; l != NULL ; l = g_list_next(l)) {
934 struct _message * msg = l->data;
936 if ((msg->messageid == NULL) ||
937 (msg->fromspace == NULL))
940 if ((strcmp(msg->messageid, msg2->messageid) == 0) &&
941 (strcmp(msg->fromspace, msg2->fromspace) == 0)) {
942 if (msg2->flags.perm_flags != msg2->old_flags.perm_flags) {
943 msg->flags = msg2->flags;
951 static void mbox_cache_synchronize(gchar * filename, gboolean sync)
953 mboxcache * new_cache;
954 mboxcache * old_cache;
955 gboolean scan_new = TRUE;
958 old_cache = mbox_cache_get_mbox(filename);
960 if (old_cache != NULL) {
961 if (stat(filename, &s) < 0) {
962 FILE_OP_ERROR(filename, "stat");
963 } else if (old_cache->mtime == s.st_mtime) {
964 debug_print("Folder is not modified.\n");
971 if (strstr(filename, "trash") == 0)
972 printf("old_cache: %p %s\n", old_cache, filename);
974 printf("begin old\n");
975 for(l = old_cache->mf->msg_list ; l != NULL ;
976 l = g_list_next(l)) {
977 struct _message * msg = l->data;
984 new_cache = mbox_cache_read_mbox(filename);
987 if (strstr(filename, "trash") == 0)
988 printf("new_cache: %p %s\n", new_cache, filename);
990 printf("begin new\n");
991 for(l = new_cache->mf->msg_list ; l != NULL ;
992 l = g_list_next(l)) {
993 struct _message * msg = l->data;
1003 if (sync && new_cache && old_cache)
1004 mbox_cache_synchronize_lists(old_cache->mf->msg_list,
1005 new_cache->mf->msg_list);
1007 if (old_cache != NULL)
1008 mbox_cache_free_mbox(old_cache);
1011 mbox_cache_insert_mbox(new_cache);
1013 printf("insert %p %s\n", new_cache, new_cache->filename);
1014 printf("inserted %s %p\n", filename,
1015 mbox_cache_get_mbox(filename));
1021 static void mbox_cache_synchronize_from_file(FILE * fp, gchar * filename,
1024 mboxcache * new_cache;
1025 mboxcache * old_cache;
1026 gboolean scan_new = TRUE;
1029 old_cache = mbox_cache_get_mbox(filename);
1031 if (old_cache != NULL) {
1032 if (stat(filename, &s) < 0) {
1033 FILE_OP_ERROR(filename, "stat");
1034 } else if (old_cache->mtime == s.st_mtime) {
1035 debug_print("Folder is not modified.\n");
1046 if (strstr(filename, "trash") == 0)
1047 printf("old_cache: %p %s\n", old_cache, filename);
1050 printf("begin old\n");
1051 for(l = old_cache->mf->msg_list ; l != NULL ;
1052 l = g_list_next(l)) {
1053 struct _message * msg = l->data;
1054 printf("%p\n", msg);
1056 printf("end old\n");
1060 new_cache = mbox_cache_read_mbox_from_file(fp, filename);
1063 if (strstr(filename, "trash") == 0)
1064 printf("new_cache: %p %s\n", new_cache, filename);
1067 printf("begin new\n");
1068 for(l = new_cache->mf->msg_list ; l != NULL ;
1069 l = g_list_next(l)) {
1070 struct _message * msg = l->data;
1071 printf("%p\n", msg);
1073 printf("end new\n");
1080 if (sync && new_cache && old_cache)
1081 mbox_cache_synchronize_lists(old_cache->mf->msg_list,
1082 new_cache->mf->msg_list);
1084 if (old_cache != NULL)
1085 mbox_cache_free_mbox(old_cache);
1088 mbox_cache_insert_mbox(new_cache);
1090 printf("insert %p %s\n", new_cache, new_cache->filename);
1091 printf("inserted %s %p\n", filename,
1092 mbox_cache_get_mbox(filename));
1098 gboolean mbox_cache_msg_fetched(gchar * filename, gint num)
1100 struct _message * msg;
1103 cache = mbox_cache_get_mbox(filename);
1108 msg = (struct _message *) g_ptr_array_index(cache->tab_mf,
1113 return msg->fetched;
1116 void mbox_cache_msg_set_fetched(gchar * filename, gint num)
1118 struct _message * msg;
1121 cache = mbox_cache_get_mbox(filename);
1126 msg = (struct _message *) g_ptr_array_index(cache->tab_mf,
1131 msg->fetched = TRUE;
1134 struct _message * mbox_cache_get_msg(gchar * filename, gint num)
1138 cache = mbox_cache_get_mbox(filename);
1140 if (cache == NULL) {
1144 return (struct _message *) g_ptr_array_index(cache->tab_mf,
1149 /**********************************************************/
1151 /* mbox operations */
1153 /**********************************************************/
1156 GSList *mbox_get_msg_list(Folder *folder, FolderItem *item, gboolean use_cache)
1165 struct timeval tv_before, tv_after, tv_result;
1167 gettimeofday(&tv_before, NULL);
1172 mbox_path = mbox_folder_get_path(item);
1174 if (mbox_path == NULL)
1177 mbox_purge_deleted(mbox_path);
1179 fp = fopen(mbox_path, "rb");
1186 mbox_lockread_file(fp, mbox_path);
1188 mbox_cache_synchronize_from_file(fp, mbox_path, TRUE);
1190 item->last_num = mbox_cache_get_count(mbox_path);
1192 for(l = mbox_cache_get_msg_list(mbox_path) ; l != NULL ;
1193 l = g_list_next(l)) {
1194 struct _message * msg;
1196 msg = (struct _message *) l->data;
1198 if (MSG_IS_INVALID(msg->flags) || !MSG_IS_REALLY_DELETED(msg->flags)) {
1199 fseek(fp, msg->header, SEEK_SET);
1201 msginfo = mbox_parse_msg(fp, msg, item);
1203 if (!MSG_IS_INVALID(msg->flags))
1204 msginfo->flags = msg->flags;
1206 msg->old_flags = msginfo->flags;
1207 msg->flags = msginfo->flags;
1210 mlist = g_slist_append(mlist, msginfo);
1213 MSG_SET_PERM_FLAGS(msg->flags, MSG_REALLY_DELETED);
1217 mbox_unlock_file(fp, mbox_path);
1224 gettimeofday(&tv_after, NULL);
1226 timersub(&tv_after, &tv_before, &tv_result);
1227 g_print("mbox_get_msg_list: %s: elapsed time: %ld.%06ld sec\n",
1228 mbox_path, tv_result.tv_sec, tv_result.tv_usec);
1234 static gboolean mbox_extract_msg(FolderItem * item, gint msgnum,
1235 gchar * dest_filename)
1237 struct _message * msg;
1244 /* GList * msg_list;*/
1245 gboolean already_fetched;
1248 mbox_path = mbox_folder_get_path(item);
1250 if (mbox_path == NULL)
1253 src = fopen(mbox_path, "rb");
1259 mbox_lockread_file(src, mbox_path);
1261 mbox_cache_synchronize_from_file(src, mbox_path, TRUE);
1263 already_fetched = mbox_cache_msg_fetched(mbox_path, msgnum);
1265 if (already_fetched) {
1266 mbox_unlock_file(src, mbox_path);
1272 msg = mbox_cache_get_msg(mbox_path, msgnum);
1275 mbox_unlock_file(src, mbox_path);
1281 offset = msg->offset;
1282 max_offset = msg->end;
1284 size = max_offset - offset;
1286 fseek(src, offset, SEEK_SET);
1288 dest = fopen(dest_filename, "wb");
1290 mbox_unlock_file(src, mbox_path);
1296 if (change_file_mode_rw(dest, dest_filename) < 0) {
1297 FILE_OP_ERROR(dest_filename, "chmod");
1298 g_warning(_("can't change file mode\n"));
1301 if (!mbox_write_data(src, dest, dest_filename, size)) {
1302 mbox_unlock_file(src, mbox_path);
1305 unlink(dest_filename);
1313 FILE_OP_ERROR(mbox_path, "fread");
1317 mbox_cache_msg_set_fetched(mbox_path, msgnum);
1319 if (fclose(dest) == -1) {
1320 FILE_OP_ERROR(dest_filename, "fclose");
1324 mbox_unlock_file(src, mbox_path);
1326 if (fclose(src) == -1) {
1327 FILE_OP_ERROR(mbox_path, "fclose");
1334 unlink(dest_filename);
1341 gchar *mbox_fetch_msg(Folder *folder, FolderItem *item, gint num)
1346 g_return_val_if_fail(item != NULL, NULL);
1348 path = folder_item_get_path(item);
1349 if (!is_dir_exist(path))
1350 make_dir_hier(path);
1352 filename = g_strconcat(path, G_DIR_SEPARATOR_S, itos(num), NULL);
1356 if (!mbox_extract_msg(item, num, filename)) {
1364 gint mbox_add_msg(Folder *folder, FolderItem *dest, const gchar *file,
1365 gboolean remove_source)
1374 gchar from_line[MSGBUFSIZE];
1376 if (dest->last_num < 0) {
1377 mbox_scan_folder(folder, dest);
1378 if (dest->last_num < 0) return -1;
1381 src_fp = fopen(file, "rb");
1382 if (src_fp == NULL) {
1386 mbox_path = mbox_folder_get_path(dest);
1387 if (mbox_path == NULL)
1390 dest_fp = fopen(mbox_path, "ab");
1391 if (dest_fp == NULL) {
1397 if (change_file_mode_rw(dest_fp, mbox_path) < 0) {
1398 FILE_OP_ERROR(mbox_path, "chmod");
1399 g_warning(_("can't change file mode\n"));
1402 old_size = ftell(dest_fp);
1404 mbox_lockwrite_file(dest_fp, mbox_path);
1406 if (fgets(from_line, sizeof(from_line), src_fp) == NULL) {
1407 mbox_unlock_file(dest_fp, mbox_path);
1408 g_warning(_("unvalid file - %s.\n"), file);
1415 if (strncmp(from_line, "From ", 5) != 0) {
1418 if (stat(file, &s) < 0) {
1419 mbox_unlock_file(dest_fp, mbox_path);
1420 g_warning(_("invalid file - %s.\n"), file);
1427 fprintf(dest_fp, "From - %s", ctime(&s.st_mtime));
1430 fputs(from_line, dest_fp);
1433 n_read = fread(buf, 1, sizeof(buf), src_fp);
1434 if ((n_read < (gint) sizeof(buf)) && ferror(src_fp))
1436 if (fwrite(buf, n_read, 1, dest_fp) < 1) {
1437 mbox_unlock_file(dest_fp, mbox_path);
1438 g_warning(_("writing to %s failed.\n"), mbox_path);
1439 ftruncate(fileno(dest_fp), old_size);
1446 if (n_read < (gint) sizeof(buf))
1452 if (ferror(src_fp)) {
1453 FILE_OP_ERROR(mbox_path, "fread");
1456 mbox_unlock_file(dest_fp, mbox_path);
1458 if (fclose(src_fp) == -1) {
1459 FILE_OP_ERROR(file, "fclose");
1463 if (fclose(dest_fp) == -1) {
1464 FILE_OP_ERROR(mbox_path, "fclose");
1470 ftruncate(fileno(dest_fp), old_size);
1475 if (remove_source) {
1476 if (unlink(file) < 0)
1477 FILE_OP_ERROR(file, "unlink");
1483 return dest->last_num;
1487 gint mbox_remove_msg(Folder *folder, FolderItem *item, gint num)
1489 struct _message * msg;
1492 mbox_path = mbox_folder_get_path(item);
1493 if (mbox_path == NULL)
1496 mbox_cache_synchronize(mbox_path, TRUE);
1498 msg = mbox_cache_get_msg(mbox_path, num);
1503 MSG_SET_PERM_FLAGS(msg->flags, MSG_REALLY_DELETED);
1508 gint mbox_remove_all_msg(Folder *folder, FolderItem *item)
1513 mbox_path = mbox_folder_get_path(item);
1514 if (mbox_path == NULL)
1517 fp = fopen(mbox_path, "wb");
1531 gint mbox_move_msg(Folder *folder, FolderItem *dest, MsgInfo *msginfo)
1536 filename = mbox_fetch_msg(folder, msginfo->folder, msginfo->msgnum);
1537 if (filename == NULL)
1540 msgnum = mbox_add_msg(folder, dest, filename, TRUE);
1543 MSG_SET_FLAGS(msginfo->flags, MSG_REALLY_DELETED);
1544 mbox_change_flags(folder, msginfo->folder, msginfo);
1550 gint mbox_move_msgs_with_dest(Folder *folder, FolderItem *dest, GSList *msglist)
1553 gchar * mbox_path = NULL;
1555 for(l = msglist ; l != NULL ; l = g_slist_next(l)) {
1556 MsgInfo * msginfo = (MsgInfo *) l->data;
1558 if (msginfo->folder && mbox_path == NULL)
1559 mbox_path = mbox_folder_get_path(msginfo->folder);
1561 mbox_move_msg(folder, dest, msginfo);
1565 mbox_cache_synchronize(mbox_path);
1569 mbox_path = mbox_folder_get_path(dest);
1570 mbox_cache_synchronize(mbox_path);
1573 return dest->last_num;
1578 gint mbox_copy_msg(Folder *folder, FolderItem *dest, MsgInfo *msginfo)
1583 filename = mbox_fetch_msg(folder, msginfo->folder, msginfo->msgnum);
1584 if (filename == NULL)
1587 msgnum = mbox_add_msg(folder, dest, filename, FALSE);
1592 gint mbox_copy_msgs_with_dest(Folder *folder, FolderItem *dest, GSList *msglist)
1595 gchar * mbox_path = NULL;
1597 for(l = msglist ; l != NULL ; l = g_slist_next(l)) {
1598 MsgInfo * msginfo = (MsgInfo *) l->data;
1600 if (msginfo->folder && mbox_path == NULL)
1601 mbox_path = mbox_folder_get_path(msginfo->folder);
1603 mbox_copy_msg(folder, dest, msginfo);
1607 mbox_cache_synchronize(mbox_path);
1611 mbox_path = mbox_folder_get_path(dest);
1612 mbox_cache_synchronize(mbox_path);
1615 return dest->last_num;
1619 struct _copy_flags_info
1625 typedef struct _copy_flags_info CopyFlagsInfo;
1627 GSList * copy_flags_data = NULL;
1629 gint mbox_copy_msg(Folder *folder, FolderItem *dest, MsgInfo *msginfo)
1631 Folder * src_folder;
1634 CopyFlagsInfo * flags_info;
1636 src_folder = msginfo->folder->folder;
1638 g_return_val_if_fail(src_folder->fetch_msg != NULL, -1);
1641 mbox_path = mbox_folder_get_path(msginfo->folder);
1642 mbox_rewrite(mbox_path);
1646 filename = src_folder->fetch_msg(src_folder,
1649 if (filename == NULL)
1652 num = folder->add_msg(folder, dest, filename, FALSE);
1655 mbox_path = mbox_folder_get_path(dest);
1656 msg = mbox_cache_get_msg(mbox_path, num);
1658 msg->flags = msginfo->flags;
1665 flags_info = g_new0(CopyFlagsInfo, 1);
1666 flags_info->num = num;
1667 flags_info->flags = msginfo->flags;
1668 copy_flags_data = g_slist_append(copy_flags_data, flags_info);
1673 void mbox_finished_copy(Folder *folder, FolderItem *dest)
1679 mbox_path = mbox_folder_get_path(dest);
1680 if (mbox_path == NULL)
1683 mbox_cache_synchronize(mbox_path, TRUE);
1685 for(l = copy_flags_data ; l != NULL ; l = g_slist_next(l)) {
1686 CopyFlagsInfo * flags_info = l->data;
1687 struct _message * msg;
1689 msg = mbox_cache_get_msg(mbox_path, flags_info->num);
1691 msg->flags = flags_info->flags;
1695 if (copy_flags_data != NULL) {
1696 cache = mbox_cache_get_mbox(mbox_path);
1697 cache->modification = TRUE;
1700 g_slist_free(copy_flags_data);
1701 copy_flags_data = NULL;
1703 mbox_rewrite(mbox_path);
1708 void mbox_scan_folder(Folder *folder, FolderItem *item)
1715 mbox_path = mbox_folder_get_path(item);
1716 if (mbox_path == NULL)
1719 mbox_cache_synchronize(mbox_path, TRUE);
1721 cached = mbox_cache_get_mbox(mbox_path);
1723 if (cached == NULL) {
1732 n_msg = mbox_cache_get_count(mbox_path);
1735 item->new = item->unread = item->total = 0;
1742 for(l = mbox_cache_get_msg_list(mbox_path) ; l != NULL ;
1743 l = g_list_next(l)) {
1744 struct _message * msg = (struct _message *) l->data;
1745 if (!MSG_IS_REALLY_DELETED(msg->flags))
1747 if (MSG_IS_NEW(msg->flags) && !MSG_IS_IGNORE_THREAD(msg->flags))
1749 if (MSG_IS_UNREAD(msg->flags) && !MSG_IS_IGNORE_THREAD(msg->flags))
1754 item->unread = unread;
1755 item->total = total;
1758 debug_print("Last number in dir %s = %d\n", mbox_path,
1760 item->last_num = n_msg;
1764 gchar * mbox_get_virtual_path(FolderItem * item)
1769 if (item->parent == NULL) {
1773 gchar * parent_path;
1774 gchar * result_path;
1776 parent_path = mbox_get_virtual_path(item->parent);
1777 if (parent_path == NULL)
1778 result_path = g_strdup(item->name);
1780 result_path = g_strconcat(parent_path,
1783 g_free(parent_path);
1789 static gboolean mbox_write_data(FILE * mbox_fp, FILE * new_fp,
1790 gchar * new_filename, gint size)
1798 while (pos < size) {
1799 if ((size - pos) > (gint) sizeof(buf))
1804 n_read = fread(buf, 1, max, mbox_fp);
1806 if (n_read < max && ferror(mbox_fp)) {
1809 if (fwrite(buf, n_read, 1, new_fp) < 1) {
1810 g_warning(_("writing to %s failed.\n"), new_filename);
1823 static gboolean mbox_write_message(FILE * mbox_fp, FILE * new_fp,
1824 gchar * new_filename,
1825 struct _message * msg)
1828 GPtrArray * headers;
1831 fseek(mbox_fp, msg->header, SEEK_SET);
1833 headers = procheader_get_header_array_asis(mbox_fp);
1835 for (i = 0; i < (gint) headers->len; i++) {
1836 Header * h = g_ptr_array_index(headers, i);
1838 if (!procheader_headername_equal(h->name,
1840 !procheader_headername_equal(h->name,
1842 fwrite(h->name, strlen(h->name),
1844 if (h->name[strlen(h->name) - 1] != ' ')
1845 fwrite(" ", 1, 1, new_fp);
1846 fwrite(h->body, strlen(h->body),
1848 fwrite("\n", 1, 1, new_fp);
1850 procheader_header_free(h);
1851 g_ptr_array_remove_index(headers, i);
1855 g_ptr_array_free(headers, FALSE);
1857 if (!MSG_IS_INVALID(msg->flags)) {
1859 fwrite("Status: ", strlen("Status: "), 1, new_fp);
1860 if (!MSG_IS_UNREAD(msg->flags))
1861 fwrite("R", 1, 1, new_fp);
1862 fwrite("O", 1, 1, new_fp);
1863 fwrite("\n", 1, 1, new_fp);
1865 /* X-Status header */
1866 if (MSG_IS_REALLY_DELETED(msg->flags)
1867 || MSG_IS_MARKED(msg->flags)
1868 || MSG_IS_DELETED(msg->flags)
1869 || MSG_IS_REPLIED(msg->flags)
1870 || MSG_IS_FORWARDED(msg->flags)) {
1871 fwrite("X-Status: ", strlen("X-Status: "), 1, new_fp);
1872 if (MSG_IS_REALLY_DELETED(msg->flags))
1873 fwrite("D", 1, 1, new_fp); /* really deleted */
1875 if (MSG_IS_MARKED(msg->flags))
1876 fwrite("F", 1, 1, new_fp);
1877 if (MSG_IS_DELETED(msg->flags))
1878 fwrite("d", 1, 1, new_fp);
1879 if (MSG_IS_REPLIED(msg->flags))
1880 fwrite("r", 1, 1, new_fp);
1881 if (MSG_IS_FORWARDED(msg->flags))
1882 fwrite("f", 1, 1, new_fp);
1884 fwrite("\n", 1, 1, new_fp);
1888 fwrite("\n", 1, 1, new_fp);
1890 size = msg->end - msg->content;
1891 fseek(mbox_fp, msg->content, SEEK_SET);
1893 return mbox_write_data(mbox_fp, new_fp, new_filename, size);
1896 void mbox_update_mark(Folder * folder, FolderItem * item)
1900 mbox_path = mbox_folder_get_path(item);
1901 if (mbox_path == NULL)
1904 mbox_rewrite(mbox_path);
1908 void mbox_change_flags(Folder * folder, FolderItem * item, MsgInfo * info)
1910 struct _message * msg;
1914 mbox_path = mbox_folder_get_path(item);
1915 if (mbox_path == NULL)
1918 msg = mbox_cache_get_msg(mbox_path, info->msgnum);
1920 cache = mbox_cache_get_mbox(mbox_path);
1924 if ((msg == NULL) || (cache == NULL))
1927 msg->flags = info->flags;
1929 cache->modification = TRUE;
1933 static gboolean mbox_rewrite(gchar * mbox)
1944 msg_list = mbox_cache_get_msg_list(mbox);
1946 cache = mbox_cache_get_mbox(mbox);
1950 if (!cache->modification) {
1951 debug_print("no modification - %s\n", mbox);
1955 debug_print("save modification - %s\n", mbox);
1957 mbox_fp = fopen(mbox, "rb+");
1958 mbox_lockwrite_file(mbox_fp, mbox);
1960 mbox_cache_synchronize_from_file(mbox_fp, mbox, TRUE);
1962 new = g_strconcat(mbox, ".", itos((int) mbox), NULL);
1963 new_fp = fopen(new, "wb");
1965 if (change_file_mode_rw(new_fp, new) < 0) {
1966 FILE_OP_ERROR(new, "chmod");
1967 g_warning(_("can't change file mode\n"));
1970 mbox_lockwrite_file(new_fp, new);
1975 msg_list = mbox_cache_get_msg_list(mbox);
1976 for(l = msg_list ; l != NULL ; l = g_list_next(l)) {
1977 struct _message * msg = (struct _message *) l->data;
1978 if (!mbox_write_message(mbox_fp, new_fp, new, msg)) {
1987 if (rename(new, mbox) == -1) {
1988 g_warning(_("can't rename %s to %s\n"), new, mbox);
1989 mbox_unlock_file(new_fp, new);
1991 mbox_unlock_file(mbox_fp, mbox);
1996 if (change_file_mode_rw(new_fp, mbox) < 0) {
1997 FILE_OP_ERROR(new, "chmod");
1998 g_warning(_("can't change file mode\n"));
2001 mbox_unlock_file(new_fp, new);
2005 mbox_unlock_file(mbox_fp, mbox);
2009 debug_print("%i messages written - %s\n", count, mbox);
2011 cache = mbox_cache_get_mbox(mbox);
2016 mbox_cache_synchronize(mbox, FALSE);
2021 static gboolean mbox_purge_deleted(gchar * mbox)
2028 gboolean modification = FALSE;
2032 mbox_cache_synchronize(mbox, TRUE);
2034 msg_list = mbox_cache_get_msg_list(mbox);
2036 for(l = msg_list ; l != NULL ; l = g_list_next(l)) {
2037 struct _message * msg = (struct _message *) l->data;
2038 if (!MSG_IS_INVALID(msg->flags) && MSG_IS_REALLY_DELETED(msg->flags)) {
2039 modification = TRUE;
2044 if (!modification) {
2045 debug_print("no deleted messages - %s\n", mbox);
2049 debug_print("purge deleted messages - %s\n", mbox);
2051 mbox_fp = fopen(mbox, "rb+");
2052 mbox_lockwrite_file(mbox_fp, mbox);
2054 mbox_cache_synchronize_from_file(mbox_fp, mbox, TRUE);
2056 new = g_strconcat(mbox, ".", itos((int) mbox), NULL);
2057 new_fp = fopen(new, "wb");
2059 if (change_file_mode_rw(new_fp, new) < 0) {
2060 FILE_OP_ERROR(new, "chmod");
2061 g_warning(_("can't change file mode\n"));
2064 mbox_lockwrite_file(new_fp, new);
2069 msg_list = mbox_cache_get_msg_list(mbox);
2070 for(l = msg_list ; l != NULL ; l = g_list_next(l)) {
2071 struct _message * msg = (struct _message *) l->data;
2072 if (MSG_IS_INVALID(msg->flags) || !MSG_IS_REALLY_DELETED(msg->flags)) {
2073 if (!mbox_write_message(mbox_fp, new_fp, new, msg)) {
2083 if (rename(new, mbox) == -1) {
2084 g_warning(_("can't rename %s to %s\n"), new, mbox);
2085 mbox_unlock_file(new_fp, new);
2087 mbox_unlock_file(mbox_fp, mbox);
2092 if (change_file_mode_rw(new_fp, mbox) < 0) {
2093 FILE_OP_ERROR(new, "chmod");
2094 g_warning(_("can't change file mode\n"));
2097 mbox_unlock_file(new_fp, new);
2101 mbox_unlock_file(mbox_fp, mbox);
2105 debug_print("%i messages written - %s\n", count, mbox);
2107 mbox_cache_synchronize(mbox, FALSE);
2112 #define MAKE_DIR_IF_NOT_EXIST(dir) \
2114 if (!is_dir_exist(dir)) { \
2115 if (is_file_exist(dir)) { \
2116 g_warning(_("File `%s' already exists.\n" \
2117 "Can't create folder."), dir); \
2120 if (mkdir(dir, S_IRWXU) < 0) { \
2121 FILE_OP_ERROR(dir, "mkdir"); \
2124 if (chmod(dir, S_IRWXU) < 0) \
2125 FILE_OP_ERROR(dir, "chmod"); \
2129 gint mbox_create_tree(Folder *folder)
2133 g_return_val_if_fail(folder != NULL, -1);
2135 CHDIR_RETURN_VAL_IF_FAIL(get_home_dir(), -1);
2136 rootpath = LOCAL_FOLDER(folder)->rootpath;
2137 MAKE_DIR_IF_NOT_EXIST(rootpath);
2138 CHDIR_RETURN_VAL_IF_FAIL(rootpath, -1);
2143 #undef MAKE_DIR_IF_NOT_EXIST
2145 static gchar * mbox_get_new_path(FolderItem * parent, gchar * name)
2149 if (strchr(name, '/') == NULL) {
2150 if (parent->path != NULL)
2151 path = g_strconcat(parent->path, ".sbd", G_DIR_SEPARATOR_S, name, NULL);
2153 path = g_strdup(name);
2156 path = g_strdup(name);
2161 static gchar * mbox_get_folderitem_name(gchar * name)
2165 foldername = g_strdup(g_basename(name));
2170 FolderItem *mbox_create_folder(Folder *folder, FolderItem *parent,
2174 FolderItem *new_item;
2177 g_return_val_if_fail(folder != NULL, NULL);
2178 g_return_val_if_fail(parent != NULL, NULL);
2179 g_return_val_if_fail(name != NULL, NULL);
2181 path = mbox_get_new_path(parent, (gchar *) name);
2183 foldername = mbox_get_folderitem_name((gchar *) name);
2185 new_item = folder_item_new(folder, foldername, path);
2186 folder_item_append(parent, new_item);
2188 if (!strcmp(name, "inbox")) {
2189 new_item->stype = F_INBOX;
2190 new_item->folder->inbox = new_item;
2191 } else if (!strcmp(name, "outbox")) {
2192 new_item->stype = F_OUTBOX;
2193 new_item->folder->outbox = new_item;
2194 } else if (!strcmp(name, "draft")) {
2195 new_item->stype = F_DRAFT;
2196 new_item->folder->draft = new_item;
2197 } else if (!strcmp(name, "queue")) {
2198 new_item->stype = F_QUEUE;
2199 new_item->folder->queue = new_item;
2200 } else if (!strcmp(name, "trash")) {
2201 new_item->stype = F_TRASH;
2202 new_item->folder->trash = new_item;
2211 gint mbox_rename_folder(Folder *folder, FolderItem *item, const gchar *name)
2216 g_return_val_if_fail(folder != NULL, -1);
2217 g_return_val_if_fail(item != NULL, -1);
2218 g_return_val_if_fail(item->path != NULL, -1);
2219 g_return_val_if_fail(name != NULL, -1);
2221 path = mbox_get_new_path(item->parent, (gchar *) name);
2222 foldername = mbox_get_folderitem_name((gchar *) name);
2224 if (rename(item->path, path) == -1) {
2227 g_warning(_("Cannot rename folder item"));
2235 item->name = foldername;
2241 gint mbox_remove_folder(Folder *folder, FolderItem *item)
2243 g_return_val_if_fail(folder != NULL, -1);
2244 g_return_val_if_fail(item != NULL, -1);
2245 g_return_val_if_fail(item->path != NULL, -1);
2247 folder_item_remove(item);
2251 GSList *mbox_get_num_list(Folder *folder, FolderItem *item)
2260 mbox_path = mbox_folder_get_path(item);
2262 if (mbox_path == NULL)
2265 mbox_purge_deleted(mbox_path);
2267 fp = fopen(mbox_path, "rb");
2274 mbox_lockread_file(fp, mbox_path);
2276 mbox_cache_synchronize_from_file(fp, mbox_path, TRUE);
2278 item->last_num = mbox_cache_get_count(mbox_path);
2280 for(l = mbox_cache_get_msg_list(mbox_path) ; l != NULL ;
2281 l = g_list_next(l)) {
2282 struct _message * msg;
2284 msg = (struct _message *) l->data;
2286 if (MSG_IS_INVALID(msg->flags) || !MSG_IS_REALLY_DELETED(msg->flags)) {
2287 mlist = g_slist_append(mlist, GINT_TO_POINTER(msg->msgnum));
2289 MSG_SET_PERM_FLAGS(msg->flags, MSG_REALLY_DELETED);
2293 mbox_unlock_file(fp, mbox_path);
2302 MsgInfo *mbox_fetch_msginfo(Folder *folder, FolderItem *item, gint num)
2305 struct _message *msg;
2309 g_return_val_if_fail(folder != NULL, NULL);
2310 g_return_val_if_fail(item != NULL, NULL);
2312 mbox_path = mbox_folder_get_path(item);
2314 g_return_val_if_fail(mbox_path != NULL, NULL);
2316 src = fopen(mbox_path, "rb");
2321 mbox_lockread_file(src, mbox_path);
2322 mbox_cache_synchronize_from_file(src, mbox_path, TRUE);
2324 msg = mbox_cache_get_msg(mbox_path, num);
2326 mbox_unlock_file(src, mbox_path);
2332 fseek(src, msg->header, SEEK_SET);
2333 msginfo = mbox_parse_msg(src, msg, item);
2335 mbox_unlock_file(src, mbox_path);
2342 gboolean mbox_check_msgnum_validity(Folder *folder, FolderItem *item)
2344 mboxcache * old_cache;
2345 gboolean scan_new = TRUE;
2349 filename = mbox_folder_get_path(item);
2351 old_cache = mbox_cache_get_mbox(filename);
2353 if (old_cache != NULL) {
2354 if (stat(filename, &s) < 0) {
2355 FILE_OP_ERROR(filename, "stat");
2356 } else if (old_cache->mtime == s.st_mtime) {
2357 debug_print("Folder is not modified.\n");