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/lib-lib.h>
25 #include <lib-mime/mime.h>
27 #include <lib-ui/curses.h>
34 void nntp_add_to_list (NNTP_SERVER * s, NNTP_DATA * d)
41 l = p_new(string_list_t, 1);
50 static int nntp_parse_newsrc_line (NNTP_SERVER * news, char *line)
53 char group[LONG_STRING];
55 char *p = line, *b, *h;
64 while (*p && (*p != ':' && *p != '!'))
69 if (len > sizeof (group))
71 m_strcpy(group, len, line);
72 if ((data = (NNTP_DATA *) hash_find (news->newsgroups, group)) == NULL) {
73 data = xmalloc(sizeof(NNTP_DATA) + m_strlen(group) + 1);
74 data->group = (char *) data + sizeof (NNTP_DATA);
75 strcpy (data->group, group);
78 if (news->newsgroups->nelem < news->newsgroups->curnelem * 2)
80 hash_resize (news->newsgroups, news->newsgroups->nelem * 2);
81 hash_insert (news->newsgroups, data->group, data, 0);
82 nntp_add_to_list (news, data);
85 p_delete(&data->entries);
88 data->entries = p_new(NEWSRC_ENTRY, x * 2);
100 while (*p && *p != ',' && *p != '\n')
106 if ((h = strchr (b, '-'))) {
109 data->entries[x].first = atoi (b);
110 data->entries[x].last = atoi (h);
113 data->entries[x].first = atoi (b);
114 data->entries[x].last = data->entries[x].first;
117 if (data->entries[x].last != 0)
120 if (x && !data->lastMessage)
121 data->lastMessage = data->entries[x - 1].last;
123 mutt_newsgroup_stat (data);
128 static int slurp_newsrc (NNTP_SERVER * news)
134 news->stat = stat (news->newsrc, &sb);
135 news->size = sb.st_size;
136 news->mtime = sb.st_mtime;
138 if ((fp = safe_fopen (news->newsrc, "r")) == NULL)
140 /* hmm, should we use dotlock? */
141 if (mx_lock_file (news->newsrc, fileno (fp), 0, 0, 1)) {
146 buf = p_new(char, sb.st_size + 1);
147 while (fgets (buf, sb.st_size + 1, fp))
148 nntp_parse_newsrc_line (news, buf);
151 mx_unlock_file (news->newsrc, fileno (fp), 0);
156 void nntp_cache_expand (char *dst, const char *src)
158 snprintf (dst, _POSIX_PATH_MAX, "%s/%s", NewsCacheDir, src);
159 mutt_expand_path (dst, _POSIX_PATH_MAX);
162 /* Loads $news_cache_dir/.index into memory, loads newsserver data
163 * and newsgroup cache names */
164 static int nntp_parse_cacheindex (NNTP_SERVER * news)
167 char buf[HUGE_STRING], *cp;
168 char dir[_POSIX_PATH_MAX], file[_POSIX_PATH_MAX];
173 /* check is server name defined or not */
174 if (!news || !news->conn || !news->conn->account.host)
176 unset_option (OPTNEWSCACHE);
177 if (!NewsCacheDir || !*NewsCacheDir)
180 m_strcpy(dir, sizeof(dir), NewsCacheDir);
181 mutt_expand_path (dir, sizeof (dir));
183 if (lstat (dir, &st) || (st.st_mode & S_IFDIR) == 0) {
184 snprintf (buf, sizeof (buf), _("Directory %s not exist. Create it?"),
186 if (mutt_yesorno (buf, M_YES) != M_YES
187 || mkdir (dir, (S_IRWXU + S_IRWXG + S_IRWXO))) {
188 mutt_error _("Cache directory not created!");
195 set_option (OPTNEWSCACHE);
197 p_delete(&news->cache);
198 snprintf (buf, sizeof (buf), "%s/.index", dir);
199 if (!(idx = safe_fopen (buf, "a+")))
202 while (fgets (buf, sizeof (buf), idx)) {
203 buf[m_strlen(buf) - 1] = 0; /* strip ending '\n' */
204 if (!m_strncmp(buf, "#: ", 3) &&
205 !m_strcasecmp(buf + 3, news->conn->account.host))
208 while (fgets (buf, sizeof (buf), idx)) {
210 while (*cp && *cp != ' ')
215 if (!m_strcmp(buf, "#:"))
217 sscanf (cp + 1, "%s %d %d", file, &l, &m);
218 if (!m_strcmp(buf, "ALL")) {
219 news->cache = m_strdup(file);
220 news->newgroups_time = m;
222 else if (news->newsgroups) {
223 if ((data = (NNTP_DATA *) hash_find (news->newsgroups, buf)) == NULL) {
224 data = xmalloc(sizeof(NNTP_DATA) + m_strlen(buf) + 1);
225 data->group = (char *) data + sizeof (NNTP_DATA);
226 strcpy (data->group, buf);
229 if (news->newsgroups->nelem < news->newsgroups->curnelem * 2)
231 hash_resize (news->newsgroups, news->newsgroups->nelem * 2);
232 hash_insert (news->newsgroups, data->group, data, 0);
233 nntp_add_to_list (news, data);
235 data->cache = m_strdup(file);
237 if (!data->firstMessage || data->lastMessage < m)
239 if (!data->firstMessage)
240 data->firstMessage = l;
241 if (data->lastMessage < m)
242 data->lastMessage = m;
243 data->lastCached = m;
244 if (t || !data->unread)
245 mutt_newsgroup_stat (data);
252 const char *nntp_format_str (char *dest, ssize_t destlen, char op,
253 const char *src, const char *fmt,
254 const char *ifstring, const char *elsestring,
255 unsigned long data, format_flag flags)
257 char fn[SHORT_STRING], tmp[SHORT_STRING];
261 m_strcpy(fn, sizeof (fn), NewsServer);
263 snprintf (tmp, sizeof (tmp), "%%%ss", fmt);
264 snprintf (dest, destlen, tmp, fn);
270 /* nntp_parse_url: given an NNPT URL, return host, port,
271 * username, password and newsgroup will recognise. */
272 int nntp_parse_url (const char *server, ACCOUNT * act,
273 char *group, ssize_t group_len)
281 act->port = NNTP_PORT;
282 act->type = M_ACCT_TYPE_NNTP;
284 c = m_strdup(server);
285 url_parse_ciss (&url, c);
287 if (url.scheme == U_NNTP || url.scheme == U_NNTPS) {
288 if (url.scheme == U_NNTPS) {
289 act->flags |= M_ACCT_SSL;
290 act->port = NNTP_SSL_PORT;
295 m_strcpy(group, group_len, url.path);
297 ret = mutt_account_fromurl (act, &url);
304 void nntp_expand_path (char *line, ssize_t len, ACCOUNT * act)
308 url.path = m_strdup(line);
309 mutt_account_tourl (act, &url);
310 url_ciss_tostring (&url, line, len, 0);
315 * Automatically loads a newsrc into memory, if necessary.
316 * Checks the size/mtime of a newsrc file, if it doesn't match, load
317 * again. Hmm, if a system has broken mtimes, this might mean the file
318 * is reloaded every time, which we'd have to fix.
320 * a newsrc file is a line per newsgroup, with the newsgroup, then a
321 * ':' denoting subscribed or '!' denoting unsubscribed, then a
322 * comma separated list of article numbers and ranges.
324 NNTP_SERVER *mutt_select_newsserver (char *server)
326 char file[_POSIX_PATH_MAX];
335 if (!server || !*server) {
336 mutt_error _("No newsserver defined!");
341 buf = p = p_new(char, m_strlen(server) + 10);
342 if (url_check_scheme (server) == U_UNKNOWN) {
343 strcpy (buf, "nntp://");
344 p = strchr (buf, '\0');
348 if ((nntp_parse_url (buf, &act, file, sizeof (file))) < 0 || *file) {
350 mutt_error (_("%s is an invalid newsserver specification!"), server);
355 conn = mutt_conn_find (NULL, &act);
359 mutt_FormatString (file, sizeof (file), NONULL (NewsRc), nntp_format_str, 0,
361 mutt_expand_path (file, sizeof (file));
363 serv = (NNTP_SERVER *) conn->data;
367 /* externally modified? */
368 if (serv->stat != stat (file, &sb) || (!serv->stat &&
369 (serv->size != sb.st_size
370 || serv->mtime != sb.st_mtime))) {
371 for (list = serv->list; list; list = list->next) {
372 NNTP_DATA *data = (NNTP_DATA *) list->data;
375 data->subscribed = 0;
381 nntp_clear_cacheindex (serv);
384 if (serv->status == NNTP_BYE)
385 serv->status = NNTP_NONE;
386 nntp_check_newgroups (serv, 0);
391 serv = p_new(NNTP_SERVER, 1);
393 serv->newsrc = m_strdup(file);
394 serv->newsgroups = hash_create (1009);
395 slurp_newsrc (serv); /* load .newsrc */
396 nntp_parse_cacheindex (serv); /* load .index */
397 if (option (OPTNEWSCACHE) && serv->cache && nntp_get_cache_all (serv) >= 0)
398 nntp_check_newgroups (serv, 1);
399 else if (nntp_get_active (serv) < 0) {
400 hash_destroy (&serv->newsgroups, nntp_delete_data);
401 for (list = serv->list; list; list = list->next)
403 string_list_wipe(&serv->list);
404 p_delete(&serv->newsrc);
405 p_delete(&serv->cache);
409 nntp_clear_cacheindex (serv);
410 conn->data = (void *) serv;
416 * full status flags are not supported by nntp, but we can fake some
417 * of them. This is how:
418 * Read = a read message number is in the .newsrc
419 * New = a message is new since we last read this newsgroup
420 * Old = anything else
421 * So, Read is marked as such in the newsrc, old is anything that is
422 * "skipped" in the newsrc, and new is anything not in the newsrc nor
423 * in the cache. By skipped, I mean before the last unread message
425 void nntp_get_status (CONTEXT * ctx, HEADER * h, char *group, int article)
427 NNTP_DATA *data = (NNTP_DATA *) ctx->data;
431 data = (NNTP_DATA *) hash_find (data->nserv->newsgroups, group);
437 for (x = 0; x < data->num; x++) {
438 if ((article >= data->entries[x].first) &&
439 (article <= data->entries[x].last)) {
440 /* we cannot use mutt_set_flag() because mx_update_context()
446 /* If article was not cached yet, it is new! :) */
447 if (!data->cache || article > data->lastCached)
449 /* Old articles are articles which aren't read but an article after them
451 if (option (OPTMARKOLD))
455 void mutt_newsgroup_stat (NNTP_DATA * data)
458 unsigned int first, last;
461 if (data->lastMessage == 0 || data->firstMessage > data->lastMessage)
464 data->unread = data->lastMessage - data->firstMessage + 1;
465 for (i = 0; i < data->num; i++) {
466 first = data->entries[i].first;
467 if (first < data->firstMessage)
468 first = data->firstMessage;
469 last = data->entries[i].last;
470 if (last > data->lastMessage)
471 last = data->lastMessage;
473 data->unread -= last - first + 1;
477 static int puti (char *line, int num)
482 *p++ = '0' + num % 10;
486 *line++ = *--p, num++;
491 static void nntp_create_newsrc_line (NNTP_DATA * data, char **buf,
492 char **pline, ssize_t * buflen)
495 ssize_t len = *buflen - (*pline - *buf);
498 if (len < LONG_STRING * 10) {
502 p_realloc(buf, *buflen);
503 line = *buf + (*pline - line);
505 strcpy (line, data->group);
506 len -= m_strlen(line) + 1;
507 line += m_strlen(line);
508 *line++ = data->subscribed ? ':' : '!';
512 for (x = 0; x < data->num; x++) {
513 if (len < LONG_STRING) {
518 p_realloc(buf, *buflen);
519 line = *buf + (*pline - line);
527 if (data->entries[x].first == data->entries[x].last)
528 snprintf (line, len, "%d%n", data->entries[x].first, &i);
530 snprintf (line, len, "%d-%d%n",
531 data->entries[x].first, data->entries[x].last, &i);
535 i = puti (line, data->entries[x].first);
538 if (data->entries[x].first != data->entries[x].last) {
541 i = puti (line, data->entries[x].last);
552 void newsrc_gen_entries (CONTEXT * ctx)
554 NNTP_DATA *data = (NNTP_DATA *) ctx->data;
556 unsigned int last = 0, first = 1;
557 int save_sort = SORT_ORDER;
559 if (Sort != SORT_ORDER) {
562 mutt_sort_headers (ctx, 0);
566 data->entries = p_new(NEWSRC_ENTRY, 5);
571 * Set up to fake initial sequence from 1 to the article before the
572 * first article in our list
577 for (x = 0; x < ctx->msgcount; x++) {
578 if (series) { /* search for first unread */
580 * We don't actually check sequential order, since we mark
581 * "missing" entries as read/deleted
583 last = ctx->hdrs[x]->article_num;
584 if (last >= data->firstMessage && !ctx->hdrs[x]->deleted &&
585 !ctx->hdrs[x]->read) {
586 if (data->num >= data->max) {
587 data->max = data->max * 2;
588 p_realloc(&data->entries, data->max);
590 data->entries[data->num].first = first;
591 data->entries[data->num].last = last - 1;
596 else { /* search for first read */
598 if (ctx->hdrs[x]->deleted || ctx->hdrs[x]->read) {
602 last = ctx->hdrs[x]->article_num;
605 if (series && first <= data->lastLoaded) {
606 if (data->num >= data->max) {
607 data->max = data->max * 2;
608 p_realloc(&data->entries, data->max);
610 data->entries[data->num].first = first;
611 data->entries[data->num].last = data->lastLoaded;
615 if (save_sort != Sort) {
617 mutt_sort_headers (ctx, 0);
621 static int mutt_update_list_file (char *filename, char *section,
622 const char *key, char *line) {
625 char buf[HUGE_STRING];
626 char tmpfile[_POSIX_PATH_MAX], link[_POSIX_PATH_MAX];
628 int ext = 0, done = 0, r = 0, l = 0;
630 /* if file not exist, create it */
631 if ((ifp = safe_fopen (filename, "a")))
633 if (!(ifp = safe_fopen (filename, "r"))) {
634 mutt_error (_("Unable to open %s for reading"), filename);
637 if (mx_lock_file (filename, fileno (ifp), 0, 0, 1)) {
639 mutt_error (_("Unable to lock %s"), filename);
642 /* use mutt_adv_mktemp() to get a tempfile in the same
643 * directory as filename is so that we can follow symlinks
644 * via rename(2); as dirname(2) may modify its argument,
645 * temporarily use buf as copy of it
647 m_strcpy(buf, sizeof(buf), filename);
648 m_strcpy(tmpfile, sizeof(tmpfile), basename(filename));
649 mutt_adv_mktemp ((const char*) dirname (buf), tmpfile, sizeof (tmpfile));
650 if (!(ofp = fopen (tmpfile, "w"))) {
652 mutt_error (_("Unable to open %s for writing"), tmpfile);
657 while (r != EOF && !done && fgets (buf, sizeof (buf), ifp)) {
658 r = fputs (buf, ofp);
660 while (*c && *c != '\n') c++;
661 c[0] = 0; /* strip EOL */
662 if (!strncmp (buf, "#: ", 3) && !m_strcasecmp(buf+3, section))
665 if (r != EOF && !done) {
666 snprintf (buf, sizeof(buf), "#: %s\n", section);
667 r = fputs (buf, ofp);
672 while (r != EOF && fgets (buf, sizeof (buf), ifp)) {
675 while (*c && (*c != '\r') && (*c != '\n')) c++;
677 if (*c != '\\') ext = 0;
678 } else if ((section && !strncmp (buf, "#: ", 3))) {
683 r = fputs (buf, ofp);
686 } else if (key && !strncmp (buf, key, strlen(key)) &&
687 (!*key || buf[strlen(key)] == ' ')) {
690 while (*c && (*c != '\r') && (*c != '\n')) c++;
692 if (*c == '\\') ext = 1;
694 r = fputs (line, ofp);
696 r = fputc ('\n', ofp);
700 r = fputs (buf, ofp);
704 while (r != EOF && fgets (buf, sizeof (buf), ifp))
705 r = fputs (buf, ofp);
707 /* If there wasn't a line to replace, put it on the end of the file */
708 if (r != EOF && !done && line) {
710 r = fputc ('\n', ofp);
712 mx_unlock_file (filename, fileno (ifp), 0);
717 mutt_error (_("Can't write %s"), tmpfile);
721 if ((l = readlink (filename, link, sizeof (link)-1)) > 0)
723 if (rename (tmpfile, l > 0 ? link : filename) < 0) {
725 mutt_error (_("Can't rename %s to %s"), tmpfile, l > 0 ? link : filename);
731 int mutt_newsrc_update (NNTP_SERVER * news)
741 llen = len = 10 * LONG_STRING;
742 line = buf = p_new(char, len);
743 /* we will generate full newsrc here */
744 for (tmp = news->list; tmp; tmp = tmp->next) {
745 data = (NNTP_DATA *) tmp->data;
746 if (!data || !data->rc)
748 nntp_create_newsrc_line (data, &buf, &line, &llen);
749 line += m_strlen(line);
751 /* newrc being fully rewritten */
753 (r = mutt_update_list_file(news->newsrc, NULL, "", buf)) == 0) {
756 stat (news->newsrc, &st);
757 news->size = st.st_size;
758 news->mtime = st.st_mtime;
764 static FILE *mutt_mkname (char *s)
766 char buf[_POSIX_PATH_MAX], *pc;
770 nntp_cache_expand (buf, s);
771 if ((fp = safe_fopen (buf, "w")))
774 nntp_cache_expand (buf, "cache-XXXXXX");
775 pc = buf + m_strlen(buf) - 12; /* positioning to "cache-XXXXXX" */
776 if ((fd = mkstemp (buf)) == -1)
778 strcpy (s, pc); /* generated name */
779 return fdopen (fd, "w");
782 /* Updates info into .index file: ALL or about selected newsgroup */
783 static int nntp_update_cacheindex (NNTP_SERVER * serv, NNTP_DATA * data)
785 char buf[LONG_STRING];
786 char file[_POSIX_PATH_MAX];
787 const char *key = "ALL";
789 if (!serv || !serv->conn || !serv->conn->account.host)
792 if (data && data->group) {
794 snprintf (buf, sizeof (buf), "%s %s %d %d", key, data->cache,
795 data->firstMessage, data->lastLoaded);
798 m_strcpy(file, sizeof(file), serv->cache);
799 snprintf (buf, sizeof (buf), "ALL %s 0 %d", file,
800 (int) serv->newgroups_time);
802 nntp_cache_expand (file, ".index");
803 return mutt_update_list_file (file, serv->conn->account.host, key, buf);
806 /* Remove cache files of unsubscribed newsgroups */
807 void nntp_clear_cacheindex (NNTP_SERVER * news)
812 if (option (OPTSAVEUNSUB) || !news)
815 for (tmp = news->list; tmp; tmp = tmp->next) {
816 data = (NNTP_DATA *) tmp->data;
817 if (!data || data->subscribed || !data->cache)
819 nntp_delete_cache (data);
824 int nntp_save_cache_index (NNTP_SERVER * news)
826 char buf[HUGE_STRING];
827 char file[_POSIX_PATH_MAX];
832 if (!news || !news->newsgroups)
834 if (!option (OPTNEWSCACHE))
838 nntp_cache_expand (file, news->cache);
840 f = safe_fopen (file, "w");
843 m_strcpy(buf, sizeof(buf), news->conn->account.host);
844 f = mutt_mkname (buf);
845 news->cache = m_strdup(buf);
846 nntp_cache_expand (file, buf);
851 for (l = news->list; l; l = l->next) {
852 if ((d = (NNTP_DATA *) l->data) && !d->deleted) {
854 snprintf (buf, sizeof (buf), "%s %d %d %c %s\n", d->group,
855 d->lastMessage, d->firstMessage, d->allowed ? 'y' : 'n',
858 snprintf (buf, sizeof (buf), "%s %d %d %c\n", d->group,
859 d->lastMessage, d->firstMessage, d->allowed ? 'y' : 'n');
860 if (fputs (buf, f) == EOF) {
869 if (nntp_update_cacheindex (news, NULL)) {
876 int nntp_save_cache_group (CONTEXT * ctx)
878 char buf[HUGE_STRING], addr[STRING];
879 char file[_POSIX_PATH_MAX];
883 int i = 0, save = SORT_ORDER;
886 if (!option (OPTNEWSCACHE))
888 if (!ctx || !ctx->data || ctx->magic != M_NNTP)
891 if (((NNTP_DATA *) ctx->data)->cache) {
892 nntp_cache_expand (file, ((NNTP_DATA *) ctx->data)->cache);
894 f = safe_fopen (file, "w");
897 snprintf (buf, sizeof (buf), "%s-%s",
898 ((NNTP_DATA *) ctx->data)->nserv->conn->account.host,
899 ((NNTP_DATA *) ctx->data)->group);
900 f = mutt_mkname (buf);
901 ((NNTP_DATA *) ctx->data)->cache = m_strdup(buf);
902 nntp_cache_expand (file, buf);
907 if (Sort != SORT_ORDER) {
910 mutt_sort_headers (ctx, 0);
913 /* Save only $nntp_context messages... */
914 ((NNTP_DATA *) ctx->data)->lastCached = 0;
915 if (NntpContext && ctx->msgcount > NntpContext)
916 i = ctx->msgcount - NntpContext;
917 for (; i < ctx->msgcount; i++) {
918 if (!ctx->hdrs[i]->deleted && ctx->hdrs[i]->article_num != prev) {
921 rfc822_write_address (addr, sizeof (addr), h->env->from, 0);
922 tm = gmtime (&h->date_sent);
923 snprintf (buf, sizeof (buf),
924 "%d\t%s\t%s\t%d %s %d %02d:%02d:%02d GMT\t%s\t",
925 h->article_num, h->env->subject, addr, tm->tm_mday,
926 Months[tm->tm_mon], tm->tm_year + 1900, tm->tm_hour,
927 tm->tm_min, tm->tm_sec, h->env->message_id);
929 if (h->env->references)
930 mutt_write_references (h->env->references, f);
931 snprintf (buf, sizeof (buf), "\t%zd\t%d\tXref: %s\n",
932 h->content->length, h->lines, NONULL (h->env->xref));
933 if (fputs (buf, f) == EOF) {
939 prev = ctx->hdrs[i]->article_num;
944 mutt_sort_headers (ctx, 0);
948 if (nntp_update_cacheindex (((NNTP_DATA *) ctx->data)->nserv,
949 (NNTP_DATA *) ctx->data)) {
953 ((NNTP_DATA *) ctx->data)->lastCached =
954 ((NNTP_DATA *) ctx->data)->lastLoaded;
958 void nntp_delete_cache (NNTP_DATA * data)
960 char buf[_POSIX_PATH_MAX];
962 if (!option (OPTNEWSCACHE) || !data || !data->cache || !data->nserv)
965 nntp_cache_expand (buf, data->cache);
967 p_delete(&data->cache);
968 data->lastCached = 0;
969 nntp_cache_expand (buf, ".index");
970 mutt_update_list_file (buf, data->nserv->conn->account.host, data->group,
974 NNTP_DATA *mutt_newsgroup_subscribe (NNTP_SERVER * news, char *group)
978 if (!news || !news->newsgroups || !group || !*group)
980 if (!(data = (NNTP_DATA *) hash_find (news->newsgroups, group))) {
981 data = xmalloc(sizeof(NNTP_DATA) + m_strlen(group) + 1);
982 data->group = (char *) data + sizeof (NNTP_DATA);
983 strcpy (data->group, group);
986 if (news->newsgroups->nelem < news->newsgroups->curnelem * 2)
988 hash_resize (news->newsgroups, news->newsgroups->nelem * 2);
989 hash_insert (news->newsgroups, data->group, data, 0);
990 nntp_add_to_list (news, data);
992 if (!data->subscribed) {
993 data->subscribed = 1;
999 NNTP_DATA *mutt_newsgroup_unsubscribe (NNTP_SERVER * news, char *group)
1003 if (!news || !news->newsgroups || !group || !*group ||
1004 !(data = (NNTP_DATA *) hash_find (news->newsgroups, group)))
1006 if (data->subscribed) {
1007 data->subscribed = 0;
1008 if (!option (OPTSAVEUNSUB))
1014 NNTP_DATA *mutt_newsgroup_catchup (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;
1028 data->entries[0].last = data->lastMessage;
1029 if (Context && Context->data == data) {
1032 for (x = 0; x < Context->msgcount; x++)
1033 mutt_set_flag (Context, Context->hdrs[x], M_READ, 1);
1038 NNTP_DATA *mutt_newsgroup_uncatchup (NNTP_SERVER * news, char *group)
1042 if (!news || !news->newsgroups || !group || !*group ||
1043 !(data = (NNTP_DATA *) hash_find (news->newsgroups, group)))
1046 data->entries = p_new(NEWSRC_ENTRY, 5);
1050 data->entries[0].first = 1;
1051 data->entries[0].last = data->firstMessage - 1;
1052 if (Context && Context->data == data) {
1055 data->unread = Context->msgcount;
1056 for (x = 0; x < Context->msgcount; x++)
1057 mutt_set_flag (Context, Context->hdrs[x], M_READ, 0);
1060 data->unread = data->lastMessage - data->entries[0].last;
1064 /* this routine gives the first newsgroup with new messages */
1065 void nntp_buffy (char* dst, ssize_t dstlen) {
1066 string_list_t *list;
1069 /* forward to current group */
1070 for (list = CurrentNewsSrv->list; list; list = list->next) {
1071 NNTP_DATA *data = (NNTP_DATA *) list->data;
1072 if (data && data->subscribed && data->unread &&
1073 Context && Context->magic == M_NNTP &&
1074 m_strcmp(data->group, ((NNTP_DATA *) Context->data)->group) == 0) {
1085 list = CurrentNewsSrv->list;
1087 for (; list; list = list->next) {
1088 NNTP_DATA *data = (NNTP_DATA *) list->data;
1090 if (data && data->subscribed && data->unread) {
1091 if (Context && Context->magic == M_NNTP &&
1092 !m_strcmp(data->group, ((NNTP_DATA *) Context->data)->group)) {
1093 unsigned int i, unread = 0;
1095 for (i = 0; i < Context->msgcount; i++)
1096 if (!Context->hdrs[i]->read && !Context->hdrs[i]->deleted)
1101 m_strcpy(dst, dstlen, data->group);