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>
38 void nntp_add_to_list (NNTP_SERVER * s, NNTP_DATA * d)
45 l = p_new(string_list_t, 1);
54 static int nntp_parse_newsrc_line (NNTP_SERVER * news, char *line)
57 char group[LONG_STRING];
59 char *p = line, *b, *h;
68 while (*p && (*p != ':' && *p != '!'))
73 if (len > sizeof (group))
75 m_strcpy(group, len, line);
76 if ((data = (NNTP_DATA *) hash_find (news->newsgroups, group)) == NULL) {
77 data = xmalloc(sizeof(NNTP_DATA) + m_strlen(group) + 1);
78 data->group = (char *) data + sizeof (NNTP_DATA);
79 strcpy (data->group, group);
82 if (news->newsgroups->nelem < news->newsgroups->curnelem * 2)
84 hash_resize (news->newsgroups, news->newsgroups->nelem * 2);
85 hash_insert (news->newsgroups, data->group, data, 0);
86 nntp_add_to_list (news, data);
89 p_delete(&data->entries);
92 data->entries = p_new(NEWSRC_ENTRY, x * 2);
104 while (*p && *p != ',' && *p != '\n')
110 if ((h = strchr (b, '-'))) {
113 data->entries[x].first = atoi (b);
114 data->entries[x].last = atoi (h);
117 data->entries[x].first = atoi (b);
118 data->entries[x].last = data->entries[x].first;
121 if (data->entries[x].last != 0)
124 if (x && !data->lastMessage)
125 data->lastMessage = data->entries[x - 1].last;
127 mutt_newsgroup_stat (data);
132 static int slurp_newsrc (NNTP_SERVER * news)
138 news->stat = stat (news->newsrc, &sb);
139 news->size = sb.st_size;
140 news->mtime = sb.st_mtime;
142 if ((fp = safe_fopen (news->newsrc, "r")) == NULL)
144 /* hmm, should we use dotlock? */
145 if (mx_lock_file (news->newsrc, fileno (fp), 0, 0, 1)) {
150 buf = p_new(char, sb.st_size + 1);
151 while (fgets (buf, sb.st_size + 1, fp))
152 nntp_parse_newsrc_line (news, buf);
155 mx_unlock_file (news->newsrc, fileno (fp), 0);
160 void nntp_cache_expand (char *dst, const char *src)
162 snprintf (dst, _POSIX_PATH_MAX, "%s/%s", NewsCacheDir, src);
163 mutt_expand_path (dst, _POSIX_PATH_MAX);
166 /* Loads $news_cache_dir/.index into memory, loads newsserver data
167 * and newsgroup cache names */
168 static int nntp_parse_cacheindex (NNTP_SERVER * news)
171 char buf[HUGE_STRING], *cp;
172 char dir[_POSIX_PATH_MAX], file[_POSIX_PATH_MAX];
177 /* check is server name defined or not */
178 if (!news || !news->conn || !news->conn->account.host)
180 unset_option (OPTNEWSCACHE);
181 if (!NewsCacheDir || !*NewsCacheDir)
184 m_strcpy(dir, sizeof(dir), NewsCacheDir);
185 mutt_expand_path (dir, sizeof (dir));
187 if (lstat (dir, &st) || (st.st_mode & S_IFDIR) == 0) {
188 snprintf (buf, sizeof (buf), _("Directory %s not exist. Create it?"),
190 if (mutt_yesorno (buf, M_YES) != M_YES
191 || mkdir (dir, (S_IRWXU + S_IRWXG + S_IRWXO))) {
192 mutt_error _("Cache directory not created!");
199 set_option (OPTNEWSCACHE);
201 p_delete(&news->cache);
202 snprintf (buf, sizeof (buf), "%s/.index", dir);
203 if (!(idx = safe_fopen (buf, "a+")))
206 while (fgets (buf, sizeof (buf), idx)) {
207 buf[m_strlen(buf) - 1] = 0; /* strip ending '\n' */
208 if (!m_strncmp(buf, "#: ", 3) &&
209 !m_strcasecmp(buf + 3, news->conn->account.host))
212 while (fgets (buf, sizeof (buf), idx)) {
214 while (*cp && *cp != ' ')
219 if (!m_strcmp(buf, "#:"))
221 sscanf (cp + 1, "%s %d %d", file, &l, &m);
222 if (!m_strcmp(buf, "ALL")) {
223 news->cache = m_strdup(file);
224 news->newgroups_time = m;
226 else if (news->newsgroups) {
227 if ((data = (NNTP_DATA *) hash_find (news->newsgroups, buf)) == NULL) {
228 data = xmalloc(sizeof(NNTP_DATA) + m_strlen(buf) + 1);
229 data->group = (char *) data + sizeof (NNTP_DATA);
230 strcpy (data->group, buf);
233 if (news->newsgroups->nelem < news->newsgroups->curnelem * 2)
235 hash_resize (news->newsgroups, news->newsgroups->nelem * 2);
236 hash_insert (news->newsgroups, data->group, data, 0);
237 nntp_add_to_list (news, data);
239 data->cache = m_strdup(file);
241 if (!data->firstMessage || data->lastMessage < m)
243 if (!data->firstMessage)
244 data->firstMessage = l;
245 if (data->lastMessage < m)
246 data->lastMessage = m;
247 data->lastCached = m;
248 if (t || !data->unread)
249 mutt_newsgroup_stat (data);
256 const char *nntp_format_str (char *dest, ssize_t destlen, char op,
257 const char *src, const char *fmt,
258 const char *ifstring, const char *elsestring,
259 unsigned long data, format_flag flags)
261 char fn[SHORT_STRING], tmp[SHORT_STRING];
265 m_strcpy(fn, sizeof (fn), NewsServer);
267 snprintf (tmp, sizeof (tmp), "%%%ss", fmt);
268 snprintf (dest, destlen, tmp, fn);
274 /* nntp_parse_url: given an NNPT URL, return host, port,
275 * username, password and newsgroup will recognise. */
276 int nntp_parse_url (const char *server, ACCOUNT * act,
277 char *group, ssize_t group_len)
285 act->port = NNTP_PORT;
286 act->type = M_ACCT_TYPE_NNTP;
288 c = m_strdup(server);
289 url_parse_ciss (&url, c);
291 if (url.scheme == U_NNTP || url.scheme == U_NNTPS) {
292 if (url.scheme == U_NNTPS) {
293 act->flags |= M_ACCT_SSL;
294 act->port = NNTP_SSL_PORT;
299 m_strcpy(group, group_len, url.path);
301 ret = mutt_account_fromurl (act, &url);
308 void nntp_expand_path (char *line, ssize_t len, ACCOUNT * act)
312 url.path = m_strdup(line);
313 mutt_account_tourl (act, &url);
314 url_ciss_tostring (&url, line, len, 0);
319 * Automatically loads a newsrc into memory, if necessary.
320 * Checks the size/mtime of a newsrc file, if it doesn't match, load
321 * again. Hmm, if a system has broken mtimes, this might mean the file
322 * is reloaded every time, which we'd have to fix.
324 * a newsrc file is a line per newsgroup, with the newsgroup, then a
325 * ':' denoting subscribed or '!' denoting unsubscribed, then a
326 * comma separated list of article numbers and ranges.
328 NNTP_SERVER *mutt_select_newsserver (char *server)
330 char file[_POSIX_PATH_MAX];
339 if (!server || !*server) {
340 mutt_error _("No newsserver defined!");
345 buf = p = p_new(char, m_strlen(server) + 10);
346 if (url_check_scheme (server) == U_UNKNOWN) {
347 strcpy (buf, "nntp://");
348 p = strchr (buf, '\0');
352 if ((nntp_parse_url (buf, &act, file, sizeof (file))) < 0 || *file) {
354 mutt_error (_("%s is an invalid newsserver specification!"), server);
359 conn = mutt_conn_find (NULL, &act);
363 mutt_FormatString (file, sizeof (file), NONULL (NewsRc), nntp_format_str, 0,
365 mutt_expand_path (file, sizeof (file));
367 serv = (NNTP_SERVER *) conn->data;
371 /* externally modified? */
372 if (serv->stat != stat (file, &sb) || (!serv->stat &&
373 (serv->size != sb.st_size
374 || serv->mtime != sb.st_mtime))) {
375 for (list = serv->list; list; list = list->next) {
376 NNTP_DATA *data = (NNTP_DATA *) list->data;
379 data->subscribed = 0;
385 nntp_clear_cacheindex (serv);
388 if (serv->status == NNTP_BYE)
389 serv->status = NNTP_NONE;
390 nntp_check_newgroups (serv, 0);
395 serv = p_new(NNTP_SERVER, 1);
397 serv->newsrc = m_strdup(file);
398 serv->newsgroups = hash_create (1009);
399 slurp_newsrc (serv); /* load .newsrc */
400 nntp_parse_cacheindex (serv); /* load .index */
401 if (option (OPTNEWSCACHE) && serv->cache && nntp_get_cache_all (serv) >= 0)
402 nntp_check_newgroups (serv, 1);
403 else if (nntp_get_active (serv) < 0) {
404 hash_destroy (&serv->newsgroups, nntp_delete_data);
405 for (list = serv->list; list; list = list->next)
407 string_list_wipe(&serv->list);
408 p_delete(&serv->newsrc);
409 p_delete(&serv->cache);
413 nntp_clear_cacheindex (serv);
414 conn->data = (void *) serv;
420 * full status flags are not supported by nntp, but we can fake some
421 * of them. This is how:
422 * Read = a read message number is in the .newsrc
423 * New = a message is new since we last read this newsgroup
424 * Old = anything else
425 * So, Read is marked as such in the newsrc, old is anything that is
426 * "skipped" in the newsrc, and new is anything not in the newsrc nor
427 * in the cache. By skipped, I mean before the last unread message
429 void nntp_get_status (CONTEXT * ctx, HEADER * h, char *group, int article)
431 NNTP_DATA *data = (NNTP_DATA *) ctx->data;
435 data = (NNTP_DATA *) hash_find (data->nserv->newsgroups, group);
441 for (x = 0; x < data->num; x++) {
442 if ((article >= data->entries[x].first) &&
443 (article <= data->entries[x].last)) {
444 /* we cannot use mutt_set_flag() because mx_update_context()
450 /* If article was not cached yet, it is new! :) */
451 if (!data->cache || article > data->lastCached)
453 /* Old articles are articles which aren't read but an article after them
455 if (option (OPTMARKOLD))
459 void mutt_newsgroup_stat (NNTP_DATA * data)
462 unsigned int first, last;
465 if (data->lastMessage == 0 || data->firstMessage > data->lastMessage)
468 data->unread = data->lastMessage - data->firstMessage + 1;
469 for (i = 0; i < data->num; i++) {
470 first = data->entries[i].first;
471 if (first < data->firstMessage)
472 first = data->firstMessage;
473 last = data->entries[i].last;
474 if (last > data->lastMessage)
475 last = data->lastMessage;
477 data->unread -= last - first + 1;
481 static int puti (char *line, int num)
486 *p++ = '0' + num % 10;
490 *line++ = *--p, num++;
495 static void nntp_create_newsrc_line (NNTP_DATA * data, char **buf,
496 char **pline, ssize_t * buflen)
499 ssize_t len = *buflen - (*pline - *buf);
502 if (len < LONG_STRING * 10) {
506 p_realloc(buf, *buflen);
507 line = *buf + (*pline - line);
509 strcpy (line, data->group);
510 len -= m_strlen(line) + 1;
511 line += m_strlen(line);
512 *line++ = data->subscribed ? ':' : '!';
516 for (x = 0; x < data->num; x++) {
517 if (len < LONG_STRING) {
522 p_realloc(buf, *buflen);
523 line = *buf + (*pline - line);
531 if (data->entries[x].first == data->entries[x].last)
532 snprintf (line, len, "%d%n", data->entries[x].first, &i);
534 snprintf (line, len, "%d-%d%n",
535 data->entries[x].first, data->entries[x].last, &i);
539 i = puti (line, data->entries[x].first);
542 if (data->entries[x].first != data->entries[x].last) {
545 i = puti (line, data->entries[x].last);
556 void newsrc_gen_entries (CONTEXT * ctx)
558 NNTP_DATA *data = (NNTP_DATA *) ctx->data;
560 unsigned int last = 0, first = 1;
561 int save_sort = SORT_ORDER;
563 if (Sort != SORT_ORDER) {
566 mutt_sort_headers (ctx, 0);
570 data->entries = p_new(NEWSRC_ENTRY, 5);
575 * Set up to fake initial sequence from 1 to the article before the
576 * first article in our list
581 for (x = 0; x < ctx->msgcount; x++) {
582 if (series) { /* search for first unread */
584 * We don't actually check sequential order, since we mark
585 * "missing" entries as read/deleted
587 last = ctx->hdrs[x]->article_num;
588 if (last >= data->firstMessage && !ctx->hdrs[x]->deleted &&
589 !ctx->hdrs[x]->read) {
590 if (data->num >= data->max) {
591 data->max = data->max * 2;
592 p_realloc(&data->entries, data->max);
594 data->entries[data->num].first = first;
595 data->entries[data->num].last = last - 1;
600 else { /* search for first read */
602 if (ctx->hdrs[x]->deleted || ctx->hdrs[x]->read) {
606 last = ctx->hdrs[x]->article_num;
609 if (series && first <= data->lastLoaded) {
610 if (data->num >= data->max) {
611 data->max = data->max * 2;
612 p_realloc(&data->entries, data->max);
614 data->entries[data->num].first = first;
615 data->entries[data->num].last = data->lastLoaded;
619 if (save_sort != Sort) {
621 mutt_sort_headers (ctx, 0);
625 static int mutt_update_list_file (char *filename, char *section,
626 const char *key, char *line) {
629 char buf[HUGE_STRING];
630 char tmpfile[_POSIX_PATH_MAX], link[_POSIX_PATH_MAX];
632 int ext = 0, done = 0, r = 0, l = 0;
634 /* if file not exist, create it */
635 if ((ifp = safe_fopen (filename, "a")))
637 if (!(ifp = safe_fopen (filename, "r"))) {
638 mutt_error (_("Unable to open %s for reading"), filename);
641 if (mx_lock_file (filename, fileno (ifp), 0, 0, 1)) {
643 mutt_error (_("Unable to lock %s"), filename);
646 /* use mutt_adv_mktemp() to get a tempfile in the same
647 * directory as filename is so that we can follow symlinks
648 * via rename(2); as dirname(2) may modify its argument,
649 * temporarily use buf as copy of it
651 m_strcpy(buf, sizeof(buf), filename);
652 m_strcpy(tmpfile, sizeof(tmpfile), basename(filename));
653 mutt_adv_mktemp ((const char*) dirname (buf), tmpfile, sizeof (tmpfile));
654 if (!(ofp = fopen (tmpfile, "w"))) {
656 mutt_error (_("Unable to open %s for writing"), tmpfile);
661 while (r != EOF && !done && fgets (buf, sizeof (buf), ifp)) {
662 r = fputs (buf, ofp);
664 while (*c && *c != '\n') c++;
665 c[0] = 0; /* strip EOL */
666 if (!strncmp (buf, "#: ", 3) && !m_strcasecmp(buf+3, section))
669 if (r != EOF && !done) {
670 snprintf (buf, sizeof(buf), "#: %s\n", section);
671 r = fputs (buf, ofp);
676 while (r != EOF && fgets (buf, sizeof (buf), ifp)) {
679 while (*c && (*c != '\r') && (*c != '\n')) c++;
681 if (*c != '\\') ext = 0;
682 } else if ((section && !strncmp (buf, "#: ", 3))) {
687 r = fputs (buf, ofp);
690 } else if (key && !strncmp (buf, key, strlen(key)) &&
691 (!*key || buf[strlen(key)] == ' ')) {
694 while (*c && (*c != '\r') && (*c != '\n')) c++;
696 if (*c == '\\') ext = 1;
698 r = fputs (line, ofp);
700 r = fputc ('\n', ofp);
704 r = fputs (buf, ofp);
708 while (r != EOF && fgets (buf, sizeof (buf), ifp))
709 r = fputs (buf, ofp);
711 /* If there wasn't a line to replace, put it on the end of the file */
712 if (r != EOF && !done && line) {
714 r = fputc ('\n', ofp);
716 mx_unlock_file (filename, fileno (ifp), 0);
721 mutt_error (_("Can't write %s"), tmpfile);
725 if ((l = readlink (filename, link, sizeof (link)-1)) > 0)
727 if (rename (tmpfile, l > 0 ? link : filename) < 0) {
729 mutt_error (_("Can't rename %s to %s"), tmpfile, l > 0 ? link : filename);
735 int mutt_newsrc_update (NNTP_SERVER * news)
745 llen = len = 10 * LONG_STRING;
746 line = buf = p_new(char, len);
747 /* we will generate full newsrc here */
748 for (tmp = news->list; tmp; tmp = tmp->next) {
749 data = (NNTP_DATA *) tmp->data;
750 if (!data || !data->rc)
752 nntp_create_newsrc_line (data, &buf, &line, &llen);
753 line += m_strlen(line);
755 /* newrc being fully rewritten */
757 (r = mutt_update_list_file(news->newsrc, NULL, "", buf)) == 0) {
760 stat (news->newsrc, &st);
761 news->size = st.st_size;
762 news->mtime = st.st_mtime;
768 static FILE *mutt_mkname (char *s)
770 char buf[_POSIX_PATH_MAX], *pc;
774 nntp_cache_expand (buf, s);
775 if ((fp = safe_fopen (buf, "w")))
778 nntp_cache_expand (buf, "cache-XXXXXX");
779 pc = buf + m_strlen(buf) - 12; /* positioning to "cache-XXXXXX" */
780 if ((fd = mkstemp (buf)) == -1)
782 strcpy (s, pc); /* generated name */
783 return fdopen (fd, "w");
786 /* Updates info into .index file: ALL or about selected newsgroup */
787 static int nntp_update_cacheindex (NNTP_SERVER * serv, NNTP_DATA * data)
789 char buf[LONG_STRING];
790 char file[_POSIX_PATH_MAX];
791 const char *key = "ALL";
793 if (!serv || !serv->conn || !serv->conn->account.host)
796 if (data && data->group) {
798 snprintf (buf, sizeof (buf), "%s %s %d %d", key, data->cache,
799 data->firstMessage, data->lastLoaded);
802 m_strcpy(file, sizeof(file), serv->cache);
803 snprintf (buf, sizeof (buf), "ALL %s 0 %d", file,
804 (int) serv->newgroups_time);
806 nntp_cache_expand (file, ".index");
807 return mutt_update_list_file (file, serv->conn->account.host, key, buf);
810 /* Remove cache files of unsubscribed newsgroups */
811 void nntp_clear_cacheindex (NNTP_SERVER * news)
816 if (option (OPTSAVEUNSUB) || !news)
819 for (tmp = news->list; tmp; tmp = tmp->next) {
820 data = (NNTP_DATA *) tmp->data;
821 if (!data || data->subscribed || !data->cache)
823 nntp_delete_cache (data);
828 int nntp_save_cache_index (NNTP_SERVER * news)
830 char buf[HUGE_STRING];
831 char file[_POSIX_PATH_MAX];
836 if (!news || !news->newsgroups)
838 if (!option (OPTNEWSCACHE))
842 nntp_cache_expand (file, news->cache);
844 f = safe_fopen (file, "w");
847 m_strcpy(buf, sizeof(buf), news->conn->account.host);
848 f = mutt_mkname (buf);
849 news->cache = m_strdup(buf);
850 nntp_cache_expand (file, buf);
855 for (l = news->list; l; l = l->next) {
856 if ((d = (NNTP_DATA *) l->data) && !d->deleted) {
858 snprintf (buf, sizeof (buf), "%s %d %d %c %s\n", d->group,
859 d->lastMessage, d->firstMessage, d->allowed ? 'y' : 'n',
862 snprintf (buf, sizeof (buf), "%s %d %d %c\n", d->group,
863 d->lastMessage, d->firstMessage, d->allowed ? 'y' : 'n');
864 if (fputs (buf, f) == EOF) {
873 if (nntp_update_cacheindex (news, NULL)) {
880 int nntp_save_cache_group (CONTEXT * ctx)
882 char buf[HUGE_STRING], addr[STRING];
883 char file[_POSIX_PATH_MAX];
887 int i = 0, save = SORT_ORDER;
890 if (!option (OPTNEWSCACHE))
892 if (!ctx || !ctx->data || ctx->magic != M_NNTP)
895 if (((NNTP_DATA *) ctx->data)->cache) {
896 nntp_cache_expand (file, ((NNTP_DATA *) ctx->data)->cache);
898 f = safe_fopen (file, "w");
901 snprintf (buf, sizeof (buf), "%s-%s",
902 ((NNTP_DATA *) ctx->data)->nserv->conn->account.host,
903 ((NNTP_DATA *) ctx->data)->group);
904 f = mutt_mkname (buf);
905 ((NNTP_DATA *) ctx->data)->cache = m_strdup(buf);
906 nntp_cache_expand (file, buf);
911 if (Sort != SORT_ORDER) {
914 mutt_sort_headers (ctx, 0);
917 /* Save only $nntp_context messages... */
918 ((NNTP_DATA *) ctx->data)->lastCached = 0;
919 if (NntpContext && ctx->msgcount > NntpContext)
920 i = ctx->msgcount - NntpContext;
921 for (; i < ctx->msgcount; i++) {
922 if (!ctx->hdrs[i]->deleted && ctx->hdrs[i]->article_num != prev) {
925 rfc822_write_address (addr, sizeof (addr), h->env->from, 0);
926 tm = gmtime (&h->date_sent);
927 snprintf (buf, sizeof (buf),
928 "%d\t%s\t%s\t%d %s %d %02d:%02d:%02d GMT\t%s\t",
929 h->article_num, h->env->subject, addr, tm->tm_mday,
930 Months[tm->tm_mon], tm->tm_year + 1900, tm->tm_hour,
931 tm->tm_min, tm->tm_sec, h->env->message_id);
933 if (h->env->references)
934 mutt_write_references (h->env->references, f);
935 snprintf (buf, sizeof (buf), "\t%zd\t%d\tXref: %s\n",
936 h->content->length, h->lines, NONULL (h->env->xref));
937 if (fputs (buf, f) == EOF) {
943 prev = ctx->hdrs[i]->article_num;
948 mutt_sort_headers (ctx, 0);
952 if (nntp_update_cacheindex (((NNTP_DATA *) ctx->data)->nserv,
953 (NNTP_DATA *) ctx->data)) {
957 ((NNTP_DATA *) ctx->data)->lastCached =
958 ((NNTP_DATA *) ctx->data)->lastLoaded;
962 void nntp_delete_cache (NNTP_DATA * data)
964 char buf[_POSIX_PATH_MAX];
966 if (!option (OPTNEWSCACHE) || !data || !data->cache || !data->nserv)
969 nntp_cache_expand (buf, data->cache);
971 p_delete(&data->cache);
972 data->lastCached = 0;
973 nntp_cache_expand (buf, ".index");
974 mutt_update_list_file (buf, data->nserv->conn->account.host, data->group,
978 NNTP_DATA *mutt_newsgroup_subscribe (NNTP_SERVER * news, char *group)
982 if (!news || !news->newsgroups || !group || !*group)
984 if (!(data = (NNTP_DATA *) hash_find (news->newsgroups, group))) {
985 data = xmalloc(sizeof(NNTP_DATA) + m_strlen(group) + 1);
986 data->group = (char *) data + sizeof (NNTP_DATA);
987 strcpy (data->group, group);
990 if (news->newsgroups->nelem < news->newsgroups->curnelem * 2)
992 hash_resize (news->newsgroups, news->newsgroups->nelem * 2);
993 hash_insert (news->newsgroups, data->group, data, 0);
994 nntp_add_to_list (news, data);
996 if (!data->subscribed) {
997 data->subscribed = 1;
1003 NNTP_DATA *mutt_newsgroup_unsubscribe (NNTP_SERVER * news, char *group)
1007 if (!news || !news->newsgroups || !group || !*group ||
1008 !(data = (NNTP_DATA *) hash_find (news->newsgroups, group)))
1010 if (data->subscribed) {
1011 data->subscribed = 0;
1012 if (!option (OPTSAVEUNSUB))
1018 NNTP_DATA *mutt_newsgroup_catchup (NNTP_SERVER * news, char *group)
1022 if (!news || !news->newsgroups || !group || !*group ||
1023 !(data = (NNTP_DATA *) hash_find (news->newsgroups, group)))
1026 data->entries = p_new(NEWSRC_ENTRY, 5);
1030 data->entries[0].first = 1;
1032 data->entries[0].last = data->lastMessage;
1033 if (Context && Context->data == data) {
1036 for (x = 0; x < Context->msgcount; x++)
1037 mutt_set_flag (Context, Context->hdrs[x], M_READ, 1);
1042 NNTP_DATA *mutt_newsgroup_uncatchup (NNTP_SERVER * news, char *group)
1046 if (!news || !news->newsgroups || !group || !*group ||
1047 !(data = (NNTP_DATA *) hash_find (news->newsgroups, group)))
1050 data->entries = p_new(NEWSRC_ENTRY, 5);
1054 data->entries[0].first = 1;
1055 data->entries[0].last = data->firstMessage - 1;
1056 if (Context && Context->data == data) {
1059 data->unread = Context->msgcount;
1060 for (x = 0; x < Context->msgcount; x++)
1061 mutt_set_flag (Context, Context->hdrs[x], M_READ, 0);
1064 data->unread = data->lastMessage - data->entries[0].last;
1068 /* this routine gives the first newsgroup with new messages */
1069 void nntp_buffy (char* dst, ssize_t dstlen) {
1070 string_list_t *list;
1073 /* forward to current group */
1074 for (list = CurrentNewsSrv->list; list; list = list->next) {
1075 NNTP_DATA *data = (NNTP_DATA *) list->data;
1076 if (data && data->subscribed && data->unread &&
1077 Context && Context->magic == M_NNTP &&
1078 m_strcmp(data->group, ((NNTP_DATA *) Context->data)->group) == 0) {
1089 list = CurrentNewsSrv->list;
1091 for (; list; list = list->next) {
1092 NNTP_DATA *data = (NNTP_DATA *) list->data;
1094 if (data && data->subscribed && data->unread) {
1095 if (Context && Context->magic == M_NNTP &&
1096 !m_strcmp(data->group, ((NNTP_DATA *) Context->data)->group)) {
1097 unsigned int i, unread = 0;
1099 for (i = 0; i < Context->msgcount; i++)
1100 if (!Context->hdrs[i]->read && !Context->hdrs[i]->deleted)
1105 m_strcpy(dst, dstlen, data->group);