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)
67 hash_resize (news->newsgroups, news->newsgroups->nelem * 2);
68 hash_insert (news->newsgroups, data->group, data);
69 nntp_add_to_list (news, data);
72 p_delete(&data->entries);
75 data->entries = p_new(NEWSRC_ENTRY, x * 2);
87 while (*p && *p != ',' && *p != '\n')
93 if ((h = strchr (b, '-'))) {
96 data->entries[x].first = atoi (b);
97 data->entries[x].last = atoi (h);
100 data->entries[x].first = atoi (b);
101 data->entries[x].last = data->entries[x].first;
104 if (data->entries[x].last != 0)
107 if (x && !data->lastMessage)
108 data->lastMessage = data->entries[x - 1].last;
110 mutt_newsgroup_stat (data);
115 static int slurp_newsrc (NNTP_SERVER * news)
121 news->stat = stat (news->newsrc, &sb);
122 news->size = sb.st_size;
123 news->mtime = sb.st_mtime;
125 if ((fp = safe_fopen (news->newsrc, "r")) == NULL)
127 /* hmm, should we use dotlock? */
128 if (mx_lock_file (news->newsrc, fileno (fp), 0, 0, 1)) {
133 buf = p_new(char, sb.st_size + 1);
134 while (fgets (buf, sb.st_size + 1, fp))
135 nntp_parse_newsrc_line (news, buf);
138 mx_unlock_file (news->newsrc, fileno (fp), 0);
143 void nntp_cache_expand (char *dst, const char *src)
145 snprintf (dst, _POSIX_PATH_MAX, "%s/%s", NewsCacheDir, src);
146 mutt_expand_path (dst, _POSIX_PATH_MAX);
149 /* Loads $news_cache_dir/.index into memory, loads newsserver data
150 * and newsgroup cache names */
151 static int nntp_parse_cacheindex (NNTP_SERVER * news)
154 char buf[HUGE_STRING], *cp;
155 char dir[_POSIX_PATH_MAX], file[_POSIX_PATH_MAX];
160 /* check is server name defined or not */
161 if (!news || !news->conn || !news->conn->account.host)
163 unset_option (OPTNEWSCACHE);
164 if (!NewsCacheDir || !*NewsCacheDir)
167 m_strcpy(dir, sizeof(dir), NewsCacheDir);
168 mutt_expand_path (dir, sizeof (dir));
170 if (lstat (dir, &st) || (st.st_mode & S_IFDIR) == 0) {
171 snprintf (buf, sizeof (buf), _("Directory %s not exist. Create it?"),
173 if (mutt_yesorno (buf, M_YES) != M_YES
174 || mkdir (dir, (S_IRWXU + S_IRWXG + S_IRWXO))) {
175 mutt_error _("Cache directory not created!");
182 set_option (OPTNEWSCACHE);
184 p_delete(&news->cache);
185 snprintf (buf, sizeof (buf), "%s/.index", dir);
186 if (!(idx = safe_fopen (buf, "a+")))
189 while (fgets (buf, sizeof (buf), idx)) {
190 buf[m_strlen(buf) - 1] = 0; /* strip ending '\n' */
191 if (!m_strncmp(buf, "#: ", 3) &&
192 !m_strcasecmp(buf + 3, news->conn->account.host))
195 while (fgets (buf, sizeof (buf), idx)) {
197 while (*cp && *cp != ' ')
202 if (!m_strcmp(buf, "#:"))
204 sscanf (cp + 1, "%s %d %d", file, &l, &m);
205 if (!m_strcmp(buf, "ALL")) {
206 news->cache = m_strdup(file);
207 news->newgroups_time = m;
209 else if (news->newsgroups) {
210 if ((data = (NNTP_DATA *) hash_find (news->newsgroups, buf)) == NULL) {
211 data = xmalloc(sizeof(NNTP_DATA) + m_strlen(buf) + 1);
212 data->group = (char *) data + sizeof (NNTP_DATA);
213 strcpy (data->group, buf);
216 if (news->newsgroups->nelem < news->newsgroups->curnelem * 2)
217 hash_resize (news->newsgroups, news->newsgroups->nelem * 2);
218 hash_insert (news->newsgroups, data->group, data);
219 nntp_add_to_list (news, data);
221 data->cache = m_strdup(file);
223 if (!data->firstMessage || data->lastMessage < m)
225 if (!data->firstMessage)
226 data->firstMessage = l;
227 if (data->lastMessage < m)
228 data->lastMessage = m;
229 data->lastCached = m;
230 if (t || !data->unread)
231 mutt_newsgroup_stat (data);
238 const char *nntp_format_str(char *dest, ssize_t destlen, char op,
239 const char *src, const char *fmt,
240 const char *ifstr __attribute__((unused)),
241 const char *elstr __attribute__((unused)),
242 anytype data __attribute__((unused)),
243 format_flag flags __attribute__((unused)))
245 char fn[STRING], tmp[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) {
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 m_strformat(file, sizeof(file), 0, NewsRc, nntp_format_str, NULL, 0);
348 mutt_expand_path(file, sizeof(file));
350 serv = (NNTP_SERVER *) conn->data;
354 /* externally modified? */
355 if (serv->stat != stat (file, &sb) || (!serv->stat &&
356 (serv->size != sb.st_size
357 || serv->mtime != sb.st_mtime))) {
358 for (list = serv->list; list; list = list->next) {
359 NNTP_DATA *data = (NNTP_DATA *) list->data;
362 data->subscribed = 0;
368 nntp_clear_cacheindex (serv);
371 if (serv->status == NNTP_BYE)
372 serv->status = NNTP_NONE;
373 nntp_check_newgroups (serv, 0);
378 serv = p_new(NNTP_SERVER, 1);
380 serv->newsrc = m_strdup(file);
381 serv->newsgroups = hash_new(1009, false);
382 slurp_newsrc (serv); /* load .newsrc */
383 nntp_parse_cacheindex (serv); /* load .index */
384 if (option (OPTNEWSCACHE) && serv->cache && nntp_get_cache_all (serv) >= 0)
385 nntp_check_newgroups (serv, 1);
386 else if (nntp_get_active (serv) < 0) {
387 hash_delete (&serv->newsgroups, nntp_delete_data);
388 for (list = serv->list; list; list = list->next)
390 string_list_wipe(&serv->list);
391 p_delete(&serv->newsrc);
392 p_delete(&serv->cache);
396 nntp_clear_cacheindex (serv);
397 conn->data = (void *) serv;
403 * full status flags are not supported by nntp, but we can fake some
404 * of them. This is how:
405 * Read = a read message number is in the .newsrc
406 * New = a message is new since we last read this newsgroup
407 * Old = anything else
408 * So, Read is marked as such in the newsrc, old is anything that is
409 * "skipped" in the newsrc, and new is anything not in the newsrc nor
410 * in the cache. By skipped, I mean before the last unread message
412 void nntp_get_status (CONTEXT * ctx, HEADER * h, char *group, int article)
414 NNTP_DATA *data = (NNTP_DATA *) ctx->data;
418 data = (NNTP_DATA *) hash_find (data->nserv->newsgroups, group);
424 for (x = 0; x < data->num; x++) {
425 if ((article >= data->entries[x].first) &&
426 (article <= data->entries[x].last)) {
427 /* we cannot use mutt_set_flag() because mx_update_context()
433 /* If article was not cached yet, it is new! :) */
434 if (!data->cache || article > data->lastCached)
436 /* Old articles are articles which aren't read but an article after them
438 if (option (OPTMARKOLD))
442 void mutt_newsgroup_stat (NNTP_DATA * data)
445 unsigned int first, last;
448 if (data->lastMessage == 0 || data->firstMessage > data->lastMessage)
451 data->unread = data->lastMessage - data->firstMessage + 1;
452 for (i = 0; i < data->num; i++) {
453 first = data->entries[i].first;
454 if (first < data->firstMessage)
455 first = data->firstMessage;
456 last = data->entries[i].last;
457 if (last > data->lastMessage)
458 last = data->lastMessage;
460 data->unread -= last - first + 1;
464 static int puti (char *line, int num)
469 *p++ = '0' + num % 10;
473 *line++ = *--p, num++;
478 static void nntp_create_newsrc_line (NNTP_DATA * data, char **buf,
479 char **pline, ssize_t * buflen)
482 ssize_t len = *buflen - (*pline - *buf);
485 if (len < LONG_STRING * 10) {
489 p_realloc(buf, *buflen);
490 line = *buf + (*pline - line);
492 strcpy (line, data->group);
493 len -= m_strlen(line) + 1;
494 line += m_strlen(line);
495 *line++ = data->subscribed ? ':' : '!';
499 for (x = 0; x < data->num; x++) {
500 if (len < LONG_STRING) {
505 p_realloc(buf, *buflen);
506 line = *buf + (*pline - line);
513 i = puti (line, data->entries[x].first);
516 if (data->entries[x].first != data->entries[x].last) {
519 i = puti (line, data->entries[x].last);
529 void newsrc_gen_entries (CONTEXT * ctx)
531 NNTP_DATA *data = (NNTP_DATA *) ctx->data;
533 unsigned int last = 0, first = 1;
534 int save_sort = SORT_ORDER;
536 if (Sort != SORT_ORDER) {
539 mutt_sort_headers (ctx, 0);
543 data->entries = p_new(NEWSRC_ENTRY, 5);
548 * Set up to fake initial sequence from 1 to the article before the
549 * first article in our list
554 for (x = 0; x < ctx->msgcount; x++) {
555 if (series) { /* search for first unread */
557 * We don't actually check sequential order, since we mark
558 * "missing" entries as read/deleted
560 last = ctx->hdrs[x]->article_num;
561 if (last >= data->firstMessage && !ctx->hdrs[x]->deleted &&
562 !ctx->hdrs[x]->read) {
563 if (data->num >= data->max) {
564 data->max = data->max * 2;
565 p_realloc(&data->entries, data->max);
567 data->entries[data->num].first = first;
568 data->entries[data->num].last = last - 1;
573 else { /* search for first read */
575 if (ctx->hdrs[x]->deleted || ctx->hdrs[x]->read) {
579 last = ctx->hdrs[x]->article_num;
582 if (series && first <= data->lastLoaded) {
583 if (data->num >= data->max) {
584 data->max = data->max * 2;
585 p_realloc(&data->entries, data->max);
587 data->entries[data->num].first = first;
588 data->entries[data->num].last = data->lastLoaded;
592 if (save_sort != Sort) {
594 mutt_sort_headers (ctx, 0);
598 static int mutt_update_list_file (char *filename, char *section,
599 const char *key, char *line) {
602 char buf[HUGE_STRING];
603 char tmpf[_POSIX_PATH_MAX], lnk[_POSIX_PATH_MAX];
605 int ext = 0, done = 0, r = 0, l = 0;
607 /* if file not exist, create it */
608 if ((ifp = safe_fopen (filename, "a")))
610 if (!(ifp = safe_fopen (filename, "r"))) {
611 mutt_error (_("Unable to open %s for reading"), filename);
614 if (mx_lock_file (filename, fileno (ifp), 0, 0, 1)) {
616 mutt_error (_("Unable to lock %s"), filename);
620 /* use m_tempfile() to get a tempfile in the same
621 * directory as filename is so that we can follow symlinks
622 * via rename(2); as dirname(2) may modify its argument,
623 * temporarily use buf as copy of it
625 m_strcpy(buf, sizeof(buf), filename);
626 ofp = m_tempfile(tmpf, sizeof(tmpf), dirname(buf), filename);
629 mutt_error (_("Unable to open %s for writing"), tmpf);
634 while (r != EOF && !done && fgets (buf, sizeof (buf), ifp)) {
635 r = fputs (buf, ofp);
637 while (*c && *c != '\n') c++;
638 c[0] = 0; /* strip EOL */
639 if (!strncmp (buf, "#: ", 3) && !m_strcasecmp(buf+3, section))
642 if (r != EOF && !done) {
643 snprintf (buf, sizeof(buf), "#: %s\n", section);
644 r = fputs (buf, ofp);
649 while (r != EOF && fgets (buf, sizeof (buf), ifp)) {
652 while (*c && (*c != '\r') && (*c != '\n')) c++;
654 if (*c != '\\') ext = 0;
655 } else if ((section && !strncmp (buf, "#: ", 3))) {
660 r = fputs (buf, ofp);
663 } else if (key && !strncmp (buf, key, strlen(key)) &&
664 (!*key || buf[strlen(key)] == ' ')) {
667 while (*c && (*c != '\r') && (*c != '\n')) c++;
669 if (*c == '\\') ext = 1;
671 r = fputs (line, ofp);
673 r = fputc ('\n', ofp);
677 r = fputs (buf, ofp);
681 while (r != EOF && fgets (buf, sizeof (buf), ifp))
682 r = fputs (buf, ofp);
684 /* If there wasn't a line to replace, put it on the end of the file */
685 if (r != EOF && !done && line) {
687 r = fputc ('\n', ofp);
689 mx_unlock_file (filename, fileno (ifp), 0);
694 mutt_error (_("Can't write %s"), tmpf);
698 if ((l = readlink (filename, lnk, sizeof(lnk)-1)) > 0)
700 if (rename (tmpf, l > 0 ? lnk : filename) < 0) {
702 mutt_error (_("Can't rename %s to %s"), tmpf, l > 0 ? lnk : filename);
708 int mutt_newsrc_update (NNTP_SERVER * news)
718 llen = len = 10 * LONG_STRING;
719 line = buf = p_new(char, len);
720 /* we will generate full newsrc here */
721 for (tmp = news->list; tmp; tmp = tmp->next) {
722 data = (NNTP_DATA *) tmp->data;
723 if (!data || !data->rc)
725 nntp_create_newsrc_line (data, &buf, &line, &llen);
726 line += m_strlen(line);
728 /* newrc being fully rewritten */
730 (r = mutt_update_list_file(news->newsrc, NULL, "", buf)) == 0) {
733 stat (news->newsrc, &st);
734 news->size = st.st_size;
735 news->mtime = st.st_mtime;
741 static FILE *mutt_mkname (char *s)
743 char buf[_POSIX_PATH_MAX], *pc;
747 nntp_cache_expand (buf, s);
748 if ((fp = safe_fopen (buf, "w")))
751 nntp_cache_expand (buf, "cache-XXXXXX");
752 pc = buf + m_strlen(buf) - 12; /* positioning to "cache-XXXXXX" */
753 if ((fd = mkstemp (buf)) == -1)
755 strcpy (s, pc); /* generated name */
756 return fdopen (fd, "w");
759 /* Updates info into .index file: ALL or about selected newsgroup */
760 static int nntp_update_cacheindex (NNTP_SERVER * serv, NNTP_DATA * data)
762 char buf[LONG_STRING];
763 char file[_POSIX_PATH_MAX];
764 const char *key = "ALL";
766 if (!serv || !serv->conn || !serv->conn->account.host)
769 if (data && data->group) {
771 snprintf (buf, sizeof (buf), "%s %s %d %d", key, data->cache,
772 data->firstMessage, data->lastLoaded);
775 m_strcpy(file, sizeof(file), serv->cache);
776 snprintf (buf, sizeof (buf), "ALL %s 0 %d", file,
777 (int) serv->newgroups_time);
779 nntp_cache_expand (file, ".index");
780 return mutt_update_list_file (file, serv->conn->account.host, key, buf);
783 /* Remove cache files of unsubscribed newsgroups */
784 void nntp_clear_cacheindex (NNTP_SERVER * news)
789 if (option (OPTSAVEUNSUB) || !news)
792 for (tmp = news->list; tmp; tmp = tmp->next) {
793 data = (NNTP_DATA *) tmp->data;
794 if (!data || data->subscribed || !data->cache)
796 nntp_delete_cache (data);
801 int nntp_save_cache_index (NNTP_SERVER * news)
803 char buf[HUGE_STRING];
804 char file[_POSIX_PATH_MAX];
809 if (!news || !news->newsgroups)
811 if (!option (OPTNEWSCACHE))
815 nntp_cache_expand (file, news->cache);
817 f = safe_fopen (file, "w");
820 m_strcpy(buf, sizeof(buf), news->conn->account.host);
821 f = mutt_mkname (buf);
822 news->cache = m_strdup(buf);
823 nntp_cache_expand (file, buf);
828 for (l = news->list; l; l = l->next) {
829 if ((d = (NNTP_DATA *) l->data) && !d->deleted) {
831 snprintf (buf, sizeof (buf), "%s %d %d %c %s\n", d->group,
832 d->lastMessage, d->firstMessage, d->allowed ? 'y' : 'n',
835 snprintf (buf, sizeof (buf), "%s %d %d %c\n", d->group,
836 d->lastMessage, d->firstMessage, d->allowed ? 'y' : 'n');
837 if (fputs (buf, f) == EOF) {
846 if (nntp_update_cacheindex (news, NULL)) {
853 int nntp_save_cache_group (CONTEXT * ctx)
855 char buf[HUGE_STRING], addr[STRING];
856 char file[_POSIX_PATH_MAX];
860 int i = 0, save = SORT_ORDER;
863 if (!option (OPTNEWSCACHE))
865 if (!ctx || !ctx->data || ctx->magic != M_NNTP)
868 if (((NNTP_DATA *) ctx->data)->cache) {
869 nntp_cache_expand (file, ((NNTP_DATA *) ctx->data)->cache);
871 f = safe_fopen (file, "w");
874 snprintf (buf, sizeof (buf), "%s-%s",
875 ((NNTP_DATA *) ctx->data)->nserv->conn->account.host,
876 ((NNTP_DATA *) ctx->data)->group);
877 f = mutt_mkname (buf);
878 ((NNTP_DATA *) ctx->data)->cache = m_strdup(buf);
879 nntp_cache_expand (file, buf);
884 if (Sort != SORT_ORDER) {
887 mutt_sort_headers (ctx, 0);
890 /* Save only $nntp_context messages... */
891 ((NNTP_DATA *) ctx->data)->lastCached = 0;
892 if (NntpContext && ctx->msgcount > NntpContext)
893 i = ctx->msgcount - NntpContext;
894 for (; i < ctx->msgcount; i++) {
895 if (!ctx->hdrs[i]->deleted && ctx->hdrs[i]->article_num != prev) {
898 rfc822_addrcat(addr, sizeof(addr), h->env->from, 0);
899 tm = gmtime (&h->date_sent);
900 snprintf (buf, sizeof (buf),
901 "%d\t%s\t%s\t%d %s %d %02d:%02d:%02d GMT\t%s\t",
902 h->article_num, h->env->subject, addr, tm->tm_mday,
903 Months[tm->tm_mon], tm->tm_year + 1900, tm->tm_hour,
904 tm->tm_min, tm->tm_sec, h->env->message_id);
906 if (h->env->references)
907 mutt_write_references (h->env->references, f);
908 snprintf (buf, sizeof (buf), "\t%zd\t%d\tXref: %s\n",
909 h->content->length, h->lines, NONULL (h->env->xref));
910 if (fputs (buf, f) == EOF) {
916 prev = ctx->hdrs[i]->article_num;
921 mutt_sort_headers (ctx, 0);
925 if (nntp_update_cacheindex (((NNTP_DATA *) ctx->data)->nserv,
926 (NNTP_DATA *) ctx->data)) {
930 ((NNTP_DATA *) ctx->data)->lastCached =
931 ((NNTP_DATA *) ctx->data)->lastLoaded;
935 void nntp_delete_cache (NNTP_DATA * data)
937 char buf[_POSIX_PATH_MAX];
939 if (!option (OPTNEWSCACHE) || !data || !data->cache || !data->nserv)
942 nntp_cache_expand (buf, data->cache);
944 p_delete(&data->cache);
945 data->lastCached = 0;
946 nntp_cache_expand (buf, ".index");
947 mutt_update_list_file (buf, data->nserv->conn->account.host, data->group,
951 NNTP_DATA *mutt_newsgroup_subscribe (NNTP_SERVER * news, char *group)
955 if (!news || !news->newsgroups || !group || !*group)
957 if (!(data = (NNTP_DATA *) hash_find (news->newsgroups, group))) {
958 data = xmalloc(sizeof(NNTP_DATA) + m_strlen(group) + 1);
959 data->group = (char *) data + sizeof (NNTP_DATA);
960 strcpy (data->group, group);
963 if (news->newsgroups->nelem < news->newsgroups->curnelem * 2)
964 hash_resize (news->newsgroups, news->newsgroups->nelem * 2);
965 hash_insert (news->newsgroups, data->group, data);
966 nntp_add_to_list (news, data);
968 if (!data->subscribed) {
969 data->subscribed = 1;
975 NNTP_DATA *mutt_newsgroup_unsubscribe (NNTP_SERVER * news, char *group)
979 if (!news || !news->newsgroups || !group || !*group ||
980 !(data = (NNTP_DATA *) hash_find (news->newsgroups, group)))
982 if (data->subscribed) {
983 data->subscribed = 0;
984 if (!option (OPTSAVEUNSUB))
990 NNTP_DATA *mutt_newsgroup_catchup (NNTP_SERVER * news, char *group)
994 if (!news || !news->newsgroups || !group || !*group ||
995 !(data = (NNTP_DATA *) hash_find (news->newsgroups, group)))
998 data->entries = p_new(NEWSRC_ENTRY, 5);
1002 data->entries[0].first = 1;
1004 data->entries[0].last = data->lastMessage;
1005 if (Context && Context->data == data) {
1008 for (x = 0; x < Context->msgcount; x++)
1009 mutt_set_flag (Context, Context->hdrs[x], M_READ, 1);
1014 NNTP_DATA *mutt_newsgroup_uncatchup (NNTP_SERVER * news, char *group)
1018 if (!news || !news->newsgroups || !group || !*group ||
1019 !(data = (NNTP_DATA *) hash_find (news->newsgroups, group)))
1022 data->entries = p_new(NEWSRC_ENTRY, 5);
1026 data->entries[0].first = 1;
1027 data->entries[0].last = data->firstMessage - 1;
1028 if (Context && Context->data == data) {
1031 data->unread = Context->msgcount;
1032 for (x = 0; x < Context->msgcount; x++)
1033 mutt_set_flag (Context, Context->hdrs[x], M_READ, 0);
1036 data->unread = data->lastMessage - data->entries[0].last;
1040 /* this routine gives the first newsgroup with new messages */
1041 void nntp_buffy (char* dst, ssize_t dstlen) {
1042 string_list_t *list;
1045 /* forward to current group */
1046 for (list = CurrentNewsSrv->list; list; list = list->next) {
1047 NNTP_DATA *data = (NNTP_DATA *) list->data;
1048 if (data && data->subscribed && data->unread &&
1049 Context && Context->magic == M_NNTP &&
1050 m_strcmp(data->group, ((NNTP_DATA *) Context->data)->group) == 0) {
1061 list = CurrentNewsSrv->list;
1063 for (; list; list = list->next) {
1064 NNTP_DATA *data = (NNTP_DATA *) list->data;
1066 if (data && data->subscribed && data->unread) {
1067 if (Context && Context->magic == M_NNTP &&
1068 !m_strcmp(data->group, ((NNTP_DATA *) Context->data)->group)) {
1069 unsigned int i, unread = 0;
1071 for (i = 0; i < Context->msgcount; i++)
1072 if (!Context->hdrs[i]->read && !Context->hdrs[i]->deleted)
1077 m_strcpy(dst, dstlen, data->group);