+static int add_group (char *buf, void *serv)
+{
+ nntp_server_t *s = serv;
+ char group[LONG_STRING], mod, desc[HUGE_STRING];
+ int first, last;
+ nntp_data_t *nntp_data;
+ static int n = 0;
+
+ _checked = n; /* _checked have N, where N = number of groups */
+ if (!buf) /* at EOF must be zerouth */
+ n = 0;
+
+ if (!s || !buf)
+ return 0;
+
+ *desc = 0;
+ sscanf (buf, "%s %d %d %c %[^\n]", group, &last, &first, &mod, desc);
+ if (!group)
+ return 0;
+ if ((nntp_data = hash_find(s->newsgroups, group)) == NULL) {
+ n++;
+ nntp_data = nntp_data_new();
+ nntp_data->group = m_strdup(group);
+ nntp_data->nserv = s;
+ if (s->newsgroups->nelem < s->newsgroups->curnelem * 2)
+ hash_resize (s->newsgroups, s->newsgroups->nelem * 2);
+ hash_insert(s->newsgroups, nntp_data->group, nntp_data);
+ nntp_data_list_append(&s->list, nntp_data);
+ }
+ nntp_data->deleted = 0;
+ nntp_data->firstMessage = first;
+ nntp_data->lastMessage = last;
+ if (mod == 'y')
+ nntp_data->allowed = 1;
+ else
+ nntp_data->allowed = 0;
+ if (nntp_data->desc)
+ p_delete(&nntp_data->desc);
+ if (*desc)
+ nntp_data->desc = m_strdup(desc);
+ if (nntp_data->rc || nntp_data->lastCached)
+ mutt_newsgroup_stat (nntp_data);
+ else if (nntp_data->lastMessage &&
+ nntp_data->firstMessage <= nntp_data->lastMessage)
+ nntp_data->unread = nntp_data->lastMessage - nntp_data->firstMessage + 1;
+ else
+ nntp_data->unread = 0;
+
+ return 0;
+}
+
+/* Load list of all newsgroups from cache ALL */
+static int nntp_get_cache_all (nntp_server_t * serv)
+{
+ char buf[HUGE_STRING];
+ FILE *f;
+
+ nntp_cache_expand(buf, ssizeof(buf), "%s", serv->cache);
+ if ((f = safe_fopen (buf, "r"))) {
+ int i = 0;
+
+ while (fgets (buf, sizeof (buf), f) != NULL) {
+ if (ReadInc && (i % ReadInc == 0))
+ mutt_message (_("Loading list from cache... %d"), i);
+ add_group (buf, serv);
+ i++;
+ }
+ add_group (NULL, NULL);
+ m_fclose(&f);
+ mutt_clear_error ();
+ return 0;
+ }
+ else {
+ p_delete(&serv->cache);
+ return -1;
+ }
+}
+