NeoMutt  2024-10-02-37-gfa9146
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
newsrc.c
Go to the documentation of this file.
1
33#include "config.h"
34#include <dirent.h>
35#include <errno.h>
36#include <limits.h>
37#include <stdbool.h>
38#include <stdio.h>
39#include <string.h>
40#include <sys/stat.h>
41#include <time.h>
42#include <unistd.h>
43#include "private.h"
44#include "mutt/lib.h"
45#include "config/lib.h"
46#include "email/lib.h"
47#include "core/lib.h"
48#include "conn/lib.h"
49#include "mutt.h"
50#include "lib.h"
51#include "bcache/lib.h"
52#include "expando/lib.h"
53#include "adata.h"
54#include "edata.h"
55#include "mdata.h"
56#include "mutt_account.h"
57#include "mutt_logging.h"
58#include "mutt_socket.h"
59#include "muttlib.h"
60#include "protos.h"
61#ifdef USE_HCACHE
62#include "hcache/lib.h"
63#endif
64
65struct BodyCache;
66
68
76static struct NntpMboxData *mdata_find(struct NntpAccountData *adata, const char *group)
77{
79 if (mdata)
80 return mdata;
81
82 size_t len = strlen(group) + 1;
83 /* create NntpMboxData structure and add it to hash */
84 mdata = mutt_mem_calloc(1, sizeof(struct NntpMboxData) + len);
85 mdata->group = (char *) mdata + sizeof(struct NntpMboxData);
86 mutt_str_copy(mdata->group, group, len);
87 mdata->adata = adata;
88 mdata->deleted = true;
90
91 /* add NntpMboxData to list */
93 {
94 adata->groups_max *= 2;
96 }
98
99 return mdata;
100}
101
107{
108 for (int i = 0; i < NNTP_ACACHE_LEN; i++)
109 {
110 if (mdata->acache[i].path)
111 {
112 unlink(mdata->acache[i].path);
113 FREE(&mdata->acache[i].path);
114 }
115 }
116}
117
123{
124 if (!adata->fp_newsrc)
125 return;
126
127 mutt_debug(LL_DEBUG1, "Unlocking %s\n", adata->newsrc_file);
130}
131
137{
138 mdata->unread = 0;
139 if ((mdata->last_message == 0) ||
140 (mdata->first_message > mdata->last_message) || !mdata->newsrc_ent)
141 {
142 return;
143 }
144
145 mdata->unread = mdata->last_message - mdata->first_message + 1;
146 for (unsigned int i = 0; i < mdata->newsrc_len; i++)
147 {
148 anum_t first = mdata->newsrc_ent[i].first;
149 if (first < mdata->first_message)
150 first = mdata->first_message;
151 anum_t last = mdata->newsrc_ent[i].last;
152 if (last > mdata->last_message)
153 last = mdata->last_message;
154 if (first <= last)
155 mdata->unread -= last - first + 1;
156 }
157}
158
167{
168 if (!adata)
169 return -1;
170
171 char *line = NULL;
172 struct stat st = { 0 };
173
174 if (adata->fp_newsrc)
175 {
176 /* if we already have a handle, close it and reopen */
178 }
179 else
180 {
181 /* if file doesn't exist, create it */
182 adata->fp_newsrc = mutt_file_fopen(adata->newsrc_file, "a");
184 }
185
186 /* open .newsrc */
187 adata->fp_newsrc = mutt_file_fopen(adata->newsrc_file, "r");
188 if (!adata->fp_newsrc)
189 {
190 mutt_perror("%s", adata->newsrc_file);
191 return -1;
192 }
193
194 /* lock it */
195 mutt_debug(LL_DEBUG1, "Locking %s\n", adata->newsrc_file);
196 if (mutt_file_lock(fileno(adata->fp_newsrc), false, true))
197 {
199 return -1;
200 }
201
202 if (stat(adata->newsrc_file, &st) != 0)
203 {
204 mutt_perror("%s", adata->newsrc_file);
205 nntp_newsrc_close(adata);
206 return -1;
207 }
208
209 if ((adata->size == st.st_size) && (adata->mtime == st.st_mtime))
210 return 0;
211
212 adata->size = st.st_size;
213 adata->mtime = st.st_mtime;
214 adata->newsrc_modified = true;
215 mutt_debug(LL_DEBUG1, "Parsing %s\n", adata->newsrc_file);
216
217 /* .newsrc has been externally modified or hasn't been loaded yet */
218 for (unsigned int i = 0; i < adata->groups_num; i++)
219 {
220 struct NntpMboxData *mdata = adata->groups_list[i];
221 if (!mdata)
222 continue;
223
224 mdata->subscribed = false;
225 mdata->newsrc_len = 0;
226 FREE(&mdata->newsrc_ent);
227 }
228
229 line = mutt_mem_malloc(st.st_size + 1);
230 while (st.st_size && fgets(line, st.st_size + 1, adata->fp_newsrc))
231 {
232 char *b = NULL, *h = NULL;
233 unsigned int j = 1;
234 bool subs = false;
235
236 /* find end of newsgroup name */
237 char *p = strpbrk(line, ":!");
238 if (!p)
239 continue;
240
241 /* ":" - subscribed, "!" - unsubscribed */
242 if (*p == ':')
243 subs = true;
244 *p++ = '\0';
245
246 /* get newsgroup data */
247 struct NntpMboxData *mdata = mdata_find(adata, line);
248 FREE(&mdata->newsrc_ent);
249
250 /* count number of entries */
251 b = p;
252 while (*b)
253 if (*b++ == ',')
254 j++;
255 mdata->newsrc_ent = mutt_mem_calloc(j, sizeof(struct NewsrcEntry));
256 mdata->subscribed = subs;
257
258 /* parse entries */
259 j = 0;
260 while (p)
261 {
262 b = p;
263
264 /* find end of entry */
265 p = strchr(p, ',');
266 if (p)
267 *p++ = '\0';
268
269 /* first-last or single number */
270 h = strchr(b, '-');
271 if (h)
272 *h++ = '\0';
273 else
274 h = b;
275
276 if ((sscanf(b, ANUM_FMT, &mdata->newsrc_ent[j].first) == 1) &&
277 (sscanf(h, ANUM_FMT, &mdata->newsrc_ent[j].last) == 1))
278 {
279 j++;
280 }
281 }
282 if (j == 0)
283 {
284 mdata->newsrc_ent[j].first = 1;
285 mdata->newsrc_ent[j].last = 0;
286 j++;
287 }
288 if (mdata->last_message == 0)
289 mdata->last_message = mdata->newsrc_ent[j - 1].last;
290 mdata->newsrc_len = j;
291 mutt_mem_realloc(&mdata->newsrc_ent, j * sizeof(struct NewsrcEntry));
293 mutt_debug(LL_DEBUG2, "%s\n", mdata->group);
294 }
295 FREE(&line);
296 return 1;
297}
298
304{
305 if (!m)
306 return;
307
308 struct NntpMboxData *mdata = m->mdata;
309 anum_t last = 0, first = 1;
310 bool series;
311 unsigned int entries;
312
313 const enum SortType c_sort = cs_subset_sort(NeoMutt->sub, "sort");
314 if (c_sort != SORT_ORDER)
315 {
318 }
319
320 entries = mdata->newsrc_len;
321 if (!entries)
322 {
323 entries = 5;
324 mdata->newsrc_ent = mutt_mem_calloc(entries, sizeof(struct NewsrcEntry));
325 }
326
327 /* Set up to fake initial sequence from 1 to the article before the
328 * first article in our list */
329 mdata->newsrc_len = 0;
330 series = true;
331 for (int i = 0; i < m->msg_count; i++)
332 {
333 struct Email *e = m->emails[i];
334 if (!e)
335 break;
336
337 /* search for first unread */
338 if (series)
339 {
340 /* We don't actually check sequential order, since we mark
341 * "missing" entries as read/deleted */
342 last = nntp_edata_get(e)->article_num;
343 if ((last >= mdata->first_message) && !e->deleted && !e->read)
344 {
345 if (mdata->newsrc_len >= entries)
346 {
347 entries *= 2;
348 mutt_mem_realloc(&mdata->newsrc_ent, entries * sizeof(struct NewsrcEntry));
349 }
350 mdata->newsrc_ent[mdata->newsrc_len].first = first;
351 mdata->newsrc_ent[mdata->newsrc_len].last = last - 1;
352 mdata->newsrc_len++;
353 series = false;
354 }
355 }
356 else
357 {
358 /* search for first read */
359 if (e->deleted || e->read)
360 {
361 first = last + 1;
362 series = true;
363 }
364 last = nntp_edata_get(e)->article_num;
365 }
366 }
367
368 if (series && (first <= mdata->last_loaded))
369 {
370 if (mdata->newsrc_len >= entries)
371 {
372 entries++;
373 mutt_mem_realloc(&mdata->newsrc_ent, entries * sizeof(struct NewsrcEntry));
374 }
375 mdata->newsrc_ent[mdata->newsrc_len].first = first;
376 mdata->newsrc_ent[mdata->newsrc_len].last = mdata->last_loaded;
377 mdata->newsrc_len++;
378 }
379 mutt_mem_realloc(&mdata->newsrc_ent, mdata->newsrc_len * sizeof(struct NewsrcEntry));
380
381 if (c_sort != SORT_ORDER)
382 {
383 cs_subset_str_native_set(NeoMutt->sub, "sort", c_sort, NULL);
385 }
386}
387
395static int update_file(char *filename, char *buf)
396{
397 FILE *fp = NULL;
398 char tmpfile[PATH_MAX] = { 0 };
399 int rc = -1;
400
401 while (true)
402 {
403 snprintf(tmpfile, sizeof(tmpfile), "%s.tmp", filename);
404 fp = mutt_file_fopen(tmpfile, "w");
405 if (!fp)
406 {
407 mutt_perror("%s", tmpfile);
408 *tmpfile = '\0';
409 break;
410 }
411 if (fputs(buf, fp) == EOF)
412 {
413 mutt_perror("%s", tmpfile);
414 break;
415 }
416 if (mutt_file_fclose(&fp) == EOF)
417 {
418 mutt_perror("%s", tmpfile);
419 fp = NULL;
420 break;
421 }
422 fp = NULL;
423 if (rename(tmpfile, filename) < 0)
424 {
425 mutt_perror("%s", filename);
426 break;
427 }
428 *tmpfile = '\0';
429 rc = 0;
430 break;
431 }
432 mutt_file_fclose(&fp);
433
434 if (*tmpfile)
435 unlink(tmpfile);
436 return rc;
437}
438
446{
447 if (!adata)
448 return -1;
449
450 int rc = -1;
451
452 size_t buflen = 10240;
453 char *buf = mutt_mem_calloc(1, buflen);
454 size_t off = 0;
455
456 /* we will generate full newsrc here */
457 for (unsigned int i = 0; i < adata->groups_num; i++)
458 {
459 struct NntpMboxData *mdata = adata->groups_list[i];
460
461 if (!mdata || !mdata->newsrc_ent)
462 continue;
463
464 /* write newsgroup name */
465 if ((off + strlen(mdata->group) + 3) > buflen)
466 {
467 buflen *= 2;
468 mutt_mem_realloc(&buf, buflen);
469 }
470 snprintf(buf + off, buflen - off, "%s%c ", mdata->group, mdata->subscribed ? ':' : '!');
471 off += strlen(buf + off);
472
473 /* write entries */
474 for (unsigned int j = 0; j < mdata->newsrc_len; j++)
475 {
476 if ((off + 1024) > buflen)
477 {
478 buflen *= 2;
479 mutt_mem_realloc(&buf, buflen);
480 }
481 if (j)
482 buf[off++] = ',';
483 if (mdata->newsrc_ent[j].first == mdata->newsrc_ent[j].last)
484 {
485 snprintf(buf + off, buflen - off, ANUM_FMT, mdata->newsrc_ent[j].first);
486 }
487 else if (mdata->newsrc_ent[j].first < mdata->newsrc_ent[j].last)
488 {
489 snprintf(buf + off, buflen - off, ANUM_FMT "-" ANUM_FMT,
490 mdata->newsrc_ent[j].first, mdata->newsrc_ent[j].last);
491 }
492 off += strlen(buf + off);
493 }
494 buf[off++] = '\n';
495 }
496 buf[off] = '\0';
497
498 /* newrc being fully rewritten */
499 mutt_debug(LL_DEBUG1, "Updating %s\n", adata->newsrc_file);
500 if (adata->newsrc_file && (update_file(adata->newsrc_file, buf) == 0))
501 {
502 struct stat st = { 0 };
503
504 rc = stat(adata->newsrc_file, &st);
505 if (rc == 0)
506 {
507 adata->size = st.st_size;
508 adata->mtime = st.st_mtime;
509 }
510 else
511 {
512 mutt_perror("%s", adata->newsrc_file);
513 }
514 }
515 FREE(&buf);
516 return rc;
517}
518
526static void cache_expand(char *dst, size_t dstlen, struct ConnAccount *cac, const char *src)
527{
528 char file[PATH_MAX] = { 0 };
529
530 /* server subdirectory */
531 struct Url url = { 0 };
532 mutt_account_tourl(cac, &url);
533 url.path = mutt_str_dup(src);
534 url_tostring(&url, file, sizeof(file), U_PATH);
535 FREE(&url.path);
536
537 /* remove trailing slash */
538 char *c = file + strlen(file) - 1;
539 if (*c == '/')
540 *c = '\0';
541
542 struct Buffer *tmp = buf_pool_get();
543 buf_addstr(tmp, file);
544 mutt_encode_path(tmp, file);
545
546 const char *const c_news_cache_dir = cs_subset_path(NeoMutt->sub, "news_cache_dir");
547 snprintf(dst, dstlen, "%s/%s", c_news_cache_dir, buf_string(tmp));
548
549 buf_pool_release(&tmp);
550}
551
558void nntp_expand_path(char *buf, size_t buflen, struct ConnAccount *cac)
559{
560 struct Url url = { 0 };
561
562 mutt_account_tourl(cac, &url);
563 url.path = mutt_str_dup(buf);
564 url_tostring(&url, buf, buflen, U_NO_FLAGS);
565 FREE(&url.path);
566}
567
574int nntp_add_group(char *line, void *data)
575{
576 struct NntpAccountData *adata = data;
577 struct NntpMboxData *mdata = NULL;
578 char group[1024] = { 0 };
579 char desc[8192] = { 0 };
580 char mod = '\0';
581 anum_t first = 0, last = 0;
582
583 if (!adata || !line)
584 return 0;
585
586 /* These sscanf limits must match the sizes of the group and desc arrays */
587 if (sscanf(line, "%1023s " ANUM_FMT " " ANUM_FMT " %c %8191[^\n]", group,
588 &last, &first, &mod, desc) < 4)
589 {
590 mutt_debug(LL_DEBUG2, "Can't parse server line: %s\n", line);
591 return 0;
592 }
593
595 mdata->deleted = false;
596 mdata->first_message = first;
597 mdata->last_message = last;
598 mdata->allowed = (mod == 'y') || (mod == 'm');
599 mutt_str_replace(&mdata->desc, desc);
600 if (mdata->newsrc_ent || (mdata->last_cached != 0))
602 else if (mdata->last_message && (mdata->first_message <= mdata->last_message))
603 mdata->unread = mdata->last_message - mdata->first_message + 1;
604 else
605 mdata->unread = 0;
606 return 0;
607}
608
616{
617 char buf[8192] = { 0 };
618 char file[4096] = { 0 };
619 time_t t = 0;
620
621 cache_expand(file, sizeof(file), &adata->conn->account, ".active");
622 mutt_debug(LL_DEBUG1, "Parsing %s\n", file);
623 FILE *fp = mutt_file_fopen(file, "r");
624 if (!fp)
625 return -1;
626
627 if (!fgets(buf, sizeof(buf), fp) || (sscanf(buf, "%jd%4095s", &t, file) != 1) || (t == 0))
628 {
629 mutt_file_fclose(&fp);
630 return -1;
631 }
633
634 mutt_message(_("Loading list of groups from cache..."));
635 while (fgets(buf, sizeof(buf), fp))
636 nntp_add_group(buf, adata);
637 nntp_add_group(NULL, NULL);
638 mutt_file_fclose(&fp);
640 return 0;
641}
642
650{
651 if (!adata->cacheable)
652 return 0;
653
654 size_t buflen = 10240;
655 char *buf = mutt_mem_calloc(1, buflen);
656 snprintf(buf, buflen, "%lu\n", (unsigned long) adata->newgroups_time);
657 size_t off = strlen(buf);
658
659 for (unsigned int i = 0; i < adata->groups_num; i++)
660 {
661 struct NntpMboxData *mdata = adata->groups_list[i];
662
663 if (!mdata || mdata->deleted)
664 continue;
665
666 if ((off + strlen(mdata->group) + (mdata->desc ? strlen(mdata->desc) : 0) + 50) > buflen)
667 {
668 buflen *= 2;
669 mutt_mem_realloc(&buf, buflen);
670 }
671 snprintf(buf + off, buflen - off, "%s " ANUM_FMT " " ANUM_FMT " %c%s%s\n",
672 mdata->group, mdata->last_message, mdata->first_message,
673 mdata->allowed ? 'y' : 'n', mdata->desc ? " " : "",
674 mdata->desc ? mdata->desc : "");
675 off += strlen(buf + off);
676 }
677
678 char file[PATH_MAX] = { 0 };
679 cache_expand(file, sizeof(file), &adata->conn->account, ".active");
680 mutt_debug(LL_DEBUG1, "Updating %s\n", file);
681 int rc = update_file(file, buf);
682 FREE(&buf);
683 return rc;
684}
685
686#ifdef USE_HCACHE
690static void nntp_hcache_namer(const char *path, struct Buffer *dest)
691{
692 buf_printf(dest, "%s.hcache", path);
693
694 /* Strip out any directories in the path */
695 char *first = strchr(buf_string(dest), '/');
696 char *last = strrchr(buf_string(dest), '/');
697 if (first && last && (last > first))
698 {
699 memmove(first, last, strlen(last) + 1);
700 }
701}
702
710{
711 struct Url url = { 0 };
712 char file[PATH_MAX] = { 0 };
713
714 const bool c_save_unsubscribed = cs_subset_bool(NeoMutt->sub, "save_unsubscribed");
715 if (!mdata->adata || !mdata->adata->cacheable || !mdata->adata->conn || !mdata->group ||
716 !(mdata->newsrc_ent || mdata->subscribed || c_save_unsubscribed))
717 {
718 return NULL;
719 }
720
721 mutt_account_tourl(&mdata->adata->conn->account, &url);
722 url.path = mdata->group;
723 url_tostring(&url, file, sizeof(file), U_PATH);
724 const char *const c_news_cache_dir = cs_subset_path(NeoMutt->sub, "news_cache_dir");
725 return hcache_open(c_news_cache_dir, file, nntp_hcache_namer, true);
726}
727
733void nntp_hcache_update(struct NntpMboxData *mdata, struct HeaderCache *hc)
734{
735 if (!hc)
736 return;
737
738 char buf[32] = { 0 };
739 bool old = false;
740 anum_t first = 0, last = 0;
741
742 /* fetch previous values of first and last */
743 char *hdata = hcache_fetch_raw_str(hc, "index", 5);
744 if (hdata)
745 {
746 mutt_debug(LL_DEBUG2, "hcache_fetch_email index: %s\n", hdata);
747 if (sscanf(hdata, ANUM_FMT " " ANUM_FMT, &first, &last) == 2)
748 {
749 old = true;
750 mdata->last_cached = last;
751
752 /* clean removed headers from cache */
753 for (anum_t current = first; current <= last; current++)
754 {
755 if ((current >= mdata->first_message) && (current <= mdata->last_message))
756 continue;
757
758 snprintf(buf, sizeof(buf), ANUM_FMT, current);
759 mutt_debug(LL_DEBUG2, "hcache_delete_email %s\n", buf);
760 hcache_delete_email(hc, buf, strlen(buf));
761 }
762 }
763 FREE(&hdata);
764 }
765
766 /* store current values of first and last */
767 if (!old || (mdata->first_message != first) || (mdata->last_message != last))
768 {
769 snprintf(buf, sizeof(buf), ANUM_FMT " " ANUM_FMT, mdata->first_message,
770 mdata->last_message);
771 mutt_debug(LL_DEBUG2, "hcache_store_email index: %s\n", buf);
772 hcache_store_raw(hc, "index", 5, buf, strlen(buf) + 1);
773 }
774}
775#endif
776
781static int nntp_bcache_delete(const char *id, struct BodyCache *bcache, void *data)
782{
783 struct NntpMboxData *mdata = data;
784 anum_t anum = 0;
785 char c = '\0';
786
787 if (!mdata || (sscanf(id, ANUM_FMT "%c", &anum, &c) != 1) ||
788 (anum < mdata->first_message) || (anum > mdata->last_message))
789 {
790 if (mdata)
791 mutt_debug(LL_DEBUG2, "mutt_bcache_del %s\n", id);
793 }
794 return 0;
795}
796
802{
804}
805
811{
812 if (!mdata || !mdata->adata || !mdata->adata->cacheable)
813 return;
814
815#ifdef USE_HCACHE
816 struct Buffer *file = buf_pool_get();
817 nntp_hcache_namer(mdata->group, file);
818 cache_expand(file->data, file->dsize, &mdata->adata->conn->account, buf_string(file));
819 unlink(buf_string(file));
820 mdata->last_cached = 0;
821 mutt_debug(LL_DEBUG2, "%s\n", buf_string(file));
822 buf_pool_release(&file);
823#endif
824
825 if (!mdata->bcache)
826 {
827 mdata->bcache = mutt_bcache_open(&mdata->adata->conn->account, mdata->group);
828 }
829 if (mdata->bcache)
830 {
831 mutt_debug(LL_DEBUG2, "%s/*\n", mdata->group);
833 mutt_bcache_close(&mdata->bcache);
834 }
835}
836
844{
845 if (!adata || !adata->cacheable)
846 return;
847
848 struct dirent *de = NULL;
849 DIR *dir = NULL;
850 struct Buffer *cache = buf_pool_get();
851 struct Buffer *file = buf_pool_get();
852
853 cache_expand(cache->data, cache->dsize, &adata->conn->account, NULL);
855 if (!dir)
856 goto done;
857
858 buf_addch(cache, '/');
859 const bool c_save_unsubscribed = cs_subset_bool(NeoMutt->sub, "save_unsubscribed");
860
861 while ((de = readdir(dir)))
862 {
863 char *group = de->d_name;
864 if (mutt_str_equal(group, ".") || mutt_str_equal(group, ".."))
865 continue;
866
867 buf_printf(file, "%s%s", buf_string(cache), group);
868 struct stat st = { 0 };
869 if (stat(buf_string(file), &st) != 0)
870 continue;
871
872#ifdef USE_HCACHE
873 if (S_ISREG(st.st_mode))
874 {
875 char *ext = group + strlen(group) - 7;
876 if ((strlen(group) < 8) || !mutt_str_equal(ext, ".hcache"))
877 continue;
878 *ext = '\0';
879 }
880 else
881#endif
882 if (!S_ISDIR(st.st_mode))
883 continue;
884
885 struct NntpMboxData tmp_mdata = { 0 };
887 if (!mdata)
888 {
889 mdata = &tmp_mdata;
890 mdata->adata = adata;
891 mdata->group = group;
892 mdata->bcache = NULL;
893 }
894 else if (mdata->newsrc_ent || mdata->subscribed || c_save_unsubscribed)
895 {
896 continue;
897 }
898
900 if (S_ISDIR(st.st_mode))
901 {
902 rmdir(buf_string(file));
903 mutt_debug(LL_DEBUG2, "%s\n", buf_string(file));
904 }
905 }
906 closedir(dir);
907
908done:
909 buf_pool_release(&cache);
910 buf_pool_release(&file);
911}
912
916void nntp_a(const struct ExpandoNode *node, void *data, MuttFormatFlags flags,
917 struct Buffer *buf)
918{
919 struct NntpAccountData *adata = data;
920 struct ConnAccount *cac = &adata->conn->account;
921
922 char tmp[128] = { 0 };
923
924 struct Url url = { 0 };
925 mutt_account_tourl(cac, &url);
926 url_tostring(&url, tmp, sizeof(tmp), U_PATH);
927 char *p = strchr(tmp, '/');
928 if (p)
929 {
930 *p = '\0';
931 }
932
933 buf_strcpy(buf, tmp);
934}
935
939long nntp_p_num(const struct ExpandoNode *node, void *data, MuttFormatFlags flags)
940{
941 const struct NntpAccountData *adata = data;
942 const struct ConnAccount *cac = &adata->conn->account;
943
944 return cac->port;
945}
946
950long nntp_P_num(const struct ExpandoNode *node, void *data, MuttFormatFlags flags)
951{
952 const struct NntpAccountData *adata = data;
953 const struct ConnAccount *cac = &adata->conn->account;
954
955 if (cac->flags & MUTT_ACCT_PORT)
956 return cac->port;
957
958 return 0;
959}
960
964void nntp_P(const struct ExpandoNode *node, void *data, MuttFormatFlags flags,
965 struct Buffer *buf)
966{
967 const struct NntpAccountData *adata = data;
968 const struct ConnAccount *cac = &adata->conn->account;
969
970 if (cac->flags & MUTT_ACCT_PORT)
971 {
972 buf_add_printf(buf, "%hd", cac->port);
973 }
974}
975
979void nntp_s(const struct ExpandoNode *node, void *data, MuttFormatFlags flags,
980 struct Buffer *buf)
981{
982 const struct NntpAccountData *adata = data;
983 const struct ConnAccount *cac = &adata->conn->account;
984
985 char tmp[128] = { 0 };
986
987 mutt_str_copy(tmp, cac->host, sizeof(tmp));
988 mutt_str_lower(tmp);
989
990 buf_strcpy(buf, tmp);
991}
992
996void nntp_S(const struct ExpandoNode *node, void *data, MuttFormatFlags flags,
997 struct Buffer *buf)
998{
999 struct NntpAccountData *adata = data;
1000 struct ConnAccount *cac = &adata->conn->account;
1001
1002 char tmp[128] = { 0 };
1003
1004 struct Url url = { 0 };
1005 mutt_account_tourl(cac, &url);
1006 url_tostring(&url, tmp, sizeof(tmp), U_PATH);
1007 char *p = strchr(tmp, ':');
1008 if (p)
1009 {
1010 *p = '\0';
1011 }
1012
1013 buf_strcpy(buf, tmp);
1014}
1015
1019void nntp_u(const struct ExpandoNode *node, void *data, MuttFormatFlags flags,
1020 struct Buffer *buf)
1021{
1022 const struct NntpAccountData *adata = data;
1023 const struct ConnAccount *cac = &adata->conn->account;
1024
1025 const char *s = cac->user;
1026 buf_strcpy(buf, s);
1027}
1028
1032static const char *nntp_get_field(enum ConnAccountField field, void *gf_data)
1033{
1034 switch (field)
1035 {
1036 case MUTT_CA_LOGIN:
1037 case MUTT_CA_USER:
1038 return cs_subset_string(NeoMutt->sub, "nntp_user");
1039 case MUTT_CA_PASS:
1040 return cs_subset_string(NeoMutt->sub, "nntp_pass");
1041 case MUTT_CA_OAUTH_CMD:
1042 case MUTT_CA_HOST:
1043 default:
1044 return NULL;
1045 }
1046}
1047
1063struct NntpAccountData *nntp_select_server(struct Mailbox *m, const char *server, bool leave_lock)
1064{
1065 char file[PATH_MAX] = { 0 };
1066 int rc;
1067 struct ConnAccount cac = { { 0 } };
1068 struct NntpAccountData *adata = NULL;
1069 struct Connection *conn = NULL;
1070
1071 if (!server || (*server == '\0'))
1072 {
1073 mutt_error(_("No news server defined"));
1074 return NULL;
1075 }
1076
1077 /* create account from news server url */
1078 cac.flags = 0;
1079 cac.port = NNTP_PORT;
1081 cac.service = "nntp";
1083
1084 snprintf(file, sizeof(file), "%s%s", strstr(server, "://") ? "" : "news://", server);
1085 struct Url *url = url_parse(file);
1086 if (!url || (url->path && *url->path) ||
1087 !((url->scheme == U_NNTP) || (url->scheme == U_NNTPS)) || !url->host ||
1088 (mutt_account_fromurl(&cac, url) < 0))
1089 {
1090 url_free(&url);
1091 mutt_error(_("%s is an invalid news server specification"), server);
1092 return NULL;
1093 }
1094 if (url->scheme == U_NNTPS)
1095 {
1096 cac.flags |= MUTT_ACCT_SSL;
1097 cac.port = NNTP_SSL_PORT;
1098 }
1099 url_free(&url);
1100
1101 // If nntp_user and nntp_pass are specified in the config, use them to find the connection
1102 const char *user = NULL;
1103 const char *pass = NULL;
1104 if ((user = cac.get_field(MUTT_CA_USER, NULL)))
1105 {
1106 mutt_str_copy(cac.user, user, sizeof(cac.user));
1107 cac.flags |= MUTT_ACCT_USER;
1108 }
1109 if ((pass = cac.get_field(MUTT_CA_PASS, NULL)))
1110 {
1111 mutt_str_copy(cac.pass, pass, sizeof(cac.pass));
1112 cac.flags |= MUTT_ACCT_PASS;
1113 }
1114
1115 /* find connection by account */
1116 conn = mutt_conn_find(&cac);
1117 if (!conn)
1118 return NULL;
1119 if (!(conn->account.flags & MUTT_ACCT_USER) && cac.flags & MUTT_ACCT_USER)
1120 {
1121 conn->account.flags |= MUTT_ACCT_USER;
1122 conn->account.user[0] = '\0';
1123 }
1124
1125 /* new news server */
1126 adata = nntp_adata_new(conn);
1127
1128 rc = nntp_open_connection(adata);
1129
1130 /* try to create cache directory and enable caching */
1131 adata->cacheable = false;
1132 const char *const c_news_cache_dir = cs_subset_path(NeoMutt->sub, "news_cache_dir");
1133 if ((rc >= 0) && c_news_cache_dir)
1134 {
1135 cache_expand(file, sizeof(file), &conn->account, NULL);
1136 if (mutt_file_mkdir(file, S_IRWXU) < 0)
1137 {
1138 mutt_error(_("Can't create %s: %s"), file, strerror(errno));
1139 }
1140 adata->cacheable = true;
1141 }
1142
1143 /* load .newsrc */
1144 if (rc >= 0)
1145 {
1146 const struct Expando *c_newsrc = cs_subset_expando(NeoMutt->sub, "newsrc");
1147 struct Buffer *buf = buf_pool_get();
1148 expando_filter(c_newsrc, NntpRenderData, adata, MUTT_FORMAT_NO_FLAGS, buf->dsize, buf);
1149 buf_expand_path(buf);
1150 adata->newsrc_file = buf_strdup(buf);
1151 buf_pool_release(&buf);
1152 rc = nntp_newsrc_parse(adata);
1153 }
1154 if (rc >= 0)
1155 {
1156 /* try to load list of newsgroups from cache */
1157 if (adata->cacheable && (active_get_cache(adata) == 0))
1158 {
1159 rc = nntp_check_new_groups(m, adata);
1160 }
1161 else
1162 {
1163 /* load list of newsgroups from server */
1164 rc = nntp_active_fetch(adata, false);
1165 }
1166 }
1167
1168 if (rc >= 0)
1169 nntp_clear_cache(adata);
1170
1171#ifdef USE_HCACHE
1172 /* check cache files */
1173 if ((rc >= 0) && adata->cacheable)
1174 {
1175 struct dirent *de = NULL;
1176 DIR *dir = mutt_file_opendir(file, MUTT_OPENDIR_NONE);
1177
1178 if (dir)
1179 {
1180 while ((de = readdir(dir)))
1181 {
1182 struct HeaderCache *hc = NULL;
1183 char *group = de->d_name;
1184
1185 char *p = group + strlen(group) - 7;
1186 if ((strlen(group) < 8) || !mutt_str_equal(p, ".hcache"))
1187 continue;
1188 *p = '\0';
1190 if (!mdata)
1191 continue;
1192
1193 hc = nntp_hcache_open(mdata);
1194 if (!hc)
1195 continue;
1196
1197 /* fetch previous values of first and last */
1198 char *hdata = hcache_fetch_raw_str(hc, "index", 5);
1199 if (hdata)
1200 {
1201 anum_t first = 0, last = 0;
1202
1203 if (sscanf(hdata, ANUM_FMT " " ANUM_FMT, &first, &last) == 2)
1204 {
1205 if (mdata->deleted)
1206 {
1207 mdata->first_message = first;
1208 mdata->last_message = last;
1209 }
1210 if ((last >= mdata->first_message) && (last <= mdata->last_message))
1211 {
1212 mdata->last_cached = last;
1213 mutt_debug(LL_DEBUG2, "%s last_cached=" ANUM_FMT "\n", mdata->group, last);
1214 }
1215 }
1216 FREE(&hdata);
1217 }
1218 hcache_close(&hc);
1219 }
1220 closedir(dir);
1221 }
1222 }
1223#endif
1224
1225 if ((rc < 0) || !leave_lock)
1227
1228 if (rc < 0)
1229 {
1234 FREE(&adata);
1235 mutt_socket_close(conn);
1236 FREE(&conn);
1237 return NULL;
1238 }
1239
1240 return adata;
1241}
1242
1255void nntp_article_status(struct Mailbox *m, struct Email *e, char *group, anum_t anum)
1256{
1257 struct NntpMboxData *mdata = m->mdata;
1258
1259 if (group)
1260 mdata = mutt_hash_find(mdata->adata->groups_hash, group);
1261
1262 if (!mdata)
1263 return;
1264
1265 for (unsigned int i = 0; i < mdata->newsrc_len; i++)
1266 {
1267 if ((anum >= mdata->newsrc_ent[i].first) && (anum <= mdata->newsrc_ent[i].last))
1268 {
1269 /* can't use mutt_set_flag() because mview_update() didn't get called yet */
1270 e->read = true;
1271 return;
1272 }
1273 }
1274
1275 /* article was not cached yet, it's new */
1276 if (anum > mdata->last_cached)
1277 return;
1278
1279 /* article isn't read but cached, it's old */
1280 const bool c_mark_old = cs_subset_bool(NeoMutt->sub, "mark_old");
1281 if (c_mark_old)
1282 e->old = true;
1283}
1284
1293{
1294 if (!adata || !adata->groups_hash || !group || (*group == '\0'))
1295 return NULL;
1296
1298 mdata->subscribed = true;
1299 if (!mdata->newsrc_ent)
1300 {
1301 mdata->newsrc_ent = mutt_mem_calloc(1, sizeof(struct NewsrcEntry));
1302 mdata->newsrc_len = 1;
1303 mdata->newsrc_ent[0].first = 1;
1304 mdata->newsrc_ent[0].last = 0;
1305 }
1306 return mdata;
1307}
1308
1317{
1318 if (!adata || !adata->groups_hash || !group || (*group == '\0'))
1319 return NULL;
1320
1322 if (!mdata)
1323 return NULL;
1324
1325 mdata->subscribed = false;
1326 const bool c_save_unsubscribed = cs_subset_bool(NeoMutt->sub, "save_unsubscribed");
1327 if (!c_save_unsubscribed)
1328 {
1329 mdata->newsrc_len = 0;
1330 FREE(&mdata->newsrc_ent);
1331 }
1332 return mdata;
1333}
1334
1344 struct NntpAccountData *adata, char *group)
1345{
1346 if (!adata || !adata->groups_hash || !group || (*group == '\0'))
1347 return NULL;
1348
1350 if (!mdata)
1351 return NULL;
1352
1353 if (mdata->newsrc_ent)
1354 {
1355 mutt_mem_realloc(&mdata->newsrc_ent, sizeof(struct NewsrcEntry));
1356 mdata->newsrc_len = 1;
1357 mdata->newsrc_ent[0].first = 1;
1358 mdata->newsrc_ent[0].last = mdata->last_message;
1359 }
1360 mdata->unread = 0;
1361 if (m && (m->mdata == mdata))
1362 {
1363 for (unsigned int i = 0; i < m->msg_count; i++)
1364 {
1365 struct Email *e = m->emails[i];
1366 if (!e)
1367 break;
1368 mutt_set_flag(m, e, MUTT_READ, true, true);
1369 }
1370 }
1371 return mdata;
1372}
1373
1383 struct NntpAccountData *adata, char *group)
1384{
1385 if (!adata || !adata->groups_hash || !group || (*group == '\0'))
1386 return NULL;
1387
1389 if (!mdata)
1390 return NULL;
1391
1392 if (mdata->newsrc_ent)
1393 {
1394 mutt_mem_realloc(&mdata->newsrc_ent, sizeof(struct NewsrcEntry));
1395 mdata->newsrc_len = 1;
1396 mdata->newsrc_ent[0].first = 1;
1397 mdata->newsrc_ent[0].last = mdata->first_message - 1;
1398 }
1399 if (m && (m->mdata == mdata))
1400 {
1401 mdata->unread = m->msg_count;
1402 for (unsigned int i = 0; i < m->msg_count; i++)
1403 {
1404 struct Email *e = m->emails[i];
1405 if (!e)
1406 break;
1407 mutt_set_flag(m, e, MUTT_READ, false, true);
1408 }
1409 }
1410 else
1411 {
1412 mdata->unread = mdata->last_message;
1413 if (mdata->newsrc_ent)
1414 mdata->unread -= mdata->newsrc_ent[0].last;
1415 }
1416 return mdata;
1417}
1418
1425void nntp_mailbox(struct Mailbox *m, char *buf, size_t buflen)
1426{
1427 if (!m)
1428 return;
1429
1430 for (unsigned int i = 0; i < CurrentNewsSrv->groups_num; i++)
1431 {
1433
1434 if (!mdata || !mdata->subscribed || !mdata->unread)
1435 continue;
1436
1437 if ((m->type == MUTT_NNTP) &&
1438 mutt_str_equal(mdata->group, ((struct NntpMboxData *) m->mdata)->group))
1439 {
1440 unsigned int unread = 0;
1441
1442 for (unsigned int j = 0; j < m->msg_count; j++)
1443 {
1444 struct Email *e = m->emails[j];
1445 if (!e)
1446 break;
1447 if (!e->read && !e->deleted)
1448 unread++;
1449 }
1450 if (unread == 0)
1451 continue;
1452 }
1453 mutt_str_copy(buf, mdata->group, buflen);
1454 break;
1455 }
1456}
1457
1464 // clang-format off
1465 { ED_NNTP, ED_NTP_ACCOUNT, nntp_a, NULL },
1466 { ED_NNTP, ED_NTP_PORT, NULL, nntp_p_num },
1468 { ED_NNTP, ED_NTP_SCHEMA, nntp_S, NULL },
1469 { ED_NNTP, ED_NTP_SERVER, nntp_s, NULL },
1470 { ED_NNTP, ED_NTP_USERNAME, nntp_u, NULL },
1471 { -1, -1, NULL, NULL },
1472 // clang-format on
1473};
Body Caching (local copies of email bodies)
struct BodyCache * mutt_bcache_open(struct ConnAccount *account, const char *mailbox)
Open an Email-Body Cache.
Definition: bcache.c:148
int mutt_bcache_list(struct BodyCache *bcache, bcache_list_t want_id, void *data)
Find matching entries in the Body Cache.
Definition: bcache.c:336
void mutt_bcache_close(struct BodyCache **ptr)
Close an Email-Body Cache.
Definition: bcache.c:169
int mutt_bcache_del(struct BodyCache *bcache, const char *id)
Delete a file from the Body Cache.
Definition: bcache.c:271
int buf_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:161
int buf_add_printf(struct Buffer *buf, const char *fmt,...)
Format a string appending a Buffer.
Definition: buffer.c:204
size_t buf_addch(struct Buffer *buf, char c)
Add a single character to a Buffer.
Definition: buffer.c:241
size_t buf_addstr(struct Buffer *buf, const char *s)
Add a string to a Buffer.
Definition: buffer.c:226
size_t buf_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition: buffer.c:395
char * buf_strdup(const struct Buffer *buf)
Copy a Buffer's string.
Definition: buffer.c:571
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition: buffer.h:96
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
Definition: helpers.c:291
const char * cs_subset_path(const struct ConfigSubset *sub, const char *name)
Get a path config item by name.
Definition: helpers.c:168
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:47
short cs_subset_sort(const struct ConfigSubset *sub, const char *name)
Get a sort config item by name.
Definition: helpers.c:266
const struct Expando * cs_subset_expando(const struct ConfigSubset *sub, const char *name)
Get an Expando config item by name.
Definition: config_type.c:357
Convenience wrapper for the config headers.
Connection Library.
ConnAccountField
Login credentials.
Definition: connaccount.h:33
@ MUTT_CA_OAUTH_CMD
OAuth refresh command.
Definition: connaccount.h:38
@ MUTT_CA_USER
User name.
Definition: connaccount.h:36
@ MUTT_CA_LOGIN
Login name.
Definition: connaccount.h:35
@ MUTT_CA_HOST
Server name.
Definition: connaccount.h:34
@ MUTT_CA_PASS
Password.
Definition: connaccount.h:37
#define MUTT_ACCT_SSL
Account uses SSL/TLS.
Definition: connaccount.h:47
@ ED_NTP_SCHEMA
ConnAccount.account.
Definition: connaccount.h:85
@ ED_NTP_USERNAME
ConnAccount.user.
Definition: connaccount.h:87
@ ED_NTP_PORT_IF
ConnAccount.port.
Definition: connaccount.h:84
@ ED_NTP_SERVER
ConnAccount.account.
Definition: connaccount.h:86
@ ED_NTP_ACCOUNT
ConnAccount.account.
Definition: connaccount.h:82
@ ED_NTP_PORT
ConnAccount.port.
Definition: connaccount.h:83
#define MUTT_ACCT_PASS
Password field has been set.
Definition: connaccount.h:46
#define MUTT_ACCT_USER
User field has been set.
Definition: connaccount.h:44
#define MUTT_ACCT_PORT
Port field has been set.
Definition: connaccount.h:43
Convenience wrapper for the core headers.
void mailbox_changed(struct Mailbox *m, enum NotifyMailbox action)
Notify observers of a change to a Mailbox.
Definition: mailbox.c:233
@ NT_MAILBOX_RESORT
Email list needs resorting.
Definition: mailbox.h:190
@ MUTT_NNTP
'NNTP' (Usenet) Mailbox type
Definition: mailbox.h:49
@ ED_NNTP
Nntp ED_NTP_ ExpandoDataNntp.
Definition: domain.h:49
Structs that make up an email.
int expando_filter(const struct Expando *exp, const struct ExpandoRenderData *rdata, void *data, MuttFormatFlags flags, int max_cols, struct Buffer *buf)
Render an Expando and run the result through a filter.
Definition: filter.c:138
Parse Expando string.
int mutt_file_mkdir(const char *path, mode_t mode)
Recursively create directories.
Definition: file.c:974
int mutt_file_lock(int fd, bool excl, bool timeout)
(Try to) Lock a file using fcntl()
Definition: file.c:1202
int mutt_file_unlock(int fd)
Unlock a file previously locked by mutt_file_lock()
Definition: file.c:1249
DIR * mutt_file_opendir(const char *path, enum MuttOpenDirMode mode)
Open a directory.
Definition: file.c:642
@ MUTT_OPENDIR_NONE
Plain opendir()
Definition: file.h:63
#define mutt_file_fclose(FP)
Definition: file.h:138
#define mutt_file_fopen(PATH, MODE)
Definition: file.h:137
void mutt_set_flag(struct Mailbox *m, struct Email *e, enum MessageType flag, bool bf, bool upd_mbox)
Set a flag on an email.
Definition: flags.c:57
static int nntp_bcache_delete(const char *id, struct BodyCache *bcache, void *data)
Delete an entry from the message cache - Implements bcache_list_t -.
Definition: newsrc.c:781
static const char * nntp_get_field(enum ConnAccountField field, void *gf_data)
Get connection login credentials - Implements ConnAccount::get_field() -.
Definition: newsrc.c:1032
long nntp_p_num(const struct ExpandoNode *node, void *data, MuttFormatFlags flags)
Newsrc: Port - Implements ExpandoRenderData::get_number() -.
Definition: newsrc.c:939
long nntp_P_num(const struct ExpandoNode *node, void *data, MuttFormatFlags flags)
Newsrc: Port if specified - Implements ExpandoRenderData::get_number() -.
Definition: newsrc.c:950
void nntp_u(const struct ExpandoNode *node, void *data, MuttFormatFlags flags, struct Buffer *buf)
Newsrc: Username - Implements ExpandoRenderData::get_string() -.
Definition: newsrc.c:1019
void nntp_P(const struct ExpandoNode *node, void *data, MuttFormatFlags flags, struct Buffer *buf)
Newsrc: Port if specified - Implements ExpandoRenderData::get_string() -.
Definition: newsrc.c:964
void nntp_S(const struct ExpandoNode *node, void *data, MuttFormatFlags flags, struct Buffer *buf)
Newsrc: Url schema - Implements ExpandoRenderData::get_string() -.
Definition: newsrc.c:996
void nntp_a(const struct ExpandoNode *node, void *data, MuttFormatFlags flags, struct Buffer *buf)
Newsrc: Account url - Implements ExpandoRenderData::get_string() -.
Definition: newsrc.c:916
void nntp_s(const struct ExpandoNode *node, void *data, MuttFormatFlags flags, struct Buffer *buf)
Newsrc: News server name - Implements ExpandoRenderData::get_string() -.
Definition: newsrc.c:979
static void nntp_hcache_namer(const char *path, struct Buffer *dest)
Compose hcache file names - Implements hcache_namer_t -.
Definition: newsrc.c:690
#define mutt_error(...)
Definition: logging2.h:92
#define mutt_message(...)
Definition: logging2.h:91
#define mutt_debug(LEVEL,...)
Definition: logging2.h:89
#define mutt_perror(...)
Definition: logging2.h:93
struct HashElem * mutt_hash_insert(struct HashTable *table, const char *strkey, void *data)
Add a new element to the Hash Table (with string keys)
Definition: hash.c:335
void * mutt_hash_find(const struct HashTable *table, const char *strkey)
Find the HashElem data in a Hash Table element using a key.
Definition: hash.c:362
void mutt_hash_free(struct HashTable **ptr)
Free a hash table.
Definition: hash.c:457
struct HeaderCache * hcache_open(const char *path, const char *folder, hcache_namer_t namer, bool create)
Multiplexor for StoreOps::open.
Definition: hcache.c:471
int hcache_delete_email(struct HeaderCache *hc, const char *key, size_t keylen)
Multiplexor for StoreOps::delete_record.
Definition: hcache.c:739
void hcache_close(struct HeaderCache **ptr)
Multiplexor for StoreOps::close.
Definition: hcache.c:542
char * hcache_fetch_raw_str(struct HeaderCache *hc, const char *key, size_t keylen)
Fetch a string from the cache.
Definition: hcache.c:652
int hcache_store_raw(struct HeaderCache *hc, const char *key, size_t keylen, void *data, size_t dlen)
Store a key / data pair.
Definition: hcache.c:724
Header cache multiplexor.
@ LL_DEBUG2
Log at debug level 2.
Definition: logging2.h:44
@ LL_DEBUG1
Log at debug level 1.
Definition: logging2.h:43
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:51
void * mutt_mem_malloc(size_t size)
Allocate memory on the heap.
Definition: memory.c:91
void mutt_mem_realloc(void *ptr, size_t size)
Resize a block of memory on the heap.
Definition: memory.c:115
#define FREE(x)
Definition: memory.h:45
Convenience wrapper for the library headers.
#define _(a)
Definition: message.h:28
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:253
char * mutt_str_lower(char *str)
Convert all characters in the string to lowercase.
Definition: string.c:313
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:660
size_t mutt_str_copy(char *dest, const char *src, size_t dsize)
Copy a string into a buffer (guaranteeing NUL-termination)
Definition: string.c:581
char * mutt_str_replace(char **p, const char *s)
Replace one string with another.
Definition: string.c:280
Many unsorted constants and some structs.
@ MUTT_READ
Messages that have been read.
Definition: mutt.h:73
#define PATH_MAX
Definition: mutt.h:42
int mutt_account_fromurl(struct ConnAccount *cac, const struct Url *url)
Fill ConnAccount with information from url.
Definition: mutt_account.c:44
void mutt_account_tourl(struct ConnAccount *cac, struct Url *url)
Fill URL with info from account.
Definition: mutt_account.c:80
ConnAccount object used by POP and IMAP.
@ MUTT_ACCT_TYPE_NNTP
Nntp (Usenet) Account.
Definition: mutt_account.h:41
void mutt_clear_error(void)
Clear the message line (bottom line of screen)
Definition: mutt_logging.c:74
NeoMutt Logging.
struct Connection * mutt_conn_find(const struct ConnAccount *cac)
Find a connection from a list.
Definition: mutt_socket.c:90
NeoMutt connections.
void buf_expand_path(struct Buffer *buf)
Create the canonical path.
Definition: muttlib.c:315
void mutt_encode_path(struct Buffer *buf, const char *src)
Convert a path to 'us-ascii'.
Definition: muttlib.c:872
Some miscellaneous functions.
struct HeaderCache * nntp_hcache_open(struct NntpMboxData *mdata)
Open newsgroup hcache.
Definition: newsrc.c:709
void nntp_clear_cache(struct NntpAccountData *adata)
Clear the NNTP cache.
Definition: newsrc.c:843
void nntp_delete_group_cache(struct NntpMboxData *mdata)
Remove hcache and bcache of newsgroup.
Definition: newsrc.c:810
const struct ExpandoRenderData NntpRenderData[]
Callbacks for Newsrc Expandos.
Definition: newsrc.c:67
void nntp_newsrc_gen_entries(struct Mailbox *m)
Generate array of .newsrc entries.
Definition: newsrc.c:303
void nntp_hcache_update(struct NntpMboxData *mdata, struct HeaderCache *hc)
Remove stale cached headers.
Definition: newsrc.c:733
void nntp_article_status(struct Mailbox *m, struct Email *e, char *group, anum_t anum)
Get status of articles from .newsrc.
Definition: newsrc.c:1255
static int update_file(char *filename, char *buf)
Update file with new contents.
Definition: newsrc.c:395
int nntp_add_group(char *line, void *data)
Parse newsgroup.
Definition: newsrc.c:574
int nntp_newsrc_parse(struct NntpAccountData *adata)
Parse .newsrc file.
Definition: newsrc.c:166
void nntp_mailbox(struct Mailbox *m, char *buf, size_t buflen)
Get first newsgroup with new messages.
Definition: newsrc.c:1425
void nntp_newsrc_close(struct NntpAccountData *adata)
Unlock and close .newsrc file.
Definition: newsrc.c:122
struct NntpMboxData * mutt_newsgroup_catchup(struct Mailbox *m, struct NntpAccountData *adata, char *group)
Catchup newsgroup.
Definition: newsrc.c:1343
int nntp_newsrc_update(struct NntpAccountData *adata)
Update .newsrc file.
Definition: newsrc.c:445
struct NntpMboxData * mutt_newsgroup_subscribe(struct NntpAccountData *adata, char *group)
Subscribe newsgroup.
Definition: newsrc.c:1292
void nntp_expand_path(char *buf, size_t buflen, struct ConnAccount *cac)
Make fully qualified url from newsgroup name.
Definition: newsrc.c:558
static int active_get_cache(struct NntpAccountData *adata)
Load list of all newsgroups from cache.
Definition: newsrc.c:615
static void cache_expand(char *dst, size_t dstlen, struct ConnAccount *cac, const char *src)
Make fully qualified cache file name.
Definition: newsrc.c:526
static struct NntpMboxData * mdata_find(struct NntpAccountData *adata, const char *group)
Find NntpMboxData for given newsgroup or add it.
Definition: newsrc.c:76
struct NntpMboxData * mutt_newsgroup_uncatchup(struct Mailbox *m, struct NntpAccountData *adata, char *group)
Uncatchup newsgroup.
Definition: newsrc.c:1382
int nntp_active_save_cache(struct NntpAccountData *adata)
Save list of all newsgroups to cache.
Definition: newsrc.c:649
void nntp_bcache_update(struct NntpMboxData *mdata)
Remove stale cached messages.
Definition: newsrc.c:801
void nntp_group_unread_stat(struct NntpMboxData *mdata)
Count number of unread articles using .newsrc data.
Definition: newsrc.c:136
void nntp_acache_free(struct NntpMboxData *mdata)
Remove all temporarily cache files.
Definition: newsrc.c:106
struct NntpAccountData * nntp_select_server(struct Mailbox *m, const char *server, bool leave_lock)
Open a connection to an NNTP server.
Definition: newsrc.c:1063
struct NntpMboxData * mutt_newsgroup_unsubscribe(struct NntpAccountData *adata, char *group)
Unsubscribe newsgroup.
Definition: newsrc.c:1316
struct NntpAccountData * nntp_adata_new(struct Connection *conn)
Allocate and initialise a new NntpAccountData structure.
Definition: adata.c:65
struct NntpEmailData * nntp_edata_get(struct Email *e)
Get the private data for this Email.
Definition: edata.c:60
int nntp_active_fetch(struct NntpAccountData *adata, bool mark_new)
Fetch list of all newsgroups from server.
Definition: nntp.c:2037
#define NNTP_ACACHE_LEN
Definition: lib.h:82
#define ANUM_FMT
Definition: lib.h:61
struct NntpAccountData * CurrentNewsSrv
Current NNTP news server.
Definition: nntp.c:77
#define anum_t
Definition: lib.h:60
#define NNTP_SSL_PORT
Definition: private.h:37
#define NNTP_PORT
Definition: private.h:36
int nntp_check_new_groups(struct Mailbox *m, struct NntpAccountData *adata)
Check for new groups/articles in subscribed groups.
Definition: nntp.c:2105
int nntp_open_connection(struct NntpAccountData *adata)
Connect to server, authenticate and get capabilities.
Definition: nntp.c:1766
Notmuch-specific Mailbox data.
struct Buffer * buf_pool_get(void)
Get a Buffer from the pool.
Definition: pool.c:81
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
Definition: pool.c:94
Pop-specific Account data.
Pop-specific Email data.
Prototypes for many functions.
#define MUTT_FORMAT_NO_FLAGS
No flags are set.
Definition: render.h:33
uint8_t MuttFormatFlags
Flags for expando_render(), e.g. MUTT_FORMAT_FORCESUBJ.
Definition: render.h:32
GUI display the mailboxes in a side panel.
int mutt_socket_close(struct Connection *conn)
Close a socket.
Definition: socket.c:100
SortType
Methods for sorting.
Definition: sort2.h:34
@ SORT_ORDER
Sort by the order the messages appear in the mailbox.
Definition: sort2.h:40
Key value store.
void * adata
Private data (for Mailbox backends)
Definition: account.h:42
Local cache of email bodies.
Definition: bcache.c:51
String manipulation buffer.
Definition: buffer.h:36
size_t dsize
Length of data.
Definition: buffer.h:39
char * data
Pointer to data.
Definition: buffer.h:37
Login details for a remote server.
Definition: connaccount.h:53
char user[128]
Username.
Definition: connaccount.h:56
char pass[256]
Password.
Definition: connaccount.h:57
const char * service
Name of the service, e.g. "imap".
Definition: connaccount.h:61
char host[128]
Server to login to.
Definition: connaccount.h:54
const char *(* get_field)(enum ConnAccountField field, void *gf_data)
Definition: connaccount.h:70
unsigned char type
Connection type, e.g. MUTT_ACCT_TYPE_IMAP.
Definition: connaccount.h:59
MuttAccountFlags flags
Which fields are initialised, e.g. MUTT_ACCT_USER.
Definition: connaccount.h:60
void * gf_data
Private data to pass to get_field()
Definition: connaccount.h:72
unsigned short port
Port to connect to.
Definition: connaccount.h:58
struct ConnAccount account
Account details: username, password, etc.
Definition: connection.h:49
The envelope/body of an email.
Definition: email.h:39
bool read
Email is read.
Definition: email.h:50
bool old
Email is seen, but unread.
Definition: email.h:49
bool deleted
Email is deleted.
Definition: email.h:78
Basic Expando Node.
Definition: node.h:67
Parsed Expando trees.
Definition: expando.h:41
Header Cache.
Definition: lib.h:86
A mailbox.
Definition: mailbox.h:79
int msg_count
Total number of messages.
Definition: mailbox.h:88
enum MailboxType type
Mailbox type.
Definition: mailbox.h:102
void * mdata
Driver specific data.
Definition: mailbox.h:132
struct Email ** emails
Array of Emails.
Definition: mailbox.h:96
Container for Accounts, Notifications.
Definition: neomutt.h:42
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:46
An entry in a .newsrc (subscribed newsgroups)
Definition: lib.h:76
anum_t last
Last article number in run.
Definition: lib.h:78
anum_t first
First article number in run.
Definition: lib.h:77
NNTP-specific Account data -.
Definition: adata.h:36
time_t newgroups_time
Definition: adata.h:56
bool newsrc_modified
Definition: adata.h:49
struct HashTable * groups_hash
Hash Table: "newsgroup" -> NntpMboxData.
Definition: adata.h:61
off_t size
Definition: adata.h:54
struct Connection * conn
Connection to NNTP Server.
Definition: adata.h:62
char * authenticators
Definition: adata.h:52
unsigned int groups_num
Definition: adata.h:58
time_t mtime
Definition: adata.h:55
unsigned int groups_max
Definition: adata.h:59
FILE * fp_newsrc
Definition: adata.h:50
void ** groups_list
Definition: adata.h:60
bool cacheable
Definition: adata.h:48
char * newsrc_file
Definition: adata.h:51
anum_t article_num
NNTP article number.
Definition: edata.h:36
NNTP-specific Mailbox data -.
Definition: mdata.h:34
anum_t last_cached
Definition: mdata.h:40
anum_t last_message
Definition: mdata.h:38
struct BodyCache * bcache
Definition: mdata.h:50
char * group
Name of newsgroup.
Definition: mdata.h:35
struct NntpAccountData * adata
Definition: mdata.h:48
char * desc
Description of newsgroup.
Definition: mdata.h:36
struct NewsrcEntry * newsrc_ent
Definition: mdata.h:47
anum_t unread
Definition: mdata.h:41
anum_t last_loaded
Definition: mdata.h:39
unsigned int newsrc_len
Definition: mdata.h:46
anum_t first_message
Definition: mdata.h:37
bool subscribed
Definition: mdata.h:42
A parsed URL proto://user:password@host:port/path?a=1&b=2
Definition: url.h:69
char * user
Username.
Definition: url.h:71
char * host
Host.
Definition: url.h:73
char * src
Raw URL string.
Definition: url.h:77
char * pass
Password.
Definition: url.h:72
char * path
Path.
Definition: url.h:75
enum UrlScheme scheme
Scheme, e.g. U_SMTPS.
Definition: url.h:70
int cs_subset_str_native_set(const struct ConfigSubset *sub, const char *name, intptr_t value, struct Buffer *err)
Natively set the value of a string config item.
Definition: subset.c:297
struct Url * url_parse(const char *src)
Fill in Url.
Definition: url.c:239
void url_free(struct Url **ptr)
Free the contents of a URL.
Definition: url.c:124
int url_tostring(const struct Url *url, char *dest, size_t len, uint8_t flags)
Output the URL string for a given Url object.
Definition: url.c:423
#define U_NO_FLAGS
Definition: url.h:49
@ U_NNTPS
Url is nntps://.
Definition: url.h:42
@ U_NNTP
Url is nntp://.
Definition: url.h:41
#define U_PATH
Definition: url.h:50