for (int i = 0; i < data->num; i++) {
int first = MAX(data->entries[i].first, data->firstMessage);
int last = MIN(data->entries[i].last, data->lastMessage);
- data->unread -= MAX(0, last - first + 1);
+ if (first <= last)
+ data->unread -= last - first + 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);
+ news->tail = nntp_data_list_append(news->tail, data);
} else {
p_delete(&data->entries);
}
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);
+ news->tail = nntp_data_list_append(news->tail, data);
}
m_strreplace(&data->cache, p);
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);
+ s->tail = nntp_data_list_append(s->tail, nntp_data);
}
nntp_data->deleted = 0;
nntp_data->firstMessage = first;
list->subscribed = list->rc = list->num = 0;
}
slurp_newsrc (serv);
- nntp_clear_cacheindex (serv);
}
if (serv->status == NNTP_BYE)
/* New newsserver */
serv = p_new(nntp_server_t, 1);
+ serv->tail = &serv->list;
serv->conn = conn;
serv->newsrc = m_strdup(file);
- serv->newsgroups = hash_new(1009, false);
+ serv->newsgroups = hash_new(SHRT_MAX, false);
slurp_newsrc (serv); /* load .newsrc */
nntp_parse_cacheindex (serv); /* load .index */
if (nntp.use_cache && serv->cache && nntp_get_cache_all (serv) >= 0)
p_delete(&serv);
return NULL;
}
- nntp_clear_cacheindex (serv);
conn->data = (void *) serv;
return serv;
NULL);
}
-/* Remove cache files of unsubscribed newsgroups */
-void nntp_clear_cacheindex (nntp_server_t * news)
-{
- nntp_data_t *data;
-
- if (option (OPTSAVEUNSUB) || !news)
- return;
-
- for (data = news->list; data; data = data->next) {
- if (!data || data->subscribed || !data->cache)
- continue;
- nntp_delete_cache (data);
- }
- return;
-}
-
static int nntp_save_cache_index (nntp_server_t * news)
{
char buf[HUGE_STRING];
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);
+ news->tail = nntp_data_list_append(news->tail, data);
}
if (!data->subscribed) {
data->subscribed = 1;
return NULL;
if (data->subscribed) {
data->subscribed = 0;
- if (!option (OPTSAVEUNSUB))
- data->rc = 0;
}
return data;
}
nntp_data = nntp_data_new();
nntp_data->group = m_strdup(buf);
hash_insert(serv->newsgroups, nntp_data->group, nntp_data);
- nntp_data_list_append(&serv->list, nntp_data);
+ serv->tail = nntp_data_list_append(serv->tail, nntp_data);
}
ctx->data = nntp_data;
nntp_data->nserv = serv;
if ((*l) == nntp_data) {
nntp_data_list_pop(l);
nntp_data_delete(&nntp_data);
+ if (!*l)
+ serv->tail = l;
break;
}
}
{
nntp_data_t *data = ctx->data;
- /* CACHE: update cache and .index files */
- if ((option (OPTSAVEUNSUB) || data->subscribed))
- nntp_save_cache_group (ctx);
- nntp_free_acache (data);
+ nntp_save_cache_group(ctx);
+ nntp_free_acache(data);
data->nserv->check_time = 0; /* next nntp_check_mailbox() will really check */
return 0;
tmp = &(*tmp)->next;
}
}
- nntp_save_cache_index (serv);
+ serv->tail = tmp;
+ nntp_save_cache_index(serv);
mutt_clear_error ();
return nntp.checked;