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.
23 #include <lib-lib/mem.h>
24 #include <lib-lib/str.h>
25 #include <lib-lib/file.h>
26 #include <lib-lib/macros.h>
28 #include <lib-mime/mime.h>
30 #include <lib-ui/curses.h>
37 void nntp_add_to_list (NNTP_SERVER * s, NNTP_DATA * d)
44 l = p_new(string_list_t, 1);
53 static int nntp_parse_newsrc_line (NNTP_SERVER * news, char *line)
56 char group[LONG_STRING];
58 char *p = line, *b, *h;
67 while (*p && (*p != ':' && *p != '!'))
72 if (len > sizeof (group))
74 m_strcpy(group, len, line);
75 if ((data = (NNTP_DATA *) hash_find (news->newsgroups, group)) == NULL) {
76 data = xmalloc(sizeof(NNTP_DATA) + m_strlen(group) + 1);
77 data->group = (char *) data + sizeof (NNTP_DATA);
78 strcpy (data->group, group);
81 if (news->newsgroups->nelem < news->newsgroups->curnelem * 2)
83 hash_resize (news->newsgroups, news->newsgroups->nelem * 2);
84 hash_insert (news->newsgroups, data->group, data, 0);
85 nntp_add_to_list (news, data);
88 p_delete(&data->entries);
91 data->entries = p_new(NEWSRC_ENTRY, x * 2);
103 while (*p && *p != ',' && *p != '\n')
109 if ((h = strchr (b, '-'))) {
112 data->entries[x].first = atoi (b);
113 data->entries[x].last = atoi (h);
116 data->entries[x].first = atoi (b);
117 data->entries[x].last = data->entries[x].first;
120 if (data->entries[x].last != 0)
123 if (x && !data->lastMessage)
124 data->lastMessage = data->entries[x - 1].last;
126 mutt_newsgroup_stat (data);
131 static int slurp_newsrc (NNTP_SERVER * news)
137 news->stat = stat (news->newsrc, &sb);
138 news->size = sb.st_size;
139 news->mtime = sb.st_mtime;
141 if ((fp = safe_fopen (news->newsrc, "r")) == NULL)
143 /* hmm, should we use dotlock? */
144 if (mx_lock_file (news->newsrc, fileno (fp), 0, 0, 1)) {
149 buf = p_new(char, sb.st_size + 1);
150 while (fgets (buf, sb.st_size + 1, fp))
151 nntp_parse_newsrc_line (news, buf);
154 mx_unlock_file (news->newsrc, fileno (fp), 0);
159 void nntp_cache_expand (char *dst, const char *src)
161 snprintf (dst, _POSIX_PATH_MAX, "%s/%s", NewsCacheDir, src);
162 mutt_expand_path (dst, _POSIX_PATH_MAX);
165 /* Loads $news_cache_dir/.index into memory, loads newsserver data
166 * and newsgroup cache names */
167 static int nntp_parse_cacheindex (NNTP_SERVER * news)
170 char buf[HUGE_STRING], *cp;
171 char dir[_POSIX_PATH_MAX], file[_POSIX_PATH_MAX];
176 /* check is server name defined or not */
177 if (!news || !news->conn || !news->conn->account.host)
179 unset_option (OPTNEWSCACHE);
180 if (!NewsCacheDir || !*NewsCacheDir)
183 m_strcpy(dir, sizeof(dir), NewsCacheDir);
184 mutt_expand_path (dir, sizeof (dir));
186 if (lstat (dir, &st) || (st.st_mode & S_IFDIR) == 0) {
187 snprintf (buf, sizeof (buf), _("Directory %s not exist. Create it?"),
189 if (mutt_yesorno (buf, M_YES) != M_YES
190 || mkdir (dir, (S_IRWXU + S_IRWXG + S_IRWXO))) {
191 mutt_error _("Cache directory not created!");
198 set_option (OPTNEWSCACHE);
200 p_delete(&news->cache);
201 snprintf (buf, sizeof (buf), "%s/.index", dir);
202 if (!(idx = safe_fopen (buf, "a+")))
205 while (fgets (buf, sizeof (buf), idx)) {
206 buf[m_strlen(buf) - 1] = 0; /* strip ending '\n' */
207 if (!m_strncmp(buf, "#: ", 3) &&
208 !m_strcasecmp(buf + 3, news->conn->account.host))
211 while (fgets (buf, sizeof (buf), idx)) {
213 while (*cp && *cp != ' ')
218 if (!m_strcmp(buf, "#:"))
220 sscanf (cp + 1, "%s %d %d", file, &l, &m);
221 if (!m_strcmp(buf, "ALL")) {
222 news->cache = m_strdup(file);
223 news->newgroups_time = m;
225 else if (news->newsgroups) {
226 if ((data = (NNTP_DATA *) hash_find (news->newsgroups, buf)) == NULL) {
227 data = xmalloc(sizeof(NNTP_DATA) + m_strlen(buf) + 1);
228 data->group = (char *) data + sizeof (NNTP_DATA);
229 strcpy (data->group, buf);
232 if (news->newsgroups->nelem < news->newsgroups->curnelem * 2)
234 hash_resize (news->newsgroups, news->newsgroups->nelem * 2);
235 hash_insert (news->newsgroups, data->group, data, 0);
236 nntp_add_to_list (news, data);
238 data->cache = m_strdup(file);
240 if (!data->firstMessage || data->lastMessage < m)
242 if (!data->firstMessage)
243 data->firstMessage = l;
244 if (data->lastMessage < m)
245 data->lastMessage = m;
246 data->lastCached = m;
247 if (t || !data->unread)
248 mutt_newsgroup_stat (data);
255 const char *nntp_format_str (char *dest, ssize_t destlen, char op,
256 const char *src, const char *fmt,
257 const char *ifstring, const char *elsestring,
258 unsigned long data, format_flag flags)
260 char fn[SHORT_STRING], tmp[SHORT_STRING];
264 m_strcpy(fn, sizeof (fn), NewsServer);
266 snprintf (tmp, sizeof (tmp), "%%%ss", fmt);
267 snprintf (dest, destlen, tmp, fn);
273 /* nntp_parse_url: given an NNPT URL, return host, port,
274 * username, password and newsgroup will recognise. */
275 int nntp_parse_url (const char *server, ACCOUNT * act,
276 char *group, ssize_t group_len)
284 act->port = NNTP_PORT;
285 act->type = M_ACCT_TYPE_NNTP;
287 c = m_strdup(server);
288 url_parse_ciss (&url, c);
290 if (url.scheme == U_NNTP || url.scheme == U_NNTPS) {
291 if (url.scheme == U_NNTPS) {
292 act->flags |= M_ACCT_SSL;
293 act->port = NNTP_SSL_PORT;
298 m_strcpy(group, group_len, url.path);
300 ret = mutt_account_fromurl (act, &url);
307 void nntp_expand_path (char *line, ssize_t len, ACCOUNT * act)
311 url.path = m_strdup(line);
312 mutt_account_tourl (act, &url);
313 url_ciss_tostring (&url, line, len, 0);
318 * Automatically loads a newsrc into memory, if necessary.
319 * Checks the size/mtime of a newsrc file, if it doesn't match, load
320 * again. Hmm, if a system has broken mtimes, this might mean the file
321 * is reloaded every time, which we'd have to fix.
323 * a newsrc file is a line per newsgroup, with the newsgroup, then a
324 * ':' denoting subscribed or '!' denoting unsubscribed, then a
325 * comma separated list of article numbers and ranges.
327 NNTP_SERVER *mutt_select_newsserver (char *server)
329 char file[_POSIX_PATH_MAX];
338 if (!server || !*server) {
339 mutt_error _("No newsserver defined!");
344 buf = p = p_new(char, m_strlen(server) + 10);
345 if (url_check_scheme (server) == U_UNKNOWN) {
346 strcpy (buf, "nntp://");
347 p = strchr (buf, '\0');
351 if ((nntp_parse_url (buf, &act, file, sizeof (file))) < 0 || *file) {
353 mutt_error (_("%s is an invalid newsserver specification!"), server);
358 conn = mutt_conn_find (NULL, &act);
362 mutt_FormatString (file, sizeof (file), NONULL (NewsRc), nntp_format_str, 0,
364 mutt_expand_path (file, sizeof (file));
366 serv = (NNTP_SERVER *) conn->data;
370 /* externally modified? */
371 if (serv->stat != stat (file, &sb) || (!serv->stat &&
372 (serv->size != sb.st_size
373 || serv->mtime != sb.st_mtime))) {
374 for (list = serv->list; list; list = list->next) {
375 NNTP_DATA *data = (NNTP_DATA *) list->data;
378 data->subscribed = 0;
384 nntp_clear_cacheindex (serv);
387 if (serv->status == NNTP_BYE)
388 serv->status = NNTP_NONE;
389 nntp_check_newgroups (serv, 0);
394 serv = p_new(NNTP_SERVER, 1);
396 serv->newsrc = m_strdup(file);
397 serv->newsgroups = hash_create (1009);
398 slurp_newsrc (serv); /* load .newsrc */
399 nntp_parse_cacheindex (serv); /* load .index */
400 if (option (OPTNEWSCACHE) && serv->cache && nntp_get_cache_all (serv) >= 0)
401 nntp_check_newgroups (serv, 1);
402 else if (nntp_get_active (serv) < 0) {
403 hash_destroy (&serv->newsgroups, nntp_delete_data);
404 for (list = serv->list; list; list = list->next)
406 string_list_wipe(&serv->list);
407 p_delete(&serv->newsrc);
408 p_delete(&serv->cache);
412 nntp_clear_cacheindex (serv);
413 conn->data = (void *) serv;
419 * full status flags are not supported by nntp, but we can fake some
420 * of them. This is how:
421 * Read = a read message number is in the .newsrc
422 * New = a message is new since we last read this newsgroup
423 * Old = anything else
424 * So, Read is marked as such in the newsrc, old is anything that is
425 * "skipped" in the newsrc, and new is anything not in the newsrc nor
426 * in the cache. By skipped, I mean before the last unread message
428 void nntp_get_status (CONTEXT * ctx, HEADER * h, char *group, int article)
430 NNTP_DATA *data = (NNTP_DATA *) ctx->data;
434 data = (NNTP_DATA *) hash_find (data->nserv->newsgroups, group);
440 for (x = 0; x < data->num; x++) {
441 if ((article >= data->entries[x].first) &&
442 (article <= data->entries[x].last)) {
443 /* we cannot use mutt_set_flag() because mx_update_context()
449 /* If article was not cached yet, it is new! :) */
450 if (!data->cache || article > data->lastCached)
452 /* Old articles are articles which aren't read but an article after them
454 if (option (OPTMARKOLD))
458 void mutt_newsgroup_stat (NNTP_DATA * data)
461 unsigned int first, last;
464 if (data->lastMessage == 0 || data->firstMessage > data->lastMessage)
467 data->unread = data->lastMessage - data->firstMessage + 1;
468 for (i = 0; i < data->num; i++) {
469 first = data->entries[i].first;
470 if (first < data->firstMessage)
471 first = data->firstMessage;
472 last = data->entries[i].last;
473 if (last > data->lastMessage)
474 last = data->lastMessage;
476 data->unread -= last - first + 1;
480 static int puti (char *line, int num)
485 *p++ = '0' + num % 10;
489 *line++ = *--p, num++;
494 static void nntp_create_newsrc_line (NNTP_DATA * data, char **buf,
495 char **pline, ssize_t * buflen)
498 ssize_t len = *buflen - (*pline - *buf);
501 if (len < LONG_STRING * 10) {
505 p_realloc(buf, *buflen);
506 line = *buf + (*pline - line);
508 strcpy (line, data->group);
509 len -= m_strlen(line) + 1;
510 line += m_strlen(line);
511 *line++ = data->subscribed ? ':' : '!';
515 for (x = 0; x < data->num; x++) {
516 if (len < LONG_STRING) {
521 p_realloc(buf, *buflen);
522 line = *buf + (*pline - line);
530 if (data->entries[x].first == data->entries[x].last)
531 snprintf (line, len, "%d%n", data->entries[x].first, &i);
533 snprintf (line, len, "%d-%d%n",
534 data->entries[x].first, data->entries[x].last, &i);
538 i = puti (line, data->entries[x].first);
541 if (data->entries[x].first != data->entries[x].last) {
544 i = puti (line, data->entries[x].last);
555 void newsrc_gen_entries (CONTEXT * ctx)
557 NNTP_DATA *data = (NNTP_DATA *) ctx->data;
559 unsigned int last = 0, first = 1;
560 int save_sort = SORT_ORDER;
562 if (Sort != SORT_ORDER) {
565 mutt_sort_headers (ctx, 0);
569 data->entries = p_new(NEWSRC_ENTRY, 5);
574 * Set up to fake initial sequence from 1 to the article before the
575 * first article in our list
580 for (x = 0; x < ctx->msgcount; x++) {
581 if (series) { /* search for first unread */
583 * We don't actually check sequential order, since we mark
584 * "missing" entries as read/deleted
586 last = ctx->hdrs[x]->article_num;
587 if (last >= data->firstMessage && !ctx->hdrs[x]->deleted &&
588 !ctx->hdrs[x]->read) {
589 if (data->num >= data->max) {
590 data->max = data->max * 2;
591 p_realloc(&data->entries, data->max);
593 data->entries[data->num].first = first;
594 data->entries[data->num].last = last - 1;
599 else { /* search for first read */
601 if (ctx->hdrs[x]->deleted || ctx->hdrs[x]->read) {
605 last = ctx->hdrs[x]->article_num;
608 if (series && first <= data->lastLoaded) {
609 if (data->num >= data->max) {
610 data->max = data->max * 2;
611 p_realloc(&data->entries, data->max);
613 data->entries[data->num].first = first;
614 data->entries[data->num].last = data->lastLoaded;
618 if (save_sort != Sort) {
620 mutt_sort_headers (ctx, 0);
624 static int mutt_update_list_file (char *filename, char *section,
625 const char *key, char *line) {
628 char buf[HUGE_STRING];
629 char tmpfile[_POSIX_PATH_MAX], link[_POSIX_PATH_MAX];
631 int ext = 0, done = 0, r = 0, l = 0;
633 /* if file not exist, create it */
634 if ((ifp = safe_fopen (filename, "a")))
636 if (!(ifp = safe_fopen (filename, "r"))) {
637 mutt_error (_("Unable to open %s for reading"), filename);
640 if (mx_lock_file (filename, fileno (ifp), 0, 0, 1)) {
642 mutt_error (_("Unable to lock %s"), filename);
645 /* use mutt_adv_mktemp() to get a tempfile in the same
646 * directory as filename is so that we can follow symlinks
647 * via rename(2); as dirname(2) may modify its argument,
648 * temporarily use buf as copy of it
650 m_strcpy(buf, sizeof(buf), filename);
651 m_strcpy(tmpfile, sizeof(tmpfile), basename(filename));
652 mutt_adv_mktemp ((const char*) dirname (buf), tmpfile, sizeof (tmpfile));
653 if (!(ofp = fopen (tmpfile, "w"))) {
655 mutt_error (_("Unable to open %s for writing"), tmpfile);
660 while (r != EOF && !done && fgets (buf, sizeof (buf), ifp)) {
661 r = fputs (buf, ofp);
663 while (*c && *c != '\n') c++;
664 c[0] = 0; /* strip EOL */
665 if (!strncmp (buf, "#: ", 3) && !m_strcasecmp(buf+3, section))
668 if (r != EOF && !done) {
669 snprintf (buf, sizeof(buf), "#: %s\n", section);
670 r = fputs (buf, ofp);
675 while (r != EOF && fgets (buf, sizeof (buf), ifp)) {
678 while (*c && (*c != '\r') && (*c != '\n')) c++;
680 if (*c != '\\') ext = 0;
681 } else if ((section && !strncmp (buf, "#: ", 3))) {
686 r = fputs (buf, ofp);
689 } else if (key && !strncmp (buf, key, strlen(key)) &&
690 (!*key || buf[strlen(key)] == ' ')) {
693 while (*c && (*c != '\r') && (*c != '\n')) c++;
695 if (*c == '\\') ext = 1;
697 r = fputs (line, ofp);
699 r = fputc ('\n', ofp);
703 r = fputs (buf, ofp);
707 while (r != EOF && fgets (buf, sizeof (buf), ifp))
708 r = fputs (buf, ofp);
710 /* If there wasn't a line to replace, put it on the end of the file */
711 if (r != EOF && !done && line) {
713 r = fputc ('\n', ofp);
715 mx_unlock_file (filename, fileno (ifp), 0);
720 mutt_error (_("Can't write %s"), tmpfile);
724 if ((l = readlink (filename, link, sizeof (link)-1)) > 0)
726 if (rename (tmpfile, l > 0 ? link : filename) < 0) {
728 mutt_error (_("Can't rename %s to %s"), tmpfile, l > 0 ? link : filename);
734 int mutt_newsrc_update (NNTP_SERVER * news)
744 llen = len = 10 * LONG_STRING;
745 line = buf = p_new(char, len);
746 /* we will generate full newsrc here */
747 for (tmp = news->list; tmp; tmp = tmp->next) {
748 data = (NNTP_DATA *) tmp->data;
749 if (!data || !data->rc)
751 nntp_create_newsrc_line (data, &buf, &line, &llen);
752 line += m_strlen(line);
754 /* newrc being fully rewritten */
756 (r = mutt_update_list_file(news->newsrc, NULL, "", buf)) == 0) {
759 stat (news->newsrc, &st);
760 news->size = st.st_size;
761 news->mtime = st.st_mtime;
767 static FILE *mutt_mkname (char *s)
769 char buf[_POSIX_PATH_MAX], *pc;
773 nntp_cache_expand (buf, s);
774 if ((fp = safe_fopen (buf, "w")))
777 nntp_cache_expand (buf, "cache-XXXXXX");
778 pc = buf + m_strlen(buf) - 12; /* positioning to "cache-XXXXXX" */
779 if ((fd = mkstemp (buf)) == -1)
781 strcpy (s, pc); /* generated name */
782 return fdopen (fd, "w");
785 /* Updates info into .index file: ALL or about selected newsgroup */
786 static int nntp_update_cacheindex (NNTP_SERVER * serv, NNTP_DATA * data)
788 char buf[LONG_STRING];
789 char file[_POSIX_PATH_MAX];
790 const char *key = "ALL";
792 if (!serv || !serv->conn || !serv->conn->account.host)
795 if (data && data->group) {
797 snprintf (buf, sizeof (buf), "%s %s %d %d", key, data->cache,
798 data->firstMessage, data->lastLoaded);
801 m_strcpy(file, sizeof(file), serv->cache);
802 snprintf (buf, sizeof (buf), "ALL %s 0 %d", file,
803 (int) serv->newgroups_time);
805 nntp_cache_expand (file, ".index");
806 return mutt_update_list_file (file, serv->conn->account.host, key, buf);
809 /* Remove cache files of unsubscribed newsgroups */
810 void nntp_clear_cacheindex (NNTP_SERVER * news)
815 if (option (OPTSAVEUNSUB) || !news)
818 for (tmp = news->list; tmp; tmp = tmp->next) {
819 data = (NNTP_DATA *) tmp->data;
820 if (!data || data->subscribed || !data->cache)
822 nntp_delete_cache (data);
827 int nntp_save_cache_index (NNTP_SERVER * news)
829 char buf[HUGE_STRING];
830 char file[_POSIX_PATH_MAX];
835 if (!news || !news->newsgroups)
837 if (!option (OPTNEWSCACHE))
841 nntp_cache_expand (file, news->cache);
843 f = safe_fopen (file, "w");
846 m_strcpy(buf, sizeof(buf), news->conn->account.host);
847 f = mutt_mkname (buf);
848 news->cache = m_strdup(buf);
849 nntp_cache_expand (file, buf);
854 for (l = news->list; l; l = l->next) {
855 if ((d = (NNTP_DATA *) l->data) && !d->deleted) {
857 snprintf (buf, sizeof (buf), "%s %d %d %c %s\n", d->group,
858 d->lastMessage, d->firstMessage, d->allowed ? 'y' : 'n',
861 snprintf (buf, sizeof (buf), "%s %d %d %c\n", d->group,
862 d->lastMessage, d->firstMessage, d->allowed ? 'y' : 'n');
863 if (fputs (buf, f) == EOF) {
872 if (nntp_update_cacheindex (news, NULL)) {
879 int nntp_save_cache_group (CONTEXT * ctx)
881 char buf[HUGE_STRING], addr[STRING];
882 char file[_POSIX_PATH_MAX];
886 int i = 0, save = SORT_ORDER;
889 if (!option (OPTNEWSCACHE))
891 if (!ctx || !ctx->data || ctx->magic != M_NNTP)
894 if (((NNTP_DATA *) ctx->data)->cache) {
895 nntp_cache_expand (file, ((NNTP_DATA *) ctx->data)->cache);
897 f = safe_fopen (file, "w");
900 snprintf (buf, sizeof (buf), "%s-%s",
901 ((NNTP_DATA *) ctx->data)->nserv->conn->account.host,
902 ((NNTP_DATA *) ctx->data)->group);
903 f = mutt_mkname (buf);
904 ((NNTP_DATA *) ctx->data)->cache = m_strdup(buf);
905 nntp_cache_expand (file, buf);
910 if (Sort != SORT_ORDER) {
913 mutt_sort_headers (ctx, 0);
916 /* Save only $nntp_context messages... */
917 ((NNTP_DATA *) ctx->data)->lastCached = 0;
918 if (NntpContext && ctx->msgcount > NntpContext)
919 i = ctx->msgcount - NntpContext;
920 for (; i < ctx->msgcount; i++) {
921 if (!ctx->hdrs[i]->deleted && ctx->hdrs[i]->article_num != prev) {
924 rfc822_write_address (addr, sizeof (addr), h->env->from, 0);
925 tm = gmtime (&h->date_sent);
926 snprintf (buf, sizeof (buf),
927 "%d\t%s\t%s\t%d %s %d %02d:%02d:%02d GMT\t%s\t",
928 h->article_num, h->env->subject, addr, tm->tm_mday,
929 Months[tm->tm_mon], tm->tm_year + 1900, tm->tm_hour,
930 tm->tm_min, tm->tm_sec, h->env->message_id);
932 if (h->env->references)
933 mutt_write_references (h->env->references, f);
934 snprintf (buf, sizeof (buf), "\t%zd\t%d\tXref: %s\n",
935 h->content->length, h->lines, NONULL (h->env->xref));
936 if (fputs (buf, f) == EOF) {
942 prev = ctx->hdrs[i]->article_num;
947 mutt_sort_headers (ctx, 0);
951 if (nntp_update_cacheindex (((NNTP_DATA *) ctx->data)->nserv,
952 (NNTP_DATA *) ctx->data)) {
956 ((NNTP_DATA *) ctx->data)->lastCached =
957 ((NNTP_DATA *) ctx->data)->lastLoaded;
961 void nntp_delete_cache (NNTP_DATA * data)
963 char buf[_POSIX_PATH_MAX];
965 if (!option (OPTNEWSCACHE) || !data || !data->cache || !data->nserv)
968 nntp_cache_expand (buf, data->cache);
970 p_delete(&data->cache);
971 data->lastCached = 0;
972 nntp_cache_expand (buf, ".index");
973 mutt_update_list_file (buf, data->nserv->conn->account.host, data->group,
977 NNTP_DATA *mutt_newsgroup_subscribe (NNTP_SERVER * news, char *group)
981 if (!news || !news->newsgroups || !group || !*group)
983 if (!(data = (NNTP_DATA *) hash_find (news->newsgroups, group))) {
984 data = xmalloc(sizeof(NNTP_DATA) + m_strlen(group) + 1);
985 data->group = (char *) data + sizeof (NNTP_DATA);
986 strcpy (data->group, group);
989 if (news->newsgroups->nelem < news->newsgroups->curnelem * 2)
991 hash_resize (news->newsgroups, news->newsgroups->nelem * 2);
992 hash_insert (news->newsgroups, data->group, data, 0);
993 nntp_add_to_list (news, data);
995 if (!data->subscribed) {
996 data->subscribed = 1;
1002 NNTP_DATA *mutt_newsgroup_unsubscribe (NNTP_SERVER * news, char *group)
1006 if (!news || !news->newsgroups || !group || !*group ||
1007 !(data = (NNTP_DATA *) hash_find (news->newsgroups, group)))
1009 if (data->subscribed) {
1010 data->subscribed = 0;
1011 if (!option (OPTSAVEUNSUB))
1017 NNTP_DATA *mutt_newsgroup_catchup (NNTP_SERVER * news, char *group)
1021 if (!news || !news->newsgroups || !group || !*group ||
1022 !(data = (NNTP_DATA *) hash_find (news->newsgroups, group)))
1025 data->entries = p_new(NEWSRC_ENTRY, 5);
1029 data->entries[0].first = 1;
1031 data->entries[0].last = data->lastMessage;
1032 if (Context && Context->data == data) {
1035 for (x = 0; x < Context->msgcount; x++)
1036 mutt_set_flag (Context, Context->hdrs[x], M_READ, 1);
1041 NNTP_DATA *mutt_newsgroup_uncatchup (NNTP_SERVER * news, char *group)
1045 if (!news || !news->newsgroups || !group || !*group ||
1046 !(data = (NNTP_DATA *) hash_find (news->newsgroups, group)))
1049 data->entries = p_new(NEWSRC_ENTRY, 5);
1053 data->entries[0].first = 1;
1054 data->entries[0].last = data->firstMessage - 1;
1055 if (Context && Context->data == data) {
1058 data->unread = Context->msgcount;
1059 for (x = 0; x < Context->msgcount; x++)
1060 mutt_set_flag (Context, Context->hdrs[x], M_READ, 0);
1063 data->unread = data->lastMessage - data->entries[0].last;
1067 /* this routine gives the first newsgroup with new messages */
1068 void nntp_buffy (char* dst, ssize_t dstlen) {
1069 string_list_t *list;
1072 /* forward to current group */
1073 for (list = CurrentNewsSrv->list; list; list = list->next) {
1074 NNTP_DATA *data = (NNTP_DATA *) list->data;
1075 if (data && data->subscribed && data->unread &&
1076 Context && Context->magic == M_NNTP &&
1077 m_strcmp(data->group, ((NNTP_DATA *) Context->data)->group) == 0) {
1088 list = CurrentNewsSrv->list;
1090 for (; list; list = list->next) {
1091 NNTP_DATA *data = (NNTP_DATA *) list->data;
1093 if (data && data->subscribed && data->unread) {
1094 if (Context && Context->magic == M_NNTP &&
1095 !m_strcmp(data->group, ((NNTP_DATA *) Context->data)->group)) {
1096 unsigned int i, unread = 0;
1098 for (i = 0; i < Context->msgcount; i++)
1099 if (!Context->hdrs[i]->read && !Context->hdrs[i]->deleted)
1104 m_strcpy(dst, dstlen, data->group);