NeoMutt  2022-04-29-215-gc12b98
Teaching an old dog new tricks
DOXYGEN
newsrc.c
Go to the documentation of this file.
1
31#include "config.h"
32#include <dirent.h>
33#include <errno.h>
34#include <inttypes.h>
35#include <limits.h>
36#include <stdbool.h>
37#include <stdio.h>
38#include <string.h>
39#include <sys/stat.h>
40#include <unistd.h>
41#include "private.h"
42#include "mutt/lib.h"
43#include "config/lib.h"
44#include "email/lib.h"
45#include "core/lib.h"
46#include "conn/lib.h"
47#include "mutt.h"
48#include "lib.h"
49#include "bcache/lib.h"
50#include "adata.h"
51#include "edata.h"
52#include "format_flags.h"
53#include "mdata.h"
54#include "mutt_account.h"
55#include "mutt_logging.h"
56#include "mutt_socket.h"
57#include "muttlib.h"
58#include "protos.h"
59#ifdef USE_HCACHE
60#include "hcache/lib.h"
61#endif
62
63struct BodyCache;
64
72static struct NntpMboxData *mdata_find(struct NntpAccountData *adata, const char *group)
73{
75 if (mdata)
76 return mdata;
77
78 size_t len = strlen(group) + 1;
79 /* create NntpMboxData structure and add it to hash */
80 mdata = mutt_mem_calloc(1, sizeof(struct NntpMboxData) + len);
81 mdata->group = (char *) mdata + sizeof(struct NntpMboxData);
82 mutt_str_copy(mdata->group, group, len);
83 mdata->adata = adata;
84 mdata->deleted = true;
86
87 /* add NntpMboxData to list */
89 {
90 adata->groups_max *= 2;
92 }
94
95 return mdata;
96}
97
103{
104 for (int i = 0; i < NNTP_ACACHE_LEN; i++)
105 {
106 if (mdata->acache[i].path)
107 {
108 unlink(mdata->acache[i].path);
109 FREE(&mdata->acache[i].path);
110 }
111 }
112}
113
119{
120 if (!adata->fp_newsrc)
121 return;
122
123 mutt_debug(LL_DEBUG1, "Unlocking %s\n", adata->newsrc_file);
126}
127
133{
134 mdata->unread = 0;
135 if ((mdata->last_message == 0) ||
136 (mdata->first_message > mdata->last_message) || !mdata->newsrc_ent)
137 {
138 return;
139 }
140
141 mdata->unread = mdata->last_message - mdata->first_message + 1;
142 for (unsigned int i = 0; i < mdata->newsrc_len; i++)
143 {
144 anum_t first = mdata->newsrc_ent[i].first;
145 if (first < mdata->first_message)
146 first = mdata->first_message;
147 anum_t last = mdata->newsrc_ent[i].last;
148 if (last > mdata->last_message)
149 last = mdata->last_message;
150 if (first <= last)
151 mdata->unread -= last - first + 1;
152 }
153}
154
163{
164 if (!adata)
165 return -1;
166
167 char *line = NULL;
168 struct stat st = { 0 };
169
170 if (adata->fp_newsrc)
171 {
172 /* if we already have a handle, close it and reopen */
174 }
175 else
176 {
177 /* if file doesn't exist, create it */
178 adata->fp_newsrc = mutt_file_fopen(adata->newsrc_file, "a");
180 }
181
182 /* open .newsrc */
183 adata->fp_newsrc = mutt_file_fopen(adata->newsrc_file, "r");
184 if (!adata->fp_newsrc)
185 {
186 mutt_perror(adata->newsrc_file);
187 return -1;
188 }
189
190 /* lock it */
191 mutt_debug(LL_DEBUG1, "Locking %s\n", adata->newsrc_file);
192 if (mutt_file_lock(fileno(adata->fp_newsrc), false, true))
193 {
195 return -1;
196 }
197
198 if (stat(adata->newsrc_file, &st) != 0)
199 {
200 mutt_perror(adata->newsrc_file);
201 nntp_newsrc_close(adata);
202 return -1;
203 }
204
205 if ((adata->size == st.st_size) && (adata->mtime == st.st_mtime))
206 return 0;
207
208 adata->size = st.st_size;
209 adata->mtime = st.st_mtime;
210 adata->newsrc_modified = true;
211 mutt_debug(LL_DEBUG1, "Parsing %s\n", adata->newsrc_file);
212
213 /* .newsrc has been externally modified or hasn't been loaded yet */
214 for (unsigned int i = 0; i < adata->groups_num; i++)
215 {
216 struct NntpMboxData *mdata = adata->groups_list[i];
217 if (!mdata)
218 continue;
219
220 mdata->subscribed = false;
221 mdata->newsrc_len = 0;
222 FREE(&mdata->newsrc_ent);
223 }
224
225 line = mutt_mem_malloc(st.st_size + 1);
226 while (st.st_size && fgets(line, st.st_size + 1, adata->fp_newsrc))
227 {
228 char *b = NULL, *h = NULL;
229 unsigned int j = 1;
230 bool subs = false;
231
232 /* find end of newsgroup name */
233 char *p = strpbrk(line, ":!");
234 if (!p)
235 continue;
236
237 /* ":" - subscribed, "!" - unsubscribed */
238 if (*p == ':')
239 subs = true;
240 *p++ = '\0';
241
242 /* get newsgroup data */
243 struct NntpMboxData *mdata = mdata_find(adata, line);
244 FREE(&mdata->newsrc_ent);
245
246 /* count number of entries */
247 b = p;
248 while (*b)
249 if (*b++ == ',')
250 j++;
251 mdata->newsrc_ent = mutt_mem_calloc(j, sizeof(struct NewsrcEntry));
252 mdata->subscribed = subs;
253
254 /* parse entries */
255 j = 0;
256 while (p)
257 {
258 b = p;
259
260 /* find end of entry */
261 p = strchr(p, ',');
262 if (p)
263 *p++ = '\0';
264
265 /* first-last or single number */
266 h = strchr(b, '-');
267 if (h)
268 *h++ = '\0';
269 else
270 h = b;
271
272 if ((sscanf(b, ANUM, &mdata->newsrc_ent[j].first) == 1) &&
273 (sscanf(h, ANUM, &mdata->newsrc_ent[j].last) == 1))
274 {
275 j++;
276 }
277 }
278 if (j == 0)
279 {
280 mdata->newsrc_ent[j].first = 1;
281 mdata->newsrc_ent[j].last = 0;
282 j++;
283 }
284 if (mdata->last_message == 0)
285 mdata->last_message = mdata->newsrc_ent[j - 1].last;
286 mdata->newsrc_len = j;
287 mutt_mem_realloc(&mdata->newsrc_ent, j * sizeof(struct NewsrcEntry));
289 mutt_debug(LL_DEBUG2, "%s\n", mdata->group);
290 }
291 FREE(&line);
292 return 1;
293}
294
300{
301 if (!m)
302 return;
303
304 struct NntpMboxData *mdata = m->mdata;
305 anum_t last = 0, first = 1;
306 bool series;
307 unsigned int entries;
308
309 const short c_sort = cs_subset_sort(NeoMutt->sub, "sort");
310 if (c_sort != SORT_ORDER)
311 {
314 }
315
316 entries = mdata->newsrc_len;
317 if (!entries)
318 {
319 entries = 5;
320 mdata->newsrc_ent = mutt_mem_calloc(entries, sizeof(struct NewsrcEntry));
321 }
322
323 /* Set up to fake initial sequence from 1 to the article before the
324 * first article in our list */
325 mdata->newsrc_len = 0;
326 series = true;
327 for (int i = 0; i < m->msg_count; i++)
328 {
329 struct Email *e = m->emails[i];
330 if (!e)
331 break;
332
333 /* search for first unread */
334 if (series)
335 {
336 /* We don't actually check sequential order, since we mark
337 * "missing" entries as read/deleted */
338 last = nntp_edata_get(e)->article_num;
339 if ((last >= mdata->first_message) && !e->deleted && !e->read)
340 {
341 if (mdata->newsrc_len >= entries)
342 {
343 entries *= 2;
344 mutt_mem_realloc(&mdata->newsrc_ent, entries * sizeof(struct NewsrcEntry));
345 }
346 mdata->newsrc_ent[mdata->newsrc_len].first = first;
347 mdata->newsrc_ent[mdata->newsrc_len].last = last - 1;
348 mdata->newsrc_len++;
349 series = false;
350 }
351 }
352
353 /* search for first read */
354 else
355 {
356 if (e->deleted || e->read)
357 {
358 first = last + 1;
359 series = true;
360 }
361 last = nntp_edata_get(e)->article_num;
362 }
363 }
364
365 if (series && (first <= mdata->last_loaded))
366 {
367 if (mdata->newsrc_len >= entries)
368 {
369 entries++;
370 mutt_mem_realloc(&mdata->newsrc_ent, entries * sizeof(struct NewsrcEntry));
371 }
372 mdata->newsrc_ent[mdata->newsrc_len].first = first;
373 mdata->newsrc_ent[mdata->newsrc_len].last = mdata->last_loaded;
374 mdata->newsrc_len++;
375 }
376 mutt_mem_realloc(&mdata->newsrc_ent, mdata->newsrc_len * sizeof(struct NewsrcEntry));
377
378 if (c_sort != SORT_ORDER)
379 {
380 cs_subset_str_native_set(NeoMutt->sub, "sort", c_sort, NULL);
382 }
383}
384
392static int update_file(char *filename, char *buf)
393{
394 FILE *fp = NULL;
395 char tmpfile[PATH_MAX] = { 0 };
396 int rc = -1;
397
398 while (true)
399 {
400 snprintf(tmpfile, sizeof(tmpfile), "%s.tmp", filename);
401 fp = mutt_file_fopen(tmpfile, "w");
402 if (!fp)
403 {
404 mutt_perror(tmpfile);
405 *tmpfile = '\0';
406 break;
407 }
408 if (fputs(buf, fp) == EOF)
409 {
410 mutt_perror(tmpfile);
411 break;
412 }
413 if (mutt_file_fclose(&fp) == EOF)
414 {
415 mutt_perror(tmpfile);
416 fp = NULL;
417 break;
418 }
419 fp = NULL;
420 if (rename(tmpfile, filename) < 0)
421 {
422 mutt_perror(filename);
423 break;
424 }
425 *tmpfile = '\0';
426 rc = 0;
427 break;
428 }
429 mutt_file_fclose(&fp);
430
431 if (*tmpfile)
432 unlink(tmpfile);
433 return rc;
434}
435
443{
444 if (!adata)
445 return -1;
446
447 int rc = -1;
448
449 size_t buflen = 10240;
450 char *buf = mutt_mem_calloc(1, buflen);
451 size_t off = 0;
452
453 /* we will generate full newsrc here */
454 for (unsigned int i = 0; i < adata->groups_num; i++)
455 {
456 struct NntpMboxData *mdata = adata->groups_list[i];
457
458 if (!mdata || !mdata->newsrc_ent)
459 continue;
460
461 /* write newsgroup name */
462 if (off + strlen(mdata->group) + 3 > buflen)
463 {
464 buflen *= 2;
465 mutt_mem_realloc(&buf, buflen);
466 }
467 snprintf(buf + off, buflen - off, "%s%c ", mdata->group, mdata->subscribed ? ':' : '!');
468 off += strlen(buf + off);
469
470 /* write entries */
471 for (unsigned int j = 0; j < mdata->newsrc_len; j++)
472 {
473 if (off + 1024 > buflen)
474 {
475 buflen *= 2;
476 mutt_mem_realloc(&buf, buflen);
477 }
478 if (j)
479 buf[off++] = ',';
480 if (mdata->newsrc_ent[j].first == mdata->newsrc_ent[j].last)
481 snprintf(buf + off, buflen - off, ANUM, mdata->newsrc_ent[j].first);
482 else if (mdata->newsrc_ent[j].first < mdata->newsrc_ent[j].last)
483 {
484 snprintf(buf + off, buflen - off, ANUM "-" ANUM,
485 mdata->newsrc_ent[j].first, mdata->newsrc_ent[j].last);
486 }
487 off += strlen(buf + off);
488 }
489 buf[off++] = '\n';
490 }
491 buf[off] = '\0';
492
493 /* newrc being fully rewritten */
494 mutt_debug(LL_DEBUG1, "Updating %s\n", adata->newsrc_file);
495 if (adata->newsrc_file && (update_file(adata->newsrc_file, buf) == 0))
496 {
497 struct stat st = { 0 };
498
499 rc = stat(adata->newsrc_file, &st);
500 if (rc == 0)
501 {
502 adata->size = st.st_size;
503 adata->mtime = st.st_mtime;
504 }
505 else
506 {
507 mutt_perror(adata->newsrc_file);
508 }
509 }
510 FREE(&buf);
511 return rc;
512}
513
521static void cache_expand(char *dst, size_t dstlen, struct ConnAccount *cac, const char *src)
522{
523 char *c = NULL;
524 char file[PATH_MAX] = { 0 };
525
526 /* server subdirectory */
527 if (cac)
528 {
529 struct Url url = { 0 };
530
531 mutt_account_tourl(cac, &url);
532 url.path = mutt_str_dup(src);
533 url_tostring(&url, file, sizeof(file), U_PATH);
534 FREE(&url.path);
535 }
536 else
537 mutt_str_copy(file, src ? src : "", sizeof(file));
538
539 const char *const c_news_cache_dir = cs_subset_path(NeoMutt->sub, "news_cache_dir");
540 snprintf(dst, dstlen, "%s/%s", c_news_cache_dir, file);
541
542 /* remove trailing slash */
543 c = dst + strlen(dst) - 1;
544 if (*c == '/')
545 *c = '\0';
546
547 struct Buffer *tmp = mutt_buffer_pool_get();
548 mutt_buffer_addstr(tmp, dst);
550 mutt_encode_path(tmp, dst);
551 mutt_str_copy(dst, mutt_buffer_string(tmp), dstlen);
553}
554
561void nntp_expand_path(char *buf, size_t buflen, struct ConnAccount *cac)
562{
563 struct Url url = { 0 };
564
565 mutt_account_tourl(cac, &url);
566 url.path = mutt_str_dup(buf);
567 url_tostring(&url, buf, buflen, U_NO_FLAGS);
568 FREE(&url.path);
569}
570
577int nntp_add_group(char *line, void *data)
578{
579 struct NntpAccountData *adata = data;
580 struct NntpMboxData *mdata = NULL;
581 char group[1024] = { 0 };
582 char desc[8192] = { 0 };
583 char mod;
584 anum_t first, last;
585
586 if (!adata || !line)
587 return 0;
588
589 /* These sscanf limits must match the sizes of the group and desc arrays */
590 if (sscanf(line, "%1023s " ANUM " " ANUM " %c %8191[^\n]", group, &last,
591 &first, &mod, desc) < 4)
592 {
593 mutt_debug(LL_DEBUG2, "Can't parse server line: %s\n", line);
594 return 0;
595 }
596
598 mdata->deleted = false;
599 mdata->first_message = first;
600 mdata->last_message = last;
601 mdata->allowed = (mod == 'y') || (mod == 'm');
602 mutt_str_replace(&mdata->desc, desc);
603 if (mdata->newsrc_ent || (mdata->last_cached != 0))
605 else if (mdata->last_message && (mdata->first_message <= mdata->last_message))
606 mdata->unread = mdata->last_message - mdata->first_message + 1;
607 else
608 mdata->unread = 0;
609 return 0;
610}
611
619{
620 char buf[8192] = { 0 };
621 char file[4096] = { 0 };
622 time_t t = 0;
623
624 cache_expand(file, sizeof(file), &adata->conn->account, ".active");
625 mutt_debug(LL_DEBUG1, "Parsing %s\n", file);
626 FILE *fp = mutt_file_fopen(file, "r");
627 if (!fp)
628 return -1;
629
630 if (!fgets(buf, sizeof(buf), fp) || (sscanf(buf, "%jd%4095s", &t, file) != 1) || (t == 0))
631 {
632 mutt_file_fclose(&fp);
633 return -1;
634 }
636
637 mutt_message(_("Loading list of groups from cache..."));
638 while (fgets(buf, sizeof(buf), fp))
639 nntp_add_group(buf, adata);
640 nntp_add_group(NULL, NULL);
641 mutt_file_fclose(&fp);
643 return 0;
644}
645
653{
654 if (!adata->cacheable)
655 return 0;
656
657 size_t buflen = 10240;
658 char *buf = mutt_mem_calloc(1, buflen);
659 snprintf(buf, buflen, "%lu\n", (unsigned long) adata->newgroups_time);
660 size_t off = strlen(buf);
661
662 for (unsigned int i = 0; i < adata->groups_num; i++)
663 {
664 struct NntpMboxData *mdata = adata->groups_list[i];
665
666 if (!mdata || mdata->deleted)
667 continue;
668
669 if ((off + strlen(mdata->group) + (mdata->desc ? strlen(mdata->desc) : 0) + 50) > buflen)
670 {
671 buflen *= 2;
672 mutt_mem_realloc(&buf, buflen);
673 }
674 snprintf(buf + off, buflen - off, "%s " ANUM " " ANUM " %c%s%s\n", mdata->group,
675 mdata->last_message, mdata->first_message, mdata->allowed ? 'y' : 'n',
676 mdata->desc ? " " : "", mdata->desc ? mdata->desc : "");
677 off += strlen(buf + off);
678 }
679
680 char file[PATH_MAX] = { 0 };
681 cache_expand(file, sizeof(file), &adata->conn->account, ".active");
682 mutt_debug(LL_DEBUG1, "Updating %s\n", file);
683 int rc = update_file(file, buf);
684 FREE(&buf);
685 return rc;
686}
687
688#ifdef USE_HCACHE
692static void nntp_hcache_namer(const char *path, struct Buffer *dest)
693{
694 mutt_buffer_printf(dest, "%s.hcache", path);
695
696 /* Strip out any directories in the path */
697 char *first = strchr(mutt_buffer_string(dest), '/');
698 char *last = strrchr(mutt_buffer_string(dest), '/');
699 if (first && last && (last > first))
700 {
701 memmove(first, last, strlen(last) + 1);
702 }
703}
704
712{
713 struct Url url = { 0 };
714 char file[PATH_MAX] = { 0 };
715
716 const bool c_save_unsubscribed = cs_subset_bool(NeoMutt->sub, "save_unsubscribed");
717 if (!mdata->adata || !mdata->adata->cacheable || !mdata->adata->conn || !mdata->group ||
718 !(mdata->newsrc_ent || mdata->subscribed || c_save_unsubscribed))
719 {
720 return NULL;
721 }
722
723 mutt_account_tourl(&mdata->adata->conn->account, &url);
724 url.path = mdata->group;
725 url_tostring(&url, file, sizeof(file), U_PATH);
726 const char *const c_news_cache_dir = cs_subset_path(NeoMutt->sub, "news_cache_dir");
727 return mutt_hcache_open(c_news_cache_dir, file, nntp_hcache_namer);
728}
729
735void nntp_hcache_update(struct NntpMboxData *mdata, struct HeaderCache *hc)
736{
737 if (!hc)
738 return;
739
740 char buf[32] = { 0 };
741 bool old = false;
742 anum_t first = 0, last = 0;
743
744 /* fetch previous values of first and last */
745 size_t dlen = 0;
746 char *hdata = mutt_hcache_fetch_raw(hc, "index", 5, &dlen);
747 if (hdata)
748 {
749 mutt_debug(LL_DEBUG2, "mutt_hcache_fetch index: %s\n", (char *) hdata);
750 if ((dlen > 0) && (hdata[dlen - 1] == '\0') &&
751 sscanf(hdata, ANUM " " ANUM, &first, &last) == 2)
752 {
753 old = true;
754 mdata->last_cached = last;
755
756 /* clean removed headers from cache */
757 for (anum_t current = first; current <= last; current++)
758 {
759 if ((current >= mdata->first_message) && (current <= mdata->last_message))
760 continue;
761
762 snprintf(buf, sizeof(buf), ANUM, current);
763 mutt_debug(LL_DEBUG2, "mutt_hcache_delete_record %s\n", buf);
764 mutt_hcache_delete_record(hc, buf, strlen(buf));
765 }
766 }
767 mutt_hcache_free_raw(hc, (void **) &hdata);
768 }
769
770 /* store current values of first and last */
771 if (!old || (mdata->first_message != first) || (mdata->last_message != last))
772 {
773 snprintf(buf, sizeof(buf), ANUM " " ANUM, mdata->first_message, mdata->last_message);
774 mutt_debug(LL_DEBUG2, "mutt_hcache_store index: %s\n", buf);
775 mutt_hcache_store_raw(hc, "index", 5, buf, strlen(buf) + 1);
776 }
777}
778#endif
779
784static int nntp_bcache_delete(const char *id, struct BodyCache *bcache, void *data)
785{
786 struct NntpMboxData *mdata = data;
787 anum_t anum;
788 char c;
789
790 if (!mdata || (sscanf(id, ANUM "%c", &anum, &c) != 1) ||
791 (anum < mdata->first_message) || (anum > mdata->last_message))
792 {
793 if (mdata)
794 mutt_debug(LL_DEBUG2, "mutt_bcache_del %s\n", id);
796 }
797 return 0;
798}
799
805{
807}
808
814{
815 if (!mdata || !mdata->adata || !mdata->adata->cacheable)
816 return;
817
818#ifdef USE_HCACHE
819 struct Buffer file = mutt_buffer_make(PATH_MAX);
820 nntp_hcache_namer(mdata->group, &file);
821 cache_expand(file.data, file.dsize, &mdata->adata->conn->account,
822 mutt_buffer_string(&file));
823 unlink(mutt_buffer_string(&file));
824 mdata->last_cached = 0;
825 mutt_debug(LL_DEBUG2, "%s\n", mutt_buffer_string(&file));
826 mutt_buffer_dealloc(&file);
827#endif
828
829 if (!mdata->bcache)
830 {
831 mdata->bcache = mutt_bcache_open(&mdata->adata->conn->account, mdata->group);
832 }
833 if (mdata->bcache)
834 {
835 mutt_debug(LL_DEBUG2, "%s/*\n", mdata->group);
837 mutt_bcache_close(&mdata->bcache);
838 }
839}
840
848{
849 char file[PATH_MAX] = { 0 };
850 char *fp = NULL;
851 struct dirent *entry = NULL;
852 DIR *dp = NULL;
853
854 if (!adata || !adata->cacheable)
855 return;
856
857 cache_expand(file, sizeof(file), &adata->conn->account, NULL);
858 dp = opendir(file);
859 if (dp)
860 {
861 mutt_strn_cat(file, sizeof(file), "/", 1);
862 fp = file + strlen(file);
863 while ((entry = readdir(dp)))
864 {
865 char *group = entry->d_name;
866 struct stat st = { 0 };
867 struct NntpMboxData *mdata = NULL;
868 struct NntpMboxData tmp_mdata;
869
870 if (mutt_str_equal(group, ".") || mutt_str_equal(group, ".."))
871 continue;
872 *fp = '\0';
873 mutt_strn_cat(file, sizeof(file), group, strlen(group));
874 if (stat(file, &st) != 0)
875 continue;
876
877#ifdef USE_HCACHE
878 if (S_ISREG(st.st_mode))
879 {
880 char *ext = group + strlen(group) - 7;
881 if ((strlen(group) < 8) || !mutt_str_equal(ext, ".hcache"))
882 continue;
883 *ext = '\0';
884 }
885 else
886#endif
887 if (!S_ISDIR(st.st_mode))
888 continue;
889
890 const bool c_save_unsubscribed = cs_subset_bool(NeoMutt->sub, "save_unsubscribed");
892 if (!mdata)
893 {
894 mdata = &tmp_mdata;
895 mdata->adata = adata;
896 mdata->group = group;
897 mdata->bcache = NULL;
898 }
899 else if (mdata->newsrc_ent || mdata->subscribed || c_save_unsubscribed)
900 continue;
901
903 if (S_ISDIR(st.st_mode))
904 {
905 rmdir(file);
906 mutt_debug(LL_DEBUG2, "%s\n", file);
907 }
908 }
909 closedir(dp);
910 }
911}
912
925const char *nntp_format_str(char *buf, size_t buflen, size_t col, int cols, char op,
926 const char *src, const char *prec, const char *if_str,
927 const char *else_str, intptr_t data, MuttFormatFlags flags)
928{
929 struct NntpAccountData *adata = (struct NntpAccountData *) data;
930 struct ConnAccount *cac = &adata->conn->account;
931 char fn[128], fmt[128];
932
933 switch (op)
934 {
935 case 'a':
936 {
937 struct Url url = { 0 };
938 mutt_account_tourl(cac, &url);
939 url_tostring(&url, fn, sizeof(fn), U_PATH);
940 char *p = strchr(fn, '/');
941 if (p)
942 *p = '\0';
943 snprintf(fmt, sizeof(fmt), "%%%ss", prec);
944 snprintf(buf, buflen, fmt, fn);
945 break;
946 }
947 case 'p':
948 snprintf(fmt, sizeof(fmt), "%%%su", prec);
949 snprintf(buf, buflen, fmt, cac->port);
950 break;
951 case 'P':
952 *buf = '\0';
953 if (cac->flags & MUTT_ACCT_PORT)
954 {
955 snprintf(fmt, sizeof(fmt), "%%%su", prec);
956 snprintf(buf, buflen, fmt, cac->port);
957 }
958 break;
959 case 's':
960 mutt_str_copy(fn, cac->host, sizeof(fn));
961 mutt_str_lower(fn);
962 snprintf(fmt, sizeof(fmt), "%%%ss", prec);
963 snprintf(buf, buflen, fmt, fn);
964 break;
965 case 'S':
966 {
967 struct Url url = { 0 };
968 mutt_account_tourl(cac, &url);
969 url_tostring(&url, fn, sizeof(fn), U_PATH);
970 char *p = strchr(fn, ':');
971 if (p)
972 *p = '\0';
973 snprintf(fmt, sizeof(fmt), "%%%ss", prec);
974 snprintf(buf, buflen, fmt, fn);
975 break;
976 }
977 case 'u':
978 snprintf(fmt, sizeof(fmt), "%%%ss", prec);
979 snprintf(buf, buflen, fmt, cac->user);
980 break;
981 }
982 return src;
983}
984
988static const char *nntp_get_field(enum ConnAccountField field, void *gf_data)
989{
990 switch (field)
991 {
992 case MUTT_CA_LOGIN:
993 case MUTT_CA_USER:
994 return cs_subset_string(NeoMutt->sub, "nntp_user");
995 case MUTT_CA_PASS:
996 return cs_subset_string(NeoMutt->sub, "nntp_pass");
998 case MUTT_CA_HOST:
999 default:
1000 return NULL;
1001 }
1002}
1003
1019struct NntpAccountData *nntp_select_server(struct Mailbox *m, const char *server, bool leave_lock)
1020{
1021 char file[PATH_MAX] = { 0 };
1022 int rc;
1023 struct ConnAccount cac = { { 0 } };
1024 struct NntpAccountData *adata = NULL;
1025 struct Connection *conn = NULL;
1026
1027 if (!server || (*server == '\0'))
1028 {
1029 mutt_error(_("No news server defined"));
1030 return NULL;
1031 }
1032
1033 /* create account from news server url */
1034 cac.flags = 0;
1035 cac.port = NNTP_PORT;
1037 cac.service = "nntp";
1039
1040 snprintf(file, sizeof(file), "%s%s", strstr(server, "://") ? "" : "news://", server);
1041 struct Url *url = url_parse(file);
1042 if (!url || (url->path && *url->path) ||
1043 !((url->scheme == U_NNTP) || (url->scheme == U_NNTPS)) || !url->host ||
1044 (mutt_account_fromurl(&cac, url) < 0))
1045 {
1046 url_free(&url);
1047 mutt_error(_("%s is an invalid news server specification"), server);
1048 return NULL;
1049 }
1050 if (url->scheme == U_NNTPS)
1051 {
1052 cac.flags |= MUTT_ACCT_SSL;
1053 cac.port = NNTP_SSL_PORT;
1054 }
1055 url_free(&url);
1056
1057 // If nntp_user and nntp_pass are specified in the config, use them to find the connection
1058 const char *user = NULL;
1059 const char *pass = NULL;
1060 if ((user = cac.get_field(MUTT_CA_USER, NULL)))
1061 {
1062 mutt_str_copy(cac.user, user, sizeof(cac.user));
1063 cac.flags |= MUTT_ACCT_USER;
1064 }
1065 if ((pass = cac.get_field(MUTT_CA_PASS, NULL)))
1066 {
1067 mutt_str_copy(cac.pass, pass, sizeof(cac.pass));
1068 cac.flags |= MUTT_ACCT_PASS;
1069 }
1070
1071 /* find connection by account */
1072 conn = mutt_conn_find(&cac);
1073 if (!conn)
1074 return NULL;
1075 if (!(conn->account.flags & MUTT_ACCT_USER) && cac.flags & MUTT_ACCT_USER)
1076 {
1077 conn->account.flags |= MUTT_ACCT_USER;
1078 conn->account.user[0] = '\0';
1079 }
1080
1081 /* news server already exists */
1082 // adata = conn->data;
1083 if (adata)
1084 {
1085 if (adata->status == NNTP_BYE)
1086 adata->status = NNTP_NONE;
1087 if (nntp_open_connection(adata) < 0)
1088 return NULL;
1089
1090 rc = nntp_newsrc_parse(adata);
1091 if (rc < 0)
1092 return NULL;
1093
1094 /* check for new newsgroups */
1095 if (!leave_lock && (nntp_check_new_groups(m, adata) < 0))
1096 rc = -1;
1097
1098 /* .newsrc has been externally modified */
1099 if (rc > 0)
1100 nntp_clear_cache(adata);
1101 if ((rc < 0) || !leave_lock)
1102 nntp_newsrc_close(adata);
1103 return (rc < 0) ? NULL : adata;
1104 }
1105
1106 /* new news server */
1107 adata = nntp_adata_new(conn);
1108
1109 rc = nntp_open_connection(adata);
1110
1111 /* try to create cache directory and enable caching */
1112 adata->cacheable = false;
1113 const char *const c_news_cache_dir = cs_subset_path(NeoMutt->sub, "news_cache_dir");
1114 if ((rc >= 0) && c_news_cache_dir)
1115 {
1116 cache_expand(file, sizeof(file), &conn->account, NULL);
1117 if (mutt_file_mkdir(file, S_IRWXU) < 0)
1118 {
1119 mutt_error(_("Can't create %s: %s"), file, strerror(errno));
1120 }
1121 adata->cacheable = true;
1122 }
1123
1124 /* load .newsrc */
1125 if (rc >= 0)
1126 {
1127 const char *const c_newsrc = cs_subset_path(NeoMutt->sub, "newsrc");
1128 mutt_expando_format(file, sizeof(file), 0, sizeof(file), NONULL(c_newsrc),
1129 nntp_format_str, (intptr_t) adata, MUTT_FORMAT_NO_FLAGS);
1130 mutt_expand_path(file, sizeof(file));
1131 adata->newsrc_file = mutt_str_dup(file);
1132 rc = nntp_newsrc_parse(adata);
1133 }
1134 if (rc >= 0)
1135 {
1136 /* try to load list of newsgroups from cache */
1137 if (adata->cacheable && (active_get_cache(adata) == 0))
1138 rc = nntp_check_new_groups(m, adata);
1139
1140 /* load list of newsgroups from server */
1141 else
1142 rc = nntp_active_fetch(adata, false);
1143 }
1144
1145 if (rc >= 0)
1146 nntp_clear_cache(adata);
1147
1148#ifdef USE_HCACHE
1149 /* check cache files */
1150 if ((rc >= 0) && adata->cacheable)
1151 {
1152 struct dirent *entry = NULL;
1153 DIR *dp = opendir(file);
1154
1155 if (dp)
1156 {
1157 while ((entry = readdir(dp)))
1158 {
1159 struct HeaderCache *hc = NULL;
1160 char *hdata = NULL;
1161 char *group = entry->d_name;
1162
1163 char *p = group + strlen(group) - 7;
1164 if ((strlen(group) < 8) || (strcmp(p, ".hcache") != 0))
1165 continue;
1166 *p = '\0';
1168 if (!mdata)
1169 continue;
1170
1171 hc = nntp_hcache_open(mdata);
1172 if (!hc)
1173 continue;
1174
1175 /* fetch previous values of first and last */
1176 size_t dlen = 0;
1177 hdata = mutt_hcache_fetch_raw(hc, "index", 5, &dlen);
1178 if (hdata)
1179 {
1180 anum_t first, last;
1181
1182 if ((dlen > 0) && (hdata[dlen - 1] == '\0') &&
1183 sscanf(hdata, ANUM " " ANUM, &first, &last) == 2)
1184 {
1185 if (mdata->deleted)
1186 {
1187 mdata->first_message = first;
1188 mdata->last_message = last;
1189 }
1190 if ((last >= mdata->first_message) && (last <= mdata->last_message))
1191 {
1192 mdata->last_cached = last;
1193 mutt_debug(LL_DEBUG2, "%s last_cached=" ANUM "\n", mdata->group, last);
1194 }
1195 }
1196 mutt_hcache_free_raw(hc, (void **) &hdata);
1197 }
1199 }
1200 closedir(dp);
1201 }
1202 }
1203#endif
1204
1205 if ((rc < 0) || !leave_lock)
1207
1208 if (rc < 0)
1209 {
1214 FREE(&adata);
1215 mutt_socket_close(conn);
1216 FREE(&conn);
1217 return NULL;
1218 }
1219
1220 return adata;
1221}
1222
1235void nntp_article_status(struct Mailbox *m, struct Email *e, char *group, anum_t anum)
1236{
1237 struct NntpMboxData *mdata = m->mdata;
1238
1239 if (group)
1240 mdata = mutt_hash_find(mdata->adata->groups_hash, group);
1241
1242 if (!mdata)
1243 return;
1244
1245 for (unsigned int i = 0; i < mdata->newsrc_len; i++)
1246 {
1247 if ((anum >= mdata->newsrc_ent[i].first) && (anum <= mdata->newsrc_ent[i].last))
1248 {
1249 /* can't use mutt_set_flag() because mview_update() didn't get called yet */
1250 e->read = true;
1251 return;
1252 }
1253 }
1254
1255 /* article was not cached yet, it's new */
1256 if (anum > mdata->last_cached)
1257 return;
1258
1259 /* article isn't read but cached, it's old */
1260 const bool c_mark_old = cs_subset_bool(NeoMutt->sub, "mark_old");
1261 if (c_mark_old)
1262 e->old = true;
1263}
1264
1273{
1274 if (!adata || !adata->groups_hash || !group || (*group == '\0'))
1275 return NULL;
1276
1278 mdata->subscribed = true;
1279 if (!mdata->newsrc_ent)
1280 {
1281 mdata->newsrc_ent = mutt_mem_calloc(1, sizeof(struct NewsrcEntry));
1282 mdata->newsrc_len = 1;
1283 mdata->newsrc_ent[0].first = 1;
1284 mdata->newsrc_ent[0].last = 0;
1285 }
1286 return mdata;
1287}
1288
1297{
1298 if (!adata || !adata->groups_hash || !group || (*group == '\0'))
1299 return NULL;
1300
1302 if (!mdata)
1303 return NULL;
1304
1305 mdata->subscribed = false;
1306 const bool c_save_unsubscribed = cs_subset_bool(NeoMutt->sub, "save_unsubscribed");
1307 if (!c_save_unsubscribed)
1308 {
1309 mdata->newsrc_len = 0;
1310 FREE(&mdata->newsrc_ent);
1311 }
1312 return mdata;
1313}
1314
1324 struct NntpAccountData *adata, char *group)
1325{
1326 if (!adata || !adata->groups_hash || !group || (*group == '\0'))
1327 return NULL;
1328
1330 if (!mdata)
1331 return NULL;
1332
1333 if (mdata->newsrc_ent)
1334 {
1335 mutt_mem_realloc(&mdata->newsrc_ent, sizeof(struct NewsrcEntry));
1336 mdata->newsrc_len = 1;
1337 mdata->newsrc_ent[0].first = 1;
1338 mdata->newsrc_ent[0].last = mdata->last_message;
1339 }
1340 mdata->unread = 0;
1341 if (m && (m->mdata == mdata))
1342 {
1343 for (unsigned int i = 0; i < m->msg_count; i++)
1344 {
1345 struct Email *e = m->emails[i];
1346 if (!e)
1347 break;
1348 mutt_set_flag(m, e, MUTT_READ, true);
1349 }
1350 }
1351 return mdata;
1352}
1353
1363 struct NntpAccountData *adata, char *group)
1364{
1365 if (!adata || !adata->groups_hash || !group || (*group == '\0'))
1366 return NULL;
1367
1369 if (!mdata)
1370 return NULL;
1371
1372 if (mdata->newsrc_ent)
1373 {
1374 mutt_mem_realloc(&mdata->newsrc_ent, sizeof(struct NewsrcEntry));
1375 mdata->newsrc_len = 1;
1376 mdata->newsrc_ent[0].first = 1;
1377 mdata->newsrc_ent[0].last = mdata->first_message - 1;
1378 }
1379 if (m && (m->mdata == mdata))
1380 {
1381 mdata->unread = m->msg_count;
1382 for (unsigned int i = 0; i < m->msg_count; i++)
1383 {
1384 struct Email *e = m->emails[i];
1385 if (!e)
1386 break;
1387 mutt_set_flag(m, e, MUTT_READ, false);
1388 }
1389 }
1390 else
1391 {
1392 mdata->unread = mdata->last_message;
1393 if (mdata->newsrc_ent)
1394 mdata->unread -= mdata->newsrc_ent[0].last;
1395 }
1396 return mdata;
1397}
1398
1405void nntp_mailbox(struct Mailbox *m, char *buf, size_t buflen)
1406{
1407 if (!m)
1408 return;
1409
1410 for (unsigned int i = 0; i < CurrentNewsSrv->groups_num; i++)
1411 {
1413
1414 if (!mdata || !mdata->subscribed || !mdata->unread)
1415 continue;
1416
1417 if ((m->type == MUTT_NNTP) &&
1418 mutt_str_equal(mdata->group, ((struct NntpMboxData *) m->mdata)->group))
1419 {
1420 unsigned int unread = 0;
1421
1422 for (unsigned int j = 0; j < m->msg_count; j++)
1423 {
1424 struct Email *e = m->emails[j];
1425 if (!e)
1426 break;
1427 if (!e->read && !e->deleted)
1428 unread++;
1429 }
1430 if (unread == 0)
1431 continue;
1432 }
1433 mutt_str_copy(buf, mdata->group, buflen);
1434 break;
1435 }
1436}
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:144
int mutt_bcache_list(struct BodyCache *bcache, bcache_list_t want_id, void *data)
Find matching entries in the Body Cache.
Definition: bcache.c:330
int mutt_bcache_del(struct BodyCache *bcache, const char *id)
Delete a file from the Body Cache.
Definition: bcache.c:265
void mutt_bcache_close(struct BodyCache **bcache)
Close an Email-Body Cache.
Definition: bcache.c:165
struct Buffer mutt_buffer_make(size_t size)
Make a new buffer on the stack.
Definition: buffer.c:67
void mutt_buffer_dealloc(struct Buffer *buf)
Release the memory allocated by a buffer.
Definition: buffer.c:309
size_t mutt_buffer_addstr(struct Buffer *buf, const char *s)
Add a string to a Buffer.
Definition: buffer.c:233
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:168
static const char * mutt_buffer_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition: buffer.h:77
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
Definition: helpers.c:317
const char * cs_subset_path(const struct ConfigSubset *sub, const char *name)
Get a path config item by name.
Definition: helpers.c:194
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:73
short cs_subset_sort(const struct ConfigSubset *sub, const char *name)
Get a sort config item by name.
Definition: helpers.c:292
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
#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.
Structs that make up an email.
FILE * mutt_file_fopen(const char *path, const char *mode)
Call fopen() safely.
Definition: file.c:618
int mutt_file_fclose(FILE **fp)
Close a FILE handle (and NULL the pointer)
Definition: file.c:152
int mutt_file_mkdir(const char *path, mode_t mode)
Recursively create directories.
Definition: file.c:930
int mutt_file_lock(int fd, bool excl, bool timeout)
(Try to) Lock a file using fcntl()
Definition: file.c:1231
int mutt_file_unlock(int fd)
Unlock a file previously locked by mutt_file_lock()
Definition: file.c:1279
Flags to control mutt_expando_format()
#define MUTT_FORMAT_NO_FLAGS
No flags are set.
Definition: format_flags.h:30
uint8_t MuttFormatFlags
Flags for mutt_expando_format(), e.g. MUTT_FORMAT_FORCESUBJ.
Definition: format_flags.h:29
static int nntp_bcache_delete(const char *id, struct BodyCache *bcache, void *data)
Remove bcache file - Implements bcache_list_t -.
Definition: newsrc.c:784
const char * nntp_format_str(char *buf, size_t buflen, size_t col, int cols, char op, const char *src, const char *prec, const char *if_str, const char *else_str, intptr_t data, MuttFormatFlags flags)
Expand the newsrc filename - Implements format_t -.
Definition: newsrc.c:925
void mutt_expando_format(char *buf, size_t buflen, size_t col, int cols, const char *src, format_t callback, intptr_t data, MuttFormatFlags flags)
Expand expandos (x) in a string -.
Definition: muttlib.c:777
static void nntp_hcache_namer(const char *path, struct Buffer *dest)
Compose hcache file names - Implements hcache_namer_t -.
Definition: newsrc.c:692
#define mutt_error(...)
Definition: logging.h:87
#define mutt_message(...)
Definition: logging.h:86
#define mutt_debug(LEVEL,...)
Definition: logging.h:84
#define mutt_perror(...)
Definition: logging.h:88
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
Header cache multiplexor.
void mutt_hcache_close(struct HeaderCache *hc)
Multiplexor for StoreOps::close.
Definition: hcache.c:432
void * mutt_hcache_fetch_raw(struct HeaderCache *hc, const char *key, size_t keylen, size_t *dlen)
Fetch a message's header from the cache.
Definition: hcache.c:519
struct HeaderCache * mutt_hcache_open(const char *path, const char *folder, hcache_namer_t namer)
Multiplexor for StoreOps::open.
Definition: hcache.c:332
int mutt_hcache_delete_record(struct HeaderCache *hc, const char *key, size_t keylen)
Multiplexor for StoreOps::delete_record.
Definition: hcache.c:631
int mutt_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:610
void mutt_hcache_free_raw(struct HeaderCache *hc, void **data)
Multiplexor for StoreOps::free.
Definition: hcache.c:538
@ LL_DEBUG2
Log at debug level 2.
Definition: logging.h:41
@ LL_DEBUG1
Log at debug level 1.
Definition: logging.h:40
void mailbox_changed(struct Mailbox *m, enum NotifyMailbox action)
Notify observers of a change to a Mailbox.
Definition: mailbox.c:222
@ NT_MAILBOX_RESORT
Email list needs resorting.
Definition: mailbox.h:177
@ MUTT_NNTP
'NNTP' (Usenet) Mailbox type
Definition: mailbox.h:49
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:50
void * mutt_mem_malloc(size_t size)
Allocate memory on the heap.
Definition: memory.c:90
void mutt_mem_realloc(void *ptr, size_t size)
Resize a block of memory on the heap.
Definition: memory.c:114
#define FREE(x)
Definition: memory.h:43
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:250
char * mutt_str_lower(char *str)
Convert all characters in the string to lowercase.
Definition: string.c:384
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:807
char * mutt_strn_cat(char *d, size_t l, const char *s, size_t sl)
Concatenate two strings.
Definition: string.c:294
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:652
char * mutt_str_replace(char **p, const char *s)
Replace one string with another.
Definition: string.c:326
Many unsorted constants and some structs.
@ MUTT_READ
Messages that have been read.
Definition: mutt.h:93
#define PATH_MAX
Definition: mutt.h:40
int mutt_account_fromurl(struct ConnAccount *cac, const struct Url *url)
Fill ConnAccount with information from url.
Definition: mutt_account.c:43
void mutt_account_tourl(struct ConnAccount *cac, struct Url *url)
Fill URL with info from account.
Definition: mutt_account.c:79
ConnAccount object used by POP and IMAP.
@ MUTT_ACCT_TYPE_NNTP
Nntp (Usenet) Account.
Definition: mutt_account.h:40
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:89
NeoMutt connections.
void mutt_buffer_expand_path(struct Buffer *buf)
Create the canonical path.
Definition: muttlib.c:322
char * mutt_expand_path(char *buf, size_t buflen)
Create the canonical path.
Definition: muttlib.c:123
void mutt_encode_path(struct Buffer *buf, const char *src)
Convert a path to 'us-ascii'.
Definition: muttlib.c:1484
Some miscellaneous functions.
struct HeaderCache * nntp_hcache_open(struct NntpMboxData *mdata)
Open newsgroup hcache.
Definition: newsrc.c:711
void nntp_clear_cache(struct NntpAccountData *adata)
Clear the NNTP cache.
Definition: newsrc.c:847
void nntp_delete_group_cache(struct NntpMboxData *mdata)
Remove hcache and bcache of newsgroup.
Definition: newsrc.c:813
void nntp_newsrc_gen_entries(struct Mailbox *m)
Generate array of .newsrc entries.
Definition: newsrc.c:299
void nntp_hcache_update(struct NntpMboxData *mdata, struct HeaderCache *hc)
Remove stale cached headers.
Definition: newsrc.c:735
void nntp_article_status(struct Mailbox *m, struct Email *e, char *group, anum_t anum)
Get status of articles from .newsrc.
Definition: newsrc.c:1235
static int update_file(char *filename, char *buf)
Update file with new contents.
Definition: newsrc.c:392
int nntp_add_group(char *line, void *data)
Parse newsgroup.
Definition: newsrc.c:577
int nntp_newsrc_parse(struct NntpAccountData *adata)
Parse .newsrc file.
Definition: newsrc.c:162
void nntp_mailbox(struct Mailbox *m, char *buf, size_t buflen)
Get first newsgroup with new messages.
Definition: newsrc.c:1405
void nntp_newsrc_close(struct NntpAccountData *adata)
Unlock and close .newsrc file.
Definition: newsrc.c:118
struct NntpMboxData * mutt_newsgroup_catchup(struct Mailbox *m, struct NntpAccountData *adata, char *group)
Catchup newsgroup.
Definition: newsrc.c:1323
int nntp_newsrc_update(struct NntpAccountData *adata)
Update .newsrc file.
Definition: newsrc.c:442
struct NntpMboxData * mutt_newsgroup_subscribe(struct NntpAccountData *adata, char *group)
Subscribe newsgroup.
Definition: newsrc.c:1272
static const char * nntp_get_field(enum ConnAccountField field, void *gf_data)
Get connection login credentials - Implements ConnAccount::get_field()
Definition: newsrc.c:988
void nntp_expand_path(char *buf, size_t buflen, struct ConnAccount *cac)
Make fully qualified url from newsgroup name.
Definition: newsrc.c:561
static int active_get_cache(struct NntpAccountData *adata)
Load list of all newsgroups from cache.
Definition: newsrc.c:618
static void cache_expand(char *dst, size_t dstlen, struct ConnAccount *cac, const char *src)
Make fully qualified cache file name.
Definition: newsrc.c:521
static struct NntpMboxData * mdata_find(struct NntpAccountData *adata, const char *group)
Find NntpMboxData for given newsgroup or add it.
Definition: newsrc.c:72
struct NntpMboxData * mutt_newsgroup_uncatchup(struct Mailbox *m, struct NntpAccountData *adata, char *group)
Uncatchup newsgroup.
Definition: newsrc.c:1362
int nntp_active_save_cache(struct NntpAccountData *adata)
Save list of all newsgroups to cache.
Definition: newsrc.c:652
void nntp_bcache_update(struct NntpMboxData *mdata)
Remove stale cached messages.
Definition: newsrc.c:804
void nntp_group_unread_stat(struct NntpMboxData *mdata)
Count number of unread articles using .newsrc data.
Definition: newsrc.c:132
void nntp_acache_free(struct NntpMboxData *mdata)
Remove all temporarily cache files.
Definition: newsrc.c:102
struct NntpAccountData * nntp_select_server(struct Mailbox *m, const char *server, bool leave_lock)
Open a connection to an NNTP server.
Definition: newsrc.c:1019
struct NntpMboxData * mutt_newsgroup_unsubscribe(struct NntpAccountData *adata, char *group)
Unsubscribe newsgroup.
Definition: newsrc.c:1296
struct NntpAccountData * nntp_adata_new(struct Connection *conn)
Allocate and initialise a new NntpAccountData structure.
Definition: adata.c:62
struct NntpEmailData * nntp_edata_get(struct Email *e)
Get the private data for this Email.
Definition: edata.c:58
int nntp_active_fetch(struct NntpAccountData *adata, bool mark_new)
Fetch list of all newsgroups from server.
Definition: nntp.c:1957
#define NNTP_ACACHE_LEN
Definition: lib.h:82
struct NntpAccountData * CurrentNewsSrv
Current NNTP news server.
Definition: nntp.c:77
#define ANUM
Definition: lib.h:61
#define anum_t
Definition: lib.h:60
#define NNTP_SSL_PORT
Definition: private.h:37
@ NNTP_NONE
No connection to server.
Definition: private.h:44
@ NNTP_BYE
Disconnected from server.
Definition: private.h:46
#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:2025
int nntp_open_connection(struct NntpAccountData *adata)
Connect to server, authenticate and get capabilities.
Definition: nntp.c:1709
Notmuch-specific Mailbox data.
void mutt_buffer_pool_release(struct Buffer **pbuf)
Free a Buffer from the pool.
Definition: pool.c:112
struct Buffer * mutt_buffer_pool_get(void)
Get a Buffer from the pool.
Definition: pool.c:101
Pop-specific Account data.
Pop-specific Email data.
Prototypes for many functions.
#define mutt_set_flag(m, e, flag, bf)
Definition: protos.h:63
GUI display the mailboxes in a side panel.
int mutt_socket_close(struct Connection *conn)
Close a socket.
Definition: socket.c:98
@ SORT_ORDER
Sort by the order the messages appear in the mailbox.
Definition: sort2.h:48
Key value store.
#define NONULL(x)
Definition: string2.h:37
void * adata
Private data (for Mailbox backends)
Definition: account.h:43
Local cache of email bodies.
Definition: bcache.c:51
String manipulation buffer.
Definition: buffer.h:34
size_t dsize
Length of data.
Definition: buffer.h:37
char * data
Pointer to data.
Definition: buffer.h:35
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)
Function to get some login credentials.
Definition: connaccount.h:68
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
unsigned short port
Port to connect to.
Definition: connaccount.h:58
struct ConnAccount account
Account details: username, password, etc.
Definition: connection.h:50
The envelope/body of an email.
Definition: email.h:37
bool read
Email is read.
Definition: email.h:48
bool old
Email is seen, but unread.
Definition: email.h:47
bool deleted
Email is deleted.
Definition: email.h:76
Header cache structure.
Definition: lib.h:87
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:37
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:39
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:37
time_t newgroups_time
Definition: adata.h:57
bool newsrc_modified
Definition: adata.h:50
struct HashTable * groups_hash
Definition: adata.h:62
off_t size
Definition: adata.h:55
struct Connection * conn
Connection to NNTP Server.
Definition: adata.h:63
unsigned int status
Definition: adata.h:48
char * authenticators
Definition: adata.h:53
unsigned int groups_num
Definition: adata.h:59
time_t mtime
Definition: adata.h:56
unsigned int groups_max
Definition: adata.h:60
FILE * fp_newsrc
Definition: adata.h:51
void ** groups_list
Definition: adata.h:61
bool cacheable
Definition: adata.h:49
char * newsrc_file
Definition: adata.h:52
anum_t article_num
NNTP article number.
Definition: edata.h:36
NNTP-specific Mailbox data -.
Definition: mdata.h:33
anum_t last_cached
Definition: mdata.h:39
anum_t last_message
Definition: mdata.h:37
struct BodyCache * bcache
Definition: mdata.h:49
char * group
Name of newsgroup.
Definition: mdata.h:34
struct NntpAccountData * adata
Definition: mdata.h:47
char * desc
Description of newsgroup.
Definition: mdata.h:35
struct NewsrcEntry * newsrc_ent
Definition: mdata.h:46
anum_t unread
Definition: mdata.h:40
anum_t last_loaded
Definition: mdata.h:38
unsigned int newsrc_len
Definition: mdata.h:45
anum_t first_message
Definition: mdata.h:36
bool subscribed
Definition: mdata.h:41
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:305
struct Url * url_parse(const char *src)
Fill in Url.
Definition: url.c:234
int url_tostring(struct Url *url, char *dest, size_t len, uint8_t flags)
Output the URL string for a given Url object.
Definition: url.c:418
void url_free(struct Url **ptr)
Free the contents of a URL.
Definition: url.c:123
#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