- p_delete(&news->cache);
- snprintf (buf, sizeof (buf), "%s/.index", dir);
- if (!(idx = safe_fopen (buf, "a+")))
- return 0;
- rewind (idx);
- while (fgets (buf, sizeof (buf), idx)) {
- buf[m_strlen(buf) - 1] = 0; /* strip ending '\n' */
- if (!m_strncmp(buf, "#: ", 3) &&
- !m_strcasecmp(buf + 3, news->conn->account.host))
- break;
- }
- while (fgets (buf, sizeof (buf), idx)) {
- cp = buf;
- while (*cp && *cp != ' ')
- cp++;
- if (!*cp)
- continue;
- cp[0] = 0;
- if (!m_strcmp(buf, "#:"))
- break;
- sscanf (cp + 1, "%s %d %d", file, &l, &m);
- if (!m_strcmp(buf, "ALL")) {
- news->cache = m_strdup(file);
- news->newgroups_time = m;
- }
- else if (news->newsgroups) {
- if ((data = hash_find (news->newsgroups, buf)) == NULL) {
- data = nntp_data_new();
- data->group = m_strdup(buf);
- data->nserv = news;
- data->deleted = 1;
- if (news->newsgroups->nelem < news->newsgroups->curnelem * 2)
- hash_resize (news->newsgroups, news->newsgroups->nelem * 2);
- hash_insert (news->newsgroups, data->group, data);
- nntp_data_list_append(&news->list, data);
- }
- data->cache = m_strdup(file);
- t = 0;
- if (!data->firstMessage || data->lastMessage < m)
- t = 1;
- if (!data->firstMessage)
- data->firstMessage = l;
- if (data->lastMessage < m)
- data->lastMessage = m;
- data->lastCached = m;
- if (t || !data->unread)
- mutt_newsgroup_stat (data);
+ if (news->newsgroups) {
+ nntp_data_t *data = hash_find(news->newsgroups, buf);
+
+ if (!data) {
+ data = nntp_data_new();
+ data->group = m_strdup(buf);
+ data->nserv = news;
+ data->deleted = 1;
+ hash_insert (news->newsgroups, data->group, data);
+ news->tail = nntp_data_list_append(news->tail, data);
+ }
+ m_strreplace(&data->cache, p);
+
+ t = !data->first || data->last < m;
+ if (!data->first)
+ data->first = l;
+ if (data->last < m)
+ data->last = m;
+ data->lastCached = m;
+ if (t || !data->unread)
+ mutt_newsgroup_stat(data);
+ }