NeoMutt  2025-12-11-236-g400a5f
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
lib.h File Reference

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

#include <stdbool.h>
#include <stdio.h>
#include "core/lib.h"
#include "expando/lib.h"
#include "expando_browser.h"
+ Include dependency graph for lib.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  NntpAcache
 NNTP article cache. More...
 
struct  NewsrcEntry
 An entry in a .newsrc (subscribed newsgroups) More...
 

Macros

#define anum_t   long
 
#define ANUM_FMT   "%ld"
 
#define NNTP_ACACHE_LEN   10
 

Functions

struct NntpAccountDatanntp_select_server (struct Mailbox *m, const char *server, bool leave_lock)
 Open a connection to an NNTP server.
 
struct NntpMboxDatamutt_newsgroup_subscribe (struct NntpAccountData *adata, char *group)
 Subscribe newsgroup.
 
struct NntpMboxDatamutt_newsgroup_unsubscribe (struct NntpAccountData *adata, char *group)
 Unsubscribe newsgroup.
 
struct NntpMboxDatamutt_newsgroup_catchup (struct Mailbox *m, struct NntpAccountData *adata, char *group)
 Catchup newsgroup.
 
struct NntpMboxDatamutt_newsgroup_uncatchup (struct Mailbox *m, struct NntpAccountData *adata, char *group)
 Uncatchup newsgroup.
 
int nntp_active_fetch (struct NntpAccountData *adata, bool mark_new)
 Fetch list of all newsgroups from server.
 
int nntp_newsrc_update (struct NntpAccountData *adata)
 Update .newsrc file.
 
int nntp_post (struct Mailbox *m, const char *msg)
 Post article.
 
int nntp_check_msgid (struct Mailbox *m, const char *msgid)
 Fetch article by Message-ID.
 
int nntp_check_children (struct Mailbox *m, const char *msgid)
 Fetch children of article with the Message-ID.
 
int nntp_newsrc_parse (struct NntpAccountData *adata)
 Parse .newsrc file.
 
void nntp_newsrc_close (struct NntpAccountData *adata)
 Unlock and close .newsrc file.
 
void nntp_mailbox (struct Mailbox *m, char *buf, size_t buflen)
 Get first newsgroup with new messages.
 
void nntp_expand_path (char *buf, size_t buflen, struct ConnAccount *acct)
 Make fully qualified url from newsgroup name.
 
void nntp_clear_cache (struct NntpAccountData *adata)
 Clear the NNTP cache.
 
int nntp_sort_unsorted (const struct Email *a, const struct Email *b, bool reverse)
 Restore the 'unsorted' order of emails - Implements sort_email_t -.
 
enum MailboxType nntp_path_probe (const char *path, const struct stat *st)
 Is this an NNTP Mailbox?
 
int nntp_complete (struct Buffer *buf)
 Auto-complete NNTP newsgroups.
 

Variables

struct NntpAccountDataCurrentNewsSrv
 Current NNTP news server.
 
const struct MxOps MxNntpOps
 NNTP Mailbox - Implements MxOps -.
 
const struct ExpandoRenderCallback NntpRenderCallbacks []
 Callbacks for Newsrc Expandos.
 

Detailed Description

Usenet network mailbox type; talk to an NNTP server.

Authors
  • Richard Russon
  • Tóth János

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 lib.h.

Macro Definition Documentation

◆ anum_t

#define anum_t   long

Definition at line 63 of file lib.h.

◆ ANUM_FMT

#define ANUM_FMT   "%ld"

Definition at line 64 of file lib.h.

◆ NNTP_ACACHE_LEN

#define NNTP_ACACHE_LEN   10

Definition at line 85 of file lib.h.

Function Documentation

◆ nntp_select_server()

struct NntpAccountData * nntp_select_server ( struct Mailbox * m,
const char * server,
bool leave_lock )

Open a connection to an NNTP server.

Parameters
mMailbox
serverServer URL
leave_lockLeave the server locked?
Return values
ptrNNTP server
NULLError

Automatically loads a newsrc into memory, if necessary. Checks the size/mtime of a newsrc file, if it doesn't match, load again. Hmm, if a system has broken mtimes, this might mean the file is reloaded every time, which we'd have to fix.

See also
$newsrc

Definition at line 944 of file newsrc.c.

945{
946 char file[PATH_MAX] = { 0 };
947 int rc;
948 struct ConnAccount cac = { { 0 } };
949 struct NntpAccountData *adata = NULL;
950 struct Connection *conn = NULL;
951
952 if (!server || (*server == '\0'))
953 {
954 mutt_error(_("No news server defined"));
955 return NULL;
956 }
957
958 /* create account from news server url */
959 cac.flags = 0;
960 cac.port = NNTP_PORT;
962 cac.service = "nntp";
964
965 snprintf(file, sizeof(file), "%s%s", strstr(server, "://") ? "" : "news://", server);
966 struct Url *url = url_parse(file);
967 if (!url || (url->path && *url->path) ||
968 !((url->scheme == U_NNTP) || (url->scheme == U_NNTPS)) || !url->host ||
969 (account_from_url(&cac, url) < 0))
970 {
971 url_free(&url);
972 mutt_error(_("%s is an invalid news server specification"), server);
973 return NULL;
974 }
975 if (url->scheme == U_NNTPS)
976 {
977 cac.flags |= MUTT_ACCT_SSL;
978 cac.port = NNTP_SSL_PORT;
979 }
980 url_free(&url);
981
982 // If nntp_user and nntp_pass are specified in the config, use them to find the connection
983 const char *user = NULL;
984 const char *pass = NULL;
985 if ((user = cac.get_field(MUTT_CA_USER, NULL)))
986 {
987 mutt_str_copy(cac.user, user, sizeof(cac.user));
988 cac.flags |= MUTT_ACCT_USER;
989 }
990 if ((pass = cac.get_field(MUTT_CA_PASS, NULL)))
991 {
992 mutt_str_copy(cac.pass, pass, sizeof(cac.pass));
993 cac.flags |= MUTT_ACCT_PASS;
994 }
995
996 /* find connection by account */
997 conn = mutt_conn_find(&cac);
998 if (!conn)
999 return NULL;
1000 if (!(conn->account.flags & MUTT_ACCT_USER) && cac.flags & MUTT_ACCT_USER)
1001 {
1002 conn->account.flags |= MUTT_ACCT_USER;
1003 conn->account.user[0] = '\0';
1004 }
1005
1006 /* new news server */
1007 adata = nntp_adata_new(conn);
1008
1009 rc = nntp_open_connection(adata);
1010
1011 /* try to create cache directory and enable caching */
1012 adata->cacheable = false;
1013 const char *const c_news_cache_dir = cs_subset_path(NeoMutt->sub, "news_cache_dir");
1014 if ((rc >= 0) && c_news_cache_dir)
1015 {
1016 cache_expand(file, sizeof(file), &conn->account, NULL);
1017 if (mutt_file_mkdir(file, S_IRWXU) < 0)
1018 {
1019 mutt_error(_("Can't create %s: %s"), file, strerror(errno));
1020 }
1021 adata->cacheable = true;
1022 }
1023
1024 /* load .newsrc */
1025 if (rc >= 0)
1026 {
1027 const struct Expando *c_newsrc = cs_subset_expando(NeoMutt->sub, "newsrc");
1028 struct Buffer *buf = buf_pool_get();
1030 buf->dsize, NeoMutt->env, buf);
1031 expand_path(buf, false);
1032 adata->newsrc_file = buf_strdup(buf);
1033 buf_pool_release(&buf);
1034 rc = nntp_newsrc_parse(adata);
1035 }
1036 if (rc >= 0)
1037 {
1038 /* try to load list of newsgroups from cache */
1039 if (adata->cacheable && (active_get_cache(adata) == 0))
1040 {
1041 rc = nntp_check_new_groups(m, adata);
1042 }
1043 else
1044 {
1045 /* load list of newsgroups from server */
1046 rc = nntp_active_fetch(adata, false);
1047 }
1048 }
1049
1050 if (rc >= 0)
1051 nntp_clear_cache(adata);
1052
1053#ifdef USE_HCACHE
1054 /* check cache files */
1055 if ((rc >= 0) && adata->cacheable)
1056 {
1057 struct dirent *de = NULL;
1058 DIR *dir = mutt_file_opendir(file, MUTT_OPENDIR_NONE);
1059
1060 if (dir)
1061 {
1062 while ((de = readdir(dir)))
1063 {
1064 struct HeaderCache *hc = NULL;
1065 char *group = de->d_name;
1066
1067 char *p = group + strlen(group) - 7;
1068 if ((strlen(group) < 8) || !mutt_str_equal(p, ".hcache"))
1069 continue;
1070 *p = '\0';
1072 if (!mdata)
1073 continue;
1074
1075 hc = nntp_hcache_open(mdata);
1076 if (!hc)
1077 continue;
1078
1079 /* fetch previous values of first and last */
1080 char *hdata = hcache_fetch_raw_str(hc, "index", 5);
1081 if (hdata)
1082 {
1083 anum_t first = 0, last = 0;
1084
1085 if (sscanf(hdata, ANUM_FMT " " ANUM_FMT, &first, &last) == 2)
1086 {
1087 if (mdata->deleted)
1088 {
1089 mdata->first_message = first;
1090 mdata->last_message = last;
1091 }
1092 if ((last >= mdata->first_message) && (last <= mdata->last_message))
1093 {
1094 mdata->last_cached = last;
1095 mutt_debug(LL_DEBUG2, "%s last_cached=" ANUM_FMT "\n", mdata->group, last);
1096 }
1097 }
1098 FREE(&hdata);
1099 }
1100 hcache_close(&hc);
1101 }
1102 closedir(dir);
1103 }
1104 }
1105#endif
1106
1107 if ((rc < 0) || !leave_lock)
1109
1110 if (rc < 0)
1111 {
1116 FREE(&adata);
1117 mutt_socket_close(conn);
1118 FREE(&conn);
1119 return NULL;
1120 }
1121
1122 return adata;
1123}
char * buf_strdup(const struct Buffer *buf)
Copy a Buffer's string.
Definition buffer.c:571
const char * cs_subset_path(const struct ConfigSubset *sub, const char *name)
Get a path config item by name.
Definition helpers.c:168
const struct Expando * cs_subset_expando(const struct ConfigSubset *sub, const char *name)
Get an Expando config item by name.
@ MUTT_CA_USER
User name.
Definition connaccount.h:36
@ 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
int expando_filter(const struct Expando *exp, const struct ExpandoRenderCallback *erc, void *data, MuttFormatFlags flags, int max_cols, char **env_list, struct Buffer *buf)
Render an Expando and run the result through a filter.
Definition filter.c:138
const struct ExpandoRenderCallback NntpRenderCallbacks[]
Callbacks for Newsrc Expandos.
int mutt_file_mkdir(const char *path, mode_t mode)
Recursively create directories.
Definition file.c:848
DIR * mutt_file_opendir(const char *path, enum MuttOpenDirMode mode)
Open a directory.
Definition file.c:539
@ MUTT_OPENDIR_NONE
Plain opendir()
Definition file.h:63
static const char * nntp_get_field(enum ConnAccountField field, void *gf_data)
Get connection login credentials - Implements ConnAccount::get_field() -.
Definition newsrc.c:913
#define mutt_error(...)
Definition logging2.h:94
#define mutt_debug(LEVEL,...)
Definition logging2.h:91
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:364
void mutt_hash_free(struct HashTable **ptr)
Free a hash table.
Definition hash.c:459
void hcache_close(struct HeaderCache **ptr)
Multiplexor for StoreOps::close.
Definition hcache.c:544
char * hcache_fetch_raw_str(struct HeaderCache *hc, const char *key, size_t keylen)
Fetch a string from the cache.
Definition hcache.c:654
@ LL_DEBUG2
Log at debug level 2.
Definition logging2.h:46
#define FREE(x)
Free memory and set the pointer to NULL.
Definition memory.h:68
#define _(a)
Definition message.h:28
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition string.c:662
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:583
#define PATH_MAX
Definition mutt.h:48
int account_from_url(struct ConnAccount *cac, const struct Url *url)
Fill ConnAccount with information from url.
@ MUTT_ACCT_TYPE_NNTP
Nntp (Usenet) Account.
struct Connection * mutt_conn_find(const struct ConnAccount *cac)
Find a connection from a list.
Definition mutt_socket.c:88
void expand_path(struct Buffer *buf, bool regex)
Create the canonical path.
Definition muttlib.c:121
struct HeaderCache * nntp_hcache_open(struct NntpMboxData *mdata)
Open newsgroup hcache.
Definition newsrc.c:706
void nntp_clear_cache(struct NntpAccountData *adata)
Clear the NNTP cache.
Definition newsrc.c:840
int nntp_newsrc_parse(struct NntpAccountData *adata)
Parse .newsrc file.
Definition newsrc.c:163
void nntp_newsrc_close(struct NntpAccountData *adata)
Unlock and close .newsrc file.
Definition newsrc.c:119
static int active_get_cache(struct NntpAccountData *adata)
Load list of all newsgroups from cache.
Definition newsrc.c:612
static void cache_expand(char *dst, size_t dstlen, struct ConnAccount *cac, const char *src)
Make fully qualified cache file name.
Definition newsrc.c:523
struct NntpAccountData * nntp_adata_new(struct Connection *conn)
Allocate and initialise a new NntpAccountData structure.
Definition adata.c:65
int nntp_active_fetch(struct NntpAccountData *adata, bool mark_new)
Fetch list of all newsgroups from server.
Definition nntp.c:2034
#define ANUM_FMT
Definition lib.h:64
#define anum_t
Definition lib.h:63
#define NNTP_SSL_PORT
Definition private.h:37
#define NNTP_PORT
Definition private.h:36
int nntp_check_new_groups(struct Mailbox *m, struct NntpAccountData *adata)
Check for new groups/articles in subscribed groups.
Definition nntp.c:2102
int nntp_open_connection(struct NntpAccountData *adata)
Connect to server, authenticate and get capabilities.
Definition nntp.c:1763
struct Buffer * buf_pool_get(void)
Get a Buffer from the pool.
Definition pool.c:91
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
Definition pool.c:111
#define MUTT_FORMAT_NO_FLAGS
No flags are set.
Definition render.h:33
int mutt_socket_close(struct Connection *conn)
Close a socket.
Definition socket.c:100
void * adata
Private data (for Mailbox backends)
Definition account.h:42
String manipulation buffer.
Definition buffer.h:36
size_t dsize
Length of data.
Definition buffer.h:39
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
const char *(* get_field)(enum ConnAccountField field, void *gf_data)
Definition connaccount.h:70
unsigned char type
Connection type, e.g. MUTT_ACCT_TYPE_IMAP.
Definition connaccount.h:59
MuttAccountFlags flags
Which fields are initialised, e.g. MUTT_ACCT_USER.
Definition connaccount.h:60
unsigned short port
Port to connect to.
Definition connaccount.h:58
struct ConnAccount account
Account details: username, password, etc.
Definition connection.h:49
Parsed Expando trees.
Definition expando.h:41
Header Cache.
Definition lib.h:87
void * mdata
Driver specific data.
Definition mailbox.h:131
Container for Accounts, Notifications.
Definition neomutt.h:128
char ** env
Private copy of the environment variables.
Definition neomutt.h:143
struct ConfigSubset * sub
Inherited config items.
Definition neomutt.h:134
NNTP-specific Account data -.
Definition adata.h:36
struct HashTable * groups_hash
Hash Table: "newsgroup" -> NntpMboxData.
Definition adata.h:62
struct NntpMboxData ** groups_list
List of newsgroups.
Definition adata.h:60
char * authenticators
Authenticators list.
Definition adata.h:52
bool cacheable
Can be cached.
Definition adata.h:48
char * newsrc_file
Newsrc file path.
Definition adata.h:51
NNTP-specific Mailbox data -.
Definition mdata.h:34
anum_t last_message
Last article number.
Definition mdata.h:38
char * group
Name of newsgroup.
Definition mdata.h:35
struct NntpAccountData * adata
Account data.
Definition mdata.h:48
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 * 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
struct Url * url_parse(const char *src)
Fill in Url.
Definition url.c:239
void url_free(struct Url **ptr)
Free the contents of a URL.
Definition url.c:124
@ U_NNTPS
Url is nntps://.
Definition url.h:42
@ U_NNTP
Url is nntp://.
Definition url.h:41
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_newsgroup_subscribe()

struct NntpMboxData * mutt_newsgroup_subscribe ( struct NntpAccountData * adata,
char * group )

Subscribe newsgroup.

Parameters
adataNNTP server
groupNewsgroup
Return values
ptrNNTP data
NULLError

Definition at line 1174 of file newsrc.c.

1175{
1176 if (!adata || !adata->groups_hash || !group || (*group == '\0'))
1177 return NULL;
1178
1180 mdata->subscribed = true;
1181 if (!mdata->newsrc_ent)
1182 {
1183 mdata->newsrc_ent = MUTT_MEM_CALLOC(1, struct NewsrcEntry);
1184 mdata->newsrc_len = 1;
1185 mdata->newsrc_ent[0].first = 1;
1186 mdata->newsrc_ent[0].last = 0;
1187 }
1188 return mdata;
1189}
#define MUTT_MEM_CALLOC(n, type)
Definition memory.h:52
static struct NntpMboxData * mdata_find(struct NntpAccountData *adata, const char *group)
Find NntpMboxData for given newsgroup or add it.
Definition newsrc.c:73
An entry in a .newsrc (subscribed newsgroups)
Definition lib.h:79
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_newsgroup_unsubscribe()

struct NntpMboxData * mutt_newsgroup_unsubscribe ( struct NntpAccountData * adata,
char * group )

Unsubscribe newsgroup.

Parameters
adataNNTP server
groupNewsgroup
Return values
ptrNNTP data
NULLError

Definition at line 1198 of file newsrc.c.

1199{
1200 if (!adata || !adata->groups_hash || !group || (*group == '\0'))
1201 return NULL;
1202
1204 if (!mdata)
1205 return NULL;
1206
1207 mdata->subscribed = false;
1208 const bool c_save_unsubscribed = cs_subset_bool(NeoMutt->sub, "save_unsubscribed");
1209 if (!c_save_unsubscribed)
1210 {
1211 mdata->newsrc_len = 0;
1212 FREE(&mdata->newsrc_ent);
1213 }
1214 return mdata;
1215}
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition helpers.c:47
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_newsgroup_catchup()

struct NntpMboxData * mutt_newsgroup_catchup ( struct Mailbox * m,
struct NntpAccountData * adata,
char * group )

Catchup newsgroup.

Parameters
mMailbox
adataNNTP server
groupNewsgroup
Return values
ptrNNTP data
NULLError

Definition at line 1225 of file newsrc.c.

1227{
1228 if (!adata || !adata->groups_hash || !group || (*group == '\0'))
1229 return NULL;
1230
1232 if (!mdata)
1233 return NULL;
1234
1235 if (mdata->newsrc_ent)
1236 {
1237 MUTT_MEM_REALLOC(&mdata->newsrc_ent, 1, struct NewsrcEntry);
1238 mdata->newsrc_len = 1;
1239 mdata->newsrc_ent[0].first = 1;
1240 mdata->newsrc_ent[0].last = mdata->last_message;
1241 }
1242 mdata->unread = 0;
1243 if (m && (m->mdata == mdata))
1244 {
1245 for (unsigned int i = 0; i < m->msg_count; i++)
1246 {
1247 struct Email *e = m->emails[i];
1248 if (!e)
1249 break;
1250 mutt_set_flag(m, e, MUTT_READ, true, true);
1251 }
1252 }
1253 return mdata;
1254}
void mutt_set_flag(struct Mailbox *m, struct Email *e, enum MessageType flag, bool bf, bool upd_mbox)
Set a flag on an email.
Definition flags.c:54
#define MUTT_MEM_REALLOC(pptr, n, type)
Definition memory.h:55
@ MUTT_READ
Messages that have been read.
Definition mutt.h:91
The envelope/body of an email.
Definition email.h:39
int msg_count
Total number of messages.
Definition mailbox.h:87
struct Email ** emails
Array of Emails.
Definition mailbox.h:95
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_newsgroup_uncatchup()

struct NntpMboxData * mutt_newsgroup_uncatchup ( struct Mailbox * m,
struct NntpAccountData * adata,
char * group )

Uncatchup newsgroup.

Parameters
mMailbox
adataNNTP server
groupNewsgroup
Return values
ptrNNTP data
NULLError

Definition at line 1264 of file newsrc.c.

1266{
1267 if (!adata || !adata->groups_hash || !group || (*group == '\0'))
1268 return NULL;
1269
1271 if (!mdata)
1272 return NULL;
1273
1274 if (mdata->newsrc_ent)
1275 {
1276 MUTT_MEM_REALLOC(&mdata->newsrc_ent, 1, struct NewsrcEntry);
1277 mdata->newsrc_len = 1;
1278 mdata->newsrc_ent[0].first = 1;
1279 mdata->newsrc_ent[0].last = mdata->first_message - 1;
1280 }
1281 if (m && (m->mdata == mdata))
1282 {
1283 mdata->unread = m->msg_count;
1284 for (unsigned int i = 0; i < m->msg_count; i++)
1285 {
1286 struct Email *e = m->emails[i];
1287 if (!e)
1288 break;
1289 mutt_set_flag(m, e, MUTT_READ, false, true);
1290 }
1291 }
1292 else
1293 {
1294 mdata->unread = mdata->last_message;
1295 if (mdata->newsrc_ent)
1296 mdata->unread -= mdata->newsrc_ent[0].last;
1297 }
1298 return mdata;
1299}
anum_t last
Last article number in run.
Definition lib.h:81
struct NewsrcEntry * newsrc_ent
Newsrc entries.
Definition mdata.h:47
anum_t unread
Unread articles.
Definition mdata.h:41
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ nntp_active_fetch()

int nntp_active_fetch ( struct NntpAccountData * adata,
bool mark_new )

Fetch list of all newsgroups from server.

Parameters
adataNNTP server
mark_newMark the groups as new
Return values
0Success
-1Failure

Definition at line 2034 of file nntp.c.

2035{
2036 struct NntpMboxData tmp_mdata = { 0 };
2037 char msg[256] = { 0 };
2038 char buf[1024] = { 0 };
2039 unsigned int i;
2040 int rc;
2041
2042 snprintf(msg, sizeof(msg), _("Loading list of groups from server %s..."),
2044 mutt_message("%s", msg);
2045 if (nntp_date(adata, &adata->newgroups_time) < 0)
2046 return -1;
2047
2048 tmp_mdata.adata = adata;
2049 tmp_mdata.group = NULL;
2050 i = adata->groups_num;
2051 mutt_str_copy(buf, "LIST\r\n", sizeof(buf));
2052 rc = nntp_fetch_lines(&tmp_mdata, buf, sizeof(buf), msg, nntp_add_group, adata);
2053 if (rc)
2054 {
2055 if (rc > 0)
2056 {
2057 mutt_error("LIST: %s", buf);
2058 }
2059 return -1;
2060 }
2061
2062 if (mark_new)
2063 {
2064 for (; i < adata->groups_num; i++)
2065 {
2066 struct NntpMboxData *mdata = adata->groups_list[i];
2067 mdata->has_new_mail = true;
2068 }
2069 }
2070
2071 for (i = 0; i < adata->groups_num; i++)
2072 {
2073 struct NntpMboxData *mdata = adata->groups_list[i];
2074
2075 if (mdata && mdata->deleted && !mdata->newsrc_ent)
2076 {
2078 mutt_hash_delete(adata->groups_hash, mdata->group, NULL);
2079 adata->groups_list[i] = NULL;
2080 }
2081 }
2082
2083 const bool c_nntp_load_description = cs_subset_bool(NeoMutt->sub, "nntp_load_description");
2084 if (c_nntp_load_description)
2085 rc = get_description(&tmp_mdata, "*", _("Loading descriptions..."));
2086
2088 if (rc < 0)
2089 return -1;
2091 return 0;
2092}
#define mutt_message(...)
Definition logging2.h:93
void mutt_hash_delete(struct HashTable *table, const char *strkey, const void *data)
Remove an element from a Hash Table.
Definition hash.c:429
void mutt_clear_error(void)
Clear the message line (bottom line of screen)
void nntp_delete_group_cache(struct NntpMboxData *mdata)
Remove hcache and bcache of newsgroup.
Definition newsrc.c:807
int nntp_add_group(char *line, void *data)
Parse newsgroup.
Definition newsrc.c:571
int nntp_active_save_cache(struct NntpAccountData *adata)
Save list of all newsgroups to cache.
Definition newsrc.c:646
static int nntp_date(struct NntpAccountData *adata, time_t *now)
Get date and time from server.
Definition nntp.c:1696
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:811
static int get_description(struct NntpMboxData *mdata, const char *wildmat, const char *msg)
Fetch newsgroups descriptions.
Definition nntp.c:933
char host[128]
Server to login to.
Definition connaccount.h:54
time_t newgroups_time
Last newgroups request time.
Definition adata.h:56
struct Connection * conn
Connection to NNTP Server.
Definition adata.h:63
unsigned int groups_num
Number of newsgroups.
Definition adata.h:58
bool has_new_mail
Has new articles.
Definition mdata.h:43
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ nntp_newsrc_update()

int nntp_newsrc_update ( struct NntpAccountData * adata)

Update .newsrc file.

Parameters
adataNNTP server
Return values
0Success
-1Failure

Definition at line 442 of file newsrc.c.

443{
444 if (!adata)
445 return -1;
446
447 int rc = -1;
448
449 size_t buflen = 10240;
450 char *buf = MUTT_MEM_CALLOC(buflen, char);
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, char);
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, char);
477 }
478 if (j)
479 buf[off++] = ',';
480 if (mdata->newsrc_ent[j].first == mdata->newsrc_ent[j].last)
481 {
482 snprintf(buf + off, buflen - off, ANUM_FMT, mdata->newsrc_ent[j].first);
483 }
484 else if (mdata->newsrc_ent[j].first < mdata->newsrc_ent[j].last)
485 {
486 snprintf(buf + off, buflen - off, ANUM_FMT "-" ANUM_FMT,
487 mdata->newsrc_ent[j].first, mdata->newsrc_ent[j].last);
488 }
489 off += strlen(buf + off);
490 }
491 buf[off++] = '\n';
492 }
493 buf[off] = '\0';
494
495 /* newrc being fully rewritten */
496 mutt_debug(LL_DEBUG1, "Updating %s\n", adata->newsrc_file);
497 if (adata->newsrc_file && (update_file(adata->newsrc_file, buf) == 0))
498 {
499 struct stat st = { 0 };
500
501 rc = stat(adata->newsrc_file, &st);
502 if (rc == 0)
503 {
504 adata->size = st.st_size;
505 adata->mtime = st.st_mtime;
506 }
507 else
508 {
509 mutt_perror("%s", adata->newsrc_file);
510 }
511 }
512 FREE(&buf);
513 return rc;
514}
#define mutt_perror(...)
Definition logging2.h:95
@ LL_DEBUG1
Log at debug level 1.
Definition logging2.h:45
static int update_file(char *filename, char *buf)
Update file with new contents.
Definition newsrc.c:392
off_t size
Newsrc file size.
Definition adata.h:54
time_t mtime
Newsrc modification time.
Definition adata.h:55
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ nntp_post()

int nntp_post ( struct Mailbox * m,
const char * msg )

Post article.

Parameters
mMailbox
msgMessage to post
Return values
0Success
-1Failure

Definition at line 1943 of file nntp.c.

1944{
1945 struct NntpMboxData *mdata = NULL;
1946 struct NntpMboxData tmp_mdata = { 0 };
1947 char buf[1024] = { 0 };
1948 int rc = -1;
1949
1950 if (m && (m->type == MUTT_NNTP))
1951 {
1952 mdata = m->mdata;
1953 }
1954 else
1955 {
1956 const char *const c_news_server = cs_subset_string(NeoMutt->sub, "news_server");
1957 CurrentNewsSrv = nntp_select_server(m, c_news_server, false);
1958 if (!CurrentNewsSrv)
1959 goto done;
1960
1961 mdata = &tmp_mdata;
1963 mdata->group = NULL;
1964 }
1965
1966 FILE *fp = mutt_file_fopen(msg, "r");
1967 if (!fp)
1968 {
1969 mutt_perror("%s", msg);
1970 goto done;
1971 }
1972
1973 mutt_str_copy(buf, "POST\r\n", sizeof(buf));
1974 if (nntp_query(mdata, buf, sizeof(buf)) < 0)
1975 {
1976 mutt_file_fclose(&fp);
1977 goto done;
1978 }
1979 if (buf[0] != '3')
1980 {
1981 mutt_error(_("Can't post article: %s"), buf);
1982 mutt_file_fclose(&fp);
1983 goto done;
1984 }
1985
1986 buf[0] = '.';
1987 buf[1] = '\0';
1988 while (fgets(buf + 1, sizeof(buf) - 2, fp))
1989 {
1990 size_t len = strlen(buf);
1991 if (buf[len - 1] == '\n')
1992 {
1993 buf[len - 1] = '\r';
1994 buf[len] = '\n';
1995 len++;
1996 buf[len] = '\0';
1997 }
1998 if (mutt_socket_send_d(mdata->adata->conn, (buf[1] == '.') ? buf : buf + 1,
1999 MUTT_SOCK_LOG_FULL) < 0)
2000 {
2001 mutt_file_fclose(&fp);
2002 nntp_connect_error(mdata->adata);
2003 goto done;
2004 }
2005 }
2006 mutt_file_fclose(&fp);
2007
2008 if (((buf[strlen(buf) - 1] != '\n') &&
2009 (mutt_socket_send_d(mdata->adata->conn, "\r\n", MUTT_SOCK_LOG_FULL) < 0)) ||
2010 (mutt_socket_send_d(mdata->adata->conn, ".\r\n", MUTT_SOCK_LOG_FULL) < 0) ||
2011 (mutt_socket_readln(buf, sizeof(buf), mdata->adata->conn) < 0))
2012 {
2013 nntp_connect_error(mdata->adata);
2014 goto done;
2015 }
2016 if (buf[0] != '2')
2017 {
2018 mutt_error(_("Can't post article: %s"), buf);
2019 goto done;
2020 }
2021 rc = 0;
2022
2023done:
2024 return rc;
2025}
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
Definition helpers.c:291
@ MUTT_NNTP
'NNTP' (Usenet) Mailbox type
Definition mailbox.h:48
#define mutt_file_fclose(FP)
Definition file.h:139
#define mutt_file_fopen(PATH, MODE)
Definition file.h:138
struct NntpAccountData * CurrentNewsSrv
Current NNTP news server.
Definition nntp.c:74
struct NntpAccountData * nntp_select_server(struct Mailbox *m, const char *server, bool leave_lock)
Open a connection to an NNTP server.
Definition newsrc.c:944
static int nntp_connect_error(struct NntpAccountData *adata)
Signal a failed connection.
Definition nntp.c:124
static int nntp_query(struct NntpMboxData *mdata, char *line, size_t linelen)
Send data from buffer and receive answer to same buffer.
Definition nntp.c:727
#define MUTT_SOCK_LOG_FULL
Log everything including full protocol.
Definition socket.h:53
#define mutt_socket_readln(buf, buflen, conn)
Definition socket.h:55
#define mutt_socket_send_d(conn, buf, dbg)
Definition socket.h:57
enum MailboxType type
Mailbox type.
Definition mailbox.h:101
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ nntp_check_msgid()

int nntp_check_msgid ( struct Mailbox * m,
const char * msgid )

Fetch article by Message-ID.

Parameters
mMailbox
msgidMessage ID
Return values
0Success
1No such article
-1Error

Definition at line 2212 of file nntp.c.

2213{
2214 if (!m)
2215 return -1;
2216
2217 struct NntpMboxData *mdata = m->mdata;
2218 char buf[1024] = { 0 };
2219
2220 FILE *fp = mutt_file_mkstemp();
2221 if (!fp)
2222 {
2223 mutt_perror(_("Can't create temporary file"));
2224 return -1;
2225 }
2226
2227 snprintf(buf, sizeof(buf), "HEAD %s\r\n", msgid);
2228 int rc = nntp_fetch_lines(mdata, buf, sizeof(buf), NULL, fetch_tempfile, fp);
2229 if (rc)
2230 {
2231 mutt_file_fclose(&fp);
2232 if (rc < 0)
2233 return -1;
2234 if (mutt_str_startswith(buf, "430"))
2235 return 1;
2236 mutt_error("HEAD: %s", buf);
2237 return -1;
2238 }
2239
2240 /* parse header */
2242 m->emails[m->msg_count] = email_new();
2243 struct Email *e = m->emails[m->msg_count];
2244 e->edata = nntp_edata_new();
2246 e->env = mutt_rfc822_read_header(fp, e, false, false);
2247 mutt_file_fclose(&fp);
2248
2249 /* get article number */
2250 if (e->env->xref)
2251 {
2252 nntp_parse_xref(m, e);
2253 }
2254 else
2255 {
2256 snprintf(buf, sizeof(buf), "STAT %s\r\n", msgid);
2257 if (nntp_query(mdata, buf, sizeof(buf)) < 0)
2258 {
2259 email_free(&e);
2260 return -1;
2261 }
2262 sscanf(buf + 4, ANUM_FMT, &nntp_edata_get(e)->article_num);
2263 }
2264
2265 /* reset flags */
2266 e->read = false;
2267 e->old = false;
2268 e->deleted = false;
2269 e->changed = true;
2270 e->received = e->date_sent;
2271 e->index = m->msg_count++;
2273 return 0;
2274}
void mailbox_changed(struct Mailbox *m, enum NotifyMailbox action)
Notify observers of a change to a Mailbox.
Definition mailbox.c:232
@ NT_MAILBOX_INVALID
Email list was changed.
Definition mailbox.h:179
struct Email * email_new(void)
Create a new Email.
Definition email.c:77
void email_free(struct Email **ptr)
Free an Email.
Definition email.c:46
struct Envelope * mutt_rfc822_read_header(FILE *fp, struct Email *e, bool user_hdrs, bool weed)
Parses an RFC822 header.
Definition parse.c:1204
void nntp_edata_free(void **ptr)
Free the private Email data - Implements Email::edata_free() -.
Definition edata.c:38
size_t mutt_str_startswith(const char *str, const char *prefix)
Check whether a string starts with a prefix.
Definition string.c:234
void mx_alloc_memory(struct Mailbox *m, int req_size)
Create storage for the emails.
Definition mx.c:1208
struct NntpEmailData * nntp_edata_get(struct Email *e)
Get the private data for this Email.
Definition edata.c:60
struct NntpEmailData * nntp_edata_new(void)
Create a new NntpEmailData for an Email.
Definition edata.c:50
static int fetch_tempfile(char *line, void *data)
Write line to temporary file.
Definition nntp.c:1006
static void nntp_parse_xref(struct Mailbox *m, struct Email *e)
Parse cross-reference.
Definition nntp.c:965
bool read
Email is read.
Definition email.h:50
struct Envelope * env
Envelope information.
Definition email.h:68
void * edata
Driver-specific data.
Definition email.h:74
bool old
Email is seen, but unread.
Definition email.h:49
void(* edata_free)(void **ptr)
Definition email.h:90
bool changed
Email has been edited.
Definition email.h:77
time_t date_sent
Time when the message was sent (UTC)
Definition email.h:60
bool deleted
Email is deleted.
Definition email.h:78
int index
The absolute (unsorted) message number.
Definition email.h:110
time_t received
Time when the message was placed in the mailbox.
Definition email.h:61
char * xref
List of cross-references.
Definition envelope.h:79
#define mutt_file_mkstemp()
Definition tmp.h:36
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ nntp_check_children()

int nntp_check_children ( struct Mailbox * m,
const char * msgid )

Fetch children of article with the Message-ID.

Parameters
mMailbox
msgidMessage ID to find
Return values
0Success
-1Failure

Definition at line 2283 of file nntp.c.

2284{
2285 if (!m)
2286 return -1;
2287
2288 struct NntpMboxData *mdata = m->mdata;
2289 char buf[256] = { 0 };
2290 int rc;
2291 struct HeaderCache *hc = NULL;
2292
2293 if (!mdata || !mdata->adata)
2294 return -1;
2295 if (mdata->first_message > mdata->last_loaded)
2296 return 0;
2297
2298 /* init context */
2299 struct ChildCtx cc = { 0 };
2300 cc.mailbox = m;
2301 cc.num = 0;
2302 cc.max = 10;
2303 cc.child = MUTT_MEM_MALLOC(cc.max, anum_t);
2304
2305 /* fetch numbers of child messages */
2306 snprintf(buf, sizeof(buf), "XPAT References " ANUM_FMT "-" ANUM_FMT " *%s*\r\n",
2307 mdata->first_message, mdata->last_loaded, msgid);
2308 rc = nntp_fetch_lines(mdata, buf, sizeof(buf), NULL, fetch_children, &cc);
2309 if (rc)
2310 {
2311 FREE(&cc.child);
2312 if (rc > 0)
2313 {
2314 if (!mutt_str_startswith(buf, "500"))
2315 {
2316 mutt_error("XPAT: %s", buf);
2317 }
2318 else
2319 {
2320 mutt_error(_("Unable to find child articles because server does not support XPAT command"));
2321 }
2322 }
2323 return -1;
2324 }
2325
2326 /* fetch all found messages */
2327 bool verbose = m->verbose;
2328 m->verbose = false;
2329#ifdef USE_HCACHE
2330 hc = nntp_hcache_open(mdata);
2331#endif
2332 int old_msg_count = m->msg_count;
2333 for (int i = 0; i < cc.num; i++)
2334 {
2335 rc = nntp_fetch_headers(m, hc, cc.child[i], cc.child[i], true);
2336 if (rc < 0)
2337 break;
2338 }
2339 if (m->msg_count > old_msg_count)
2341
2342#ifdef USE_HCACHE
2343 hcache_close(&hc);
2344#endif
2345 m->verbose = verbose;
2346 FREE(&cc.child);
2347 return (rc < 0) ? -1 : 0;
2348}
#define MUTT_MEM_MALLOC(n, type)
Definition memory.h:53
static int fetch_children(char *line, void *data)
Parse XPAT line.
Definition nntp.c:1733
static int nntp_fetch_headers(struct Mailbox *m, void *hc, anum_t first, anum_t last, bool restore)
Fetch headers.
Definition nntp.c:1201
Keep track of the children of an article.
Definition nntp.c:104
anum_t * child
Array of child article numbers.
Definition nntp.c:108
struct Mailbox * mailbox
Mailbox.
Definition nntp.c:105
unsigned int max
Maximum number of children.
Definition nntp.c:107
unsigned int num
Number of children.
Definition nntp.c:106
bool verbose
Display status messages?
Definition mailbox.h:116
anum_t last_loaded
Last loaded article.
Definition mdata.h:39
anum_t first_message
First article number.
Definition mdata.h:37
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ nntp_newsrc_parse()

int nntp_newsrc_parse ( struct NntpAccountData * adata)

Parse .newsrc file.

Parameters
adataNNTP server
Return values
0Not changed
1Parsed
-1Error

Definition at line 163 of file newsrc.c.

164{
165 if (!adata)
166 return -1;
167
168 char *line = NULL;
169 struct stat st = { 0 };
170
171 if (adata->fp_newsrc)
172 {
173 /* if we already have a handle, close it and reopen */
175 }
176 else
177 {
178 /* if file doesn't exist, create it */
179 adata->fp_newsrc = mutt_file_fopen(adata->newsrc_file, "a");
181 }
182
183 /* open .newsrc */
184 adata->fp_newsrc = mutt_file_fopen(adata->newsrc_file, "r");
185 if (!adata->fp_newsrc)
186 {
187 mutt_perror("%s", adata->newsrc_file);
188 return -1;
189 }
190
191 /* lock it */
192 mutt_debug(LL_DEBUG1, "Locking %s\n", adata->newsrc_file);
193 if (mutt_file_lock(fileno(adata->fp_newsrc), false, true))
194 {
196 return -1;
197 }
198
199 if (stat(adata->newsrc_file, &st) != 0)
200 {
201 mutt_perror("%s", adata->newsrc_file);
202 nntp_newsrc_close(adata);
203 return -1;
204 }
205
206 if ((adata->size == st.st_size) && (adata->mtime == st.st_mtime))
207 return 0;
208
209 adata->size = st.st_size;
210 adata->mtime = st.st_mtime;
211 adata->newsrc_modified = true;
212 mutt_debug(LL_DEBUG1, "Parsing %s\n", adata->newsrc_file);
213
214 /* .newsrc has been externally modified or hasn't been loaded yet */
215 for (unsigned int i = 0; i < adata->groups_num; i++)
216 {
217 struct NntpMboxData *mdata = adata->groups_list[i];
218 if (!mdata)
219 continue;
220
221 mdata->subscribed = false;
222 mdata->newsrc_len = 0;
223 FREE(&mdata->newsrc_ent);
224 }
225
226 line = MUTT_MEM_MALLOC(st.st_size + 1, char);
227 while (st.st_size && fgets(line, st.st_size + 1, adata->fp_newsrc))
228 {
229 char *b = NULL, *h = NULL;
230 unsigned int j = 1;
231 bool subs = false;
232
233 /* find end of newsgroup name */
234 char *p = strpbrk(line, ":!");
235 if (!p)
236 continue;
237
238 /* ":" - subscribed, "!" - unsubscribed */
239 if (*p == ':')
240 subs = true;
241 *p++ = '\0';
242
243 /* get newsgroup data */
244 struct NntpMboxData *mdata = mdata_find(adata, line);
245 FREE(&mdata->newsrc_ent);
246
247 /* count number of entries */
248 b = p;
249 while (*b)
250 if (*b++ == ',')
251 j++;
252 mdata->newsrc_ent = MUTT_MEM_CALLOC(j, struct NewsrcEntry);
253 mdata->subscribed = subs;
254
255 /* parse entries */
256 j = 0;
257 while (p)
258 {
259 b = p;
260
261 /* find end of entry */
262 p = strchr(p, ',');
263 if (p)
264 *p++ = '\0';
265
266 /* first-last or single number */
267 h = strchr(b, '-');
268 if (h)
269 *h++ = '\0';
270 else
271 h = b;
272
273 if ((sscanf(b, ANUM_FMT, &mdata->newsrc_ent[j].first) == 1) &&
274 (sscanf(h, ANUM_FMT, &mdata->newsrc_ent[j].last) == 1))
275 {
276 j++;
277 }
278 }
279 if (j == 0)
280 {
281 mdata->newsrc_ent[j].first = 1;
282 mdata->newsrc_ent[j].last = 0;
283 j++;
284 }
285 if (mdata->last_message == 0)
286 mdata->last_message = mdata->newsrc_ent[j - 1].last;
287 mdata->newsrc_len = j;
288 MUTT_MEM_REALLOC(&mdata->newsrc_ent, j, struct NewsrcEntry);
290 mutt_debug(LL_DEBUG2, "%s\n", mdata->group);
291 }
292 FREE(&line);
293 return 1;
294}
int mutt_file_lock(int fd, bool excl, bool timeout)
(Try to) Lock a file using fcntl()
Definition file.c:1092
void nntp_group_unread_stat(struct NntpMboxData *mdata)
Count number of unread articles using .newsrc data.
Definition newsrc.c:133
bool newsrc_modified
Newsrc file was modified.
Definition adata.h:49
FILE * fp_newsrc
Newsrc file handle.
Definition adata.h:50
bool subscribed
Subscribed to this newsgroup.
Definition mdata.h:42
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ nntp_newsrc_close()

void nntp_newsrc_close ( struct NntpAccountData * adata)

Unlock and close .newsrc file.

Parameters
adataNNTP server

Definition at line 119 of file newsrc.c.

120{
121 if (!adata->fp_newsrc)
122 return;
123
124 mutt_debug(LL_DEBUG1, "Unlocking %s\n", adata->newsrc_file);
125 mutt_file_unlock(fileno(adata->fp_newsrc));
127}
int mutt_file_unlock(int fd)
Unlock a file previously locked by mutt_file_lock()
Definition file.c:1139
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ nntp_mailbox()

void nntp_mailbox ( struct Mailbox * m,
char * buf,
size_t buflen )

Get first newsgroup with new messages.

Parameters
mMailbox
bufBuffer for result
buflenLength of buffer

Definition at line 1307 of file newsrc.c.

1308{
1309 if (!m)
1310 return;
1311
1312 for (unsigned int i = 0; i < CurrentNewsSrv->groups_num; i++)
1313 {
1314 struct NntpMboxData *mdata = CurrentNewsSrv->groups_list[i];
1315
1316 if (!mdata || !mdata->subscribed || !mdata->unread)
1317 continue;
1318
1319 if ((m->type == MUTT_NNTP) &&
1320 mutt_str_equal(mdata->group, ((struct NntpMboxData *) m->mdata)->group))
1321 {
1322 unsigned int unread = 0;
1323
1324 for (unsigned int j = 0; j < m->msg_count; j++)
1325 {
1326 struct Email *e = m->emails[j];
1327 if (!e)
1328 break;
1329 if (!e->read && !e->deleted)
1330 unread++;
1331 }
1332 if (unread == 0)
1333 continue;
1334 }
1335 mutt_str_copy(buf, mdata->group, buflen);
1336 break;
1337 }
1338}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ nntp_expand_path()

void nntp_expand_path ( char * buf,
size_t buflen,
struct ConnAccount * cac )

Make fully qualified url from newsgroup name.

Parameters
bufBuffer for the result
buflenLength of buffer
cacAccount to serialise

Definition at line 555 of file newsrc.c.

556{
557 struct Url url = { 0 };
558
559 account_to_url(cac, &url);
560 url.path = mutt_str_dup(buf);
561 url_tostring(&url, buf, buflen, U_NO_FLAGS);
562 FREE(&url.path);
563}
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition string.c:257
void account_to_url(struct ConnAccount *cac, struct Url *url)
Fill URL with info from account.
int url_tostring(const struct Url *url, char *dest, size_t len, uint8_t flags)
Output the URL string for a given Url object.
Definition url.c:423
#define U_NO_FLAGS
No flags are set for URL parsing.
Definition url.h:49
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ nntp_clear_cache()

void nntp_clear_cache ( struct NntpAccountData * adata)

Clear the NNTP cache.

Parameters
adataNNTP server

Remove hcache and bcache of all unexistent and unsubscribed newsgroups

Definition at line 840 of file newsrc.c.

841{
842 if (!adata || !adata->cacheable)
843 return;
844
845 struct dirent *de = NULL;
846 DIR *dir = NULL;
847 struct Buffer *cache = buf_pool_get();
848 struct Buffer *file = buf_pool_get();
849
850 cache_expand(cache->data, cache->dsize, &adata->conn->account, NULL);
852 if (!dir)
853 goto done;
854
855 buf_addch(cache, '/');
856 const bool c_save_unsubscribed = cs_subset_bool(NeoMutt->sub, "save_unsubscribed");
857
858 while ((de = readdir(dir)))
859 {
860 char *group = de->d_name;
861 if (mutt_str_equal(group, ".") || mutt_str_equal(group, ".."))
862 continue;
863
864 buf_printf(file, "%s%s", buf_string(cache), group);
865 struct stat st = { 0 };
866 if (stat(buf_string(file), &st) != 0)
867 continue;
868
869#ifdef USE_HCACHE
870 if (S_ISREG(st.st_mode))
871 {
872 char *ext = group + strlen(group) - 7;
873 if ((strlen(group) < 8) || !mutt_str_equal(ext, ".hcache"))
874 continue;
875 *ext = '\0';
876 }
877 else
878#endif
879 if (!S_ISDIR(st.st_mode))
880 continue;
881
882 struct NntpMboxData tmp_mdata = { 0 };
884 if (!mdata)
885 {
886 mdata = &tmp_mdata;
887 mdata->adata = adata;
888 mdata->group = group;
889 mdata->bcache = NULL;
890 }
891 else if (mdata->newsrc_ent || mdata->subscribed || c_save_unsubscribed)
892 {
893 continue;
894 }
895
897 if (S_ISDIR(st.st_mode))
898 {
899 rmdir(buf_string(file));
900 mutt_debug(LL_DEBUG2, "%s\n", buf_string(file));
901 }
902 }
903 closedir(dir);
904
905done:
906 buf_pool_release(&cache);
907 buf_pool_release(&file);
908}
int buf_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition buffer.c:161
size_t buf_addch(struct Buffer *buf, char c)
Add a single character to a Buffer.
Definition buffer.c:241
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition buffer.h:96
char * data
Pointer to data.
Definition buffer.h:37
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ nntp_complete()

int nntp_complete ( struct Buffer * buf)

Auto-complete NNTP newsgroups.

Parameters
bufBuffer containing pathname
Return values
0Match found
-1No matches

XXX rules

Definition at line 46 of file complete.c.

47{
49 size_t n = 0;
50 struct Buffer *filepart = buf_new(buf_string(buf));
51 bool init = false;
52
53 /* special case to handle when there is no filepart yet
54 * find the first subscribed newsgroup */
55 int len = buf_len(filepart);
56 if (len == 0)
57 {
58 for (; n < adata->groups_num; n++)
59 {
60 struct NntpMboxData *mdata = adata->groups_list[n];
61
62 if (mdata && mdata->subscribed)
63 {
64 buf_strcpy(filepart, mdata->group);
65 init = true;
66 n++;
67 break;
68 }
69 }
70 }
71
72 for (; n < adata->groups_num; n++)
73 {
74 struct NntpMboxData *mdata = adata->groups_list[n];
75
76 if (mdata && mdata->subscribed &&
77 mutt_strn_equal(mdata->group, buf_string(filepart), len))
78 {
79 if (init)
80 {
81 char *str = filepart->data;
82 size_t i;
83 for (i = 0; (str[i] != '\0') && mdata->group[i]; i++)
84 {
85 if (str[i] != mdata->group[i])
86 break;
87 }
88 str[i] = '\0';
89 buf_fix_dptr(filepart);
90 }
91 else
92 {
93 buf_strcpy(filepart, mdata->group);
94 init = true;
95 }
96 }
97 }
98
99 buf_copy(buf, filepart);
100 buf_free(&filepart);
101 return init ? 0 : -1;
102}
size_t buf_len(const struct Buffer *buf)
Calculate the length of a Buffer.
Definition buffer.c:491
void buf_fix_dptr(struct Buffer *buf)
Move the dptr to end of the Buffer.
Definition buffer.c:182
void buf_free(struct Buffer **ptr)
Deallocates a buffer.
Definition buffer.c:319
struct Buffer * buf_new(const char *str)
Allocate a new Buffer.
Definition buffer.c:304
size_t buf_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition buffer.c:395
size_t buf_copy(struct Buffer *dst, const struct Buffer *src)
Copy a Buffer's contents to another Buffer.
Definition buffer.c:601
bool mutt_strn_equal(const char *a, const char *b, size_t num)
Check for equality of two strings (to a maximum), safely.
Definition string.c:429
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ CurrentNewsSrv

struct NntpAccountData* CurrentNewsSrv
extern

Current NNTP news server.

Current NNTP news server.

Definition at line 74 of file nntp.c.

◆ NntpRenderCallbacks

const struct ExpandoRenderCallback NntpRenderCallbacks[]
extern

Callbacks for Newsrc Expandos.

See also
NntpFormatDef, ExpandoDataNntp

Definition at line 161 of file expando_newsrc.c.

161 {
162 // clang-format off
164 { ED_NNTP, ED_NTP_PORT, NULL, nntp_port },
169 { -1, -1, NULL, NULL },
170 // clang-format on
171};
@ ED_NTP_SCHEMA
ConnAccount.account.
Definition connaccount.h:85
@ ED_NTP_USERNAME
ConnAccount.user.
Definition connaccount.h:87
@ ED_NTP_PORT_IF
ConnAccount.port.
Definition connaccount.h:84
@ ED_NTP_SERVER
ConnAccount.account.
Definition connaccount.h:86
@ ED_NTP_ACCOUNT
ConnAccount.account.
Definition connaccount.h:82
@ ED_NTP_PORT
ConnAccount.port.
Definition connaccount.h:83
@ ED_NNTP
Nntp ED_NTP_ ExpandoDataNntp.
Definition domain.h:50
static long nntp_port(const struct ExpandoNode *node, void *data, MuttFormatFlags flags)
Newsrc: Port - Implements get_number_t -.
static long nntp_port_if_num(const struct ExpandoNode *node, void *data, MuttFormatFlags flags)
Newsrc: Port if specified - Implements get_number_t -.
static void nntp_account(const struct ExpandoNode *node, void *data, MuttFormatFlags flags, struct Buffer *buf)
Newsrc: Account url - Implements get_string_t -.
static void nntp_port_if(const struct ExpandoNode *node, void *data, MuttFormatFlags flags, struct Buffer *buf)
Newsrc: Port if specified - Implements get_string_t -.
static void nntp_username(const struct ExpandoNode *node, void *data, MuttFormatFlags flags, struct Buffer *buf)
Newsrc: Username - Implements get_string_t -.
static void nntp_server(const struct ExpandoNode *node, void *data, MuttFormatFlags flags, struct Buffer *buf)
Newsrc: News server name - Implements get_string_t -.
static void nntp_schema(const struct ExpandoNode *node, void *data, MuttFormatFlags flags, struct Buffer *buf)
Newsrc: Url schema - Implements get_string_t -.