/*
* Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2012 Hiroyuki Yamamoto and the Claws Mail team
+ * Copyright (C) 1999-2014 Hiroyuki Yamamoto 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
gchar last_seen_separator;
guint refcnt;
guint max_set_size;
- const gchar *search_charset;
+ gchar *search_charset;
gboolean search_charset_supported;
};
const gchar *name);
static gint imap_do_copy_msgs (Folder *folder,
+ FolderItem *dest,
+ MsgInfoList *msglist,
+ GHashTable *relation,
+ gboolean same_dest_ok);
+
+static gint imap_do_remove_msgs (Folder *folder,
FolderItem *dest,
MsgInfoList *msglist,
GHashTable *relation);
while (imap_folder_get_refcnt(folder) > 0)
gtk_main_iteration();
+ g_free(IMAP_FOLDER(folder)->search_charset);
+
folder_remote_folder_destroy(REMOTE_FOLDER(folder));
imap_done(folder);
}
folder_remote_folder_init((Folder *)folder, name, path);
IMAP_FOLDER(folder)->max_set_size = IMAP_SET_MAX_COUNT;
IMAP_FOLDER(folder)->search_charset_supported = TRUE;
- IMAP_FOLDER(folder)->search_charset = conv_get_locale_charset_str_no_utf8();
+ IMAP_FOLDER(folder)->search_charset = g_strdup(conv_get_locale_charset_str_no_utf8());
}
static FolderItem *imap_folder_item_new(Folder *folder)
return cnt;
}
-static void imap_remove_cached_msg(Folder *folder, FolderItem *item, MsgInfo *msginfo)
+static gchar *imap_get_cached_filename(FolderItem *item, guint msgnum)
{
gchar *path, *filename;
+ cm_return_val_if_fail(item != NULL, NULL);
+
path = folder_item_get_path(item);
if (!is_dir_exist(path)) {
g_free(path);
- return;
+ return NULL;
}
- filename = g_strconcat(path, G_DIR_SEPARATOR_S, itos(msginfo->msgnum), NULL);
+ filename = g_strconcat(path, G_DIR_SEPARATOR_S, itos(msgnum), NULL);
+
+ if (is_dir_exist(filename)) {
+ g_free(filename);
+ filename = g_strconcat(path, G_DIR_SEPARATOR_S, ".", itos(msgnum), NULL);
+ }
g_free(path);
+ return filename;
+}
+
+static void imap_remove_cached_msg(Folder *folder, FolderItem *item, MsgInfo *msginfo)
+{
+ gchar *filename;
+
+ filename = imap_get_cached_filename(item, msginfo->msgnum);
+
+ cm_return_if_fail(filename != NULL);
+
if (is_file_exist(filename)) {
claws_unlink(filename);
}
return NULL;
path = folder_item_get_path(item);
- if (!is_dir_exist(path))
+ if (!is_dir_exist(path)) {
+ if(is_file_exist(path))
+ claws_unlink(path);
make_dir_hier(path);
- filename = g_strconcat(path, G_DIR_SEPARATOR_S, itos(uid), NULL);
+ }
g_free(path);
+
+ filename = imap_get_cached_filename(item, uid);
debug_print("trying to fetch cached %s\n", filename);
+
if (is_file_exist(filename)) {
/* see whether the local file represents the whole message
* or not. As the IMAP server reports size with \r chars,
static gboolean imap_is_msg_fully_cached(Folder *folder, FolderItem *item, gint uid)
{
- gchar *path, *filename;
+ gchar *filename;
guint size = 0;
MsgInfo *cached = msgcache_get_msg(item->cache,uid);
procmsg_msginfo_free(cached);
return TRUE;
}
- path = folder_item_get_path(item);
- if (!is_dir_exist(path)) {
- g_free(path);
- return FALSE;
- }
- filename = g_strconcat(path, G_DIR_SEPARATOR_S, itos(uid), NULL);
- g_free(path);
+ filename = imap_get_cached_filename(item, uid);
+
if (is_file_exist(filename)) {
if (cached && cached->total_size == cached->size) {
/* fast path */
return -1;
}
destdir = imap_get_real_path(session, IMAP_FOLDER(folder), dest->path, &ok);
- if (is_fatal(ok))
+ if (is_fatal(ok)) {
+ g_free(destdir);
return -1;
+ }
statusbar_print_all(_("Adding messages..."));
total = g_slist_length(file_list);
for (cur = file_list; cur != NULL; cur = cur->next) {
return result;
}
static gint imap_do_copy_msgs(Folder *folder, FolderItem *dest,
- MsgInfoList *msglist, GHashTable *relation)
+ MsgInfoList *msglist, GHashTable *relation,
+ gboolean same_dest_ok)
{
FolderItem *src;
gchar *destdir;
msginfo = (MsgInfo *)msglist->data;
src = msginfo->folder;
- if (src == dest) {
+ if (!same_dest_ok && src == dest) {
g_warning("the src folder is identical to the dest.\n");
return -1;
}
destdir = imap_get_real_path(session, IMAP_FOLDER(folder), dest->path, &ok);
- if (is_fatal(ok))
+ if (is_fatal(ok)) {
+ g_free(destdir);
return ok;
+ }
seq_list = imap_get_lep_set_from_msglist(IMAP_FOLDER(folder), msglist);
uid_hash = g_hash_table_new(g_direct_hash, g_direct_equal);
msginfo = (MsgInfo *)msglist->data;
g_return_val_if_fail(msginfo->folder != NULL, -1);
- ret = imap_do_copy_msgs(folder, dest, msglist, relation);
+ ret = imap_do_copy_msgs(folder, dest, msglist, relation, FALSE);
return ret;
}
case MATCHCRITERIA_NOT_HEADER: invert = TRUE; matchertype = MATCHCRITERIA_HEADER; break;
case MATCHCRITERIA_NOT_TAG: invert = TRUE; matchertype = MATCHCRITERIA_TAG; break;
case MATCHCRITERIA_NOT_HEADERS_PART: invert = TRUE; matchertype = MATCHCRITERIA_HEADERS_PART; break;
+ case MATCHCRITERIA_NOT_HEADERS_CONT: invert = TRUE; matchertype = MATCHCRITERIA_HEADERS_CONT; break;
case MATCHCRITERIA_NOT_MESSAGE: invert = TRUE; matchertype = MATCHCRITERIA_MESSAGE; break;
case MATCHCRITERIA_NOT_BODY_PART: invert = TRUE; matchertype = MATCHCRITERIA_BODY_PART; break;
case MATCHCRITERIA_NOT_TO_AND_NOT_CC: invert = TRUE; matchertype = MATCHCRITERIA_TO_OR_CC; break;
break;
case MATCHCRITERIA_HEADERS_PART:
+ case MATCHCRITERIA_HEADERS_CONT:
result = imap_search_and(
imap_search_not(imap_search_new(IMAP_SEARCH_CRITERIA_BODY, NULL, match->expr, 0)),
imap_search_new(IMAP_SEARCH_CRITERIA_MESSAGE, NULL, match->expr, 0)
imap_scan_required(folder, dest);
g_free(destdir);
- if (ok == MAILIMAP_NO_ERROR)
- return 0;
- else
- return -1;
+
+ return 0;
}
static gint imap_remove_msgs(Folder *folder, FolderItem *dest,
strtailchomp(root_folder, '/');
real_path = imap_get_real_path
(session, IMAP_FOLDER(folder), root_folder, &r);
- if (is_fatal(r))
+ if (is_fatal(r)) {
+ g_free(real_path);
return -1;
+ }
debug_print("IMAP root directory: %s\n", real_path);
/* check if root directory exist */
}
}
if (!new_item) {
- if (old_item && old_item->path && !strcmp(old_item->path, "INBOX")) {
+ if (old_item && old_item->path && !strcasecmp(old_item->path, "INBOX")) {
debug_print("not removing INBOX\n");
} else {
debug_print("folder '%s' not found. removing...\n",
folder_item_append(item, new_item);
}
- if (!strcmp(new_item->path, "INBOX")) {
+ if (!strcasecmp(new_item->path, "INBOX")) {
new_item->stype = F_INBOX;
folder->inbox = new_item;
} else if (!folder_item_parent(item) || item->stype == F_INBOX) {
if (!folder->outbox && !g_ascii_strcasecmp(base, "Sent")) {
new_item->stype = F_OUTBOX;
folder->outbox = new_item;
- } else if (!folder->draft && !g_ascii_strcasecmp(base, "Drafts")) {
+ } else if (!folder->draft && (!g_ascii_strcasecmp(base, "Drafts") || !g_ascii_strcasecmp(base, "Draft"))) {
new_item->stype = F_DRAFT;
folder->draft = new_item;
} else if (!folder->queue && !g_ascii_strcasecmp(base, "Queue")) {
if (r) {
g_free(real_path);
statusbar_pop_all();
+ g_free(tmp);
return NULL;
}
folder_item_destroy(cur_item);
g_return_val_if_fail(parent != NULL, NULL);
g_return_val_if_fail(name != NULL, NULL);
+ if (to_number(name) > 0) {
+ gchar *cached_msg = imap_get_cached_filename(parent, to_number(name));
+ if (is_file_exist(cached_msg)) {
+ if (claws_unlink(cached_msg) != 0) {
+ return NULL;
+ }
+ }
+ }
+
debug_print("getting session...\n");
session = imap_session_get(folder);
if (!session) {
return NULL;
}
- if (!folder_item_parent(parent) && strcmp(name, "INBOX") == 0) {
+ if (!folder_item_parent(parent) && strcasecmp(name, "INBOX") == 0) {
dirpath = g_strdup(name);
}else if (parent->path)
dirpath = g_strconcat(parent->path, "/", name, NULL);
/* remove trailing / for display */
strtailchomp(new_name, '/');
- if (strcmp(dirpath, "INBOX") != 0) {
+ if (strcasecmp(dirpath, "INBOX") != 0) {
GPtrArray *argbuf;
int r;
clist * lep_list;
real_oldpath = imap_get_real_path(session, IMAP_FOLDER(folder), item->path, &ok);
if (is_fatal(ok)) {
+ g_free(real_oldpath);
return -1;
}
}
separator = imap_get_path_separator(session, IMAP_FOLDER(folder), item->path, &ok);
- if (is_fatal(ok))
+ if (is_fatal(ok)) {
+ g_free(real_oldpath);
return -1;
+ }
if (strchr(item->path, G_DIR_SEPARATOR)) {
dirpath = g_path_get_dirname(item->path);
newpath = g_strconcat(dirpath, G_DIR_SEPARATOR_S, name, NULL);
g_free(path);
return -1;
}
- if (!strcmp(path, "INBOX") && sub == FALSE) {
+ if (!strcasecmp(path, "INBOX") && sub == FALSE) {
g_free(path);
return -1;
}
return -1;
}
path = imap_get_real_path(session, IMAP_FOLDER(folder), item->path, &ok);
- if (is_fatal(ok))
+ if (is_fatal(ok)) {
+ g_free(path);
return -1;
-
+ }
imap_threaded_subscribe(folder, path, FALSE);
selected_folder = (session->mbox != NULL) &&
if (!item)
return '/';
folder = item->folder;
-
+
if (!folder)
return '/';
-
+
imap_folder = IMAP_FOLDER(folder);
-
- if (!imap_folder)
- return '/';
-
+
debug_print("getting session...");
session = imap_session_get(FOLDER(folder));
result = imap_get_path_separator(session, imap_folder, item->path, &ok);
session->expunge = 0;
real_path = imap_get_real_path(session, folder, path, &ok);
- if (is_fatal(ok))
- return ok;
+ if (is_fatal(ok)) {
+ g_free(real_path);
+ return ok;
+ }
g_slist_free(IMAP_FOLDER_ITEM(item)->ok_flags);
IMAP_FOLDER_ITEM(item)->ok_flags = NULL;
ok = imap_cmd_select(session, real_path,
}
if (r == MAILIMAP_NO_ERROR) {
- GSList * fetchuid_list =
- imap_uid_list_from_lep(lep_uidlist, NULL);
+ uidlist = imap_uid_list_from_lep(lep_uidlist, NULL);
mailimap_search_result_free(lep_uidlist);
-
- uidlist = g_slist_concat(fetchuid_list, uidlist);
} else {
carray * lep_uidtab;
if (r != -1) { /* inited */
r = imap_threaded_fetch_uid(folder, 1,
&lep_uidtab);
if (r == MAILIMAP_NO_ERROR) {
- GSList * fetchuid_list =
- imap_uid_list_from_lep_tab(lep_uidtab);
+ uidlist = imap_uid_list_from_lep_tab(lep_uidtab);
imap_fetch_uid_list_free(lep_uidtab);
- uidlist = g_slist_concat(fetchuid_list, uidlist);
}
}
GSList *uidlist = NULL;
gchar *dir;
gint known_list_len = 0;
+ gchar *path;
+
debug_print("get_num_list\n");
g_return_val_if_fail(folder != NULL, -1);
return -1;
}
+ path = folder_item_get_path(_item);
+ if (!is_dir_exist(path)) {
+ if(is_file_exist(path))
+ claws_unlink(path);
+ make_dir_hier(path);
+ }
+ g_free(path);
+
debug_print("getting session...\n");
session = imap_session_get(folder);
g_return_val_if_fail(session != NULL, -1);
debug_print("exists %d, item->item.total_msgs %d\n",
exists, item->item.total_msgs);
+ debug_print("unseen %d, item->item.unread_msgs %d\n",
+ unseen, item->item.unread_msgs);
+ debug_print("uid_next %d, item->uid_next %d\n",
+ uid_next, item->uid_next);
+ debug_print("uid_val %d, item->item.mtime %d\n",
+ uid_val, item->item.mtime);
if (exists != item->item.total_msgs
|| unseen != item->item.unread_msgs
|| uid_next != item->uid_next
new_item = folder_item_new(FOLDER(folder), loc_name, loc_path);
if ((flags & ETPAN_IMAP_MB_NOINFERIORS) != 0)
new_item->no_sub = TRUE;
- if (strcmp(dup_name, "INBOX") != 0 &&
+ if (strcasecmp(dup_name, "INBOX") != 0 &&
((flags & ETPAN_IMAP_MB_NOSELECT) != 0))
new_item->no_select = TRUE;