2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2002 Hiroyuki Yamamoto
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.
40 #include "procheader.h"
43 #include "statusbar.h"
46 #include "prefs_common.h"
47 #include "prefs_account.h"
48 #include "inputdialog.h"
50 #include "progressindicator.h"
57 #define NNTPS_PORT 563
60 static void news_folder_init (Folder *folder,
65 static Session *news_session_new (const gchar *server,
71 static Session *news_session_new (const gchar *server,
77 static gint news_get_article_cmd (NNTPSession *session,
81 static gint news_get_article (NNTPSession *session,
85 static gint news_select_group (NNTPSession *session,
90 static MsgInfo *news_parse_xover (const gchar *xover_str);
91 static gchar *news_parse_xhdr (const gchar *xhdr_str,
93 static gint news_remove_msg (Folder *folder,
96 gint news_get_num_list (Folder *folder,
99 MsgInfo *news_get_msginfo (Folder *folder,
102 GSList *news_get_msginfos (Folder *folder,
104 GSList *msgnum_list);
106 gint news_post_stream (Folder *folder,
109 FolderClass news_class =
115 /* Folder functions */
121 /* FolderItem functions */
133 /* Message functions */
149 FolderClass *news_get_class()
154 Folder *news_folder_new(const gchar *name, const gchar *path)
158 folder = (Folder *)g_new0(NewsFolder, 1);
159 folder->class = &news_class;
160 news_folder_init(folder, name, path);
165 void news_folder_destroy(Folder *folder)
169 dir = folder_get_path(folder);
170 if (is_dir_exist(dir))
171 remove_dir_recursive(dir);
174 folder_remote_folder_destroy(REMOTE_FOLDER(folder));
177 static void news_folder_init(Folder *folder, const gchar *name,
180 folder_remote_folder_init(folder, name, path);
184 static Session *news_session_new(const gchar *server, gushort port,
185 const gchar *userid, const gchar *passwd,
188 static Session *news_session_new(const gchar *server, gushort port,
189 const gchar *userid, const gchar *passwd)
192 gchar buf[NNTPBUFSIZE];
193 NNTPSession *session;
194 NNTPSockInfo *nntp_sock;
196 g_return_val_if_fail(server != NULL, NULL);
198 log_message(_("creating NNTP connection to %s:%d ...\n"), server, port);
201 if (userid && passwd)
202 nntp_sock = nntp_open_auth(server, port, buf, userid, passwd,
205 nntp_sock = nntp_open(server, port, buf, ssl_type);
207 if (userid && passwd)
208 nntp_sock = nntp_open_auth(server, port, buf, userid, passwd);
210 nntp_sock = nntp_open(server, port, buf);
213 if (nntp_sock == NULL)
216 session = g_new(NNTPSession, 1);
217 SESSION(session)->type = SESSION_NEWS;
218 SESSION(session)->server = g_strdup(server);
219 session->nntp_sock = nntp_sock;
220 SESSION(session)->sock = nntp_sock->sock;
221 SESSION(session)->connected = TRUE;
222 SESSION(session)->phase = SESSION_READY;
223 SESSION(session)->last_access_time = time(NULL);
224 SESSION(session)->data = NULL;
226 SESSION(session)->destroy = news_session_destroy;
228 session->group = NULL;
230 return SESSION(session);
233 void news_session_destroy(Session *session)
235 nntp_close(NNTP_SESSION(session)->nntp_sock);
236 NNTP_SESSION(session)->nntp_sock = NULL;
237 session->sock = NULL;
239 g_free(NNTP_SESSION(session)->group);
242 static Session *news_session_new_for_folder(Folder *folder)
246 const gchar *userid = NULL;
247 gchar *passwd = NULL;
249 gchar buf[NNTPBUFSIZE];
251 g_return_val_if_fail(folder != NULL, NULL);
252 g_return_val_if_fail(folder->account != NULL, NULL);
254 ac = folder->account;
255 if (ac->use_nntp_auth && ac->userid && ac->userid[0]) {
257 if (ac->passwd && ac->passwd[0])
258 passwd = g_strdup(ac->passwd);
260 passwd = input_dialog_query_password(ac->nntp_server,
265 port = ac->set_nntpport ? ac->nntpport
266 : ac->ssl_nntp ? NNTPS_PORT : NNTP_PORT;
267 session = news_session_new(ac->nntp_server, port, userid, passwd,
270 port = ac->set_nntpport ? ac->nntpport : NNTP_PORT;
271 session = news_session_new(ac->nntp_server, port, userid, passwd);
273 if ((session != NULL) && ac->use_nntp_auth && ac->use_nntp_auth_onconnect)
274 nntp_forceauth(NNTP_SESSION(session)->nntp_sock, buf, userid, passwd);
281 NNTPSession *news_session_get(Folder *folder)
283 RemoteFolder *rfolder = REMOTE_FOLDER(folder);
285 g_return_val_if_fail(folder != NULL, NULL);
286 g_return_val_if_fail(FOLDER_CLASS(folder) == &news_class, NULL);
287 g_return_val_if_fail(folder->account != NULL, NULL);
289 if (!rfolder->session) {
290 rfolder->session = news_session_new_for_folder(folder);
291 return NNTP_SESSION(rfolder->session);
294 if (time(NULL) - rfolder->session->last_access_time < SESSION_TIMEOUT) {
295 rfolder->session->last_access_time = time(NULL);
296 return NNTP_SESSION(rfolder->session);
299 if (nntp_mode(NNTP_SESSION(rfolder->session)->nntp_sock, FALSE)
301 log_warning("NNTP connection to %s:%d has been"
302 " disconnected. Reconnecting...\n",
303 folder->account->nntp_server,
304 folder->account->set_nntpport ?
305 folder->account->nntpport : NNTP_PORT);
306 session_destroy(rfolder->session);
307 rfolder->session = news_session_new_for_folder(folder);
310 if (rfolder->session)
311 rfolder->session->last_access_time = time(NULL);
312 return NNTP_SESSION(rfolder->session);
315 gchar *news_fetch_msg(Folder *folder, FolderItem *item, gint num)
317 gchar *path, *filename;
318 NNTPSession *session;
321 g_return_val_if_fail(folder != NULL, NULL);
322 g_return_val_if_fail(item != NULL, NULL);
324 path = folder_item_get_path(item);
325 if (!is_dir_exist(path))
327 filename = g_strconcat(path, G_DIR_SEPARATOR_S, itos(num), NULL);
330 if (is_file_exist(filename)) {
331 debug_print("article %d has been already cached.\n", num);
335 session = news_session_get(folder);
341 ok = news_select_group(session, item->path, NULL, NULL, NULL);
342 if (ok != NN_SUCCESS) {
343 g_warning("can't select group %s\n", item->path);
348 debug_print("getting article %d...\n", num);
349 ok = news_get_article(NNTP_SESSION(REMOTE_FOLDER(folder)->session),
352 g_warning("can't read article %d\n", num);
353 session_destroy(SESSION(session));
354 REMOTE_FOLDER(folder)->session = NULL;
362 gint news_scan_group(Folder *folder, FolderItem *item)
364 NNTPSession *session;
365 gint num = 0, first = 0, last = 0;
368 g_return_val_if_fail(folder != NULL, -1);
369 g_return_val_if_fail(item != NULL, -1);
371 session = news_session_get(folder);
372 if (!session) return -1;
374 ok = news_select_group(session, item->path, &num, &first, &last);
375 if (ok != NN_SUCCESS) {
376 log_warning("can't set group: %s\n", item->path);
381 item->new = item->unread = item->total = item->last_num = 0;
386 path = folder_item_get_path(item);
387 if (path && is_dir_exist(path)) {
388 procmsg_get_mark_sum(path, &new, &unread, &total, &min, &max,
393 if (max < first || last < min)
394 new = unread = total = num;
401 else if (max < last) {
403 unread += last - max;
406 if (new > num) new = num;
407 if (unread > num) unread = num;
411 item->unread = unread;
413 item->last_num = last;
418 static NewsGroupInfo *news_group_info_new(const gchar *name,
419 gint first, gint last, gchar type)
421 NewsGroupInfo *ginfo;
423 ginfo = g_new(NewsGroupInfo, 1);
424 ginfo->name = g_strdup(name);
425 ginfo->first = first;
432 static void news_group_info_free(NewsGroupInfo *ginfo)
438 static gint news_group_info_compare(NewsGroupInfo *ginfo1,
439 NewsGroupInfo *ginfo2)
441 return g_strcasecmp(ginfo1->name, ginfo2->name);
444 GSList *news_get_group_list(Folder *folder)
446 gchar *path, *filename;
450 gchar buf[NNTPBUFSIZE];
452 g_return_val_if_fail(folder != NULL, NULL);
453 g_return_val_if_fail(FOLDER_CLASS(folder) == &news_class, NULL);
455 path = folder_item_get_path(FOLDER_ITEM(folder->node->data));
456 if (!is_dir_exist(path))
458 filename = g_strconcat(path, G_DIR_SEPARATOR_S, NEWSGROUP_LIST, NULL);
461 if ((fp = fopen(filename, "rb")) == NULL) {
462 NNTPSession *session;
464 session = news_session_get(folder);
470 if (nntp_list(session->nntp_sock) != NN_SUCCESS) {
474 if (recv_write_to_file(SESSION(session)->sock, filename) < 0) {
475 log_warning("can't retrieve newsgroup list\n");
476 session_destroy(SESSION(session));
477 REMOTE_FOLDER(folder)->session = NULL;
482 if ((fp = fopen(filename, "rb")) == NULL) {
483 FILE_OP_ERROR(filename, "fopen");
489 while (fgets(buf, sizeof(buf), fp) != NULL) {
495 NewsGroupInfo *ginfo;
503 if (sscanf(p, "%d %d %c", &last_num, &first_num, &type) < 3)
506 ginfo = news_group_info_new(name, first_num, last_num, type);
509 last = list = g_slist_append(NULL, ginfo);
511 last = g_slist_append(last, ginfo);
519 list = g_slist_sort(list, (GCompareFunc)news_group_info_compare);
524 void news_group_list_free(GSList *group_list)
528 if (!group_list) return;
530 for (cur = group_list; cur != NULL; cur = cur->next)
531 news_group_info_free((NewsGroupInfo *)cur->data);
532 g_slist_free(group_list);
535 void news_remove_group_list_cache(Folder *folder)
537 gchar *path, *filename;
539 g_return_if_fail(folder != NULL);
540 g_return_if_fail(FOLDER_CLASS(folder) == &news_class);
542 path = folder_item_get_path(FOLDER_ITEM(folder->node->data));
543 filename = g_strconcat(path, G_DIR_SEPARATOR_S, NEWSGROUP_LIST, NULL);
546 if (is_file_exist(filename)) {
547 if (remove(filename) < 0)
548 FILE_OP_ERROR(filename, "remove");
553 gint news_post(Folder *folder, const gchar *file)
558 g_return_val_if_fail(folder != NULL, -1);
559 g_return_val_if_fail(FOLDER_CLASS(folder) == &news_class, -1);
560 g_return_val_if_fail(file != NULL, -1);
562 if ((fp = fopen(file, "rb")) == NULL) {
563 FILE_OP_ERROR(file, "fopen");
567 ok = news_post_stream(folder, fp);
574 gint news_post_stream(Folder *folder, FILE *fp)
576 NNTPSession *session;
579 g_return_val_if_fail(folder != NULL, -1);
580 g_return_val_if_fail(FOLDER_CLASS(folder) == &news_class, -1);
581 g_return_val_if_fail(fp != NULL, -1);
583 session = news_session_get(folder);
584 if (!session) return -1;
586 ok = nntp_post(session->nntp_sock, fp);
587 if (ok != NN_SUCCESS) {
588 log_warning("can't post article.\n");
595 static gint news_get_article_cmd(NNTPSession *session, const gchar *cmd,
596 gint num, gchar *filename)
600 if (nntp_get_article(session->nntp_sock, cmd, num, &msgid)
604 debug_print("Message-Id = %s, num = %d\n", msgid, num);
607 if (recv_write_to_file(session->nntp_sock->sock, filename) < 0) {
608 log_warning("can't retrieve article %d\n", num);
615 static gint news_remove_msg(Folder *folder, FolderItem *item, gint num)
620 dir = folder_item_get_path(item);
621 debug_print("news_remove_msg: removing msg %d in %s\n",num,dir);
622 r = remove_numbered_files(dir, num, num);
628 static gint news_get_article(NNTPSession *session, gint num, gchar *filename)
630 return news_get_article_cmd(session, "ARTICLE", num, filename);
635 * @session: Active NNTP session.
636 * @group: Newsgroup name.
637 * @num: Estimated number of articles.
638 * @first: First article number.
639 * @last: Last article number.
641 * Select newsgroup @group with the GROUP command if it is not already
642 * selected in @session, or article numbers need to be returned.
644 * Return value: NNTP result code.
646 static gint news_select_group(NNTPSession *session, const gchar *group,
647 gint *num, gint *first, gint *last)
650 gint num_, first_, last_;
652 if (!num || !first || !last) {
653 if (session->group && g_strcasecmp(session->group, group) == 0)
660 g_free(session->group);
661 session->group = NULL;
663 ok = nntp_group(session->nntp_sock, group, num, first, last);
664 if (ok == NN_SUCCESS)
665 session->group = g_strdup(group);
670 #define PARSE_ONE_PARAM(p, srcp) \
672 p = strchr(srcp, '\t'); \
673 if (!p) return NULL; \
678 static MsgInfo *news_parse_xover(const gchar *xover_str)
681 gchar buf[NNTPBUFSIZE];
682 gchar *subject, *sender, *size, *line, *date, *msgid, *ref, *tmp, *xref;
684 gint num, size_int, line_int;
687 Xstrdup_a(xover_buf, xover_str, return NULL);
689 PARSE_ONE_PARAM(subject, xover_buf);
690 PARSE_ONE_PARAM(sender, subject);
691 PARSE_ONE_PARAM(date, sender);
692 PARSE_ONE_PARAM(msgid, date);
693 PARSE_ONE_PARAM(ref, msgid);
694 PARSE_ONE_PARAM(size, ref);
695 PARSE_ONE_PARAM(line, size);
696 PARSE_ONE_PARAM(xref, line);
698 tmp = strchr(xref, '\t');
699 if (!tmp) tmp = strchr(line, '\r');
700 if (!tmp) tmp = strchr(line, '\n');
701 if (tmp) *tmp = '\0';
703 num = atoi(xover_str);
704 size_int = atoi(size);
705 line_int = atoi(line);
708 msginfo = procmsg_msginfo_new();
709 msginfo->msgnum = num;
710 msginfo->size = size_int;
712 msginfo->date = g_strdup(date);
713 msginfo->date_t = procheader_date_parse(NULL, date, 0);
715 conv_unmime_header(buf, sizeof(buf), sender, NULL);
716 msginfo->from = g_strdup(buf);
717 msginfo->fromname = procheader_get_fromname(buf);
719 conv_unmime_header(buf, sizeof(buf), subject, NULL);
720 msginfo->subject = g_strdup(buf);
722 extract_parenthesis(msgid, '<', '>');
725 msginfo->msgid = g_strdup(msgid);
727 msginfo->references = g_strdup(ref);
728 eliminate_parenthesis(ref, '(', ')');
729 if ((p = strrchr(ref, '<')) != NULL) {
730 extract_parenthesis(p, '<', '>');
733 msginfo->inreplyto = g_strdup(p);
736 msginfo->xref = g_strdup(xref);
737 p = msginfo->xref+strlen(msginfo->xref) - 1;
738 while (*p == '\r' || *p == '\n') {
746 static gchar *news_parse_xhdr(const gchar *xhdr_str, MsgInfo *msginfo)
752 p = strchr(xhdr_str, ' ');
758 num = atoi(xhdr_str);
759 if (msginfo->msgnum != num) return NULL;
761 tmp = strchr(p, '\r');
762 if (!tmp) tmp = strchr(p, '\n');
765 return g_strndup(p, tmp - p);
770 gint news_cancel_article(Folder * folder, MsgInfo * msginfo)
776 tmp = g_strdup_printf("%s%ctmp%d", g_get_tmp_dir(),
777 G_DIR_SEPARATOR, (gint)msginfo);
781 if ((tmpfp = fopen(tmp, "wb")) == NULL) {
782 FILE_OP_ERROR(tmp, "fopen");
785 if (change_file_mode_rw(tmpfp, tmp) < 0) {
786 FILE_OP_ERROR(tmp, "chmod");
787 g_warning("can't change file mode\n");
790 fprintf(tmpfp, "From: %s\r\n", msginfo->from);
791 fprintf(tmpfp, "Newsgroups: %s\r\n", msginfo->newsgroups);
792 fprintf(tmpfp, "Subject: cmsg cancel <%s>\r\n", msginfo->msgid);
793 fprintf(tmpfp, "Control: cancel <%s>\r\n", msginfo->msgid);
794 fprintf(tmpfp, "Approved: %s\r\n", msginfo->from);
795 fprintf(tmpfp, "X-Cancelled-by: %s\r\n", msginfo->from);
796 get_rfc822_date(buf, sizeof(buf));
797 fprintf(tmpfp, "Date: %s\r\n", buf);
798 fprintf(tmpfp, "\r\n");
799 fprintf(tmpfp, "removed with sylpheed\r\n");
803 news_post(folder, tmp);
811 gint news_get_num_list(Folder *folder, FolderItem *item, GSList **msgnum_list)
813 NNTPSession *session;
814 gint i, ok, num, first, last, nummsgs = 0;
817 g_return_val_if_fail(item != NULL, -1);
818 g_return_val_if_fail(item->folder != NULL, -1);
819 g_return_val_if_fail(FOLDER_CLASS(folder) == &news_class, -1);
821 session = news_session_get(folder);
822 g_return_val_if_fail(session != NULL, -1);
824 ok = news_select_group(session, item->path, &num, &first, &last);
825 if (ok != NN_SUCCESS) {
826 log_warning(_("can't set group: %s\n"), item->path);
831 log_warning(_("invalid article range: %d - %d\n"),
836 for(i = first; i <= last; i++) {
837 *msgnum_list = g_slist_prepend(*msgnum_list, GINT_TO_POINTER(i));
841 dir = folder_item_get_path(item);
842 debug_print("removing old messages from %d to %d in %s\n", first, last, dir);
843 remove_numbered_files(dir, 1, first - 1);
849 #define READ_TO_LISTEND(hdr) \
850 while (!(buf[0] == '.' && buf[1] == '\r')) { \
851 if (sock_gets(SESSION(session)->sock, buf, sizeof(buf)) < 0) { \
852 log_warning(_("error occurred while getting %s.\n"), hdr); \
857 MsgInfo *news_get_msginfo(Folder *folder, FolderItem *item, gint num)
859 NNTPSession *session;
860 MsgInfo *msginfo = NULL;
861 gchar buf[NNTPBUFSIZE];
863 session = news_session_get(folder);
864 g_return_val_if_fail(session != NULL, NULL);
865 g_return_val_if_fail(item != NULL, NULL);
866 g_return_val_if_fail(item->folder != NULL, NULL);
867 g_return_val_if_fail(FOLDER_CLASS(item->folder) == &news_class, NULL);
869 log_message(_("getting xover %d in %s...\n"),
871 if (nntp_xover(session->nntp_sock, num, num) != NN_SUCCESS) {
872 log_warning(_("can't get xover\n"));
876 if (sock_gets(SESSION(session)->sock, buf, sizeof(buf)) < 0) {
877 log_warning(_("error occurred while getting xover.\n"));
881 msginfo = news_parse_xover(buf);
883 log_warning(_("invalid xover line: %s\n"), buf);
886 READ_TO_LISTEND("xover");
891 msginfo->folder = item;
892 msginfo->flags.perm_flags = MSG_NEW|MSG_UNREAD;
893 msginfo->flags.tmp_flags = MSG_NEWS;
894 msginfo->newsgroups = g_strdup(item->path);
896 if (nntp_xhdr(session->nntp_sock, "to", num, num) != NN_SUCCESS) {
897 log_warning(_("can't get xhdr\n"));
901 if (sock_gets(SESSION(session)->sock, buf, sizeof(buf)) < 0) {
902 log_warning(_("error occurred while getting xhdr.\n"));
906 msginfo->to = news_parse_xhdr(buf, msginfo);
908 READ_TO_LISTEND("xhdr (to)");
910 if (nntp_xhdr(session->nntp_sock, "cc", num, num) != NN_SUCCESS) {
911 log_warning(_("can't get xhdr\n"));
915 if (sock_gets(SESSION(session)->sock, buf, sizeof(buf)) < 0) {
916 log_warning(_("error occurred while getting xhdr.\n"));
920 msginfo->cc = news_parse_xhdr(buf, msginfo);
922 READ_TO_LISTEND("xhdr (cc)");
927 static GSList *news_get_msginfos_for_range(NNTPSession *session, FolderItem *item, guint begin, guint end)
929 gchar buf[NNTPBUFSIZE];
930 GSList *newlist = NULL;
931 GSList *llast = NULL;
933 guint count = 0, lines = (end - begin + 2) * 3;
935 g_return_val_if_fail(session != NULL, NULL);
936 g_return_val_if_fail(item != NULL, NULL);
938 log_message(_("getting xover %d - %d in %s...\n"),
939 begin, end, item->path);
940 if (nntp_xover(session->nntp_sock, begin, end) != NN_SUCCESS) {
941 log_warning(_("can't get xover\n"));
946 if (sock_gets(SESSION(session)->sock, buf, sizeof(buf)) < 0) {
947 log_warning(_("error occurred while getting xover.\n"));
951 progressindicator_set_percentage
952 (PROGRESS_TYPE_NETWORK,
953 session->fetch_base_percentage +
954 (((gfloat) count) / ((gfloat) lines)) * session->fetch_total_percentage);
956 if (buf[0] == '.' && buf[1] == '\r') break;
958 msginfo = news_parse_xover(buf);
960 log_warning(_("invalid xover line: %s\n"), buf);
964 msginfo->folder = item;
965 msginfo->flags.perm_flags = MSG_NEW|MSG_UNREAD;
966 msginfo->flags.tmp_flags = MSG_NEWS;
967 msginfo->newsgroups = g_strdup(item->path);
970 llast = newlist = g_slist_append(newlist, msginfo);
972 llast = g_slist_append(llast, msginfo);
977 if (nntp_xhdr(session->nntp_sock, "to", begin, end) != NN_SUCCESS) {
978 log_warning(_("can't get xhdr\n"));
985 if (sock_gets(SESSION(session)->sock, buf, sizeof(buf)) < 0) {
986 log_warning(_("error occurred while getting xhdr.\n"));
990 progressindicator_set_percentage
991 (PROGRESS_TYPE_NETWORK,
992 session->fetch_base_percentage +
993 (((gfloat) count) / ((gfloat) lines)) * session->fetch_total_percentage);
995 if (buf[0] == '.' && buf[1] == '\r') break;
997 g_warning("llast == NULL\n");
1001 msginfo = (MsgInfo *)llast->data;
1002 msginfo->to = news_parse_xhdr(buf, msginfo);
1004 llast = llast->next;
1007 if (nntp_xhdr(session->nntp_sock, "cc", begin, end) != NN_SUCCESS) {
1008 log_warning(_("can't get xhdr\n"));
1015 if (sock_gets(SESSION(session)->sock, buf, sizeof(buf)) < 0) {
1016 log_warning(_("error occurred while getting xhdr.\n"));
1020 progressindicator_set_percentage
1021 (PROGRESS_TYPE_NETWORK,
1022 session->fetch_base_percentage +
1023 (((gfloat) count) / ((gfloat) lines)) * session->fetch_total_percentage);
1025 if (buf[0] == '.' && buf[1] == '\r') break;
1027 g_warning("llast == NULL\n");
1031 msginfo = (MsgInfo *)llast->data;
1032 msginfo->cc = news_parse_xhdr(buf, msginfo);
1034 llast = llast->next;
1040 gint news_fetch_msgnum_sort(gconstpointer a, gconstpointer b)
1042 return (GPOINTER_TO_INT(a) - GPOINTER_TO_INT(b));
1045 GSList *news_get_msginfos(Folder *folder, FolderItem *item, GSList *msgnum_list)
1047 NNTPSession *session;
1048 GSList *elem, *msginfo_list = NULL, *tmp_msgnum_list, *tmp_msginfo_list;
1049 guint first, last, next;
1050 guint tofetch, fetched;
1052 g_return_val_if_fail(folder != NULL, NULL);
1053 g_return_val_if_fail(FOLDER_CLASS(folder) == &news_class, NULL);
1054 g_return_val_if_fail(msgnum_list != NULL, NULL);
1055 g_return_val_if_fail(item != NULL, NULL);
1057 session = news_session_get(folder);
1058 g_return_val_if_fail(session != NULL, NULL);
1060 tmp_msgnum_list = g_slist_copy(msgnum_list);
1061 tmp_msgnum_list = g_slist_sort(tmp_msgnum_list, news_fetch_msgnum_sort);
1063 progressindicator_start(PROGRESS_TYPE_NETWORK);
1064 tofetch = g_slist_length(tmp_msgnum_list);
1067 first = GPOINTER_TO_INT(tmp_msgnum_list->data);
1069 for(elem = g_slist_next(tmp_msgnum_list); elem != NULL; elem = g_slist_next(elem)) {
1070 next = GPOINTER_TO_INT(elem->data);
1071 if(next != (last + 1)) {
1072 session->fetch_base_percentage = ((gfloat) fetched) / ((gfloat) tofetch);
1073 session->fetch_total_percentage = ((gfloat) (last - first + 1)) / ((gfloat) tofetch);
1074 tmp_msginfo_list = news_get_msginfos_for_range(session, item, first, last);
1075 msginfo_list = g_slist_concat(msginfo_list, tmp_msginfo_list);
1076 fetched = last - first + 1;
1081 session->fetch_base_percentage = ((gfloat) fetched) / ((gfloat) tofetch);
1082 session->fetch_total_percentage = ((gfloat) (last - first + 1)) / ((gfloat) tofetch);
1083 tmp_msginfo_list = news_get_msginfos_for_range(session, item, first, last);
1084 msginfo_list = g_slist_concat(msginfo_list, tmp_msginfo_list);
1086 g_slist_free(tmp_msgnum_list);
1088 progressindicator_stop(PROGRESS_TYPE_NETWORK);
1090 return msginfo_list;