0.8.11claws7
[claws.git] / src / news.c
index caa0dd824ee242cacb09cf1cd012d7a242922138..345d7712cc0fe4a7ce501b6aa154c94979ceb4a7 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999,2000 Hiroyuki Yamamoto
+ * Copyright (C) 1999-2002 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
@@ -29,6 +29,7 @@
 #include <stdlib.h>
 #include <dirent.h>
 #include <unistd.h>
+#include <time.h>
 
 #include "intl.h"
 #include "news.h"
 #include "prefs_common.h"
 #include "prefs_account.h"
 #include "inputdialog.h"
-#include "alertpanel.h"
+#include "log.h"
+#include "progressindicator.h"
+#if USE_OPENSSL
+#  include "ssl.h"
+#endif
+
+#define NNTP_PORT      119
+#if USE_OPENSSL
+#define NNTPS_PORT     563
+#endif
+
+static void news_folder_init            (Folder        *folder,
+                                         const gchar   *name,
+                                         const gchar   *path);
+
+#if USE_OPENSSL
+static Session *news_session_new        (const gchar   *server,
+                                         gushort        port,
+                                         const gchar   *userid,
+                                         const gchar   *passwd,
+                                         SSLType        ssl_type);
+#else
+static Session *news_session_new        (const gchar   *server,
+                                         gushort        port,
+                                         const gchar   *userid,
+                                         const gchar   *passwd);
+#endif
 
 static gint news_get_article_cmd        (NNTPSession   *session,
                                          const gchar   *cmd,
@@ -54,27 +81,112 @@ static gint news_get_article_cmd    (NNTPSession   *session,
 static gint news_get_article            (NNTPSession   *session,
                                          gint           num,
                                          gchar         *filename);
-static gint news_get_header             (NNTPSession   *session,
-                                         gint           num,
-                                         gchar         *filename);
 
 static gint news_select_group           (NNTPSession   *session,
-                                         const char    *group);
-static GSList *news_get_uncached_articles(NNTPSession  *session,
-                                         FolderItem    *item,
-                                         gint           cache_last,
-                                         gint          *rfirst,
-                                         gint          *rlast);
+                                         const gchar   *group,
+                                         gint          *num,
+                                         gint          *first,
+                                         gint          *last);
 static MsgInfo *news_parse_xover        (const gchar   *xover_str);
-static gchar * news_parse_xhdr           (const gchar *xover_str,
-                                         MsgInfo * info);
-static GSList *news_delete_old_article  (GSList        *alist,
-                                         gint           first);
-static void news_delete_all_article     (FolderItem    *item);
+static gchar *news_parse_xhdr           (const gchar   *xhdr_str,
+                                         MsgInfo       *msginfo);
+static gint news_remove_msg             (Folder        *folder, 
+                                         FolderItem    *item, 
+                                         gint           num);
+gint news_get_num_list                  (Folder        *folder, 
+                                         FolderItem    *item,
+                                         GSList       **list);
+MsgInfo *news_get_msginfo               (Folder        *folder, 
+                                         FolderItem    *item,
+                                         gint           num);
+GSList *news_get_msginfos               (Folder        *folder,
+                                         FolderItem    *item,
+                                         GSList        *msgnum_list);
+
+gint news_post_stream                   (Folder        *folder, 
+                                         FILE          *fp);
+
+FolderClass news_class =
+{
+       F_NEWS,
+       "news",
+
+       /* Folder functions */
+       news_folder_new,
+       news_folder_destroy,
+       NULL,
+       NULL,
+
+       /* FolderItem functions */
+       NULL,
+       NULL,
+       NULL,
+       NULL,
+       NULL,
+       news_get_num_list,
+       NULL,
+       NULL,
+       NULL,
+       NULL,
+
+       /* Message functions */
+       news_get_msginfo,
+       news_get_msginfos,
+       news_fetch_msg,
+       NULL,
+       NULL,
+       NULL,
+       NULL,
+       NULL,
+       news_remove_msg,
+       NULL,
+       NULL,
+       NULL,
+       NULL,
+};
+
+FolderClass *news_get_class()
+{
+       return &news_class;
+}
+
+Folder *news_folder_new(const gchar *name, const gchar *path)
+{
+       Folder *folder;
+
+       folder = (Folder *)g_new0(NewsFolder, 1);
+       folder->class = &news_class;
+       news_folder_init(folder, name, path);
+
+       return folder;
+}
+
+void news_folder_destroy(Folder *folder)
+{
+       gchar *dir;
+
+       dir = folder_get_path(folder);
+       if (is_dir_exist(dir))
+               remove_dir_recursive(dir);
+       g_free(dir);
+
+       folder_remote_folder_destroy(REMOTE_FOLDER(folder));
+}
 
+static void news_folder_init(Folder *folder, const gchar *name,
+                            const gchar *path)
+{
+       folder_remote_folder_init(folder, name, path);
+}
 
+#if USE_OPENSSL
+static Session *news_session_new(const gchar *server, gushort port,
+                                const gchar *userid, const gchar *passwd,
+                                SSLType ssl_type)
+#else
 static Session *news_session_new(const gchar *server, gushort port,
                                 const gchar *userid, const gchar *passwd)
+#endif
 {
        gchar buf[NNTPBUFSIZE];
        NNTPSession *session;
@@ -84,184 +196,161 @@ static Session *news_session_new(const gchar *server, gushort port,
 
        log_message(_("creating NNTP connection to %s:%d ...\n"), server, port);
 
+#if USE_OPENSSL
+       if (userid && passwd)
+               nntp_sock = nntp_open_auth(server, port, buf, userid, passwd,
+                                          ssl_type);
+       else
+               nntp_sock = nntp_open(server, port, buf, ssl_type);
+#else
        if (userid && passwd)
                nntp_sock = nntp_open_auth(server, port, buf, userid, passwd);
        else
                nntp_sock = nntp_open(server, port, buf);
+#endif
+
        if (nntp_sock == NULL)
                return NULL;
 
        session = g_new(NNTPSession, 1);
-       SESSION(session)->type      = SESSION_NEWS;
-       SESSION(session)->server    = g_strdup(server);
-       session->nntp_sock          = nntp_sock;
-       SESSION(session)->sock      = nntp_sock->sock;
-       SESSION(session)->connected = TRUE;
-       SESSION(session)->phase     = SESSION_READY;
-       SESSION(session)->data      = NULL;
+       SESSION(session)->type             = SESSION_NEWS;
+       SESSION(session)->server           = g_strdup(server);
+       session->nntp_sock                 = nntp_sock;
+       SESSION(session)->sock             = nntp_sock->sock;
+       SESSION(session)->connected        = TRUE;
+       SESSION(session)->phase            = SESSION_READY;
+       SESSION(session)->last_access_time = time(NULL);
+       SESSION(session)->data             = NULL;
+
+       SESSION(session)->destroy          = news_session_destroy;
+
        session->group = NULL;
 
        return SESSION(session);
 }
 
-void news_session_destroy(NNTPSession *session)
+void news_session_destroy(Session *session)
 {
-       nntp_close(session->nntp_sock);
-       session->nntp_sock = NULL;
-       SESSION(session)->sock = NULL;
-
-       g_free(session->group);
-}
+       nntp_close(NNTP_SESSION(session)->nntp_sock);
+       NNTP_SESSION(session)->nntp_sock = NULL;
+       session->sock = NULL;
 
-static gchar *news_query_password(const gchar *server,
-                                 const gchar *user)
-{
-       gchar *message;
-       gchar *pass;
-
-       message = g_strdup_printf(_("Input password for %s on %s:"),
-                                 user, server);
-
-       pass = input_dialog_with_invisible(_("Input password"),
-                                          message, NULL);
-       g_free(message);
-/*     manage_window_focus_in(inc_dialog->mainwin->window, */
-/*                            NULL, NULL); */
-       return pass;
+       g_free(NNTP_SESSION(session)->group);
 }
 
 static Session *news_session_new_for_folder(Folder *folder)
 {
        Session *session;
        PrefsAccount *ac;
-       const gchar *userid;
-       gchar *passwd;
+       const gchar *userid = NULL;
+       gchar *passwd = NULL;
+       gushort port;
+       gchar buf[NNTPBUFSIZE];
+
+       g_return_val_if_fail(folder != NULL, NULL);
+       g_return_val_if_fail(folder->account != NULL, NULL);
 
        ac = folder->account;
        if (ac->use_nntp_auth && ac->userid && ac->userid[0]) {
                userid = ac->userid;
                if (ac->passwd && ac->passwd[0])
                        passwd = g_strdup(ac->passwd);
-               else {
-                       passwd = news_query_password(ac->nntp_server, userid);
-                       if (!passwd)
-                               userid = NULL;
-               }
-       } else {
-               userid = passwd = NULL;
+               else
+                       passwd = input_dialog_query_password(ac->nntp_server,
+                                                            userid);
        }
-       session = news_session_new(ac->nntp_server, 119, userid, passwd);
+
+#if USE_OPENSSL
+       port = ac->set_nntpport ? ac->nntpport
+               : ac->ssl_nntp ? NNTPS_PORT : NNTP_PORT;
+       session = news_session_new(ac->nntp_server, port, userid, passwd,
+                                  ac->ssl_nntp);
+#else
+       port = ac->set_nntpport ? ac->nntpport : NNTP_PORT;
+       session = news_session_new(ac->nntp_server, port, userid, passwd);
+#endif
+       if ((session != NULL) && ac->use_nntp_auth && ac->use_nntp_auth_onconnect)
+               nntp_forceauth(NNTP_SESSION(session)->nntp_sock, buf, userid, passwd);
+
        g_free(passwd);
+
        return session;
 }
 
 NNTPSession *news_session_get(Folder *folder)
 {
-       NNTPSession *session;
+       RemoteFolder *rfolder = REMOTE_FOLDER(folder);
 
        g_return_val_if_fail(folder != NULL, NULL);
-       g_return_val_if_fail(folder->type == F_NEWS, NULL);
+       g_return_val_if_fail(FOLDER_CLASS(folder) == &news_class, NULL);
        g_return_val_if_fail(folder->account != NULL, NULL);
 
-       if (!REMOTE_FOLDER(folder)->session) {
-               REMOTE_FOLDER(folder)->session =
-                       news_session_new_for_folder(folder);
-       } else {
-               session = NNTP_SESSION(REMOTE_FOLDER(folder)->session);
-               if (nntp_mode(session->nntp_sock, FALSE) != NN_SUCCESS) {
-                       log_warning(_("NNTP connection to %s:%d has been"
-                                     " disconnected. Reconnecting...\n"),
-                                   folder->account->nntp_server, 119);
-                       session_destroy(REMOTE_FOLDER(folder)->session);
-                       REMOTE_FOLDER(folder)->session =
-                               news_session_new_for_folder(folder);
-               }
+       if (!rfolder->session) {
+               rfolder->session = news_session_new_for_folder(folder);
+               return NNTP_SESSION(rfolder->session);
        }
 
-       return NNTP_SESSION(REMOTE_FOLDER(folder)->session);
-}
-
-GSList *news_get_article_list(Folder *folder, FolderItem *item,
-                             gboolean use_cache)
-{
-       GSList *alist;
-       NNTPSession *session;
-
-       g_return_val_if_fail(folder != NULL, NULL);
-       g_return_val_if_fail(item != NULL, NULL);
-       g_return_val_if_fail(folder->type == F_NEWS, NULL);
-
-       session = news_session_get(folder);
-
-       if (!session) {
-               alist = procmsg_read_cache(item, FALSE);
-               item->last_num = procmsg_get_last_num_in_cache(alist);
-       } else if (use_cache) {
-               GSList *newlist;
-               gint cache_last;
-               gint first, last;
-
-               alist = procmsg_read_cache(item, FALSE);
-
-               cache_last = procmsg_get_last_num_in_cache(alist);
-               newlist = news_get_uncached_articles
-                       (session, item, cache_last, &first, &last);
-               alist = news_delete_old_article(alist, first);
-
-               alist = g_slist_concat(alist, newlist);
-               item->last_num = last;
-       } else {
-               gint last;
-
-               alist = news_get_uncached_articles
-                       (session, item, 0, NULL, &last);
-               news_delete_all_article(item);
-               item->last_num = last;
+       if (time(NULL) - rfolder->session->last_access_time < SESSION_TIMEOUT) {
+               rfolder->session->last_access_time = time(NULL);
+               return NNTP_SESSION(rfolder->session);
        }
 
-       procmsg_set_flags(alist, item);
-
-       statusbar_pop_all();
+       if (nntp_mode(NNTP_SESSION(rfolder->session)->nntp_sock, FALSE)
+           != NN_SUCCESS) {
+               log_warning("NNTP connection to %s:%d has been"
+                             " disconnected. Reconnecting...\n",
+                           folder->account->nntp_server,
+                           folder->account->set_nntpport ?
+                           folder->account->nntpport : NNTP_PORT);
+               session_destroy(rfolder->session);
+               rfolder->session = news_session_new_for_folder(folder);
+       }
 
-       return alist;
+       if (rfolder->session)
+               rfolder->session->last_access_time = time(NULL);
+       return NNTP_SESSION(rfolder->session);
 }
 
 gchar *news_fetch_msg(Folder *folder, FolderItem *item, gint num)
 {
        gchar *path, *filename;
+       NNTPSession *session;
        gint ok;
 
        g_return_val_if_fail(folder != NULL, NULL);
        g_return_val_if_fail(item != NULL, NULL);
 
        path = folder_item_get_path(item);
+       if (!is_dir_exist(path))
+               make_dir_hier(path);
        filename = g_strconcat(path, G_DIR_SEPARATOR_S, itos(num), NULL);
        g_free(path);
 
        if (is_file_exist(filename)) {
-               debug_print(_("article %d has been already cached.\n"), num);
+               debug_print("article %d has been already cached.\n", num);
                return filename;
        }
 
-       if (!REMOTE_FOLDER(folder)->session) {
+       session = news_session_get(folder);
+       if (!session) {
                g_free(filename);
                return NULL;
        }
 
-       ok = news_select_group(NNTP_SESSION(REMOTE_FOLDER(folder)->session),
-                              item->path);
+       ok = news_select_group(session, item->path, NULL, NULL, NULL);
        if (ok != NN_SUCCESS) {
-               g_warning(_("can't select group %s\n"), item->path);
+               g_warning("can't select group %s\n", item->path);
                g_free(filename);
                return NULL;
        }
 
-       debug_print(_("getting article %d...\n"), num);
+       debug_print("getting article %d...\n", num);
        ok = news_get_article(NNTP_SESSION(REMOTE_FOLDER(folder)->session),
                              num, filename);
-       statusbar_pop_all();
        if (ok < 0) {
-               g_warning(_("can't read article %d\n"), num);
+               g_warning("can't read article %d\n", num);
+               session_destroy(SESSION(session));
+               REMOTE_FOLDER(folder)->session = NULL;
                g_free(filename);
                return NULL;
        }
@@ -269,243 +358,312 @@ gchar *news_fetch_msg(Folder *folder, FolderItem *item, gint num)
        return filename;
 }
 
-void news_scan_group(Folder *folder, FolderItem *item)
-{
-}
-
-gint news_post(Folder *folder, const gchar *file)
+gint news_scan_group(Folder *folder, FolderItem *item)
 {
        NNTPSession *session;
-       FILE *fp;
+       gint num = 0, first = 0, last = 0;
        gint ok;
 
        g_return_val_if_fail(folder != NULL, -1);
-       g_return_val_if_fail(folder->type == F_NEWS, -1);
-       g_return_val_if_fail(file != NULL, -1);
+       g_return_val_if_fail(item != NULL, -1);
 
        session = news_session_get(folder);
        if (!session) return -1;
 
-       if ((fp = fopen(file, "r")) == NULL) {
-               FILE_OP_ERROR(file, "fopen");
+       ok = news_select_group(session, item->path, &num, &first, &last);
+       if (ok != NN_SUCCESS) {
+               log_warning("can't set group: %s\n", item->path);
                return -1;
        }
 
-       ok = nntp_post(session->nntp_sock, fp);
-       if (ok != NN_SUCCESS) {
-               log_warning(_("can't post article.\n"));
-               return -1;
+       if (num == 0) {
+               item->new = item->unread = item->total = item->last_num = 0;
+               return 0;
        }
 
-       fclose(fp);
+/*
+       path = folder_item_get_path(item);
+       if (path && is_dir_exist(path)) {
+               procmsg_get_mark_sum(path, &new, &unread, &total, &min, &max,
+                                    first);
+       }
+       g_free(path);
 
-       statusbar_pop_all();
+       if (max < first || last < min)
+               new = unread = total = num;
+       else {
+               if (min < first)
+                       min = first;
+
+               if (last < max)
+                       max = last;
+               else if (max < last) {
+                       new += last - max;
+                       unread += last - max;
+               }
+
+               if (new > num) new = num;
+               if (unread > num) unread = num;
+       }
 
+       item->new = new;
+       item->unread = unread;
+       item->total = num;
+       item->last_num = last;
+*/
        return 0;
 }
 
-static gint news_get_article_cmd(NNTPSession *session, const gchar *cmd,
-                                gint num, gchar *filename)
+static NewsGroupInfo *news_group_info_new(const gchar *name,
+                                         gint first, gint last, gchar type)
 {
-       gchar *msgid;
+       NewsGroupInfo *ginfo;
 
-       if (nntp_get_article(session->nntp_sock, cmd, num, &msgid)
-           != NN_SUCCESS)
-               return -1;
+       ginfo = g_new(NewsGroupInfo, 1);
+       ginfo->name = g_strdup(name);
+       ginfo->first = first;
+       ginfo->last = last;
+       ginfo->type = type;
 
-       debug_print("Message-Id = %s, num = %d\n", msgid, num);
-       g_free(msgid);
-
-       if (recv_write_to_file(session->nntp_sock->sock, filename) < 0) {
-               log_warning(_("can't retrieve article %d\n"), num);
-               return -1;
-       }
-
-       return 0;
+       return ginfo;
 }
 
-static gint news_get_article(NNTPSession *session, gint num, gchar *filename)
+static void news_group_info_free(NewsGroupInfo *ginfo)
 {
-       return news_get_article_cmd(session, "ARTICLE", num, filename);
+       g_free(ginfo->name);
+       g_free(ginfo);
 }
 
-static gint news_get_header(NNTPSession *session, gint num, gchar *filename)
+static gint news_group_info_compare(NewsGroupInfo *ginfo1,
+                                   NewsGroupInfo *ginfo2)
 {
-       return news_get_article_cmd(session, "HEAD", num, filename);
+       return g_strcasecmp(ginfo1->name, ginfo2->name);
 }
 
-/**
- * news_select_group:
- * @session: Active NNTP session.
- * @group: Newsgroup name.
- * 
- * Select newsgroup @group with the GROUP command if it is not already
- * selected in @session.
- * 
- * Return value: NNTP result code.
- **/
-static gint news_select_group(NNTPSession *session,
-                             const char *group)
+GSList *news_get_group_list(Folder *folder)
 {
-       gint ok;
-       gint num, first, last;
+       gchar *path, *filename;
+       FILE *fp;
+       GSList *list = NULL;
+       GSList *last = NULL;
+       gchar buf[NNTPBUFSIZE];
 
-       if (g_strcasecmp(session->group, group) == 0)
-               return NN_SUCCESS;
+       g_return_val_if_fail(folder != NULL, NULL);
+       g_return_val_if_fail(FOLDER_CLASS(folder) == &news_class, NULL);
 
-       g_free(session->group);
-       session->group = NULL;
+       path = folder_item_get_path(FOLDER_ITEM(folder->node->data));
+       if (!is_dir_exist(path))
+               make_dir_hier(path);
+       filename = g_strconcat(path, G_DIR_SEPARATOR_S, NEWSGROUP_LIST, NULL);
+       g_free(path);
 
-       ok = nntp_group(session->nntp_sock, group, &num, &first, &last);
+       if ((fp = fopen(filename, "rb")) == NULL) {
+               NNTPSession *session;
 
-       if (ok == NN_SUCCESS)
-               session->group = g_strdup(group);
+               session = news_session_get(folder);
+               if (!session) {
+                       g_free(filename);
+                       return NULL;
+               }
 
-       return ok;
-}
+               if (nntp_list(session->nntp_sock) != NN_SUCCESS) {
+                       g_free(filename);
+                       return NULL;
+               }
+               if (recv_write_to_file(SESSION(session)->sock, filename) < 0) {
+                       log_warning("can't retrieve newsgroup list\n");
+                       session_destroy(SESSION(session));
+                       REMOTE_FOLDER(folder)->session = NULL;
+                       g_free(filename);
+                       return NULL;
+               }
 
-static GSList *news_get_uncached_articles(NNTPSession *session,
-                                         FolderItem *item, gint cache_last,
-                                         gint *rfirst, gint *rlast)
-{
-       gint ok;
-       gint num = 0, first = 0, last = 0, begin = 0, end = 0;
-       gchar buf[NNTPBUFSIZE];
-       GSList *newlist = NULL;
-       GSList *llast = NULL;
-       MsgInfo *msginfo;
+               if ((fp = fopen(filename, "rb")) == NULL) {
+                       FILE_OP_ERROR(filename, "fopen");
+                       g_free(filename);
+                       return NULL;
+               }
+       }
 
-       if (rfirst) *rfirst = 0;
-       if (rlast)  *rlast  = 0;
+       while (fgets(buf, sizeof(buf), fp) != NULL) {
+               gchar *p = buf;
+               gchar *name;
+               gint last_num;
+               gint first_num;
+               gchar type;
+               NewsGroupInfo *ginfo;
+
+               p = strchr(p, ' ');
+               if (!p) continue;
+               *p = '\0';
+               p++;
+               name = buf;
 
-       g_return_val_if_fail(session != NULL, NULL);
-       g_return_val_if_fail(item != NULL, NULL);
-       g_return_val_if_fail(item->folder != NULL, NULL);
-       g_return_val_if_fail(item->folder->type == F_NEWS, NULL);
+               if (sscanf(p, "%d %d %c", &last_num, &first_num, &type) < 3)
+                       continue;
 
-       g_free(session->group);
-       session->group = NULL;
+               ginfo = news_group_info_new(name, first_num, last_num, type);
 
-       ok = nntp_group(session->nntp_sock, item->path,
-                       &num, &first, &last);
-       if (ok != NN_SUCCESS) {
-               log_warning(_("can't set group: %s\n"), item->path);
-               return NULL;
+               if (!last)
+                       last = list = g_slist_append(NULL, ginfo);
+               else {
+                       last = g_slist_append(last, ginfo);
+                       last = last->next;
+               }
        }
 
-       session->group = g_strdup(item->path);
+       fclose(fp);
+       g_free(filename);
 
-       /* calculate getting overview range */
-       if (first > last) {
-               log_warning(_("invalid article range: %d - %d\n"),
-                           first, last);
-               return NULL;
-       }
-       if (cache_last < first)
-               begin = first;
-       else if (last < cache_last)
-               begin = first;
-       else if (last == cache_last) {
-               debug_print(_("no new articles.\n"));
-               return NULL;
-       } else
-               begin = cache_last + 1;
-       end = last;
+       list = g_slist_sort(list, (GCompareFunc)news_group_info_compare);
 
-       if (prefs_common.max_articles > 0 &&
-           end - begin + 1 > prefs_common.max_articles)
-               begin = end - prefs_common.max_articles + 1;
+       return list;
+}
 
-       log_message(_("getting xover %d - %d in %s...\n"),
-                   begin, end, item->path);
-       if (nntp_xover(session->nntp_sock, begin, end) != NN_SUCCESS) {
-               log_warning(_("can't get xover\n"));
-               return NULL;
-       }
+void news_group_list_free(GSList *group_list)
+{
+       GSList *cur;
 
-       for (;;) {
-               if (sock_gets(SESSION(session)->sock, buf, sizeof(buf)) < 0) {
-                       log_warning(_("error occurred while getting xover.\n"));
-                       return newlist;
-               }
+       if (!group_list) return;
 
-               if (buf[0] == '.' && buf[1] == '\r') break;
+       for (cur = group_list; cur != NULL; cur = cur->next)
+               news_group_info_free((NewsGroupInfo *)cur->data);
+       g_slist_free(group_list);
+}
 
-               msginfo = news_parse_xover(buf);
-               if (!msginfo) {
-                       log_warning(_("invalid xover line: %s\n"), buf);
-                       continue;
-               }
+void news_remove_group_list_cache(Folder *folder)
+{
+       gchar *path, *filename;
 
-               msginfo->folder = item;
-               msginfo->flags = MSG_NEW|MSG_UNREAD|MSG_NEWS;
+       g_return_if_fail(folder != NULL);
+       g_return_if_fail(FOLDER_CLASS(folder) == &news_class);
 
-               if (!newlist)
-                       llast = newlist = g_slist_append(newlist, msginfo);
-               else {
-                       llast = g_slist_append(llast, msginfo);
-                       llast = llast->next;
-               }
+       path = folder_item_get_path(FOLDER_ITEM(folder->node->data));
+       filename = g_strconcat(path, G_DIR_SEPARATOR_S, NEWSGROUP_LIST, NULL);
+       g_free(path);
+
+       if (is_file_exist(filename)) {
+               if (remove(filename) < 0)
+                       FILE_OP_ERROR(filename, "remove");
        }
+       g_free(filename);
+}
 
-       if (nntp_xhdr(session->nntp_sock, "to", begin, end) != NN_SUCCESS) {
-               log_warning(_("can't get xhdr\n"));
-               return NULL;
+gint news_post(Folder *folder, const gchar *file)
+{
+       FILE *fp;
+       gint ok;
+
+       g_return_val_if_fail(folder != NULL, -1);
+       g_return_val_if_fail(FOLDER_CLASS(folder) == &news_class, -1);
+       g_return_val_if_fail(file != NULL, -1);
+
+       if ((fp = fopen(file, "rb")) == NULL) {
+               FILE_OP_ERROR(file, "fopen");
+               return -1;
        }
 
-       llast = newlist;
+       ok = news_post_stream(folder, fp);
 
-       for (;;) {
-               gchar * value;
-               
-               if (sock_gets(SESSION(session)->sock, buf, sizeof(buf)) < 0) {
-                       log_warning(_("error occurred while getting xover.\n"));
-                       return newlist;
-               }
+       fclose(fp);
 
-               if (buf[0] == '.' && buf[1] == '\r') break;
+       return ok;
+}
 
-               msginfo = (MsgInfo *) llast->data;
+gint news_post_stream(Folder *folder, FILE *fp)
+{
+       NNTPSession *session;
+       gint ok;
 
-               value = news_parse_xhdr(buf, msginfo);
+       g_return_val_if_fail(folder != NULL, -1);
+       g_return_val_if_fail(FOLDER_CLASS(folder) == &news_class, -1);
+       g_return_val_if_fail(fp != NULL, -1);
 
-               if (value)
-                       msginfo->to = value;
+       session = news_session_get(folder);
+       if (!session) return -1;
 
-               llast = llast->next;
-               
+       ok = nntp_post(session->nntp_sock, fp);
+       if (ok != NN_SUCCESS) {
+               log_warning("can't post article.\n");
+               return -1;
        }
 
-       if (nntp_xhdr(session->nntp_sock, "cc", begin, end) != NN_SUCCESS) {
-               log_warning(_("can't get xhdr\n"));
-               return NULL;
-       }
+       return 0;
+}
 
-       llast = newlist;
+static gint news_get_article_cmd(NNTPSession *session, const gchar *cmd,
+                                gint num, gchar *filename)
+{
+       gchar *msgid;
 
-       for (;;) {
-               gchar * value;
-               
-               if (sock_gets(SESSION(session)->sock, buf, sizeof(buf)) < 0) {
-                       log_warning(_("error occurred while getting xover.\n"));
-                       return newlist;
-               }
+       if (nntp_get_article(session->nntp_sock, cmd, num, &msgid)
+           != NN_SUCCESS)
+               return -1;
 
-               if (buf[0] == '.' && buf[1] == '\r') break;
+       debug_print("Message-Id = %s, num = %d\n", msgid, num);
+       g_free(msgid);
 
-               msginfo = (MsgInfo *) llast->data;
+       if (recv_write_to_file(session->nntp_sock->sock, filename) < 0) {
+               log_warning("can't retrieve article %d\n", num);
+               return -1;
+       }
 
-               value = news_parse_xhdr(buf, msginfo);
+       return 0;
+}
 
-               if (value)
-                       msginfo->cc = value;
+static gint news_remove_msg(Folder *folder, FolderItem *item, gint num)
+{
+       gchar * dir;
+       gint r;
 
-               llast = llast->next;
+       dir = folder_item_get_path(item);
+       debug_print("news_remove_msg: removing msg %d in %s\n",num,dir);
+       r = remove_numbered_files(dir, num, num);
+       g_free(dir);
+
+       return r;
+}
+
+static gint news_get_article(NNTPSession *session, gint num, gchar *filename)
+{
+       return news_get_article_cmd(session, "ARTICLE", num, filename);
+}
+
+/**
+ * news_select_group:
+ * @session: Active NNTP session.
+ * @group: Newsgroup name.
+ * @num: Estimated number of articles.
+ * @first: First article number.
+ * @last: Last article number.
+ *
+ * Select newsgroup @group with the GROUP command if it is not already
+ * selected in @session, or article numbers need to be returned.
+ *
+ * Return value: NNTP result code.
+ **/
+static gint news_select_group(NNTPSession *session, const gchar *group,
+                             gint *num, gint *first, gint *last)
+{
+       gint ok;
+       gint num_, first_, last_;
+
+       if (!num || !first || !last) {
+               if (session->group && g_strcasecmp(session->group, group) == 0)
+                       return NN_SUCCESS;
+               num = &num_;
+               first = &first_;
+               last = &last_;
        }
 
-       if (rfirst) *rfirst = first;
-       if (rlast)  *rlast  = last;
-       return newlist;
+       g_free(session->group);
+       session->group = NULL;
+
+       ok = nntp_group(session->nntp_sock, group, num, first, last);
+       if (ok == NN_SUCCESS)
+               session->group = g_strdup(group);
+
+       return ok;
 }
 
 #define PARSE_ONE_PARAM(p, srcp) \
@@ -520,13 +678,12 @@ static MsgInfo *news_parse_xover(const gchar *xover_str)
 {
        MsgInfo *msginfo;
        gchar buf[NNTPBUFSIZE];
-       gchar *subject, *sender, *size, *line, *date, *msgid, *ref, *tmp;
+       gchar *subject, *sender, *size, *line, *date, *msgid, *ref, *tmp, *xref;
        gchar *p;
        gint num, size_int, line_int;
        gchar *xover_buf;
 
-       Xalloca(xover_buf, strlen(xover_str) + 1, return NULL);
-       strcpy(xover_buf, xover_str);
+       Xstrdup_a(xover_buf, xover_str, return NULL);
 
        PARSE_ONE_PARAM(subject, xover_buf);
        PARSE_ONE_PARAM(sender, subject);
@@ -535,8 +692,9 @@ static MsgInfo *news_parse_xover(const gchar *xover_str)
        PARSE_ONE_PARAM(ref, msgid);
        PARSE_ONE_PARAM(size, ref);
        PARSE_ONE_PARAM(line, size);
+       PARSE_ONE_PARAM(xref, line);
 
-       tmp = strchr(line, '\t');
+       tmp = strchr(xref, '\t');
        if (!tmp) tmp = strchr(line, '\r');
        if (!tmp) tmp = strchr(line, '\n');
        if (tmp) *tmp = '\0';
@@ -546,7 +704,7 @@ static MsgInfo *news_parse_xover(const gchar *xover_str)
        line_int = atoi(line);
 
        /* set MsgInfo */
-       msginfo = g_new0(MsgInfo, 1);
+       msginfo = procmsg_msginfo_new();
        msginfo->msgnum = num;
        msginfo->size = size_int;
 
@@ -565,6 +723,7 @@ static MsgInfo *news_parse_xover(const gchar *xover_str)
        if (*msgid != '\0')
                msginfo->msgid = g_strdup(msgid);
 
+       msginfo->references = g_strdup(ref);
        eliminate_parenthesis(ref, '(', ')');
        if ((p = strrchr(ref, '<')) != NULL) {
                extract_parenthesis(p, '<', '>');
@@ -573,176 +732,359 @@ static MsgInfo *news_parse_xover(const gchar *xover_str)
                        msginfo->inreplyto = g_strdup(p);
        }
 
+       msginfo->xref = g_strdup(xref);
+       p = msginfo->xref+strlen(msginfo->xref) - 1;
+       while (*p == '\r' || *p == '\n') {
+               *p = '\0';
+               p--;
+       }
+
        return msginfo;
 }
 
-static gchar * news_parse_xhdr(const gchar *xover_str, MsgInfo * info)
+static gchar *news_parse_xhdr(const gchar *xhdr_str, MsgInfo *msginfo)
 {
-       gchar buf[NNTPBUFSIZE];
        gchar *p;
+       gchar *tmp;
        gint num;
 
-       p = strchr(xover_str, ' ');
+       p = strchr(xhdr_str, ' ');
        if (!p)
                return NULL;
        else
                p++;
 
-       num = atoi(xover_str);
+       num = atoi(xhdr_str);
+       if (msginfo->msgnum != num) return NULL;
 
-       if (info->msgnum != num)
-               return NULL;
+       tmp = strchr(p, '\r');
+       if (!tmp) tmp = strchr(p, '\n');
 
-       return g_strdup(p);
+       if (tmp)
+               return g_strndup(p, tmp - p);
+       else
+               return g_strdup(p);
 }
 
-static GSList *news_delete_old_article(GSList *alist, gint first)
+gint news_cancel_article(Folder * folder, MsgInfo * msginfo)
 {
-       GSList *cur, *next;
-       MsgInfo *msginfo;
-       gchar *cache_file;
+       gchar * tmp;
+       FILE * tmpfp;
+       gchar buf[BUFFSIZE];
 
-       if (first < 2) return alist;
+       tmp = g_strdup_printf("%s%ctmp%d", g_get_tmp_dir(),
+                             G_DIR_SEPARATOR, (gint)msginfo);
+       if (tmp == NULL)
+               return -1;
 
-       for (cur = alist; cur != NULL; ) {
-               next = cur->next;
+       if ((tmpfp = fopen(tmp, "wb")) == NULL) {
+               FILE_OP_ERROR(tmp, "fopen");
+               return -1;
+       }
+       if (change_file_mode_rw(tmpfp, tmp) < 0) {
+               FILE_OP_ERROR(tmp, "chmod");
+               g_warning("can't change file mode\n");
+       }
+       
+       fprintf(tmpfp, "From: %s\r\n", msginfo->from);
+       fprintf(tmpfp, "Newsgroups: %s\r\n", msginfo->newsgroups);
+       fprintf(tmpfp, "Subject: cmsg cancel <%s>\r\n", msginfo->msgid);
+       fprintf(tmpfp, "Control: cancel <%s>\r\n", msginfo->msgid);
+       fprintf(tmpfp, "Approved: %s\r\n", msginfo->from);
+       fprintf(tmpfp, "X-Cancelled-by: %s\r\n", msginfo->from);
+       get_rfc822_date(buf, sizeof(buf));
+       fprintf(tmpfp, "Date: %s\r\n", buf);
+       fprintf(tmpfp, "\r\n");
+       fprintf(tmpfp, "removed with sylpheed\r\n");
 
-               msginfo = (MsgInfo *)cur->data;
-               if (msginfo && msginfo->msgnum < first) {
-                       debug_print(_("deleting article %d...\n"),
-                                   msginfo->msgnum);
+       fclose(tmpfp);
 
-                       cache_file = procmsg_get_message_file_path(msginfo);
-                       if (is_file_exist(cache_file)) unlink(cache_file);
-                       g_free(cache_file);
+       news_post(folder, tmp);
+       remove(tmp);
 
-                       procmsg_msginfo_free(msginfo);
-                       alist = g_slist_remove(alist, msginfo);
-               }
+       g_free(tmp);
 
-               cur = next;
-       }
-
-       return alist;
+       return 0;
 }
 
-static void news_delete_all_article(FolderItem *item)
+gint news_get_num_list(Folder *folder, FolderItem *item, GSList **msgnum_list)
 {
-       DIR *dp;
-       struct dirent *d;
+       NNTPSession *session;
+       gint i, ok, num, first, last, nummsgs = 0;
        gchar *dir;
-       gchar *file;
-
-       dir = folder_item_get_path(item);
-       if ((dp = opendir(dir)) == NULL) {
-               FILE_OP_ERROR(dir, "opendir");
-               g_free(dir);
-               return;
-       }
 
-       debug_print(_("\tDeleting all cached articles... "));
+       g_return_val_if_fail(item != NULL, -1);
+       g_return_val_if_fail(item->folder != NULL, -1);
+       g_return_val_if_fail(FOLDER_CLASS(folder) == &news_class, -1);
 
-       while ((d = readdir(dp)) != NULL) {
-               if (to_number(d->d_name) < 0) continue;
+       session = news_session_get(folder);
+       g_return_val_if_fail(session != NULL, -1);
 
-               file = g_strconcat(dir, G_DIR_SEPARATOR_S, d->d_name, NULL);
+       ok = news_select_group(session, item->path, &num, &first, &last);
+       if (ok != NN_SUCCESS) {
+               log_warning(_("can't set group: %s\n"), item->path);
+               return -1;
+       }
 
-               if (is_file_exist(file)) {
-                       if (unlink(file) < 0)
-                               FILE_OP_ERROR(file, "unlink");
-               }
+       if(last < first) {
+               log_warning(_("invalid article range: %d - %d\n"),
+                           first, last);
+               return 0;
+       }
 
-               g_free(file);
+       for(i = first; i <= last; i++) {
+               *msgnum_list = g_slist_prepend(*msgnum_list, GINT_TO_POINTER(i));
+               nummsgs++;
        }
 
-       closedir(dp);
+       dir = folder_item_get_path(item);
+       debug_print("removing old messages from %d to %d in %s\n", first, last, dir);
+       remove_numbered_files(dir, 1, first - 1);
        g_free(dir);
 
-       debug_print(_("done.\n"));
+       return nummsgs;
 }
 
-/*
-  news_get_group_list returns a strings list.
-  These strings are the names of the newsgroups of a server.
-  item is the FolderItem of the news server.
-  The names of the newsgroups are cached into a file so that
-  when the function is called again, there is no need to make
-  a request to the server.
- */
+#define READ_TO_LISTEND(hdr) \
+       while (!(buf[0] == '.' && buf[1] == '\r')) { \
+               if (sock_gets(SESSION(session)->sock, buf, sizeof(buf)) < 0) { \
+                       log_warning(_("error occurred while getting %s.\n"), hdr); \
+                       return msginfo; \
+               } \
+       }
 
-GSList * news_get_group_list(FolderItem *item)
+MsgInfo *news_get_msginfo(Folder *folder, FolderItem *item, gint num)
 {
-       gchar *path, *filename;
-       gint ok;
        NNTPSession *session;
-       GSList * group_list = NULL;
-       FILE * f;
+       MsgInfo *msginfo = NULL;
        gchar buf[NNTPBUFSIZE];
-       int len;
 
-       if (item == NULL)
-         return NULL;
+       session = news_session_get(folder);
+       g_return_val_if_fail(session != NULL, NULL);
+       g_return_val_if_fail(item != NULL, NULL);
+       g_return_val_if_fail(item->folder != NULL, NULL);
+       g_return_val_if_fail(FOLDER_CLASS(item->folder) == &news_class, NULL);
 
-       path = folder_item_get_path(item);
+       log_message(_("getting xover %d in %s...\n"),
+                   num, item->path);
+       if (nntp_xover(session->nntp_sock, num, num) != NN_SUCCESS) {
+               log_warning(_("can't get xover\n"));
+               return NULL;
+       }
+       
+       if (sock_gets(SESSION(session)->sock, buf, sizeof(buf)) < 0) {
+               log_warning(_("error occurred while getting xover.\n"));
+               return NULL;
+       }
+       
+       msginfo = news_parse_xover(buf);
+       if (!msginfo) {
+               log_warning(_("invalid xover line: %s\n"), buf);
+       }
 
-       if (!is_dir_exist(path))
-               make_dir_hier(path);
+       READ_TO_LISTEND("xover");
 
-       filename = g_strconcat(path, G_DIR_SEPARATOR_S, GROUPLIST_FILE, NULL);
-       g_free(path);
+       if(!msginfo)
+               return NULL;
+       
+       msginfo->folder = item;
+       msginfo->flags.perm_flags = MSG_NEW|MSG_UNREAD;
+       msginfo->flags.tmp_flags = MSG_NEWS;
+       msginfo->newsgroups = g_strdup(item->path);
 
-       session = news_session_get(item->folder);
+       if (nntp_xhdr(session->nntp_sock, "to", num, num) != NN_SUCCESS) {
+               log_warning(_("can't get xhdr\n"));
+               return msginfo;
+       }
 
-       if (session == NULL)
-         return NULL;
+       if (sock_gets(SESSION(session)->sock, buf, sizeof(buf)) < 0) {
+               log_warning(_("error occurred while getting xhdr.\n"));
+               return msginfo;
+       }
 
-       if (is_file_exist(filename)) {
-               debug_print(_("group list has been already cached.\n"));
+       msginfo->to = news_parse_xhdr(buf, msginfo);
+
+       READ_TO_LISTEND("xhdr (to)");
+
+       if (nntp_xhdr(session->nntp_sock, "cc", num, num) != NN_SUCCESS) {
+               log_warning(_("can't get xhdr\n"));
+               return msginfo;
        }
-       else {
-           ok = nntp_list(session->nntp_sock);
-           if (ok != NN_SUCCESS)
-             return NULL;
-           
-           if (recv_write_to_file(SESSION(session)->sock, filename) < 0) {
-             log_warning(_("can't retrieve group list\n"));
-             return NULL;
-           }
+
+       if (sock_gets(SESSION(session)->sock, buf, sizeof(buf)) < 0) {
+               log_warning(_("error occurred while getting xhdr.\n"));
+               return msginfo;
        }
 
-       f = fopen(filename, "r");
-       while (fgets(buf, NNTPBUFSIZE, f)) {
-           char * s;
+       msginfo->cc = news_parse_xhdr(buf, msginfo);
+
+       READ_TO_LISTEND("xhdr (cc)");
+
+       return msginfo;
+}
+
+static GSList *news_get_msginfos_for_range(NNTPSession *session, FolderItem *item, guint begin, guint end)
+{
+       gchar buf[NNTPBUFSIZE];
+       GSList *newlist = NULL;
+       GSList *llast = NULL;
+       MsgInfo *msginfo;
+       guint count = 0, lines = (end - begin + 2) * 3;
 
-           len = 0;
-           while ((buf[len] != 0) && (buf[len] != ' '))
-             len++;
-           buf[len] = 0;
-           s = g_strdup(buf);
+       g_return_val_if_fail(session != NULL, NULL);
+       g_return_val_if_fail(item != NULL, NULL);
 
-           group_list = g_slist_append(group_list, s);
+       log_message(_("getting xover %d - %d in %s...\n"),
+                   begin, end, item->path);
+       if (nntp_xover(session->nntp_sock, begin, end) != NN_SUCCESS) {
+               log_warning(_("can't get xover\n"));
+               return NULL;
        }
-       fclose(f);
-       g_free(filename);
 
-       group_list = g_slist_sort(group_list, (GCompareFunc) g_strcasecmp);
+       for (;;) {
+               if (sock_gets(SESSION(session)->sock, buf, sizeof(buf)) < 0) {
+                       log_warning(_("error occurred while getting xover.\n"));
+                       return newlist;
+               }
+               count++;
+               progressindicator_set_percentage
+                       (PROGRESS_TYPE_NETWORK,
+                        session->fetch_base_percentage +
+                        (((gfloat) count) / ((gfloat) lines)) * session->fetch_total_percentage);
+
+               if (buf[0] == '.' && buf[1] == '\r') break;
 
-       return group_list;
+               msginfo = news_parse_xover(buf);
+               if (!msginfo) {
+                       log_warning(_("invalid xover line: %s\n"), buf);
+                       continue;
+               }
+
+               msginfo->folder = item;
+               msginfo->flags.perm_flags = MSG_NEW|MSG_UNREAD;
+               msginfo->flags.tmp_flags = MSG_NEWS;
+               msginfo->newsgroups = g_strdup(item->path);
+
+               if (!newlist)
+                       llast = newlist = g_slist_append(newlist, msginfo);
+               else {
+                       llast = g_slist_append(llast, msginfo);
+                       llast = llast->next;
+               }
+       }
+
+       if (nntp_xhdr(session->nntp_sock, "to", begin, end) != NN_SUCCESS) {
+               log_warning(_("can't get xhdr\n"));
+               return newlist;
+       }
+
+       llast = newlist;
+
+       for (;;) {
+               if (sock_gets(SESSION(session)->sock, buf, sizeof(buf)) < 0) {
+                       log_warning(_("error occurred while getting xhdr.\n"));
+                       return newlist;
+               }
+               count++;
+               progressindicator_set_percentage
+                       (PROGRESS_TYPE_NETWORK,
+                        session->fetch_base_percentage +
+                        (((gfloat) count) / ((gfloat) lines)) * session->fetch_total_percentage);
+
+               if (buf[0] == '.' && buf[1] == '\r') break;
+               if (!llast) {
+                       g_warning("llast == NULL\n");
+                       continue;
+               }
+
+               msginfo = (MsgInfo *)llast->data;
+               msginfo->to = news_parse_xhdr(buf, msginfo);
+
+               llast = llast->next;
+       }
+
+       if (nntp_xhdr(session->nntp_sock, "cc", begin, end) != NN_SUCCESS) {
+               log_warning(_("can't get xhdr\n"));
+               return newlist;
+       }
+
+       llast = newlist;
+
+       for (;;) {
+               if (sock_gets(SESSION(session)->sock, buf, sizeof(buf)) < 0) {
+                       log_warning(_("error occurred while getting xhdr.\n"));
+                       return newlist;
+               }
+               count++;
+               progressindicator_set_percentage
+                       (PROGRESS_TYPE_NETWORK,
+                        session->fetch_base_percentage +
+                        (((gfloat) count) / ((gfloat) lines)) * session->fetch_total_percentage);
+
+               if (buf[0] == '.' && buf[1] == '\r') break;
+               if (!llast) {
+                       g_warning("llast == NULL\n");
+                       continue;
+               }
+
+               msginfo = (MsgInfo *)llast->data;
+               msginfo->cc = news_parse_xhdr(buf, msginfo);
+
+               llast = llast->next;
+       }
+
+       return newlist;
 }
 
-/*
-  remove the cache file of the names of the newsgroups.
- */
+gint news_fetch_msgnum_sort(gconstpointer a, gconstpointer b)
+{
+       return (GPOINTER_TO_INT(a) - GPOINTER_TO_INT(b));
+}
 
-void news_reset_group_list(FolderItem *item)
+GSList *news_get_msginfos(Folder *folder, FolderItem *item, GSList *msgnum_list)
 {
-       gchar *path, *filename;
+       NNTPSession *session;
+       GSList *elem, *msginfo_list = NULL, *tmp_msgnum_list, *tmp_msginfo_list;
+       guint first, last, next;
+       guint tofetch, fetched;
+       
+       g_return_val_if_fail(folder != NULL, NULL);
+       g_return_val_if_fail(FOLDER_CLASS(folder) == &news_class, NULL);
+       g_return_val_if_fail(msgnum_list != NULL, NULL);
+       g_return_val_if_fail(item != NULL, NULL);
+       
+       session = news_session_get(folder);
+       g_return_val_if_fail(session != NULL, NULL);
 
-       debug_print(_("\tDeleting cached group list... "));
-       path = folder_item_get_path(item);
-       filename = g_strconcat(path, G_DIR_SEPARATOR_S, GROUPLIST_FILE, NULL);
-       g_free(path);
-       if (remove(filename) != 0)
-         log_warning(_("can't delete cached group list %s\n"), filename);
-       g_free(filename);
+       tmp_msgnum_list = g_slist_copy(msgnum_list);
+       tmp_msgnum_list = g_slist_sort(tmp_msgnum_list, news_fetch_msgnum_sort);
+
+       progressindicator_start(PROGRESS_TYPE_NETWORK);
+       tofetch = g_slist_length(tmp_msgnum_list);
+       fetched = 0;
+
+       first = GPOINTER_TO_INT(tmp_msgnum_list->data);
+       last = first;
+       for(elem = g_slist_next(tmp_msgnum_list); elem != NULL; elem = g_slist_next(elem)) {
+               next = GPOINTER_TO_INT(elem->data);
+               if(next != (last + 1)) {
+                       session->fetch_base_percentage = ((gfloat) fetched) / ((gfloat) tofetch);
+                       session->fetch_total_percentage = ((gfloat) (last - first + 1)) / ((gfloat) tofetch);
+                       tmp_msginfo_list = news_get_msginfos_for_range(session, item, first, last);
+                       msginfo_list = g_slist_concat(msginfo_list, tmp_msginfo_list);
+                       fetched = last - first + 1;
+                       first = next;
+               }
+               last = next;
+       }
+       session->fetch_base_percentage = ((gfloat) fetched) / ((gfloat) tofetch);
+       session->fetch_total_percentage = ((gfloat) (last - first + 1)) / ((gfloat) tofetch);
+       tmp_msginfo_list = news_get_msginfos_for_range(session, item, first, last);
+       msginfo_list = g_slist_concat(msginfo_list, tmp_msginfo_list);
+
+       g_slist_free(tmp_msgnum_list);
+       
+       progressindicator_stop(PROGRESS_TYPE_NETWORK);
+
+       return msginfo_list;
 }