void nntp_hcache_update(struct NntpMboxData *mdata, struct HeaderCache *hc) { char buf[32] = { 0 }; bool old = false; anum_t first = 0, last = 0; /* fetch previous values of first and last */ size_t dlen = 0; char *hdata = mutt_hcache_fetch_raw(hc, "index", 5, &dlen); if (hdata) { mutt_debug(LL_DEBUG2, "mutt_hcache_fetch index: %s\n", (char *) hdata); if ((dlen > 0) && (hdata[dlen - 1] == '\0') && sscanf(hdata, ANUM " " ANUM, &first, &last) == 2) { old = true; mdata->last_cached = last; /* clean removed headers from cache */ for (anum_t current = first; current <= last; current++) { if ((current >= mdata->first_message) && (current <= mdata->last_message)) continue; snprintf(buf, sizeof(buf), ANUM, current); mutt_debug(LL_DEBUG2, "mutt_hcache_delete_record %s\n", buf); mutt_hcache_delete_record(hc, buf, strlen(buf)); } } mutt_hcache_free_raw(hc, (void **) &hdata); } /* store current values of first and last */ if (!old || (mdata->first_message != first) || (mdata->last_message != last)) { snprintf(buf, sizeof(buf), ANUM " " ANUM, mdata->first_message, mdata->last_message); mutt_debug(LL_DEBUG2, "mutt_hcache_store index: %s\n", buf); mutt_hcache_store_raw(hc, "index", 5, buf, strlen(buf) + 1); } } void nntp_clear_cache(struct NntpAccountData *adata) { char file[PATH_MAX] = { 0 }; char *fp = NULL; struct dirent *entry = NULL; DIR *dp = NULL; if (!adata || !adata->cacheable) return; cache_expand(file, sizeof(file), &adata->conn->account, NULL); dp = opendir(file); if (dp) { mutt_strn_cat(file, sizeof(file), "/", 1); fp = file + strlen(file); while ((entry = readdir(dp))) { char *group = entry->d_name; struct stat st = { 0 }; struct NntpMboxData *mdata = NULL; struct NntpMboxData tmp_mdata; if (mutt_str_equal(group, ".") || mutt_str_equal(group, "..")) continue; *fp = '\0'; mutt_strn_cat(file, sizeof(file), group, strlen(group)); if (stat(file, &st) != 0) continue; #ifdef USE_HCACHE if (S_ISREG(st.st_mode)) { char *ext = group + strlen(group) - 7; if ((strlen(group) < 8) || !mutt_str_equal(ext, ".hcache")) continue; *ext = '\0'; } else #endif if (!S_ISDIR(st.st_mode)) continue; const bool c_save_unsubscribed = cs_subset_bool(NeoMutt->sub, "save_unsubscribed"); mdata = mutt_hash_find(adata->groups_hash, group); } closedir(dp); } } struct NntpAccountData *nntp_select_server(struct Mailbox *m, const char *server, bool leave_lock) { /* news server already exists */ // adata = conn->data; if (rc > 0) nntp_clear_cache(adata); if ((rc < 0) || !leave_lock) nntp_newsrc_close(adata); return adata; }