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>
17 #include <lib-lib/str.h>
18 #include <lib-lib/file.h>
19 #include <lib-lib/macros.h>
21 #include <lib-mime/mime.h>
24 #include "mutt_curses.h"
32 #include "lib/debug.h"
41 void nntp_add_to_list (NNTP_SERVER * s, NNTP_DATA * d)
57 static int nntp_parse_newsrc_line (NNTP_SERVER * news, char *line)
60 char group[LONG_STRING];
62 char *p = line, *b, *h;
71 while (*p && (*p != ':' && *p != '!'))
76 if (len > sizeof (group))
78 m_strcpy(group, len, line);
79 if ((data = (NNTP_DATA *) hash_find (news->newsgroups, group)) == NULL) {
80 data = xmalloc(sizeof(NNTP_DATA) + m_strlen(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 = p_new(NEWSRC_ENTRY, x * 2);
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 m_strcpy(dir, sizeof(dir), NewsCacheDir);
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[m_strlen(buf) - 1] = 0; /* strip ending '\n' */
212 if (!m_strncmp(buf, "#: ", 3) &&
213 !m_strcasecmp(buf + 3, news->conn->account.host))
216 while (fgets (buf, sizeof (buf), index)) {
218 while (*cp && *cp != ' ')
223 if (!m_strcmp(buf, "#:"))
225 sscanf (cp + 1, "%s %d %d", file, &l, &m);
226 if (!m_strcmp(buf, "ALL")) {
227 news->cache = m_strdup(file);
228 news->newgroups_time = m;
230 else if (news->newsgroups) {
231 if ((data = (NNTP_DATA *) hash_find (news->newsgroups, buf)) == NULL) {
232 data = xmalloc(sizeof(NNTP_DATA) + m_strlen(buf) + 1);
233 data->group = (char *) data + sizeof (NNTP_DATA);
234 strcpy (data->group, buf);
237 if (news->newsgroups->nelem < news->newsgroups->curnelem * 2)
239 hash_resize (news->newsgroups, news->newsgroups->nelem * 2);
240 hash_insert (news->newsgroups, data->group, data, 0);
241 nntp_add_to_list (news, data);
243 data->cache = m_strdup(file);
245 if (!data->firstMessage || data->lastMessage < m)
247 if (!data->firstMessage)
248 data->firstMessage = l;
249 if (data->lastMessage < m)
250 data->lastMessage = m;
251 data->lastCached = m;
252 if (t || !data->unread)
253 mutt_newsgroup_stat (data);
260 const char *nntp_format_str (char *dest, size_t destlen, char op,
261 const char *src, const char *fmt,
262 const char *ifstring, const char *elsestring,
263 unsigned long data, format_flag flags)
265 char fn[SHORT_STRING], tmp[SHORT_STRING];
269 m_strcpy(fn, sizeof (fn), NewsServer);
271 snprintf (tmp, sizeof (tmp), "%%%ss", fmt);
272 snprintf (dest, destlen, tmp, fn);
278 /* nntp_parse_url: given an NNPT URL, return host, port,
279 * username, password and newsgroup will recognise. */
280 int nntp_parse_url (const char *server, ACCOUNT * acct,
281 char *group, size_t group_len)
289 acct->port = NNTP_PORT;
290 acct->type = M_ACCT_TYPE_NNTP;
292 c = m_strdup(server);
293 url_parse_ciss (&url, c);
295 if (url.scheme == U_NNTP || url.scheme == U_NNTPS) {
296 if (url.scheme == U_NNTPS) {
297 acct->flags |= M_ACCT_SSL;
298 acct->port = NNTP_SSL_PORT;
303 m_strcpy(group, group_len, url.path);
305 ret = mutt_account_fromurl (acct, &url);
312 void nntp_expand_path (char *line, size_t len, ACCOUNT * acct)
316 url.path = m_strdup(line);
317 mutt_account_tourl (acct, &url);
318 url_ciss_tostring (&url, line, len, 0);
323 * Automatically loads a newsrc into memory, if necessary.
324 * Checks the size/mtime of a newsrc file, if it doesn't match, load
325 * again. Hmm, if a system has broken mtimes, this might mean the file
326 * is reloaded every time, which we'd have to fix.
328 * a newsrc file is a line per newsgroup, with the newsgroup, then a
329 * ':' denoting subscribed or '!' denoting unsubscribed, then a
330 * comma separated list of article numbers and ranges.
332 NNTP_SERVER *mutt_select_newsserver (char *server)
334 char file[_POSIX_PATH_MAX];
343 if (!server || !*server) {
344 mutt_error _("No newsserver defined!");
349 buf = p = p_new(char, m_strlen(server) + 10);
350 if (url_check_scheme (server) == U_UNKNOWN) {
351 strcpy (buf, "nntp://");
352 p = strchr (buf, '\0');
356 if ((nntp_parse_url (buf, &acct, file, sizeof (file))) < 0 || *file) {
358 mutt_error (_("%s is an invalid newsserver specification!"), server);
363 conn = mutt_conn_find (NULL, &acct);
367 mutt_FormatString (file, sizeof (file), NONULL (NewsRc), nntp_format_str, 0,
369 mutt_expand_path (file, sizeof (file));
371 serv = (NNTP_SERVER *) conn->data;
375 /* externally modified? */
376 if (serv->stat != stat (file, &sb) || (!serv->stat &&
377 (serv->size != sb.st_size
378 || serv->mtime != sb.st_mtime))) {
379 for (list = serv->list; list; list = list->next) {
380 NNTP_DATA *data = (NNTP_DATA *) list->data;
383 data->subscribed = 0;
389 nntp_clear_cacheindex (serv);
392 if (serv->status == NNTP_BYE)
393 serv->status = NNTP_NONE;
394 nntp_check_newgroups (serv, 0);
399 serv = p_new(NNTP_SERVER, 1);
401 serv->newsrc = m_strdup(file);
402 serv->newsgroups = hash_create (1009);
403 slurp_newsrc (serv); /* load .newsrc */
404 nntp_parse_cacheindex (serv); /* load .index */
405 if (option (OPTNEWSCACHE) && serv->cache && nntp_get_cache_all (serv) >= 0)
406 nntp_check_newgroups (serv, 1);
407 else if (nntp_get_active (serv) < 0) {
408 hash_destroy (&serv->newsgroups, nntp_delete_data);
409 for (list = serv->list; list; list = list->next)
411 mutt_free_list (&serv->list);
412 p_delete(&serv->newsrc);
413 p_delete(&serv->cache);
417 nntp_clear_cacheindex (serv);
418 conn->data = (void *) serv;
424 * full status flags are not supported by nntp, but we can fake some
425 * of them. This is how:
426 * Read = a read message number is in the .newsrc
427 * New = a message is new since we last read this newsgroup
428 * Old = anything else
429 * So, Read is marked as such in the newsrc, old is anything that is
430 * "skipped" in the newsrc, and new is anything not in the newsrc nor
431 * in the cache. By skipped, I mean before the last unread message
433 void nntp_get_status (CONTEXT * ctx, HEADER * h, char *group, int article)
435 NNTP_DATA *data = (NNTP_DATA *) ctx->data;
439 data = (NNTP_DATA *) hash_find (data->nserv->newsgroups, group);
444 debug_print (3, ("newsgroup %s not found\n", group));
449 for (x = 0; x < data->num; x++) {
450 if ((article >= data->entries[x].first) &&
451 (article <= data->entries[x].last)) {
452 /* we cannot use mutt_set_flag() because mx_update_context()
458 /* If article was not cached yet, it is new! :) */
459 if (!data->cache || article > data->lastCached)
461 /* Old articles are articles which aren't read but an article after them
463 if (option (OPTMARKOLD))
467 void mutt_newsgroup_stat (NNTP_DATA * data)
470 unsigned int first, last;
473 if (data->lastMessage == 0 || data->firstMessage > data->lastMessage)
476 data->unread = data->lastMessage - data->firstMessage + 1;
477 for (i = 0; i < data->num; i++) {
478 first = data->entries[i].first;
479 if (first < data->firstMessage)
480 first = data->firstMessage;
481 last = data->entries[i].last;
482 if (last > data->lastMessage)
483 last = data->lastMessage;
485 data->unread -= last - first + 1;
489 static int puti (char *line, int num)
494 *p++ = '0' + num % 10;
498 *line++ = *--p, num++;
503 static void nntp_create_newsrc_line (NNTP_DATA * data, char **buf,
504 char **pline, size_t * buflen)
507 size_t len = *buflen - (*pline - *buf);
510 if (len < LONG_STRING * 10) {
514 p_realloc(buf, *buflen);
515 line = *buf + (*pline - line);
517 strcpy (line, data->group);
518 len -= m_strlen(line) + 1;
519 line += m_strlen(line);
520 *line++ = data->subscribed ? ':' : '!';
524 for (x = 0; x < data->num; x++) {
525 if (len < LONG_STRING) {
530 p_realloc(buf, *buflen);
531 line = *buf + (*pline - line);
539 if (data->entries[x].first == data->entries[x].last)
540 snprintf (line, len, "%d%n", data->entries[x].first, &i);
542 snprintf (line, len, "%d-%d%n",
543 data->entries[x].first, data->entries[x].last, &i);
547 i = puti (line, data->entries[x].first);
550 if (data->entries[x].first != data->entries[x].last) {
553 i = puti (line, data->entries[x].last);
564 void newsrc_gen_entries (CONTEXT * ctx)
566 NNTP_DATA *data = (NNTP_DATA *) ctx->data;
568 unsigned int last = 0, first = 1;
569 int save_sort = SORT_ORDER;
571 if (Sort != SORT_ORDER) {
574 mutt_sort_headers (ctx, 0);
578 data->entries = p_new(NEWSRC_ENTRY, 5);
583 * Set up to fake initial sequence from 1 to the article before the
584 * first article in our list
589 for (x = 0; x < ctx->msgcount; x++) {
590 if (series) { /* search for first unread */
592 * We don't actually check sequential order, since we mark
593 * "missing" entries as read/deleted
595 last = ctx->hdrs[x]->article_num;
596 if (last >= data->firstMessage && !ctx->hdrs[x]->deleted &&
597 !ctx->hdrs[x]->read) {
598 if (data->num >= data->max) {
599 data->max = data->max * 2;
600 p_realloc(&data->entries, data->max);
602 data->entries[data->num].first = first;
603 data->entries[data->num].last = last - 1;
608 else { /* search for first read */
610 if (ctx->hdrs[x]->deleted || ctx->hdrs[x]->read) {
614 last = ctx->hdrs[x]->article_num;
617 if (series && first <= data->lastLoaded) {
618 if (data->num >= data->max) {
619 data->max = data->max * 2;
620 p_realloc(&data->entries, data->max);
622 data->entries[data->num].first = first;
623 data->entries[data->num].last = data->lastLoaded;
627 if (save_sort != Sort) {
629 mutt_sort_headers (ctx, 0);
633 static int mutt_update_list_file (char *filename, char *section,
634 const char *key, char *line) {
637 char buf[HUGE_STRING];
638 char tmpfile[_POSIX_PATH_MAX], link[_POSIX_PATH_MAX];
640 int ext = 0, done = 0, r = 0, l = 0;
642 /* if file not exist, create it */
643 if ((ifp = safe_fopen (filename, "a")))
645 debug_print (1, ("Opening %s\n", filename));
646 if (!(ifp = safe_fopen (filename, "r"))) {
647 mutt_error (_("Unable to open %s for reading"), filename);
650 if (mx_lock_file (filename, fileno (ifp), 0, 0, 1)) {
652 mutt_error (_("Unable to lock %s"), filename);
655 /* use mutt_adv_mktemp() to get a tempfile in the same
656 * directory as filename is so that we can follow symlinks
657 * via rename(2); as dirname(2) may modify its argument,
658 * temporarily use buf as copy of it
660 m_strcpy(buf, sizeof(buf), filename);
661 m_strcpy(tmpfile, sizeof(tmpfile), basename(filename));
662 mutt_adv_mktemp ((const char*) dirname (buf), tmpfile, sizeof (tmpfile));
663 debug_print (1, ("Opening %s\n", tmpfile));
664 if (!(ofp = fopen (tmpfile, "w"))) {
666 mutt_error (_("Unable to open %s for writing"), tmpfile);
671 while (r != EOF && !done && fgets (buf, sizeof (buf), ifp)) {
672 r = fputs (buf, ofp);
674 while (*c && *c != '\n') c++;
675 c[0] = 0; /* strip EOL */
676 if (!strncmp (buf, "#: ", 3) && !m_strcasecmp(buf+3, section))
679 if (r != EOF && !done) {
680 snprintf (buf, sizeof(buf), "#: %s\n", section);
681 r = fputs (buf, ofp);
686 while (r != EOF && fgets (buf, sizeof (buf), ifp)) {
689 while (*c && (*c != '\r') && (*c != '\n')) c++;
691 if (*c != '\\') ext = 0;
692 } else if ((section && !strncmp (buf, "#: ", 3))) {
697 r = fputs (buf, ofp);
700 } else if (key && !strncmp (buf, key, strlen(key)) &&
701 (!*key || buf[strlen(key)] == ' ')) {
704 while (*c && (*c != '\r') && (*c != '\n')) c++;
706 if (*c == '\\') ext = 1;
708 r = fputs (line, ofp);
710 r = fputc ('\n', ofp);
714 r = fputs (buf, ofp);
718 while (r != EOF && fgets (buf, sizeof (buf), ifp))
719 r = fputs (buf, ofp);
721 /* If there wasn't a line to replace, put it on the end of the file */
722 if (r != EOF && !done && line) {
724 r = fputc ('\n', ofp);
726 mx_unlock_file (filename, fileno (ifp), 0);
731 mutt_error (_("Can't write %s"), tmpfile);
735 if ((l = readlink (filename, link, sizeof (link)-1)) > 0)
737 debug_print (1, ("Renaming %s to %s\n",tmpfile, l > 0 ? link : filename));
738 if (rename (tmpfile, l > 0 ? link : filename) < 0) {
740 mutt_error (_("Can't rename %s to %s"), tmpfile, l > 0 ? link : filename);
746 int mutt_newsrc_update (NNTP_SERVER * news)
756 llen = len = 10 * LONG_STRING;
757 line = buf = p_new(char, len);
758 /* we will generate full newsrc here */
759 for (tmp = news->list; tmp; tmp = tmp->next) {
760 data = (NNTP_DATA *) tmp->data;
761 if (!data || !data->rc)
763 nntp_create_newsrc_line (data, &buf, &line, &llen);
764 debug_print (2, ("Added to newsrc: %s\n", line));
765 line += m_strlen(line);
767 /* newrc being fully rewritten */
769 (r = mutt_update_list_file(news->newsrc, NULL, "", buf)) == 0) {
772 stat (news->newsrc, &st);
773 news->size = st.st_size;
774 news->mtime = st.st_mtime;
780 static FILE *mutt_mkname (char *s)
782 char buf[_POSIX_PATH_MAX], *pc;
786 nntp_cache_expand (buf, s);
787 if ((fp = safe_fopen (buf, "w")))
790 nntp_cache_expand (buf, "cache-XXXXXX");
791 pc = buf + m_strlen(buf) - 12; /* positioning to "cache-XXXXXX" */
792 if ((fd = mkstemp (buf)) == -1)
794 strcpy (s, pc); /* generated name */
795 return fdopen (fd, "w");
798 /* Updates info into .index file: ALL or about selected newsgroup */
799 static int nntp_update_cacheindex (NNTP_SERVER * serv, NNTP_DATA * data)
801 char buf[LONG_STRING];
802 char file[_POSIX_PATH_MAX];
803 const char *key = "ALL";
805 if (!serv || !serv->conn || !serv->conn->account.host)
808 if (data && data->group) {
810 snprintf (buf, sizeof (buf), "%s %s %d %d", key, data->cache,
811 data->firstMessage, data->lastLoaded);
814 m_strcpy(file, sizeof(file), serv->cache);
815 snprintf (buf, sizeof (buf), "ALL %s 0 %d", file,
816 (int) serv->newgroups_time);
818 nntp_cache_expand (file, ".index");
819 return mutt_update_list_file (file, serv->conn->account.host, key, buf);
822 /* Remove cache files of unsubscribed newsgroups */
823 void nntp_clear_cacheindex (NNTP_SERVER * news)
828 if (option (OPTSAVEUNSUB) || !news)
831 for (tmp = news->list; tmp; tmp = tmp->next) {
832 data = (NNTP_DATA *) tmp->data;
833 if (!data || data->subscribed || !data->cache)
835 nntp_delete_cache (data);
836 debug_print (2, ("Removed from .index: %s\n", data->group));
841 int nntp_save_cache_index (NNTP_SERVER * news)
843 char buf[HUGE_STRING];
844 char file[_POSIX_PATH_MAX];
849 if (!news || !news->newsgroups)
851 if (!option (OPTNEWSCACHE))
855 nntp_cache_expand (file, news->cache);
857 f = safe_fopen (file, "w");
860 m_strcpy(buf, sizeof(buf), news->conn->account.host);
861 f = mutt_mkname (buf);
862 news->cache = m_strdup(buf);
863 nntp_cache_expand (file, buf);
868 for (l = news->list; l; l = l->next) {
869 if ((d = (NNTP_DATA *) l->data) && !d->deleted) {
871 snprintf (buf, sizeof (buf), "%s %d %d %c %s\n", d->group,
872 d->lastMessage, d->firstMessage, d->allowed ? 'y' : 'n',
875 snprintf (buf, sizeof (buf), "%s %d %d %c\n", d->group,
876 d->lastMessage, d->firstMessage, d->allowed ? 'y' : 'n');
877 if (fputs (buf, f) == EOF) {
886 if (nntp_update_cacheindex (news, NULL)) {
893 int nntp_save_cache_group (CONTEXT * ctx)
895 char buf[HUGE_STRING], addr[STRING];
896 char file[_POSIX_PATH_MAX];
900 int i = 0, save = SORT_ORDER;
903 if (!option (OPTNEWSCACHE))
905 if (!ctx || !ctx->data || ctx->magic != M_NNTP)
908 if (((NNTP_DATA *) ctx->data)->cache) {
909 nntp_cache_expand (file, ((NNTP_DATA *) ctx->data)->cache);
911 f = safe_fopen (file, "w");
914 snprintf (buf, sizeof (buf), "%s-%s",
915 ((NNTP_DATA *) ctx->data)->nserv->conn->account.host,
916 ((NNTP_DATA *) ctx->data)->group);
917 f = mutt_mkname (buf);
918 ((NNTP_DATA *) ctx->data)->cache = m_strdup(buf);
919 nntp_cache_expand (file, buf);
924 if (Sort != SORT_ORDER) {
927 mutt_sort_headers (ctx, 0);
930 /* Save only $nntp_context messages... */
931 ((NNTP_DATA *) ctx->data)->lastCached = 0;
932 if (NntpContext && ctx->msgcount > NntpContext)
933 i = ctx->msgcount - NntpContext;
934 for (; i < ctx->msgcount; i++) {
935 if (!ctx->hdrs[i]->deleted && ctx->hdrs[i]->article_num != prev) {
938 rfc822_write_address (addr, sizeof (addr), h->env->from, 0);
939 tm = gmtime (&h->date_sent);
940 snprintf (buf, sizeof (buf),
941 "%d\t%s\t%s\t%d %s %d %02d:%02d:%02d GMT\t%s\t",
942 h->article_num, h->env->subject, addr, tm->tm_mday,
943 Months[tm->tm_mon], tm->tm_year + 1900, tm->tm_hour,
944 tm->tm_min, tm->tm_sec, h->env->message_id);
946 if (h->env->references)
947 mutt_write_references (h->env->references, f);
948 snprintf (buf, sizeof (buf), "\t%zd\t%d\tXref: %s\n",
949 h->content->length, h->lines, NONULL (h->env->xref));
950 if (fputs (buf, f) == EOF) {
956 prev = ctx->hdrs[i]->article_num;
961 mutt_sort_headers (ctx, 0);
965 if (nntp_update_cacheindex (((NNTP_DATA *) ctx->data)->nserv,
966 (NNTP_DATA *) ctx->data)) {
970 ((NNTP_DATA *) ctx->data)->lastCached =
971 ((NNTP_DATA *) ctx->data)->lastLoaded;
975 void nntp_delete_cache (NNTP_DATA * data)
977 char buf[_POSIX_PATH_MAX];
979 if (!option (OPTNEWSCACHE) || !data || !data->cache || !data->nserv)
982 nntp_cache_expand (buf, data->cache);
984 p_delete(&data->cache);
985 data->lastCached = 0;
986 nntp_cache_expand (buf, ".index");
987 mutt_update_list_file (buf, data->nserv->conn->account.host, data->group,
991 NNTP_DATA *mutt_newsgroup_subscribe (NNTP_SERVER * news, char *group)
995 if (!news || !news->newsgroups || !group || !*group)
997 if (!(data = (NNTP_DATA *) hash_find (news->newsgroups, group))) {
998 data = xmalloc(sizeof(NNTP_DATA) + m_strlen(group) + 1);
999 data->group = (char *) data + sizeof (NNTP_DATA);
1000 strcpy (data->group, group);
1003 if (news->newsgroups->nelem < news->newsgroups->curnelem * 2)
1005 hash_resize (news->newsgroups, news->newsgroups->nelem * 2);
1006 hash_insert (news->newsgroups, data->group, data, 0);
1007 nntp_add_to_list (news, data);
1009 if (!data->subscribed) {
1010 data->subscribed = 1;
1016 NNTP_DATA *mutt_newsgroup_unsubscribe (NNTP_SERVER * news, char *group)
1020 if (!news || !news->newsgroups || !group || !*group ||
1021 !(data = (NNTP_DATA *) hash_find (news->newsgroups, group)))
1023 if (data->subscribed) {
1024 data->subscribed = 0;
1025 if (!option (OPTSAVEUNSUB))
1031 NNTP_DATA *mutt_newsgroup_catchup (NNTP_SERVER * news, char *group)
1035 if (!news || !news->newsgroups || !group || !*group ||
1036 !(data = (NNTP_DATA *) hash_find (news->newsgroups, group)))
1039 data->entries = p_new(NEWSRC_ENTRY, 5);
1043 data->entries[0].first = 1;
1045 data->entries[0].last = data->lastMessage;
1046 if (Context && Context->data == data) {
1049 for (x = 0; x < Context->msgcount; x++)
1050 mutt_set_flag (Context, Context->hdrs[x], M_READ, 1);
1055 NNTP_DATA *mutt_newsgroup_uncatchup (NNTP_SERVER * news, char *group)
1059 if (!news || !news->newsgroups || !group || !*group ||
1060 !(data = (NNTP_DATA *) hash_find (news->newsgroups, group)))
1063 data->entries = p_new(NEWSRC_ENTRY, 5);
1067 data->entries[0].first = 1;
1068 data->entries[0].last = data->firstMessage - 1;
1069 if (Context && Context->data == data) {
1072 data->unread = Context->msgcount;
1073 for (x = 0; x < Context->msgcount; x++)
1074 mutt_set_flag (Context, Context->hdrs[x], M_READ, 0);
1077 data->unread = data->lastMessage - data->entries[0].last;
1081 /* this routine gives the first newsgroup with new messages */
1082 void nntp_buffy (char* dst, size_t dstlen) {
1086 /* forward to current group */
1087 for (list = CurrentNewsSrv->list; list; list = list->next) {
1088 NNTP_DATA *data = (NNTP_DATA *) list->data;
1089 if (data && data->subscribed && data->unread &&
1090 Context && Context->magic == M_NNTP &&
1091 m_strcmp(data->group, ((NNTP_DATA *) Context->data)->group) == 0) {
1102 list = CurrentNewsSrv->list;
1104 for (; list; list = list->next) {
1105 NNTP_DATA *data = (NNTP_DATA *) list->data;
1107 if (data && data->subscribed && data->unread) {
1108 if (Context && Context->magic == M_NNTP &&
1109 !m_strcmp(data->group, ((NNTP_DATA *) Context->data)->group)) {
1110 unsigned int i, unread = 0;
1112 for (i = 0; i < Context->msgcount; i++)
1113 if (!Context->hdrs[i]->read && !Context->hdrs[i]->deleted)
1118 m_strcpy(dst, dstlen, data->group);