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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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"
62 #define NNTPS_PORT 563
65 typedef struct _NewsFolder NewsFolder;
67 #define NEWS_FOLDER(obj) ((NewsFolder *)obj)
76 static void news_folder_init (Folder *folder,
80 static Folder *news_folder_new (const gchar *name,
82 static void news_folder_destroy (Folder *folder);
84 static gchar *news_fetch_msg (Folder *folder,
90 static Session *news_session_new (const gchar *server,
96 static Session *news_session_new (const gchar *server,
102 static gint news_get_article_cmd (NNTPSession *session,
106 static gint news_get_article (NNTPSession *session,
110 static gint news_select_group (NNTPSession *session,
115 static MsgInfo *news_parse_xover (const gchar *xover_str);
116 static gchar *news_parse_xhdr (const gchar *xhdr_str,
118 gint news_get_num_list (Folder *folder,
121 gboolean *old_uids_valid);
122 MsgInfo *news_get_msginfo (Folder *folder,
125 GSList *news_get_msginfos (Folder *folder,
127 GSList *msgnum_list);
128 gboolean news_scan_required (Folder *folder,
131 gint news_post_stream (Folder *folder,
133 static gchar *news_folder_get_path (Folder *folder);
134 gchar *news_item_get_path (Folder *folder,
136 static void news_synchronise (FolderItem *item);
137 static int news_dummy_remove (Folder *folder,
140 static FolderClass news_class;
142 FolderClass *news_get_class(void)
144 if (news_class.idstr == NULL) {
145 news_class.type = F_NEWS;
146 news_class.idstr = "news";
147 news_class.uistr = "News";
149 /* Folder functions */
150 news_class.new_folder = news_folder_new;
151 news_class.destroy_folder = news_folder_destroy;
153 /* FolderItem functions */
154 news_class.item_get_path = news_item_get_path;
155 news_class.get_num_list = news_get_num_list;
156 news_class.scan_required = news_scan_required;
158 /* Message functions */
159 news_class.get_msginfo = news_get_msginfo;
160 news_class.get_msginfos = news_get_msginfos;
161 news_class.fetch_msg = news_fetch_msg;
162 news_class.synchronise = news_synchronise;
163 news_class.remove_msg = news_dummy_remove;
169 static int news_dummy_remove (Folder *folder,
173 debug_print("doing nothing on purpose\n");
177 static Folder *news_folder_new(const gchar *name, const gchar *path)
181 folder = (Folder *)g_new0(NewsFolder, 1);
182 folder->klass = &news_class;
183 news_folder_init(folder, name, path);
188 static void news_folder_destroy(Folder *folder)
192 dir = news_folder_get_path(folder);
193 if (is_dir_exist(dir))
194 remove_dir_recursive(dir);
197 folder_remote_folder_destroy(REMOTE_FOLDER(folder));
200 static void news_folder_init(Folder *folder, const gchar *name,
203 folder_remote_folder_init(folder, name, path);
207 static Session *news_session_new(const gchar *server, gushort port,
208 const gchar *userid, const gchar *passwd,
211 static Session *news_session_new(const gchar *server, gushort port,
212 const gchar *userid, const gchar *passwd)
215 gchar buf[NNTPBUFSIZE];
218 g_return_val_if_fail(server != NULL, NULL);
220 log_message(_("creating NNTP connection to %s:%d ...\n"), server, port);
223 session = nntp_session_new(server, port, buf, userid, passwd, ssl_type);
225 session = nntp_session_new(server, port, buf, userid, passwd);
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 if (ac->ssl_nntp != SSL_NONE) {
260 if (alertpanel_full(_("Insecure connection"),
261 _("This connection is configured to be secured "
262 "using SSL, but SSL is not available in this "
263 "build of Sylpheed-Claws. \n\n"
264 "Do you want to continue connecting to this "
265 "server? The communication would not be "
267 _("Con_tinue connecting"),
268 GTK_STOCK_CANCEL, NULL,
269 FALSE, NULL, ALERT_WARNING,
270 G_ALERTALTERNATE) != G_ALERTDEFAULT)
273 port = ac->set_nntpport ? ac->nntpport : NNTP_PORT;
274 session = news_session_new(ac->nntp_server, port, userid, passwd);
276 if ((session != NULL) && ac->use_nntp_auth && ac->use_nntp_auth_onconnect)
277 nntp_forceauth(NNTP_SESSION(session), buf, userid, passwd);
284 static NNTPSession *news_session_get(Folder *folder)
286 RemoteFolder *rfolder = REMOTE_FOLDER(folder);
288 g_return_val_if_fail(folder != NULL, NULL);
289 g_return_val_if_fail(FOLDER_CLASS(folder) == &news_class, NULL);
290 g_return_val_if_fail(folder->account != NULL, NULL);
292 if (prefs_common.work_offline && !inc_offline_should_override()) {
296 if (!rfolder->session) {
297 rfolder->session = news_session_new_for_folder(folder);
298 return NNTP_SESSION(rfolder->session);
301 if (time(NULL) - rfolder->session->last_access_time <
302 SESSION_TIMEOUT_INTERVAL) {
303 return NNTP_SESSION(rfolder->session);
306 if (nntp_mode(NNTP_SESSION(rfolder->session), FALSE)
308 log_warning(_("NNTP connection to %s:%d has been"
309 " disconnected. Reconnecting...\n"),
310 folder->account->nntp_server,
311 folder->account->set_nntpport ?
312 folder->account->nntpport : NNTP_PORT);
313 session_destroy(rfolder->session);
314 rfolder->session = news_session_new_for_folder(folder);
317 if (rfolder->session)
318 session_set_access_time(rfolder->session);
320 return NNTP_SESSION(rfolder->session);
323 static gchar *news_fetch_msg(Folder *folder, FolderItem *item, gint num)
325 gchar *path, *filename;
326 NNTPSession *session;
329 g_return_val_if_fail(folder != NULL, NULL);
330 g_return_val_if_fail(item != NULL, NULL);
332 path = folder_item_get_path(item);
333 if (!is_dir_exist(path))
335 filename = g_strconcat(path, G_DIR_SEPARATOR_S, itos(num), NULL);
338 if (is_file_exist(filename)) {
339 debug_print("article %d has been already cached.\n", num);
343 session = news_session_get(folder);
349 ok = news_select_group(session, item->path, NULL, NULL, NULL);
350 if (ok != NN_SUCCESS) {
351 if (ok == NN_SOCKET) {
352 session_destroy(SESSION(session));
353 REMOTE_FOLDER(folder)->session = NULL;
359 debug_print("getting article %d...\n", num);
360 ok = news_get_article(NNTP_SESSION(REMOTE_FOLDER(folder)->session),
362 if (ok != NN_SUCCESS) {
363 g_warning("can't read article %d\n", num);
364 if (ok == NN_SOCKET) {
365 session_destroy(SESSION(session));
366 REMOTE_FOLDER(folder)->session = NULL;
375 static NewsGroupInfo *news_group_info_new(const gchar *name,
376 gint first, gint last, gchar type)
378 NewsGroupInfo *ginfo;
380 ginfo = g_new(NewsGroupInfo, 1);
381 ginfo->name = g_strdup(name);
382 ginfo->first = first;
389 static void news_group_info_free(NewsGroupInfo *ginfo)
395 static gint news_group_info_compare(NewsGroupInfo *ginfo1,
396 NewsGroupInfo *ginfo2)
398 return g_ascii_strcasecmp(ginfo1->name, ginfo2->name);
401 GSList *news_get_group_list(Folder *folder)
403 gchar *path, *filename;
407 gchar buf[NNTPBUFSIZE];
409 g_return_val_if_fail(folder != NULL, NULL);
410 g_return_val_if_fail(FOLDER_CLASS(folder) == &news_class, NULL);
412 path = folder_item_get_path(FOLDER_ITEM(folder->node->data));
413 if (!is_dir_exist(path))
415 filename = g_strconcat(path, G_DIR_SEPARATOR_S, NEWSGROUP_LIST, NULL);
418 if ((fp = g_fopen(filename, "rb")) == NULL) {
419 NNTPSession *session;
422 session = news_session_get(folder);
428 ok = nntp_list(session);
429 if (ok != NN_SUCCESS) {
430 if (ok == NN_SOCKET) {
431 session_destroy(SESSION(session));
432 REMOTE_FOLDER(folder)->session = NULL;
437 if (recv_write_to_file(SESSION(session)->sock, filename) < 0) {
438 log_warning(_("can't retrieve newsgroup list\n"));
439 session_destroy(SESSION(session));
440 REMOTE_FOLDER(folder)->session = NULL;
445 if ((fp = g_fopen(filename, "rb")) == NULL) {
446 FILE_OP_ERROR(filename, "fopen");
452 while (fgets(buf, sizeof(buf), fp) != NULL) {
458 NewsGroupInfo *ginfo;
466 if (sscanf(p, "%d %d %c", &last_num, &first_num, &type) < 3)
469 ginfo = news_group_info_new(name, first_num, last_num, type);
472 last = list = g_slist_append(NULL, ginfo);
474 last = g_slist_append(last, ginfo);
482 list = g_slist_sort(list, (GCompareFunc)news_group_info_compare);
487 void news_group_list_free(GSList *group_list)
491 if (!group_list) return;
493 for (cur = group_list; cur != NULL; cur = cur->next)
494 news_group_info_free((NewsGroupInfo *)cur->data);
495 g_slist_free(group_list);
498 void news_remove_group_list_cache(Folder *folder)
500 gchar *path, *filename;
502 g_return_if_fail(folder != NULL);
503 g_return_if_fail(FOLDER_CLASS(folder) == &news_class);
505 path = folder_item_get_path(FOLDER_ITEM(folder->node->data));
506 filename = g_strconcat(path, G_DIR_SEPARATOR_S, NEWSGROUP_LIST, NULL);
509 if (is_file_exist(filename)) {
510 if (remove(filename) < 0)
511 FILE_OP_ERROR(filename, "remove");
516 gint news_post(Folder *folder, const gchar *file)
521 g_return_val_if_fail(folder != NULL, -1);
522 g_return_val_if_fail(FOLDER_CLASS(folder) == &news_class, -1);
523 g_return_val_if_fail(file != NULL, -1);
525 if ((fp = g_fopen(file, "rb")) == NULL) {
526 FILE_OP_ERROR(file, "fopen");
530 ok = news_post_stream(folder, fp);
537 gint news_post_stream(Folder *folder, FILE *fp)
539 NNTPSession *session;
542 g_return_val_if_fail(folder != NULL, -1);
543 g_return_val_if_fail(FOLDER_CLASS(folder) == &news_class, -1);
544 g_return_val_if_fail(fp != NULL, -1);
546 session = news_session_get(folder);
547 if (!session) return -1;
549 ok = nntp_post(session, fp);
550 if (ok != NN_SUCCESS) {
551 log_warning(_("can't post article.\n"));
552 if (ok == NN_SOCKET) {
553 session_destroy(SESSION(session));
554 REMOTE_FOLDER(folder)->session = NULL;
562 static gint news_get_article_cmd(NNTPSession *session, const gchar *cmd,
563 gint num, gchar *filename)
568 ok = nntp_get_article(session, cmd, num, &msgid);
569 if (ok != NN_SUCCESS)
572 debug_print("Message-ID = %s, num = %d\n", msgid, num);
575 ok = recv_write_to_file(SESSION(session)->sock, filename);
577 log_warning(_("can't retrieve article %d\n"), num);
587 static gint news_get_article(NNTPSession *session, gint num, gchar *filename)
589 return news_get_article_cmd(session, "ARTICLE", num, filename);
594 * @session: Active NNTP session.
595 * @group: Newsgroup name.
596 * @num: Estimated number of articles.
597 * @first: First article number.
598 * @last: Last article number.
600 * Select newsgroup @group with the GROUP command if it is not already
601 * selected in @session, or article numbers need to be returned.
603 * Return value: NNTP result code.
605 static gint news_select_group(NNTPSession *session, const gchar *group,
606 gint *num, gint *first, gint *last)
609 gint num_, first_, last_;
611 if (!num || !first || !last) {
612 if (session->group && g_ascii_strcasecmp(session->group, group) == 0)
619 g_free(session->group);
620 session->group = NULL;
622 ok = nntp_group(session, group, num, first, last);
623 if (ok == NN_SUCCESS)
624 session->group = g_strdup(group);
626 log_warning(_("can't select group: %s\n"), group);
631 #define PARSE_ONE_PARAM(p, srcp) \
633 p = strchr(srcp, '\t'); \
634 if (!p) return NULL; \
639 static MsgInfo *news_parse_xover(const gchar *xover_str)
642 gchar *subject, *sender, *size, *line, *date, *msgid, *ref, *tmp;
644 gint num, size_int, line_int;
647 Xstrdup_a(xover_buf, xover_str, return NULL);
649 PARSE_ONE_PARAM(subject, xover_buf);
650 PARSE_ONE_PARAM(sender, subject);
651 PARSE_ONE_PARAM(date, sender);
652 PARSE_ONE_PARAM(msgid, date);
653 PARSE_ONE_PARAM(ref, msgid);
654 PARSE_ONE_PARAM(size, ref);
655 PARSE_ONE_PARAM(line, size);
657 * PARSE_ONE_PARAM(xref, line);
659 * if we parse extra headers we should first examine the
660 * LIST OVERVIEW.FMT response from the server. See
661 * RFC2980 for details
664 tmp = strchr(line, '\t');
665 if (!tmp) tmp = strchr(line, '\r');
666 if (!tmp) tmp = strchr(line, '\n');
667 if (tmp) *tmp = '\0';
669 num = atoi(xover_str);
670 size_int = atoi(size);
671 line_int = atoi(line);
674 msginfo = procmsg_msginfo_new();
675 msginfo->msgnum = num;
676 msginfo->size = size_int;
678 msginfo->date = g_strdup(date);
679 msginfo->date_t = procheader_date_parse(NULL, date, 0);
681 msginfo->from = conv_unmime_header(sender, NULL);
682 msginfo->fromname = procheader_get_fromname(msginfo->from);
684 msginfo->subject = conv_unmime_header(subject, NULL);
687 extract_parenthesis(msgid, '<', '>');
690 msginfo->msgid = g_strdup(msgid);
693 /* FIXME: this is a quick fix; references' meaning was changed
694 * into having the actual list of references in the References: header.
695 * We need a GSList here, so msginfo_free() and msginfo_copy() can do
696 * their things properly. */
697 if (ref && strlen(ref)) {
698 gchar **ref_tokens = g_strsplit(ref, " ", -1);
701 while (ref_tokens[i]) {
702 gchar *cur_ref = ref_tokens[i];
703 msginfo->references = references_list_append(msginfo->references,
707 g_strfreev(ref_tokens);
709 eliminate_parenthesis(ref, '(', ')');
710 if ((p = strrchr(ref, '<')) != NULL) {
711 extract_parenthesis(p, '<', '>');
714 msginfo->inreplyto = g_strdup(p);
719 msginfo->xref = g_strdup(xref);
720 p = msginfo->xref+strlen(msginfo->xref) - 1;
721 while (*p == '\r' || *p == '\n') {
730 static gchar *news_parse_xhdr(const gchar *xhdr_str, MsgInfo *msginfo)
736 p = strchr(xhdr_str, ' ');
742 num = atoi(xhdr_str);
743 if (msginfo->msgnum != num) return NULL;
745 tmp = strchr(p, '\r');
746 if (!tmp) tmp = strchr(p, '\n');
749 return g_strndup(p, tmp - p);
754 gint news_cancel_article(Folder * folder, MsgInfo * msginfo)
760 tmp = g_strdup_printf("%s%ctmp%d", g_get_tmp_dir(),
761 G_DIR_SEPARATOR, (gint)msginfo);
765 if ((tmpfp = g_fopen(tmp, "wb")) == NULL) {
766 FILE_OP_ERROR(tmp, "fopen");
769 if (change_file_mode_rw(tmpfp, tmp) < 0) {
770 FILE_OP_ERROR(tmp, "chmod");
771 g_warning("can't change file mode\n");
774 fprintf(tmpfp, "From: %s\r\n", msginfo->from);
775 fprintf(tmpfp, "Newsgroups: %s\r\n", msginfo->newsgroups);
776 fprintf(tmpfp, "Subject: cmsg cancel <%s>\r\n", msginfo->msgid);
777 fprintf(tmpfp, "Control: cancel <%s>\r\n", msginfo->msgid);
778 fprintf(tmpfp, "Approved: %s\r\n", msginfo->from);
779 fprintf(tmpfp, "X-Cancelled-by: %s\r\n", msginfo->from);
780 get_rfc822_date(buf, sizeof(buf));
781 fprintf(tmpfp, "Date: %s\r\n", buf);
782 fprintf(tmpfp, "\r\n");
783 fprintf(tmpfp, "removed with sylpheed\r\n");
787 news_post(folder, tmp);
795 static gchar *news_folder_get_path(Folder *folder)
799 g_return_val_if_fail(folder->account != NULL, NULL);
801 folder_path = g_strconcat(get_news_cache_dir(),
803 folder->account->nntp_server,
808 gchar *news_item_get_path(Folder *folder, FolderItem *item)
810 gchar *folder_path, *path;
812 g_return_val_if_fail(folder != NULL, NULL);
813 g_return_val_if_fail(item != NULL, NULL);
814 folder_path = news_folder_get_path(folder);
816 g_return_val_if_fail(folder_path != NULL, NULL);
817 if (folder_path[0] == G_DIR_SEPARATOR) {
819 path = g_strconcat(folder_path, G_DIR_SEPARATOR_S,
822 path = g_strdup(folder_path);
825 path = g_strconcat(get_home_dir(), G_DIR_SEPARATOR_S,
826 folder_path, G_DIR_SEPARATOR_S,
829 path = g_strconcat(get_home_dir(), G_DIR_SEPARATOR_S,
837 gint news_get_num_list(Folder *folder, FolderItem *item, GSList **msgnum_list, gboolean *old_uids_valid)
839 NNTPSession *session;
840 gint i, ok, num, first, last, nummsgs = 0;
843 g_return_val_if_fail(item != NULL, -1);
844 g_return_val_if_fail(item->folder != NULL, -1);
845 g_return_val_if_fail(FOLDER_CLASS(folder) == &news_class, -1);
847 session = news_session_get(folder);
848 g_return_val_if_fail(session != NULL, -1);
850 *old_uids_valid = TRUE;
852 ok = news_select_group(session, item->path, &num, &first, &last);
853 if (ok != NN_SUCCESS) {
854 log_warning(_("can't set group: %s\n"), item->path);
858 dir = news_folder_get_path(folder);
860 remove_all_numbered_files(dir);
861 else if (last < first)
862 log_warning(_("invalid article range: %d - %d\n"),
865 for (i = first; i <= last; i++) {
866 *msgnum_list = g_slist_prepend(*msgnum_list,
870 debug_print("removing old messages from %d to %d in %s\n",
872 remove_numbered_files(dir, 1, first - 1);
879 #define READ_TO_LISTEND(hdr) \
880 while (!(buf[0] == '.' && buf[1] == '\r')) { \
881 if (sock_gets(SESSION(session)->sock, buf, sizeof(buf)) < 0) { \
882 log_warning(_("error occurred while getting %s.\n"), hdr); \
887 MsgInfo *news_get_msginfo(Folder *folder, FolderItem *item, gint num)
889 NNTPSession *session;
890 MsgInfo *msginfo = NULL;
891 gchar buf[NNTPBUFSIZE];
894 session = news_session_get(folder);
895 g_return_val_if_fail(session != NULL, NULL);
896 g_return_val_if_fail(item != NULL, NULL);
897 g_return_val_if_fail(item->folder != NULL, NULL);
898 g_return_val_if_fail(FOLDER_CLASS(item->folder) == &news_class, NULL);
900 log_message(_("getting xover %d in %s...\n"),
902 ok = nntp_xover(session, num, num);
903 if (ok != NN_SUCCESS) {
904 log_warning(_("can't get xover\n"));
905 if (ok == NN_SOCKET) {
906 session_destroy(SESSION(session));
907 REMOTE_FOLDER(item->folder)->session = NULL;
912 if (sock_gets(SESSION(session)->sock, buf, sizeof(buf)) < 0) {
913 log_warning(_("error occurred while getting xover.\n"));
917 msginfo = news_parse_xover(buf);
919 log_warning(_("invalid xover line: %s\n"), buf);
922 READ_TO_LISTEND("xover");
927 msginfo->folder = item;
928 msginfo->flags.perm_flags = MSG_NEW|MSG_UNREAD;
929 msginfo->flags.tmp_flags = MSG_NEWS;
930 msginfo->newsgroups = g_strdup(item->path);
932 ok = nntp_xhdr(session, "to", num, num);
933 if (ok != NN_SUCCESS) {
934 log_warning(_("can't get xhdr\n"));
935 if (ok == NN_SOCKET) {
936 session_destroy(SESSION(session));
937 REMOTE_FOLDER(item->folder)->session = NULL;
942 if (sock_gets(SESSION(session)->sock, buf, sizeof(buf)) < 0) {
943 log_warning(_("error occurred while getting xhdr.\n"));
947 msginfo->to = news_parse_xhdr(buf, msginfo);
949 READ_TO_LISTEND("xhdr (to)");
951 ok = nntp_xhdr(session, "cc", num, num);
952 if (ok != NN_SUCCESS) {
953 log_warning(_("can't get xhdr\n"));
954 if (ok == NN_SOCKET) {
955 session_destroy(SESSION(session));
956 REMOTE_FOLDER(item->folder)->session = NULL;
961 if (sock_gets(SESSION(session)->sock, buf, sizeof(buf)) < 0) {
962 log_warning(_("error occurred while getting xhdr.\n"));
966 msginfo->cc = news_parse_xhdr(buf, msginfo);
968 READ_TO_LISTEND("xhdr (cc)");
973 static GSList *news_get_msginfos_for_range(NNTPSession *session, FolderItem *item, guint begin, guint end)
975 gchar buf[NNTPBUFSIZE];
976 GSList *newlist = NULL;
977 GSList *llast = NULL;
979 guint count = 0, lines = (end - begin + 2) * 3;
982 g_return_val_if_fail(session != NULL, NULL);
983 g_return_val_if_fail(item != NULL, NULL);
985 log_message(_("getting xover %d - %d in %s...\n"),
986 begin, end, item->path);
987 ok = nntp_xover(session, begin, end);
988 if (ok != NN_SUCCESS) {
989 log_warning(_("can't get xover\n"));
990 if (ok == NN_SOCKET) {
991 session_destroy(SESSION(session));
992 REMOTE_FOLDER(item->folder)->session = NULL;
998 if (sock_gets(SESSION(session)->sock, buf, sizeof(buf)) < 0) {
999 log_warning(_("error occurred while getting xover.\n"));
1003 progressindicator_set_percentage
1004 (PROGRESS_TYPE_NETWORK,
1005 session->fetch_base_percentage +
1006 (((gfloat) count) / ((gfloat) lines)) * session->fetch_total_percentage);
1008 if (buf[0] == '.' && buf[1] == '\r') break;
1010 msginfo = news_parse_xover(buf);
1012 log_warning(_("invalid xover line: %s\n"), buf);
1016 msginfo->folder = item;
1017 msginfo->flags.perm_flags = MSG_NEW|MSG_UNREAD;
1018 msginfo->flags.tmp_flags = MSG_NEWS;
1019 msginfo->newsgroups = g_strdup(item->path);
1022 llast = newlist = g_slist_append(newlist, msginfo);
1024 llast = g_slist_append(llast, msginfo);
1025 llast = llast->next;
1029 ok = nntp_xhdr(session, "to", begin, end);
1030 if (ok != NN_SUCCESS) {
1031 log_warning(_("can't get xhdr\n"));
1032 if (ok == NN_SOCKET) {
1033 session_destroy(SESSION(session));
1034 REMOTE_FOLDER(item->folder)->session = NULL;
1042 if (sock_gets(SESSION(session)->sock, buf, sizeof(buf)) < 0) {
1043 log_warning(_("error occurred while getting xhdr.\n"));
1047 progressindicator_set_percentage
1048 (PROGRESS_TYPE_NETWORK,
1049 session->fetch_base_percentage +
1050 (((gfloat) count) / ((gfloat) lines)) * session->fetch_total_percentage);
1052 if (buf[0] == '.' && buf[1] == '\r') break;
1054 g_warning("llast == NULL\n");
1058 msginfo = (MsgInfo *)llast->data;
1059 msginfo->to = news_parse_xhdr(buf, msginfo);
1061 llast = llast->next;
1064 ok = nntp_xhdr(session, "cc", begin, end);
1065 if (ok != NN_SUCCESS) {
1066 log_warning(_("can't get xhdr\n"));
1067 if (ok == NN_SOCKET) {
1068 session_destroy(SESSION(session));
1069 REMOTE_FOLDER(item->folder)->session = NULL;
1077 if (sock_gets(SESSION(session)->sock, buf, sizeof(buf)) < 0) {
1078 log_warning(_("error occurred while getting xhdr.\n"));
1082 progressindicator_set_percentage
1083 (PROGRESS_TYPE_NETWORK,
1084 session->fetch_base_percentage +
1085 (((gfloat) count) / ((gfloat) lines)) * session->fetch_total_percentage);
1087 if (buf[0] == '.' && buf[1] == '\r') break;
1089 g_warning("llast == NULL\n");
1093 msginfo = (MsgInfo *)llast->data;
1094 msginfo->cc = news_parse_xhdr(buf, msginfo);
1096 llast = llast->next;
1099 session_set_access_time(SESSION(session));
1104 GSList *news_get_msginfos(Folder *folder, FolderItem *item, GSList *msgnum_list)
1106 NNTPSession *session;
1107 GSList *elem, *msginfo_list = NULL, *tmp_msgnum_list, *tmp_msginfo_list;
1108 guint first, last, next;
1109 guint tofetch, fetched;
1111 g_return_val_if_fail(folder != NULL, NULL);
1112 g_return_val_if_fail(FOLDER_CLASS(folder) == &news_class, NULL);
1113 g_return_val_if_fail(msgnum_list != NULL, NULL);
1114 g_return_val_if_fail(item != NULL, NULL);
1116 session = news_session_get(folder);
1117 g_return_val_if_fail(session != NULL, NULL);
1119 tmp_msgnum_list = g_slist_copy(msgnum_list);
1120 tmp_msgnum_list = g_slist_sort(tmp_msgnum_list, g_int_compare);
1122 progressindicator_start(PROGRESS_TYPE_NETWORK);
1123 tofetch = g_slist_length(tmp_msgnum_list);
1126 first = GPOINTER_TO_INT(tmp_msgnum_list->data);
1128 for(elem = g_slist_next(tmp_msgnum_list); elem != NULL; elem = g_slist_next(elem)) {
1129 next = GPOINTER_TO_INT(elem->data);
1130 if(next != (last + 1)) {
1131 session->fetch_base_percentage = ((gfloat) fetched) / ((gfloat) tofetch);
1132 session->fetch_total_percentage = ((gfloat) (last - first + 1)) / ((gfloat) tofetch);
1133 tmp_msginfo_list = news_get_msginfos_for_range(session, item, first, last);
1134 msginfo_list = g_slist_concat(msginfo_list, tmp_msginfo_list);
1135 fetched = last - first + 1;
1140 session->fetch_base_percentage = ((gfloat) fetched) / ((gfloat) tofetch);
1141 session->fetch_total_percentage = ((gfloat) (last - first + 1)) / ((gfloat) tofetch);
1142 tmp_msginfo_list = news_get_msginfos_for_range(session, item, first, last);
1143 msginfo_list = g_slist_concat(msginfo_list, tmp_msginfo_list);
1145 g_slist_free(tmp_msgnum_list);
1147 progressindicator_stop(PROGRESS_TYPE_NETWORK);
1149 return msginfo_list;
1152 gboolean news_scan_required(Folder *folder, FolderItem *item)
1157 void news_synchronise(FolderItem *item)
1159 news_gtk_synchronise(item);