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 =
143 FolderClass *news_get_class()
148 Folder *news_folder_new(const gchar *name, const gchar *path)
152 folder = (Folder *)g_new0(NewsFolder, 1);
153 folder->class = &news_class;
154 news_folder_init(folder, name, path);
159 void news_folder_destroy(Folder *folder)
163 dir = folder_get_path(folder);
164 if (is_dir_exist(dir))
165 remove_dir_recursive(dir);
168 folder_remote_folder_destroy(REMOTE_FOLDER(folder));
171 static void news_folder_init(Folder *folder, const gchar *name,
174 folder_remote_folder_init(folder, name, path);
178 static Session *news_session_new(const gchar *server, gushort port,
179 const gchar *userid, const gchar *passwd,
182 static Session *news_session_new(const gchar *server, gushort port,
183 const gchar *userid, const gchar *passwd)
186 gchar buf[NNTPBUFSIZE];
187 NNTPSession *session;
188 NNTPSockInfo *nntp_sock;
190 g_return_val_if_fail(server != NULL, NULL);
192 log_message(_("creating NNTP connection to %s:%d ...\n"), server, port);
195 if (userid && passwd)
196 nntp_sock = nntp_open_auth(server, port, buf, userid, passwd,
199 nntp_sock = nntp_open(server, port, buf, ssl_type);
201 if (userid && passwd)
202 nntp_sock = nntp_open_auth(server, port, buf, userid, passwd);
204 nntp_sock = nntp_open(server, port, buf);
207 if (nntp_sock == NULL)
210 session = g_new(NNTPSession, 1);
211 SESSION(session)->type = SESSION_NEWS;
212 SESSION(session)->server = g_strdup(server);
213 session->nntp_sock = nntp_sock;
214 SESSION(session)->sock = nntp_sock->sock;
215 SESSION(session)->connected = TRUE;
216 SESSION(session)->phase = SESSION_READY;
217 SESSION(session)->last_access_time = time(NULL);
218 SESSION(session)->data = NULL;
220 SESSION(session)->destroy = news_session_destroy;
222 session->group = NULL;
224 return SESSION(session);
227 void news_session_destroy(Session *session)
229 nntp_close(NNTP_SESSION(session)->nntp_sock);
230 NNTP_SESSION(session)->nntp_sock = NULL;
231 session->sock = NULL;
233 g_free(NNTP_SESSION(session)->group);
236 static Session *news_session_new_for_folder(Folder *folder)
240 const gchar *userid = NULL;
241 gchar *passwd = NULL;
243 gchar buf[NNTPBUFSIZE];
245 g_return_val_if_fail(folder != NULL, NULL);
246 g_return_val_if_fail(folder->account != NULL, NULL);
248 ac = folder->account;
249 if (ac->use_nntp_auth && ac->userid && ac->userid[0]) {
251 if (ac->passwd && ac->passwd[0])
252 passwd = g_strdup(ac->passwd);
254 passwd = input_dialog_query_password(ac->nntp_server,
259 port = ac->set_nntpport ? ac->nntpport
260 : ac->ssl_nntp ? NNTPS_PORT : NNTP_PORT;
261 session = news_session_new(ac->nntp_server, port, userid, passwd,
264 port = ac->set_nntpport ? ac->nntpport : NNTP_PORT;
265 session = news_session_new(ac->nntp_server, port, userid, passwd);
267 if ((session != NULL) && ac->use_nntp_auth && ac->use_nntp_auth_onconnect)
268 nntp_forceauth(NNTP_SESSION(session)->nntp_sock, buf, userid, passwd);
275 NNTPSession *news_session_get(Folder *folder)
277 RemoteFolder *rfolder = REMOTE_FOLDER(folder);
279 g_return_val_if_fail(folder != NULL, NULL);
280 g_return_val_if_fail(FOLDER_CLASS(folder) == &news_class, NULL);
281 g_return_val_if_fail(folder->account != NULL, NULL);
283 if (!rfolder->session) {
284 rfolder->session = news_session_new_for_folder(folder);
285 return NNTP_SESSION(rfolder->session);
288 if (time(NULL) - rfolder->session->last_access_time < SESSION_TIMEOUT) {
289 rfolder->session->last_access_time = time(NULL);
290 return NNTP_SESSION(rfolder->session);
293 if (nntp_mode(NNTP_SESSION(rfolder->session)->nntp_sock, FALSE)
295 log_warning("NNTP connection to %s:%d has been"
296 " disconnected. Reconnecting...\n",
297 folder->account->nntp_server,
298 folder->account->set_nntpport ?
299 folder->account->nntpport : NNTP_PORT);
300 session_destroy(rfolder->session);
301 rfolder->session = news_session_new_for_folder(folder);
304 if (rfolder->session)
305 rfolder->session->last_access_time = time(NULL);
306 return NNTP_SESSION(rfolder->session);
309 gchar *news_fetch_msg(Folder *folder, FolderItem *item, gint num)
311 gchar *path, *filename;
312 NNTPSession *session;
315 g_return_val_if_fail(folder != NULL, NULL);
316 g_return_val_if_fail(item != NULL, NULL);
318 path = folder_item_get_path(item);
319 if (!is_dir_exist(path))
321 filename = g_strconcat(path, G_DIR_SEPARATOR_S, itos(num), NULL);
324 if (is_file_exist(filename)) {
325 debug_print("article %d has been already cached.\n", num);
329 session = news_session_get(folder);
335 ok = news_select_group(session, item->path, NULL, NULL, NULL);
336 if (ok != NN_SUCCESS) {
337 g_warning("can't select group %s\n", item->path);
342 debug_print("getting article %d...\n", num);
343 ok = news_get_article(NNTP_SESSION(REMOTE_FOLDER(folder)->session),
346 g_warning("can't read article %d\n", num);
347 session_destroy(SESSION(session));
348 REMOTE_FOLDER(folder)->session = NULL;
356 gint news_scan_group(Folder *folder, FolderItem *item)
358 NNTPSession *session;
359 gint num = 0, first = 0, last = 0;
362 g_return_val_if_fail(folder != NULL, -1);
363 g_return_val_if_fail(item != NULL, -1);
365 session = news_session_get(folder);
366 if (!session) return -1;
368 ok = news_select_group(session, item->path, &num, &first, &last);
369 if (ok != NN_SUCCESS) {
370 log_warning("can't set group: %s\n", item->path);
375 item->new = item->unread = item->total = item->last_num = 0;
380 path = folder_item_get_path(item);
381 if (path && is_dir_exist(path)) {
382 procmsg_get_mark_sum(path, &new, &unread, &total, &min, &max,
387 if (max < first || last < min)
388 new = unread = total = num;
395 else if (max < last) {
397 unread += last - max;
400 if (new > num) new = num;
401 if (unread > num) unread = num;
405 item->unread = unread;
407 item->last_num = last;
412 static NewsGroupInfo *news_group_info_new(const gchar *name,
413 gint first, gint last, gchar type)
415 NewsGroupInfo *ginfo;
417 ginfo = g_new(NewsGroupInfo, 1);
418 ginfo->name = g_strdup(name);
419 ginfo->first = first;
426 static void news_group_info_free(NewsGroupInfo *ginfo)
432 static gint news_group_info_compare(NewsGroupInfo *ginfo1,
433 NewsGroupInfo *ginfo2)
435 return g_strcasecmp(ginfo1->name, ginfo2->name);
438 GSList *news_get_group_list(Folder *folder)
440 gchar *path, *filename;
444 gchar buf[NNTPBUFSIZE];
446 g_return_val_if_fail(folder != NULL, NULL);
447 g_return_val_if_fail(FOLDER_CLASS(folder) == &news_class, NULL);
449 path = folder_item_get_path(FOLDER_ITEM(folder->node->data));
450 if (!is_dir_exist(path))
452 filename = g_strconcat(path, G_DIR_SEPARATOR_S, NEWSGROUP_LIST, NULL);
455 if ((fp = fopen(filename, "rb")) == NULL) {
456 NNTPSession *session;
458 session = news_session_get(folder);
464 if (nntp_list(session->nntp_sock) != NN_SUCCESS) {
468 if (recv_write_to_file(SESSION(session)->sock, filename) < 0) {
469 log_warning("can't retrieve newsgroup list\n");
470 session_destroy(SESSION(session));
471 REMOTE_FOLDER(folder)->session = NULL;
476 if ((fp = fopen(filename, "rb")) == NULL) {
477 FILE_OP_ERROR(filename, "fopen");
483 while (fgets(buf, sizeof(buf), fp) != NULL) {
489 NewsGroupInfo *ginfo;
497 if (sscanf(p, "%d %d %c", &last_num, &first_num, &type) < 3)
500 ginfo = news_group_info_new(name, first_num, last_num, type);
503 last = list = g_slist_append(NULL, ginfo);
505 last = g_slist_append(last, ginfo);
513 list = g_slist_sort(list, (GCompareFunc)news_group_info_compare);
518 void news_group_list_free(GSList *group_list)
522 if (!group_list) return;
524 for (cur = group_list; cur != NULL; cur = cur->next)
525 news_group_info_free((NewsGroupInfo *)cur->data);
526 g_slist_free(group_list);
529 void news_remove_group_list_cache(Folder *folder)
531 gchar *path, *filename;
533 g_return_if_fail(folder != NULL);
534 g_return_if_fail(FOLDER_CLASS(folder) == &news_class);
536 path = folder_item_get_path(FOLDER_ITEM(folder->node->data));
537 filename = g_strconcat(path, G_DIR_SEPARATOR_S, NEWSGROUP_LIST, NULL);
540 if (is_file_exist(filename)) {
541 if (remove(filename) < 0)
542 FILE_OP_ERROR(filename, "remove");
547 gint news_post(Folder *folder, const gchar *file)
552 g_return_val_if_fail(folder != NULL, -1);
553 g_return_val_if_fail(FOLDER_CLASS(folder) == &news_class, -1);
554 g_return_val_if_fail(file != NULL, -1);
556 if ((fp = fopen(file, "rb")) == NULL) {
557 FILE_OP_ERROR(file, "fopen");
561 ok = news_post_stream(folder, fp);
568 gint news_post_stream(Folder *folder, FILE *fp)
570 NNTPSession *session;
573 g_return_val_if_fail(folder != NULL, -1);
574 g_return_val_if_fail(FOLDER_CLASS(folder) == &news_class, -1);
575 g_return_val_if_fail(fp != NULL, -1);
577 session = news_session_get(folder);
578 if (!session) return -1;
580 ok = nntp_post(session->nntp_sock, fp);
581 if (ok != NN_SUCCESS) {
582 log_warning("can't post article.\n");
589 static gint news_get_article_cmd(NNTPSession *session, const gchar *cmd,
590 gint num, gchar *filename)
594 if (nntp_get_article(session->nntp_sock, cmd, num, &msgid)
598 debug_print("Message-Id = %s, num = %d\n", msgid, num);
601 if (recv_write_to_file(session->nntp_sock->sock, filename) < 0) {
602 log_warning("can't retrieve article %d\n", num);
609 static gint news_remove_msg(Folder *folder, FolderItem *item, gint num)
614 dir = folder_item_get_path(item);
615 debug_print("news_remove_msg: removing msg %d in %s\n",num,dir);
616 r = remove_numbered_files(dir, num, num);
622 static gint news_get_article(NNTPSession *session, gint num, gchar *filename)
624 return news_get_article_cmd(session, "ARTICLE", num, filename);
629 * @session: Active NNTP session.
630 * @group: Newsgroup name.
631 * @num: Estimated number of articles.
632 * @first: First article number.
633 * @last: Last article number.
635 * Select newsgroup @group with the GROUP command if it is not already
636 * selected in @session, or article numbers need to be returned.
638 * Return value: NNTP result code.
640 static gint news_select_group(NNTPSession *session, const gchar *group,
641 gint *num, gint *first, gint *last)
644 gint num_, first_, last_;
646 if (!num || !first || !last) {
647 if (session->group && g_strcasecmp(session->group, group) == 0)
654 g_free(session->group);
655 session->group = NULL;
657 ok = nntp_group(session->nntp_sock, group, num, first, last);
658 if (ok == NN_SUCCESS)
659 session->group = g_strdup(group);
664 #define PARSE_ONE_PARAM(p, srcp) \
666 p = strchr(srcp, '\t'); \
667 if (!p) return NULL; \
672 static MsgInfo *news_parse_xover(const gchar *xover_str)
675 gchar buf[NNTPBUFSIZE];
676 gchar *subject, *sender, *size, *line, *date, *msgid, *ref, *tmp, *xref;
678 gint num, size_int, line_int;
681 Xstrdup_a(xover_buf, xover_str, return NULL);
683 PARSE_ONE_PARAM(subject, xover_buf);
684 PARSE_ONE_PARAM(sender, subject);
685 PARSE_ONE_PARAM(date, sender);
686 PARSE_ONE_PARAM(msgid, date);
687 PARSE_ONE_PARAM(ref, msgid);
688 PARSE_ONE_PARAM(size, ref);
689 PARSE_ONE_PARAM(line, size);
690 PARSE_ONE_PARAM(xref, line);
692 tmp = strchr(xref, '\t');
693 if (!tmp) tmp = strchr(line, '\r');
694 if (!tmp) tmp = strchr(line, '\n');
695 if (tmp) *tmp = '\0';
697 num = atoi(xover_str);
698 size_int = atoi(size);
699 line_int = atoi(line);
702 msginfo = procmsg_msginfo_new();
703 msginfo->msgnum = num;
704 msginfo->size = size_int;
706 msginfo->date = g_strdup(date);
707 msginfo->date_t = procheader_date_parse(NULL, date, 0);
709 conv_unmime_header(buf, sizeof(buf), sender, NULL);
710 msginfo->from = g_strdup(buf);
711 msginfo->fromname = procheader_get_fromname(buf);
713 conv_unmime_header(buf, sizeof(buf), subject, NULL);
714 msginfo->subject = g_strdup(buf);
716 extract_parenthesis(msgid, '<', '>');
719 msginfo->msgid = g_strdup(msgid);
721 msginfo->references = g_strdup(ref);
722 eliminate_parenthesis(ref, '(', ')');
723 if ((p = strrchr(ref, '<')) != NULL) {
724 extract_parenthesis(p, '<', '>');
727 msginfo->inreplyto = g_strdup(p);
730 msginfo->xref = g_strdup(xref);
731 p = msginfo->xref+strlen(msginfo->xref) - 1;
732 while (*p == '\r' || *p == '\n') {
740 static gchar *news_parse_xhdr(const gchar *xhdr_str, MsgInfo *msginfo)
746 p = strchr(xhdr_str, ' ');
752 num = atoi(xhdr_str);
753 if (msginfo->msgnum != num) return NULL;
755 tmp = strchr(p, '\r');
756 if (!tmp) tmp = strchr(p, '\n');
759 return g_strndup(p, tmp - p);
764 gint news_cancel_article(Folder * folder, MsgInfo * msginfo)
770 tmp = g_strdup_printf("%s%ctmp%d", g_get_tmp_dir(),
771 G_DIR_SEPARATOR, (gint)msginfo);
775 if ((tmpfp = fopen(tmp, "wb")) == NULL) {
776 FILE_OP_ERROR(tmp, "fopen");
779 if (change_file_mode_rw(tmpfp, tmp) < 0) {
780 FILE_OP_ERROR(tmp, "chmod");
781 g_warning("can't change file mode\n");
784 fprintf(tmpfp, "From: %s\r\n", msginfo->from);
785 fprintf(tmpfp, "Newsgroups: %s\r\n", msginfo->newsgroups);
786 fprintf(tmpfp, "Subject: cmsg cancel <%s>\r\n", msginfo->msgid);
787 fprintf(tmpfp, "Control: cancel <%s>\r\n", msginfo->msgid);
788 fprintf(tmpfp, "Approved: %s\r\n", msginfo->from);
789 fprintf(tmpfp, "X-Cancelled-by: %s\r\n", msginfo->from);
790 get_rfc822_date(buf, sizeof(buf));
791 fprintf(tmpfp, "Date: %s\r\n", buf);
792 fprintf(tmpfp, "\r\n");
793 fprintf(tmpfp, "removed with sylpheed\r\n");
797 news_post(folder, tmp);
805 gint news_get_num_list(Folder *folder, FolderItem *item, GSList **msgnum_list)
807 NNTPSession *session;
808 gint i, ok, num, first, last, nummsgs = 0;
811 g_return_val_if_fail(item != NULL, -1);
812 g_return_val_if_fail(item->folder != NULL, -1);
813 g_return_val_if_fail(FOLDER_CLASS(folder) == &news_class, -1);
815 session = news_session_get(folder);
816 g_return_val_if_fail(session != NULL, -1);
818 ok = news_select_group(session, item->path, &num, &first, &last);
819 if (ok != NN_SUCCESS) {
820 log_warning(_("can't set group: %s\n"), item->path);
825 log_warning(_("invalid article range: %d - %d\n"),
830 for(i = first; i <= last; i++) {
831 *msgnum_list = g_slist_prepend(*msgnum_list, GINT_TO_POINTER(i));
835 dir = folder_item_get_path(item);
836 debug_print("removing old messages from %d to %d in %s\n", first, last, dir);
837 remove_numbered_files(dir, 1, first - 1);
843 #define READ_TO_LISTEND(hdr) \
844 while (!(buf[0] == '.' && buf[1] == '\r')) { \
845 if (sock_gets(SESSION(session)->sock, buf, sizeof(buf)) < 0) { \
846 log_warning(_("error occurred while getting %s.\n"), hdr); \
851 MsgInfo *news_get_msginfo(Folder *folder, FolderItem *item, gint num)
853 NNTPSession *session;
854 MsgInfo *msginfo = NULL;
855 gchar buf[NNTPBUFSIZE];
857 session = news_session_get(folder);
858 g_return_val_if_fail(session != NULL, NULL);
859 g_return_val_if_fail(item != NULL, NULL);
860 g_return_val_if_fail(item->folder != NULL, NULL);
861 g_return_val_if_fail(FOLDER_CLASS(item->folder) == &news_class, NULL);
863 log_message(_("getting xover %d in %s...\n"),
865 if (nntp_xover(session->nntp_sock, num, num) != NN_SUCCESS) {
866 log_warning(_("can't get xover\n"));
870 if (sock_gets(SESSION(session)->sock, buf, sizeof(buf)) < 0) {
871 log_warning(_("error occurred while getting xover.\n"));
875 msginfo = news_parse_xover(buf);
877 log_warning(_("invalid xover line: %s\n"), buf);
880 READ_TO_LISTEND("xover");
885 msginfo->folder = item;
886 msginfo->flags.perm_flags = MSG_NEW|MSG_UNREAD;
887 msginfo->flags.tmp_flags = MSG_NEWS;
888 msginfo->newsgroups = g_strdup(item->path);
890 if (nntp_xhdr(session->nntp_sock, "to", num, num) != NN_SUCCESS) {
891 log_warning(_("can't get xhdr\n"));
895 if (sock_gets(SESSION(session)->sock, buf, sizeof(buf)) < 0) {
896 log_warning(_("error occurred while getting xhdr.\n"));
900 msginfo->to = news_parse_xhdr(buf, msginfo);
902 READ_TO_LISTEND("xhdr (to)");
904 if (nntp_xhdr(session->nntp_sock, "cc", num, num) != NN_SUCCESS) {
905 log_warning(_("can't get xhdr\n"));
909 if (sock_gets(SESSION(session)->sock, buf, sizeof(buf)) < 0) {
910 log_warning(_("error occurred while getting xhdr.\n"));
914 msginfo->cc = news_parse_xhdr(buf, msginfo);
916 READ_TO_LISTEND("xhdr (cc)");
921 static GSList *news_get_msginfos_for_range(NNTPSession *session, FolderItem *item, guint begin, guint end)
923 gchar buf[NNTPBUFSIZE];
924 GSList *newlist = NULL;
925 GSList *llast = NULL;
927 guint count = 0, lines = (end - begin + 2) * 3;
929 g_return_val_if_fail(session != NULL, NULL);
930 g_return_val_if_fail(item != NULL, NULL);
932 log_message(_("getting xover %d - %d in %s...\n"),
933 begin, end, item->path);
934 if (nntp_xover(session->nntp_sock, begin, end) != NN_SUCCESS) {
935 log_warning(_("can't get xover\n"));
940 if (sock_gets(SESSION(session)->sock, buf, sizeof(buf)) < 0) {
941 log_warning(_("error occurred while getting xover.\n"));
945 progressindicator_set_percentage
946 (PROGRESS_TYPE_NETWORK,
947 session->fetch_base_percentage +
948 (((gfloat) count) / ((gfloat) lines)) * session->fetch_total_percentage);
950 if (buf[0] == '.' && buf[1] == '\r') break;
952 msginfo = news_parse_xover(buf);
954 log_warning(_("invalid xover line: %s\n"), buf);
958 msginfo->folder = item;
959 msginfo->flags.perm_flags = MSG_NEW|MSG_UNREAD;
960 msginfo->flags.tmp_flags = MSG_NEWS;
961 msginfo->newsgroups = g_strdup(item->path);
964 llast = newlist = g_slist_append(newlist, msginfo);
966 llast = g_slist_append(llast, msginfo);
971 if (nntp_xhdr(session->nntp_sock, "to", begin, end) != NN_SUCCESS) {
972 log_warning(_("can't get xhdr\n"));
979 if (sock_gets(SESSION(session)->sock, buf, sizeof(buf)) < 0) {
980 log_warning(_("error occurred while getting xhdr.\n"));
984 progressindicator_set_percentage
985 (PROGRESS_TYPE_NETWORK,
986 session->fetch_base_percentage +
987 (((gfloat) count) / ((gfloat) lines)) * session->fetch_total_percentage);
989 if (buf[0] == '.' && buf[1] == '\r') break;
991 g_warning("llast == NULL\n");
995 msginfo = (MsgInfo *)llast->data;
996 msginfo->to = news_parse_xhdr(buf, msginfo);
1001 if (nntp_xhdr(session->nntp_sock, "cc", begin, end) != NN_SUCCESS) {
1002 log_warning(_("can't get xhdr\n"));
1009 if (sock_gets(SESSION(session)->sock, buf, sizeof(buf)) < 0) {
1010 log_warning(_("error occurred while getting xhdr.\n"));
1014 progressindicator_set_percentage
1015 (PROGRESS_TYPE_NETWORK,
1016 session->fetch_base_percentage +
1017 (((gfloat) count) / ((gfloat) lines)) * session->fetch_total_percentage);
1019 if (buf[0] == '.' && buf[1] == '\r') break;
1021 g_warning("llast == NULL\n");
1025 msginfo = (MsgInfo *)llast->data;
1026 msginfo->cc = news_parse_xhdr(buf, msginfo);
1028 llast = llast->next;
1034 gint news_fetch_msgnum_sort(gconstpointer a, gconstpointer b)
1036 return (GPOINTER_TO_INT(a) - GPOINTER_TO_INT(b));
1039 GSList *news_get_msginfos(Folder *folder, FolderItem *item, GSList *msgnum_list)
1041 NNTPSession *session;
1042 GSList *elem, *msginfo_list = NULL, *tmp_msgnum_list, *tmp_msginfo_list;
1043 guint first, last, next;
1044 guint tofetch, fetched;
1046 g_return_val_if_fail(folder != NULL, NULL);
1047 g_return_val_if_fail(FOLDER_CLASS(folder) == &news_class, NULL);
1048 g_return_val_if_fail(msgnum_list != NULL, NULL);
1049 g_return_val_if_fail(item != NULL, NULL);
1051 session = news_session_get(folder);
1052 g_return_val_if_fail(session != NULL, NULL);
1054 tmp_msgnum_list = g_slist_copy(msgnum_list);
1055 tmp_msgnum_list = g_slist_sort(tmp_msgnum_list, news_fetch_msgnum_sort);
1057 progressindicator_start(PROGRESS_TYPE_NETWORK);
1058 tofetch = g_slist_length(tmp_msgnum_list);
1061 first = GPOINTER_TO_INT(tmp_msgnum_list->data);
1063 for(elem = g_slist_next(tmp_msgnum_list); elem != NULL; elem = g_slist_next(elem)) {
1064 next = GPOINTER_TO_INT(elem->data);
1065 if(next != (last + 1)) {
1066 session->fetch_base_percentage = ((gfloat) fetched) / ((gfloat) tofetch);
1067 session->fetch_total_percentage = ((gfloat) (last - first + 1)) / ((gfloat) tofetch);
1068 tmp_msginfo_list = news_get_msginfos_for_range(session, item, first, last);
1069 msginfo_list = g_slist_concat(msginfo_list, tmp_msginfo_list);
1070 fetched = last - first + 1;
1075 session->fetch_base_percentage = ((gfloat) fetched) / ((gfloat) tofetch);
1076 session->fetch_total_percentage = ((gfloat) (last - first + 1)) / ((gfloat) tofetch);
1077 tmp_msginfo_list = news_get_msginfos_for_range(session, item, first, last);
1078 msginfo_list = g_slist_concat(msginfo_list, tmp_msginfo_list);
1080 g_slist_free(tmp_msgnum_list);
1082 progressindicator_stop(PROGRESS_TYPE_NETWORK);
1084 return msginfo_list;