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 != '!'))
59 if (len > sizeof (group))
61 m_strcpy(group, len, line);
62 if ((data = (NNTP_DATA *) hash_find (news->newsgroups, group)) == NULL) {
63 data = xmalloc(sizeof(NNTP_DATA) + m_strlen(group) + 1);
64 data->group = (char *) data + sizeof (NNTP_DATA);
65 strcpy (data->group, group);
68 if (news->newsgroups->nelem < news->newsgroups->curnelem * 2)
70 hash_resize (news->newsgroups, news->newsgroups->nelem * 2);
71 hash_insert (news->newsgroups, data->group, data, 0);
72 nntp_add_to_list (news, data);
75 p_delete(&data->entries);
78 data->entries = p_new(NEWSRC_ENTRY, x * 2);
90 while (*p && *p != ',' && *p != '\n')
96 if ((h = strchr (b, '-'))) {
99 data->entries[x].first = atoi (b);
100 data->entries[x].last = atoi (h);
103 data->entries[x].first = atoi (b);
104 data->entries[x].last = data->entries[x].first;
107 if (data->entries[x].last != 0)
110 if (x && !data->lastMessage)
111 data->lastMessage = data->entries[x - 1].last;
113 mutt_newsgroup_stat (data);
118 static int slurp_newsrc (NNTP_SERVER * news)
124 news->stat = stat (news->newsrc, &sb);
125 news->size = sb.st_size;
126 news->mtime = sb.st_mtime;
128 if ((fp = safe_fopen (news->newsrc, "r")) == NULL)
130 /* hmm, should we use dotlock? */
131 if (mx_lock_file (news->newsrc, fileno (fp), 0, 0, 1)) {
136 buf = p_new(char, sb.st_size + 1);
137 while (fgets (buf, sb.st_size + 1, fp))
138 nntp_parse_newsrc_line (news, buf);
141 mx_unlock_file (news->newsrc, fileno (fp), 0);
146 void nntp_cache_expand (char *dst, const char *src)
148 snprintf (dst, _POSIX_PATH_MAX, "%s/%s", NewsCacheDir, src);
149 mutt_expand_path (dst, _POSIX_PATH_MAX);
152 /* Loads $news_cache_dir/.index into memory, loads newsserver data
153 * and newsgroup cache names */
154 static int nntp_parse_cacheindex (NNTP_SERVER * news)
157 char buf[HUGE_STRING], *cp;
158 char dir[_POSIX_PATH_MAX], file[_POSIX_PATH_MAX];
163 /* check is server name defined or not */
164 if (!news || !news->conn || !news->conn->account.host)
166 unset_option (OPTNEWSCACHE);
167 if (!NewsCacheDir || !*NewsCacheDir)
170 m_strcpy(dir, sizeof(dir), NewsCacheDir);
171 mutt_expand_path (dir, sizeof (dir));
173 if (lstat (dir, &st) || (st.st_mode & S_IFDIR) == 0) {
174 snprintf (buf, sizeof (buf), _("Directory %s not exist. Create it?"),
176 if (mutt_yesorno (buf, M_YES) != M_YES
177 || mkdir (dir, (S_IRWXU + S_IRWXG + S_IRWXO))) {
178 mutt_error _("Cache directory not created!");
185 set_option (OPTNEWSCACHE);
187 p_delete(&news->cache);
188 snprintf (buf, sizeof (buf), "%s/.index", dir);
189 if (!(idx = safe_fopen (buf, "a+")))
192 while (fgets (buf, sizeof (buf), idx)) {
193 buf[m_strlen(buf) - 1] = 0; /* strip ending '\n' */
194 if (!m_strncmp(buf, "#: ", 3) &&
195 !m_strcasecmp(buf + 3, news->conn->account.host))
198 while (fgets (buf, sizeof (buf), idx)) {
200 while (*cp && *cp != ' ')
205 if (!m_strcmp(buf, "#:"))
207 sscanf (cp + 1, "%s %d %d", file, &l, &m);
208 if (!m_strcmp(buf, "ALL")) {
209 news->cache = m_strdup(file);
210 news->newgroups_time = m;
212 else if (news->newsgroups) {
213 if ((data = (NNTP_DATA *) hash_find (news->newsgroups, buf)) == NULL) {
214 data = xmalloc(sizeof(NNTP_DATA) + m_strlen(buf) + 1);
215 data->group = (char *) data + sizeof (NNTP_DATA);
216 strcpy (data->group, buf);
219 if (news->newsgroups->nelem < news->newsgroups->curnelem * 2)
221 hash_resize (news->newsgroups, news->newsgroups->nelem * 2);
222 hash_insert (news->newsgroups, data->group, data, 0);
223 nntp_add_to_list (news, data);
225 data->cache = m_strdup(file);
227 if (!data->firstMessage || data->lastMessage < m)
229 if (!data->firstMessage)
230 data->firstMessage = l;
231 if (data->lastMessage < m)
232 data->lastMessage = m;
233 data->lastCached = m;
234 if (t || !data->unread)
235 mutt_newsgroup_stat (data);
242 const char *nntp_format_str (char *dest, ssize_t destlen, char op,
243 const char *src, const char *fmt,
244 const char *ifstring, const char *elsestring,
245 unsigned long data, format_flag flags)
247 char fn[SHORT_STRING], tmp[SHORT_STRING];
251 m_strcpy(fn, sizeof (fn), NewsServer);
253 snprintf (tmp, sizeof (tmp), "%%%ss", fmt);
254 snprintf (dest, destlen, tmp, fn);
260 /* nntp_parse_url: given an NNPT URL, return host, port,
261 * username, password and newsgroup will recognise. */
262 int nntp_parse_url (const char *server, ACCOUNT * act,
263 char *group, ssize_t group_len)
271 act->port = NNTP_PORT;
272 act->type = M_ACCT_TYPE_NNTP;
274 c = m_strdup(server);
275 url_parse_ciss (&url, c);
277 if (url.scheme == U_NNTP || url.scheme == U_NNTPS) {
278 if (url.scheme == U_NNTPS) {
279 act->flags |= M_ACCT_SSL;
280 act->port = NNTP_SSL_PORT;
285 m_strcpy(group, group_len, url.path);
287 ret = mutt_account_fromurl (act, &url);
294 void nntp_expand_path (char *line, ssize_t len, ACCOUNT * act)
298 url.path = m_strdup(line);
299 mutt_account_tourl (act, &url);
300 url_ciss_tostring (&url, line, len, 0);
305 * Automatically loads a newsrc into memory, if necessary.
306 * Checks the size/mtime of a newsrc file, if it doesn't match, load
307 * again. Hmm, if a system has broken mtimes, this might mean the file
308 * is reloaded every time, which we'd have to fix.
310 * a newsrc file is a line per newsgroup, with the newsgroup, then a
311 * ':' denoting subscribed or '!' denoting unsubscribed, then a
312 * comma separated list of article numbers and ranges.
314 NNTP_SERVER *mutt_select_newsserver (char *server)
316 char file[_POSIX_PATH_MAX];
325 if (!server || !*server) {
326 mutt_error _("No newsserver defined!");
331 buf = p = p_new(char, m_strlen(server) + 10);
332 if (url_check_scheme (server) == U_UNKNOWN) {
333 strcpy (buf, "nntp://");
334 p = strchr (buf, '\0');
338 if ((nntp_parse_url (buf, &act, file, sizeof (file))) < 0 || *file) {
340 mutt_error (_("%s is an invalid newsserver specification!"), server);
345 conn = mutt_conn_find (NULL, &act);
349 mutt_FormatString (file, sizeof (file), NONULL (NewsRc), nntp_format_str, 0,
351 mutt_expand_path (file, sizeof (file));
353 serv = (NNTP_SERVER *) conn->data;
357 /* externally modified? */
358 if (serv->stat != stat (file, &sb) || (!serv->stat &&
359 (serv->size != sb.st_size
360 || serv->mtime != sb.st_mtime))) {
361 for (list = serv->list; list; list = list->next) {
362 NNTP_DATA *data = (NNTP_DATA *) list->data;
365 data->subscribed = 0;
371 nntp_clear_cacheindex (serv);
374 if (serv->status == NNTP_BYE)
375 serv->status = NNTP_NONE;
376 nntp_check_newgroups (serv, 0);
381 serv = p_new(NNTP_SERVER, 1);
383 serv->newsrc = m_strdup(file);
384 serv->newsgroups = hash_create (1009);
385 slurp_newsrc (serv); /* load .newsrc */
386 nntp_parse_cacheindex (serv); /* load .index */
387 if (option (OPTNEWSCACHE) && serv->cache && nntp_get_cache_all (serv) >= 0)
388 nntp_check_newgroups (serv, 1);
389 else if (nntp_get_active (serv) < 0) {
390 hash_destroy (&serv->newsgroups, nntp_delete_data);
391 for (list = serv->list; list; list = list->next)
393 string_list_wipe(&serv->list);
394 p_delete(&serv->newsrc);
395 p_delete(&serv->cache);
399 nntp_clear_cacheindex (serv);
400 conn->data = (void *) serv;
406 * full status flags are not supported by nntp, but we can fake some
407 * of them. This is how:
408 * Read = a read message number is in the .newsrc
409 * New = a message is new since we last read this newsgroup
410 * Old = anything else
411 * So, Read is marked as such in the newsrc, old is anything that is
412 * "skipped" in the newsrc, and new is anything not in the newsrc nor
413 * in the cache. By skipped, I mean before the last unread message
415 void nntp_get_status (CONTEXT * ctx, HEADER * h, char *group, int article)
417 NNTP_DATA *data = (NNTP_DATA *) ctx->data;
421 data = (NNTP_DATA *) hash_find (data->nserv->newsgroups, group);
427 for (x = 0; x < data->num; x++) {
428 if ((article >= data->entries[x].first) &&
429 (article <= data->entries[x].last)) {
430 /* we cannot use mutt_set_flag() because mx_update_context()
436 /* If article was not cached yet, it is new! :) */
437 if (!data->cache || article > data->lastCached)
439 /* Old articles are articles which aren't read but an article after them
441 if (option (OPTMARKOLD))
445 void mutt_newsgroup_stat (NNTP_DATA * data)
448 unsigned int first, last;
451 if (data->lastMessage == 0 || data->firstMessage > data->lastMessage)
454 data->unread = data->lastMessage - data->firstMessage + 1;
455 for (i = 0; i < data->num; i++) {
456 first = data->entries[i].first;
457 if (first < data->firstMessage)
458 first = data->firstMessage;
459 last = data->entries[i].last;
460 if (last > data->lastMessage)
461 last = data->lastMessage;
463 data->unread -= last - first + 1;
467 static int puti (char *line, int num)
472 *p++ = '0' + num % 10;
476 *line++ = *--p, num++;
481 static void nntp_create_newsrc_line (NNTP_DATA * data, char **buf,
482 char **pline, ssize_t * buflen)
485 ssize_t len = *buflen - (*pline - *buf);
488 if (len < LONG_STRING * 10) {
492 p_realloc(buf, *buflen);
493 line = *buf + (*pline - line);
495 strcpy (line, data->group);
496 len -= m_strlen(line) + 1;
497 line += m_strlen(line);
498 *line++ = data->subscribed ? ':' : '!';
502 for (x = 0; x < data->num; x++) {
503 if (len < LONG_STRING) {
508 p_realloc(buf, *buflen);
509 line = *buf + (*pline - line);
517 if (data->entries[x].first == data->entries[x].last)
518 snprintf (line, len, "%d%n", data->entries[x].first, &i);
520 snprintf (line, len, "%d-%d%n",
521 data->entries[x].first, data->entries[x].last, &i);
525 i = puti (line, data->entries[x].first);
528 if (data->entries[x].first != data->entries[x].last) {
531 i = puti (line, data->entries[x].last);
542 void newsrc_gen_entries (CONTEXT * ctx)
544 NNTP_DATA *data = (NNTP_DATA *) ctx->data;
546 unsigned int last = 0, first = 1;
547 int save_sort = SORT_ORDER;
549 if (Sort != SORT_ORDER) {
552 mutt_sort_headers (ctx, 0);
556 data->entries = p_new(NEWSRC_ENTRY, 5);
561 * Set up to fake initial sequence from 1 to the article before the
562 * first article in our list
567 for (x = 0; x < ctx->msgcount; x++) {
568 if (series) { /* search for first unread */
570 * We don't actually check sequential order, since we mark
571 * "missing" entries as read/deleted
573 last = ctx->hdrs[x]->article_num;
574 if (last >= data->firstMessage && !ctx->hdrs[x]->deleted &&
575 !ctx->hdrs[x]->read) {
576 if (data->num >= data->max) {
577 data->max = data->max * 2;
578 p_realloc(&data->entries, data->max);
580 data->entries[data->num].first = first;
581 data->entries[data->num].last = last - 1;
586 else { /* search for first read */
588 if (ctx->hdrs[x]->deleted || ctx->hdrs[x]->read) {
592 last = ctx->hdrs[x]->article_num;
595 if (series && first <= data->lastLoaded) {
596 if (data->num >= data->max) {
597 data->max = data->max * 2;
598 p_realloc(&data->entries, data->max);
600 data->entries[data->num].first = first;
601 data->entries[data->num].last = data->lastLoaded;
605 if (save_sort != Sort) {
607 mutt_sort_headers (ctx, 0);
611 static int mutt_update_list_file (char *filename, char *section,
612 const char *key, char *line) {
615 char buf[HUGE_STRING];
616 char tmpfile[_POSIX_PATH_MAX], link[_POSIX_PATH_MAX];
618 int ext = 0, done = 0, r = 0, l = 0;
620 /* if file not exist, create it */
621 if ((ifp = safe_fopen (filename, "a")))
623 if (!(ifp = safe_fopen (filename, "r"))) {
624 mutt_error (_("Unable to open %s for reading"), filename);
627 if (mx_lock_file (filename, fileno (ifp), 0, 0, 1)) {
629 mutt_error (_("Unable to lock %s"), filename);
632 /* use mutt_adv_mktemp() to get a tempfile in the same
633 * directory as filename is so that we can follow symlinks
634 * via rename(2); as dirname(2) may modify its argument,
635 * temporarily use buf as copy of it
637 m_strcpy(buf, sizeof(buf), filename);
638 m_strcpy(tmpfile, sizeof(tmpfile), basename(filename));
639 mutt_adv_mktemp ((const char*) dirname (buf), tmpfile, sizeof (tmpfile));
640 if (!(ofp = fopen (tmpfile, "w"))) {
642 mutt_error (_("Unable to open %s for writing"), tmpfile);
647 while (r != EOF && !done && fgets (buf, sizeof (buf), ifp)) {
648 r = fputs (buf, ofp);
650 while (*c && *c != '\n') c++;
651 c[0] = 0; /* strip EOL */
652 if (!strncmp (buf, "#: ", 3) && !m_strcasecmp(buf+3, section))
655 if (r != EOF && !done) {
656 snprintf (buf, sizeof(buf), "#: %s\n", section);
657 r = fputs (buf, ofp);
662 while (r != EOF && fgets (buf, sizeof (buf), ifp)) {
665 while (*c && (*c != '\r') && (*c != '\n')) c++;
667 if (*c != '\\') ext = 0;
668 } else if ((section && !strncmp (buf, "#: ", 3))) {
673 r = fputs (buf, ofp);
676 } else if (key && !strncmp (buf, key, strlen(key)) &&
677 (!*key || buf[strlen(key)] == ' ')) {
680 while (*c && (*c != '\r') && (*c != '\n')) c++;
682 if (*c == '\\') ext = 1;
684 r = fputs (line, ofp);
686 r = fputc ('\n', ofp);
690 r = fputs (buf, ofp);
694 while (r != EOF && fgets (buf, sizeof (buf), ifp))
695 r = fputs (buf, ofp);
697 /* If there wasn't a line to replace, put it on the end of the file */
698 if (r != EOF && !done && line) {
700 r = fputc ('\n', ofp);
702 mx_unlock_file (filename, fileno (ifp), 0);
707 mutt_error (_("Can't write %s"), tmpfile);
711 if ((l = readlink (filename, link, sizeof (link)-1)) > 0)
713 if (rename (tmpfile, l > 0 ? link : filename) < 0) {
715 mutt_error (_("Can't rename %s to %s"), tmpfile, l > 0 ? link : filename);
721 int mutt_newsrc_update (NNTP_SERVER * news)
731 llen = len = 10 * LONG_STRING;
732 line = buf = p_new(char, len);
733 /* we will generate full newsrc here */
734 for (tmp = news->list; tmp; tmp = tmp->next) {
735 data = (NNTP_DATA *) tmp->data;
736 if (!data || !data->rc)
738 nntp_create_newsrc_line (data, &buf, &line, &llen);
739 line += m_strlen(line);
741 /* newrc being fully rewritten */
743 (r = mutt_update_list_file(news->newsrc, NULL, "", buf)) == 0) {
746 stat (news->newsrc, &st);
747 news->size = st.st_size;
748 news->mtime = st.st_mtime;
754 static FILE *mutt_mkname (char *s)
756 char buf[_POSIX_PATH_MAX], *pc;
760 nntp_cache_expand (buf, s);
761 if ((fp = safe_fopen (buf, "w")))
764 nntp_cache_expand (buf, "cache-XXXXXX");
765 pc = buf + m_strlen(buf) - 12; /* positioning to "cache-XXXXXX" */
766 if ((fd = mkstemp (buf)) == -1)
768 strcpy (s, pc); /* generated name */
769 return fdopen (fd, "w");
772 /* Updates info into .index file: ALL or about selected newsgroup */
773 static int nntp_update_cacheindex (NNTP_SERVER * serv, NNTP_DATA * data)
775 char buf[LONG_STRING];
776 char file[_POSIX_PATH_MAX];
777 const char *key = "ALL";
779 if (!serv || !serv->conn || !serv->conn->account.host)
782 if (data && data->group) {
784 snprintf (buf, sizeof (buf), "%s %s %d %d", key, data->cache,
785 data->firstMessage, data->lastLoaded);
788 m_strcpy(file, sizeof(file), serv->cache);
789 snprintf (buf, sizeof (buf), "ALL %s 0 %d", file,
790 (int) serv->newgroups_time);
792 nntp_cache_expand (file, ".index");
793 return mutt_update_list_file (file, serv->conn->account.host, key, buf);
796 /* Remove cache files of unsubscribed newsgroups */
797 void nntp_clear_cacheindex (NNTP_SERVER * news)
802 if (option (OPTSAVEUNSUB) || !news)
805 for (tmp = news->list; tmp; tmp = tmp->next) {
806 data = (NNTP_DATA *) tmp->data;
807 if (!data || data->subscribed || !data->cache)
809 nntp_delete_cache (data);
814 int nntp_save_cache_index (NNTP_SERVER * news)
816 char buf[HUGE_STRING];
817 char file[_POSIX_PATH_MAX];
822 if (!news || !news->newsgroups)
824 if (!option (OPTNEWSCACHE))
828 nntp_cache_expand (file, news->cache);
830 f = safe_fopen (file, "w");
833 m_strcpy(buf, sizeof(buf), news->conn->account.host);
834 f = mutt_mkname (buf);
835 news->cache = m_strdup(buf);
836 nntp_cache_expand (file, buf);
841 for (l = news->list; l; l = l->next) {
842 if ((d = (NNTP_DATA *) l->data) && !d->deleted) {
844 snprintf (buf, sizeof (buf), "%s %d %d %c %s\n", d->group,
845 d->lastMessage, d->firstMessage, d->allowed ? 'y' : 'n',
848 snprintf (buf, sizeof (buf), "%s %d %d %c\n", d->group,
849 d->lastMessage, d->firstMessage, d->allowed ? 'y' : 'n');
850 if (fputs (buf, f) == EOF) {
859 if (nntp_update_cacheindex (news, NULL)) {
866 int nntp_save_cache_group (CONTEXT * ctx)
868 char buf[HUGE_STRING], addr[STRING];
869 char file[_POSIX_PATH_MAX];
873 int i = 0, save = SORT_ORDER;
876 if (!option (OPTNEWSCACHE))
878 if (!ctx || !ctx->data || ctx->magic != M_NNTP)
881 if (((NNTP_DATA *) ctx->data)->cache) {
882 nntp_cache_expand (file, ((NNTP_DATA *) ctx->data)->cache);
884 f = safe_fopen (file, "w");
887 snprintf (buf, sizeof (buf), "%s-%s",
888 ((NNTP_DATA *) ctx->data)->nserv->conn->account.host,
889 ((NNTP_DATA *) ctx->data)->group);
890 f = mutt_mkname (buf);
891 ((NNTP_DATA *) ctx->data)->cache = m_strdup(buf);
892 nntp_cache_expand (file, buf);
897 if (Sort != SORT_ORDER) {
900 mutt_sort_headers (ctx, 0);
903 /* Save only $nntp_context messages... */
904 ((NNTP_DATA *) ctx->data)->lastCached = 0;
905 if (NntpContext && ctx->msgcount > NntpContext)
906 i = ctx->msgcount - NntpContext;
907 for (; i < ctx->msgcount; i++) {
908 if (!ctx->hdrs[i]->deleted && ctx->hdrs[i]->article_num != prev) {
911 rfc822_write_address (addr, sizeof (addr), h->env->from, 0);
912 tm = gmtime (&h->date_sent);
913 snprintf (buf, sizeof (buf),
914 "%d\t%s\t%s\t%d %s %d %02d:%02d:%02d GMT\t%s\t",
915 h->article_num, h->env->subject, addr, tm->tm_mday,
916 Months[tm->tm_mon], tm->tm_year + 1900, tm->tm_hour,
917 tm->tm_min, tm->tm_sec, h->env->message_id);
919 if (h->env->references)
920 mutt_write_references (h->env->references, f);
921 snprintf (buf, sizeof (buf), "\t%zd\t%d\tXref: %s\n",
922 h->content->length, h->lines, NONULL (h->env->xref));
923 if (fputs (buf, f) == EOF) {
929 prev = ctx->hdrs[i]->article_num;
934 mutt_sort_headers (ctx, 0);
938 if (nntp_update_cacheindex (((NNTP_DATA *) ctx->data)->nserv,
939 (NNTP_DATA *) ctx->data)) {
943 ((NNTP_DATA *) ctx->data)->lastCached =
944 ((NNTP_DATA *) ctx->data)->lastLoaded;
948 void nntp_delete_cache (NNTP_DATA * data)
950 char buf[_POSIX_PATH_MAX];
952 if (!option (OPTNEWSCACHE) || !data || !data->cache || !data->nserv)
955 nntp_cache_expand (buf, data->cache);
957 p_delete(&data->cache);
958 data->lastCached = 0;
959 nntp_cache_expand (buf, ".index");
960 mutt_update_list_file (buf, data->nserv->conn->account.host, data->group,
964 NNTP_DATA *mutt_newsgroup_subscribe (NNTP_SERVER * news, char *group)
968 if (!news || !news->newsgroups || !group || !*group)
970 if (!(data = (NNTP_DATA *) hash_find (news->newsgroups, group))) {
971 data = xmalloc(sizeof(NNTP_DATA) + m_strlen(group) + 1);
972 data->group = (char *) data + sizeof (NNTP_DATA);
973 strcpy (data->group, group);
976 if (news->newsgroups->nelem < news->newsgroups->curnelem * 2)
978 hash_resize (news->newsgroups, news->newsgroups->nelem * 2);
979 hash_insert (news->newsgroups, data->group, data, 0);
980 nntp_add_to_list (news, data);
982 if (!data->subscribed) {
983 data->subscribed = 1;
989 NNTP_DATA *mutt_newsgroup_unsubscribe (NNTP_SERVER * news, char *group)
993 if (!news || !news->newsgroups || !group || !*group ||
994 !(data = (NNTP_DATA *) hash_find (news->newsgroups, group)))
996 if (data->subscribed) {
997 data->subscribed = 0;
998 if (!option (OPTSAVEUNSUB))
1004 NNTP_DATA *mutt_newsgroup_catchup (NNTP_SERVER * news, char *group)
1008 if (!news || !news->newsgroups || !group || !*group ||
1009 !(data = (NNTP_DATA *) hash_find (news->newsgroups, group)))
1012 data->entries = p_new(NEWSRC_ENTRY, 5);
1016 data->entries[0].first = 1;
1018 data->entries[0].last = data->lastMessage;
1019 if (Context && Context->data == data) {
1022 for (x = 0; x < Context->msgcount; x++)
1023 mutt_set_flag (Context, Context->hdrs[x], M_READ, 1);
1028 NNTP_DATA *mutt_newsgroup_uncatchup (NNTP_SERVER * news, char *group)
1032 if (!news || !news->newsgroups || !group || !*group ||
1033 !(data = (NNTP_DATA *) hash_find (news->newsgroups, group)))
1036 data->entries = p_new(NEWSRC_ENTRY, 5);
1040 data->entries[0].first = 1;
1041 data->entries[0].last = data->firstMessage - 1;
1042 if (Context && Context->data == data) {
1045 data->unread = Context->msgcount;
1046 for (x = 0; x < Context->msgcount; x++)
1047 mutt_set_flag (Context, Context->hdrs[x], M_READ, 0);
1050 data->unread = data->lastMessage - data->entries[0].last;
1054 /* this routine gives the first newsgroup with new messages */
1055 void nntp_buffy (char* dst, ssize_t dstlen) {
1056 string_list_t *list;
1059 /* forward to current group */
1060 for (list = CurrentNewsSrv->list; list; list = list->next) {
1061 NNTP_DATA *data = (NNTP_DATA *) list->data;
1062 if (data && data->subscribed && data->unread &&
1063 Context && Context->magic == M_NNTP &&
1064 m_strcmp(data->group, ((NNTP_DATA *) Context->data)->group) == 0) {
1075 list = CurrentNewsSrv->list;
1077 for (; list; list = list->next) {
1078 NNTP_DATA *data = (NNTP_DATA *) list->data;
1080 if (data && data->subscribed && data->unread) {
1081 if (Context && Context->magic == M_NNTP &&
1082 !m_strcmp(data->group, ((NNTP_DATA *) Context->data)->group)) {
1083 unsigned int i, unread = 0;
1085 for (i = 0; i < Context->msgcount; i++)
1086 if (!Context->hdrs[i]->read && !Context->hdrs[i]->deleted)
1091 m_strcpy(dst, dstlen, data->group);