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 Folder *news_folder_new(const gchar *name, const gchar *path)
147 folder = (Folder *)g_new0(NewsFolder, 1);
148 folder->class = &news_class;
149 news_folder_init(folder, name, path);
154 void news_folder_destroy(Folder *folder)
158 dir = folder_get_path(folder);
159 if (is_dir_exist(dir))
160 remove_dir_recursive(dir);
163 folder_remote_folder_destroy(REMOTE_FOLDER(folder));
166 static void news_folder_init(Folder *folder, const gchar *name,
169 folder_remote_folder_init(folder, name, path);
173 static Session *news_session_new(const gchar *server, gushort port,
174 const gchar *userid, const gchar *passwd,
177 static Session *news_session_new(const gchar *server, gushort port,
178 const gchar *userid, const gchar *passwd)
181 gchar buf[NNTPBUFSIZE];
182 NNTPSession *session;
183 NNTPSockInfo *nntp_sock;
185 g_return_val_if_fail(server != NULL, NULL);
187 log_message(_("creating NNTP connection to %s:%d ...\n"), server, port);
190 if (userid && passwd)
191 nntp_sock = nntp_open_auth(server, port, buf, userid, passwd,
194 nntp_sock = nntp_open(server, port, buf, ssl_type);
196 if (userid && passwd)
197 nntp_sock = nntp_open_auth(server, port, buf, userid, passwd);
199 nntp_sock = nntp_open(server, port, buf);
202 if (nntp_sock == NULL)
205 session = g_new(NNTPSession, 1);
206 SESSION(session)->type = SESSION_NEWS;
207 SESSION(session)->server = g_strdup(server);
208 session->nntp_sock = nntp_sock;
209 SESSION(session)->sock = nntp_sock->sock;
210 SESSION(session)->connected = TRUE;
211 SESSION(session)->phase = SESSION_READY;
212 SESSION(session)->last_access_time = time(NULL);
213 SESSION(session)->data = NULL;
215 SESSION(session)->destroy = news_session_destroy;
217 session->group = NULL;
219 return SESSION(session);
222 void news_session_destroy(Session *session)
224 nntp_close(NNTP_SESSION(session)->nntp_sock);
225 NNTP_SESSION(session)->nntp_sock = NULL;
226 session->sock = NULL;
228 g_free(NNTP_SESSION(session)->group);
231 static Session *news_session_new_for_folder(Folder *folder)
235 const gchar *userid = NULL;
236 gchar *passwd = NULL;
238 gchar buf[NNTPBUFSIZE];
240 g_return_val_if_fail(folder != NULL, NULL);
241 g_return_val_if_fail(folder->account != NULL, NULL);
243 ac = folder->account;
244 if (ac->use_nntp_auth && ac->userid && ac->userid[0]) {
246 if (ac->passwd && ac->passwd[0])
247 passwd = g_strdup(ac->passwd);
249 passwd = input_dialog_query_password(ac->nntp_server,
254 port = ac->set_nntpport ? ac->nntpport
255 : ac->ssl_nntp ? NNTPS_PORT : NNTP_PORT;
256 session = news_session_new(ac->nntp_server, port, userid, passwd,
259 port = ac->set_nntpport ? ac->nntpport : NNTP_PORT;
260 session = news_session_new(ac->nntp_server, port, userid, passwd);
262 if ((session != NULL) && ac->use_nntp_auth && ac->use_nntp_auth_onconnect)
263 nntp_forceauth(NNTP_SESSION(session)->nntp_sock, buf, userid, passwd);
270 NNTPSession *news_session_get(Folder *folder)
272 RemoteFolder *rfolder = REMOTE_FOLDER(folder);
274 g_return_val_if_fail(folder != NULL, NULL);
275 g_return_val_if_fail(FOLDER_TYPE(folder) == F_NEWS, NULL);
276 g_return_val_if_fail(folder->account != NULL, NULL);
278 if (!rfolder->session) {
279 rfolder->session = news_session_new_for_folder(folder);
280 return NNTP_SESSION(rfolder->session);
283 if (time(NULL) - rfolder->session->last_access_time < SESSION_TIMEOUT) {
284 rfolder->session->last_access_time = time(NULL);
285 return NNTP_SESSION(rfolder->session);
288 if (nntp_mode(NNTP_SESSION(rfolder->session)->nntp_sock, FALSE)
290 log_warning("NNTP connection to %s:%d has been"
291 " disconnected. Reconnecting...\n",
292 folder->account->nntp_server,
293 folder->account->set_nntpport ?
294 folder->account->nntpport : NNTP_PORT);
295 session_destroy(rfolder->session);
296 rfolder->session = news_session_new_for_folder(folder);
299 if (rfolder->session)
300 rfolder->session->last_access_time = time(NULL);
301 return NNTP_SESSION(rfolder->session);
304 gchar *news_fetch_msg(Folder *folder, FolderItem *item, gint num)
306 gchar *path, *filename;
307 NNTPSession *session;
310 g_return_val_if_fail(folder != NULL, NULL);
311 g_return_val_if_fail(item != NULL, NULL);
313 path = folder_item_get_path(item);
314 if (!is_dir_exist(path))
316 filename = g_strconcat(path, G_DIR_SEPARATOR_S, itos(num), NULL);
319 if (is_file_exist(filename)) {
320 debug_print("article %d has been already cached.\n", num);
324 session = news_session_get(folder);
330 ok = news_select_group(session, item->path, NULL, NULL, NULL);
331 if (ok != NN_SUCCESS) {
332 g_warning("can't select group %s\n", item->path);
337 debug_print("getting article %d...\n", num);
338 ok = news_get_article(NNTP_SESSION(REMOTE_FOLDER(folder)->session),
341 g_warning("can't read article %d\n", num);
342 session_destroy(SESSION(session));
343 REMOTE_FOLDER(folder)->session = NULL;
351 gint news_scan_group(Folder *folder, FolderItem *item)
353 NNTPSession *session;
354 gint num = 0, first = 0, last = 0;
357 g_return_val_if_fail(folder != NULL, -1);
358 g_return_val_if_fail(item != NULL, -1);
360 session = news_session_get(folder);
361 if (!session) return -1;
363 ok = news_select_group(session, item->path, &num, &first, &last);
364 if (ok != NN_SUCCESS) {
365 log_warning("can't set group: %s\n", item->path);
370 item->new = item->unread = item->total = item->last_num = 0;
375 path = folder_item_get_path(item);
376 if (path && is_dir_exist(path)) {
377 procmsg_get_mark_sum(path, &new, &unread, &total, &min, &max,
382 if (max < first || last < min)
383 new = unread = total = num;
390 else if (max < last) {
392 unread += last - max;
395 if (new > num) new = num;
396 if (unread > num) unread = num;
400 item->unread = unread;
402 item->last_num = last;
407 static NewsGroupInfo *news_group_info_new(const gchar *name,
408 gint first, gint last, gchar type)
410 NewsGroupInfo *ginfo;
412 ginfo = g_new(NewsGroupInfo, 1);
413 ginfo->name = g_strdup(name);
414 ginfo->first = first;
421 static void news_group_info_free(NewsGroupInfo *ginfo)
427 static gint news_group_info_compare(NewsGroupInfo *ginfo1,
428 NewsGroupInfo *ginfo2)
430 return g_strcasecmp(ginfo1->name, ginfo2->name);
433 GSList *news_get_group_list(Folder *folder)
435 gchar *path, *filename;
439 gchar buf[NNTPBUFSIZE];
441 g_return_val_if_fail(folder != NULL, NULL);
442 g_return_val_if_fail(FOLDER_TYPE(folder) == F_NEWS, NULL);
444 path = folder_item_get_path(FOLDER_ITEM(folder->node->data));
445 if (!is_dir_exist(path))
447 filename = g_strconcat(path, G_DIR_SEPARATOR_S, NEWSGROUP_LIST, NULL);
450 if ((fp = fopen(filename, "rb")) == NULL) {
451 NNTPSession *session;
453 session = news_session_get(folder);
459 if (nntp_list(session->nntp_sock) != NN_SUCCESS) {
463 if (recv_write_to_file(SESSION(session)->sock, filename) < 0) {
464 log_warning("can't retrieve newsgroup list\n");
465 session_destroy(SESSION(session));
466 REMOTE_FOLDER(folder)->session = NULL;
471 if ((fp = fopen(filename, "rb")) == NULL) {
472 FILE_OP_ERROR(filename, "fopen");
478 while (fgets(buf, sizeof(buf), fp) != NULL) {
484 NewsGroupInfo *ginfo;
492 if (sscanf(p, "%d %d %c", &last_num, &first_num, &type) < 3)
495 ginfo = news_group_info_new(name, first_num, last_num, type);
498 last = list = g_slist_append(NULL, ginfo);
500 last = g_slist_append(last, ginfo);
508 list = g_slist_sort(list, (GCompareFunc)news_group_info_compare);
513 void news_group_list_free(GSList *group_list)
517 if (!group_list) return;
519 for (cur = group_list; cur != NULL; cur = cur->next)
520 news_group_info_free((NewsGroupInfo *)cur->data);
521 g_slist_free(group_list);
524 void news_remove_group_list_cache(Folder *folder)
526 gchar *path, *filename;
528 g_return_if_fail(folder != NULL);
529 g_return_if_fail(FOLDER_TYPE(folder) == F_NEWS);
531 path = folder_item_get_path(FOLDER_ITEM(folder->node->data));
532 filename = g_strconcat(path, G_DIR_SEPARATOR_S, NEWSGROUP_LIST, NULL);
535 if (is_file_exist(filename)) {
536 if (remove(filename) < 0)
537 FILE_OP_ERROR(filename, "remove");
542 gint news_post(Folder *folder, const gchar *file)
547 g_return_val_if_fail(folder != NULL, -1);
548 g_return_val_if_fail(FOLDER_TYPE(folder) == F_NEWS, -1);
549 g_return_val_if_fail(file != NULL, -1);
551 if ((fp = fopen(file, "rb")) == NULL) {
552 FILE_OP_ERROR(file, "fopen");
556 ok = news_post_stream(folder, fp);
563 gint news_post_stream(Folder *folder, FILE *fp)
565 NNTPSession *session;
568 g_return_val_if_fail(folder != NULL, -1);
569 g_return_val_if_fail(FOLDER_TYPE(folder) == F_NEWS, -1);
570 g_return_val_if_fail(fp != NULL, -1);
572 session = news_session_get(folder);
573 if (!session) return -1;
575 ok = nntp_post(session->nntp_sock, fp);
576 if (ok != NN_SUCCESS) {
577 log_warning("can't post article.\n");
584 static gint news_get_article_cmd(NNTPSession *session, const gchar *cmd,
585 gint num, gchar *filename)
589 if (nntp_get_article(session->nntp_sock, cmd, num, &msgid)
593 debug_print("Message-Id = %s, num = %d\n", msgid, num);
596 if (recv_write_to_file(session->nntp_sock->sock, filename) < 0) {
597 log_warning("can't retrieve article %d\n", num);
604 static gint news_remove_msg(Folder *folder, FolderItem *item, gint num)
609 dir = folder_item_get_path(item);
610 debug_print("news_remove_msg: removing msg %d in %s\n",num,dir);
611 r = remove_numbered_files(dir, num, num);
617 static gint news_get_article(NNTPSession *session, gint num, gchar *filename)
619 return news_get_article_cmd(session, "ARTICLE", num, filename);
624 * @session: Active NNTP session.
625 * @group: Newsgroup name.
626 * @num: Estimated number of articles.
627 * @first: First article number.
628 * @last: Last article number.
630 * Select newsgroup @group with the GROUP command if it is not already
631 * selected in @session, or article numbers need to be returned.
633 * Return value: NNTP result code.
635 static gint news_select_group(NNTPSession *session, const gchar *group,
636 gint *num, gint *first, gint *last)
639 gint num_, first_, last_;
641 if (!num || !first || !last) {
642 if (session->group && g_strcasecmp(session->group, group) == 0)
649 g_free(session->group);
650 session->group = NULL;
652 ok = nntp_group(session->nntp_sock, group, num, first, last);
653 if (ok == NN_SUCCESS)
654 session->group = g_strdup(group);
659 #define PARSE_ONE_PARAM(p, srcp) \
661 p = strchr(srcp, '\t'); \
662 if (!p) return NULL; \
667 static MsgInfo *news_parse_xover(const gchar *xover_str)
670 gchar buf[NNTPBUFSIZE];
671 gchar *subject, *sender, *size, *line, *date, *msgid, *ref, *tmp, *xref;
673 gint num, size_int, line_int;
676 Xstrdup_a(xover_buf, xover_str, return NULL);
678 PARSE_ONE_PARAM(subject, xover_buf);
679 PARSE_ONE_PARAM(sender, subject);
680 PARSE_ONE_PARAM(date, sender);
681 PARSE_ONE_PARAM(msgid, date);
682 PARSE_ONE_PARAM(ref, msgid);
683 PARSE_ONE_PARAM(size, ref);
684 PARSE_ONE_PARAM(line, size);
685 PARSE_ONE_PARAM(xref, line);
687 tmp = strchr(xref, '\t');
688 if (!tmp) tmp = strchr(line, '\r');
689 if (!tmp) tmp = strchr(line, '\n');
690 if (tmp) *tmp = '\0';
692 num = atoi(xover_str);
693 size_int = atoi(size);
694 line_int = atoi(line);
697 msginfo = procmsg_msginfo_new();
698 msginfo->msgnum = num;
699 msginfo->size = size_int;
701 msginfo->date = g_strdup(date);
702 msginfo->date_t = procheader_date_parse(NULL, date, 0);
704 conv_unmime_header(buf, sizeof(buf), sender, NULL);
705 msginfo->from = g_strdup(buf);
706 msginfo->fromname = procheader_get_fromname(buf);
708 conv_unmime_header(buf, sizeof(buf), subject, NULL);
709 msginfo->subject = g_strdup(buf);
711 extract_parenthesis(msgid, '<', '>');
714 msginfo->msgid = g_strdup(msgid);
716 msginfo->references = g_strdup(ref);
717 eliminate_parenthesis(ref, '(', ')');
718 if ((p = strrchr(ref, '<')) != NULL) {
719 extract_parenthesis(p, '<', '>');
722 msginfo->inreplyto = g_strdup(p);
725 msginfo->xref = g_strdup(xref);
726 p = msginfo->xref+strlen(msginfo->xref) - 1;
727 while (*p == '\r' || *p == '\n') {
735 static gchar *news_parse_xhdr(const gchar *xhdr_str, MsgInfo *msginfo)
741 p = strchr(xhdr_str, ' ');
747 num = atoi(xhdr_str);
748 if (msginfo->msgnum != num) return NULL;
750 tmp = strchr(p, '\r');
751 if (!tmp) tmp = strchr(p, '\n');
754 return g_strndup(p, tmp - p);
759 gint news_cancel_article(Folder * folder, MsgInfo * msginfo)
765 tmp = g_strdup_printf("%s%ctmp%d", g_get_tmp_dir(),
766 G_DIR_SEPARATOR, (gint)msginfo);
770 if ((tmpfp = fopen(tmp, "wb")) == NULL) {
771 FILE_OP_ERROR(tmp, "fopen");
774 if (change_file_mode_rw(tmpfp, tmp) < 0) {
775 FILE_OP_ERROR(tmp, "chmod");
776 g_warning("can't change file mode\n");
779 fprintf(tmpfp, "From: %s\r\n", msginfo->from);
780 fprintf(tmpfp, "Newsgroups: %s\r\n", msginfo->newsgroups);
781 fprintf(tmpfp, "Subject: cmsg cancel <%s>\r\n", msginfo->msgid);
782 fprintf(tmpfp, "Control: cancel <%s>\r\n", msginfo->msgid);
783 fprintf(tmpfp, "Approved: %s\r\n", msginfo->from);
784 fprintf(tmpfp, "X-Cancelled-by: %s\r\n", msginfo->from);
785 get_rfc822_date(buf, sizeof(buf));
786 fprintf(tmpfp, "Date: %s\r\n", buf);
787 fprintf(tmpfp, "\r\n");
788 fprintf(tmpfp, "removed with sylpheed\r\n");
792 news_post(folder, tmp);
800 gint news_get_num_list(Folder *folder, FolderItem *item, GSList **msgnum_list)
802 NNTPSession *session;
803 gint i, ok, num, first, last, nummsgs = 0;
806 g_return_val_if_fail(item != NULL, -1);
807 g_return_val_if_fail(item->folder != NULL, -1);
808 g_return_val_if_fail(FOLDER_TYPE(folder) == F_NEWS, -1);
810 session = news_session_get(folder);
811 g_return_val_if_fail(session != NULL, -1);
813 ok = news_select_group(session, item->path, &num, &first, &last);
814 if (ok != NN_SUCCESS) {
815 log_warning(_("can't set group: %s\n"), item->path);
820 log_warning(_("invalid article range: %d - %d\n"),
825 for(i = first; i <= last; i++) {
826 *msgnum_list = g_slist_prepend(*msgnum_list, GINT_TO_POINTER(i));
830 dir = folder_item_get_path(item);
831 debug_print("removing old messages from %d to %d in %s\n", first, last, dir);
832 remove_numbered_files(dir, 1, first - 1);
838 #define READ_TO_LISTEND(hdr) \
839 while (!(buf[0] == '.' && buf[1] == '\r')) { \
840 if (sock_gets(SESSION(session)->sock, buf, sizeof(buf)) < 0) { \
841 log_warning(_("error occurred while getting %s.\n"), hdr); \
846 MsgInfo *news_get_msginfo(Folder *folder, FolderItem *item, gint num)
848 NNTPSession *session;
849 MsgInfo *msginfo = NULL;
850 gchar buf[NNTPBUFSIZE];
852 session = news_session_get(folder);
853 g_return_val_if_fail(session != NULL, NULL);
854 g_return_val_if_fail(item != NULL, NULL);
855 g_return_val_if_fail(item->folder != NULL, NULL);
856 g_return_val_if_fail(FOLDER_TYPE(item->folder) == F_NEWS, NULL);
858 log_message(_("getting xover %d in %s...\n"),
860 if (nntp_xover(session->nntp_sock, num, num) != NN_SUCCESS) {
861 log_warning(_("can't get xover\n"));
865 if (sock_gets(SESSION(session)->sock, buf, sizeof(buf)) < 0) {
866 log_warning(_("error occurred while getting xover.\n"));
870 msginfo = news_parse_xover(buf);
872 log_warning(_("invalid xover line: %s\n"), buf);
875 READ_TO_LISTEND("xover");
880 msginfo->folder = item;
881 msginfo->flags.perm_flags = MSG_NEW|MSG_UNREAD;
882 msginfo->flags.tmp_flags = MSG_NEWS;
883 msginfo->newsgroups = g_strdup(item->path);
885 if (nntp_xhdr(session->nntp_sock, "to", num, num) != NN_SUCCESS) {
886 log_warning(_("can't get xhdr\n"));
890 if (sock_gets(SESSION(session)->sock, buf, sizeof(buf)) < 0) {
891 log_warning(_("error occurred while getting xhdr.\n"));
895 msginfo->to = news_parse_xhdr(buf, msginfo);
897 READ_TO_LISTEND("xhdr (to)");
899 if (nntp_xhdr(session->nntp_sock, "cc", num, num) != NN_SUCCESS) {
900 log_warning(_("can't get xhdr\n"));
904 if (sock_gets(SESSION(session)->sock, buf, sizeof(buf)) < 0) {
905 log_warning(_("error occurred while getting xhdr.\n"));
909 msginfo->cc = news_parse_xhdr(buf, msginfo);
911 READ_TO_LISTEND("xhdr (cc)");
916 static GSList *news_get_msginfos_for_range(NNTPSession *session, FolderItem *item, guint begin, guint end)
918 gchar buf[NNTPBUFSIZE];
919 GSList *newlist = NULL;
920 GSList *llast = NULL;
922 guint count = 0, lines = (end - begin + 2) * 3;
924 g_return_val_if_fail(session != NULL, NULL);
925 g_return_val_if_fail(item != NULL, NULL);
927 log_message(_("getting xover %d - %d in %s...\n"),
928 begin, end, item->path);
929 if (nntp_xover(session->nntp_sock, begin, end) != NN_SUCCESS) {
930 log_warning(_("can't get xover\n"));
935 if (sock_gets(SESSION(session)->sock, buf, sizeof(buf)) < 0) {
936 log_warning(_("error occurred while getting xover.\n"));
940 progressindicator_set_percentage
941 (PROGRESS_TYPE_NETWORK,
942 session->fetch_base_percentage +
943 (((gfloat) count) / ((gfloat) lines)) * session->fetch_total_percentage);
945 if (buf[0] == '.' && buf[1] == '\r') break;
947 msginfo = news_parse_xover(buf);
949 log_warning(_("invalid xover line: %s\n"), buf);
953 msginfo->folder = item;
954 msginfo->flags.perm_flags = MSG_NEW|MSG_UNREAD;
955 msginfo->flags.tmp_flags = MSG_NEWS;
956 msginfo->newsgroups = g_strdup(item->path);
959 llast = newlist = g_slist_append(newlist, msginfo);
961 llast = g_slist_append(llast, msginfo);
966 if (nntp_xhdr(session->nntp_sock, "to", begin, end) != NN_SUCCESS) {
967 log_warning(_("can't get xhdr\n"));
974 if (sock_gets(SESSION(session)->sock, buf, sizeof(buf)) < 0) {
975 log_warning(_("error occurred while getting xhdr.\n"));
979 progressindicator_set_percentage
980 (PROGRESS_TYPE_NETWORK,
981 session->fetch_base_percentage +
982 (((gfloat) count) / ((gfloat) lines)) * session->fetch_total_percentage);
984 if (buf[0] == '.' && buf[1] == '\r') break;
986 g_warning("llast == NULL\n");
990 msginfo = (MsgInfo *)llast->data;
991 msginfo->to = news_parse_xhdr(buf, msginfo);
996 if (nntp_xhdr(session->nntp_sock, "cc", begin, end) != NN_SUCCESS) {
997 log_warning(_("can't get xhdr\n"));
1004 if (sock_gets(SESSION(session)->sock, buf, sizeof(buf)) < 0) {
1005 log_warning(_("error occurred while getting xhdr.\n"));
1009 progressindicator_set_percentage
1010 (PROGRESS_TYPE_NETWORK,
1011 session->fetch_base_percentage +
1012 (((gfloat) count) / ((gfloat) lines)) * session->fetch_total_percentage);
1014 if (buf[0] == '.' && buf[1] == '\r') break;
1016 g_warning("llast == NULL\n");
1020 msginfo = (MsgInfo *)llast->data;
1021 msginfo->cc = news_parse_xhdr(buf, msginfo);
1023 llast = llast->next;
1029 gint news_fetch_msgnum_sort(gconstpointer a, gconstpointer b)
1031 return (GPOINTER_TO_INT(a) - GPOINTER_TO_INT(b));
1034 GSList *news_get_msginfos(Folder *folder, FolderItem *item, GSList *msgnum_list)
1036 NNTPSession *session;
1037 GSList *elem, *msginfo_list = NULL, *tmp_msgnum_list, *tmp_msginfo_list;
1038 guint first, last, next;
1039 guint tofetch, fetched;
1041 g_return_val_if_fail(folder != NULL, NULL);
1042 g_return_val_if_fail(FOLDER_TYPE(folder) == F_NEWS, NULL);
1043 g_return_val_if_fail(msgnum_list != NULL, NULL);
1044 g_return_val_if_fail(item != NULL, NULL);
1046 session = news_session_get(folder);
1047 g_return_val_if_fail(session != NULL, NULL);
1049 tmp_msgnum_list = g_slist_copy(msgnum_list);
1050 tmp_msgnum_list = g_slist_sort(tmp_msgnum_list, news_fetch_msgnum_sort);
1052 progressindicator_start(PROGRESS_TYPE_NETWORK);
1053 tofetch = g_slist_length(tmp_msgnum_list);
1056 first = GPOINTER_TO_INT(tmp_msgnum_list->data);
1058 for(elem = g_slist_next(tmp_msgnum_list); elem != NULL; elem = g_slist_next(elem)) {
1059 next = GPOINTER_TO_INT(elem->data);
1060 if(next != (last + 1)) {
1061 session->fetch_base_percentage = ((gfloat) fetched) / ((gfloat) tofetch);
1062 session->fetch_total_percentage = ((gfloat) (last - first + 1)) / ((gfloat) tofetch);
1063 tmp_msginfo_list = news_get_msginfos_for_range(session, item, first, last);
1064 msginfo_list = g_slist_concat(msginfo_list, tmp_msginfo_list);
1065 fetched = last - first + 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);
1075 g_slist_free(tmp_msgnum_list);
1077 progressindicator_stop(PROGRESS_TYPE_NETWORK);
1079 return msginfo_list;