2 * Copyright notice from original mutt:
3 * Copyright (C) 1998 Brandon Long <blong@fiction.net>
4 * Copyright (C) 1999 Andrej Gritsenko <andrej@lucky.net>
5 * Copyright (C) 2000-2001 Vsevolod Volkov <vvv@mutt.org.ua>
7 * This file is part of mutt-ng, see http://www.muttng.org/.
8 * It's licensed under the GNU General Public License,
9 * please see the file GPL in the top level source directory.
16 #include <lib-lib/mem.h>
17 #include <lib-lib/str.h>
18 #include <lib-lib/file.h>
19 #include <lib-lib/macros.h>
21 #include <lib-mime/mime.h>
24 #include "mutt_curses.h"
31 #include "lib/debug.h"
40 void nntp_add_to_list (NNTP_SERVER * s, NNTP_DATA * d)
56 static int nntp_parse_newsrc_line (NNTP_SERVER * news, char *line)
59 char group[LONG_STRING];
61 char *p = line, *b, *h;
70 while (*p && (*p != ':' && *p != '!'))
75 if (len > sizeof (group))
77 m_strcpy(group, len, line);
78 if ((data = (NNTP_DATA *) hash_find (news->newsgroups, group)) == NULL) {
79 data = xmalloc(sizeof(NNTP_DATA) + m_strlen(group) + 1);
80 data->group = (char *) data + sizeof (NNTP_DATA);
81 strcpy (data->group, group);
84 if (news->newsgroups->nelem < news->newsgroups->curnelem * 2)
86 hash_resize (news->newsgroups, news->newsgroups->nelem * 2);
87 hash_insert (news->newsgroups, data->group, data, 0);
88 nntp_add_to_list (news, data);
91 p_delete(&data->entries);
94 data->entries = p_new(NEWSRC_ENTRY, x * 2);
100 data->subscribed = 0;
106 while (*p && *p != ',' && *p != '\n')
112 if ((h = strchr (b, '-'))) {
115 data->entries[x].first = atoi (b);
116 data->entries[x].last = atoi (h);
119 data->entries[x].first = atoi (b);
120 data->entries[x].last = data->entries[x].first;
123 if (data->entries[x].last != 0)
126 if (x && !data->lastMessage)
127 data->lastMessage = data->entries[x - 1].last;
129 mutt_newsgroup_stat (data);
130 debug_print (2, ("Newsgroup %s\n", data->group));
135 static int slurp_newsrc (NNTP_SERVER * news)
141 news->stat = stat (news->newsrc, &sb);
142 news->size = sb.st_size;
143 news->mtime = sb.st_mtime;
145 if ((fp = safe_fopen (news->newsrc, "r")) == NULL)
147 /* hmm, should we use dotlock? */
148 if (mx_lock_file (news->newsrc, fileno (fp), 0, 0, 1)) {
153 buf = p_new(char, sb.st_size + 1);
154 while (fgets (buf, sb.st_size + 1, fp))
155 nntp_parse_newsrc_line (news, buf);
158 mx_unlock_file (news->newsrc, fileno (fp), 0);
163 void nntp_cache_expand (char *dst, const char *src)
165 snprintf (dst, _POSIX_PATH_MAX, "%s/%s", NewsCacheDir, src);
166 mutt_expand_path (dst, _POSIX_PATH_MAX);
169 /* Loads $news_cache_dir/.index into memory, loads newsserver data
170 * and newsgroup cache names */
171 static int nntp_parse_cacheindex (NNTP_SERVER * news)
174 char buf[HUGE_STRING], *cp;
175 char dir[_POSIX_PATH_MAX], file[_POSIX_PATH_MAX];
180 /* check is server name defined or not */
181 if (!news || !news->conn || !news->conn->account.host)
183 unset_option (OPTNEWSCACHE);
184 if (!NewsCacheDir || !*NewsCacheDir)
187 m_strcpy(dir, sizeof(dir), NewsCacheDir);
188 mutt_expand_path (dir, sizeof (dir));
190 if (lstat (dir, &st) || (st.st_mode & S_IFDIR) == 0) {
191 snprintf (buf, sizeof (buf), _("Directory %s not exist. Create it?"),
193 if (mutt_yesorno (buf, M_YES) != M_YES
194 || mkdir (dir, (S_IRWXU + S_IRWXG + S_IRWXO))) {
195 mutt_error _("Cache directory not created!");
202 set_option (OPTNEWSCACHE);
204 p_delete(&news->cache);
205 snprintf (buf, sizeof (buf), "%s/.index", dir);
206 if (!(index = safe_fopen (buf, "a+")))
209 while (fgets (buf, sizeof (buf), index)) {
210 buf[m_strlen(buf) - 1] = 0; /* strip ending '\n' */
211 if (!m_strncmp(buf, "#: ", 3) &&
212 !m_strcasecmp(buf + 3, news->conn->account.host))
215 while (fgets (buf, sizeof (buf), index)) {
217 while (*cp && *cp != ' ')
222 if (!m_strcmp(buf, "#:"))
224 sscanf (cp + 1, "%s %d %d", file, &l, &m);
225 if (!m_strcmp(buf, "ALL")) {
226 news->cache = m_strdup(file);
227 news->newgroups_time = m;
229 else if (news->newsgroups) {
230 if ((data = (NNTP_DATA *) hash_find (news->newsgroups, buf)) == NULL) {
231 data = xmalloc(sizeof(NNTP_DATA) + m_strlen(buf) + 1);
232 data->group = (char *) data + sizeof (NNTP_DATA);
233 strcpy (data->group, buf);
236 if (news->newsgroups->nelem < news->newsgroups->curnelem * 2)
238 hash_resize (news->newsgroups, news->newsgroups->nelem * 2);
239 hash_insert (news->newsgroups, data->group, data, 0);
240 nntp_add_to_list (news, data);
242 data->cache = m_strdup(file);
244 if (!data->firstMessage || data->lastMessage < m)
246 if (!data->firstMessage)
247 data->firstMessage = l;
248 if (data->lastMessage < m)
249 data->lastMessage = m;
250 data->lastCached = m;
251 if (t || !data->unread)
252 mutt_newsgroup_stat (data);
259 const char *nntp_format_str (char *dest, size_t destlen, char op,
260 const char *src, const char *fmt,
261 const char *ifstring, const char *elsestring,
262 unsigned long data, format_flag flags)
264 char fn[SHORT_STRING], tmp[SHORT_STRING];
268 m_strcpy(fn, sizeof (fn), NewsServer);
270 snprintf (tmp, sizeof (tmp), "%%%ss", fmt);
271 snprintf (dest, destlen, tmp, fn);
277 /* nntp_parse_url: given an NNPT URL, return host, port,
278 * username, password and newsgroup will recognise. */
279 int nntp_parse_url (const char *server, ACCOUNT * acct,
280 char *group, size_t group_len)
288 acct->port = NNTP_PORT;
289 acct->type = M_ACCT_TYPE_NNTP;
291 c = m_strdup(server);
292 url_parse_ciss (&url, c);
294 if (url.scheme == U_NNTP || url.scheme == U_NNTPS) {
295 if (url.scheme == U_NNTPS) {
296 acct->flags |= M_ACCT_SSL;
297 acct->port = NNTP_SSL_PORT;
302 m_strcpy(group, group_len, url.path);
304 ret = mutt_account_fromurl (acct, &url);
311 void nntp_expand_path (char *line, size_t len, ACCOUNT * acct)
315 url.path = m_strdup(line);
316 mutt_account_tourl (acct, &url);
317 url_ciss_tostring (&url, line, len, 0);
322 * Automatically loads a newsrc into memory, if necessary.
323 * Checks the size/mtime of a newsrc file, if it doesn't match, load
324 * again. Hmm, if a system has broken mtimes, this might mean the file
325 * is reloaded every time, which we'd have to fix.
327 * a newsrc file is a line per newsgroup, with the newsgroup, then a
328 * ':' denoting subscribed or '!' denoting unsubscribed, then a
329 * comma separated list of article numbers and ranges.
331 NNTP_SERVER *mutt_select_newsserver (char *server)
333 char file[_POSIX_PATH_MAX];
342 if (!server || !*server) {
343 mutt_error _("No newsserver defined!");
348 buf = p = p_new(char, m_strlen(server) + 10);
349 if (url_check_scheme (server) == U_UNKNOWN) {
350 strcpy (buf, "nntp://");
351 p = strchr (buf, '\0');
355 if ((nntp_parse_url (buf, &acct, file, sizeof (file))) < 0 || *file) {
357 mutt_error (_("%s is an invalid newsserver specification!"), server);
362 conn = mutt_conn_find (NULL, &acct);
366 mutt_FormatString (file, sizeof (file), NONULL (NewsRc), nntp_format_str, 0,
368 mutt_expand_path (file, sizeof (file));
370 serv = (NNTP_SERVER *) conn->data;
374 /* externally modified? */
375 if (serv->stat != stat (file, &sb) || (!serv->stat &&
376 (serv->size != sb.st_size
377 || serv->mtime != sb.st_mtime))) {
378 for (list = serv->list; list; list = list->next) {
379 NNTP_DATA *data = (NNTP_DATA *) list->data;
382 data->subscribed = 0;
388 nntp_clear_cacheindex (serv);
391 if (serv->status == NNTP_BYE)
392 serv->status = NNTP_NONE;
393 nntp_check_newgroups (serv, 0);
398 serv = p_new(NNTP_SERVER, 1);
400 serv->newsrc = m_strdup(file);
401 serv->newsgroups = hash_create (1009);
402 slurp_newsrc (serv); /* load .newsrc */
403 nntp_parse_cacheindex (serv); /* load .index */
404 if (option (OPTNEWSCACHE) && serv->cache && nntp_get_cache_all (serv) >= 0)
405 nntp_check_newgroups (serv, 1);
406 else if (nntp_get_active (serv) < 0) {
407 hash_destroy (&serv->newsgroups, nntp_delete_data);
408 for (list = serv->list; list; list = list->next)
410 mutt_free_list (&serv->list);
411 p_delete(&serv->newsrc);
412 p_delete(&serv->cache);
416 nntp_clear_cacheindex (serv);
417 conn->data = (void *) serv;
423 * full status flags are not supported by nntp, but we can fake some
424 * of them. This is how:
425 * Read = a read message number is in the .newsrc
426 * New = a message is new since we last read this newsgroup
427 * Old = anything else
428 * So, Read is marked as such in the newsrc, old is anything that is
429 * "skipped" in the newsrc, and new is anything not in the newsrc nor
430 * in the cache. By skipped, I mean before the last unread message
432 void nntp_get_status (CONTEXT * ctx, HEADER * h, char *group, int article)
434 NNTP_DATA *data = (NNTP_DATA *) ctx->data;
438 data = (NNTP_DATA *) hash_find (data->nserv->newsgroups, group);
443 debug_print (3, ("newsgroup %s not found\n", group));
448 for (x = 0; x < data->num; x++) {
449 if ((article >= data->entries[x].first) &&
450 (article <= data->entries[x].last)) {
451 /* we cannot use mutt_set_flag() because mx_update_context()
457 /* If article was not cached yet, it is new! :) */
458 if (!data->cache || article > data->lastCached)
460 /* Old articles are articles which aren't read but an article after them
462 if (option (OPTMARKOLD))
466 void mutt_newsgroup_stat (NNTP_DATA * data)
469 unsigned int first, last;
472 if (data->lastMessage == 0 || data->firstMessage > data->lastMessage)
475 data->unread = data->lastMessage - data->firstMessage + 1;
476 for (i = 0; i < data->num; i++) {
477 first = data->entries[i].first;
478 if (first < data->firstMessage)
479 first = data->firstMessage;
480 last = data->entries[i].last;
481 if (last > data->lastMessage)
482 last = data->lastMessage;
484 data->unread -= last - first + 1;
488 static int puti (char *line, int num)
493 *p++ = '0' + num % 10;
497 *line++ = *--p, num++;
502 static void nntp_create_newsrc_line (NNTP_DATA * data, char **buf,
503 char **pline, size_t * buflen)
506 size_t len = *buflen - (*pline - *buf);
509 if (len < LONG_STRING * 10) {
513 p_realloc(buf, *buflen);
514 line = *buf + (*pline - line);
516 strcpy (line, data->group);
517 len -= m_strlen(line) + 1;
518 line += m_strlen(line);
519 *line++ = data->subscribed ? ':' : '!';
523 for (x = 0; x < data->num; x++) {
524 if (len < LONG_STRING) {
529 p_realloc(buf, *buflen);
530 line = *buf + (*pline - line);
538 if (data->entries[x].first == data->entries[x].last)
539 snprintf (line, len, "%d%n", data->entries[x].first, &i);
541 snprintf (line, len, "%d-%d%n",
542 data->entries[x].first, data->entries[x].last, &i);
546 i = puti (line, data->entries[x].first);
549 if (data->entries[x].first != data->entries[x].last) {
552 i = puti (line, data->entries[x].last);
563 void newsrc_gen_entries (CONTEXT * ctx)
565 NNTP_DATA *data = (NNTP_DATA *) ctx->data;
567 unsigned int last = 0, first = 1;
568 int save_sort = SORT_ORDER;
570 if (Sort != SORT_ORDER) {
573 mutt_sort_headers (ctx, 0);
577 data->entries = p_new(NEWSRC_ENTRY, 5);
582 * Set up to fake initial sequence from 1 to the article before the
583 * first article in our list
588 for (x = 0; x < ctx->msgcount; x++) {
589 if (series) { /* search for first unread */
591 * We don't actually check sequential order, since we mark
592 * "missing" entries as read/deleted
594 last = ctx->hdrs[x]->article_num;
595 if (last >= data->firstMessage && !ctx->hdrs[x]->deleted &&
596 !ctx->hdrs[x]->read) {
597 if (data->num >= data->max) {
598 data->max = data->max * 2;
599 p_realloc(&data->entries, data->max);
601 data->entries[data->num].first = first;
602 data->entries[data->num].last = last - 1;
607 else { /* search for first read */
609 if (ctx->hdrs[x]->deleted || ctx->hdrs[x]->read) {
613 last = ctx->hdrs[x]->article_num;
616 if (series && first <= data->lastLoaded) {
617 if (data->num >= data->max) {
618 data->max = data->max * 2;
619 p_realloc(&data->entries, data->max);
621 data->entries[data->num].first = first;
622 data->entries[data->num].last = data->lastLoaded;
626 if (save_sort != Sort) {
628 mutt_sort_headers (ctx, 0);
632 static int mutt_update_list_file (char *filename, char *section,
633 const char *key, char *line) {
636 char buf[HUGE_STRING];
637 char tmpfile[_POSIX_PATH_MAX], link[_POSIX_PATH_MAX];
639 int ext = 0, done = 0, r = 0, l = 0;
641 /* if file not exist, create it */
642 if ((ifp = safe_fopen (filename, "a")))
644 debug_print (1, ("Opening %s\n", filename));
645 if (!(ifp = safe_fopen (filename, "r"))) {
646 mutt_error (_("Unable to open %s for reading"), filename);
649 if (mx_lock_file (filename, fileno (ifp), 0, 0, 1)) {
651 mutt_error (_("Unable to lock %s"), filename);
654 /* use mutt_adv_mktemp() to get a tempfile in the same
655 * directory as filename is so that we can follow symlinks
656 * via rename(2); as dirname(2) may modify its argument,
657 * temporarily use buf as copy of it
659 m_strcpy(buf, sizeof(buf), filename);
660 m_strcpy(tmpfile, sizeof(tmpfile), basename(filename));
661 mutt_adv_mktemp ((const char*) dirname (buf), tmpfile, sizeof (tmpfile));
662 debug_print (1, ("Opening %s\n", tmpfile));
663 if (!(ofp = fopen (tmpfile, "w"))) {
665 mutt_error (_("Unable to open %s for writing"), tmpfile);
670 while (r != EOF && !done && fgets (buf, sizeof (buf), ifp)) {
671 r = fputs (buf, ofp);
673 while (*c && *c != '\n') c++;
674 c[0] = 0; /* strip EOL */
675 if (!strncmp (buf, "#: ", 3) && !m_strcasecmp(buf+3, section))
678 if (r != EOF && !done) {
679 snprintf (buf, sizeof(buf), "#: %s\n", section);
680 r = fputs (buf, ofp);
685 while (r != EOF && fgets (buf, sizeof (buf), ifp)) {
688 while (*c && (*c != '\r') && (*c != '\n')) c++;
690 if (*c != '\\') ext = 0;
691 } else if ((section && !strncmp (buf, "#: ", 3))) {
696 r = fputs (buf, ofp);
699 } else if (key && !strncmp (buf, key, strlen(key)) &&
700 (!*key || buf[strlen(key)] == ' ')) {
703 while (*c && (*c != '\r') && (*c != '\n')) c++;
705 if (*c == '\\') ext = 1;
707 r = fputs (line, ofp);
709 r = fputc ('\n', ofp);
713 r = fputs (buf, ofp);
717 while (r != EOF && fgets (buf, sizeof (buf), ifp))
718 r = fputs (buf, ofp);
720 /* If there wasn't a line to replace, put it on the end of the file */
721 if (r != EOF && !done && line) {
723 r = fputc ('\n', ofp);
725 mx_unlock_file (filename, fileno (ifp), 0);
730 mutt_error (_("Can't write %s"), tmpfile);
734 if ((l = readlink (filename, link, sizeof (link)-1)) > 0)
736 debug_print (1, ("Renaming %s to %s\n",tmpfile, l > 0 ? link : filename));
737 if (rename (tmpfile, l > 0 ? link : filename) < 0) {
739 mutt_error (_("Can't rename %s to %s"), tmpfile, l > 0 ? link : filename);
745 int mutt_newsrc_update (NNTP_SERVER * news)
755 llen = len = 10 * LONG_STRING;
756 line = buf = p_new(char, len);
757 /* we will generate full newsrc here */
758 for (tmp = news->list; tmp; tmp = tmp->next) {
759 data = (NNTP_DATA *) tmp->data;
760 if (!data || !data->rc)
762 nntp_create_newsrc_line (data, &buf, &line, &llen);
763 debug_print (2, ("Added to newsrc: %s\n", line));
764 line += m_strlen(line);
766 /* newrc being fully rewritten */
768 (r = mutt_update_list_file(news->newsrc, NULL, "", buf)) == 0) {
771 stat (news->newsrc, &st);
772 news->size = st.st_size;
773 news->mtime = st.st_mtime;
779 static FILE *mutt_mkname (char *s)
781 char buf[_POSIX_PATH_MAX], *pc;
785 nntp_cache_expand (buf, s);
786 if ((fp = safe_fopen (buf, "w")))
789 nntp_cache_expand (buf, "cache-XXXXXX");
790 pc = buf + m_strlen(buf) - 12; /* positioning to "cache-XXXXXX" */
791 if ((fd = mkstemp (buf)) == -1)
793 strcpy (s, pc); /* generated name */
794 return fdopen (fd, "w");
797 /* Updates info into .index file: ALL or about selected newsgroup */
798 static int nntp_update_cacheindex (NNTP_SERVER * serv, NNTP_DATA * data)
800 char buf[LONG_STRING];
801 char file[_POSIX_PATH_MAX];
802 const char *key = "ALL";
804 if (!serv || !serv->conn || !serv->conn->account.host)
807 if (data && data->group) {
809 snprintf (buf, sizeof (buf), "%s %s %d %d", key, data->cache,
810 data->firstMessage, data->lastLoaded);
813 m_strcpy(file, sizeof(file), serv->cache);
814 snprintf (buf, sizeof (buf), "ALL %s 0 %d", file,
815 (int) serv->newgroups_time);
817 nntp_cache_expand (file, ".index");
818 return mutt_update_list_file (file, serv->conn->account.host, key, buf);
821 /* Remove cache files of unsubscribed newsgroups */
822 void nntp_clear_cacheindex (NNTP_SERVER * news)
827 if (option (OPTSAVEUNSUB) || !news)
830 for (tmp = news->list; tmp; tmp = tmp->next) {
831 data = (NNTP_DATA *) tmp->data;
832 if (!data || data->subscribed || !data->cache)
834 nntp_delete_cache (data);
835 debug_print (2, ("Removed from .index: %s\n", data->group));
840 int nntp_save_cache_index (NNTP_SERVER * news)
842 char buf[HUGE_STRING];
843 char file[_POSIX_PATH_MAX];
848 if (!news || !news->newsgroups)
850 if (!option (OPTNEWSCACHE))
854 nntp_cache_expand (file, news->cache);
856 f = safe_fopen (file, "w");
859 m_strcpy(buf, sizeof(buf), news->conn->account.host);
860 f = mutt_mkname (buf);
861 news->cache = m_strdup(buf);
862 nntp_cache_expand (file, buf);
867 for (l = news->list; l; l = l->next) {
868 if ((d = (NNTP_DATA *) l->data) && !d->deleted) {
870 snprintf (buf, sizeof (buf), "%s %d %d %c %s\n", d->group,
871 d->lastMessage, d->firstMessage, d->allowed ? 'y' : 'n',
874 snprintf (buf, sizeof (buf), "%s %d %d %c\n", d->group,
875 d->lastMessage, d->firstMessage, d->allowed ? 'y' : 'n');
876 if (fputs (buf, f) == EOF) {
885 if (nntp_update_cacheindex (news, NULL)) {
892 int nntp_save_cache_group (CONTEXT * ctx)
894 char buf[HUGE_STRING], addr[STRING];
895 char file[_POSIX_PATH_MAX];
899 int i = 0, save = SORT_ORDER;
902 if (!option (OPTNEWSCACHE))
904 if (!ctx || !ctx->data || ctx->magic != M_NNTP)
907 if (((NNTP_DATA *) ctx->data)->cache) {
908 nntp_cache_expand (file, ((NNTP_DATA *) ctx->data)->cache);
910 f = safe_fopen (file, "w");
913 snprintf (buf, sizeof (buf), "%s-%s",
914 ((NNTP_DATA *) ctx->data)->nserv->conn->account.host,
915 ((NNTP_DATA *) ctx->data)->group);
916 f = mutt_mkname (buf);
917 ((NNTP_DATA *) ctx->data)->cache = m_strdup(buf);
918 nntp_cache_expand (file, buf);
923 if (Sort != SORT_ORDER) {
926 mutt_sort_headers (ctx, 0);
929 /* Save only $nntp_context messages... */
930 ((NNTP_DATA *) ctx->data)->lastCached = 0;
931 if (NntpContext && ctx->msgcount > NntpContext)
932 i = ctx->msgcount - NntpContext;
933 for (; i < ctx->msgcount; i++) {
934 if (!ctx->hdrs[i]->deleted && ctx->hdrs[i]->article_num != prev) {
937 rfc822_write_address (addr, sizeof (addr), h->env->from, 0);
938 tm = gmtime (&h->date_sent);
939 snprintf (buf, sizeof (buf),
940 "%d\t%s\t%s\t%d %s %d %02d:%02d:%02d GMT\t%s\t",
941 h->article_num, h->env->subject, addr, tm->tm_mday,
942 Months[tm->tm_mon], tm->tm_year + 1900, tm->tm_hour,
943 tm->tm_min, tm->tm_sec, h->env->message_id);
945 if (h->env->references)
946 mutt_write_references (h->env->references, f);
947 snprintf (buf, sizeof (buf), "\t%zd\t%d\tXref: %s\n",
948 h->content->length, h->lines, NONULL (h->env->xref));
949 if (fputs (buf, f) == EOF) {
955 prev = ctx->hdrs[i]->article_num;
960 mutt_sort_headers (ctx, 0);
964 if (nntp_update_cacheindex (((NNTP_DATA *) ctx->data)->nserv,
965 (NNTP_DATA *) ctx->data)) {
969 ((NNTP_DATA *) ctx->data)->lastCached =
970 ((NNTP_DATA *) ctx->data)->lastLoaded;
974 void nntp_delete_cache (NNTP_DATA * data)
976 char buf[_POSIX_PATH_MAX];
978 if (!option (OPTNEWSCACHE) || !data || !data->cache || !data->nserv)
981 nntp_cache_expand (buf, data->cache);
983 p_delete(&data->cache);
984 data->lastCached = 0;
985 nntp_cache_expand (buf, ".index");
986 mutt_update_list_file (buf, data->nserv->conn->account.host, data->group,
990 NNTP_DATA *mutt_newsgroup_subscribe (NNTP_SERVER * news, char *group)
994 if (!news || !news->newsgroups || !group || !*group)
996 if (!(data = (NNTP_DATA *) hash_find (news->newsgroups, group))) {
997 data = xmalloc(sizeof(NNTP_DATA) + m_strlen(group) + 1);
998 data->group = (char *) data + sizeof (NNTP_DATA);
999 strcpy (data->group, group);
1002 if (news->newsgroups->nelem < news->newsgroups->curnelem * 2)
1004 hash_resize (news->newsgroups, news->newsgroups->nelem * 2);
1005 hash_insert (news->newsgroups, data->group, data, 0);
1006 nntp_add_to_list (news, data);
1008 if (!data->subscribed) {
1009 data->subscribed = 1;
1015 NNTP_DATA *mutt_newsgroup_unsubscribe (NNTP_SERVER * news, char *group)
1019 if (!news || !news->newsgroups || !group || !*group ||
1020 !(data = (NNTP_DATA *) hash_find (news->newsgroups, group)))
1022 if (data->subscribed) {
1023 data->subscribed = 0;
1024 if (!option (OPTSAVEUNSUB))
1030 NNTP_DATA *mutt_newsgroup_catchup (NNTP_SERVER * news, char *group)
1034 if (!news || !news->newsgroups || !group || !*group ||
1035 !(data = (NNTP_DATA *) hash_find (news->newsgroups, group)))
1038 data->entries = p_new(NEWSRC_ENTRY, 5);
1042 data->entries[0].first = 1;
1044 data->entries[0].last = data->lastMessage;
1045 if (Context && Context->data == data) {
1048 for (x = 0; x < Context->msgcount; x++)
1049 mutt_set_flag (Context, Context->hdrs[x], M_READ, 1);
1054 NNTP_DATA *mutt_newsgroup_uncatchup (NNTP_SERVER * news, char *group)
1058 if (!news || !news->newsgroups || !group || !*group ||
1059 !(data = (NNTP_DATA *) hash_find (news->newsgroups, group)))
1062 data->entries = p_new(NEWSRC_ENTRY, 5);
1066 data->entries[0].first = 1;
1067 data->entries[0].last = data->firstMessage - 1;
1068 if (Context && Context->data == data) {
1071 data->unread = Context->msgcount;
1072 for (x = 0; x < Context->msgcount; x++)
1073 mutt_set_flag (Context, Context->hdrs[x], M_READ, 0);
1076 data->unread = data->lastMessage - data->entries[0].last;
1080 /* this routine gives the first newsgroup with new messages */
1081 void nntp_buffy (char* dst, size_t dstlen) {
1085 /* forward to current group */
1086 for (list = CurrentNewsSrv->list; list; list = list->next) {
1087 NNTP_DATA *data = (NNTP_DATA *) list->data;
1088 if (data && data->subscribed && data->unread &&
1089 Context && Context->magic == M_NNTP &&
1090 m_strcmp(data->group, ((NNTP_DATA *) Context->data)->group) == 0) {
1101 list = CurrentNewsSrv->list;
1103 for (; list; list = list->next) {
1104 NNTP_DATA *data = (NNTP_DATA *) list->data;
1106 if (data && data->subscribed && data->unread) {
1107 if (Context && Context->magic == M_NNTP &&
1108 !m_strcmp(data->group, ((NNTP_DATA *) Context->data)->group)) {
1109 unsigned int i, unread = 0;
1111 for (i = 0; i < Context->msgcount; i++)
1112 if (!Context->hdrs[i]->read && !Context->hdrs[i]->deleted)
1117 m_strcpy(dst, dstlen, data->group);