2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2004 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.
27 #include <glib/gi18n.h>
41 #include "procheader.h"
44 #include "statusbar.h"
47 #include "prefs_common.h"
48 #include "prefs_account.h"
49 #include "inputdialog.h"
51 #include "progressindicator.h"
52 #include "remotefolder.h"
53 #include "alertpanel.h"
60 #define NNTPS_PORT 563
63 typedef struct _NewsFolder NewsFolder;
65 #define NEWS_FOLDER(obj) ((NewsFolder *)obj)
74 static void news_folder_init (Folder *folder,
78 static Folder *news_folder_new (const gchar *name,
80 static void news_folder_destroy (Folder *folder);
82 static gchar *news_fetch_msg (Folder *folder,
88 static Session *news_session_new (const gchar *server,
94 static Session *news_session_new (const gchar *server,
100 static gint news_get_article_cmd (NNTPSession *session,
104 static gint news_get_article (NNTPSession *session,
108 static gint news_select_group (NNTPSession *session,
113 static MsgInfo *news_parse_xover (const gchar *xover_str);
114 static gchar *news_parse_xhdr (const gchar *xhdr_str,
116 gint news_get_num_list (Folder *folder,
119 gboolean *old_uids_valid);
120 MsgInfo *news_get_msginfo (Folder *folder,
123 GSList *news_get_msginfos (Folder *folder,
125 GSList *msgnum_list);
126 gboolean news_scan_required (Folder *folder,
129 gint news_post_stream (Folder *folder,
131 static gchar *news_folder_get_path (Folder *folder);
132 gchar *news_item_get_path (Folder *folder,
135 static FolderClass news_class;
137 FolderClass *news_get_class(void)
139 if (news_class.idstr == NULL) {
140 news_class.type = F_NEWS;
141 news_class.idstr = "news";
142 news_class.uistr = "News";
144 /* Folder functions */
145 news_class.new_folder = news_folder_new;
146 news_class.destroy_folder = news_folder_destroy;
148 /* FolderItem functions */
149 news_class.item_get_path = news_item_get_path;
150 news_class.get_num_list = news_get_num_list;
151 news_class.scan_required = news_scan_required;
153 /* Message functions */
154 news_class.get_msginfo = news_get_msginfo;
155 news_class.get_msginfos = news_get_msginfos;
156 news_class.fetch_msg = news_fetch_msg;
162 static Folder *news_folder_new(const gchar *name, const gchar *path)
166 folder = (Folder *)g_new0(NewsFolder, 1);
167 folder->klass = &news_class;
168 news_folder_init(folder, name, path);
173 static void news_folder_destroy(Folder *folder)
177 dir = news_folder_get_path(folder);
178 if (is_dir_exist(dir))
179 remove_dir_recursive(dir);
182 folder_remote_folder_destroy(REMOTE_FOLDER(folder));
185 static void news_folder_init(Folder *folder, const gchar *name,
188 folder_remote_folder_init(folder, name, path);
192 static Session *news_session_new(const gchar *server, gushort port,
193 const gchar *userid, const gchar *passwd,
196 static Session *news_session_new(const gchar *server, gushort port,
197 const gchar *userid, const gchar *passwd)
200 gchar buf[NNTPBUFSIZE];
203 g_return_val_if_fail(server != NULL, NULL);
205 log_message(_("creating NNTP connection to %s:%d ...\n"), server, port);
208 session = nntp_session_new(server, port, buf, userid, passwd, ssl_type);
210 session = nntp_session_new(server, port, buf, userid, passwd);
216 static Session *news_session_new_for_folder(Folder *folder)
220 const gchar *userid = NULL;
221 gchar *passwd = NULL;
223 gchar buf[NNTPBUFSIZE];
225 g_return_val_if_fail(folder != NULL, NULL);
226 g_return_val_if_fail(folder->account != NULL, NULL);
228 ac = folder->account;
229 if (ac->use_nntp_auth && ac->userid && ac->userid[0]) {
231 if (ac->passwd && ac->passwd[0])
232 passwd = g_strdup(ac->passwd);
234 passwd = input_dialog_query_password(ac->nntp_server,
239 port = ac->set_nntpport ? ac->nntpport
240 : ac->ssl_nntp ? NNTPS_PORT : NNTP_PORT;
241 session = news_session_new(ac->nntp_server, port, userid, passwd,
244 port = ac->set_nntpport ? ac->nntpport : NNTP_PORT;
245 session = news_session_new(ac->nntp_server, port, userid, passwd);
247 if ((session != NULL) && ac->use_nntp_auth && ac->use_nntp_auth_onconnect)
248 nntp_forceauth(NNTP_SESSION(session), buf, userid, passwd);
255 static NNTPSession *news_session_get(Folder *folder)
257 RemoteFolder *rfolder = REMOTE_FOLDER(folder);
259 g_return_val_if_fail(folder != NULL, NULL);
260 g_return_val_if_fail(FOLDER_CLASS(folder) == &news_class, NULL);
261 g_return_val_if_fail(folder->account != NULL, NULL);
263 if (prefs_common.work_offline && !news_gtk_should_override()) {
267 if (!rfolder->session) {
268 rfolder->session = news_session_new_for_folder(folder);
269 return NNTP_SESSION(rfolder->session);
272 if (time(NULL) - rfolder->session->last_access_time <
273 SESSION_TIMEOUT_INTERVAL) {
274 return NNTP_SESSION(rfolder->session);
277 if (nntp_mode(NNTP_SESSION(rfolder->session), FALSE)
279 log_warning(_("NNTP connection to %s:%d has been"
280 " disconnected. Reconnecting...\n"),
281 folder->account->nntp_server,
282 folder->account->set_nntpport ?
283 folder->account->nntpport : NNTP_PORT);
284 session_destroy(rfolder->session);
285 rfolder->session = news_session_new_for_folder(folder);
288 if (rfolder->session)
289 session_set_access_time(rfolder->session);
291 return NNTP_SESSION(rfolder->session);
294 static gchar *news_fetch_msg(Folder *folder, FolderItem *item, gint num)
296 gchar *path, *filename;
297 NNTPSession *session;
300 g_return_val_if_fail(folder != NULL, NULL);
301 g_return_val_if_fail(item != NULL, NULL);
303 path = folder_item_get_path(item);
304 if (!is_dir_exist(path))
306 filename = g_strconcat(path, G_DIR_SEPARATOR_S, itos(num), NULL);
309 if (is_file_exist(filename)) {
310 debug_print("article %d has been already cached.\n", num);
314 session = news_session_get(folder);
320 ok = news_select_group(session, item->path, NULL, NULL, NULL);
321 if (ok != NN_SUCCESS) {
322 if (ok == NN_SOCKET) {
323 session_destroy(SESSION(session));
324 REMOTE_FOLDER(folder)->session = NULL;
330 debug_print("getting article %d...\n", num);
331 ok = news_get_article(NNTP_SESSION(REMOTE_FOLDER(folder)->session),
333 if (ok != NN_SUCCESS) {
334 g_warning("can't read article %d\n", num);
335 if (ok == NN_SOCKET) {
336 session_destroy(SESSION(session));
337 REMOTE_FOLDER(folder)->session = NULL;
346 static NewsGroupInfo *news_group_info_new(const gchar *name,
347 gint first, gint last, gchar type)
349 NewsGroupInfo *ginfo;
351 ginfo = g_new(NewsGroupInfo, 1);
352 ginfo->name = g_strdup(name);
353 ginfo->first = first;
360 static void news_group_info_free(NewsGroupInfo *ginfo)
366 static gint news_group_info_compare(NewsGroupInfo *ginfo1,
367 NewsGroupInfo *ginfo2)
369 return g_ascii_strcasecmp(ginfo1->name, ginfo2->name);
372 GSList *news_get_group_list(Folder *folder)
374 gchar *path, *filename;
378 gchar buf[NNTPBUFSIZE];
380 g_return_val_if_fail(folder != NULL, NULL);
381 g_return_val_if_fail(FOLDER_CLASS(folder) == &news_class, NULL);
383 path = folder_item_get_path(FOLDER_ITEM(folder->node->data));
384 if (!is_dir_exist(path))
386 filename = g_strconcat(path, G_DIR_SEPARATOR_S, NEWSGROUP_LIST, NULL);
389 if ((fp = g_fopen(filename, "rb")) == NULL) {
390 NNTPSession *session;
393 session = news_session_get(folder);
399 ok = nntp_list(session);
400 if (ok != NN_SUCCESS) {
401 if (ok == NN_SOCKET) {
402 session_destroy(SESSION(session));
403 REMOTE_FOLDER(folder)->session = NULL;
408 if (recv_write_to_file(SESSION(session)->sock, filename) < 0) {
409 log_warning(_("can't retrieve newsgroup list\n"));
410 session_destroy(SESSION(session));
411 REMOTE_FOLDER(folder)->session = NULL;
416 if ((fp = g_fopen(filename, "rb")) == NULL) {
417 FILE_OP_ERROR(filename, "fopen");
423 while (fgets(buf, sizeof(buf), fp) != NULL) {
429 NewsGroupInfo *ginfo;
437 if (sscanf(p, "%d %d %c", &last_num, &first_num, &type) < 3)
440 ginfo = news_group_info_new(name, first_num, last_num, type);
443 last = list = g_slist_append(NULL, ginfo);
445 last = g_slist_append(last, ginfo);
453 list = g_slist_sort(list, (GCompareFunc)news_group_info_compare);
458 void news_group_list_free(GSList *group_list)
462 if (!group_list) return;
464 for (cur = group_list; cur != NULL; cur = cur->next)
465 news_group_info_free((NewsGroupInfo *)cur->data);
466 g_slist_free(group_list);
469 void news_remove_group_list_cache(Folder *folder)
471 gchar *path, *filename;
473 g_return_if_fail(folder != NULL);
474 g_return_if_fail(FOLDER_CLASS(folder) == &news_class);
476 path = folder_item_get_path(FOLDER_ITEM(folder->node->data));
477 filename = g_strconcat(path, G_DIR_SEPARATOR_S, NEWSGROUP_LIST, NULL);
480 if (is_file_exist(filename)) {
481 if (remove(filename) < 0)
482 FILE_OP_ERROR(filename, "remove");
487 gint news_post(Folder *folder, const gchar *file)
492 g_return_val_if_fail(folder != NULL, -1);
493 g_return_val_if_fail(FOLDER_CLASS(folder) == &news_class, -1);
494 g_return_val_if_fail(file != NULL, -1);
496 if ((fp = g_fopen(file, "rb")) == NULL) {
497 FILE_OP_ERROR(file, "fopen");
501 ok = news_post_stream(folder, fp);
508 gint news_post_stream(Folder *folder, FILE *fp)
510 NNTPSession *session;
513 g_return_val_if_fail(folder != NULL, -1);
514 g_return_val_if_fail(FOLDER_CLASS(folder) == &news_class, -1);
515 g_return_val_if_fail(fp != NULL, -1);
517 session = news_session_get(folder);
518 if (!session) return -1;
520 ok = nntp_post(session, fp);
521 if (ok != NN_SUCCESS) {
522 log_warning(_("can't post article.\n"));
523 if (ok == NN_SOCKET) {
524 session_destroy(SESSION(session));
525 REMOTE_FOLDER(folder)->session = NULL;
533 static gint news_get_article_cmd(NNTPSession *session, const gchar *cmd,
534 gint num, gchar *filename)
539 ok = nntp_get_article(session, cmd, num, &msgid);
540 if (ok != NN_SUCCESS)
543 debug_print("Message-ID = %s, num = %d\n", msgid, num);
546 ok = recv_write_to_file(SESSION(session)->sock, filename);
548 log_warning(_("can't retrieve article %d\n"), num);
558 static gint news_get_article(NNTPSession *session, gint num, gchar *filename)
560 return news_get_article_cmd(session, "ARTICLE", num, filename);
565 * @session: Active NNTP session.
566 * @group: Newsgroup name.
567 * @num: Estimated number of articles.
568 * @first: First article number.
569 * @last: Last article number.
571 * Select newsgroup @group with the GROUP command if it is not already
572 * selected in @session, or article numbers need to be returned.
574 * Return value: NNTP result code.
576 static gint news_select_group(NNTPSession *session, const gchar *group,
577 gint *num, gint *first, gint *last)
580 gint num_, first_, last_;
582 if (!num || !first || !last) {
583 if (session->group && g_ascii_strcasecmp(session->group, group) == 0)
590 g_free(session->group);
591 session->group = NULL;
593 ok = nntp_group(session, group, num, first, last);
594 if (ok == NN_SUCCESS)
595 session->group = g_strdup(group);
597 log_warning(_("can't select group: %s\n"), group);
602 #define PARSE_ONE_PARAM(p, srcp) \
604 p = strchr(srcp, '\t'); \
605 if (!p) return NULL; \
610 static MsgInfo *news_parse_xover(const gchar *xover_str)
613 gchar *subject, *sender, *size, *line, *date, *msgid, *ref, *tmp;
615 gint num, size_int, line_int;
618 Xstrdup_a(xover_buf, xover_str, return NULL);
620 PARSE_ONE_PARAM(subject, xover_buf);
621 PARSE_ONE_PARAM(sender, subject);
622 PARSE_ONE_PARAM(date, sender);
623 PARSE_ONE_PARAM(msgid, date);
624 PARSE_ONE_PARAM(ref, msgid);
625 PARSE_ONE_PARAM(size, ref);
626 PARSE_ONE_PARAM(line, size);
628 * PARSE_ONE_PARAM(xref, line);
630 * if we parse extra headers we should first examine the
631 * LIST OVERVIEW.FMT response from the server. See
632 * RFC2980 for details
635 tmp = strchr(line, '\t');
636 if (!tmp) tmp = strchr(line, '\r');
637 if (!tmp) tmp = strchr(line, '\n');
638 if (tmp) *tmp = '\0';
640 num = atoi(xover_str);
641 size_int = atoi(size);
642 line_int = atoi(line);
645 msginfo = procmsg_msginfo_new();
646 msginfo->msgnum = num;
647 msginfo->size = size_int;
649 msginfo->date = g_strdup(date);
650 msginfo->date_t = procheader_date_parse(NULL, date, 0);
652 msginfo->from = conv_unmime_header(sender, NULL);
653 msginfo->fromname = procheader_get_fromname(msginfo->from);
655 msginfo->subject = conv_unmime_header(subject, NULL);
658 extract_parenthesis(msgid, '<', '>');
661 msginfo->msgid = g_strdup(msgid);
664 /* FIXME: this is a quick fix; references' meaning was changed
665 * into having the actual list of references in the References: header.
666 * We need a GSList here, so msginfo_free() and msginfo_copy() can do
667 * their things properly. */
668 if (ref && strlen(ref)) {
669 gchar **ref_tokens = g_strsplit(ref, " ", -1);
672 while (ref_tokens[i]) {
673 gchar *cur_ref = ref_tokens[i];
674 msginfo->references = references_list_append(msginfo->references,
678 g_strfreev(ref_tokens);
680 eliminate_parenthesis(ref, '(', ')');
681 if ((p = strrchr(ref, '<')) != NULL) {
682 extract_parenthesis(p, '<', '>');
685 msginfo->inreplyto = g_strdup(p);
690 msginfo->xref = g_strdup(xref);
691 p = msginfo->xref+strlen(msginfo->xref) - 1;
692 while (*p == '\r' || *p == '\n') {
701 static gchar *news_parse_xhdr(const gchar *xhdr_str, MsgInfo *msginfo)
707 p = strchr(xhdr_str, ' ');
713 num = atoi(xhdr_str);
714 if (msginfo->msgnum != num) return NULL;
716 tmp = strchr(p, '\r');
717 if (!tmp) tmp = strchr(p, '\n');
720 return g_strndup(p, tmp - p);
725 gint news_cancel_article(Folder * folder, MsgInfo * msginfo)
731 tmp = g_strdup_printf("%s%ctmp%d", g_get_tmp_dir(),
732 G_DIR_SEPARATOR, (gint)msginfo);
736 if ((tmpfp = g_fopen(tmp, "wb")) == NULL) {
737 FILE_OP_ERROR(tmp, "fopen");
740 if (change_file_mode_rw(tmpfp, tmp) < 0) {
741 FILE_OP_ERROR(tmp, "chmod");
742 g_warning("can't change file mode\n");
745 fprintf(tmpfp, "From: %s\r\n", msginfo->from);
746 fprintf(tmpfp, "Newsgroups: %s\r\n", msginfo->newsgroups);
747 fprintf(tmpfp, "Subject: cmsg cancel <%s>\r\n", msginfo->msgid);
748 fprintf(tmpfp, "Control: cancel <%s>\r\n", msginfo->msgid);
749 fprintf(tmpfp, "Approved: %s\r\n", msginfo->from);
750 fprintf(tmpfp, "X-Cancelled-by: %s\r\n", msginfo->from);
751 get_rfc822_date(buf, sizeof(buf));
752 fprintf(tmpfp, "Date: %s\r\n", buf);
753 fprintf(tmpfp, "\r\n");
754 fprintf(tmpfp, "removed with sylpheed\r\n");
758 news_post(folder, tmp);
766 static gchar *news_folder_get_path(Folder *folder)
770 g_return_val_if_fail(folder->account != NULL, NULL);
772 folder_path = g_strconcat(get_news_cache_dir(),
774 folder->account->nntp_server,
779 gchar *news_item_get_path(Folder *folder, FolderItem *item)
781 gchar *folder_path, *path;
783 g_return_val_if_fail(folder != NULL, NULL);
784 g_return_val_if_fail(item != NULL, NULL);
785 folder_path = news_folder_get_path(folder);
787 g_return_val_if_fail(folder_path != NULL, NULL);
788 if (folder_path[0] == G_DIR_SEPARATOR) {
790 path = g_strconcat(folder_path, G_DIR_SEPARATOR_S,
793 path = g_strdup(folder_path);
796 path = g_strconcat(get_home_dir(), G_DIR_SEPARATOR_S,
797 folder_path, G_DIR_SEPARATOR_S,
800 path = g_strconcat(get_home_dir(), G_DIR_SEPARATOR_S,
808 gint news_get_num_list(Folder *folder, FolderItem *item, GSList **msgnum_list, gboolean *old_uids_valid)
810 NNTPSession *session;
811 gint i, ok, num, first, last, nummsgs = 0;
814 g_return_val_if_fail(item != NULL, -1);
815 g_return_val_if_fail(item->folder != NULL, -1);
816 g_return_val_if_fail(FOLDER_CLASS(folder) == &news_class, -1);
818 session = news_session_get(folder);
819 g_return_val_if_fail(session != NULL, -1);
821 *old_uids_valid = TRUE;
823 ok = news_select_group(session, item->path, &num, &first, &last);
824 if (ok != NN_SUCCESS) {
825 log_warning(_("can't set group: %s\n"), item->path);
829 dir = news_folder_get_path(folder);
831 remove_all_numbered_files(dir);
832 else if (last < first)
833 log_warning(_("invalid article range: %d - %d\n"),
836 for (i = first; i <= last; i++) {
837 *msgnum_list = g_slist_prepend(*msgnum_list,
841 debug_print("removing old messages from %d to %d in %s\n",
843 remove_numbered_files(dir, 1, first - 1);
850 #define READ_TO_LISTEND(hdr) \
851 while (!(buf[0] == '.' && buf[1] == '\r')) { \
852 if (sock_gets(SESSION(session)->sock, buf, sizeof(buf)) < 0) { \
853 log_warning(_("error occurred while getting %s.\n"), hdr); \
858 MsgInfo *news_get_msginfo(Folder *folder, FolderItem *item, gint num)
860 NNTPSession *session;
861 MsgInfo *msginfo = NULL;
862 gchar buf[NNTPBUFSIZE];
865 session = news_session_get(folder);
866 g_return_val_if_fail(session != NULL, NULL);
867 g_return_val_if_fail(item != NULL, NULL);
868 g_return_val_if_fail(item->folder != NULL, NULL);
869 g_return_val_if_fail(FOLDER_CLASS(item->folder) == &news_class, NULL);
871 log_message(_("getting xover %d in %s...\n"),
873 ok = nntp_xover(session, num, num);
874 if (ok != NN_SUCCESS) {
875 log_warning(_("can't get xover\n"));
876 if (ok == NN_SOCKET) {
877 session_destroy(SESSION(session));
878 REMOTE_FOLDER(item->folder)->session = NULL;
883 if (sock_gets(SESSION(session)->sock, buf, sizeof(buf)) < 0) {
884 log_warning(_("error occurred while getting xover.\n"));
888 msginfo = news_parse_xover(buf);
890 log_warning(_("invalid xover line: %s\n"), buf);
893 READ_TO_LISTEND("xover");
898 msginfo->folder = item;
899 msginfo->flags.perm_flags = MSG_NEW|MSG_UNREAD;
900 msginfo->flags.tmp_flags = MSG_NEWS;
901 msginfo->newsgroups = g_strdup(item->path);
903 ok = nntp_xhdr(session, "to", num, num);
904 if (ok != NN_SUCCESS) {
905 log_warning(_("can't get xhdr\n"));
906 if (ok == NN_SOCKET) {
907 session_destroy(SESSION(session));
908 REMOTE_FOLDER(item->folder)->session = NULL;
913 if (sock_gets(SESSION(session)->sock, buf, sizeof(buf)) < 0) {
914 log_warning(_("error occurred while getting xhdr.\n"));
918 msginfo->to = news_parse_xhdr(buf, msginfo);
920 READ_TO_LISTEND("xhdr (to)");
922 ok = nntp_xhdr(session, "cc", num, num);
923 if (ok != NN_SUCCESS) {
924 log_warning(_("can't get xhdr\n"));
925 if (ok == NN_SOCKET) {
926 session_destroy(SESSION(session));
927 REMOTE_FOLDER(item->folder)->session = NULL;
932 if (sock_gets(SESSION(session)->sock, buf, sizeof(buf)) < 0) {
933 log_warning(_("error occurred while getting xhdr.\n"));
937 msginfo->cc = news_parse_xhdr(buf, msginfo);
939 READ_TO_LISTEND("xhdr (cc)");
944 static GSList *news_get_msginfos_for_range(NNTPSession *session, FolderItem *item, guint begin, guint end)
946 gchar buf[NNTPBUFSIZE];
947 GSList *newlist = NULL;
948 GSList *llast = NULL;
950 guint count = 0, lines = (end - begin + 2) * 3;
953 g_return_val_if_fail(session != NULL, NULL);
954 g_return_val_if_fail(item != NULL, NULL);
956 log_message(_("getting xover %d - %d in %s...\n"),
957 begin, end, item->path);
958 ok = nntp_xover(session, begin, end);
959 if (ok != NN_SUCCESS) {
960 log_warning(_("can't get xover\n"));
961 if (ok == NN_SOCKET) {
962 session_destroy(SESSION(session));
963 REMOTE_FOLDER(item->folder)->session = NULL;
969 if (sock_gets(SESSION(session)->sock, buf, sizeof(buf)) < 0) {
970 log_warning(_("error occurred while getting xover.\n"));
974 progressindicator_set_percentage
975 (PROGRESS_TYPE_NETWORK,
976 session->fetch_base_percentage +
977 (((gfloat) count) / ((gfloat) lines)) * session->fetch_total_percentage);
979 if (buf[0] == '.' && buf[1] == '\r') break;
981 msginfo = news_parse_xover(buf);
983 log_warning(_("invalid xover line: %s\n"), buf);
987 msginfo->folder = item;
988 msginfo->flags.perm_flags = MSG_NEW|MSG_UNREAD;
989 msginfo->flags.tmp_flags = MSG_NEWS;
990 msginfo->newsgroups = g_strdup(item->path);
993 llast = newlist = g_slist_append(newlist, msginfo);
995 llast = g_slist_append(llast, msginfo);
1000 ok = nntp_xhdr(session, "to", begin, end);
1001 if (ok != NN_SUCCESS) {
1002 log_warning(_("can't get xhdr\n"));
1003 if (ok == NN_SOCKET) {
1004 session_destroy(SESSION(session));
1005 REMOTE_FOLDER(item->folder)->session = NULL;
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->to = news_parse_xhdr(buf, msginfo);
1032 llast = llast->next;
1035 ok = nntp_xhdr(session, "cc", begin, end);
1036 if (ok != NN_SUCCESS) {
1037 log_warning(_("can't get xhdr\n"));
1038 if (ok == NN_SOCKET) {
1039 session_destroy(SESSION(session));
1040 REMOTE_FOLDER(item->folder)->session = NULL;
1048 if (sock_gets(SESSION(session)->sock, buf, sizeof(buf)) < 0) {
1049 log_warning(_("error occurred while getting xhdr.\n"));
1053 progressindicator_set_percentage
1054 (PROGRESS_TYPE_NETWORK,
1055 session->fetch_base_percentage +
1056 (((gfloat) count) / ((gfloat) lines)) * session->fetch_total_percentage);
1058 if (buf[0] == '.' && buf[1] == '\r') break;
1060 g_warning("llast == NULL\n");
1064 msginfo = (MsgInfo *)llast->data;
1065 msginfo->cc = news_parse_xhdr(buf, msginfo);
1067 llast = llast->next;
1070 session_set_access_time(SESSION(session));
1075 GSList *news_get_msginfos(Folder *folder, FolderItem *item, GSList *msgnum_list)
1077 NNTPSession *session;
1078 GSList *elem, *msginfo_list = NULL, *tmp_msgnum_list, *tmp_msginfo_list;
1079 guint first, last, next;
1080 guint tofetch, fetched;
1082 g_return_val_if_fail(folder != NULL, NULL);
1083 g_return_val_if_fail(FOLDER_CLASS(folder) == &news_class, NULL);
1084 g_return_val_if_fail(msgnum_list != NULL, NULL);
1085 g_return_val_if_fail(item != NULL, NULL);
1087 session = news_session_get(folder);
1088 g_return_val_if_fail(session != NULL, NULL);
1090 tmp_msgnum_list = g_slist_copy(msgnum_list);
1091 tmp_msgnum_list = g_slist_sort(tmp_msgnum_list, g_int_compare);
1093 progressindicator_start(PROGRESS_TYPE_NETWORK);
1094 tofetch = g_slist_length(tmp_msgnum_list);
1097 first = GPOINTER_TO_INT(tmp_msgnum_list->data);
1099 for(elem = g_slist_next(tmp_msgnum_list); elem != NULL; elem = g_slist_next(elem)) {
1100 next = GPOINTER_TO_INT(elem->data);
1101 if(next != (last + 1)) {
1102 session->fetch_base_percentage = ((gfloat) fetched) / ((gfloat) tofetch);
1103 session->fetch_total_percentage = ((gfloat) (last - first + 1)) / ((gfloat) tofetch);
1104 tmp_msginfo_list = news_get_msginfos_for_range(session, item, first, last);
1105 msginfo_list = g_slist_concat(msginfo_list, tmp_msginfo_list);
1106 fetched = last - first + 1;
1111 session->fetch_base_percentage = ((gfloat) fetched) / ((gfloat) tofetch);
1112 session->fetch_total_percentage = ((gfloat) (last - first + 1)) / ((gfloat) tofetch);
1113 tmp_msginfo_list = news_get_msginfos_for_range(session, item, first, last);
1114 msginfo_list = g_slist_concat(msginfo_list, tmp_msginfo_list);
1116 g_slist_free(tmp_msgnum_list);
1118 progressindicator_stop(PROGRESS_TYPE_NETWORK);
1120 return msginfo_list;
1123 gboolean news_scan_required(Folder *folder, FolderItem *item)