gint uid,
gboolean headers,
gboolean body);
+static void imap_remove_cached_msg (Folder *folder,
+ FolderItem *item,
+ MsgInfo *msginfo);
static gint imap_add_msg (Folder *folder,
FolderItem *dest,
const gchar *file,
static gchar *imap_get_real_path (IMAPSession *session,
IMAPFolder *folder,
const gchar *path);
-static void imap_synchronise (FolderItem *item);
+static void imap_synchronise (FolderItem *item, gint days);
static gboolean imap_is_busy (Folder *folder);
static void imap_free_capabilities (IMAPSession *session);
imap_class.get_flags = imap_get_flags;
imap_class.set_batch = imap_set_batch;
imap_class.synchronise = imap_synchronise;
+ imap_class.remove_cached_msg = imap_remove_cached_msg;
#ifdef USE_PTREAD
pthread_mutex_init(&imap_mutex, NULL);
#endif
return cnt;
}
+static void imap_remove_cached_msg(Folder *folder, FolderItem *item, MsgInfo *msginfo)
+{
+ gchar *path, *filename;
+
+ path = folder_item_get_path(item);
+
+ if (!is_dir_exist(path)) {
+ g_free(path);
+ return;
+ }
+
+ filename = g_strconcat(path, G_DIR_SEPARATOR_S, itos(msginfo->msgnum), NULL);
+ g_free(path);
+
+ if (is_file_exist(filename)) {
+ g_unlink(filename);
+ }
+ g_free(filename);
+}
+
static gchar *imap_fetch_msg_full(Folder *folder, FolderItem *item, gint uid,
gboolean headers, gboolean body)
{
return ret;
}
+static gint imap_get_msg_from_local(Folder *folder, FolderItem *dest, const gchar *real_file)
+{
+ /* don't get session, already done. */
+ MsgInfo *msginfo;
+ MsgFlags flags = {0, 0};
+ gint msgnum = 0;
+ msginfo = procheader_parse_file(real_file, flags, FALSE, FALSE);
+
+ if (msginfo && msginfo->msgid) {
+ GSList *msglist = folder_item_get_msg_list(dest);
+ GSList *cur;
+ gint found_num = 0;
+
+ /* gets last matching mail with msgid. Slower than by msgid but gets the
+ * most recent one */
+ for (cur = msglist ; cur != NULL ; cur = cur->next) {
+ MsgInfo * r_msginfo;
+
+ r_msginfo = (MsgInfo *) cur->data;
+
+ if (r_msginfo->msgid && !strcmp(r_msginfo->msgid,msginfo->msgid)) {
+ if (found_num < r_msginfo->msgnum) {
+ found_num = r_msginfo->msgnum;
+ }
+ }
+ procmsg_msginfo_free(r_msginfo);
+ }
+ msgnum = found_num;
+ g_slist_free(msglist);
+
+ }
+ procmsg_msginfo_free(msginfo);
+ return msgnum;
+}
+
static gint imap_add_msgs(Folder *folder, FolderItem *dest, GSList *file_list,
GRelation *relation)
{
MsgFileInfo *fileinfo;
gint ok;
gint curnum = 0, total = 0;
-
+ gboolean missing_uids = FALSE;
g_return_val_if_fail(folder != NULL, -1);
g_return_val_if_fail(dest != NULL, -1);
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) {
+ missing_uids = TRUE;
+ debug_print("Missing UID (0)\n");
+ }
if (new_uid > 0) {
gchar *cache_path = folder_item_get_path(dest);
if (!is_dir_exist(cache_path))
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);
+ debug_print("got UID %d, copied to cache: %s\n", new_uid, cache_file);
g_free(cache_file);
}
g_free(cache_path);
if (relation != NULL)
g_relation_insert(relation, fileinfo->msginfo != NULL ?
(gpointer) fileinfo->msginfo : (gpointer) fileinfo,
- GINT_TO_POINTER(dest->last_num + 1));
- if (new_uid == 0) {
- new_uid = dest->last_num+1;
- }
+ GINT_TO_POINTER(new_uid));
if (last_uid < new_uid) {
last_uid = new_uid;
}
g_free(real_file);
}
+
+ if (missing_uids) {
+ unlock_session(IMAP_SESSION(REMOTE_FOLDER(folder)->session));
+ folder_item_scan_full(dest, FALSE);
+ lock_session(IMAP_SESSION(REMOTE_FOLDER(folder)->session));
+ for (cur = file_list; cur != NULL; cur = cur->next) {
+ guint32 new_uid = 0;
+ fileinfo = (MsgFileInfo *)cur->data;
+
+ if (!fileinfo->file)
+ continue;
+
+ new_uid = imap_get_msg_from_local(folder, dest, fileinfo->file);
+ debug_print("new uid %d from scanning\n", new_uid);
+ 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(fileinfo->file, cache_file, TRUE);
+ debug_print("copied to cache: %s\n", cache_file);
+ g_free(cache_file);
+ }
+ g_free(cache_path);
+ g_relation_delete(relation, fileinfo->msginfo != NULL ?
+ (gpointer) fileinfo->msginfo : (gpointer) fileinfo,
+ 0);
+
+ g_relation_insert(relation, fileinfo->msginfo != NULL ?
+ (gpointer) fileinfo->msginfo : (gpointer) fileinfo,
+ GINT_TO_POINTER(new_uid));
+ }
+ if (last_uid < new_uid) {
+ last_uid = new_uid;
+ }
+ }
+ }
statusbar_progress_all(0,0,0);
statusbar_pop_all();
- imap_cmd_expunge(session);
unlock_session(session);
g_free(destdir);
return last_uid;
}
+static GSList *flatten_mailimap_set(struct mailimap_set * set)
+{
+ GSList *result = NULL;
+ clistiter *list;
+ int start, end, t;
+ GSList *cur;
+
+ for (list = clist_begin(set->set_list); list; list = clist_next(list)) {
+ struct mailimap_set_item *item = (struct mailimap_set_item *)clist_content(list);
+ start = item->set_first;
+ end = item->set_last;
+ for (t = start; t <= end; t++) {
+ result = g_slist_prepend(result, GINT_TO_POINTER(t));
+ }
+ }
+ result = g_slist_reverse(result);
+ if (debug_get_mode()) {
+ debug_print("flat imap set: ");
+ for (cur = result; cur; cur = cur->next) {
+ debug_print("%d ", GPOINTER_TO_INT(cur->data));
+ }
+ debug_print("\n");
+ }
+
+ return result;
+}
static gint imap_do_copy_msgs(Folder *folder, FolderItem *dest,
MsgInfoList *msglist, GRelation *relation)
{
&source, &dest);
if (ok == IMAP_SUCCESS) {
- if (single && relation && source && dest) {
- clistiter *l = clist_begin(source->set_list);
- struct mailimap_set_item *i = (struct mailimap_set_item *)clist_content(l);
- int snum = i->set_first;
- int dnum = 0;
- l = clist_begin(dest->set_list);
- i = (struct mailimap_set_item *)clist_content(l);
- dnum = i->set_first;
- g_relation_insert(uid_mapping, GINT_TO_POINTER(snum),
- GINT_TO_POINTER(dnum));
+ if (relation && source && dest) {
+ GSList *s_list = flatten_mailimap_set(source);
+ GSList *d_list = flatten_mailimap_set(dest);
+ GSList *s_cur, *d_cur;
+ if (g_slist_length(s_list) == g_slist_length(d_list)) {
+
+ for (s_cur = s_list, d_cur = d_list;
+ s_cur && d_cur;
+ s_cur = s_cur->next, d_cur = d_cur->next) {
+ g_relation_insert(uid_mapping, s_cur->data, d_cur->data);
+ }
+
+ } else {
+ debug_print("hhhmm, source list length != dest list length.\n");
+ }
+ g_slist_free(s_list);
+ g_slist_free(d_list);
}
}
GINT_TO_POINTER(num));
if (num > last_num)
last_num = num;
- debug_print("copied new message as %d\n", num);
+ debug_print("copied message %d as %d\n", msginfo->msgnum, num);
/* put the local file in the imapcache, so that we don't
* have to fetch it back later. */
if (num > 0) {
int i;
for (i = startnum; i <= lastnum; ++i) {
gchar *file;
-
+ unlock_session(session);
file = imap_fetch_msg(folder, item, i);
+ lock_session(session);
if (file != NULL) {
MsgInfo *msginfo = imap_parse_msg(file, item);
if (msginfo != NULL) {
#endif
-void imap_synchronise(FolderItem *item)
+void imap_synchronise(FolderItem *item, gint days)
{
#ifdef HAVE_LIBETPAN
if (IMAP_FOLDER_ITEM(item)->last_sync == IMAP_FOLDER_ITEM(item)->last_change) {
return;
}
debug_print("syncing %s\n", item->path?item->path:item->name);
- imap_gtk_synchronise(item);
+ imap_gtk_synchronise(item, days);
IMAP_FOLDER_ITEM(item)->last_sync = IMAP_FOLDER_ITEM(item)->last_change;
#endif
}