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>
19 #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 strfcpy (group, line, len);
78 if ((data = (NNTP_DATA *) hash_find (news->newsgroups, group)) == NULL) {
79 data = xmalloc(sizeof(NNTP_DATA) + str_len(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 strfcpy (dir, NewsCacheDir, sizeof (dir));
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[str_len (buf) - 1] = 0; /* strip ending '\n' */
211 if (!str_ncmp (buf, "#: ", 3) &&
212 !str_casecmp (buf + 3, news->conn->account.host))
215 while (fgets (buf, sizeof (buf), index)) {
217 while (*cp && *cp != ' ')
222 if (!str_cmp (buf, "#:"))
224 sscanf (cp + 1, "%s %d %d", file, &l, &m);
225 if (!str_cmp (buf, "ALL")) {
226 news->cache = str_dup (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) + str_len(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 = str_dup (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 strncpy (fn, NewsServer, sizeof (fn) - 1);
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 = str_dup (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 strfcpy (group, url.path, group_len);
304 ret = mutt_account_fromurl (acct, &url);
311 void nntp_expand_path (char *line, size_t len, ACCOUNT * acct)
315 url.path = str_dup (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];
340 memset (&acct, 0, sizeof (ACCOUNT));
342 if (!server || !*server) {
343 mutt_error _("No newsserver defined!");
348 buf = p = p_new(char, str_len (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 = str_dup (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 mem_realloc (buf, *buflen);
514 line = *buf + (*pline - line);
516 strcpy (line, data->group);
517 len -= str_len (line) + 1;
518 line += str_len (line);
519 *line++ = data->subscribed ? ':' : '!';
523 for (x = 0; x < data->num; x++) {
524 if (len < LONG_STRING) {
529 mem_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 mem_realloc (&data->entries, data->max * sizeof (NEWSRC_ENTRY));
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 mem_realloc (&data->entries, data->max * sizeof (NEWSRC_ENTRY));
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 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 strncpy (buf, filename, sizeof (buf));
660 strncpy (tmpfile, basename (filename), sizeof (tmpfile));
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) && !str_casecmp (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 += str_len (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 + str_len (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], *key = "ALL";
801 char file[_POSIX_PATH_MAX];
803 if (!serv || !serv->conn || !serv->conn->account.host)
806 if (data && data->group) {
808 snprintf (buf, sizeof (buf), "%s %s %d %d", key, data->cache,
809 data->firstMessage, data->lastLoaded);
812 strfcpy (file, serv->cache, sizeof (file));
813 snprintf (buf, sizeof (buf), "ALL %s 0 %d", file,
814 (int) serv->newgroups_time);
816 nntp_cache_expand (file, ".index");
817 return mutt_update_list_file (file, serv->conn->account.host, key, buf);
820 /* Remove cache files of unsubscribed newsgroups */
821 void nntp_clear_cacheindex (NNTP_SERVER * news)
826 if (option (OPTSAVEUNSUB) || !news)
829 for (tmp = news->list; tmp; tmp = tmp->next) {
830 data = (NNTP_DATA *) tmp->data;
831 if (!data || data->subscribed || !data->cache)
833 nntp_delete_cache (data);
834 debug_print (2, ("Removed from .index: %s\n", data->group));
839 int nntp_save_cache_index (NNTP_SERVER * news)
841 char buf[HUGE_STRING];
842 char file[_POSIX_PATH_MAX];
847 if (!news || !news->newsgroups)
849 if (!option (OPTNEWSCACHE))
853 nntp_cache_expand (file, news->cache);
855 f = safe_fopen (file, "w");
858 strfcpy (buf, news->conn->account.host, sizeof (buf));
859 f = mutt_mkname (buf);
860 news->cache = str_dup (buf);
861 nntp_cache_expand (file, buf);
866 for (l = news->list; l; l = l->next) {
867 if ((d = (NNTP_DATA *) l->data) && !d->deleted) {
869 snprintf (buf, sizeof (buf), "%s %d %d %c %s\n", d->group,
870 d->lastMessage, d->firstMessage, d->allowed ? 'y' : 'n',
873 snprintf (buf, sizeof (buf), "%s %d %d %c\n", d->group,
874 d->lastMessage, d->firstMessage, d->allowed ? 'y' : 'n');
875 if (fputs (buf, f) == EOF) {
884 if (nntp_update_cacheindex (news, NULL)) {
891 int nntp_save_cache_group (CONTEXT * ctx)
893 char buf[HUGE_STRING], addr[STRING];
894 char file[_POSIX_PATH_MAX];
898 int i = 0, save = SORT_ORDER;
901 if (!option (OPTNEWSCACHE))
903 if (!ctx || !ctx->data || ctx->magic != M_NNTP)
906 if (((NNTP_DATA *) ctx->data)->cache) {
907 nntp_cache_expand (file, ((NNTP_DATA *) ctx->data)->cache);
909 f = safe_fopen (file, "w");
912 snprintf (buf, sizeof (buf), "%s-%s",
913 ((NNTP_DATA *) ctx->data)->nserv->conn->account.host,
914 ((NNTP_DATA *) ctx->data)->group);
915 f = mutt_mkname (buf);
916 ((NNTP_DATA *) ctx->data)->cache = str_dup (buf);
917 nntp_cache_expand (file, buf);
922 if (Sort != SORT_ORDER) {
925 mutt_sort_headers (ctx, 0);
928 /* Save only $nntp_context messages... */
929 ((NNTP_DATA *) ctx->data)->lastCached = 0;
930 if (NntpContext && ctx->msgcount > NntpContext)
931 i = ctx->msgcount - NntpContext;
932 for (; i < ctx->msgcount; i++) {
933 if (!ctx->hdrs[i]->deleted && ctx->hdrs[i]->article_num != prev) {
936 rfc822_write_address (addr, sizeof (addr), h->env->from, 0);
937 tm = gmtime (&h->date_sent);
938 snprintf (buf, sizeof (buf),
939 "%d\t%s\t%s\t%d %s %d %02d:%02d:%02d GMT\t%s\t",
940 h->article_num, h->env->subject, addr, tm->tm_mday,
941 Months[tm->tm_mon], tm->tm_year + 1900, tm->tm_hour,
942 tm->tm_min, tm->tm_sec, h->env->message_id);
944 if (h->env->references)
945 mutt_write_references (h->env->references, f);
946 snprintf (buf, sizeof (buf), "\t%zd\t%d\tXref: %s\n",
947 h->content->length, h->lines, NONULL (h->env->xref));
948 if (fputs (buf, f) == EOF) {
954 prev = ctx->hdrs[i]->article_num;
959 mutt_sort_headers (ctx, 0);
963 if (nntp_update_cacheindex (((NNTP_DATA *) ctx->data)->nserv,
964 (NNTP_DATA *) ctx->data)) {
968 ((NNTP_DATA *) ctx->data)->lastCached =
969 ((NNTP_DATA *) ctx->data)->lastLoaded;
973 void nntp_delete_cache (NNTP_DATA * data)
975 char buf[_POSIX_PATH_MAX];
977 if (!option (OPTNEWSCACHE) || !data || !data->cache || !data->nserv)
980 nntp_cache_expand (buf, data->cache);
982 p_delete(&data->cache);
983 data->lastCached = 0;
984 nntp_cache_expand (buf, ".index");
985 mutt_update_list_file (buf, data->nserv->conn->account.host, data->group,
989 NNTP_DATA *mutt_newsgroup_subscribe (NNTP_SERVER * news, char *group)
993 if (!news || !news->newsgroups || !group || !*group)
995 if (!(data = (NNTP_DATA *) hash_find (news->newsgroups, group))) {
996 data = xmalloc(sizeof(NNTP_DATA) + str_len(group) + 1);
997 data->group = (char *) data + sizeof (NNTP_DATA);
998 strcpy (data->group, group);
1001 if (news->newsgroups->nelem < news->newsgroups->curnelem * 2)
1003 hash_resize (news->newsgroups, news->newsgroups->nelem * 2);
1004 hash_insert (news->newsgroups, data->group, data, 0);
1005 nntp_add_to_list (news, data);
1007 if (!data->subscribed) {
1008 data->subscribed = 1;
1014 NNTP_DATA *mutt_newsgroup_unsubscribe (NNTP_SERVER * news, char *group)
1018 if (!news || !news->newsgroups || !group || !*group ||
1019 !(data = (NNTP_DATA *) hash_find (news->newsgroups, group)))
1021 if (data->subscribed) {
1022 data->subscribed = 0;
1023 if (!option (OPTSAVEUNSUB))
1029 NNTP_DATA *mutt_newsgroup_catchup (NNTP_SERVER * news, char *group)
1033 if (!news || !news->newsgroups || !group || !*group ||
1034 !(data = (NNTP_DATA *) hash_find (news->newsgroups, group)))
1037 data->entries = p_new(NEWSRC_ENTRY, 5);
1041 data->entries[0].first = 1;
1043 data->entries[0].last = data->lastMessage;
1044 if (Context && Context->data == data) {
1047 for (x = 0; x < Context->msgcount; x++)
1048 mutt_set_flag (Context, Context->hdrs[x], M_READ, 1);
1053 NNTP_DATA *mutt_newsgroup_uncatchup (NNTP_SERVER * news, char *group)
1057 if (!news || !news->newsgroups || !group || !*group ||
1058 !(data = (NNTP_DATA *) hash_find (news->newsgroups, group)))
1061 data->entries = p_new(NEWSRC_ENTRY, 5);
1065 data->entries[0].first = 1;
1066 data->entries[0].last = data->firstMessage - 1;
1067 if (Context && Context->data == data) {
1070 data->unread = Context->msgcount;
1071 for (x = 0; x < Context->msgcount; x++)
1072 mutt_set_flag (Context, Context->hdrs[x], M_READ, 0);
1075 data->unread = data->lastMessage - data->entries[0].last;
1079 /* this routine gives the first newsgroup with new messages */
1080 void nntp_buffy (char* dst, size_t dstlen) {
1084 /* forward to current group */
1085 for (list = CurrentNewsSrv->list; list; list = list->next) {
1086 NNTP_DATA *data = (NNTP_DATA *) list->data;
1087 if (data && data->subscribed && data->unread &&
1088 Context && Context->magic == M_NNTP &&
1089 str_cmp (data->group, ((NNTP_DATA *) Context->data)->group) == 0) {
1100 list = CurrentNewsSrv->list;
1102 for (; list; list = list->next) {
1103 NNTP_DATA *data = (NNTP_DATA *) list->data;
1105 if (data && data->subscribed && data->unread) {
1106 if (Context && Context->magic == M_NNTP &&
1107 !str_cmp (data->group, ((NNTP_DATA *) Context->data)->group)) {
1108 unsigned int i, unread = 0;
1110 for (i = 0; i < Context->msgcount; i++)
1111 if (!Context->hdrs[i]->read && !Context->hdrs[i]->deleted)
1116 strncpy (dst, data->group, dstlen);