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.
12 #include <lib-lib/lib-lib.h>
16 #include <lib-mime/mime.h>
17 #include <lib-ui/curses.h>
18 #include <lib-mx/mx.h>
24 void nntp_add_to_list (NNTP_SERVER * s, NNTP_DATA * d)
31 l = p_new(string_list_t, 1);
40 static int nntp_parse_newsrc_line (NNTP_SERVER * news, char *line)
43 char group[LONG_STRING];
45 char *p = line, *b, *h;
54 while (*p && (*p != ':' && *p != '!'))
58 len = MIN(p + 1 - line, ssizeof(group));
59 m_strcpy(group, len, line);
60 if ((data = (NNTP_DATA *) hash_find (news->newsgroups, group)) == NULL) {
61 data = xmalloc(sizeof(NNTP_DATA) + m_strlen(group) + 1);
62 data->group = (char *) data + sizeof (NNTP_DATA);
63 strcpy (data->group, group);
66 if (news->newsgroups->nelem < news->newsgroups->curnelem * 2)
68 hash_resize (news->newsgroups, news->newsgroups->nelem * 2);
69 hash_insert (news->newsgroups, data->group, data, 0);
70 nntp_add_to_list (news, data);
73 p_delete(&data->entries);
76 data->entries = p_new(NEWSRC_ENTRY, x * 2);
88 while (*p && *p != ',' && *p != '\n')
94 if ((h = strchr (b, '-'))) {
97 data->entries[x].first = atoi (b);
98 data->entries[x].last = atoi (h);
101 data->entries[x].first = atoi (b);
102 data->entries[x].last = data->entries[x].first;
105 if (data->entries[x].last != 0)
108 if (x && !data->lastMessage)
109 data->lastMessage = data->entries[x - 1].last;
111 mutt_newsgroup_stat (data);
116 static int slurp_newsrc (NNTP_SERVER * news)
122 news->stat = stat (news->newsrc, &sb);
123 news->size = sb.st_size;
124 news->mtime = sb.st_mtime;
126 if ((fp = safe_fopen (news->newsrc, "r")) == NULL)
128 /* hmm, should we use dotlock? */
129 if (mx_lock_file (news->newsrc, fileno (fp), 0, 0, 1)) {
134 buf = p_new(char, sb.st_size + 1);
135 while (fgets (buf, sb.st_size + 1, fp))
136 nntp_parse_newsrc_line (news, buf);
139 mx_unlock_file (news->newsrc, fileno (fp), 0);
144 void nntp_cache_expand (char *dst, const char *src)
146 snprintf (dst, _POSIX_PATH_MAX, "%s/%s", NewsCacheDir, src);
147 mutt_expand_path (dst, _POSIX_PATH_MAX);
150 /* Loads $news_cache_dir/.index into memory, loads newsserver data
151 * and newsgroup cache names */
152 static int nntp_parse_cacheindex (NNTP_SERVER * news)
155 char buf[HUGE_STRING], *cp;
156 char dir[_POSIX_PATH_MAX], file[_POSIX_PATH_MAX];
161 /* check is server name defined or not */
162 if (!news || !news->conn || !news->conn->account.host)
164 unset_option (OPTNEWSCACHE);
165 if (!NewsCacheDir || !*NewsCacheDir)
168 m_strcpy(dir, sizeof(dir), NewsCacheDir);
169 mutt_expand_path (dir, sizeof (dir));
171 if (lstat (dir, &st) || (st.st_mode & S_IFDIR) == 0) {
172 snprintf (buf, sizeof (buf), _("Directory %s not exist. Create it?"),
174 if (mutt_yesorno (buf, M_YES) != M_YES
175 || mkdir (dir, (S_IRWXU + S_IRWXG + S_IRWXO))) {
176 mutt_error _("Cache directory not created!");
183 set_option (OPTNEWSCACHE);
185 p_delete(&news->cache);
186 snprintf (buf, sizeof (buf), "%s/.index", dir);
187 if (!(idx = safe_fopen (buf, "a+")))
190 while (fgets (buf, sizeof (buf), idx)) {
191 buf[m_strlen(buf) - 1] = 0; /* strip ending '\n' */
192 if (!m_strncmp(buf, "#: ", 3) &&
193 !m_strcasecmp(buf + 3, news->conn->account.host))
196 while (fgets (buf, sizeof (buf), idx)) {
198 while (*cp && *cp != ' ')
203 if (!m_strcmp(buf, "#:"))
205 sscanf (cp + 1, "%s %d %d", file, &l, &m);
206 if (!m_strcmp(buf, "ALL")) {
207 news->cache = m_strdup(file);
208 news->newgroups_time = m;
210 else if (news->newsgroups) {
211 if ((data = (NNTP_DATA *) hash_find (news->newsgroups, buf)) == NULL) {
212 data = xmalloc(sizeof(NNTP_DATA) + m_strlen(buf) + 1);
213 data->group = (char *) data + sizeof (NNTP_DATA);
214 strcpy (data->group, buf);
217 if (news->newsgroups->nelem < news->newsgroups->curnelem * 2)
219 hash_resize (news->newsgroups, news->newsgroups->nelem * 2);
220 hash_insert (news->newsgroups, data->group, data, 0);
221 nntp_add_to_list (news, data);
223 data->cache = m_strdup(file);
225 if (!data->firstMessage || data->lastMessage < m)
227 if (!data->firstMessage)
228 data->firstMessage = l;
229 if (data->lastMessage < m)
230 data->lastMessage = m;
231 data->lastCached = m;
232 if (t || !data->unread)
233 mutt_newsgroup_stat (data);
240 const char *nntp_format_str (char *dest, ssize_t destlen, char op,
241 const char *src, const char *fmt,
242 const char *ifstring, const char *elsestring,
243 unsigned long data, format_flag flags)
245 char fn[SHORT_STRING], tmp[SHORT_STRING];
249 m_strcpy(fn, sizeof (fn), NewsServer);
251 snprintf (tmp, sizeof (tmp), "%%%ss", fmt);
252 snprintf (dest, destlen, tmp, fn);
258 /* nntp_parse_url: given an NNPT URL, return host, port,
259 * username, password and newsgroup will recognise. */
260 int nntp_parse_url (const char *server, ACCOUNT * act,
261 char *group, ssize_t group_len)
269 act->port = NNTP_PORT;
270 act->type = M_ACCT_TYPE_NNTP;
272 c = m_strdup(server);
273 url_parse_ciss (&url, c);
275 if (url.scheme == U_NNTP || url.scheme == U_NNTPS) {
276 if (url.scheme == U_NNTPS) {
277 act->flags |= M_ACCT_SSL;
278 act->port = NNTP_SSL_PORT;
283 m_strcpy(group, group_len, url.path);
285 ret = mutt_account_fromurl (act, &url);
292 void nntp_expand_path (char *line, ssize_t len, ACCOUNT * act)
296 url.path = m_strdup(line);
297 mutt_account_tourl (act, &url);
298 url_ciss_tostring (&url, line, len, 0);
303 * Automatically loads a newsrc into memory, if necessary.
304 * Checks the size/mtime of a newsrc file, if it doesn't match, load
305 * again. Hmm, if a system has broken mtimes, this might mean the file
306 * is reloaded every time, which we'd have to fix.
308 * a newsrc file is a line per newsgroup, with the newsgroup, then a
309 * ':' denoting subscribed or '!' denoting unsubscribed, then a
310 * comma separated list of article numbers and ranges.
312 NNTP_SERVER *mutt_select_newsserver (char *server)
314 char file[_POSIX_PATH_MAX];
323 if (!server || !*server) {
324 mutt_error _("No newsserver defined!");
329 buf = p = p_new(char, m_strlen(server) + 10);
330 if (url_check_scheme (server) == U_UNKNOWN) {
331 strcpy (buf, "nntp://");
332 p = strchr (buf, '\0');
336 if ((nntp_parse_url (buf, &act, file, sizeof (file))) < 0 || *file) {
338 mutt_error (_("%s is an invalid newsserver specification!"), server);
343 conn = mutt_conn_find (NULL, &act);
347 mutt_FormatString (file, sizeof (file), NONULL (NewsRc), nntp_format_str, 0,
349 mutt_expand_path (file, sizeof (file));
351 serv = (NNTP_SERVER *) conn->data;
355 /* externally modified? */
356 if (serv->stat != stat (file, &sb) || (!serv->stat &&
357 (serv->size != sb.st_size
358 || serv->mtime != sb.st_mtime))) {
359 for (list = serv->list; list; list = list->next) {
360 NNTP_DATA *data = (NNTP_DATA *) list->data;
363 data->subscribed = 0;
369 nntp_clear_cacheindex (serv);
372 if (serv->status == NNTP_BYE)
373 serv->status = NNTP_NONE;
374 nntp_check_newgroups (serv, 0);
379 serv = p_new(NNTP_SERVER, 1);
381 serv->newsrc = m_strdup(file);
382 serv->newsgroups = hash_create (1009);
383 slurp_newsrc (serv); /* load .newsrc */
384 nntp_parse_cacheindex (serv); /* load .index */
385 if (option (OPTNEWSCACHE) && serv->cache && nntp_get_cache_all (serv) >= 0)
386 nntp_check_newgroups (serv, 1);
387 else if (nntp_get_active (serv) < 0) {
388 hash_destroy (&serv->newsgroups, nntp_delete_data);
389 for (list = serv->list; list; list = list->next)
391 string_list_wipe(&serv->list);
392 p_delete(&serv->newsrc);
393 p_delete(&serv->cache);
397 nntp_clear_cacheindex (serv);
398 conn->data = (void *) serv;
404 * full status flags are not supported by nntp, but we can fake some
405 * of them. This is how:
406 * Read = a read message number is in the .newsrc
407 * New = a message is new since we last read this newsgroup
408 * Old = anything else
409 * So, Read is marked as such in the newsrc, old is anything that is
410 * "skipped" in the newsrc, and new is anything not in the newsrc nor
411 * in the cache. By skipped, I mean before the last unread message
413 void nntp_get_status (CONTEXT * ctx, HEADER * h, char *group, int article)
415 NNTP_DATA *data = (NNTP_DATA *) ctx->data;
419 data = (NNTP_DATA *) hash_find (data->nserv->newsgroups, group);
425 for (x = 0; x < data->num; x++) {
426 if ((article >= data->entries[x].first) &&
427 (article <= data->entries[x].last)) {
428 /* we cannot use mutt_set_flag() because mx_update_context()
434 /* If article was not cached yet, it is new! :) */
435 if (!data->cache || article > data->lastCached)
437 /* Old articles are articles which aren't read but an article after them
439 if (option (OPTMARKOLD))
443 void mutt_newsgroup_stat (NNTP_DATA * data)
446 unsigned int first, last;
449 if (data->lastMessage == 0 || data->firstMessage > data->lastMessage)
452 data->unread = data->lastMessage - data->firstMessage + 1;
453 for (i = 0; i < data->num; i++) {
454 first = data->entries[i].first;
455 if (first < data->firstMessage)
456 first = data->firstMessage;
457 last = data->entries[i].last;
458 if (last > data->lastMessage)
459 last = data->lastMessage;
461 data->unread -= last - first + 1;
465 static int puti (char *line, int num)
470 *p++ = '0' + num % 10;
474 *line++ = *--p, num++;
479 static void nntp_create_newsrc_line (NNTP_DATA * data, char **buf,
480 char **pline, ssize_t * buflen)
483 ssize_t len = *buflen - (*pline - *buf);
486 if (len < LONG_STRING * 10) {
490 p_realloc(buf, *buflen);
491 line = *buf + (*pline - line);
493 strcpy (line, data->group);
494 len -= m_strlen(line) + 1;
495 line += m_strlen(line);
496 *line++ = data->subscribed ? ':' : '!';
500 for (x = 0; x < data->num; x++) {
501 if (len < LONG_STRING) {
506 p_realloc(buf, *buflen);
507 line = *buf + (*pline - line);
514 i = puti (line, data->entries[x].first);
517 if (data->entries[x].first != data->entries[x].last) {
520 i = puti (line, data->entries[x].last);
530 void newsrc_gen_entries (CONTEXT * ctx)
532 NNTP_DATA *data = (NNTP_DATA *) ctx->data;
534 unsigned int last = 0, first = 1;
535 int save_sort = SORT_ORDER;
537 if (Sort != SORT_ORDER) {
540 mutt_sort_headers (ctx, 0);
544 data->entries = p_new(NEWSRC_ENTRY, 5);
549 * Set up to fake initial sequence from 1 to the article before the
550 * first article in our list
555 for (x = 0; x < ctx->msgcount; x++) {
556 if (series) { /* search for first unread */
558 * We don't actually check sequential order, since we mark
559 * "missing" entries as read/deleted
561 last = ctx->hdrs[x]->article_num;
562 if (last >= data->firstMessage && !ctx->hdrs[x]->deleted &&
563 !ctx->hdrs[x]->read) {
564 if (data->num >= data->max) {
565 data->max = data->max * 2;
566 p_realloc(&data->entries, data->max);
568 data->entries[data->num].first = first;
569 data->entries[data->num].last = last - 1;
574 else { /* search for first read */
576 if (ctx->hdrs[x]->deleted || ctx->hdrs[x]->read) {
580 last = ctx->hdrs[x]->article_num;
583 if (series && first <= data->lastLoaded) {
584 if (data->num >= data->max) {
585 data->max = data->max * 2;
586 p_realloc(&data->entries, data->max);
588 data->entries[data->num].first = first;
589 data->entries[data->num].last = data->lastLoaded;
593 if (save_sort != Sort) {
595 mutt_sort_headers (ctx, 0);
599 static int mutt_update_list_file (char *filename, char *section,
600 const char *key, char *line) {
603 char buf[HUGE_STRING];
604 char tmpf[_POSIX_PATH_MAX], lnk[_POSIX_PATH_MAX];
606 int ext = 0, done = 0, r = 0, l = 0;
608 /* if file not exist, create it */
609 if ((ifp = safe_fopen (filename, "a")))
611 if (!(ifp = safe_fopen (filename, "r"))) {
612 mutt_error (_("Unable to open %s for reading"), filename);
615 if (mx_lock_file (filename, fileno (ifp), 0, 0, 1)) {
617 mutt_error (_("Unable to lock %s"), filename);
621 /* use m_tempfile() to get a tempfile in the same
622 * directory as filename is so that we can follow symlinks
623 * via rename(2); as dirname(2) may modify its argument,
624 * temporarily use buf as copy of it
626 m_strcpy(buf, sizeof(buf), filename);
627 ofp = m_tempfile(tmpf, sizeof(tmpf), dirname(buf), filename);
630 mutt_error (_("Unable to open %s for writing"), tmpf);
635 while (r != EOF && !done && fgets (buf, sizeof (buf), ifp)) {
636 r = fputs (buf, ofp);
638 while (*c && *c != '\n') c++;
639 c[0] = 0; /* strip EOL */
640 if (!strncmp (buf, "#: ", 3) && !m_strcasecmp(buf+3, section))
643 if (r != EOF && !done) {
644 snprintf (buf, sizeof(buf), "#: %s\n", section);
645 r = fputs (buf, ofp);
650 while (r != EOF && fgets (buf, sizeof (buf), ifp)) {
653 while (*c && (*c != '\r') && (*c != '\n')) c++;
655 if (*c != '\\') ext = 0;
656 } else if ((section && !strncmp (buf, "#: ", 3))) {
661 r = fputs (buf, ofp);
664 } else if (key && !strncmp (buf, key, strlen(key)) &&
665 (!*key || buf[strlen(key)] == ' ')) {
668 while (*c && (*c != '\r') && (*c != '\n')) c++;
670 if (*c == '\\') ext = 1;
672 r = fputs (line, ofp);
674 r = fputc ('\n', ofp);
678 r = fputs (buf, ofp);
682 while (r != EOF && fgets (buf, sizeof (buf), ifp))
683 r = fputs (buf, ofp);
685 /* If there wasn't a line to replace, put it on the end of the file */
686 if (r != EOF && !done && line) {
688 r = fputc ('\n', ofp);
690 mx_unlock_file (filename, fileno (ifp), 0);
695 mutt_error (_("Can't write %s"), tmpf);
699 if ((l = readlink (filename, lnk, sizeof(lnk)-1)) > 0)
701 if (rename (tmpf, l > 0 ? lnk : filename) < 0) {
703 mutt_error (_("Can't rename %s to %s"), tmpf, l > 0 ? lnk : filename);
709 int mutt_newsrc_update (NNTP_SERVER * news)
719 llen = len = 10 * LONG_STRING;
720 line = buf = p_new(char, len);
721 /* we will generate full newsrc here */
722 for (tmp = news->list; tmp; tmp = tmp->next) {
723 data = (NNTP_DATA *) tmp->data;
724 if (!data || !data->rc)
726 nntp_create_newsrc_line (data, &buf, &line, &llen);
727 line += m_strlen(line);
729 /* newrc being fully rewritten */
731 (r = mutt_update_list_file(news->newsrc, NULL, "", buf)) == 0) {
734 stat (news->newsrc, &st);
735 news->size = st.st_size;
736 news->mtime = st.st_mtime;
742 static FILE *mutt_mkname (char *s)
744 char buf[_POSIX_PATH_MAX], *pc;
748 nntp_cache_expand (buf, s);
749 if ((fp = safe_fopen (buf, "w")))
752 nntp_cache_expand (buf, "cache-XXXXXX");
753 pc = buf + m_strlen(buf) - 12; /* positioning to "cache-XXXXXX" */
754 if ((fd = mkstemp (buf)) == -1)
756 strcpy (s, pc); /* generated name */
757 return fdopen (fd, "w");
760 /* Updates info into .index file: ALL or about selected newsgroup */
761 static int nntp_update_cacheindex (NNTP_SERVER * serv, NNTP_DATA * data)
763 char buf[LONG_STRING];
764 char file[_POSIX_PATH_MAX];
765 const char *key = "ALL";
767 if (!serv || !serv->conn || !serv->conn->account.host)
770 if (data && data->group) {
772 snprintf (buf, sizeof (buf), "%s %s %d %d", key, data->cache,
773 data->firstMessage, data->lastLoaded);
776 m_strcpy(file, sizeof(file), serv->cache);
777 snprintf (buf, sizeof (buf), "ALL %s 0 %d", file,
778 (int) serv->newgroups_time);
780 nntp_cache_expand (file, ".index");
781 return mutt_update_list_file (file, serv->conn->account.host, key, buf);
784 /* Remove cache files of unsubscribed newsgroups */
785 void nntp_clear_cacheindex (NNTP_SERVER * news)
790 if (option (OPTSAVEUNSUB) || !news)
793 for (tmp = news->list; tmp; tmp = tmp->next) {
794 data = (NNTP_DATA *) tmp->data;
795 if (!data || data->subscribed || !data->cache)
797 nntp_delete_cache (data);
802 int nntp_save_cache_index (NNTP_SERVER * news)
804 char buf[HUGE_STRING];
805 char file[_POSIX_PATH_MAX];
810 if (!news || !news->newsgroups)
812 if (!option (OPTNEWSCACHE))
816 nntp_cache_expand (file, news->cache);
818 f = safe_fopen (file, "w");
821 m_strcpy(buf, sizeof(buf), news->conn->account.host);
822 f = mutt_mkname (buf);
823 news->cache = m_strdup(buf);
824 nntp_cache_expand (file, buf);
829 for (l = news->list; l; l = l->next) {
830 if ((d = (NNTP_DATA *) l->data) && !d->deleted) {
832 snprintf (buf, sizeof (buf), "%s %d %d %c %s\n", d->group,
833 d->lastMessage, d->firstMessage, d->allowed ? 'y' : 'n',
836 snprintf (buf, sizeof (buf), "%s %d %d %c\n", d->group,
837 d->lastMessage, d->firstMessage, d->allowed ? 'y' : 'n');
838 if (fputs (buf, f) == EOF) {
847 if (nntp_update_cacheindex (news, NULL)) {
854 int nntp_save_cache_group (CONTEXT * ctx)
856 char buf[HUGE_STRING], addr[STRING];
857 char file[_POSIX_PATH_MAX];
861 int i = 0, save = SORT_ORDER;
864 if (!option (OPTNEWSCACHE))
866 if (!ctx || !ctx->data || ctx->magic != M_NNTP)
869 if (((NNTP_DATA *) ctx->data)->cache) {
870 nntp_cache_expand (file, ((NNTP_DATA *) ctx->data)->cache);
872 f = safe_fopen (file, "w");
875 snprintf (buf, sizeof (buf), "%s-%s",
876 ((NNTP_DATA *) ctx->data)->nserv->conn->account.host,
877 ((NNTP_DATA *) ctx->data)->group);
878 f = mutt_mkname (buf);
879 ((NNTP_DATA *) ctx->data)->cache = m_strdup(buf);
880 nntp_cache_expand (file, buf);
885 if (Sort != SORT_ORDER) {
888 mutt_sort_headers (ctx, 0);
891 /* Save only $nntp_context messages... */
892 ((NNTP_DATA *) ctx->data)->lastCached = 0;
893 if (NntpContext && ctx->msgcount > NntpContext)
894 i = ctx->msgcount - NntpContext;
895 for (; i < ctx->msgcount; i++) {
896 if (!ctx->hdrs[i]->deleted && ctx->hdrs[i]->article_num != prev) {
899 rfc822_write_address (addr, sizeof (addr), h->env->from, 0);
900 tm = gmtime (&h->date_sent);
901 snprintf (buf, sizeof (buf),
902 "%d\t%s\t%s\t%d %s %d %02d:%02d:%02d GMT\t%s\t",
903 h->article_num, h->env->subject, addr, tm->tm_mday,
904 Months[tm->tm_mon], tm->tm_year + 1900, tm->tm_hour,
905 tm->tm_min, tm->tm_sec, h->env->message_id);
907 if (h->env->references)
908 mutt_write_references (h->env->references, f);
909 snprintf (buf, sizeof (buf), "\t%zd\t%d\tXref: %s\n",
910 h->content->length, h->lines, NONULL (h->env->xref));
911 if (fputs (buf, f) == EOF) {
917 prev = ctx->hdrs[i]->article_num;
922 mutt_sort_headers (ctx, 0);
926 if (nntp_update_cacheindex (((NNTP_DATA *) ctx->data)->nserv,
927 (NNTP_DATA *) ctx->data)) {
931 ((NNTP_DATA *) ctx->data)->lastCached =
932 ((NNTP_DATA *) ctx->data)->lastLoaded;
936 void nntp_delete_cache (NNTP_DATA * data)
938 char buf[_POSIX_PATH_MAX];
940 if (!option (OPTNEWSCACHE) || !data || !data->cache || !data->nserv)
943 nntp_cache_expand (buf, data->cache);
945 p_delete(&data->cache);
946 data->lastCached = 0;
947 nntp_cache_expand (buf, ".index");
948 mutt_update_list_file (buf, data->nserv->conn->account.host, data->group,
952 NNTP_DATA *mutt_newsgroup_subscribe (NNTP_SERVER * news, char *group)
956 if (!news || !news->newsgroups || !group || !*group)
958 if (!(data = (NNTP_DATA *) hash_find (news->newsgroups, group))) {
959 data = xmalloc(sizeof(NNTP_DATA) + m_strlen(group) + 1);
960 data->group = (char *) data + sizeof (NNTP_DATA);
961 strcpy (data->group, group);
964 if (news->newsgroups->nelem < news->newsgroups->curnelem * 2)
966 hash_resize (news->newsgroups, news->newsgroups->nelem * 2);
967 hash_insert (news->newsgroups, data->group, data, 0);
968 nntp_add_to_list (news, data);
970 if (!data->subscribed) {
971 data->subscribed = 1;
977 NNTP_DATA *mutt_newsgroup_unsubscribe (NNTP_SERVER * news, char *group)
981 if (!news || !news->newsgroups || !group || !*group ||
982 !(data = (NNTP_DATA *) hash_find (news->newsgroups, group)))
984 if (data->subscribed) {
985 data->subscribed = 0;
986 if (!option (OPTSAVEUNSUB))
992 NNTP_DATA *mutt_newsgroup_catchup (NNTP_SERVER * news, char *group)
996 if (!news || !news->newsgroups || !group || !*group ||
997 !(data = (NNTP_DATA *) hash_find (news->newsgroups, group)))
1000 data->entries = p_new(NEWSRC_ENTRY, 5);
1004 data->entries[0].first = 1;
1006 data->entries[0].last = data->lastMessage;
1007 if (Context && Context->data == data) {
1010 for (x = 0; x < Context->msgcount; x++)
1011 mutt_set_flag (Context, Context->hdrs[x], M_READ, 1);
1016 NNTP_DATA *mutt_newsgroup_uncatchup (NNTP_SERVER * news, char *group)
1020 if (!news || !news->newsgroups || !group || !*group ||
1021 !(data = (NNTP_DATA *) hash_find (news->newsgroups, group)))
1024 data->entries = p_new(NEWSRC_ENTRY, 5);
1028 data->entries[0].first = 1;
1029 data->entries[0].last = data->firstMessage - 1;
1030 if (Context && Context->data == data) {
1033 data->unread = Context->msgcount;
1034 for (x = 0; x < Context->msgcount; x++)
1035 mutt_set_flag (Context, Context->hdrs[x], M_READ, 0);
1038 data->unread = data->lastMessage - data->entries[0].last;
1042 /* this routine gives the first newsgroup with new messages */
1043 void nntp_buffy (char* dst, ssize_t dstlen) {
1044 string_list_t *list;
1047 /* forward to current group */
1048 for (list = CurrentNewsSrv->list; list; list = list->next) {
1049 NNTP_DATA *data = (NNTP_DATA *) list->data;
1050 if (data && data->subscribed && data->unread &&
1051 Context && Context->magic == M_NNTP &&
1052 m_strcmp(data->group, ((NNTP_DATA *) Context->data)->group) == 0) {
1063 list = CurrentNewsSrv->list;
1065 for (; list; list = list->next) {
1066 NNTP_DATA *data = (NNTP_DATA *) list->data;
1068 if (data && data->subscribed && data->unread) {
1069 if (Context && Context->magic == M_NNTP &&
1070 !m_strcmp(data->group, ((NNTP_DATA *) Context->data)->group)) {
1071 unsigned int i, unread = 0;
1073 for (i = 0; i < Context->msgcount; i++)
1074 if (!Context->hdrs[i]->read && !Context->hdrs[i]->deleted)
1079 m_strcpy(dst, dstlen, data->group);