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/macros.h>
21 #include "mutt_curses.h"
30 #include "lib/debug.h"
39 void nntp_add_to_list (NNTP_SERVER * s, NNTP_DATA * d)
55 static int nntp_parse_newsrc_line (NNTP_SERVER * news, char *line)
58 char group[LONG_STRING];
60 char *p = line, *b, *h;
69 while (*p && (*p != ':' && *p != '!'))
74 if (len > sizeof (group))
76 strfcpy (group, line, len);
77 if ((data = (NNTP_DATA *) hash_find (news->newsgroups, group)) == NULL) {
78 data = xmalloc(sizeof(NNTP_DATA) + m_strlen(group) + 1);
79 data->group = (char *) data + sizeof (NNTP_DATA);
80 strcpy (data->group, group);
83 if (news->newsgroups->nelem < news->newsgroups->curnelem * 2)
85 hash_resize (news->newsgroups, news->newsgroups->nelem * 2);
86 hash_insert (news->newsgroups, data->group, data, 0);
87 nntp_add_to_list (news, data);
90 p_delete(&data->entries);
93 data->entries = p_new(NEWSRC_ENTRY, x * 2);
105 while (*p && *p != ',' && *p != '\n')
111 if ((h = strchr (b, '-'))) {
114 data->entries[x].first = atoi (b);
115 data->entries[x].last = atoi (h);
118 data->entries[x].first = atoi (b);
119 data->entries[x].last = data->entries[x].first;
122 if (data->entries[x].last != 0)
125 if (x && !data->lastMessage)
126 data->lastMessage = data->entries[x - 1].last;
128 mutt_newsgroup_stat (data);
129 debug_print (2, ("Newsgroup %s\n", data->group));
134 static int slurp_newsrc (NNTP_SERVER * news)
140 news->stat = stat (news->newsrc, &sb);
141 news->size = sb.st_size;
142 news->mtime = sb.st_mtime;
144 if ((fp = safe_fopen (news->newsrc, "r")) == NULL)
146 /* hmm, should we use dotlock? */
147 if (mx_lock_file (news->newsrc, fileno (fp), 0, 0, 1)) {
152 buf = p_new(char, sb.st_size + 1);
153 while (fgets (buf, sb.st_size + 1, fp))
154 nntp_parse_newsrc_line (news, buf);
157 mx_unlock_file (news->newsrc, fileno (fp), 0);
162 void nntp_cache_expand (char *dst, const char *src)
164 snprintf (dst, _POSIX_PATH_MAX, "%s/%s", NewsCacheDir, src);
165 mutt_expand_path (dst, _POSIX_PATH_MAX);
168 /* Loads $news_cache_dir/.index into memory, loads newsserver data
169 * and newsgroup cache names */
170 static int nntp_parse_cacheindex (NNTP_SERVER * news)
173 char buf[HUGE_STRING], *cp;
174 char dir[_POSIX_PATH_MAX], file[_POSIX_PATH_MAX];
179 /* check is server name defined or not */
180 if (!news || !news->conn || !news->conn->account.host)
182 unset_option (OPTNEWSCACHE);
183 if (!NewsCacheDir || !*NewsCacheDir)
186 strfcpy (dir, NewsCacheDir, sizeof (dir));
187 mutt_expand_path (dir, sizeof (dir));
189 if (lstat (dir, &st) || (st.st_mode & S_IFDIR) == 0) {
190 snprintf (buf, sizeof (buf), _("Directory %s not exist. Create it?"),
192 if (mutt_yesorno (buf, M_YES) != M_YES
193 || mkdir (dir, (S_IRWXU + S_IRWXG + S_IRWXO))) {
194 mutt_error _("Cache directory not created!");
201 set_option (OPTNEWSCACHE);
203 p_delete(&news->cache);
204 snprintf (buf, sizeof (buf), "%s/.index", dir);
205 if (!(index = safe_fopen (buf, "a+")))
208 while (fgets (buf, sizeof (buf), index)) {
209 buf[m_strlen(buf) - 1] = 0; /* strip ending '\n' */
210 if (!str_ncmp (buf, "#: ", 3) &&
211 !str_casecmp (buf + 3, news->conn->account.host))
214 while (fgets (buf, sizeof (buf), index)) {
216 while (*cp && *cp != ' ')
221 if (!str_cmp (buf, "#:"))
223 sscanf (cp + 1, "%s %d %d", file, &l, &m);
224 if (!str_cmp (buf, "ALL")) {
225 news->cache = m_strdup(file);
226 news->newgroups_time = m;
228 else if (news->newsgroups) {
229 if ((data = (NNTP_DATA *) hash_find (news->newsgroups, buf)) == NULL) {
230 data = xmalloc(sizeof(NNTP_DATA) + m_strlen(buf) + 1);
231 data->group = (char *) data + sizeof (NNTP_DATA);
232 strcpy (data->group, buf);
235 if (news->newsgroups->nelem < news->newsgroups->curnelem * 2)
237 hash_resize (news->newsgroups, news->newsgroups->nelem * 2);
238 hash_insert (news->newsgroups, data->group, data, 0);
239 nntp_add_to_list (news, data);
241 data->cache = m_strdup(file);
243 if (!data->firstMessage || data->lastMessage < m)
245 if (!data->firstMessage)
246 data->firstMessage = l;
247 if (data->lastMessage < m)
248 data->lastMessage = m;
249 data->lastCached = m;
250 if (t || !data->unread)
251 mutt_newsgroup_stat (data);
258 const char *nntp_format_str (char *dest, size_t destlen, char op,
259 const char *src, const char *fmt,
260 const char *ifstring, const char *elsestring,
261 unsigned long data, format_flag flags)
263 char fn[SHORT_STRING], tmp[SHORT_STRING];
267 strncpy (fn, NewsServer, sizeof (fn) - 1);
269 snprintf (tmp, sizeof (tmp), "%%%ss", fmt);
270 snprintf (dest, destlen, tmp, fn);
276 /* nntp_parse_url: given an NNPT URL, return host, port,
277 * username, password and newsgroup will recognise. */
278 int nntp_parse_url (const char *server, ACCOUNT * acct,
279 char *group, size_t group_len)
287 acct->port = NNTP_PORT;
288 acct->type = M_ACCT_TYPE_NNTP;
290 c = m_strdup(server);
291 url_parse_ciss (&url, c);
293 if (url.scheme == U_NNTP || url.scheme == U_NNTPS) {
294 if (url.scheme == U_NNTPS) {
295 acct->flags |= M_ACCT_SSL;
296 acct->port = NNTP_SSL_PORT;
301 strfcpy (group, url.path, group_len);
303 ret = mutt_account_fromurl (acct, &url);
310 void nntp_expand_path (char *line, size_t len, ACCOUNT * acct)
314 url.path = m_strdup(line);
315 mutt_account_tourl (acct, &url);
316 url_ciss_tostring (&url, line, len, 0);
321 * Automatically loads a newsrc into memory, if necessary.
322 * Checks the size/mtime of a newsrc file, if it doesn't match, load
323 * again. Hmm, if a system has broken mtimes, this might mean the file
324 * is reloaded every time, which we'd have to fix.
326 * a newsrc file is a line per newsgroup, with the newsgroup, then a
327 * ':' denoting subscribed or '!' denoting unsubscribed, then a
328 * comma separated list of article numbers and ranges.
330 NNTP_SERVER *mutt_select_newsserver (char *server)
332 char file[_POSIX_PATH_MAX];
339 memset (&acct, 0, sizeof (ACCOUNT));
341 if (!server || !*server) {
342 mutt_error _("No newsserver defined!");
347 buf = p = p_new(char, m_strlen(server) + 10);
348 if (url_check_scheme (server) == U_UNKNOWN) {
349 strcpy (buf, "nntp://");
350 p = strchr (buf, '\0');
354 if ((nntp_parse_url (buf, &acct, file, sizeof (file))) < 0 || *file) {
356 mutt_error (_("%s is an invalid newsserver specification!"), server);
361 conn = mutt_conn_find (NULL, &acct);
365 mutt_FormatString (file, sizeof (file), NONULL (NewsRc), nntp_format_str, 0,
367 mutt_expand_path (file, sizeof (file));
369 serv = (NNTP_SERVER *) conn->data;
373 /* externally modified? */
374 if (serv->stat != stat (file, &sb) || (!serv->stat &&
375 (serv->size != sb.st_size
376 || serv->mtime != sb.st_mtime))) {
377 for (list = serv->list; list; list = list->next) {
378 NNTP_DATA *data = (NNTP_DATA *) list->data;
381 data->subscribed = 0;
387 nntp_clear_cacheindex (serv);
390 if (serv->status == NNTP_BYE)
391 serv->status = NNTP_NONE;
392 nntp_check_newgroups (serv, 0);
397 serv = p_new(NNTP_SERVER, 1);
399 serv->newsrc = m_strdup(file);
400 serv->newsgroups = hash_create (1009);
401 slurp_newsrc (serv); /* load .newsrc */
402 nntp_parse_cacheindex (serv); /* load .index */
403 if (option (OPTNEWSCACHE) && serv->cache && nntp_get_cache_all (serv) >= 0)
404 nntp_check_newgroups (serv, 1);
405 else if (nntp_get_active (serv) < 0) {
406 hash_destroy (&serv->newsgroups, nntp_delete_data);
407 for (list = serv->list; list; list = list->next)
409 mutt_free_list (&serv->list);
410 p_delete(&serv->newsrc);
411 p_delete(&serv->cache);
415 nntp_clear_cacheindex (serv);
416 conn->data = (void *) serv;
422 * full status flags are not supported by nntp, but we can fake some
423 * of them. This is how:
424 * Read = a read message number is in the .newsrc
425 * New = a message is new since we last read this newsgroup
426 * Old = anything else
427 * So, Read is marked as such in the newsrc, old is anything that is
428 * "skipped" in the newsrc, and new is anything not in the newsrc nor
429 * in the cache. By skipped, I mean before the last unread message
431 void nntp_get_status (CONTEXT * ctx, HEADER * h, char *group, int article)
433 NNTP_DATA *data = (NNTP_DATA *) ctx->data;
437 data = (NNTP_DATA *) hash_find (data->nserv->newsgroups, group);
442 debug_print (3, ("newsgroup %s not found\n", group));
447 for (x = 0; x < data->num; x++) {
448 if ((article >= data->entries[x].first) &&
449 (article <= data->entries[x].last)) {
450 /* we cannot use mutt_set_flag() because mx_update_context()
456 /* If article was not cached yet, it is new! :) */
457 if (!data->cache || article > data->lastCached)
459 /* Old articles are articles which aren't read but an article after them
461 if (option (OPTMARKOLD))
465 void mutt_newsgroup_stat (NNTP_DATA * data)
468 unsigned int first, last;
471 if (data->lastMessage == 0 || data->firstMessage > data->lastMessage)
474 data->unread = data->lastMessage - data->firstMessage + 1;
475 for (i = 0; i < data->num; i++) {
476 first = data->entries[i].first;
477 if (first < data->firstMessage)
478 first = data->firstMessage;
479 last = data->entries[i].last;
480 if (last > data->lastMessage)
481 last = data->lastMessage;
483 data->unread -= last - first + 1;
487 static int puti (char *line, int num)
492 *p++ = '0' + num % 10;
496 *line++ = *--p, num++;
501 static void nntp_create_newsrc_line (NNTP_DATA * data, char **buf,
502 char **pline, size_t * buflen)
505 size_t len = *buflen - (*pline - *buf);
508 if (len < LONG_STRING * 10) {
512 p_realloc(buf, *buflen);
513 line = *buf + (*pline - line);
515 strcpy (line, data->group);
516 len -= m_strlen(line) + 1;
517 line += m_strlen(line);
518 *line++ = data->subscribed ? ':' : '!';
522 for (x = 0; x < data->num; x++) {
523 if (len < LONG_STRING) {
528 p_realloc(buf, *buflen);
529 line = *buf + (*pline - line);
537 if (data->entries[x].first == data->entries[x].last)
538 snprintf (line, len, "%d%n", data->entries[x].first, &i);
540 snprintf (line, len, "%d-%d%n",
541 data->entries[x].first, data->entries[x].last, &i);
545 i = puti (line, data->entries[x].first);
548 if (data->entries[x].first != data->entries[x].last) {
551 i = puti (line, data->entries[x].last);
562 void newsrc_gen_entries (CONTEXT * ctx)
564 NNTP_DATA *data = (NNTP_DATA *) ctx->data;
566 unsigned int last = 0, first = 1;
567 int save_sort = SORT_ORDER;
569 if (Sort != SORT_ORDER) {
572 mutt_sort_headers (ctx, 0);
576 data->entries = p_new(NEWSRC_ENTRY, 5);
581 * Set up to fake initial sequence from 1 to the article before the
582 * first article in our list
587 for (x = 0; x < ctx->msgcount; x++) {
588 if (series) { /* search for first unread */
590 * We don't actually check sequential order, since we mark
591 * "missing" entries as read/deleted
593 last = ctx->hdrs[x]->article_num;
594 if (last >= data->firstMessage && !ctx->hdrs[x]->deleted &&
595 !ctx->hdrs[x]->read) {
596 if (data->num >= data->max) {
597 data->max = data->max * 2;
598 p_realloc(&data->entries, data->max);
600 data->entries[data->num].first = first;
601 data->entries[data->num].last = last - 1;
606 else { /* search for first read */
608 if (ctx->hdrs[x]->deleted || ctx->hdrs[x]->read) {
612 last = ctx->hdrs[x]->article_num;
615 if (series && first <= data->lastLoaded) {
616 if (data->num >= data->max) {
617 data->max = data->max * 2;
618 p_realloc(&data->entries, data->max);
620 data->entries[data->num].first = first;
621 data->entries[data->num].last = data->lastLoaded;
625 if (save_sort != Sort) {
627 mutt_sort_headers (ctx, 0);
631 static int mutt_update_list_file (char *filename, char *section,
632 char *key, char *line) {
635 char buf[HUGE_STRING];
636 char tmpfile[_POSIX_PATH_MAX], link[_POSIX_PATH_MAX];
638 int ext = 0, done = 0, r = 0, l = 0;
640 /* if file not exist, create it */
641 if ((ifp = safe_fopen (filename, "a")))
643 debug_print (1, ("Opening %s\n", filename));
644 if (!(ifp = safe_fopen (filename, "r"))) {
645 mutt_error (_("Unable to open %s for reading"), filename);
648 if (mx_lock_file (filename, fileno (ifp), 0, 0, 1)) {
650 mutt_error (_("Unable to lock %s"), filename);
653 /* use mutt_adv_mktemp() to get a tempfile in the same
654 * directory as filename is so that we can follow symlinks
655 * via rename(2); as dirname(2) may modify its argument,
656 * temporarily use buf as copy of it
658 strncpy (buf, filename, sizeof (buf));
659 strncpy (tmpfile, basename (filename), sizeof (tmpfile));
660 mutt_adv_mktemp ((const char*) dirname (buf), tmpfile, sizeof (tmpfile));
661 debug_print (1, ("Opening %s\n", tmpfile));
662 if (!(ofp = fopen (tmpfile, "w"))) {
664 mutt_error (_("Unable to open %s for writing"), tmpfile);
669 while (r != EOF && !done && fgets (buf, sizeof (buf), ifp)) {
670 r = fputs (buf, ofp);
672 while (*c && *c != '\n') c++;
673 c[0] = 0; /* strip EOL */
674 if (!strncmp (buf, "#: ", 3) && !str_casecmp (buf+3, section))
677 if (r != EOF && !done) {
678 snprintf (buf, sizeof(buf), "#: %s\n", section);
679 r = fputs (buf, ofp);
684 while (r != EOF && fgets (buf, sizeof (buf), ifp)) {
687 while (*c && (*c != '\r') && (*c != '\n')) c++;
689 if (*c != '\\') ext = 0;
690 } else if ((section && !strncmp (buf, "#: ", 3))) {
695 r = fputs (buf, ofp);
698 } else if (key && !strncmp (buf, key, strlen(key)) &&
699 (!*key || buf[strlen(key)] == ' ')) {
702 while (*c && (*c != '\r') && (*c != '\n')) c++;
704 if (*c == '\\') ext = 1;
706 r = fputs (line, ofp);
708 r = fputc ('\n', ofp);
712 r = fputs (buf, ofp);
716 while (r != EOF && fgets (buf, sizeof (buf), ifp))
717 r = fputs (buf, ofp);
719 /* If there wasn't a line to replace, put it on the end of the file */
720 if (r != EOF && !done && line) {
722 r = fputc ('\n', ofp);
724 mx_unlock_file (filename, fileno (ifp), 0);
729 mutt_error (_("Can't write %s"), tmpfile);
733 if ((l = readlink (filename, link, sizeof (link)-1)) > 0)
735 debug_print (1, ("Renaming %s to %s\n",tmpfile, l > 0 ? link : filename));
736 if (rename (tmpfile, l > 0 ? link : filename) < 0) {
738 mutt_error (_("Can't rename %s to %s"), tmpfile, l > 0 ? link : filename);
744 int mutt_newsrc_update (NNTP_SERVER * news)
754 llen = len = 10 * LONG_STRING;
755 line = buf = p_new(char, len);
756 /* we will generate full newsrc here */
757 for (tmp = news->list; tmp; tmp = tmp->next) {
758 data = (NNTP_DATA *) tmp->data;
759 if (!data || !data->rc)
761 nntp_create_newsrc_line (data, &buf, &line, &llen);
762 debug_print (2, ("Added to newsrc: %s\n", line));
763 line += m_strlen(line);
765 /* newrc being fully rewritten */
767 (r = mutt_update_list_file (news->newsrc, NULL, "", buf)) == 0) {
770 stat (news->newsrc, &st);
771 news->size = st.st_size;
772 news->mtime = st.st_mtime;
778 static FILE *mutt_mkname (char *s)
780 char buf[_POSIX_PATH_MAX], *pc;
784 nntp_cache_expand (buf, s);
785 if ((fp = safe_fopen (buf, "w")))
788 nntp_cache_expand (buf, "cache-XXXXXX");
789 pc = buf + m_strlen(buf) - 12; /* positioning to "cache-XXXXXX" */
790 if ((fd = mkstemp (buf)) == -1)
792 strcpy (s, pc); /* generated name */
793 return fdopen (fd, "w");
796 /* Updates info into .index file: ALL or about selected newsgroup */
797 static int nntp_update_cacheindex (NNTP_SERVER * serv, NNTP_DATA * data)
799 char buf[LONG_STRING], *key = "ALL";
800 char file[_POSIX_PATH_MAX];
802 if (!serv || !serv->conn || !serv->conn->account.host)
805 if (data && data->group) {
807 snprintf (buf, sizeof (buf), "%s %s %d %d", key, data->cache,
808 data->firstMessage, data->lastLoaded);
811 strfcpy (file, serv->cache, sizeof (file));
812 snprintf (buf, sizeof (buf), "ALL %s 0 %d", file,
813 (int) serv->newgroups_time);
815 nntp_cache_expand (file, ".index");
816 return mutt_update_list_file (file, serv->conn->account.host, key, buf);
819 /* Remove cache files of unsubscribed newsgroups */
820 void nntp_clear_cacheindex (NNTP_SERVER * news)
825 if (option (OPTSAVEUNSUB) || !news)
828 for (tmp = news->list; tmp; tmp = tmp->next) {
829 data = (NNTP_DATA *) tmp->data;
830 if (!data || data->subscribed || !data->cache)
832 nntp_delete_cache (data);
833 debug_print (2, ("Removed from .index: %s\n", data->group));
838 int nntp_save_cache_index (NNTP_SERVER * news)
840 char buf[HUGE_STRING];
841 char file[_POSIX_PATH_MAX];
846 if (!news || !news->newsgroups)
848 if (!option (OPTNEWSCACHE))
852 nntp_cache_expand (file, news->cache);
854 f = safe_fopen (file, "w");
857 strfcpy (buf, news->conn->account.host, sizeof (buf));
858 f = mutt_mkname (buf);
859 news->cache = m_strdup(buf);
860 nntp_cache_expand (file, buf);
865 for (l = news->list; l; l = l->next) {
866 if ((d = (NNTP_DATA *) l->data) && !d->deleted) {
868 snprintf (buf, sizeof (buf), "%s %d %d %c %s\n", d->group,
869 d->lastMessage, d->firstMessage, d->allowed ? 'y' : 'n',
872 snprintf (buf, sizeof (buf), "%s %d %d %c\n", d->group,
873 d->lastMessage, d->firstMessage, d->allowed ? 'y' : 'n');
874 if (fputs (buf, f) == EOF) {
883 if (nntp_update_cacheindex (news, NULL)) {
890 int nntp_save_cache_group (CONTEXT * ctx)
892 char buf[HUGE_STRING], addr[STRING];
893 char file[_POSIX_PATH_MAX];
897 int i = 0, save = SORT_ORDER;
900 if (!option (OPTNEWSCACHE))
902 if (!ctx || !ctx->data || ctx->magic != M_NNTP)
905 if (((NNTP_DATA *) ctx->data)->cache) {
906 nntp_cache_expand (file, ((NNTP_DATA *) ctx->data)->cache);
908 f = safe_fopen (file, "w");
911 snprintf (buf, sizeof (buf), "%s-%s",
912 ((NNTP_DATA *) ctx->data)->nserv->conn->account.host,
913 ((NNTP_DATA *) ctx->data)->group);
914 f = mutt_mkname (buf);
915 ((NNTP_DATA *) ctx->data)->cache = m_strdup(buf);
916 nntp_cache_expand (file, buf);
921 if (Sort != SORT_ORDER) {
924 mutt_sort_headers (ctx, 0);
927 /* Save only $nntp_context messages... */
928 ((NNTP_DATA *) ctx->data)->lastCached = 0;
929 if (NntpContext && ctx->msgcount > NntpContext)
930 i = ctx->msgcount - NntpContext;
931 for (; i < ctx->msgcount; i++) {
932 if (!ctx->hdrs[i]->deleted && ctx->hdrs[i]->article_num != prev) {
935 rfc822_write_address (addr, sizeof (addr), h->env->from, 0);
936 tm = gmtime (&h->date_sent);
937 snprintf (buf, sizeof (buf),
938 "%d\t%s\t%s\t%d %s %d %02d:%02d:%02d GMT\t%s\t",
939 h->article_num, h->env->subject, addr, tm->tm_mday,
940 Months[tm->tm_mon], tm->tm_year + 1900, tm->tm_hour,
941 tm->tm_min, tm->tm_sec, h->env->message_id);
943 if (h->env->references)
944 mutt_write_references (h->env->references, f);
945 snprintf (buf, sizeof (buf), "\t%zd\t%d\tXref: %s\n",
946 h->content->length, h->lines, NONULL (h->env->xref));
947 if (fputs (buf, f) == EOF) {
953 prev = ctx->hdrs[i]->article_num;
958 mutt_sort_headers (ctx, 0);
962 if (nntp_update_cacheindex (((NNTP_DATA *) ctx->data)->nserv,
963 (NNTP_DATA *) ctx->data)) {
967 ((NNTP_DATA *) ctx->data)->lastCached =
968 ((NNTP_DATA *) ctx->data)->lastLoaded;
972 void nntp_delete_cache (NNTP_DATA * data)
974 char buf[_POSIX_PATH_MAX];
976 if (!option (OPTNEWSCACHE) || !data || !data->cache || !data->nserv)
979 nntp_cache_expand (buf, data->cache);
981 p_delete(&data->cache);
982 data->lastCached = 0;
983 nntp_cache_expand (buf, ".index");
984 mutt_update_list_file (buf, data->nserv->conn->account.host, data->group,
988 NNTP_DATA *mutt_newsgroup_subscribe (NNTP_SERVER * news, char *group)
992 if (!news || !news->newsgroups || !group || !*group)
994 if (!(data = (NNTP_DATA *) hash_find (news->newsgroups, group))) {
995 data = xmalloc(sizeof(NNTP_DATA) + m_strlen(group) + 1);
996 data->group = (char *) data + sizeof (NNTP_DATA);
997 strcpy (data->group, group);
1000 if (news->newsgroups->nelem < news->newsgroups->curnelem * 2)
1002 hash_resize (news->newsgroups, news->newsgroups->nelem * 2);
1003 hash_insert (news->newsgroups, data->group, data, 0);
1004 nntp_add_to_list (news, data);
1006 if (!data->subscribed) {
1007 data->subscribed = 1;
1013 NNTP_DATA *mutt_newsgroup_unsubscribe (NNTP_SERVER * news, char *group)
1017 if (!news || !news->newsgroups || !group || !*group ||
1018 !(data = (NNTP_DATA *) hash_find (news->newsgroups, group)))
1020 if (data->subscribed) {
1021 data->subscribed = 0;
1022 if (!option (OPTSAVEUNSUB))
1028 NNTP_DATA *mutt_newsgroup_catchup (NNTP_SERVER * news, char *group)
1032 if (!news || !news->newsgroups || !group || !*group ||
1033 !(data = (NNTP_DATA *) hash_find (news->newsgroups, group)))
1036 data->entries = p_new(NEWSRC_ENTRY, 5);
1040 data->entries[0].first = 1;
1042 data->entries[0].last = data->lastMessage;
1043 if (Context && Context->data == data) {
1046 for (x = 0; x < Context->msgcount; x++)
1047 mutt_set_flag (Context, Context->hdrs[x], M_READ, 1);
1052 NNTP_DATA *mutt_newsgroup_uncatchup (NNTP_SERVER * news, char *group)
1056 if (!news || !news->newsgroups || !group || !*group ||
1057 !(data = (NNTP_DATA *) hash_find (news->newsgroups, group)))
1060 data->entries = p_new(NEWSRC_ENTRY, 5);
1064 data->entries[0].first = 1;
1065 data->entries[0].last = data->firstMessage - 1;
1066 if (Context && Context->data == data) {
1069 data->unread = Context->msgcount;
1070 for (x = 0; x < Context->msgcount; x++)
1071 mutt_set_flag (Context, Context->hdrs[x], M_READ, 0);
1074 data->unread = data->lastMessage - data->entries[0].last;
1078 /* this routine gives the first newsgroup with new messages */
1079 void nntp_buffy (char* dst, size_t dstlen) {
1083 /* forward to current group */
1084 for (list = CurrentNewsSrv->list; list; list = list->next) {
1085 NNTP_DATA *data = (NNTP_DATA *) list->data;
1086 if (data && data->subscribed && data->unread &&
1087 Context && Context->magic == M_NNTP &&
1088 str_cmp (data->group, ((NNTP_DATA *) Context->data)->group) == 0) {
1099 list = CurrentNewsSrv->list;
1101 for (; list; list = list->next) {
1102 NNTP_DATA *data = (NNTP_DATA *) list->data;
1104 if (data && data->subscribed && data->unread) {
1105 if (Context && Context->magic == M_NNTP &&
1106 !str_cmp (data->group, ((NNTP_DATA *) Context->data)->group)) {
1107 unsigned int i, unread = 0;
1109 for (i = 0; i < Context->msgcount; i++)
1110 if (!Context->hdrs[i]->read && !Context->hdrs[i]->deleted)
1115 strncpy (dst, data->group, dstlen);