#include "imap.h"
#include "imap_gtk.h"
#include "inc.h"
+#include "xml.h"
#ifdef HAVE_LIBETPAN
GHashTable *flags_unset_table;
};
+static XMLTag *imap_item_get_xml(Folder *folder, FolderItem *item);
+static void imap_item_set_xml(Folder *folder, FolderItem *item, XMLTag *tag);
+
static void imap_folder_init (Folder *folder,
const gchar *name,
const gchar *path);
imap_class.close = imap_close;
imap_class.get_num_list = imap_get_num_list;
imap_class.scan_required = imap_scan_required;
+ imap_class.set_xml = folder_set_xml;
+ imap_class.get_xml = folder_get_xml;
+ imap_class.item_set_xml = imap_item_set_xml;
+ imap_class.item_get_xml = imap_item_get_xml;
/* Message functions */
imap_class.get_msginfo = imap_get_msginfo;
IMAPFolderItem *item = (IMAPFolderItem *)node->data;
item->lastuid = 0;
- item->uid_next = 0;
g_slist_free(item->uid_list);
item->uid_list = NULL;
imap_get_capabilities(session);
switch(type) {
+ case IMAP_AUTH_ANON:
+ ok = imap_cmd_login(session, user, pass, "ANONYMOUS");
+ break;
case IMAP_AUTH_CRAM_MD5:
ok = imap_cmd_login(session, user, pass, "CRAM-MD5");
break;
break;
default:
debug_print("capabilities:\n"
+ "\t ANONYMOUS %d\n"
"\t CRAM-MD5 %d\n"
"\t LOGIN %d\n",
+ imap_has_capability(session, "ANONYMOUS"),
imap_has_capability(session, "CRAM-MD5"),
imap_has_capability(session, "LOGIN"));
if (imap_has_capability(session, "CRAM-MD5"))
{
RemoteFolder *rfolder = REMOTE_FOLDER(folder);
IMAPSession *session = NULL;
+ static time_t last_failure = 0;
g_return_val_if_fail(folder != NULL, NULL);
g_return_val_if_fail(FOLDER_CLASS(folder) == &imap_class, NULL);
g_return_val_if_fail(folder->account != NULL, NULL);
- if (prefs_common.work_offline && !inc_offline_should_override()) {
+ if (prefs_common.work_offline &&
+ !inc_offline_should_override(
+ _("Sylpheed-Claws needs network access in order "
+ "to access the IMAP server."))) {
return NULL;
}
} */
} else {
imap_reset_uid_lists(folder);
+ if (time(NULL) - last_failure <= 2)
+ return NULL;
session = imap_session_new(folder, folder->account);
}
- if(session == NULL)
+ if(session == NULL) {
+ last_failure = time(NULL);
return NULL;
+ }
/* Make sure session is authenticated */
if (!IMAP_SESSION(session)->authenticated)
if (!IMAP_SESSION(session)->authenticated) {
session_destroy(SESSION(session));
rfolder->session = NULL;
+ last_failure = time(NULL);
return NULL;
}
g_return_if_fail(account->userid != NULL);
pass = account->passwd;
- if (!pass) {
+ if (!pass && account->imap_auth_type != IMAP_AUTH_ANON) {
gchar *tmp_pass;
tmp_pass = input_dialog_query_password(account->recv_server, account->userid);
if (!tmp_pass)
- tmp_pass = g_strdup(""); /* allow empty password */
+ return;
Xstrdup_a(pass, tmp_pass, {g_free(tmp_pass); return;});
g_free(tmp_pass);
+ } else if (account->imap_auth_type == IMAP_AUTH_ANON) {
+ pass = "";
}
statusbar_print_all(_("Connecting to IMAP4 server %s...\n"),
account->recv_server);
make_dir_hier(path);
filename = g_strconcat(path, G_DIR_SEPARATOR_S, itos(uid), NULL);
g_free(path);
-
+ 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,
procmsg_msginfo_free(msginfo);
file_strip_crs(filename);
return filename;
+ } else if (!cached) {
+ debug_print("message not cached, considering file complete\n");
+ procmsg_msginfo_free(msginfo);
+ file_strip_crs(filename);
+ return filename;
} else {
procmsg_msginfo_free(cached);
procmsg_msginfo_free(msginfo);
statusbar_progress_all(0,0,0);
statusbar_pop_all();
return -1;
+ } else {
+ debug_print("appended new message as %d\n", new_uid);
+ /* put the local file in the imapcache, so that we don't
+ * have to fetch it back later. */
+ if (new_uid > 0) {
+ gchar *cache_path = folder_item_get_path(dest);
+ if (!is_dir_exist(cache_path))
+ make_dir_hier(cache_path);
+ if (is_dir_exist(cache_path)) {
+ gchar *cache_file = g_strconcat(
+ cache_path, G_DIR_SEPARATOR_S,
+ itos(new_uid), NULL);
+ copy_file(real_file, cache_file, TRUE);
+ debug_print("copied to cache: %s\n", cache_file);
+ g_free(cache_file);
+ }
+ g_free(cache_path);
+ }
}
if (relation != NULL)
if (r != MAILIMAP_NO_ERROR)
continue;
+ session_set_access_time(SESSION(session));
+
count = 0;
for(i = 0 ; i < carray_count(env_list) ; i ++) {
struct imap_fetch_env_info * info;
data->numlist = newlist;
data->cur += count;
- if (prefs_common.work_offline && !inc_offline_should_override()) {
+ if (prefs_common.work_offline &&
+ !inc_offline_should_override(
+ _("Sylpheed-Claws needs network access in order "
+ "to access the IMAP server."))) {
g_free(data);
return NULL;
}
/* low-level IMAP4rev1 commands */
-#if 0
-static gint imap_cmd_authenticate(IMAPSession *session, const gchar *user,
- const gchar *pass, IMAPAuthType type)
-{
- gchar *auth_type;
- gint ok;
- gchar *buf = NULL;
- gchar *challenge;
- gint challenge_len;
- gchar hexdigest[33];
- gchar *response;
- gchar *response64;
-
- auth_type = "CRAM-MD5";
-
- imap_gen_send(session, "AUTHENTICATE %s", auth_type);
- ok = imap_gen_recv(session, &buf);
- if (ok != IMAP_SUCCESS || buf[0] != '+' || buf[1] != ' ') {
- g_free(buf);
- return IMAP_ERROR;
- }
-
- challenge = g_malloc(strlen(buf + 2) + 1);
- challenge_len = base64_decode(challenge, buf + 2, -1);
- challenge[challenge_len] = '\0';
- g_free(buf);
-
- md5_hex_hmac(hexdigest, challenge, challenge_len, pass, strlen(pass));
- g_free(challenge);
-
- response = g_strdup_printf("%s %s", user, hexdigest);
- response64 = g_malloc((strlen(response) + 3) * 2 + 1);
- base64_encode(response64, response, strlen(response));
- g_free(response);
-
- sock_puts(SESSION(session)->sock, response64);
- ok = imap_cmd_ok(session, NULL);
- if (ok != IMAP_SUCCESS)
- log_warning(_("IMAP4 authentication failed.\n"));
-
- return ok;
-}
-#endif
-
static gint imap_cmd_login(IMAPSession *session,
const gchar *user, const gchar *pass,
const gchar *type)
{
int r;
- r = imap_threaded_starttls(session->folder);
+ r = imap_threaded_starttls(session->folder,
+ SESSION(session)->server, SESSION(session)->port);
if (r != MAILIMAP_NO_ERROR) {
debug_print("starttls err %d\n", r);
return IMAP_ERROR;
data->headers = headers;
data->body = body;
- if (prefs_common.work_offline && !inc_offline_should_override()) {
+ if (prefs_common.work_offline &&
+ !inc_offline_should_override(
+ _("Sylpheed-Claws needs network access in order "
+ "to access the IMAP server."))) {
g_free(data);
return -1;
}
flag_list = imap_flag_to_lep(flags);
r = imap_threaded_append(session->folder, destfolder,
- file, flag_list);
+ file, flag_list, new_uid);
mailimap_flag_list_free(flag_list);
- if (new_uid != NULL)
- *new_uid = 0;
if (r != MAILIMAP_NO_ERROR) {
debug_print("append err %d\n", r);
{
int r;
- if (prefs_common.work_offline && !inc_offline_should_override()) {
+ if (prefs_common.work_offline &&
+ !inc_offline_should_override(
+ _("Sylpheed-Claws needs network access in order "
+ "to access the IMAP server."))) {
return -1;
}
data->item = item;
data->msgnum_list = msgnum_list;
data->session = session;
- if (prefs_common.work_offline && !inc_offline_should_override()) {
+ if (prefs_common.work_offline &&
+ !inc_offline_should_override(
+ _("Sylpheed-Claws needs network access in order "
+ "to access the IMAP server."))) {
g_free(data);
return -1;
}
session = imap_session_get(folder);
g_return_val_if_fail(session != NULL, -1);
lock_session();
- statusbar_print_all("Scanning %s...\n", FOLDER_ITEM(item)->path
- ? FOLDER_ITEM(item)->path:"");
+
+ if (FOLDER_ITEM(item)->path)
+ statusbar_print_all(_("Scanning folder %s%c%s ..."),
+ FOLDER_ITEM(item)->folder->name,
+ G_DIR_SEPARATOR,
+ FOLDER_ITEM(item)->path);
+ else
+ statusbar_print_all(_("Scanning folder %s ..."),
+ FOLDER_ITEM(item)->folder->name);
selected_folder = (session->mbox != NULL) &&
(!strcmp(session->mbox, item->item.path));
}
g_free(file);
}
+ session_set_access_time(SESSION(session));
}
if (elem == NULL)
item->item.last_num = uid_next - 1;
debug_print("uidnext %d, item->uid_next %d, exists %d, item->item.total_msgs %d\n",
uid_next, item->uid_next, exists, item->item.total_msgs);
- if ((uid_next != item->uid_next) || (exists != item->item.total_msgs)) {
+ if ((uid_next != item->uid_next) || (exists != item->item.total_msgs)
+ || unseen != item->item.unread_msgs || uid_val != item->item.mtime) {
unlock_session();
return TRUE;
}
unseen = g_slist_concat(unseen, uidlist);
}
- r = imap_threaded_search(folder, IMAP_SEARCH_TYPE_ANSWERED,
- imapset, &lep_uidlist);
- if (r == MAILIMAP_NO_ERROR) {
- GSList * uidlist;
-
- uidlist = imap_uid_list_from_lep(lep_uidlist);
- mailimap_search_result_free(lep_uidlist);
-
- answered = g_slist_concat(answered, uidlist);
- }
-
r = imap_threaded_search(folder, IMAP_SEARCH_TYPE_FLAGGED,
imapset, &lep_uidlist);
if (r == MAILIMAP_NO_ERROR) {
GSList * uidlist;
-
+
uidlist = imap_uid_list_from_lep(lep_uidlist);
mailimap_search_result_free(lep_uidlist);
-
+
flagged = g_slist_concat(flagged, uidlist);
}
-
- r = imap_threaded_search(folder, IMAP_SEARCH_TYPE_DELETED,
- imapset, &lep_uidlist);
- if (r == MAILIMAP_NO_ERROR) {
- GSList * uidlist;
-
- uidlist = imap_uid_list_from_lep(lep_uidlist);
- mailimap_search_result_free(lep_uidlist);
-
- deleted = g_slist_concat(deleted, uidlist);
+
+ if (item->opened || item->processing_pending || item == folder->inbox) {
+ r = imap_threaded_search(folder, IMAP_SEARCH_TYPE_ANSWERED,
+ imapset, &lep_uidlist);
+ if (r == MAILIMAP_NO_ERROR) {
+ GSList * uidlist;
+
+ uidlist = imap_uid_list_from_lep(lep_uidlist);
+ mailimap_search_result_free(lep_uidlist);
+
+ answered = g_slist_concat(answered, uidlist);
+ }
+
+ r = imap_threaded_search(folder, IMAP_SEARCH_TYPE_DELETED,
+ imapset, &lep_uidlist);
+ if (r == MAILIMAP_NO_ERROR) {
+ GSList * uidlist;
+
+ uidlist = imap_uid_list_from_lep(lep_uidlist);
+ mailimap_search_result_free(lep_uidlist);
+
+ deleted = g_slist_concat(deleted, uidlist);
+ }
}
}
msginfo = (MsgInfo *) elem->data;
flags = msginfo->flags.perm_flags;
wasnew = (flags & MSG_NEW);
- flags &= ~((reverse_seen ? 0 : MSG_UNREAD | MSG_NEW) | MSG_REPLIED | MSG_MARKED);
+ if (item->opened || item->processing_pending || item == folder->inbox) {
+ flags &= ~((reverse_seen ? 0 : MSG_UNREAD | MSG_NEW) | MSG_REPLIED | MSG_MARKED);
+ } else {
+ flags &= ~((reverse_seen ? 0 : MSG_UNREAD | MSG_NEW | MSG_MARKED));
+ }
if (reverse_seen)
flags |= MSG_UNREAD | (wasnew ? MSG_NEW : 0);
if (gslist_find_next_num(&p_unseen, msginfo->msgnum) == msginfo->msgnum) {
flags &= ~(MSG_UNREAD | MSG_NEW);
}
}
- if (gslist_find_next_num(&p_answered, msginfo->msgnum) == msginfo->msgnum)
- flags |= MSG_REPLIED;
- else
- flags &= ~MSG_REPLIED;
+
if (gslist_find_next_num(&p_flagged, msginfo->msgnum) == msginfo->msgnum)
flags |= MSG_MARKED;
else
flags &= ~MSG_MARKED;
- if (gslist_find_next_num(&p_deleted, msginfo->msgnum) == msginfo->msgnum)
- flags |= MSG_DELETED;
- else
- flags &= ~MSG_DELETED;
+
+ if (item->opened || item->processing_pending || item == folder->inbox) {
+ if (gslist_find_next_num(&p_answered, msginfo->msgnum) == msginfo->msgnum)
+ flags |= MSG_REPLIED;
+ else
+ flags &= ~MSG_REPLIED;
+ if (gslist_find_next_num(&p_deleted, msginfo->msgnum) == msginfo->msgnum)
+ flags |= MSG_DELETED;
+ else
+ flags &= ~MSG_DELETED;
+ }
g_relation_insert(msgflags, msginfo, GINT_TO_POINTER(flags));
}
GSList *tmp = NULL, *cur;
- if (prefs_common.work_offline && !inc_offline_should_override()) {
+ if (prefs_common.work_offline &&
+ !inc_offline_should_override(
+ _("Sylpheed-Claws needs network access in order "
+ "to access the IMAP server."))) {
g_free(data);
return -1;
}
tmp = folder_item_get_msg_list(item);
- if (g_slist_length(tmp) == g_slist_length(msginfo_list))
+ if (g_slist_length(tmp) <= g_slist_length(msginfo_list))
data->full_search = TRUE;
for (cur = tmp; cur; cur = cur->next)
static FolderClass imap_class;
+static XMLTag *imap_item_get_xml(Folder *folder, FolderItem *item);
+static void imap_item_set_xml(Folder *folder, FolderItem *item, XMLTag *tag);
+
static Folder *imap_folder_new (const gchar *name,
const gchar *path)
{
imap_class.create_tree = imap_create_tree;
imap_class.create_folder = imap_create_folder;
imap_class.rename_folder = imap_rename_folder;
+
+ imap_class.set_xml = folder_set_xml;
+ imap_class.get_xml = folder_get_xml;
+ imap_class.item_set_xml = imap_item_set_xml;
+ imap_class.item_get_xml = imap_item_get_xml;
/* nothing implemented */
}
{
imap_gtk_synchronise(item);
}
+
+static void imap_item_set_xml(Folder *folder, FolderItem *item, XMLTag *tag)
+{
+ GList *cur;
+
+ folder_item_set_xml(folder, item, tag);
+
+ for (cur = tag->attr; cur != NULL; cur = g_list_next(cur)) {
+ XMLAttr *attr = (XMLAttr *) cur->data;
+
+ if (!attr || !attr->name || !attr->value) continue;
+ if (!strcmp(attr->name, "uidnext"))
+ IMAP_FOLDER_ITEM(item)->uid_next = atoi(attr->value);
+ }
+}
+
+static XMLTag *imap_item_get_xml(Folder *folder, FolderItem *item)
+{
+ XMLTag *tag;
+
+ tag = folder_item_get_xml(folder, item);
+
+ xml_tag_add_attr(tag, xml_attr_new_int("uidnext",
+ IMAP_FOLDER_ITEM(item)->uid_next));
+
+ return tag;
+}