2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2003 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_new0(NNTPSession, 1);
217 session_init(SESSION(session));
218 SESSION(session)->type = SESSION_NEWS;
219 SESSION(session)->server = g_strdup(server);
220 SESSION(session)->sock = NULL;
221 SESSION(session)->data = NULL;
223 SESSION(session)->destroy = news_session_destroy;
225 session->nntp_sock = nntp_sock;
226 session->group = NULL;
228 return SESSION(session);
231 void news_session_destroy(Session *session)
233 nntp_close(NNTP_SESSION(session)->nntp_sock);
234 NNTP_SESSION(session)->nntp_sock = NULL;
236 g_free(NNTP_SESSION(session)->group);
239 static Session *news_session_new_for_folder(Folder *folder)
243 const gchar *userid = NULL;
244 gchar *passwd = NULL;
246 gchar buf[NNTPBUFSIZE];
248 g_return_val_if_fail(folder != NULL, NULL);
249 g_return_val_if_fail(folder->account != NULL, NULL);
251 ac = folder->account;
252 if (ac->use_nntp_auth && ac->userid && ac->userid[0]) {
254 if (ac->passwd && ac->passwd[0])
255 passwd = g_strdup(ac->passwd);
257 passwd = input_dialog_query_password(ac->nntp_server,
262 port = ac->set_nntpport ? ac->nntpport
263 : ac->ssl_nntp ? NNTPS_PORT : NNTP_PORT;
264 session = news_session_new(ac->nntp_server, port, userid, passwd,
267 port = ac->set_nntpport ? ac->nntpport : NNTP_PORT;
268 session = news_session_new(ac->nntp_server, port, userid, passwd);
270 if ((session != NULL) && ac->use_nntp_auth && ac->use_nntp_auth_onconnect)
271 nntp_forceauth(NNTP_SESSION(session)->nntp_sock, buf, userid, passwd);
278 NNTPSession *news_session_get(Folder *folder)
280 RemoteFolder *rfolder = REMOTE_FOLDER(folder);
282 g_return_val_if_fail(folder != NULL, NULL);
283 g_return_val_if_fail(FOLDER_CLASS(folder) == &news_class, NULL);
284 g_return_val_if_fail(folder->account != NULL, NULL);
286 if (!rfolder->session) {
287 rfolder->session = news_session_new_for_folder(folder);
288 return NNTP_SESSION(rfolder->session);
291 if (time(NULL) - rfolder->session->last_access_time < SESSION_TIMEOUT) {
292 rfolder->session->last_access_time = time(NULL);
293 return NNTP_SESSION(rfolder->session);
296 if (nntp_mode(NNTP_SESSION(rfolder->session)->nntp_sock, FALSE)
298 log_warning("NNTP connection to %s:%d has been"
299 " disconnected. Reconnecting...\n",
300 folder->account->nntp_server,
301 folder->account->set_nntpport ?
302 folder->account->nntpport : NNTP_PORT);
303 session_destroy(rfolder->session);
304 rfolder->session = news_session_new_for_folder(folder);
307 if (rfolder->session)
308 rfolder->session->last_access_time = time(NULL);
309 return NNTP_SESSION(rfolder->session);
312 gchar *news_fetch_msg(Folder *folder, FolderItem *item, gint num)
314 gchar *path, *filename;
315 NNTPSession *session;
318 g_return_val_if_fail(folder != NULL, NULL);
319 g_return_val_if_fail(item != NULL, NULL);
321 path = folder_item_get_path(item);
322 if (!is_dir_exist(path))
324 filename = g_strconcat(path, G_DIR_SEPARATOR_S, itos(num), NULL);
327 if (is_file_exist(filename)) {
328 debug_print("article %d has been already cached.\n", num);
332 session = news_session_get(folder);
338 ok = news_select_group(session, item->path, NULL, NULL, NULL);
339 if (ok != NN_SUCCESS) {
340 g_warning("can't select group %s\n", item->path);
345 debug_print("getting article %d...\n", num);
346 ok = news_get_article(NNTP_SESSION(REMOTE_FOLDER(folder)->session),
349 g_warning("can't read article %d\n", num);
350 session_destroy(SESSION(session));
351 REMOTE_FOLDER(folder)->session = NULL;
359 gint news_scan_group(Folder *folder, FolderItem *item)
361 NNTPSession *session;
362 gint num = 0, first = 0, last = 0;
365 g_return_val_if_fail(folder != NULL, -1);
366 g_return_val_if_fail(item != NULL, -1);
368 session = news_session_get(folder);
369 if (!session) return -1;
371 ok = news_select_group(session, item->path, &num, &first, &last);
372 if (ok != NN_SUCCESS) {
373 log_warning("can't set group: %s\n", item->path);
378 item->new = item->unread = item->total = item->last_num = 0;
383 path = folder_item_get_path(item);
384 if (path && is_dir_exist(path)) {
385 procmsg_get_mark_sum(path, &new, &unread, &total, &min, &max,
390 if (max < first || last < min)
391 new = unread = total = num;
398 else if (max < last) {
400 unread += last - max;
403 if (new > num) new = num;
404 if (unread > num) unread = num;
408 item->unread = unread;
410 item->last_num = last;
415 static NewsGroupInfo *news_group_info_new(const gchar *name,
416 gint first, gint last, gchar type)
418 NewsGroupInfo *ginfo;
420 ginfo = g_new(NewsGroupInfo, 1);
421 ginfo->name = g_strdup(name);
422 ginfo->first = first;
429 static void news_group_info_free(NewsGroupInfo *ginfo)
435 static gint news_group_info_compare(NewsGroupInfo *ginfo1,
436 NewsGroupInfo *ginfo2)
438 return g_strcasecmp(ginfo1->name, ginfo2->name);
441 GSList *news_get_group_list(Folder *folder)
443 gchar *path, *filename;
447 gchar buf[NNTPBUFSIZE];
449 g_return_val_if_fail(folder != NULL, NULL);
450 g_return_val_if_fail(FOLDER_CLASS(folder) == &news_class, NULL);
452 path = folder_item_get_path(FOLDER_ITEM(folder->node->data));
453 if (!is_dir_exist(path))
455 filename = g_strconcat(path, G_DIR_SEPARATOR_S, NEWSGROUP_LIST, NULL);
458 if ((fp = fopen(filename, "rb")) == NULL) {
459 NNTPSession *session;
461 session = news_session_get(folder);
467 if (nntp_list(session->nntp_sock) != NN_SUCCESS) {
471 if (recv_write_to_file
472 (session->nntp_sock->sock, filename) < 0) {
473 log_warning("can't retrieve newsgroup list\n");
474 session_destroy(SESSION(session));
475 REMOTE_FOLDER(folder)->session = NULL;
480 if ((fp = fopen(filename, "rb")) == NULL) {
481 FILE_OP_ERROR(filename, "fopen");
487 while (fgets(buf, sizeof(buf), fp) != NULL) {
493 NewsGroupInfo *ginfo;
501 if (sscanf(p, "%d %d %c", &last_num, &first_num, &type) < 3)
504 ginfo = news_group_info_new(name, first_num, last_num, type);
507 last = list = g_slist_append(NULL, ginfo);
509 last = g_slist_append(last, ginfo);
517 list = g_slist_sort(list, (GCompareFunc)news_group_info_compare);
522 void news_group_list_free(GSList *group_list)
526 if (!group_list) return;
528 for (cur = group_list; cur != NULL; cur = cur->next)
529 news_group_info_free((NewsGroupInfo *)cur->data);
530 g_slist_free(group_list);
533 void news_remove_group_list_cache(Folder *folder)
535 gchar *path, *filename;
537 g_return_if_fail(folder != NULL);
538 g_return_if_fail(FOLDER_CLASS(folder) == &news_class);
540 path = folder_item_get_path(FOLDER_ITEM(folder->node->data));
541 filename = g_strconcat(path, G_DIR_SEPARATOR_S, NEWSGROUP_LIST, NULL);
544 if (is_file_exist(filename)) {
545 if (remove(filename) < 0)
546 FILE_OP_ERROR(filename, "remove");
551 gint news_post(Folder *folder, const gchar *file)
556 g_return_val_if_fail(folder != NULL, -1);
557 g_return_val_if_fail(FOLDER_CLASS(folder) == &news_class, -1);
558 g_return_val_if_fail(file != NULL, -1);
560 if ((fp = fopen(file, "rb")) == NULL) {
561 FILE_OP_ERROR(file, "fopen");
565 ok = news_post_stream(folder, fp);
572 gint news_post_stream(Folder *folder, FILE *fp)
574 NNTPSession *session;
577 g_return_val_if_fail(folder != NULL, -1);
578 g_return_val_if_fail(FOLDER_CLASS(folder) == &news_class, -1);
579 g_return_val_if_fail(fp != NULL, -1);
581 session = news_session_get(folder);
582 if (!session) return -1;
584 ok = nntp_post(session->nntp_sock, fp);
585 if (ok != NN_SUCCESS) {
586 log_warning("can't post article.\n");
593 static gint news_get_article_cmd(NNTPSession *session, const gchar *cmd,
594 gint num, gchar *filename)
598 if (nntp_get_article(session->nntp_sock, cmd, num, &msgid)
602 debug_print("Message-Id = %s, num = %d\n", msgid, num);
605 if (recv_write_to_file(session->nntp_sock->sock, filename) < 0) {
606 log_warning("can't retrieve article %d\n", num);
613 static gint news_remove_msg(Folder *folder, FolderItem *item, gint num)
618 dir = folder_item_get_path(item);
619 debug_print("news_remove_msg: removing msg %d in %s\n",num,dir);
620 r = remove_numbered_files(dir, num, num);
626 static gint news_get_article(NNTPSession *session, gint num, gchar *filename)
628 return news_get_article_cmd(session, "ARTICLE", num, filename);
633 * @session: Active NNTP session.
634 * @group: Newsgroup name.
635 * @num: Estimated number of articles.
636 * @first: First article number.
637 * @last: Last article number.
639 * Select newsgroup @group with the GROUP command if it is not already
640 * selected in @session, or article numbers need to be returned.
642 * Return value: NNTP result code.
644 static gint news_select_group(NNTPSession *session, const gchar *group,
645 gint *num, gint *first, gint *last)
648 gint num_, first_, last_;
650 if (!num || !first || !last) {
651 if (session->group && g_strcasecmp(session->group, group) == 0)
658 g_free(session->group);
659 session->group = NULL;
661 ok = nntp_group(session->nntp_sock, group, num, first, last);
662 if (ok == NN_SUCCESS)
663 session->group = g_strdup(group);
668 #define PARSE_ONE_PARAM(p, srcp) \
670 p = strchr(srcp, '\t'); \
671 if (!p) return NULL; \
676 static MsgInfo *news_parse_xover(const gchar *xover_str)
679 gchar buf[NNTPBUFSIZE];
680 gchar *subject, *sender, *size, *line, *date, *msgid, *ref, *tmp, *xref;
682 gint num, size_int, line_int;
685 Xstrdup_a(xover_buf, xover_str, return NULL);
687 PARSE_ONE_PARAM(subject, xover_buf);
688 PARSE_ONE_PARAM(sender, subject);
689 PARSE_ONE_PARAM(date, sender);
690 PARSE_ONE_PARAM(msgid, date);
691 PARSE_ONE_PARAM(ref, msgid);
692 PARSE_ONE_PARAM(size, ref);
693 PARSE_ONE_PARAM(line, size);
694 PARSE_ONE_PARAM(xref, line);
696 tmp = strchr(xref, '\t');
697 if (!tmp) tmp = strchr(line, '\r');
698 if (!tmp) tmp = strchr(line, '\n');
699 if (tmp) *tmp = '\0';
701 num = atoi(xover_str);
702 size_int = atoi(size);
703 line_int = atoi(line);
706 msginfo = procmsg_msginfo_new();
707 msginfo->msgnum = num;
708 msginfo->size = size_int;
710 msginfo->date = g_strdup(date);
711 msginfo->date_t = procheader_date_parse(NULL, date, 0);
713 conv_unmime_header(buf, sizeof(buf), sender, NULL);
714 msginfo->from = g_strdup(buf);
715 msginfo->fromname = procheader_get_fromname(buf);
717 conv_unmime_header(buf, sizeof(buf), subject, NULL);
718 msginfo->subject = g_strdup(buf);
720 extract_parenthesis(msgid, '<', '>');
723 msginfo->msgid = g_strdup(msgid);
725 msginfo->references = g_strdup(ref);
726 eliminate_parenthesis(ref, '(', ')');
727 if ((p = strrchr(ref, '<')) != NULL) {
728 extract_parenthesis(p, '<', '>');
731 msginfo->inreplyto = g_strdup(p);
734 msginfo->xref = g_strdup(xref);
735 p = msginfo->xref+strlen(msginfo->xref) - 1;
736 while (*p == '\r' || *p == '\n') {
744 static gchar *news_parse_xhdr(const gchar *xhdr_str, MsgInfo *msginfo)
750 p = strchr(xhdr_str, ' ');
756 num = atoi(xhdr_str);
757 if (msginfo->msgnum != num) return NULL;
759 tmp = strchr(p, '\r');
760 if (!tmp) tmp = strchr(p, '\n');
763 return g_strndup(p, tmp - p);
768 gint news_cancel_article(Folder * folder, MsgInfo * msginfo)
774 tmp = g_strdup_printf("%s%ctmp%d", g_get_tmp_dir(),
775 G_DIR_SEPARATOR, (gint)msginfo);
779 if ((tmpfp = fopen(tmp, "wb")) == NULL) {
780 FILE_OP_ERROR(tmp, "fopen");
783 if (change_file_mode_rw(tmpfp, tmp) < 0) {
784 FILE_OP_ERROR(tmp, "chmod");
785 g_warning("can't change file mode\n");
788 fprintf(tmpfp, "From: %s\r\n", msginfo->from);
789 fprintf(tmpfp, "Newsgroups: %s\r\n", msginfo->newsgroups);
790 fprintf(tmpfp, "Subject: cmsg cancel <%s>\r\n", msginfo->msgid);
791 fprintf(tmpfp, "Control: cancel <%s>\r\n", msginfo->msgid);
792 fprintf(tmpfp, "Approved: %s\r\n", msginfo->from);
793 fprintf(tmpfp, "X-Cancelled-by: %s\r\n", msginfo->from);
794 get_rfc822_date(buf, sizeof(buf));
795 fprintf(tmpfp, "Date: %s\r\n", buf);
796 fprintf(tmpfp, "\r\n");
797 fprintf(tmpfp, "removed with sylpheed\r\n");
801 news_post(folder, tmp);
809 gint news_get_num_list(Folder *folder, FolderItem *item, GSList **msgnum_list)
811 NNTPSession *session;
812 gint i, ok, num, first, last, nummsgs = 0;
815 g_return_val_if_fail(item != NULL, -1);
816 g_return_val_if_fail(item->folder != NULL, -1);
817 g_return_val_if_fail(FOLDER_CLASS(folder) == &news_class, -1);
819 session = news_session_get(folder);
820 g_return_val_if_fail(session != NULL, -1);
822 ok = news_select_group(session, item->path, &num, &first, &last);
823 if (ok != NN_SUCCESS) {
824 log_warning(_("can't set group: %s\n"), item->path);
829 log_warning(_("invalid article range: %d - %d\n"),
834 for(i = first; i <= last; i++) {
835 *msgnum_list = g_slist_prepend(*msgnum_list, GINT_TO_POINTER(i));
839 dir = folder_item_get_path(item);
840 debug_print("removing old messages from %d to %d in %s\n", first, last, dir);
841 remove_numbered_files(dir, 1, first - 1);
847 #define READ_TO_LISTEND(hdr) \
848 while (!(buf[0] == '.' && buf[1] == '\r')) { \
849 if (sock_gets(SESSION(session)->sock, buf, sizeof(buf)) < 0) { \
850 log_warning(_("error occurred while getting %s.\n"), hdr); \
855 MsgInfo *news_get_msginfo(Folder *folder, FolderItem *item, gint num)
857 NNTPSession *session;
858 MsgInfo *msginfo = NULL;
859 gchar buf[NNTPBUFSIZE];
861 session = news_session_get(folder);
862 g_return_val_if_fail(session != NULL, NULL);
863 g_return_val_if_fail(item != NULL, NULL);
864 g_return_val_if_fail(item->folder != NULL, NULL);
865 g_return_val_if_fail(FOLDER_CLASS(item->folder) == &news_class, NULL);
867 log_message(_("getting xover %d in %s...\n"),
869 if (nntp_xover(session->nntp_sock, num, num) != NN_SUCCESS) {
870 log_warning(_("can't get xover\n"));
874 if (sock_gets(SESSION(session)->sock, buf, sizeof(buf)) < 0) {
875 log_warning(_("error occurred while getting xover.\n"));
879 msginfo = news_parse_xover(buf);
881 log_warning(_("invalid xover line: %s\n"), buf);
884 READ_TO_LISTEND("xover");
889 msginfo->folder = item;
890 msginfo->flags.perm_flags = MSG_NEW|MSG_UNREAD;
891 msginfo->flags.tmp_flags = MSG_NEWS;
892 msginfo->newsgroups = g_strdup(item->path);
894 if (nntp_xhdr(session->nntp_sock, "to", num, num) != NN_SUCCESS) {
895 log_warning(_("can't get xhdr\n"));
899 if (sock_gets(SESSION(session)->sock, buf, sizeof(buf)) < 0) {
900 log_warning(_("error occurred while getting xhdr.\n"));
904 msginfo->to = news_parse_xhdr(buf, msginfo);
906 READ_TO_LISTEND("xhdr (to)");
908 if (nntp_xhdr(session->nntp_sock, "cc", num, num) != NN_SUCCESS) {
909 log_warning(_("can't get xhdr\n"));
913 if (sock_gets(SESSION(session)->sock, buf, sizeof(buf)) < 0) {
914 log_warning(_("error occurred while getting xhdr.\n"));
918 msginfo->cc = news_parse_xhdr(buf, msginfo);
920 READ_TO_LISTEND("xhdr (cc)");
925 static GSList *news_get_msginfos_for_range(NNTPSession *session, FolderItem *item, guint begin, guint end)
927 gchar buf[NNTPBUFSIZE];
928 GSList *newlist = NULL;
929 GSList *llast = NULL;
931 guint count = 0, lines = (end - begin + 2) * 3;
933 g_return_val_if_fail(session != NULL, NULL);
934 g_return_val_if_fail(item != NULL, NULL);
936 log_message(_("getting xover %d - %d in %s...\n"),
937 begin, end, item->path);
938 if (nntp_xover(session->nntp_sock, begin, end) != NN_SUCCESS) {
939 log_warning(_("can't get xover\n"));
944 if (sock_gets(SESSION(session)->sock, buf, sizeof(buf)) < 0) {
945 log_warning(_("error occurred while getting xover.\n"));
949 progressindicator_set_percentage
950 (PROGRESS_TYPE_NETWORK,
951 session->fetch_base_percentage +
952 (((gfloat) count) / ((gfloat) lines)) * session->fetch_total_percentage);
954 if (buf[0] == '.' && buf[1] == '\r') break;
956 msginfo = news_parse_xover(buf);
958 log_warning(_("invalid xover line: %s\n"), buf);
962 msginfo->folder = item;
963 msginfo->flags.perm_flags = MSG_NEW|MSG_UNREAD;
964 msginfo->flags.tmp_flags = MSG_NEWS;
965 msginfo->newsgroups = g_strdup(item->path);
968 llast = newlist = g_slist_append(newlist, msginfo);
970 llast = g_slist_append(llast, msginfo);
975 if (nntp_xhdr(session->nntp_sock, "to", begin, end) != NN_SUCCESS) {
976 log_warning(_("can't get xhdr\n"));
983 if (sock_gets(SESSION(session)->sock, buf, sizeof(buf)) < 0) {
984 log_warning(_("error occurred while getting xhdr.\n"));
988 progressindicator_set_percentage
989 (PROGRESS_TYPE_NETWORK,
990 session->fetch_base_percentage +
991 (((gfloat) count) / ((gfloat) lines)) * session->fetch_total_percentage);
993 if (buf[0] == '.' && buf[1] == '\r') break;
995 g_warning("llast == NULL\n");
999 msginfo = (MsgInfo *)llast->data;
1000 msginfo->to = news_parse_xhdr(buf, msginfo);
1002 llast = llast->next;
1005 if (nntp_xhdr(session->nntp_sock, "cc", begin, end) != NN_SUCCESS) {
1006 log_warning(_("can't get xhdr\n"));
1013 if (sock_gets(SESSION(session)->sock, buf, sizeof(buf)) < 0) {
1014 log_warning(_("error occurred while getting xhdr.\n"));
1018 progressindicator_set_percentage
1019 (PROGRESS_TYPE_NETWORK,
1020 session->fetch_base_percentage +
1021 (((gfloat) count) / ((gfloat) lines)) * session->fetch_total_percentage);
1023 if (buf[0] == '.' && buf[1] == '\r') break;
1025 g_warning("llast == NULL\n");
1029 msginfo = (MsgInfo *)llast->data;
1030 msginfo->cc = news_parse_xhdr(buf, msginfo);
1032 llast = llast->next;
1038 gint news_fetch_msgnum_sort(gconstpointer a, gconstpointer b)
1040 return (GPOINTER_TO_INT(a) - GPOINTER_TO_INT(b));
1043 GSList *news_get_msginfos(Folder *folder, FolderItem *item, GSList *msgnum_list)
1045 NNTPSession *session;
1046 GSList *elem, *msginfo_list = NULL, *tmp_msgnum_list, *tmp_msginfo_list;
1047 guint first, last, next;
1048 guint tofetch, fetched;
1050 g_return_val_if_fail(folder != NULL, NULL);
1051 g_return_val_if_fail(FOLDER_CLASS(folder) == &news_class, NULL);
1052 g_return_val_if_fail(msgnum_list != NULL, NULL);
1053 g_return_val_if_fail(item != NULL, NULL);
1055 session = news_session_get(folder);
1056 g_return_val_if_fail(session != NULL, NULL);
1058 tmp_msgnum_list = g_slist_copy(msgnum_list);
1059 tmp_msgnum_list = g_slist_sort(tmp_msgnum_list, news_fetch_msgnum_sort);
1061 progressindicator_start(PROGRESS_TYPE_NETWORK);
1062 tofetch = g_slist_length(tmp_msgnum_list);
1065 first = GPOINTER_TO_INT(tmp_msgnum_list->data);
1067 for(elem = g_slist_next(tmp_msgnum_list); elem != NULL; elem = g_slist_next(elem)) {
1068 next = GPOINTER_TO_INT(elem->data);
1069 if(next != (last + 1)) {
1070 session->fetch_base_percentage = ((gfloat) fetched) / ((gfloat) tofetch);
1071 session->fetch_total_percentage = ((gfloat) (last - first + 1)) / ((gfloat) tofetch);
1072 tmp_msginfo_list = news_get_msginfos_for_range(session, item, first, last);
1073 msginfo_list = g_slist_concat(msginfo_list, tmp_msginfo_list);
1074 fetched = last - first + 1;
1079 session->fetch_base_percentage = ((gfloat) fetched) / ((gfloat) tofetch);
1080 session->fetch_total_percentage = ((gfloat) (last - first + 1)) / ((gfloat) tofetch);
1081 tmp_msginfo_list = news_get_msginfos_for_range(session, item, first, last);
1082 msginfo_list = g_slist_concat(msginfo_list, tmp_msginfo_list);
1084 g_slist_free(tmp_msgnum_list);
1086 progressindicator_stop(PROGRESS_TYPE_NETWORK);
1088 return msginfo_list;