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"
49 #include "alertpanel.h"
51 #include "progressindicator.h"
58 #define NNTPS_PORT 563
61 static void news_folder_init (Folder *folder,
66 static Session *news_session_new (const gchar *server,
72 static Session *news_session_new (const gchar *server,
78 static gint news_get_article_cmd (NNTPSession *session,
82 static gint news_get_article (NNTPSession *session,
86 static gint news_select_group (NNTPSession *session,
91 static MsgInfo *news_parse_xover (const gchar *xover_str);
92 static gchar *news_parse_xhdr (const gchar *xhdr_str,
94 static gint news_remove_msg (Folder *folder,
97 gint news_get_num_list (Folder *folder,
100 MsgInfo *news_get_msginfo (Folder *folder,
103 GSList *news_get_msginfos (Folder *folder,
105 GSList *msgnum_list);
107 gint news_post_stream (Folder *folder,
110 Folder *news_folder_new(const gchar *name, const gchar *path)
114 folder = (Folder *)g_new0(NewsFolder, 1);
115 news_folder_init(folder, name, path);
120 void news_folder_destroy(Folder *folder)
124 dir = folder_get_path(folder);
125 if (is_dir_exist(dir))
126 remove_dir_recursive(dir);
129 folder_remote_folder_destroy(REMOTE_FOLDER(folder));
132 static void news_folder_init(Folder *folder, const gchar *name,
135 folder->type = F_NEWS;
137 folder_remote_folder_init(folder, name, path);
140 folder->get_msg_list = news_get_article_list;
142 folder->fetch_msg = news_fetch_msg;
144 folder->scan = news_scan_group;
146 folder->destroy = news_folder_destroy;
147 folder->remove_msg = news_remove_msg;
148 folder->get_num_list = news_get_num_list;
149 folder->get_msginfo = news_get_msginfo;
150 folder->get_msginfos = news_get_msginfos;
154 static Session *news_session_new(const gchar *server, gushort port,
155 const gchar *userid, const gchar *passwd,
158 static Session *news_session_new(const gchar *server, gushort port,
159 const gchar *userid, const gchar *passwd)
162 gchar buf[NNTPBUFSIZE];
163 NNTPSession *session;
164 NNTPSockInfo *nntp_sock;
166 g_return_val_if_fail(server != NULL, NULL);
168 log_message(_("creating NNTP connection to %s:%d ...\n"), server, port);
171 if (userid && passwd)
172 nntp_sock = nntp_open_auth(server, port, buf, userid, passwd,
175 nntp_sock = nntp_open(server, port, buf, ssl_type);
177 if (userid && passwd)
178 nntp_sock = nntp_open_auth(server, port, buf, userid, passwd);
180 nntp_sock = nntp_open(server, port, buf);
183 if (nntp_sock == NULL)
186 session = g_new(NNTPSession, 1);
187 SESSION(session)->type = SESSION_NEWS;
188 SESSION(session)->server = g_strdup(server);
189 session->nntp_sock = nntp_sock;
190 SESSION(session)->sock = nntp_sock->sock;
191 SESSION(session)->connected = TRUE;
192 SESSION(session)->phase = SESSION_READY;
193 SESSION(session)->last_access_time = time(NULL);
194 SESSION(session)->data = NULL;
196 SESSION(session)->destroy = news_session_destroy;
198 session->group = NULL;
200 return SESSION(session);
203 void news_session_destroy(Session *session)
205 nntp_close(NNTP_SESSION(session)->nntp_sock);
206 NNTP_SESSION(session)->nntp_sock = NULL;
207 session->sock = NULL;
209 g_free(NNTP_SESSION(session)->group);
212 static Session *news_session_new_for_folder(Folder *folder)
216 const gchar *userid = NULL;
217 gchar *passwd = NULL;
219 gchar buf[NNTPBUFSIZE];
221 g_return_val_if_fail(folder != NULL, NULL);
222 g_return_val_if_fail(folder->account != NULL, NULL);
224 ac = folder->account;
225 if (ac->use_nntp_auth && ac->userid && ac->userid[0]) {
227 if (ac->passwd && ac->passwd[0])
228 passwd = g_strdup(ac->passwd);
230 passwd = input_dialog_query_password(ac->nntp_server,
235 port = ac->set_nntpport ? ac->nntpport
236 : ac->ssl_nntp ? NNTPS_PORT : NNTP_PORT;
237 session = news_session_new(ac->nntp_server, port, userid, passwd,
240 port = ac->set_nntpport ? ac->nntpport : NNTP_PORT;
241 session = news_session_new(ac->nntp_server, port, userid, passwd);
243 if ((session != NULL) && ac->use_nntp_auth && ac->use_nntp_auth_onconnect)
244 nntp_forceauth(NNTP_SESSION(session)->nntp_sock, buf, userid, passwd);
251 NNTPSession *news_session_get(Folder *folder)
253 RemoteFolder *rfolder = REMOTE_FOLDER(folder);
255 g_return_val_if_fail(folder != NULL, NULL);
256 g_return_val_if_fail(folder->type == F_NEWS, NULL);
257 g_return_val_if_fail(folder->account != NULL, NULL);
259 if (!rfolder->session) {
260 rfolder->session = news_session_new_for_folder(folder);
261 return NNTP_SESSION(rfolder->session);
264 if (time(NULL) - rfolder->session->last_access_time < SESSION_TIMEOUT) {
265 rfolder->session->last_access_time = time(NULL);
266 return NNTP_SESSION(rfolder->session);
269 if (nntp_mode(NNTP_SESSION(rfolder->session)->nntp_sock, FALSE)
271 log_warning("NNTP connection to %s:%d has been"
272 " disconnected. Reconnecting...\n",
273 folder->account->nntp_server,
274 folder->account->set_nntpport ?
275 folder->account->nntpport : NNTP_PORT);
276 session_destroy(rfolder->session);
277 rfolder->session = news_session_new_for_folder(folder);
280 if (rfolder->session)
281 rfolder->session->last_access_time = time(NULL);
282 return NNTP_SESSION(rfolder->session);
285 gchar *news_fetch_msg(Folder *folder, FolderItem *item, gint num)
287 gchar *path, *filename;
288 NNTPSession *session;
291 g_return_val_if_fail(folder != NULL, NULL);
292 g_return_val_if_fail(item != NULL, NULL);
294 path = folder_item_get_path(item);
295 if (!is_dir_exist(path))
297 filename = g_strconcat(path, G_DIR_SEPARATOR_S, itos(num), NULL);
300 if (is_file_exist(filename)) {
301 debug_print("article %d has been already cached.\n", num);
305 session = news_session_get(folder);
311 ok = news_select_group(session, item->path, NULL, NULL, NULL);
312 if (ok != NN_SUCCESS) {
313 g_warning("can't select group %s\n", item->path);
318 debug_print("getting article %d...\n", num);
319 ok = news_get_article(NNTP_SESSION(REMOTE_FOLDER(folder)->session),
322 g_warning("can't read article %d\n", num);
323 session_destroy(SESSION(session));
324 REMOTE_FOLDER(folder)->session = NULL;
332 gint news_scan_group(Folder *folder, FolderItem *item)
334 NNTPSession *session;
335 gint num = 0, first = 0, last = 0;
338 g_return_val_if_fail(folder != NULL, -1);
339 g_return_val_if_fail(item != NULL, -1);
341 session = news_session_get(folder);
342 if (!session) return -1;
344 ok = news_select_group(session, item->path, &num, &first, &last);
345 if (ok != NN_SUCCESS) {
346 log_warning("can't set group: %s\n", item->path);
351 item->new = item->unread = item->total = item->last_num = 0;
356 path = folder_item_get_path(item);
357 if (path && is_dir_exist(path)) {
358 procmsg_get_mark_sum(path, &new, &unread, &total, &min, &max,
363 if (max < first || last < min)
364 new = unread = total = num;
371 else if (max < last) {
373 unread += last - max;
376 if (new > num) new = num;
377 if (unread > num) unread = num;
381 item->unread = unread;
383 item->last_num = last;
388 static NewsGroupInfo *news_group_info_new(const gchar *name,
389 gint first, gint last, gchar type)
391 NewsGroupInfo *ginfo;
393 ginfo = g_new(NewsGroupInfo, 1);
394 ginfo->name = g_strdup(name);
395 ginfo->first = first;
402 static void news_group_info_free(NewsGroupInfo *ginfo)
408 static gint news_group_info_compare(NewsGroupInfo *ginfo1,
409 NewsGroupInfo *ginfo2)
411 return g_strcasecmp(ginfo1->name, ginfo2->name);
414 GSList *news_get_group_list(Folder *folder)
416 gchar *path, *filename;
420 gchar buf[NNTPBUFSIZE];
422 g_return_val_if_fail(folder != NULL, NULL);
423 g_return_val_if_fail(folder->type == F_NEWS, NULL);
425 path = folder_item_get_path(FOLDER_ITEM(folder->node->data));
426 if (!is_dir_exist(path))
428 filename = g_strconcat(path, G_DIR_SEPARATOR_S, NEWSGROUP_LIST, NULL);
431 if ((fp = fopen(filename, "rb")) == NULL) {
432 NNTPSession *session;
434 session = news_session_get(folder);
440 if (nntp_list(session->nntp_sock) != NN_SUCCESS) {
444 if (recv_write_to_file(SESSION(session)->sock, filename) < 0) {
445 log_warning("can't retrieve newsgroup list\n");
446 session_destroy(SESSION(session));
447 REMOTE_FOLDER(folder)->session = NULL;
452 if ((fp = fopen(filename, "rb")) == NULL) {
453 FILE_OP_ERROR(filename, "fopen");
459 while (fgets(buf, sizeof(buf), fp) != NULL) {
465 NewsGroupInfo *ginfo;
473 if (sscanf(p, "%d %d %c", &last_num, &first_num, &type) < 3)
476 ginfo = news_group_info_new(name, first_num, last_num, type);
479 last = list = g_slist_append(NULL, ginfo);
481 last = g_slist_append(last, ginfo);
489 list = g_slist_sort(list, (GCompareFunc)news_group_info_compare);
494 void news_group_list_free(GSList *group_list)
498 if (!group_list) return;
500 for (cur = group_list; cur != NULL; cur = cur->next)
501 news_group_info_free((NewsGroupInfo *)cur->data);
502 g_slist_free(group_list);
505 void news_remove_group_list_cache(Folder *folder)
507 gchar *path, *filename;
509 g_return_if_fail(folder != NULL);
510 g_return_if_fail(folder->type == F_NEWS);
512 path = folder_item_get_path(FOLDER_ITEM(folder->node->data));
513 filename = g_strconcat(path, G_DIR_SEPARATOR_S, NEWSGROUP_LIST, NULL);
516 if (is_file_exist(filename)) {
517 if (remove(filename) < 0)
518 FILE_OP_ERROR(filename, "remove");
523 gint news_post(Folder *folder, const gchar *file)
528 g_return_val_if_fail(folder != NULL, -1);
529 g_return_val_if_fail(folder->type == F_NEWS, -1);
530 g_return_val_if_fail(file != NULL, -1);
532 if ((fp = fopen(file, "rb")) == NULL) {
533 FILE_OP_ERROR(file, "fopen");
537 ok = news_post_stream(folder, fp);
544 gint news_post_stream(Folder *folder, FILE *fp)
546 NNTPSession *session;
549 g_return_val_if_fail(folder != NULL, -1);
550 g_return_val_if_fail(folder->type == F_NEWS, -1);
551 g_return_val_if_fail(fp != NULL, -1);
553 session = news_session_get(folder);
554 if (!session) return -1;
556 ok = nntp_post(session->nntp_sock, fp);
557 if (ok != NN_SUCCESS) {
558 log_warning("can't post article.\n");
565 static gint news_get_article_cmd(NNTPSession *session, const gchar *cmd,
566 gint num, gchar *filename)
570 if (nntp_get_article(session->nntp_sock, cmd, num, &msgid)
574 debug_print("Message-Id = %s, num = %d\n", msgid, num);
577 if (recv_write_to_file(session->nntp_sock->sock, filename) < 0) {
578 log_warning("can't retrieve article %d\n", num);
585 static gint news_remove_msg(Folder *folder, FolderItem *item, gint num)
590 dir = folder_item_get_path(item);
591 debug_print("news_remove_msg: removing msg %d in %s\n",num,dir);
592 r = remove_numbered_files(dir, num, num);
598 static gint news_get_article(NNTPSession *session, gint num, gchar *filename)
600 return news_get_article_cmd(session, "ARTICLE", num, filename);
605 * @session: Active NNTP session.
606 * @group: Newsgroup name.
607 * @num: Estimated number of articles.
608 * @first: First article number.
609 * @last: Last article number.
611 * Select newsgroup @group with the GROUP command if it is not already
612 * selected in @session, or article numbers need to be returned.
614 * Return value: NNTP result code.
616 static gint news_select_group(NNTPSession *session, const gchar *group,
617 gint *num, gint *first, gint *last)
620 gint num_, first_, last_;
622 if (!num || !first || !last) {
623 if (session->group && g_strcasecmp(session->group, group) == 0)
630 g_free(session->group);
631 session->group = NULL;
633 ok = nntp_group(session->nntp_sock, group, num, first, last);
634 if (ok == NN_SUCCESS)
635 session->group = g_strdup(group);
640 #define PARSE_ONE_PARAM(p, srcp) \
642 p = strchr(srcp, '\t'); \
643 if (!p) return NULL; \
648 static MsgInfo *news_parse_xover(const gchar *xover_str)
651 gchar buf[NNTPBUFSIZE];
652 gchar *subject, *sender, *size, *line, *date, *msgid, *ref, *tmp, *xref;
654 gint num, size_int, line_int;
657 Xstrdup_a(xover_buf, xover_str, return NULL);
659 PARSE_ONE_PARAM(subject, xover_buf);
660 PARSE_ONE_PARAM(sender, subject);
661 PARSE_ONE_PARAM(date, sender);
662 PARSE_ONE_PARAM(msgid, date);
663 PARSE_ONE_PARAM(ref, msgid);
664 PARSE_ONE_PARAM(size, ref);
665 PARSE_ONE_PARAM(line, size);
666 PARSE_ONE_PARAM(xref, line);
668 tmp = strchr(xref, '\t');
669 if (!tmp) tmp = strchr(line, '\r');
670 if (!tmp) tmp = strchr(line, '\n');
671 if (tmp) *tmp = '\0';
673 num = atoi(xover_str);
674 size_int = atoi(size);
675 line_int = atoi(line);
678 msginfo = procmsg_msginfo_new();
679 msginfo->msgnum = num;
680 msginfo->size = size_int;
682 msginfo->date = g_strdup(date);
683 msginfo->date_t = procheader_date_parse(NULL, date, 0);
685 conv_unmime_header(buf, sizeof(buf), sender, NULL);
686 msginfo->from = g_strdup(buf);
687 msginfo->fromname = procheader_get_fromname(buf);
689 conv_unmime_header(buf, sizeof(buf), subject, NULL);
690 msginfo->subject = g_strdup(buf);
692 extract_parenthesis(msgid, '<', '>');
695 msginfo->msgid = g_strdup(msgid);
697 msginfo->references = g_strdup(ref);
698 eliminate_parenthesis(ref, '(', ')');
699 if ((p = strrchr(ref, '<')) != NULL) {
700 extract_parenthesis(p, '<', '>');
703 msginfo->inreplyto = g_strdup(p);
706 msginfo->xref = g_strdup(xref);
707 p = msginfo->xref+strlen(msginfo->xref) - 1;
708 while (*p == '\r' || *p == '\n') {
716 static gchar *news_parse_xhdr(const gchar *xhdr_str, MsgInfo *msginfo)
722 p = strchr(xhdr_str, ' ');
728 num = atoi(xhdr_str);
729 if (msginfo->msgnum != num) return NULL;
731 tmp = strchr(p, '\r');
732 if (!tmp) tmp = strchr(p, '\n');
735 return g_strndup(p, tmp - p);
740 gint news_cancel_article(Folder * folder, MsgInfo * msginfo)
746 tmp = g_strdup_printf("%s%ctmp%d", g_get_tmp_dir(),
747 G_DIR_SEPARATOR, (gint)msginfo);
751 if ((tmpfp = fopen(tmp, "wb")) == NULL) {
752 FILE_OP_ERROR(tmp, "fopen");
755 if (change_file_mode_rw(tmpfp, tmp) < 0) {
756 FILE_OP_ERROR(tmp, "chmod");
757 g_warning("can't change file mode\n");
760 fprintf(tmpfp, "From: %s\r\n", msginfo->from);
761 fprintf(tmpfp, "Newsgroups: %s\r\n", msginfo->newsgroups);
762 fprintf(tmpfp, "Subject: cmsg cancel <%s>\r\n", msginfo->msgid);
763 fprintf(tmpfp, "Control: cancel <%s>\r\n", msginfo->msgid);
764 fprintf(tmpfp, "Approved: %s\r\n", msginfo->from);
765 fprintf(tmpfp, "X-Cancelled-by: %s\r\n", msginfo->from);
766 get_rfc822_date(buf, sizeof(buf));
767 fprintf(tmpfp, "Date: %s\r\n", buf);
768 fprintf(tmpfp, "\r\n");
769 fprintf(tmpfp, "removed with sylpheed\r\n");
773 news_post(folder, tmp);
781 gint news_get_num_list(Folder *folder, FolderItem *item, GSList **msgnum_list)
783 NNTPSession *session;
784 gint i, ok, num, first, last, nummsgs = 0;
787 g_return_val_if_fail(item != NULL, -1);
788 g_return_val_if_fail(item->folder != NULL, -1);
789 g_return_val_if_fail(item->folder->type == F_NEWS, -1);
791 session = news_session_get(folder);
792 g_return_val_if_fail(session != NULL, -1);
794 ok = news_select_group(session, item->path, &num, &first, &last);
795 if (ok != NN_SUCCESS) {
796 log_warning(_("can't set group: %s\n"), item->path);
801 log_warning(_("invalid article range: %d - %d\n"),
806 for(i = first; i <= last; i++) {
807 *msgnum_list = g_slist_prepend(*msgnum_list, GINT_TO_POINTER(i));
811 dir = folder_item_get_path(item);
812 debug_print("removing old messages from %d to %d in %s\n", first, last, dir);
813 remove_numbered_files(dir, 1, first - 1);
819 #define READ_TO_LISTEND(hdr) \
820 while (!(buf[0] == '.' && buf[1] == '\r')) { \
821 if (sock_gets(SESSION(session)->sock, buf, sizeof(buf)) < 0) { \
822 log_warning(_("error occurred while getting %s.\n"), hdr); \
827 MsgInfo *news_get_msginfo(Folder *folder, FolderItem *item, gint num)
829 NNTPSession *session;
830 MsgInfo *msginfo = NULL;
831 gchar buf[NNTPBUFSIZE];
833 session = news_session_get(folder);
834 g_return_val_if_fail(session != NULL, NULL);
835 g_return_val_if_fail(item != NULL, NULL);
836 g_return_val_if_fail(item->folder != NULL, NULL);
837 g_return_val_if_fail(item->folder->type == F_NEWS, NULL);
839 log_message(_("getting xover %d in %s...\n"),
841 if (nntp_xover(session->nntp_sock, num, num) != NN_SUCCESS) {
842 log_warning(_("can't get xover\n"));
846 if (sock_gets(SESSION(session)->sock, buf, sizeof(buf)) < 0) {
847 log_warning(_("error occurred while getting xover.\n"));
851 msginfo = news_parse_xover(buf);
853 log_warning(_("invalid xover line: %s\n"), buf);
856 READ_TO_LISTEND("xover");
861 msginfo->folder = item;
862 msginfo->flags.perm_flags = MSG_NEW|MSG_UNREAD;
863 msginfo->flags.tmp_flags = MSG_NEWS;
864 msginfo->newsgroups = g_strdup(item->path);
866 if (nntp_xhdr(session->nntp_sock, "to", num, num) != NN_SUCCESS) {
867 log_warning(_("can't get xhdr\n"));
871 if (sock_gets(SESSION(session)->sock, buf, sizeof(buf)) < 0) {
872 log_warning(_("error occurred while getting xhdr.\n"));
876 msginfo->to = news_parse_xhdr(buf, msginfo);
878 READ_TO_LISTEND("xhdr (to)");
880 if (nntp_xhdr(session->nntp_sock, "cc", num, num) != NN_SUCCESS) {
881 log_warning(_("can't get xhdr\n"));
885 if (sock_gets(SESSION(session)->sock, buf, sizeof(buf)) < 0) {
886 log_warning(_("error occurred while getting xhdr.\n"));
890 msginfo->cc = news_parse_xhdr(buf, msginfo);
892 READ_TO_LISTEND("xhdr (cc)");
897 static GSList *news_get_msginfos_for_range(NNTPSession *session, FolderItem *item, guint begin, guint end)
899 gchar buf[NNTPBUFSIZE];
900 GSList *newlist = NULL;
901 GSList *llast = NULL;
903 guint count = 0, lines = (end - begin + 1) * 3;
905 g_return_val_if_fail(session != NULL, NULL);
906 g_return_val_if_fail(item != NULL, NULL);
908 log_message(_("getting xover %d - %d in %s...\n"),
909 begin, end, item->path);
910 if (nntp_xover(session->nntp_sock, begin, end) != NN_SUCCESS) {
911 log_warning(_("can't get xover\n"));
916 if (sock_gets(SESSION(session)->sock, buf, sizeof(buf)) < 0) {
917 log_warning(_("error occurred while getting xover.\n"));
921 progressindicator_set_percentage
922 (PROGRESS_TYPE_NETWORK, session->fetch_base_percentage + ((gfloat) count / (gfloat) lines));
924 if (buf[0] == '.' && buf[1] == '\r') break;
926 msginfo = news_parse_xover(buf);
928 log_warning(_("invalid xover line: %s\n"), buf);
932 msginfo->folder = item;
933 msginfo->flags.perm_flags = MSG_NEW|MSG_UNREAD;
934 msginfo->flags.tmp_flags = MSG_NEWS;
935 msginfo->newsgroups = g_strdup(item->path);
938 llast = newlist = g_slist_append(newlist, msginfo);
940 llast = g_slist_append(llast, msginfo);
945 if (nntp_xhdr(session->nntp_sock, "to", begin, end) != NN_SUCCESS) {
946 log_warning(_("can't get xhdr\n"));
953 if (sock_gets(SESSION(session)->sock, buf, sizeof(buf)) < 0) {
954 log_warning(_("error occurred while getting xhdr.\n"));
958 progressindicator_set_percentage
959 (PROGRESS_TYPE_NETWORK, session->fetch_base_percentage + ((gfloat) count / (gfloat) lines));
961 if (buf[0] == '.' && buf[1] == '\r') break;
963 g_warning("llast == NULL\n");
967 msginfo = (MsgInfo *)llast->data;
968 msginfo->to = news_parse_xhdr(buf, msginfo);
973 if (nntp_xhdr(session->nntp_sock, "cc", begin, end) != NN_SUCCESS) {
974 log_warning(_("can't get xhdr\n"));
981 if (sock_gets(SESSION(session)->sock, buf, sizeof(buf)) < 0) {
982 log_warning(_("error occurred while getting xhdr.\n"));
986 progressindicator_set_percentage
987 (PROGRESS_TYPE_NETWORK, session->fetch_base_percentage + ((gfloat) count / (gfloat) lines));
989 if (buf[0] == '.' && buf[1] == '\r') break;
991 g_warning("llast == NULL\n");
995 msginfo = (MsgInfo *)llast->data;
996 msginfo->cc = news_parse_xhdr(buf, msginfo);
1004 gint news_fetch_msgnum_sort(gconstpointer a, gconstpointer b)
1006 return (GPOINTER_TO_INT(a) - GPOINTER_TO_INT(b));
1009 GSList *news_get_msginfos(Folder *folder, FolderItem *item, GSList *msgnum_list)
1011 NNTPSession *session;
1012 GSList *elem, *msginfo_list = NULL, *tmp_msgnum_list, *tmp_msginfo_list;
1013 guint first, last, next;
1014 guint tofetch, fetched;
1016 g_return_val_if_fail(folder != NULL, NULL);
1017 g_return_val_if_fail(folder->type == F_NEWS, NULL);
1018 g_return_val_if_fail(msgnum_list != NULL, NULL);
1019 g_return_val_if_fail(item != NULL, NULL);
1021 session = news_session_get(folder);
1022 g_return_val_if_fail(session != NULL, NULL);
1024 tmp_msgnum_list = g_slist_copy(msgnum_list);
1025 tmp_msgnum_list = g_slist_sort(tmp_msgnum_list, news_fetch_msgnum_sort);
1027 progressindicator_start(PROGRESS_TYPE_NETWORK);
1028 tofetch = g_slist_length(tmp_msgnum_list);
1031 first = GPOINTER_TO_INT(tmp_msgnum_list->data);
1033 for(elem = g_slist_next(tmp_msgnum_list); elem != NULL; elem = g_slist_next(elem)) {
1034 next = GPOINTER_TO_INT(elem->data);
1035 if(next != (last + 1)) {
1036 session->fetch_base_percentage = (gfloat) fetched / (gfloat) tofetch;
1037 tmp_msginfo_list = news_get_msginfos_for_range(session, item, first, last);
1038 msginfo_list = g_slist_concat(msginfo_list, tmp_msginfo_list);
1039 fetched = last - first + 1;
1044 tmp_msginfo_list = news_get_msginfos_for_range(session, item, first, last);
1045 msginfo_list = g_slist_concat(msginfo_list, tmp_msginfo_list);
1047 g_slist_free(tmp_msgnum_list);
1049 progressindicator_stop(PROGRESS_TYPE_NETWORK);
1051 return msginfo_list;