# include "config.h"
#endif
+#include "defs.h"
+
#include <glib.h>
#include <stdio.h>
#include <string.h>
#include <dirent.h>
#include <unistd.h>
-#include "defs.h"
#include "intl.h"
#include "news.h"
#include "nntp.h"
gint num,
gchar *filename);
+static gint news_select_group (NNTPSession *session,
+ const char *group);
static GSList *news_get_uncached_articles(NNTPSession *session,
FolderItem *item,
gint cache_last,
gint *rfirst,
gint *rlast);
static MsgInfo *news_parse_xover (const gchar *xover_str);
+static gchar * news_parse_xhdr (const gchar *xover_str,
+ MsgInfo * info);
static GSList *news_delete_old_article (GSList *alist,
gint first);
static void news_delete_all_article (FolderItem *item);
nntp_sock = nntp_open_auth(server, port, buf, userid, passwd);
else
nntp_sock = nntp_open(server, port, buf);
- if (nntp_sock < 0)
+ if (nntp_sock == NULL)
return NULL;
session = g_new(NNTPSession, 1);
gchar *passwd;
ac = folder->account;
- if (ac->userid && ac->userid[0]) {
+ if (ac->use_nntp_auth && ac->userid && ac->userid[0]) {
userid = ac->userid;
if (ac->passwd && ac->passwd[0])
passwd = g_strdup(ac->passwd);
g_return_val_if_fail(item != NULL, NULL);
path = folder_item_get_path(item);
+ if (!is_dir_exist(path))
+ make_dir_hier(path);
+
filename = g_strconcat(path, G_DIR_SEPARATOR_S, itos(num), NULL);
g_free(path);
return NULL;
}
+ ok = news_select_group(NNTP_SESSION(REMOTE_FOLDER(folder)->session),
+ item->path);
+ if (ok != NN_SUCCESS) {
+ g_warning(_("can't select group %s\n"), item->path);
+ g_free(filename);
+ return NULL;
+ }
+
debug_print(_("getting article %d...\n"), num);
ok = news_get_article(NNTP_SESSION(REMOTE_FOLDER(folder)->session),
num, filename);
return news_get_article_cmd(session, "HEAD", num, filename);
}
+/**
+ * news_select_group:
+ * @session: Active NNTP session.
+ * @group: Newsgroup name.
+ *
+ * Select newsgroup @group with the GROUP command if it is not already
+ * selected in @session.
+ *
+ * Return value: NNTP result code.
+ **/
+static gint news_select_group(NNTPSession *session,
+ const char *group)
+{
+ gint ok;
+ gint num, first, last;
+
+ if (g_strcasecmp(session->group, group) == 0)
+ return NN_SUCCESS;
+
+ g_free(session->group);
+ session->group = NULL;
+
+ ok = nntp_group(session->nntp_sock, group, &num, &first, &last);
+
+ if (ok == NN_SUCCESS)
+ session->group = g_strdup(group);
+
+ return ok;
+}
+
static GSList *news_get_uncached_articles(NNTPSession *session,
FolderItem *item, gint cache_last,
gint *rfirst, gint *rlast)
g_return_val_if_fail(item->folder != NULL, NULL);
g_return_val_if_fail(item->folder->type == F_NEWS, NULL);
+ g_free(session->group);
+ session->group = NULL;
+
ok = nntp_group(session->nntp_sock, item->path,
&num, &first, &last);
if (ok != NN_SUCCESS) {
return NULL;
}
+ session->group = g_strdup(item->path);
+
/* calculate getting overview range */
if (first > last) {
log_warning(_("invalid article range: %d - %d\n"),
}
for (;;) {
- if (sock_read(SESSION(session)->sock, buf, sizeof(buf)) < 0) {
+ if (sock_gets(SESSION(session)->sock, buf, sizeof(buf)) < 0) {
log_warning(_("error occurred while getting xover.\n"));
return newlist;
}
msginfo->folder = item;
msginfo->flags = MSG_NEW|MSG_UNREAD|MSG_NEWS;
+ msginfo->newsgroups = g_strdup(item->path);
if (!newlist)
llast = newlist = g_slist_append(newlist, msginfo);
}
}
+ if (nntp_xhdr(session->nntp_sock, "to", begin, end) != NN_SUCCESS) {
+ log_warning(_("can't get xhdr\n"));
+ return NULL;
+ }
+
+ llast = newlist;
+
+ for (;;) {
+ gchar * value;
+
+ if (sock_gets(SESSION(session)->sock, buf, sizeof(buf)) < 0) {
+ log_warning(_("error occurred while getting xover.\n"));
+ return newlist;
+ }
+
+ if (buf[0] == '.' && buf[1] == '\r') break;
+
+ msginfo = (MsgInfo *) llast->data;
+
+ value = news_parse_xhdr(buf, msginfo);
+
+ if (value)
+ msginfo->to = value;
+
+ llast = llast->next;
+
+ }
+
+ if (nntp_xhdr(session->nntp_sock, "cc", begin, end) != NN_SUCCESS) {
+ log_warning(_("can't get xhdr\n"));
+ return NULL;
+ }
+
+ llast = newlist;
+
+ for (;;) {
+ gchar * value;
+
+ if (sock_gets(SESSION(session)->sock, buf, sizeof(buf)) < 0) {
+ log_warning(_("error occurred while getting xover.\n"));
+ return newlist;
+ }
+
+ if (buf[0] == '.' && buf[1] == '\r') break;
+
+ msginfo = (MsgInfo *) llast->data;
+
+ value = news_parse_xhdr(buf, msginfo);
+
+ if (value)
+ msginfo->cc = value;
+
+ llast = llast->next;
+ }
+
if (rfirst) *rfirst = first;
if (rlast) *rlast = last;
return newlist;
if (*msgid != '\0')
msginfo->msgid = g_strdup(msgid);
+ msginfo->references = g_strdup(ref);
eliminate_parenthesis(ref, '(', ')');
if ((p = strrchr(ref, '<')) != NULL) {
extract_parenthesis(p, '<', '>');
return msginfo;
}
+static gchar * news_parse_xhdr(const gchar *xover_str, MsgInfo * info)
+{
+ gchar buf[NNTPBUFSIZE];
+ gchar *p;
+ gint num;
+ gchar * tmp;
+
+ p = strchr(xover_str, ' ');
+ if (!p)
+ return NULL;
+ else
+ p++;
+
+ num = atoi(xover_str);
+
+ if (info->msgnum != num)
+ return NULL;
+
+ tmp = strchr(p, '\r');
+ if (!tmp) tmp = strchr(p, '\n');
+
+ if (tmp)
+ return g_strndup(p, tmp - p);
+ else
+ return g_strdup(p);
+}
+
static GSList *news_delete_old_article(GSList *alist, gint first)
{
GSList *cur, *next;
gchar *file;
dir = folder_item_get_path(item);
+ if (!is_dir_exist(dir))
+ make_dir_hier(dir);
+
if ((dp = opendir(dir)) == NULL) {
FILE_OP_ERROR(dir, "opendir");
g_free(dir);
debug_print(_("\tDeleting cached group list... "));
path = folder_item_get_path(item);
+ if (!is_dir_exist(path))
+ make_dir_hier(path);
+
filename = g_strconcat(path, G_DIR_SEPARATOR_S, GROUPLIST_FILE, NULL);
g_free(path);
if (remove(filename) != 0)