NeoMutt  2024-04-16-36-g75b6fb
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
private.h File Reference

Usenet network mailbox type; talk to an NNTP server. More...

#include <stdbool.h>
#include <stdint.h>
#include "lib.h"
+ Include dependency graph for private.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define NNTP_PORT   119
 
#define NNTP_SSL_PORT   563
 

Enumerations

enum  NntpStatus { NNTP_NONE = 0 , NNTP_OK , NNTP_BYE }
 NNTP server return values. More...
 

Functions

void nntp_acache_free (struct NntpMboxData *mdata)
 Remove all temporarily cache files.
 
int nntp_active_save_cache (struct NntpAccountData *adata)
 Save list of all newsgroups to cache.
 
int nntp_add_group (char *line, void *data)
 Parse newsgroup.
 
void nntp_article_status (struct Mailbox *m, struct Email *e, char *group, anum_t anum)
 Get status of articles from .newsrc.
 
void nntp_bcache_update (struct NntpMboxData *mdata)
 Remove stale cached messages.
 
int nntp_check_new_groups (struct Mailbox *m, struct NntpAccountData *adata)
 Check for new groups/articles in subscribed groups.
 
void nntp_delete_group_cache (struct NntpMboxData *mdata)
 Remove hcache and bcache of newsgroup.
 
void nntp_group_unread_stat (struct NntpMboxData *mdata)
 Count number of unread articles using .newsrc data.
 
void nntp_hash_destructor_t (int type, void *obj, intptr_t data)
 
void nntp_hashelem_free (int type, void *obj, intptr_t data)
 Free our hash table data - Implements hash_hdata_free_t -.
 
struct HeaderCachenntp_hcache_open (struct NntpMboxData *mdata)
 Open newsgroup hcache.
 
void nntp_hcache_update (struct NntpMboxData *mdata, struct HeaderCache *hc)
 Remove stale cached headers.
 
void nntp_newsrc_gen_entries (struct Mailbox *m)
 Generate array of .newsrc entries.
 
int nntp_open_connection (struct NntpAccountData *adata)
 Connect to server, authenticate and get capabilities.
 

Detailed Description

Usenet network mailbox type; talk to an NNTP server.

Authors
  • Richard Russon

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Definition in file private.h.

Macro Definition Documentation

◆ NNTP_PORT

#define NNTP_PORT   119

Definition at line 36 of file private.h.

◆ NNTP_SSL_PORT

#define NNTP_SSL_PORT   563

Definition at line 37 of file private.h.

Enumeration Type Documentation

◆ NntpStatus

enum NntpStatus

NNTP server return values.

Enumerator
NNTP_NONE 

No connection to server.

NNTP_OK 

Connected to server.

NNTP_BYE 

Disconnected from server.

Definition at line 42 of file private.h.

43{
44 NNTP_NONE = 0,
45 NNTP_OK,
46 NNTP_BYE,
47};
@ NNTP_NONE
No connection to server.
Definition: private.h:44
@ NNTP_BYE
Disconnected from server.
Definition: private.h:46
@ NNTP_OK
Connected to server.
Definition: private.h:45

Function Documentation

◆ nntp_acache_free()

void nntp_acache_free ( struct NntpMboxData mdata)

Remove all temporarily cache files.

Parameters
mdataNNTP Mailbox data

Definition at line 105 of file newsrc.c.

106{
107 for (int i = 0; i < NNTP_ACACHE_LEN; i++)
108 {
109 if (mdata->acache[i].path)
110 {
111 unlink(mdata->acache[i].path);
112 FREE(&mdata->acache[i].path);
113 }
114 }
115}
#define FREE(x)
Definition: memory.h:45
#define NNTP_ACACHE_LEN
Definition: lib.h:82
char * path
Cache path.
Definition: lib.h:69
struct NntpAcache acache[NNTP_ACACHE_LEN]
Definition: mdata.h:49
+ Here is the caller graph for this function:

◆ nntp_active_save_cache()

int nntp_active_save_cache ( struct NntpAccountData adata)

Save list of all newsgroups to cache.

Parameters
adataNNTP server
Return values
0Success
-1Failure

Definition at line 650 of file newsrc.c.

651{
652 if (!adata->cacheable)
653 return 0;
654
655 size_t buflen = 10240;
656 char *buf = mutt_mem_calloc(1, buflen);
657 snprintf(buf, buflen, "%lu\n", (unsigned long) adata->newgroups_time);
658 size_t off = strlen(buf);
659
660 for (unsigned int i = 0; i < adata->groups_num; i++)
661 {
662 struct NntpMboxData *mdata = adata->groups_list[i];
663
664 if (!mdata || mdata->deleted)
665 continue;
666
667 if ((off + strlen(mdata->group) + (mdata->desc ? strlen(mdata->desc) : 0) + 50) > buflen)
668 {
669 buflen *= 2;
670 mutt_mem_realloc(&buf, buflen);
671 }
672 snprintf(buf + off, buflen - off, "%s " ANUM_FMT " " ANUM_FMT " %c%s%s\n",
673 mdata->group, mdata->last_message, mdata->first_message,
674 mdata->allowed ? 'y' : 'n', mdata->desc ? " " : "",
675 mdata->desc ? mdata->desc : "");
676 off += strlen(buf + off);
677 }
678
679 char file[PATH_MAX] = { 0 };
680 cache_expand(file, sizeof(file), &adata->conn->account, ".active");
681 mutt_debug(LL_DEBUG1, "Updating %s\n", file);
682 int rc = update_file(file, buf);
683 FREE(&buf);
684 return rc;
685}
#define mutt_debug(LEVEL,...)
Definition: logging2.h:89
@ 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:50
void mutt_mem_realloc(void *ptr, size_t size)
Resize a block of memory on the heap.
Definition: memory.c:114
#define PATH_MAX
Definition: mutt.h:42
static int update_file(char *filename, char *buf)
Update file with new contents.
Definition: newsrc.c:394
static void cache_expand(char *dst, size_t dstlen, struct ConnAccount *cac, const char *src)
Make fully qualified cache file name.
Definition: newsrc.c:525
#define ANUM_FMT
Definition: lib.h:61
struct ConnAccount account
Account details: username, password, etc.
Definition: connection.h:49
void * mdata
Driver specific data.
Definition: mailbox.h:132
time_t newgroups_time
Definition: adata.h:56
struct Connection * conn
Connection to NNTP Server.
Definition: adata.h:62
unsigned int groups_num
Definition: adata.h:58
void ** groups_list
Definition: adata.h:60
bool cacheable
Definition: adata.h:48
NNTP-specific Mailbox data -.
Definition: mdata.h:34
struct NntpAccountData * adata
Definition: mdata.h:48
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ nntp_add_group()

int nntp_add_group ( char *  line,
void *  data 
)

Parse newsgroup.

Parameters
lineString to parse
dataNNTP data
Return values
0Always

Definition at line 575 of file newsrc.c.

576{
577 struct NntpAccountData *adata = data;
578 struct NntpMboxData *mdata = NULL;
579 char group[1024] = { 0 };
580 char desc[8192] = { 0 };
581 char mod;
582 anum_t first, last;
583
584 if (!adata || !line)
585 return 0;
586
587 /* These sscanf limits must match the sizes of the group and desc arrays */
588 if (sscanf(line, "%1023s " ANUM_FMT " " ANUM_FMT " %c %8191[^\n]", group,
589 &last, &first, &mod, desc) < 4)
590 {
591 mutt_debug(LL_DEBUG2, "Can't parse server line: %s\n", line);
592 return 0;
593 }
594
596 mdata->deleted = false;
597 mdata->first_message = first;
598 mdata->last_message = last;
599 mdata->allowed = (mod == 'y') || (mod == 'm');
600 mutt_str_replace(&mdata->desc, desc);
601 if (mdata->newsrc_ent || (mdata->last_cached != 0))
603 else if (mdata->last_message && (mdata->first_message <= mdata->last_message))
604 mdata->unread = mdata->last_message - mdata->first_message + 1;
605 else
606 mdata->unread = 0;
607 return 0;
608}
@ LL_DEBUG2
Log at debug level 2.
Definition: logging2.h:44
char * mutt_str_replace(char **p, const char *s)
Replace one string with another.
Definition: string.c:274
static struct NntpMboxData * mdata_find(struct NntpAccountData *adata, const char *group)
Find NntpMboxData for given newsgroup or add it.
Definition: newsrc.c:75
void nntp_group_unread_stat(struct NntpMboxData *mdata)
Count number of unread articles using .newsrc data.
Definition: newsrc.c:135
#define anum_t
Definition: lib.h:60
void * adata
Private data (for Mailbox backends)
Definition: account.h:42
NNTP-specific Account data -.
Definition: adata.h:36
char * group
Name of newsgroup.
Definition: mdata.h:35
char * desc
Description of newsgroup.
Definition: mdata.h:36
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ nntp_article_status()

void nntp_article_status ( struct Mailbox m,
struct Email e,
char *  group,
anum_t  anum 
)

Get status of articles from .newsrc.

Parameters
mMailbox
eEmail
groupNewsgroup
anumArticle number

Full status flags are not supported by nntp, but we can fake some of them: Read = a read message number is in the .newsrc New = not read and not cached Old = not read but cached

Definition at line 1256 of file newsrc.c.

1257{
1258 struct NntpMboxData *mdata = m->mdata;
1259
1260 if (group)
1261 mdata = mutt_hash_find(mdata->adata->groups_hash, group);
1262
1263 if (!mdata)
1264 return;
1265
1266 for (unsigned int i = 0; i < mdata->newsrc_len; i++)
1267 {
1268 if ((anum >= mdata->newsrc_ent[i].first) && (anum <= mdata->newsrc_ent[i].last))
1269 {
1270 /* can't use mutt_set_flag() because mview_update() didn't get called yet */
1271 e->read = true;
1272 return;
1273 }
1274 }
1275
1276 /* article was not cached yet, it's new */
1277 if (anum > mdata->last_cached)
1278 return;
1279
1280 /* article isn't read but cached, it's old */
1281 const bool c_mark_old = cs_subset_bool(NeoMutt->sub, "mark_old");
1282 if (c_mark_old)
1283 e->old = true;
1284}
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:48
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
bool read
Email is read.
Definition: email.h:50
bool old
Email is seen, but unread.
Definition: email.h:49
Container for Accounts, Notifications.
Definition: neomutt.h:41
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:45
anum_t last
Last article number in run.
Definition: lib.h:78
struct NewsrcEntry * newsrc_ent
Definition: mdata.h:47
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ nntp_bcache_update()

void nntp_bcache_update ( struct NntpMboxData mdata)

Remove stale cached messages.

Parameters
mdataNNTP Mailbox data

Definition at line 802 of file newsrc.c.

803{
805}
int mutt_bcache_list(struct BodyCache *bcache, bcache_list_t want_id, void *data)
Find matching entries in the Body Cache.
Definition: bcache.c:331
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:782
struct BodyCache * bcache
Definition: mdata.h:50
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ nntp_check_new_groups()

int nntp_check_new_groups ( struct Mailbox m,
struct NntpAccountData adata 
)

Check for new groups/articles in subscribed groups.

Parameters
mMailbox
adataNNTP server
Return values
1New groups found
0No new groups
-1Error

Definition at line 2077 of file nntp.c.

2078{
2079 struct NntpMboxData tmp_mdata = { 0 };
2080 time_t now = 0;
2081 char buf[1024] = { 0 };
2082 char *msg = _("Checking for new newsgroups...");
2083 unsigned int i;
2084 int rc, update_active = false;
2085
2086 if (!adata || !adata->newgroups_time)
2087 return -1;
2088
2089 /* check subscribed newsgroups for new articles */
2090 const bool c_show_new_news = cs_subset_bool(NeoMutt->sub, "show_new_news");
2091 if (c_show_new_news)
2092 {
2093 mutt_message(_("Checking for new messages..."));
2094 for (i = 0; i < adata->groups_num; i++)
2095 {
2096 struct NntpMboxData *mdata = adata->groups_list[i];
2097
2098 if (mdata && mdata->subscribed)
2099 {
2100 rc = nntp_group_poll(mdata, true);
2101 if (rc < 0)
2102 return -1;
2103 if (rc > 0)
2104 update_active = true;
2105 }
2106 }
2107 }
2108 else if (adata->newgroups_time)
2109 {
2110 return 0;
2111 }
2112
2113 /* get list of new groups */
2114 mutt_message("%s", msg);
2115 if (nntp_date(adata, &now) < 0)
2116 return -1;
2117 tmp_mdata.adata = adata;
2118 if (m && m->mdata)
2119 tmp_mdata.group = ((struct NntpMboxData *) m->mdata)->group;
2120 else
2121 tmp_mdata.group = NULL;
2122 i = adata->groups_num;
2123 struct tm tm = mutt_date_gmtime(adata->newgroups_time);
2124 snprintf(buf, sizeof(buf), "NEWGROUPS %02d%02d%02d %02d%02d%02d GMT\r\n",
2125 tm.tm_year % 100, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
2126 rc = nntp_fetch_lines(&tmp_mdata, buf, sizeof(buf), msg, nntp_add_group, adata);
2127 if (rc)
2128 {
2129 if (rc > 0)
2130 {
2131 mutt_error("NEWGROUPS: %s", buf);
2132 }
2133 return -1;
2134 }
2135
2136 /* new groups found */
2137 rc = 0;
2138 if (adata->groups_num != i)
2139 {
2140 int groups_num = i;
2141
2142 adata->newgroups_time = now;
2143 for (; i < adata->groups_num; i++)
2144 {
2145 struct NntpMboxData *mdata = adata->groups_list[i];
2146 mdata->has_new_mail = true;
2147 }
2148
2149 /* loading descriptions */
2150 const bool c_nntp_load_description = cs_subset_bool(NeoMutt->sub, "nntp_load_description");
2151 if (c_nntp_load_description)
2152 {
2153 unsigned int count = 0;
2154 struct Progress *progress = progress_new(MUTT_PROGRESS_READ, adata->groups_num - i);
2155 progress_set_message(progress, _("Loading descriptions..."));
2156
2157 for (i = groups_num; i < adata->groups_num; i++)
2158 {
2159 struct NntpMboxData *mdata = adata->groups_list[i];
2160
2161 if (get_description(mdata, NULL, NULL) < 0)
2162 {
2163 progress_free(&progress);
2164 return -1;
2165 }
2166 progress_update(progress, ++count, -1);
2167 }
2168 progress_free(&progress);
2169 }
2170 update_active = true;
2171 rc = 1;
2172 }
2173 if (update_active)
2176 return rc;
2177}
#define mutt_error(...)
Definition: logging2.h:92
#define mutt_message(...)
Definition: logging2.h:91
struct tm mutt_date_gmtime(time_t t)
Converts calendar time to a broken-down time structure expressed in UTC timezone.
Definition: date.c:926
#define _(a)
Definition: message.h:28
void mutt_clear_error(void)
Clear the message line (bottom line of screen)
Definition: mutt_logging.c:74
int nntp_add_group(char *line, void *data)
Parse newsgroup.
Definition: newsrc.c:575
int nntp_active_save_cache(struct NntpAccountData *adata)
Save list of all newsgroups to cache.
Definition: newsrc.c:650
static int nntp_date(struct NntpAccountData *adata, time_t *now)
Get date and time from server.
Definition: nntp.c:1687
static int nntp_group_poll(struct NntpMboxData *mdata, bool update_stat)
Check newsgroup for new articles.
Definition: nntp.c:1429
static int nntp_fetch_lines(struct NntpMboxData *mdata, char *query, size_t qlen, const char *msg, int(*func)(char *, void *), void *data)
Read lines, calling a callback function for each.
Definition: nntp.c:802
static int get_description(struct NntpMboxData *mdata, const char *wildmat, const char *msg)
Fetch newsgroups descriptions.
Definition: nntp.c:924
@ MUTT_PROGRESS_READ
Progress tracks elements, according to $read_inc
Definition: lib.h:82
struct Progress * progress_new(enum ProgressType type, size_t size)
Create a new Progress Bar.
Definition: progress.c:139
void progress_free(struct Progress **ptr)
Free a Progress Bar.
Definition: progress.c:110
void progress_set_message(struct Progress *progress, const char *fmt,...) __attribute__((__format__(__printf__
bool progress_update(struct Progress *progress, size_t pos, int percent)
Update the state of the progress bar.
Definition: progress.c:80
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ nntp_delete_group_cache()

void nntp_delete_group_cache ( struct NntpMboxData mdata)

Remove hcache and bcache of newsgroup.

Parameters
mdataNNTP Mailbox data

Definition at line 811 of file newsrc.c.

812{
813 if (!mdata || !mdata->adata || !mdata->adata->cacheable)
814 return;
815
816#ifdef USE_HCACHE
817 struct Buffer *file = buf_pool_get();
818 nntp_hcache_namer(mdata->group, file);
819 cache_expand(file->data, file->dsize, &mdata->adata->conn->account, buf_string(file));
820 unlink(buf_string(file));
821 mdata->last_cached = 0;
822 mutt_debug(LL_DEBUG2, "%s\n", buf_string(file));
823 buf_pool_release(&file);
824#endif
825
826 if (!mdata->bcache)
827 {
828 mdata->bcache = mutt_bcache_open(&mdata->adata->conn->account, mdata->group);
829 }
830 if (mdata->bcache)
831 {
832 mutt_debug(LL_DEBUG2, "%s/*\n", mdata->group);
834 mutt_bcache_close(&mdata->bcache);
835 }
836}
struct BodyCache * mutt_bcache_open(struct ConnAccount *account, const char *mailbox)
Open an Email-Body Cache.
Definition: bcache.c:143
void mutt_bcache_close(struct BodyCache **ptr)
Close an Email-Body Cache.
Definition: bcache.c:164
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition: buffer.h:96
static void nntp_hcache_namer(const char *path, struct Buffer *dest)
Compose hcache file names - Implements hcache_namer_t -.
Definition: newsrc.c:691
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
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
anum_t last_cached
Definition: mdata.h:40
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ nntp_group_unread_stat()

void nntp_group_unread_stat ( struct NntpMboxData mdata)

Count number of unread articles using .newsrc data.

Parameters
mdataNNTP Mailbox data

Definition at line 135 of file newsrc.c.

136{
137 mdata->unread = 0;
138 if ((mdata->last_message == 0) ||
139 (mdata->first_message > mdata->last_message) || !mdata->newsrc_ent)
140 {
141 return;
142 }
143
144 mdata->unread = mdata->last_message - mdata->first_message + 1;
145 for (unsigned int i = 0; i < mdata->newsrc_len; i++)
146 {
147 anum_t first = mdata->newsrc_ent[i].first;
148 if (first < mdata->first_message)
149 first = mdata->first_message;
150 anum_t last = mdata->newsrc_ent[i].last;
151 if (last > mdata->last_message)
152 last = mdata->last_message;
153 if (first <= last)
154 mdata->unread -= last - first + 1;
155 }
156}
anum_t first
First article number in run.
Definition: lib.h:77
anum_t last_message
Definition: mdata.h:38
anum_t unread
Definition: mdata.h:41
unsigned int newsrc_len
Definition: mdata.h:46
anum_t first_message
Definition: mdata.h:37
+ Here is the caller graph for this function:

◆ nntp_hash_destructor_t()

void nntp_hash_destructor_t ( int  type,
void *  obj,
intptr_t  data 
)

◆ nntp_hcache_open()

struct HeaderCache * nntp_hcache_open ( struct NntpMboxData mdata)

Open newsgroup hcache.

Parameters
mdataNNTP Mailbox data
Return values
ptrHeader cache
NULLError

Definition at line 710 of file newsrc.c.

711{
712 struct Url url = { 0 };
713 char file[PATH_MAX] = { 0 };
714
715 const bool c_save_unsubscribed = cs_subset_bool(NeoMutt->sub, "save_unsubscribed");
716 if (!mdata->adata || !mdata->adata->cacheable || !mdata->adata->conn || !mdata->group ||
717 !(mdata->newsrc_ent || mdata->subscribed || c_save_unsubscribed))
718 {
719 return NULL;
720 }
721
722 mutt_account_tourl(&mdata->adata->conn->account, &url);
723 url.path = mdata->group;
724 url_tostring(&url, file, sizeof(file), U_PATH);
725 const char *const c_news_cache_dir = cs_subset_path(NeoMutt->sub, "news_cache_dir");
726 return hcache_open(c_news_cache_dir, file, nntp_hcache_namer);
727}
const char * cs_subset_path(const struct ConfigSubset *sub, const char *name)
Get a path config item by name.
Definition: helpers.c:169
struct HeaderCache * hcache_open(const char *path, const char *folder, hcache_namer_t namer)
Multiplexor for StoreOps::open.
Definition: hcache.c:471
void mutt_account_tourl(struct ConnAccount *cac, struct Url *url)
Fill URL with info from account.
Definition: mutt_account.c:80
bool subscribed
Definition: mdata.h:42
A parsed URL proto://user:password@host:port/path?a=1&b=2
Definition: url.h:69
char * path
Path.
Definition: url.h:75
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_PATH
Definition: url.h:50
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ nntp_hcache_update()

void nntp_hcache_update ( struct NntpMboxData mdata,
struct HeaderCache hc 
)

Remove stale cached headers.

Parameters
mdataNNTP Mailbox data
hcHeader cache

Definition at line 734 of file newsrc.c.

735{
736 if (!hc)
737 return;
738
739 char buf[32] = { 0 };
740 bool old = false;
741 anum_t first = 0, last = 0;
742
743 /* fetch previous values of first and last */
744 char *hdata = hcache_fetch_raw_str(hc, "index", 5);
745 if (hdata)
746 {
747 mutt_debug(LL_DEBUG2, "hcache_fetch_email index: %s\n", hdata);
748 if (sscanf(hdata, ANUM_FMT " " ANUM_FMT, &first, &last) == 2)
749 {
750 old = true;
751 mdata->last_cached = last;
752
753 /* clean removed headers from cache */
754 for (anum_t current = first; current <= last; current++)
755 {
756 if ((current >= mdata->first_message) && (current <= mdata->last_message))
757 continue;
758
759 snprintf(buf, sizeof(buf), ANUM_FMT, current);
760 mutt_debug(LL_DEBUG2, "hcache_delete_email %s\n", buf);
761 hcache_delete_email(hc, buf, strlen(buf));
762 }
763 }
764 FREE(&hdata);
765 }
766
767 /* store current values of first and last */
768 if (!old || (mdata->first_message != first) || (mdata->last_message != last))
769 {
770 snprintf(buf, sizeof(buf), ANUM_FMT " " ANUM_FMT, mdata->first_message,
771 mdata->last_message);
772 mutt_debug(LL_DEBUG2, "hcache_store_email index: %s\n", buf);
773 hcache_store_raw(hc, "index", 5, buf, strlen(buf) + 1);
774 }
775}
int hcache_delete_email(struct HeaderCache *hc, const char *key, size_t keylen)
Multiplexor for StoreOps::delete_record.
Definition: hcache.c:737
char * hcache_fetch_raw_str(struct HeaderCache *hc, const char *key, size_t keylen)
Fetch a string from the cache.
Definition: hcache.c:650
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:722
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ nntp_newsrc_gen_entries()

void nntp_newsrc_gen_entries ( struct Mailbox m)

Generate array of .newsrc entries.

Parameters
mMailbox

Definition at line 302 of file newsrc.c.

303{
304 if (!m)
305 return;
306
307 struct NntpMboxData *mdata = m->mdata;
308 anum_t last = 0, first = 1;
309 bool series;
310 unsigned int entries;
311
312 const enum SortType c_sort = cs_subset_sort(NeoMutt->sub, "sort");
313 if (c_sort != SORT_ORDER)
314 {
317 }
318
319 entries = mdata->newsrc_len;
320 if (!entries)
321 {
322 entries = 5;
323 mdata->newsrc_ent = mutt_mem_calloc(entries, sizeof(struct NewsrcEntry));
324 }
325
326 /* Set up to fake initial sequence from 1 to the article before the
327 * first article in our list */
328 mdata->newsrc_len = 0;
329 series = true;
330 for (int i = 0; i < m->msg_count; i++)
331 {
332 struct Email *e = m->emails[i];
333 if (!e)
334 break;
335
336 /* search for first unread */
337 if (series)
338 {
339 /* We don't actually check sequential order, since we mark
340 * "missing" entries as read/deleted */
341 last = nntp_edata_get(e)->article_num;
342 if ((last >= mdata->first_message) && !e->deleted && !e->read)
343 {
344 if (mdata->newsrc_len >= entries)
345 {
346 entries *= 2;
347 mutt_mem_realloc(&mdata->newsrc_ent, entries * sizeof(struct NewsrcEntry));
348 }
349 mdata->newsrc_ent[mdata->newsrc_len].first = first;
350 mdata->newsrc_ent[mdata->newsrc_len].last = last - 1;
351 mdata->newsrc_len++;
352 series = false;
353 }
354 }
355 else
356 {
357 /* search for first read */
358 if (e->deleted || e->read)
359 {
360 first = last + 1;
361 series = true;
362 }
363 last = nntp_edata_get(e)->article_num;
364 }
365 }
366
367 if (series && (first <= mdata->last_loaded))
368 {
369 if (mdata->newsrc_len >= entries)
370 {
371 entries++;
372 mutt_mem_realloc(&mdata->newsrc_ent, entries * sizeof(struct NewsrcEntry));
373 }
374 mdata->newsrc_ent[mdata->newsrc_len].first = first;
375 mdata->newsrc_ent[mdata->newsrc_len].last = mdata->last_loaded;
376 mdata->newsrc_len++;
377 }
378 mutt_mem_realloc(&mdata->newsrc_ent, mdata->newsrc_len * sizeof(struct NewsrcEntry));
379
380 if (c_sort != SORT_ORDER)
381 {
382 cs_subset_str_native_set(NeoMutt->sub, "sort", c_sort, NULL);
384 }
385}
short cs_subset_sort(const struct ConfigSubset *sub, const char *name)
Get a sort config item by name.
Definition: helpers.c:267
void mailbox_changed(struct Mailbox *m, enum NotifyMailbox action)
Notify observers of a change to a Mailbox.
Definition: mailbox.c:234
@ NT_MAILBOX_RESORT
Email list needs resorting.
Definition: mailbox.h:190
struct NntpEmailData * nntp_edata_get(struct Email *e)
Get the private data for this Email.
Definition: edata.c:60
SortType
Methods for sorting.
Definition: sort2.h:34
@ SORT_ORDER
Sort by the order the messages appear in the mailbox.
Definition: sort2.h:40
The envelope/body of an email.
Definition: email.h:39
bool deleted
Email is deleted.
Definition: email.h:78
int msg_count
Total number of messages.
Definition: mailbox.h:88
struct Email ** emails
Array of Emails.
Definition: mailbox.h:96
An entry in a .newsrc (subscribed newsgroups)
Definition: lib.h:76
anum_t article_num
NNTP article number.
Definition: edata.h:36
anum_t last_loaded
Definition: mdata.h:39
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
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ nntp_open_connection()

int nntp_open_connection ( struct NntpAccountData adata)

Connect to server, authenticate and get capabilities.

Parameters
adataNNTP server
Return values
0Success
-1Failure

Definition at line 1754 of file nntp.c.

1755{
1756 struct Connection *conn = adata->conn;
1757 char buf[256] = { 0 };
1758 int cap;
1759 bool posting = false, auth = true;
1760
1761 if (adata->status == NNTP_OK)
1762 return 0;
1763 if (adata->status == NNTP_BYE)
1764 return -1;
1765 adata->status = NNTP_NONE;
1766
1767 if (mutt_socket_open(conn) < 0)
1768 return -1;
1769
1770 if (mutt_socket_readln(buf, sizeof(buf), conn) < 0)
1771 return nntp_connect_error(adata);
1772
1773 if (mutt_str_startswith(buf, "200"))
1774 {
1775 posting = true;
1776 }
1777 else if (!mutt_str_startswith(buf, "201"))
1778 {
1779 mutt_socket_close(conn);
1781 mutt_error("%s", buf);
1782 return -1;
1783 }
1784
1785 /* get initial capabilities */
1786 cap = nntp_capabilities(adata);
1787 if (cap < 0)
1788 return -1;
1789
1790 /* tell news server to switch to mode reader if it isn't so */
1791 if (cap > 0)
1792 {
1793 if ((mutt_socket_send(conn, "MODE READER\r\n") < 0) ||
1794 (mutt_socket_readln(buf, sizeof(buf), conn) < 0))
1795 {
1796 return nntp_connect_error(adata);
1797 }
1798
1799 if (mutt_str_startswith(buf, "200"))
1800 {
1801 posting = true;
1802 }
1803 else if (mutt_str_startswith(buf, "201"))
1804 {
1805 posting = false;
1806 }
1807 else if (adata->hasCAPABILITIES)
1808 {
1809 /* error if has capabilities, ignore result if no capabilities */
1810 mutt_socket_close(conn);
1811 mutt_error(_("Could not switch to reader mode"));
1812 return -1;
1813 }
1814
1815 /* recheck capabilities after MODE READER */
1816 if (adata->hasCAPABILITIES)
1817 {
1818 cap = nntp_capabilities(adata);
1819 if (cap < 0)
1820 return -1;
1821 }
1822 }
1823
1824 mutt_message(_("Connected to %s. %s"), conn->account.host,
1825 posting ? _("Posting is ok") : _("Posting is NOT ok"));
1826 mutt_sleep(1);
1827
1828#ifdef USE_SSL
1829 /* Attempt STARTTLS if available and desired. */
1830 const bool c_ssl_force_tls = cs_subset_bool(NeoMutt->sub, "ssl_force_tls");
1831 if ((adata->use_tls != 1) && (adata->hasSTARTTLS || c_ssl_force_tls))
1832 {
1833 if (adata->use_tls == 0)
1834 {
1835 adata->use_tls = c_ssl_force_tls ||
1836 (query_quadoption(_("Secure connection with TLS?"),
1837 NeoMutt->sub, "ssl_starttls") == MUTT_YES) ?
1838 2 :
1839 1;
1840 }
1841 if (adata->use_tls == 2)
1842 {
1843 if ((mutt_socket_send(conn, "STARTTLS\r\n") < 0) ||
1844 (mutt_socket_readln(buf, sizeof(buf), conn) < 0))
1845 {
1846 return nntp_connect_error(adata);
1847 }
1848 // Clear any data after the STARTTLS acknowledgement
1849 mutt_socket_empty(conn);
1850 if (!mutt_str_startswith(buf, "382"))
1851 {
1852 adata->use_tls = 0;
1853 mutt_error("STARTTLS: %s", buf);
1854 }
1855 else if (mutt_ssl_starttls(conn))
1856 {
1857 adata->use_tls = 0;
1858 adata->status = NNTP_NONE;
1859 mutt_socket_close(adata->conn);
1860 mutt_error(_("Could not negotiate TLS connection"));
1861 return -1;
1862 }
1863 else
1864 {
1865 /* recheck capabilities after STARTTLS */
1866 cap = nntp_capabilities(adata);
1867 if (cap < 0)
1868 return -1;
1869 }
1870 }
1871 }
1872#endif
1873
1874 /* authentication required? */
1875 if (conn->account.flags & MUTT_ACCT_USER)
1876 {
1877 if (!conn->account.user[0])
1878 auth = false;
1879 }
1880 else
1881 {
1882 if ((mutt_socket_send(conn, "STAT\r\n") < 0) ||
1883 (mutt_socket_readln(buf, sizeof(buf), conn) < 0))
1884 {
1885 return nntp_connect_error(adata);
1886 }
1887 if (!mutt_str_startswith(buf, "480"))
1888 auth = false;
1889 }
1890
1891 /* authenticate */
1892 if (auth && (nntp_auth(adata) < 0))
1893 return -1;
1894
1895 /* get final capabilities after authentication */
1896 if (adata->hasCAPABILITIES && (auth || (cap > 0)))
1897 {
1898 cap = nntp_capabilities(adata);
1899 if (cap < 0)
1900 return -1;
1901 if (cap > 0)
1902 {
1903 mutt_socket_close(conn);
1904 mutt_error(_("Could not switch to reader mode"));
1905 return -1;
1906 }
1907 }
1908
1909 /* attempt features */
1910 if (nntp_attempt_features(adata) < 0)
1911 return -1;
1912
1913 adata->status = NNTP_OK;
1914 return 0;
1915}
#define MUTT_ACCT_USER
User field has been set.
Definition: connaccount.h:44
int mutt_ssl_starttls(struct Connection *conn)
Negotiate TLS over an already opened connection.
Definition: gnutls.c:1149
void mutt_str_remove_trailing_ws(char *s)
Trim trailing whitespace from a string.
Definition: string.c:559
size_t mutt_str_startswith(const char *str, const char *prefix)
Check whether a string starts with a prefix.
Definition: string.c:230
void mutt_sleep(short s)
Sleep for a while.
Definition: muttlib.c:878
static int nntp_auth(struct NntpAccountData *adata)
Get login, password and authenticate.
Definition: nntp.c:445
static int nntp_capabilities(struct NntpAccountData *adata)
Get capabilities.
Definition: nntp.c:141
static int nntp_connect_error(struct NntpAccountData *adata)
Signal a failed connection.
Definition: nntp.c:127
static int nntp_attempt_features(struct NntpAccountData *adata)
Detect supported commands.
Definition: nntp.c:260
@ MUTT_YES
User answered 'Yes', or assume 'Yes'.
Definition: quad.h:39
enum QuadOption query_quadoption(const char *prompt, struct ConfigSubset *sub, const char *name)
Ask the user a quad-question.
Definition: question.c:366
int mutt_socket_close(struct Connection *conn)
Close a socket.
Definition: socket.c:100
void mutt_socket_empty(struct Connection *conn)
Clear out any queued data.
Definition: socket.c:306
int mutt_socket_open(struct Connection *conn)
Simple wrapper.
Definition: socket.c:76
#define mutt_socket_readln(buf, buflen, conn)
Definition: socket.h:56
#define mutt_socket_send(conn, buf)
Definition: socket.h:57
char user[128]
Username.
Definition: connaccount.h:56
char host[128]
Server to login to.
Definition: connaccount.h:54
MuttAccountFlags flags
Which fields are initialised, e.g. MUTT_ACCT_USER.
Definition: connaccount.h:60
unsigned int status
Definition: adata.h:47
bool hasCAPABILITIES
Server supports CAPABILITIES command.
Definition: adata.h:37
bool hasSTARTTLS
Server supports STARTTLS command.
Definition: adata.h:38
unsigned int use_tls
Definition: adata.h:46
+ Here is the call graph for this function:
+ Here is the caller graph for this function: