NeoMutt  2024-10-02-7-gd3e66a
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 106 of file newsrc.c.

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}
#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 649 of file newsrc.c.

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}
#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:51
void mutt_mem_realloc(void *ptr, size_t size)
Resize a block of memory on the heap.
Definition: memory.c:115
#define PATH_MAX
Definition: mutt.h:42
static int update_file(char *filename, char *buf)
Update file with new contents.
Definition: newsrc.c:395
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
#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 574 of file newsrc.c.

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}
@ 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:280
static struct NntpMboxData * mdata_find(struct NntpAccountData *adata, const char *group)
Find NntpMboxData for given newsgroup or add it.
Definition: newsrc.c:76
void nntp_group_unread_stat(struct NntpMboxData *mdata)
Count number of unread articles using .newsrc data.
Definition: newsrc.c:136
#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 1255 of file newsrc.c.

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}
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:47
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:42
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:46
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 801 of file newsrc.c.

802{
804}
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
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
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 2105 of file nntp.c.

2106{
2107 struct NntpMboxData tmp_mdata = { 0 };
2108 time_t now = 0;
2109 char buf[1024] = { 0 };
2110 char *msg = _("Checking for new newsgroups...");
2111 unsigned int i;
2112 int rc, update_active = false;
2113
2114 if (!adata || !adata->newgroups_time)
2115 return -1;
2116
2117 /* check subscribed newsgroups for new articles */
2118 const bool c_show_new_news = cs_subset_bool(NeoMutt->sub, "show_new_news");
2119 if (c_show_new_news)
2120 {
2121 mutt_message(_("Checking for new messages..."));
2122 for (i = 0; i < adata->groups_num; i++)
2123 {
2124 struct NntpMboxData *mdata = adata->groups_list[i];
2125
2126 if (mdata && mdata->subscribed)
2127 {
2128 rc = nntp_group_poll(mdata, true);
2129 if (rc < 0)
2130 return -1;
2131 if (rc > 0)
2132 update_active = true;
2133 }
2134 }
2135 }
2136 else if (adata->newgroups_time)
2137 {
2138 return 0;
2139 }
2140
2141 /* get list of new groups */
2142 mutt_message("%s", msg);
2143 if (nntp_date(adata, &now) < 0)
2144 return -1;
2145 tmp_mdata.adata = adata;
2146 if (m && m->mdata)
2147 tmp_mdata.group = ((struct NntpMboxData *) m->mdata)->group;
2148 else
2149 tmp_mdata.group = NULL;
2150 i = adata->groups_num;
2151 struct tm tm = mutt_date_gmtime(adata->newgroups_time);
2152 snprintf(buf, sizeof(buf), "NEWGROUPS %02d%02d%02d %02d%02d%02d GMT\r\n",
2153 tm.tm_year % 100, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
2154 rc = nntp_fetch_lines(&tmp_mdata, buf, sizeof(buf), msg, nntp_add_group, adata);
2155 if (rc)
2156 {
2157 if (rc > 0)
2158 {
2159 mutt_error("NEWGROUPS: %s", buf);
2160 }
2161 return -1;
2162 }
2163
2164 /* new groups found */
2165 rc = 0;
2166 if (adata->groups_num != i)
2167 {
2168 int groups_num = i;
2169
2170 adata->newgroups_time = now;
2171 for (; i < adata->groups_num; i++)
2172 {
2173 struct NntpMboxData *mdata = adata->groups_list[i];
2174 mdata->has_new_mail = true;
2175 }
2176
2177 /* loading descriptions */
2178 const bool c_nntp_load_description = cs_subset_bool(NeoMutt->sub, "nntp_load_description");
2179 if (c_nntp_load_description)
2180 {
2181 unsigned int count = 0;
2182 struct Progress *progress = progress_new(MUTT_PROGRESS_READ, adata->groups_num - i);
2183 progress_set_message(progress, _("Loading descriptions..."));
2184
2185 for (i = groups_num; i < adata->groups_num; i++)
2186 {
2187 struct NntpMboxData *mdata = adata->groups_list[i];
2188
2189 if (get_description(mdata, NULL, NULL) < 0)
2190 {
2191 progress_free(&progress);
2192 return -1;
2193 }
2194 progress_update(progress, ++count, -1);
2195 }
2196 progress_free(&progress);
2197 }
2198 update_active = true;
2199 rc = 1;
2200 }
2201 if (update_active)
2204 return rc;
2205}
#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:927
#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:574
int nntp_active_save_cache(struct NntpAccountData *adata)
Save list of all newsgroups to cache.
Definition: newsrc.c:649
static int nntp_date(struct NntpAccountData *adata, time_t *now)
Get date and time from server.
Definition: nntp.c:1699
static int nntp_group_poll(struct NntpMboxData *mdata, bool update_stat)
Check newsgroup for new articles.
Definition: nntp.c:1441
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:814
static int get_description(struct NntpMboxData *mdata, const char *wildmat, const char *msg)
Fetch newsgroups descriptions.
Definition: nntp.c:936
@ 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 810 of file newsrc.c.

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}
struct BodyCache * mutt_bcache_open(struct ConnAccount *account, const char *mailbox)
Open an Email-Body Cache.
Definition: bcache.c:148
void mutt_bcache_close(struct BodyCache **ptr)
Close an Email-Body Cache.
Definition: bcache.c:169
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:690
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 136 of file newsrc.c.

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}
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 709 of file newsrc.c.

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}
const char * cs_subset_path(const struct ConfigSubset *sub, const char *name)
Get a path config item by name.
Definition: helpers.c:168
struct HeaderCache * hcache_open(const char *path, const char *folder, hcache_namer_t namer, bool create)
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 733 of file newsrc.c.

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}
int hcache_delete_email(struct HeaderCache *hc, const char *key, size_t keylen)
Multiplexor for StoreOps::delete_record.
Definition: hcache.c:742
char * hcache_fetch_raw_str(struct HeaderCache *hc, const char *key, size_t keylen)
Fetch a string from the cache.
Definition: hcache.c:655
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:727
+ 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 303 of file newsrc.c.

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}
short cs_subset_sort(const struct ConfigSubset *sub, const char *name)
Get a sort config item by name.
Definition: helpers.c:266
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
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 1766 of file nntp.c.

1767{
1768 if (adata->status == NNTP_OK)
1769 return 0;
1770 if (adata->status == NNTP_BYE)
1771 return -1;
1772 adata->status = NNTP_NONE;
1773
1774 struct Connection *conn = adata->conn;
1775 if (mutt_socket_open(conn) < 0)
1776 return -1;
1777
1778 char buf[256] = { 0 };
1779 int cap;
1780 bool posting = false, auth = true;
1781 int rc = -1;
1782
1783 if (mutt_socket_readln(buf, sizeof(buf), conn) < 0)
1784 {
1785 nntp_connect_error(adata);
1786 goto done;
1787 }
1788
1789 if (mutt_str_startswith(buf, "200"))
1790 {
1791 posting = true;
1792 }
1793 else if (!mutt_str_startswith(buf, "201"))
1794 {
1795 mutt_socket_close(conn);
1797 mutt_error("%s", buf);
1798 goto done;
1799 }
1800
1801 /* get initial capabilities */
1802 cap = nntp_capabilities(adata);
1803 if (cap < 0)
1804 goto done;
1805
1806 /* tell news server to switch to mode reader if it isn't so */
1807 if (cap > 0)
1808 {
1809 if ((mutt_socket_send(conn, "MODE READER\r\n") < 0) ||
1810 (mutt_socket_readln(buf, sizeof(buf), conn) < 0))
1811 {
1812 nntp_connect_error(adata);
1813 goto done;
1814 }
1815
1816 if (mutt_str_startswith(buf, "200"))
1817 {
1818 posting = true;
1819 }
1820 else if (mutt_str_startswith(buf, "201"))
1821 {
1822 posting = false;
1823 }
1824 else if (adata->hasCAPABILITIES)
1825 {
1826 /* error if has capabilities, ignore result if no capabilities */
1827 mutt_socket_close(conn);
1828 mutt_error(_("Could not switch to reader mode"));
1829 goto done;
1830 }
1831
1832 /* recheck capabilities after MODE READER */
1833 if (adata->hasCAPABILITIES)
1834 {
1835 cap = nntp_capabilities(adata);
1836 if (cap < 0)
1837 goto done;
1838 }
1839 }
1840
1841 mutt_message(_("Connected to %s. %s"), conn->account.host,
1842 posting ? _("Posting is ok") : _("Posting is NOT ok"));
1843 mutt_sleep(1);
1844
1845#ifdef USE_SSL
1846 /* Attempt STARTTLS if available and desired. */
1847 const bool c_ssl_force_tls = cs_subset_bool(NeoMutt->sub, "ssl_force_tls");
1848 if ((adata->use_tls != 1) && (adata->hasSTARTTLS || c_ssl_force_tls))
1849 {
1850 if (adata->use_tls == 0)
1851 {
1852 adata->use_tls = c_ssl_force_tls ||
1853 (query_quadoption(_("Secure connection with TLS?"),
1854 NeoMutt->sub, "ssl_starttls") == MUTT_YES) ?
1855 2 :
1856 1;
1857 }
1858 if (adata->use_tls == 2)
1859 {
1860 if ((mutt_socket_send(conn, "STARTTLS\r\n") < 0) ||
1861 (mutt_socket_readln(buf, sizeof(buf), conn) < 0))
1862 {
1863 nntp_connect_error(adata);
1864 goto done;
1865 }
1866 // Clear any data after the STARTTLS acknowledgement
1867 mutt_socket_empty(conn);
1868 if (!mutt_str_startswith(buf, "382"))
1869 {
1870 adata->use_tls = 0;
1871 mutt_error("STARTTLS: %s", buf);
1872 }
1873 else if (mutt_ssl_starttls(conn))
1874 {
1875 adata->use_tls = 0;
1876 adata->status = NNTP_NONE;
1877 mutt_socket_close(adata->conn);
1878 mutt_error(_("Could not negotiate TLS connection"));
1879 goto done;
1880 }
1881 else
1882 {
1883 /* recheck capabilities after STARTTLS */
1884 cap = nntp_capabilities(adata);
1885 if (cap < 0)
1886 goto done;
1887 }
1888 }
1889 }
1890#endif
1891
1892 /* authentication required? */
1893 if (conn->account.flags & MUTT_ACCT_USER)
1894 {
1895 if (!conn->account.user[0])
1896 auth = false;
1897 }
1898 else
1899 {
1900 if ((mutt_socket_send(conn, "STAT\r\n") < 0) ||
1901 (mutt_socket_readln(buf, sizeof(buf), conn) < 0))
1902 {
1903 nntp_connect_error(adata);
1904 goto done;
1905 }
1906 if (!mutt_str_startswith(buf, "480"))
1907 auth = false;
1908 }
1909
1910 /* authenticate */
1911 if (auth && (nntp_auth(adata) < 0))
1912 goto done;
1913
1914 /* get final capabilities after authentication */
1915 if (adata->hasCAPABILITIES && (auth || (cap > 0)))
1916 {
1917 cap = nntp_capabilities(adata);
1918 if (cap < 0)
1919 goto done;
1920 if (cap > 0)
1921 {
1922 mutt_socket_close(conn);
1923 mutt_error(_("Could not switch to reader mode"));
1924 goto done;
1925 }
1926 }
1927
1928 /* attempt features */
1929 if (nntp_attempt_features(adata) < 0)
1930 goto done;
1931
1932 rc = 0;
1933 adata->status = NNTP_OK;
1934
1935done:
1936 return rc;
1937}
#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:1145
void mutt_str_remove_trailing_ws(char *s)
Trim trailing whitespace from a string.
Definition: string.c:565
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:843
static int nntp_auth(struct NntpAccountData *adata)
Get login, password and authenticate.
Definition: nntp.c:452
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:379
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: