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 Folder *news_folder_new(const gchar *name, const gchar *path)
113 folder = (Folder *)g_new0(NewsFolder, 1);
114 news_folder_init(folder, name, path);
119 void news_folder_destroy(Folder *folder)
123 dir = folder_get_path(folder);
124 if (is_dir_exist(dir))
125 remove_dir_recursive(dir);
128 folder_remote_folder_destroy(REMOTE_FOLDER(folder));
131 static void news_folder_init(Folder *folder, const gchar *name,
134 folder->type = F_NEWS;
136 folder_remote_folder_init(folder, name, path);
139 folder->get_msg_list = news_get_article_list;
141 folder->fetch_msg = news_fetch_msg;
143 folder->scan = news_scan_group;
145 folder->destroy = news_folder_destroy;
146 folder->remove_msg = news_remove_msg;
147 folder->get_num_list = news_get_num_list;
148 folder->get_msginfo = news_get_msginfo;
149 folder->get_msginfos = news_get_msginfos;
153 static Session *news_session_new(const gchar *server, gushort port,
154 const gchar *userid, const gchar *passwd,
157 static Session *news_session_new(const gchar *server, gushort port,
158 const gchar *userid, const gchar *passwd)
161 gchar buf[NNTPBUFSIZE];
162 NNTPSession *session;
163 NNTPSockInfo *nntp_sock;
165 g_return_val_if_fail(server != NULL, NULL);
167 log_message(_("creating NNTP connection to %s:%d ...\n"), server, port);
170 if (userid && passwd)
171 nntp_sock = nntp_open_auth(server, port, buf, userid, passwd,
174 nntp_sock = nntp_open(server, port, buf, ssl_type);
176 if (userid && passwd)
177 nntp_sock = nntp_open_auth(server, port, buf, userid, passwd);
179 nntp_sock = nntp_open(server, port, buf);
182 if (nntp_sock == NULL)
185 session = g_new(NNTPSession, 1);
186 SESSION(session)->type = SESSION_NEWS;
187 SESSION(session)->server = g_strdup(server);
188 session->nntp_sock = nntp_sock;
189 SESSION(session)->sock = nntp_sock->sock;
190 SESSION(session)->connected = TRUE;
191 SESSION(session)->phase = SESSION_READY;
192 SESSION(session)->last_access_time = time(NULL);
193 SESSION(session)->data = NULL;
195 SESSION(session)->destroy = news_session_destroy;
197 session->group = NULL;
199 return SESSION(session);
202 void news_session_destroy(Session *session)
204 nntp_close(NNTP_SESSION(session)->nntp_sock);
205 NNTP_SESSION(session)->nntp_sock = NULL;
206 session->sock = NULL;
208 g_free(NNTP_SESSION(session)->group);
211 static Session *news_session_new_for_folder(Folder *folder)
215 const gchar *userid = NULL;
216 gchar *passwd = NULL;
218 gchar buf[NNTPBUFSIZE];
220 g_return_val_if_fail(folder != NULL, NULL);
221 g_return_val_if_fail(folder->account != NULL, NULL);
223 ac = folder->account;
224 if (ac->use_nntp_auth && ac->userid && ac->userid[0]) {
226 if (ac->passwd && ac->passwd[0])
227 passwd = g_strdup(ac->passwd);
229 passwd = input_dialog_query_password(ac->nntp_server,
234 port = ac->set_nntpport ? ac->nntpport
235 : ac->ssl_nntp ? NNTPS_PORT : NNTP_PORT;
236 session = news_session_new(ac->nntp_server, port, userid, passwd,
239 port = ac->set_nntpport ? ac->nntpport : NNTP_PORT;
240 session = news_session_new(ac->nntp_server, port, userid, passwd);
242 if ((session != NULL) && ac->use_nntp_auth && ac->use_nntp_auth_onconnect)
243 nntp_forceauth(NNTP_SESSION(session)->nntp_sock, buf, userid, passwd);
250 NNTPSession *news_session_get(Folder *folder)
252 RemoteFolder *rfolder = REMOTE_FOLDER(folder);
254 g_return_val_if_fail(folder != NULL, NULL);
255 g_return_val_if_fail(folder->type == F_NEWS, NULL);
256 g_return_val_if_fail(folder->account != NULL, NULL);
258 if (!rfolder->session) {
259 rfolder->session = news_session_new_for_folder(folder);
260 return NNTP_SESSION(rfolder->session);
263 if (time(NULL) - rfolder->session->last_access_time < SESSION_TIMEOUT) {
264 rfolder->session->last_access_time = time(NULL);
265 return NNTP_SESSION(rfolder->session);
268 if (nntp_mode(NNTP_SESSION(rfolder->session)->nntp_sock, FALSE)
270 log_warning("NNTP connection to %s:%d has been"
271 " disconnected. Reconnecting...\n",
272 folder->account->nntp_server,
273 folder->account->set_nntpport ?
274 folder->account->nntpport : NNTP_PORT);
275 session_destroy(rfolder->session);
276 rfolder->session = news_session_new_for_folder(folder);
279 if (rfolder->session)
280 rfolder->session->last_access_time = time(NULL);
281 return NNTP_SESSION(rfolder->session);
284 gchar *news_fetch_msg(Folder *folder, FolderItem *item, gint num)
286 gchar *path, *filename;
287 NNTPSession *session;
290 g_return_val_if_fail(folder != NULL, NULL);
291 g_return_val_if_fail(item != NULL, NULL);
293 path = folder_item_get_path(item);
294 if (!is_dir_exist(path))
296 filename = g_strconcat(path, G_DIR_SEPARATOR_S, itos(num), NULL);
299 if (is_file_exist(filename)) {
300 debug_print("article %d has been already cached.\n", num);
304 session = news_session_get(folder);
310 ok = news_select_group(session, item->path, NULL, NULL, NULL);
311 if (ok != NN_SUCCESS) {
312 g_warning("can't select group %s\n", item->path);
317 debug_print("getting article %d...\n", num);
318 ok = news_get_article(NNTP_SESSION(REMOTE_FOLDER(folder)->session),
321 g_warning("can't read article %d\n", num);
322 session_destroy(SESSION(session));
323 REMOTE_FOLDER(folder)->session = NULL;
331 gint news_scan_group(Folder *folder, FolderItem *item)
333 NNTPSession *session;
334 gint num = 0, first = 0, last = 0;
337 g_return_val_if_fail(folder != NULL, -1);
338 g_return_val_if_fail(item != NULL, -1);
340 session = news_session_get(folder);
341 if (!session) return -1;
343 ok = news_select_group(session, item->path, &num, &first, &last);
344 if (ok != NN_SUCCESS) {
345 log_warning("can't set group: %s\n", item->path);
350 item->new = item->unread = item->total = item->last_num = 0;
355 path = folder_item_get_path(item);
356 if (path && is_dir_exist(path)) {
357 procmsg_get_mark_sum(path, &new, &unread, &total, &min, &max,
362 if (max < first || last < min)
363 new = unread = total = num;
370 else if (max < last) {
372 unread += last - max;
375 if (new > num) new = num;
376 if (unread > num) unread = num;
380 item->unread = unread;
382 item->last_num = last;
387 static NewsGroupInfo *news_group_info_new(const gchar *name,
388 gint first, gint last, gchar type)
390 NewsGroupInfo *ginfo;
392 ginfo = g_new(NewsGroupInfo, 1);
393 ginfo->name = g_strdup(name);
394 ginfo->first = first;
401 static void news_group_info_free(NewsGroupInfo *ginfo)
407 static gint news_group_info_compare(NewsGroupInfo *ginfo1,
408 NewsGroupInfo *ginfo2)
410 return g_strcasecmp(ginfo1->name, ginfo2->name);
413 GSList *news_get_group_list(Folder *folder)
415 gchar *path, *filename;
419 gchar buf[NNTPBUFSIZE];
421 g_return_val_if_fail(folder != NULL, NULL);
422 g_return_val_if_fail(folder->type == F_NEWS, NULL);
424 path = folder_item_get_path(FOLDER_ITEM(folder->node->data));
425 if (!is_dir_exist(path))
427 filename = g_strconcat(path, G_DIR_SEPARATOR_S, NEWSGROUP_LIST, NULL);
430 if ((fp = fopen(filename, "rb")) == NULL) {
431 NNTPSession *session;
433 session = news_session_get(folder);
439 if (nntp_list(session->nntp_sock) != NN_SUCCESS) {
443 if (recv_write_to_file(SESSION(session)->sock, filename) < 0) {
444 log_warning("can't retrieve newsgroup list\n");
445 session_destroy(SESSION(session));
446 REMOTE_FOLDER(folder)->session = NULL;
451 if ((fp = fopen(filename, "rb")) == NULL) {
452 FILE_OP_ERROR(filename, "fopen");
458 while (fgets(buf, sizeof(buf), fp) != NULL) {
464 NewsGroupInfo *ginfo;
472 if (sscanf(p, "%d %d %c", &last_num, &first_num, &type) < 3)
475 ginfo = news_group_info_new(name, first_num, last_num, type);
478 last = list = g_slist_append(NULL, ginfo);
480 last = g_slist_append(last, ginfo);
488 list = g_slist_sort(list, (GCompareFunc)news_group_info_compare);
493 void news_group_list_free(GSList *group_list)
497 if (!group_list) return;
499 for (cur = group_list; cur != NULL; cur = cur->next)
500 news_group_info_free((NewsGroupInfo *)cur->data);
501 g_slist_free(group_list);
504 void news_remove_group_list_cache(Folder *folder)
506 gchar *path, *filename;
508 g_return_if_fail(folder != NULL);
509 g_return_if_fail(folder->type == F_NEWS);
511 path = folder_item_get_path(FOLDER_ITEM(folder->node->data));
512 filename = g_strconcat(path, G_DIR_SEPARATOR_S, NEWSGROUP_LIST, NULL);
515 if (is_file_exist(filename)) {
516 if (remove(filename) < 0)
517 FILE_OP_ERROR(filename, "remove");
522 gint news_post(Folder *folder, const gchar *file)
527 g_return_val_if_fail(folder != NULL, -1);
528 g_return_val_if_fail(folder->type == F_NEWS, -1);
529 g_return_val_if_fail(file != NULL, -1);
531 if ((fp = fopen(file, "rb")) == NULL) {
532 FILE_OP_ERROR(file, "fopen");
536 ok = news_post_stream(folder, fp);
543 gint news_post_stream(Folder *folder, FILE *fp)
545 NNTPSession *session;
548 g_return_val_if_fail(folder != NULL, -1);
549 g_return_val_if_fail(folder->type == F_NEWS, -1);
550 g_return_val_if_fail(fp != NULL, -1);
552 session = news_session_get(folder);
553 if (!session) return -1;
555 ok = nntp_post(session->nntp_sock, fp);
556 if (ok != NN_SUCCESS) {
557 log_warning("can't post article.\n");
564 static gint news_get_article_cmd(NNTPSession *session, const gchar *cmd,
565 gint num, gchar *filename)
569 if (nntp_get_article(session->nntp_sock, cmd, num, &msgid)
573 debug_print("Message-Id = %s, num = %d\n", msgid, num);
576 if (recv_write_to_file(session->nntp_sock->sock, filename) < 0) {
577 log_warning("can't retrieve article %d\n", num);
584 static gint news_remove_msg(Folder *folder, FolderItem *item, gint num)
589 dir = folder_item_get_path(item);
590 debug_print("news_remove_msg: removing msg %d in %s\n",num,dir);
591 r = remove_numbered_files(dir, num, num);
597 static gint news_get_article(NNTPSession *session, gint num, gchar *filename)
599 return news_get_article_cmd(session, "ARTICLE", num, filename);
604 * @session: Active NNTP session.
605 * @group: Newsgroup name.
606 * @num: Estimated number of articles.
607 * @first: First article number.
608 * @last: Last article number.
610 * Select newsgroup @group with the GROUP command if it is not already
611 * selected in @session, or article numbers need to be returned.
613 * Return value: NNTP result code.
615 static gint news_select_group(NNTPSession *session, const gchar *group,
616 gint *num, gint *first, gint *last)
619 gint num_, first_, last_;
621 if (!num || !first || !last) {
622 if (session->group && g_strcasecmp(session->group, group) == 0)
629 g_free(session->group);
630 session->group = NULL;
632 ok = nntp_group(session->nntp_sock, group, num, first, last);
633 if (ok == NN_SUCCESS)
634 session->group = g_strdup(group);
639 #define PARSE_ONE_PARAM(p, srcp) \
641 p = strchr(srcp, '\t'); \
642 if (!p) return NULL; \
647 static MsgInfo *news_parse_xover(const gchar *xover_str)
650 gchar buf[NNTPBUFSIZE];
651 gchar *subject, *sender, *size, *line, *date, *msgid, *ref, *tmp, *xref;
653 gint num, size_int, line_int;
656 Xstrdup_a(xover_buf, xover_str, return NULL);
658 PARSE_ONE_PARAM(subject, xover_buf);
659 PARSE_ONE_PARAM(sender, subject);
660 PARSE_ONE_PARAM(date, sender);
661 PARSE_ONE_PARAM(msgid, date);
662 PARSE_ONE_PARAM(ref, msgid);
663 PARSE_ONE_PARAM(size, ref);
664 PARSE_ONE_PARAM(line, size);
665 PARSE_ONE_PARAM(xref, line);
667 tmp = strchr(xref, '\t');
668 if (!tmp) tmp = strchr(line, '\r');
669 if (!tmp) tmp = strchr(line, '\n');
670 if (tmp) *tmp = '\0';
672 num = atoi(xover_str);
673 size_int = atoi(size);
674 line_int = atoi(line);
677 msginfo = procmsg_msginfo_new();
678 msginfo->msgnum = num;
679 msginfo->size = size_int;
681 msginfo->date = g_strdup(date);
682 msginfo->date_t = procheader_date_parse(NULL, date, 0);
684 conv_unmime_header(buf, sizeof(buf), sender, NULL);
685 msginfo->from = g_strdup(buf);
686 msginfo->fromname = procheader_get_fromname(buf);
688 conv_unmime_header(buf, sizeof(buf), subject, NULL);
689 msginfo->subject = g_strdup(buf);
691 extract_parenthesis(msgid, '<', '>');
694 msginfo->msgid = g_strdup(msgid);
696 msginfo->references = g_strdup(ref);
697 eliminate_parenthesis(ref, '(', ')');
698 if ((p = strrchr(ref, '<')) != NULL) {
699 extract_parenthesis(p, '<', '>');
702 msginfo->inreplyto = g_strdup(p);
705 msginfo->xref = g_strdup(xref);
706 p = msginfo->xref+strlen(msginfo->xref) - 1;
707 while (*p == '\r' || *p == '\n') {
715 static gchar *news_parse_xhdr(const gchar *xhdr_str, MsgInfo *msginfo)
721 p = strchr(xhdr_str, ' ');
727 num = atoi(xhdr_str);
728 if (msginfo->msgnum != num) return NULL;
730 tmp = strchr(p, '\r');
731 if (!tmp) tmp = strchr(p, '\n');
734 return g_strndup(p, tmp - p);
739 gint news_cancel_article(Folder * folder, MsgInfo * msginfo)
745 tmp = g_strdup_printf("%s%ctmp%d", g_get_tmp_dir(),
746 G_DIR_SEPARATOR, (gint)msginfo);
750 if ((tmpfp = fopen(tmp, "wb")) == NULL) {
751 FILE_OP_ERROR(tmp, "fopen");
754 if (change_file_mode_rw(tmpfp, tmp) < 0) {
755 FILE_OP_ERROR(tmp, "chmod");
756 g_warning("can't change file mode\n");
759 fprintf(tmpfp, "From: %s\r\n", msginfo->from);
760 fprintf(tmpfp, "Newsgroups: %s\r\n", msginfo->newsgroups);
761 fprintf(tmpfp, "Subject: cmsg cancel <%s>\r\n", msginfo->msgid);
762 fprintf(tmpfp, "Control: cancel <%s>\r\n", msginfo->msgid);
763 fprintf(tmpfp, "Approved: %s\r\n", msginfo->from);
764 fprintf(tmpfp, "X-Cancelled-by: %s\r\n", msginfo->from);
765 get_rfc822_date(buf, sizeof(buf));
766 fprintf(tmpfp, "Date: %s\r\n", buf);
767 fprintf(tmpfp, "\r\n");
768 fprintf(tmpfp, "removed with sylpheed\r\n");
772 news_post(folder, tmp);
780 gint news_get_num_list(Folder *folder, FolderItem *item, GSList **msgnum_list)
782 NNTPSession *session;
783 gint i, ok, num, first, last, nummsgs = 0;
786 g_return_val_if_fail(item != NULL, -1);
787 g_return_val_if_fail(item->folder != NULL, -1);
788 g_return_val_if_fail(item->folder->type == F_NEWS, -1);
790 session = news_session_get(folder);
791 g_return_val_if_fail(session != NULL, -1);
793 ok = news_select_group(session, item->path, &num, &first, &last);
794 if (ok != NN_SUCCESS) {
795 log_warning(_("can't set group: %s\n"), item->path);
800 log_warning(_("invalid article range: %d - %d\n"),
805 for(i = first; i <= last; i++) {
806 *msgnum_list = g_slist_prepend(*msgnum_list, GINT_TO_POINTER(i));
810 dir = folder_item_get_path(item);
811 debug_print("removing old messages from %d to %d in %s\n", first, last, dir);
812 remove_numbered_files(dir, 1, first - 1);
818 #define READ_TO_LISTEND(hdr) \
819 while (!(buf[0] == '.' && buf[1] == '\r')) { \
820 if (sock_gets(SESSION(session)->sock, buf, sizeof(buf)) < 0) { \
821 log_warning(_("error occurred while getting %s.\n"), hdr); \
826 MsgInfo *news_get_msginfo(Folder *folder, FolderItem *item, gint num)
828 NNTPSession *session;
829 MsgInfo *msginfo = NULL;
830 gchar buf[NNTPBUFSIZE];
832 session = news_session_get(folder);
833 g_return_val_if_fail(session != NULL, NULL);
834 g_return_val_if_fail(item != NULL, NULL);
835 g_return_val_if_fail(item->folder != NULL, NULL);
836 g_return_val_if_fail(item->folder->type == F_NEWS, NULL);
838 log_message(_("getting xover %d in %s...\n"),
840 if (nntp_xover(session->nntp_sock, num, num) != NN_SUCCESS) {
841 log_warning(_("can't get xover\n"));
845 if (sock_gets(SESSION(session)->sock, buf, sizeof(buf)) < 0) {
846 log_warning(_("error occurred while getting xover.\n"));
850 msginfo = news_parse_xover(buf);
852 log_warning(_("invalid xover line: %s\n"), buf);
855 READ_TO_LISTEND("xover");
860 msginfo->folder = item;
861 msginfo->flags.perm_flags = MSG_NEW|MSG_UNREAD;
862 msginfo->flags.tmp_flags = MSG_NEWS;
863 msginfo->newsgroups = g_strdup(item->path);
865 if (nntp_xhdr(session->nntp_sock, "to", num, num) != NN_SUCCESS) {
866 log_warning(_("can't get xhdr\n"));
870 if (sock_gets(SESSION(session)->sock, buf, sizeof(buf)) < 0) {
871 log_warning(_("error occurred while getting xhdr.\n"));
875 msginfo->to = news_parse_xhdr(buf, msginfo);
877 READ_TO_LISTEND("xhdr (to)");
879 if (nntp_xhdr(session->nntp_sock, "cc", num, num) != NN_SUCCESS) {
880 log_warning(_("can't get xhdr\n"));
884 if (sock_gets(SESSION(session)->sock, buf, sizeof(buf)) < 0) {
885 log_warning(_("error occurred while getting xhdr.\n"));
889 msginfo->cc = news_parse_xhdr(buf, msginfo);
891 READ_TO_LISTEND("xhdr (cc)");
896 static GSList *news_get_msginfos_for_range(NNTPSession *session, FolderItem *item, guint begin, guint end)
898 gchar buf[NNTPBUFSIZE];
899 GSList *newlist = NULL;
900 GSList *llast = NULL;
902 guint count = 0, lines = (end - begin + 2) * 3;
904 g_return_val_if_fail(session != NULL, NULL);
905 g_return_val_if_fail(item != NULL, NULL);
907 log_message(_("getting xover %d - %d in %s...\n"),
908 begin, end, item->path);
909 if (nntp_xover(session->nntp_sock, begin, end) != NN_SUCCESS) {
910 log_warning(_("can't get xover\n"));
915 if (sock_gets(SESSION(session)->sock, buf, sizeof(buf)) < 0) {
916 log_warning(_("error occurred while getting xover.\n"));
920 progressindicator_set_percentage
921 (PROGRESS_TYPE_NETWORK,
922 session->fetch_base_percentage +
923 (((gfloat) count) / ((gfloat) lines)) * session->fetch_total_percentage);
925 if (buf[0] == '.' && buf[1] == '\r') break;
927 msginfo = news_parse_xover(buf);
929 log_warning(_("invalid xover line: %s\n"), buf);
933 msginfo->folder = item;
934 msginfo->flags.perm_flags = MSG_NEW|MSG_UNREAD;
935 msginfo->flags.tmp_flags = MSG_NEWS;
936 msginfo->newsgroups = g_strdup(item->path);
939 llast = newlist = g_slist_append(newlist, msginfo);
941 llast = g_slist_append(llast, msginfo);
946 if (nntp_xhdr(session->nntp_sock, "to", begin, end) != NN_SUCCESS) {
947 log_warning(_("can't get xhdr\n"));
954 if (sock_gets(SESSION(session)->sock, buf, sizeof(buf)) < 0) {
955 log_warning(_("error occurred while getting xhdr.\n"));
959 progressindicator_set_percentage
960 (PROGRESS_TYPE_NETWORK,
961 session->fetch_base_percentage +
962 (((gfloat) count) / ((gfloat) lines)) * session->fetch_total_percentage);
964 if (buf[0] == '.' && buf[1] == '\r') break;
966 g_warning("llast == NULL\n");
970 msginfo = (MsgInfo *)llast->data;
971 msginfo->to = news_parse_xhdr(buf, msginfo);
976 if (nntp_xhdr(session->nntp_sock, "cc", begin, end) != NN_SUCCESS) {
977 log_warning(_("can't get xhdr\n"));
984 if (sock_gets(SESSION(session)->sock, buf, sizeof(buf)) < 0) {
985 log_warning(_("error occurred while getting xhdr.\n"));
989 progressindicator_set_percentage
990 (PROGRESS_TYPE_NETWORK,
991 session->fetch_base_percentage +
992 (((gfloat) count) / ((gfloat) lines)) * session->fetch_total_percentage);
994 if (buf[0] == '.' && buf[1] == '\r') break;
996 g_warning("llast == NULL\n");
1000 msginfo = (MsgInfo *)llast->data;
1001 msginfo->cc = news_parse_xhdr(buf, msginfo);
1003 llast = llast->next;
1009 gint news_fetch_msgnum_sort(gconstpointer a, gconstpointer b)
1011 return (GPOINTER_TO_INT(a) - GPOINTER_TO_INT(b));
1014 GSList *news_get_msginfos(Folder *folder, FolderItem *item, GSList *msgnum_list)
1016 NNTPSession *session;
1017 GSList *elem, *msginfo_list = NULL, *tmp_msgnum_list, *tmp_msginfo_list;
1018 guint first, last, next;
1019 guint tofetch, fetched;
1021 g_return_val_if_fail(folder != NULL, NULL);
1022 g_return_val_if_fail(folder->type == F_NEWS, NULL);
1023 g_return_val_if_fail(msgnum_list != NULL, NULL);
1024 g_return_val_if_fail(item != NULL, NULL);
1026 session = news_session_get(folder);
1027 g_return_val_if_fail(session != NULL, NULL);
1029 tmp_msgnum_list = g_slist_copy(msgnum_list);
1030 tmp_msgnum_list = g_slist_sort(tmp_msgnum_list, news_fetch_msgnum_sort);
1032 progressindicator_start(PROGRESS_TYPE_NETWORK);
1033 tofetch = g_slist_length(tmp_msgnum_list);
1036 first = GPOINTER_TO_INT(tmp_msgnum_list->data);
1038 for(elem = g_slist_next(tmp_msgnum_list); elem != NULL; elem = g_slist_next(elem)) {
1039 next = GPOINTER_TO_INT(elem->data);
1040 if(next != (last + 1)) {
1041 session->fetch_base_percentage = ((gfloat) fetched) / ((gfloat) tofetch);
1042 session->fetch_total_percentage = ((gfloat) (last - first + 1)) / ((gfloat) tofetch);
1043 tmp_msginfo_list = news_get_msginfos_for_range(session, item, first, last);
1044 msginfo_list = g_slist_concat(msginfo_list, tmp_msginfo_list);
1045 fetched = last - first + 1;
1050 session->fetch_base_percentage = ((gfloat) fetched) / ((gfloat) tofetch);
1051 session->fetch_total_percentage = ((gfloat) (last - first + 1)) / ((gfloat) tofetch);
1052 tmp_msginfo_list = news_get_msginfos_for_range(session, item, first, last);
1053 msginfo_list = g_slist_concat(msginfo_list, tmp_msginfo_list);
1055 g_slist_free(tmp_msgnum_list);
1057 progressindicator_stop(PROGRESS_TYPE_NETWORK);
1059 return msginfo_list;