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.
16 #include <lib-lib/mem.h>
19 #include "mutt_curses.h"
31 #include "lib/debug.h"
40 void nntp_add_to_list (NNTP_SERVER * s, NNTP_DATA * d)
47 l = mem_calloc (1, sizeof (LIST));
56 static int nntp_parse_newsrc_line (NNTP_SERVER * news, char *line)
59 char group[LONG_STRING];
61 char *p = line, *b, *h;
70 while (*p && (*p != ':' && *p != '!'))
75 if (len > sizeof (group))
77 strfcpy (group, line, len);
78 if ((data = (NNTP_DATA *) hash_find (news->newsgroups, group)) == NULL) {
80 (NNTP_DATA *) mem_calloc (1, sizeof (NNTP_DATA) + str_len (group) + 1);
81 data->group = (char *) data + sizeof (NNTP_DATA);
82 strcpy (data->group, group);
85 if (news->newsgroups->nelem < news->newsgroups->curnelem * 2)
87 hash_resize (news->newsgroups, news->newsgroups->nelem * 2);
88 hash_insert (news->newsgroups, data->group, data, 0);
89 nntp_add_to_list (news, data);
92 p_delete(&data->entries);
95 data->entries = mem_calloc (x * 2, sizeof (NEWSRC_ENTRY));
101 data->subscribed = 0;
107 while (*p && *p != ',' && *p != '\n')
113 if ((h = strchr (b, '-'))) {
116 data->entries[x].first = atoi (b);
117 data->entries[x].last = atoi (h);
120 data->entries[x].first = atoi (b);
121 data->entries[x].last = data->entries[x].first;
124 if (data->entries[x].last != 0)
127 if (x && !data->lastMessage)
128 data->lastMessage = data->entries[x - 1].last;
130 mutt_newsgroup_stat (data);
131 debug_print (2, ("Newsgroup %s\n", data->group));
136 static int slurp_newsrc (NNTP_SERVER * news)
142 news->stat = stat (news->newsrc, &sb);
143 news->size = sb.st_size;
144 news->mtime = sb.st_mtime;
146 if ((fp = safe_fopen (news->newsrc, "r")) == NULL)
148 /* hmm, should we use dotlock? */
149 if (mx_lock_file (news->newsrc, fileno (fp), 0, 0, 1)) {
154 buf = p_new(char, sb.st_size + 1);
155 while (fgets (buf, sb.st_size + 1, fp))
156 nntp_parse_newsrc_line (news, buf);
159 mx_unlock_file (news->newsrc, fileno (fp), 0);
164 void nntp_cache_expand (char *dst, const char *src)
166 snprintf (dst, _POSIX_PATH_MAX, "%s/%s", NewsCacheDir, src);
167 mutt_expand_path (dst, _POSIX_PATH_MAX);
170 /* Loads $news_cache_dir/.index into memory, loads newsserver data
171 * and newsgroup cache names */
172 static int nntp_parse_cacheindex (NNTP_SERVER * news)
175 char buf[HUGE_STRING], *cp;
176 char dir[_POSIX_PATH_MAX], file[_POSIX_PATH_MAX];
181 /* check is server name defined or not */
182 if (!news || !news->conn || !news->conn->account.host)
184 unset_option (OPTNEWSCACHE);
185 if (!NewsCacheDir || !*NewsCacheDir)
188 strfcpy (dir, NewsCacheDir, sizeof (dir));
189 mutt_expand_path (dir, sizeof (dir));
191 if (lstat (dir, &st) || (st.st_mode & S_IFDIR) == 0) {
192 snprintf (buf, sizeof (buf), _("Directory %s not exist. Create it?"),
194 if (mutt_yesorno (buf, M_YES) != M_YES
195 || mkdir (dir, (S_IRWXU + S_IRWXG + S_IRWXO))) {
196 mutt_error _("Cache directory not created!");
203 set_option (OPTNEWSCACHE);
205 p_delete(&news->cache);
206 snprintf (buf, sizeof (buf), "%s/.index", dir);
207 if (!(index = safe_fopen (buf, "a+")))
210 while (fgets (buf, sizeof (buf), index)) {
211 buf[str_len (buf) - 1] = 0; /* strip ending '\n' */
212 if (!str_ncmp (buf, "#: ", 3) &&
213 !str_casecmp (buf + 3, news->conn->account.host))
216 while (fgets (buf, sizeof (buf), index)) {
218 while (*cp && *cp != ' ')
223 if (!str_cmp (buf, "#:"))
225 sscanf (cp + 1, "%s %d %d", file, &l, &m);
226 if (!str_cmp (buf, "ALL")) {
227 news->cache = str_dup (file);
228 news->newgroups_time = m;
230 else if (news->newsgroups) {
231 if ((data = (NNTP_DATA *) hash_find (news->newsgroups, buf)) == NULL) {
233 (NNTP_DATA *) mem_calloc (1,
234 sizeof (NNTP_DATA) + str_len (buf) + 1);
235 data->group = (char *) data + sizeof (NNTP_DATA);
236 strcpy (data->group, buf);
239 if (news->newsgroups->nelem < news->newsgroups->curnelem * 2)
241 hash_resize (news->newsgroups, news->newsgroups->nelem * 2);
242 hash_insert (news->newsgroups, data->group, data, 0);
243 nntp_add_to_list (news, data);
245 data->cache = str_dup (file);
247 if (!data->firstMessage || data->lastMessage < m)
249 if (!data->firstMessage)
250 data->firstMessage = l;
251 if (data->lastMessage < m)
252 data->lastMessage = m;
253 data->lastCached = m;
254 if (t || !data->unread)
255 mutt_newsgroup_stat (data);
262 const char *nntp_format_str (char *dest, size_t destlen, char op,
263 const char *src, const char *fmt,
264 const char *ifstring, const char *elsestring,
265 unsigned long data, format_flag flags)
267 char fn[SHORT_STRING], tmp[SHORT_STRING];
271 strncpy (fn, NewsServer, sizeof (fn) - 1);
273 snprintf (tmp, sizeof (tmp), "%%%ss", fmt);
274 snprintf (dest, destlen, tmp, fn);
280 /* nntp_parse_url: given an NNPT URL, return host, port,
281 * username, password and newsgroup will recognise. */
282 int nntp_parse_url (const char *server, ACCOUNT * acct,
283 char *group, size_t group_len)
291 acct->port = NNTP_PORT;
292 acct->type = M_ACCT_TYPE_NNTP;
294 c = str_dup (server);
295 url_parse_ciss (&url, c);
297 if (url.scheme == U_NNTP || url.scheme == U_NNTPS) {
298 if (url.scheme == U_NNTPS) {
299 acct->flags |= M_ACCT_SSL;
300 acct->port = NNTP_SSL_PORT;
305 strfcpy (group, url.path, group_len);
307 ret = mutt_account_fromurl (acct, &url);
314 void nntp_expand_path (char *line, size_t len, ACCOUNT * acct)
318 url.path = str_dup (line);
319 mutt_account_tourl (acct, &url);
320 url_ciss_tostring (&url, line, len, 0);
325 * Automatically loads a newsrc into memory, if necessary.
326 * Checks the size/mtime of a newsrc file, if it doesn't match, load
327 * again. Hmm, if a system has broken mtimes, this might mean the file
328 * is reloaded every time, which we'd have to fix.
330 * a newsrc file is a line per newsgroup, with the newsgroup, then a
331 * ':' denoting subscribed or '!' denoting unsubscribed, then a
332 * comma separated list of article numbers and ranges.
334 NNTP_SERVER *mutt_select_newsserver (char *server)
336 char file[_POSIX_PATH_MAX];
343 memset (&acct, 0, sizeof (ACCOUNT));
345 if (!server || !*server) {
346 mutt_error _("No newsserver defined!");
351 buf = p = mem_calloc (str_len (server) + 10, sizeof (char));
352 if (url_check_scheme (server) == U_UNKNOWN) {
353 strcpy (buf, "nntp://");
354 p = strchr (buf, '\0');
358 if ((nntp_parse_url (buf, &acct, file, sizeof (file))) < 0 || *file) {
360 mutt_error (_("%s is an invalid newsserver specification!"), server);
365 conn = mutt_conn_find (NULL, &acct);
369 mutt_FormatString (file, sizeof (file), NONULL (NewsRc), nntp_format_str, 0,
371 mutt_expand_path (file, sizeof (file));
373 serv = (NNTP_SERVER *) conn->data;
377 /* externally modified? */
378 if (serv->stat != stat (file, &sb) || (!serv->stat &&
379 (serv->size != sb.st_size
380 || serv->mtime != sb.st_mtime))) {
381 for (list = serv->list; list; list = list->next) {
382 NNTP_DATA *data = (NNTP_DATA *) list->data;
385 data->subscribed = 0;
391 nntp_clear_cacheindex (serv);
394 if (serv->status == NNTP_BYE)
395 serv->status = NNTP_NONE;
396 nntp_check_newgroups (serv, 0);
401 serv = mem_calloc (1, sizeof (NNTP_SERVER));
403 serv->newsrc = str_dup (file);
404 serv->newsgroups = hash_create (1009);
405 slurp_newsrc (serv); /* load .newsrc */
406 nntp_parse_cacheindex (serv); /* load .index */
407 if (option (OPTNEWSCACHE) && serv->cache && nntp_get_cache_all (serv) >= 0)
408 nntp_check_newgroups (serv, 1);
409 else if (nntp_get_active (serv) < 0) {
410 hash_destroy (&serv->newsgroups, nntp_delete_data);
411 for (list = serv->list; list; list = list->next)
413 mutt_free_list (&serv->list);
414 p_delete(&serv->newsrc);
415 p_delete(&serv->cache);
419 nntp_clear_cacheindex (serv);
420 conn->data = (void *) serv;
426 * full status flags are not supported by nntp, but we can fake some
427 * of them. This is how:
428 * Read = a read message number is in the .newsrc
429 * New = a message is new since we last read this newsgroup
430 * Old = anything else
431 * So, Read is marked as such in the newsrc, old is anything that is
432 * "skipped" in the newsrc, and new is anything not in the newsrc nor
433 * in the cache. By skipped, I mean before the last unread message
435 void nntp_get_status (CONTEXT * ctx, HEADER * h, char *group, int article)
437 NNTP_DATA *data = (NNTP_DATA *) ctx->data;
441 data = (NNTP_DATA *) hash_find (data->nserv->newsgroups, group);
446 debug_print (3, ("newsgroup %s not found\n", group));
451 for (x = 0; x < data->num; x++) {
452 if ((article >= data->entries[x].first) &&
453 (article <= data->entries[x].last)) {
454 /* we cannot use mutt_set_flag() because mx_update_context()
460 /* If article was not cached yet, it is new! :) */
461 if (!data->cache || article > data->lastCached)
463 /* Old articles are articles which aren't read but an article after them
465 if (option (OPTMARKOLD))
469 void mutt_newsgroup_stat (NNTP_DATA * data)
472 unsigned int first, last;
475 if (data->lastMessage == 0 || data->firstMessage > data->lastMessage)
478 data->unread = data->lastMessage - data->firstMessage + 1;
479 for (i = 0; i < data->num; i++) {
480 first = data->entries[i].first;
481 if (first < data->firstMessage)
482 first = data->firstMessage;
483 last = data->entries[i].last;
484 if (last > data->lastMessage)
485 last = data->lastMessage;
487 data->unread -= last - first + 1;
491 static int puti (char *line, int num)
496 *p++ = '0' + num % 10;
500 *line++ = *--p, num++;
505 static void nntp_create_newsrc_line (NNTP_DATA * data, char **buf,
506 char **pline, size_t * buflen)
509 size_t len = *buflen - (*pline - *buf);
512 if (len < LONG_STRING * 10) {
516 mem_realloc (buf, *buflen);
517 line = *buf + (*pline - line);
519 strcpy (line, data->group);
520 len -= str_len (line) + 1;
521 line += str_len (line);
522 *line++ = data->subscribed ? ':' : '!';
526 for (x = 0; x < data->num; x++) {
527 if (len < LONG_STRING) {
532 mem_realloc (buf, *buflen);
533 line = *buf + (*pline - line);
541 if (data->entries[x].first == data->entries[x].last)
542 snprintf (line, len, "%d%n", data->entries[x].first, &i);
544 snprintf (line, len, "%d-%d%n",
545 data->entries[x].first, data->entries[x].last, &i);
549 i = puti (line, data->entries[x].first);
552 if (data->entries[x].first != data->entries[x].last) {
555 i = puti (line, data->entries[x].last);
566 void newsrc_gen_entries (CONTEXT * ctx)
568 NNTP_DATA *data = (NNTP_DATA *) ctx->data;
570 unsigned int last = 0, first = 1;
571 int save_sort = SORT_ORDER;
573 if (Sort != SORT_ORDER) {
576 mutt_sort_headers (ctx, 0);
580 data->entries = mem_calloc (5, sizeof (NEWSRC_ENTRY));
585 * Set up to fake initial sequence from 1 to the article before the
586 * first article in our list
591 for (x = 0; x < ctx->msgcount; x++) {
592 if (series) { /* search for first unread */
594 * We don't actually check sequential order, since we mark
595 * "missing" entries as read/deleted
597 last = ctx->hdrs[x]->article_num;
598 if (last >= data->firstMessage && !ctx->hdrs[x]->deleted &&
599 !ctx->hdrs[x]->read) {
600 if (data->num >= data->max) {
601 data->max = data->max * 2;
602 mem_realloc (&data->entries, data->max * sizeof (NEWSRC_ENTRY));
604 data->entries[data->num].first = first;
605 data->entries[data->num].last = last - 1;
610 else { /* search for first read */
612 if (ctx->hdrs[x]->deleted || ctx->hdrs[x]->read) {
616 last = ctx->hdrs[x]->article_num;
619 if (series && first <= data->lastLoaded) {
620 if (data->num >= data->max) {
621 data->max = data->max * 2;
622 mem_realloc (&data->entries, data->max * sizeof (NEWSRC_ENTRY));
624 data->entries[data->num].first = first;
625 data->entries[data->num].last = data->lastLoaded;
629 if (save_sort != Sort) {
631 mutt_sort_headers (ctx, 0);
635 static int mutt_update_list_file (char *filename, char *section,
636 char *key, char *line) {
639 char buf[HUGE_STRING];
640 char tmpfile[_POSIX_PATH_MAX], link[_POSIX_PATH_MAX];
642 int ext = 0, done = 0, r = 0, l = 0;
644 /* if file not exist, create it */
645 if ((ifp = safe_fopen (filename, "a")))
647 debug_print (1, ("Opening %s\n", filename));
648 if (!(ifp = safe_fopen (filename, "r"))) {
649 mutt_error (_("Unable to open %s for reading"), filename);
652 if (mx_lock_file (filename, fileno (ifp), 0, 0, 1)) {
654 mutt_error (_("Unable to lock %s"), filename);
657 /* use mutt_adv_mktemp() to get a tempfile in the same
658 * directory as filename is so that we can follow symlinks
659 * via rename(2); as dirname(2) may modify its argument,
660 * temporarily use buf as copy of it
662 strncpy (buf, filename, sizeof (buf));
663 strncpy (tmpfile, basename (filename), sizeof (tmpfile));
664 mutt_adv_mktemp ((const char*) dirname (buf), tmpfile, sizeof (tmpfile));
665 debug_print (1, ("Opening %s\n", tmpfile));
666 if (!(ofp = fopen (tmpfile, "w"))) {
668 mutt_error (_("Unable to open %s for writing"), tmpfile);
673 while (r != EOF && !done && fgets (buf, sizeof (buf), ifp)) {
674 r = fputs (buf, ofp);
676 while (*c && *c != '\n') c++;
677 c[0] = 0; /* strip EOL */
678 if (!strncmp (buf, "#: ", 3) && !str_casecmp (buf+3, section))
681 if (r != EOF && !done) {
682 snprintf (buf, sizeof(buf), "#: %s\n", section);
683 r = fputs (buf, ofp);
688 while (r != EOF && fgets (buf, sizeof (buf), ifp)) {
691 while (*c && (*c != '\r') && (*c != '\n')) c++;
693 if (*c != '\\') ext = 0;
694 } else if ((section && !strncmp (buf, "#: ", 3))) {
699 r = fputs (buf, ofp);
702 } else if (key && !strncmp (buf, key, strlen(key)) &&
703 (!*key || buf[strlen(key)] == ' ')) {
706 while (*c && (*c != '\r') && (*c != '\n')) c++;
708 if (*c == '\\') ext = 1;
710 r = fputs (line, ofp);
712 r = fputc ('\n', ofp);
716 r = fputs (buf, ofp);
720 while (r != EOF && fgets (buf, sizeof (buf), ifp))
721 r = fputs (buf, ofp);
723 /* If there wasn't a line to replace, put it on the end of the file */
724 if (r != EOF && !done && line) {
726 r = fputc ('\n', ofp);
728 mx_unlock_file (filename, fileno (ifp), 0);
733 mutt_error (_("Can't write %s"), tmpfile);
737 if ((l = readlink (filename, link, sizeof (link)-1)) > 0)
739 debug_print (1, ("Renaming %s to %s\n",tmpfile, l > 0 ? link : filename));
740 if (rename (tmpfile, l > 0 ? link : filename) < 0) {
742 mutt_error (_("Can't rename %s to %s"), tmpfile, l > 0 ? link : filename);
748 int mutt_newsrc_update (NNTP_SERVER * news)
758 llen = len = 10 * LONG_STRING;
759 line = buf = mem_calloc (1, len);
760 /* we will generate full newsrc here */
761 for (tmp = news->list; tmp; tmp = tmp->next) {
762 data = (NNTP_DATA *) tmp->data;
763 if (!data || !data->rc)
765 nntp_create_newsrc_line (data, &buf, &line, &llen);
766 debug_print (2, ("Added to newsrc: %s\n", line));
767 line += str_len (line);
769 /* newrc being fully rewritten */
771 (r = mutt_update_list_file (news->newsrc, NULL, "", buf)) == 0) {
774 stat (news->newsrc, &st);
775 news->size = st.st_size;
776 news->mtime = st.st_mtime;
782 static FILE *mutt_mkname (char *s)
784 char buf[_POSIX_PATH_MAX], *pc;
788 nntp_cache_expand (buf, s);
789 if ((fp = safe_fopen (buf, "w")))
792 nntp_cache_expand (buf, "cache-XXXXXX");
793 pc = buf + str_len (buf) - 12; /* positioning to "cache-XXXXXX" */
794 if ((fd = mkstemp (buf)) == -1)
796 strcpy (s, pc); /* generated name */
797 return fdopen (fd, "w");
800 /* Updates info into .index file: ALL or about selected newsgroup */
801 static int nntp_update_cacheindex (NNTP_SERVER * serv, NNTP_DATA * data)
803 char buf[LONG_STRING], *key = "ALL";
804 char file[_POSIX_PATH_MAX];
806 if (!serv || !serv->conn || !serv->conn->account.host)
809 if (data && data->group) {
811 snprintf (buf, sizeof (buf), "%s %s %d %d", key, data->cache,
812 data->firstMessage, data->lastLoaded);
815 strfcpy (file, serv->cache, sizeof (file));
816 snprintf (buf, sizeof (buf), "ALL %s 0 %d", file,
817 (int) serv->newgroups_time);
819 nntp_cache_expand (file, ".index");
820 return mutt_update_list_file (file, serv->conn->account.host, key, buf);
823 /* Remove cache files of unsubscribed newsgroups */
824 void nntp_clear_cacheindex (NNTP_SERVER * news)
829 if (option (OPTSAVEUNSUB) || !news)
832 for (tmp = news->list; tmp; tmp = tmp->next) {
833 data = (NNTP_DATA *) tmp->data;
834 if (!data || data->subscribed || !data->cache)
836 nntp_delete_cache (data);
837 debug_print (2, ("Removed from .index: %s\n", data->group));
842 int nntp_save_cache_index (NNTP_SERVER * news)
844 char buf[HUGE_STRING];
845 char file[_POSIX_PATH_MAX];
850 if (!news || !news->newsgroups)
852 if (!option (OPTNEWSCACHE))
856 nntp_cache_expand (file, news->cache);
858 f = safe_fopen (file, "w");
861 strfcpy (buf, news->conn->account.host, sizeof (buf));
862 f = mutt_mkname (buf);
863 news->cache = str_dup (buf);
864 nntp_cache_expand (file, buf);
869 for (l = news->list; l; l = l->next) {
870 if ((d = (NNTP_DATA *) l->data) && !d->deleted) {
872 snprintf (buf, sizeof (buf), "%s %d %d %c %s\n", d->group,
873 d->lastMessage, d->firstMessage, d->allowed ? 'y' : 'n',
876 snprintf (buf, sizeof (buf), "%s %d %d %c\n", d->group,
877 d->lastMessage, d->firstMessage, d->allowed ? 'y' : 'n');
878 if (fputs (buf, f) == EOF) {
887 if (nntp_update_cacheindex (news, NULL)) {
894 int nntp_save_cache_group (CONTEXT * ctx)
896 char buf[HUGE_STRING], addr[STRING];
897 char file[_POSIX_PATH_MAX];
901 int i = 0, save = SORT_ORDER;
904 if (!option (OPTNEWSCACHE))
906 if (!ctx || !ctx->data || ctx->magic != M_NNTP)
909 if (((NNTP_DATA *) ctx->data)->cache) {
910 nntp_cache_expand (file, ((NNTP_DATA *) ctx->data)->cache);
912 f = safe_fopen (file, "w");
915 snprintf (buf, sizeof (buf), "%s-%s",
916 ((NNTP_DATA *) ctx->data)->nserv->conn->account.host,
917 ((NNTP_DATA *) ctx->data)->group);
918 f = mutt_mkname (buf);
919 ((NNTP_DATA *) ctx->data)->cache = str_dup (buf);
920 nntp_cache_expand (file, buf);
925 if (Sort != SORT_ORDER) {
928 mutt_sort_headers (ctx, 0);
931 /* Save only $nntp_context messages... */
932 ((NNTP_DATA *) ctx->data)->lastCached = 0;
933 if (NntpContext && ctx->msgcount > NntpContext)
934 i = ctx->msgcount - NntpContext;
935 for (; i < ctx->msgcount; i++) {
936 if (!ctx->hdrs[i]->deleted && ctx->hdrs[i]->article_num != prev) {
939 rfc822_write_address (addr, sizeof (addr), h->env->from, 0);
940 tm = gmtime (&h->date_sent);
941 snprintf (buf, sizeof (buf),
942 "%d\t%s\t%s\t%d %s %d %02d:%02d:%02d GMT\t%s\t",
943 h->article_num, h->env->subject, addr, tm->tm_mday,
944 Months[tm->tm_mon], tm->tm_year + 1900, tm->tm_hour,
945 tm->tm_min, tm->tm_sec, h->env->message_id);
947 if (h->env->references)
948 mutt_write_references (h->env->references, f);
949 snprintf (buf, sizeof (buf), "\t%zd\t%d\tXref: %s\n",
950 h->content->length, h->lines, NONULL (h->env->xref));
951 if (fputs (buf, f) == EOF) {
957 prev = ctx->hdrs[i]->article_num;
962 mutt_sort_headers (ctx, 0);
966 if (nntp_update_cacheindex (((NNTP_DATA *) ctx->data)->nserv,
967 (NNTP_DATA *) ctx->data)) {
971 ((NNTP_DATA *) ctx->data)->lastCached =
972 ((NNTP_DATA *) ctx->data)->lastLoaded;
976 void nntp_delete_cache (NNTP_DATA * data)
978 char buf[_POSIX_PATH_MAX];
980 if (!option (OPTNEWSCACHE) || !data || !data->cache || !data->nserv)
983 nntp_cache_expand (buf, data->cache);
985 p_delete(&data->cache);
986 data->lastCached = 0;
987 nntp_cache_expand (buf, ".index");
988 mutt_update_list_file (buf, data->nserv->conn->account.host, data->group,
992 NNTP_DATA *mutt_newsgroup_subscribe (NNTP_SERVER * news, char *group)
996 if (!news || !news->newsgroups || !group || !*group)
998 if (!(data = (NNTP_DATA *) hash_find (news->newsgroups, group))) {
1000 (NNTP_DATA *) mem_calloc (1, sizeof (NNTP_DATA) + str_len (group) + 1);
1001 data->group = (char *) data + sizeof (NNTP_DATA);
1002 strcpy (data->group, group);
1005 if (news->newsgroups->nelem < news->newsgroups->curnelem * 2)
1007 hash_resize (news->newsgroups, news->newsgroups->nelem * 2);
1008 hash_insert (news->newsgroups, data->group, data, 0);
1009 nntp_add_to_list (news, data);
1011 if (!data->subscribed) {
1012 data->subscribed = 1;
1018 NNTP_DATA *mutt_newsgroup_unsubscribe (NNTP_SERVER * news, char *group)
1022 if (!news || !news->newsgroups || !group || !*group ||
1023 !(data = (NNTP_DATA *) hash_find (news->newsgroups, group)))
1025 if (data->subscribed) {
1026 data->subscribed = 0;
1027 if (!option (OPTSAVEUNSUB))
1033 NNTP_DATA *mutt_newsgroup_catchup (NNTP_SERVER * news, char *group)
1037 if (!news || !news->newsgroups || !group || !*group ||
1038 !(data = (NNTP_DATA *) hash_find (news->newsgroups, group)))
1041 data->entries = mem_calloc (5, sizeof (NEWSRC_ENTRY));
1045 data->entries[0].first = 1;
1047 data->entries[0].last = data->lastMessage;
1048 if (Context && Context->data == data) {
1051 for (x = 0; x < Context->msgcount; x++)
1052 mutt_set_flag (Context, Context->hdrs[x], M_READ, 1);
1057 NNTP_DATA *mutt_newsgroup_uncatchup (NNTP_SERVER * news, char *group)
1061 if (!news || !news->newsgroups || !group || !*group ||
1062 !(data = (NNTP_DATA *) hash_find (news->newsgroups, group)))
1065 data->entries = mem_calloc (5, sizeof (NEWSRC_ENTRY));
1069 data->entries[0].first = 1;
1070 data->entries[0].last = data->firstMessage - 1;
1071 if (Context && Context->data == data) {
1074 data->unread = Context->msgcount;
1075 for (x = 0; x < Context->msgcount; x++)
1076 mutt_set_flag (Context, Context->hdrs[x], M_READ, 0);
1079 data->unread = data->lastMessage - data->entries[0].last;
1083 /* this routine gives the first newsgroup with new messages */
1084 void nntp_buffy (char* dst, size_t dstlen) {
1088 /* forward to current group */
1089 for (list = CurrentNewsSrv->list; list; list = list->next) {
1090 NNTP_DATA *data = (NNTP_DATA *) list->data;
1091 if (data && data->subscribed && data->unread &&
1092 Context && Context->magic == M_NNTP &&
1093 str_cmp (data->group, ((NNTP_DATA *) Context->data)->group) == 0) {
1104 list = CurrentNewsSrv->list;
1106 for (; list; list = list->next) {
1107 NNTP_DATA *data = (NNTP_DATA *) list->data;
1109 if (data && data->subscribed && data->unread) {
1110 if (Context && Context->magic == M_NNTP &&
1111 !str_cmp (data->group, ((NNTP_DATA *) Context->data)->group)) {
1112 unsigned int i, unread = 0;
1114 for (i = 0; i < Context->msgcount; i++)
1115 if (!Context->hdrs[i]->read && !Context->hdrs[i]->deleted)
1120 strncpy (dst, data->group, dstlen);