NeoMutt  2025-12-11-872-g385a04
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 "module_data.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

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

954{
955 char file[PATH_MAX] = { 0 };
956 int rc;
957 struct ConnAccount cac = { { 0 } };
958 struct NntpAccountData *adata = NULL;
959 struct Connection *conn = NULL;
960
961 if (!server || (*server == '\0'))
962 {
963 mutt_error(_("No news server defined"));
964 return NULL;
965 }
966
967 /* create account from news server url */
968 cac.flags = 0;
969 cac.port = NNTP_PORT;
971 cac.service = "nntp";
973
974 snprintf(file, sizeof(file), "%s%s", strstr(server, "://") ? "" : "news://", server);
975 struct Url *url = url_parse(file);
976 if (!url || (url->path && *url->path) ||
977 !((url->scheme == U_NNTP) || (url->scheme == U_NNTPS)) || !url->host ||
978 (account_from_url(&cac, url) < 0))
979 {
980 url_free(&url);
981 mutt_error(_("%s is an invalid news server specification"), server);
982 return NULL;
983 }
984 if (url->scheme == U_NNTPS)
985 {
986 cac.flags |= MUTT_ACCT_SSL;
987 cac.port = NNTP_SSL_PORT;
988 }
989 url_free(&url);
990
991 // If nntp_user and nntp_pass are specified in the config, use them to find the connection
992 const char *user = NULL;
993 const char *pass = NULL;
994 if ((user = cac.get_field(MUTT_CA_USER, NULL)))
995 {
996 mutt_str_copy(cac.user, user, sizeof(cac.user));
997 cac.flags |= MUTT_ACCT_USER;
998 }
999 if ((pass = cac.get_field(MUTT_CA_PASS, NULL)))
1000 {
1001 mutt_str_copy(cac.pass, pass, sizeof(cac.pass));
1002 cac.flags |= MUTT_ACCT_PASS;
1003 }
1004
1005 /* find connection by account */
1006 conn = mutt_conn_find(&cac);
1007 if (!conn)
1008 return NULL;
1009 if (!(conn->account.flags & MUTT_ACCT_USER) && cac.flags & MUTT_ACCT_USER)
1010 {
1011 conn->account.flags |= MUTT_ACCT_USER;
1012 conn->account.user[0] = '\0';
1013 }
1014
1015 /* new news server */
1016 adata = nntp_adata_new(conn);
1017
1018 rc = nntp_open_connection(adata);
1019
1020 /* try to create cache directory and enable caching */
1021 adata->cacheable = false;
1022 const char *const c_news_cache_dir = cs_subset_path(NeoMutt->sub, "news_cache_dir");
1023 if ((rc >= 0) && c_news_cache_dir)
1024 {
1025 cache_expand(file, sizeof(file), &conn->account, NULL);
1026 if (mutt_file_mkdir(file, S_IRWXU) < 0)
1027 {
1028 mutt_error(_("Can't create %s: %s"), file, strerror(errno));
1029 }
1030 adata->cacheable = true;
1031 }
1032
1033 /* load .newsrc */
1034 if (rc >= 0)
1035 {
1036 const struct Expando *c_newsrc = cs_subset_expando(NeoMutt->sub, "newsrc");
1037 struct Buffer *buf = buf_pool_get();
1039 buf->dsize, NeoMutt->env, buf);
1040 expand_path(buf, false);
1041 adata->newsrc_file = buf_strdup(buf);
1042 buf_pool_release(&buf);
1043 rc = nntp_newsrc_parse(adata);
1044 }
1045 if (rc >= 0)
1046 {
1047 /* try to load list of newsgroups from cache */
1048 if (adata->cacheable && (active_get_cache(adata) == 0))
1049 {
1050 rc = nntp_check_new_groups(m, adata);
1051 }
1052 else
1053 {
1054 /* load list of newsgroups from server */
1055 rc = nntp_active_fetch(adata, false);
1056 }
1057 }
1058
1059 if (rc >= 0)
1060 nntp_clear_cache(adata);
1061
1062#ifdef USE_HCACHE
1063 /* check cache files */
1064 if ((rc >= 0) && adata->cacheable)
1065 {
1066 struct dirent *de = NULL;
1067 DIR *dir = mutt_file_opendir(file, MUTT_OPENDIR_NONE);
1068
1069 if (dir)
1070 {
1071 while ((de = readdir(dir)))
1072 {
1073 struct HeaderCache *hc = NULL;
1074 char *group = de->d_name;
1075
1076 char *p = group + strlen(group) - 7;
1077 if ((strlen(group) < 8) || !mutt_str_equal(p, ".hcache"))
1078 continue;
1079 *p = '\0';
1081 if (!mdata)
1082 continue;
1083
1084 hc = nntp_hcache_open(mdata);
1085 if (!hc)
1086 continue;
1087
1088 /* fetch previous values of first and last */
1089 char *hdata = hcache_fetch_raw_str(hc, "index", 5);
1090 if (hdata)
1091 {
1092 anum_t first = 0, last = 0;
1093
1094 if (sscanf(hdata, ANUM_FMT " " ANUM_FMT, &first, &last) == 2)
1095 {
1096 if (mdata->deleted)
1097 {
1098 mdata->first_message = first;
1099 mdata->last_message = last;
1100 }
1101 if ((last >= mdata->first_message) && (last <= mdata->last_message))
1102 {
1103 mdata->last_cached = last;
1104 mutt_debug(LL_DEBUG2, "%s last_cached=" ANUM_FMT "\n", mdata->group, last);
1105 }
1106 }
1107 FREE(&hdata);
1108 }
1109 hcache_close(&hc);
1110 }
1111 closedir(dir);
1112 }
1113 }
1114#endif
1115
1116 if ((rc < 0) || !leave_lock)
1118
1119 if (rc < 0)
1120 {
1125 FREE(&adata);
1126 mutt_socket_close(conn);
1127 FREE(&conn);
1128 return NULL;
1129 }
1130
1131 return adata;
1132}
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
@ MUTT_ACCT_SSL
Account uses SSL/TLS.
Definition connaccount.h:51
@ MUTT_ACCT_PASS
Password field has been set.
Definition connaccount.h:50
@ MUTT_ACCT_USER
User field has been set.
Definition connaccount.h:48
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:139
const struct ExpandoRenderCallback NntpRenderCallbacks[]
Callbacks for Newsrc Expandos.
int mutt_file_mkdir(const char *path, mode_t mode)
Recursively create directories.
Definition file.c:844
DIR * mutt_file_opendir(const char *path, enum MuttOpenDirMode mode)
Open a directory.
Definition file.c:535
@ MUTT_OPENDIR_NONE
Plain opendir()
Definition file.h:68
static const char * nntp_get_field(enum ConnAccountField field, void *gf_data)
Get connection login credentials - Implements ConnAccount::get_field() -.
Definition newsrc.c:922
#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:549
char * hcache_fetch_raw_str(struct HeaderCache *hc, const char *key, size_t keylen)
Fetch a string from the cache.
Definition hcache.c:662
@ 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:665
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:586
#define PATH_MAX
Definition mutt.h:49
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:122
struct HeaderCache * nntp_hcache_open(struct NntpMboxData *mdata)
Open newsgroup hcache.
Definition newsrc.c:709
void nntp_clear_cache(struct NntpAccountData *adata)
Clear the NNTP cache.
Definition newsrc.c:848
int nntp_newsrc_parse(struct NntpAccountData *adata)
Parse .newsrc file.
Definition newsrc.c:165
void nntp_newsrc_close(struct NntpAccountData *adata)
Unlock and close .newsrc file.
Definition newsrc.c:121
static int active_get_cache(struct NntpAccountData *adata)
Load list of all newsgroups from cache.
Definition newsrc.c:614
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
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:2037
#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:2105
int nntp_open_connection(struct NntpAccountData *adata)
Connect to server, authenticate and get capabilities.
Definition nntp.c:1765
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
@ MUTT_FORMAT_NONE
No flags are set.
Definition render.h:37
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:59
char user[128]
Username.
Definition connaccount.h:62
char pass[256]
Password.
Definition connaccount.h:63
const char * service
Name of the service, e.g. "imap".
Definition connaccount.h:67
const char *(* get_field)(enum ConnAccountField field, void *gf_data)
Definition connaccount.h:76
unsigned char type
Connection type, e.g. MUTT_ACCT_TYPE_IMAP.
Definition connaccount.h:65
MuttAccountFlags flags
Which fields are initialised, e.g. MUTT_ACCT_USER.
Definition connaccount.h:66
unsigned short port
Port to connect to.
Definition connaccount.h:64
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:134
Container for Accounts, Notifications.
Definition neomutt.h:41
char ** env
Private copy of the environment variables.
Definition neomutt.h:57
struct ConfigSubset * sub
Inherited config items.
Definition neomutt.h:49
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:242
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 1183 of file newsrc.c.

1184{
1185 if (!adata || !adata->groups_hash || !group || (*group == '\0'))
1186 return NULL;
1187
1189 mdata->subscribed = true;
1190 if (!mdata->newsrc_ent)
1191 {
1192 mdata->newsrc_ent = MUTT_MEM_CALLOC(1, struct NewsrcEntry);
1193 mdata->newsrc_len = 1;
1194 mdata->newsrc_ent[0].first = 1;
1195 mdata->newsrc_ent[0].last = 0;
1196 }
1197 return mdata;
1198}
#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:75
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 1207 of file newsrc.c.

1208{
1209 if (!adata || !adata->groups_hash || !group || (*group == '\0'))
1210 return NULL;
1211
1213 if (!mdata)
1214 return NULL;
1215
1216 mdata->subscribed = false;
1217 const bool c_save_unsubscribed = cs_subset_bool(NeoMutt->sub, "save_unsubscribed");
1218 if (!c_save_unsubscribed)
1219 {
1220 mdata->newsrc_len = 0;
1221 FREE(&mdata->newsrc_ent);
1222 }
1223 return mdata;
1224}
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 1234 of file newsrc.c.

1236{
1237 if (!adata || !adata->groups_hash || !group || (*group == '\0'))
1238 return NULL;
1239
1241 if (!mdata)
1242 return NULL;
1243
1244 if (mdata->newsrc_ent)
1245 {
1246 MUTT_MEM_REALLOC(&mdata->newsrc_ent, 1, struct NewsrcEntry);
1247 mdata->newsrc_len = 1;
1248 mdata->newsrc_ent[0].first = 1;
1249 mdata->newsrc_ent[0].last = mdata->last_message;
1250 }
1251 mdata->unread = 0;
1252 if (m && (m->mdata == mdata))
1253 {
1254 for (unsigned int i = 0; i < m->msg_count; i++)
1255 {
1256 struct Email *e = m->emails[i];
1257 if (!e)
1258 break;
1259 mutt_set_flag(m, e, MUTT_READ, true, true);
1260 }
1261 }
1262 return mdata;
1263}
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:92
The envelope/body of an email.
Definition email.h:39
int msg_count
Total number of messages.
Definition mailbox.h:90
struct Email ** emails
Array of Emails.
Definition mailbox.h:98
+ 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 1273 of file newsrc.c.

1275{
1276 if (!adata || !adata->groups_hash || !group || (*group == '\0'))
1277 return NULL;
1278
1280 if (!mdata)
1281 return NULL;
1282
1283 if (mdata->newsrc_ent)
1284 {
1285 MUTT_MEM_REALLOC(&mdata->newsrc_ent, 1, struct NewsrcEntry);
1286 mdata->newsrc_len = 1;
1287 mdata->newsrc_ent[0].first = 1;
1288 mdata->newsrc_ent[0].last = mdata->first_message - 1;
1289 }
1290 if (m && (m->mdata == mdata))
1291 {
1292 mdata->unread = m->msg_count;
1293 for (unsigned int i = 0; i < m->msg_count; i++)
1294 {
1295 struct Email *e = m->emails[i];
1296 if (!e)
1297 break;
1298 mutt_set_flag(m, e, MUTT_READ, false, true);
1299 }
1300 }
1301 else
1302 {
1303 mdata->unread = mdata->last_message;
1304 if (mdata->newsrc_ent)
1305 mdata->unread -= mdata->newsrc_ent[0].last;
1306 }
1307 return mdata;
1308}
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 2037 of file nntp.c.

2038{
2039 struct NntpMboxData tmp_mdata = { 0 };
2040 char msg[256] = { 0 };
2041 char buf[1024] = { 0 };
2042 unsigned int i;
2043 int rc;
2044
2045 snprintf(msg, sizeof(msg), _("Loading list of groups from server %s..."),
2047 mutt_message("%s", msg);
2048 if (nntp_date(adata, &adata->newgroups_time) < 0)
2049 return -1;
2050
2051 tmp_mdata.adata = adata;
2052 tmp_mdata.group = NULL;
2053 i = adata->groups_num;
2054 mutt_str_copy(buf, "LIST\r\n", sizeof(buf));
2055 rc = nntp_fetch_lines(&tmp_mdata, buf, sizeof(buf), msg, nntp_add_group, adata);
2056 if (rc)
2057 {
2058 if (rc > 0)
2059 {
2060 mutt_error("LIST: %s", buf);
2061 }
2062 return -1;
2063 }
2064
2065 if (mark_new)
2066 {
2067 for (; i < adata->groups_num; i++)
2068 {
2069 struct NntpMboxData *mdata = adata->groups_list[i];
2070 mdata->has_new_mail = true;
2071 }
2072 }
2073
2074 for (i = 0; i < adata->groups_num; i++)
2075 {
2076 struct NntpMboxData *mdata = adata->groups_list[i];
2077
2078 if (mdata && mdata->deleted && !mdata->newsrc_ent)
2079 {
2081 mutt_hash_delete(adata->groups_hash, mdata->group, NULL);
2082 adata->groups_list[i] = NULL;
2083 }
2084 }
2085
2086 const bool c_nntp_load_description = cs_subset_bool(NeoMutt->sub, "nntp_load_description");
2087 if (c_nntp_load_description)
2088 rc = get_description(&tmp_mdata, "*", _("Loading descriptions..."));
2089
2091 if (rc < 0)
2092 return -1;
2094 return 0;
2095}
#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:810
int nntp_add_group(char *line, void *data)
Parse newsgroup.
Definition newsrc.c:573
int nntp_active_save_cache(struct NntpAccountData *adata)
Save list of all newsgroups to cache.
Definition newsrc.c:648
static int nntp_date(struct NntpAccountData *adata, time_t *now)
Get date and time from server.
Definition nntp.c:1698
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:813
static int get_description(struct NntpMboxData *mdata, const char *wildmat, const char *msg)
Fetch newsgroups descriptions.
Definition nntp.c:935
char host[128]
Server to login to.
Definition connaccount.h:60
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 444 of file newsrc.c.

445{
446 if (!adata)
447 return -1;
448
449 int rc = -1;
450
451 size_t buflen = 10240;
452 char *buf = MUTT_MEM_CALLOC(buflen, char);
453 size_t off = 0;
454
455 /* we will generate full newsrc here */
456 for (unsigned int i = 0; i < adata->groups_num; i++)
457 {
458 struct NntpMboxData *mdata = adata->groups_list[i];
459
460 if (!mdata || !mdata->newsrc_ent)
461 continue;
462
463 /* write newsgroup name */
464 if ((off + strlen(mdata->group) + 3) > buflen)
465 {
466 buflen *= 2;
467 MUTT_MEM_REALLOC(&buf, buflen, char);
468 }
469 snprintf(buf + off, buflen - off, "%s%c ", mdata->group, mdata->subscribed ? ':' : '!');
470 off += strlen(buf + off);
471
472 /* write entries */
473 for (unsigned int j = 0; j < mdata->newsrc_len; j++)
474 {
475 if ((off + 1024) > buflen)
476 {
477 buflen *= 2;
478 MUTT_MEM_REALLOC(&buf, buflen, char);
479 }
480 if (j)
481 buf[off++] = ',';
482 if (mdata->newsrc_ent[j].first == mdata->newsrc_ent[j].last)
483 {
484 snprintf(buf + off, buflen - off, ANUM_FMT, mdata->newsrc_ent[j].first);
485 }
486 else if (mdata->newsrc_ent[j].first < mdata->newsrc_ent[j].last)
487 {
488 snprintf(buf + off, buflen - off, ANUM_FMT "-" ANUM_FMT,
489 mdata->newsrc_ent[j].first, mdata->newsrc_ent[j].last);
490 }
491 off += strlen(buf + off);
492 }
493 buf[off++] = '\n';
494 }
495 buf[off] = '\0';
496
497 /* newrc being fully rewritten */
498 mutt_debug(LL_DEBUG1, "Updating %s\n", adata->newsrc_file);
499 if (adata->newsrc_file && (update_file(adata->newsrc_file, buf) == 0))
500 {
501 struct stat st = { 0 };
502
503 rc = stat(adata->newsrc_file, &st);
504 if (rc == 0)
505 {
506 adata->size = st.st_size;
507 adata->mtime = st.st_mtime;
508 }
509 else
510 {
511 mutt_perror("%s", adata->newsrc_file);
512 }
513 }
514 FREE(&buf);
515 return rc;
516}
#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:394
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 1945 of file nntp.c.

1946{
1948 struct NntpMboxData *mdata = NULL;
1949 struct NntpMboxData tmp_mdata = { 0 };
1950 char buf[1024] = { 0 };
1951 int rc = -1;
1952
1953 if (m && (m->type == MUTT_NNTP))
1954 {
1955 mdata = m->mdata;
1956 }
1957 else
1958 {
1959 const char *const c_news_server = cs_subset_string(NeoMutt->sub, "news_server");
1960 mod_data->current_news_srv = nntp_select_server(m, c_news_server, false);
1961 if (!mod_data->current_news_srv)
1962 goto done;
1963
1964 mdata = &tmp_mdata;
1965 mdata->adata = mod_data->current_news_srv;
1966 mdata->group = NULL;
1967 }
1968
1969 FILE *fp = mutt_file_fopen(msg, "r");
1970 if (!fp)
1971 {
1972 mutt_perror("%s", msg);
1973 goto done;
1974 }
1975
1976 mutt_str_copy(buf, "POST\r\n", sizeof(buf));
1977 if (nntp_query(mdata, buf, sizeof(buf)) < 0)
1978 {
1979 mutt_file_fclose(&fp);
1980 goto done;
1981 }
1982 if (buf[0] != '3')
1983 {
1984 mutt_error(_("Can't post article: %s"), buf);
1985 mutt_file_fclose(&fp);
1986 goto done;
1987 }
1988
1989 buf[0] = '.';
1990 buf[1] = '\0';
1991 while (fgets(buf + 1, sizeof(buf) - 2, fp))
1992 {
1993 size_t len = strlen(buf);
1994 if (buf[len - 1] == '\n')
1995 {
1996 buf[len - 1] = '\r';
1997 buf[len] = '\n';
1998 len++;
1999 buf[len] = '\0';
2000 }
2001 if (mutt_socket_send_d(mdata->adata->conn, (buf[1] == '.') ? buf : buf + 1,
2002 MUTT_SOCK_LOG_FULL) < 0)
2003 {
2004 mutt_file_fclose(&fp);
2005 nntp_connect_error(mdata->adata);
2006 goto done;
2007 }
2008 }
2009 mutt_file_fclose(&fp);
2010
2011 if (((buf[strlen(buf) - 1] != '\n') &&
2012 (mutt_socket_send_d(mdata->adata->conn, "\r\n", MUTT_SOCK_LOG_FULL) < 0)) ||
2013 (mutt_socket_send_d(mdata->adata->conn, ".\r\n", MUTT_SOCK_LOG_FULL) < 0) ||
2014 (mutt_socket_readln(buf, sizeof(buf), mdata->adata->conn) < 0))
2015 {
2016 nntp_connect_error(mdata->adata);
2017 goto done;
2018 }
2019 if (buf[0] != '2')
2020 {
2021 mutt_error(_("Can't post article: %s"), buf);
2022 goto done;
2023 }
2024 rc = 0;
2025
2026done:
2027 return rc;
2028}
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:144
#define mutt_file_fopen(PATH, MODE)
Definition file.h:143
@ MODULE_ID_NNTP
ModuleNntp, Nntp
Definition module_api.h:81
void * neomutt_get_module_data(struct NeoMutt *n, enum ModuleId id)
Get the private data for a Module.
Definition neomutt.c:663
struct NntpAccountData * nntp_select_server(struct Mailbox *m, const char *server, bool leave_lock)
Open a connection to an NNTP server.
Definition newsrc.c:953
static int nntp_connect_error(struct NntpAccountData *adata)
Signal a failed connection.
Definition nntp.c:122
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:729
#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:104
Nntp private Module data.
Definition module_data.h:30
struct NntpAccountData * current_news_srv
Current NNTP news server.
Definition module_data.h:32
+ 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 2215 of file nntp.c.

2216{
2217 if (!m)
2218 return -1;
2219
2220 struct NntpMboxData *mdata = m->mdata;
2221 char buf[1024] = { 0 };
2222
2223 FILE *fp = mutt_file_mkstemp();
2224 if (!fp)
2225 {
2226 mutt_perror(_("Can't create temporary file"));
2227 return -1;
2228 }
2229
2230 snprintf(buf, sizeof(buf), "HEAD %s\r\n", msgid);
2231 int rc = nntp_fetch_lines(mdata, buf, sizeof(buf), NULL, fetch_tempfile, fp);
2232 if (rc)
2233 {
2234 mutt_file_fclose(&fp);
2235 if (rc < 0)
2236 return -1;
2237 if (mutt_str_startswith(buf, "430"))
2238 return 1;
2239 mutt_error("HEAD: %s", buf);
2240 return -1;
2241 }
2242
2243 /* parse header */
2245 m->emails[m->msg_count] = email_new();
2246 struct Email *e = m->emails[m->msg_count];
2247 e->edata = nntp_edata_new();
2249 e->env = mutt_rfc822_read_header(fp, e, false, false);
2250 mutt_file_fclose(&fp);
2251
2252 /* get article number */
2253 if (e->env->xref)
2254 {
2255 nntp_parse_xref(m, e);
2256 }
2257 else
2258 {
2259 snprintf(buf, sizeof(buf), "STAT %s\r\n", msgid);
2260 if (nntp_query(mdata, buf, sizeof(buf)) < 0)
2261 {
2262 email_free(&e);
2263 return -1;
2264 }
2265 sscanf(buf + 4, ANUM_FMT, &nntp_edata_get(e)->article_num);
2266 }
2267
2268 /* reset flags */
2269 e->read = false;
2270 e->old = false;
2271 e->deleted = false;
2272 e->changed = true;
2273 e->received = e->date_sent;
2274 e->index = m->msg_count++;
2276 return 0;
2277}
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:182
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:1175
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:1008
static void nntp_parse_xref(struct Mailbox *m, struct Email *e)
Parse cross-reference.
Definition nntp.c:967
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 2286 of file nntp.c.

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

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

122{
123 if (!adata->fp_newsrc)
124 return;
125
126 mutt_debug(LL_DEBUG1, "Unlocking %s\n", adata->newsrc_file);
127 mutt_file_unlock(fileno(adata->fp_newsrc));
129}
int mutt_file_unlock(int fd)
Unlock a file previously locked by mutt_file_lock()
Definition file.c:1135
+ 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 1316 of file newsrc.c.

1317{
1318 if (!m)
1319 return;
1320
1322 for (unsigned int i = 0; i < mod_data->current_news_srv->groups_num; i++)
1323 {
1324 struct NntpMboxData *mdata = mod_data->current_news_srv->groups_list[i];
1325
1326 if (!mdata || !mdata->subscribed || !mdata->unread)
1327 continue;
1328
1329 if ((m->type == MUTT_NNTP) &&
1330 mutt_str_equal(mdata->group, ((struct NntpMboxData *) m->mdata)->group))
1331 {
1332 unsigned int unread = 0;
1333
1334 for (unsigned int j = 0; j < m->msg_count; j++)
1335 {
1336 struct Email *e = m->emails[j];
1337 if (!e)
1338 break;
1339 if (!e->read && !e->deleted)
1340 unread++;
1341 }
1342 if (unread == 0)
1343 continue;
1344 }
1345 mutt_str_copy(buf, mdata->group, buflen);
1346 break;
1347 }
1348}
+ 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 557 of file newsrc.c.

558{
559 struct Url url = { 0 };
560
561 account_to_url(cac, &url);
562 url.path = mutt_str_dup(buf);
563 url_tostring(&url, buf, buflen, U_NONE);
564 FREE(&url.path);
565}
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:426
#define U_NONE
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 848 of file newsrc.c.

849{
850 if (!adata || !adata->cacheable)
851 return;
852
853 struct dirent *de = NULL;
854 DIR *dir = NULL;
855 struct Buffer *cache = buf_pool_get();
856 struct Buffer *file = buf_pool_get();
857
858 cache_expand(cache->data, cache->dsize, &adata->conn->account, NULL);
859 buf_fix_dptr(cache);
861 if (!dir)
862 goto done;
863
864 buf_addch(cache, '/');
865 const bool c_save_unsubscribed = cs_subset_bool(NeoMutt->sub, "save_unsubscribed");
866
867 while ((de = readdir(dir)))
868 {
869 char *group = de->d_name;
870 if (mutt_str_equal(group, ".") || mutt_str_equal(group, ".."))
871 continue;
872
873 buf_printf(file, "%s%s", buf_string(cache), group);
874 struct stat st = { 0 };
875 if (stat(buf_string(file), &st) != 0)
876 continue;
877
878#ifdef USE_HCACHE
879 if (S_ISREG(st.st_mode))
880 {
881 char *ext = group + strlen(group) - 7;
882 if ((strlen(group) < 8) || !mutt_str_equal(ext, ".hcache"))
883 continue;
884 *ext = '\0';
885 }
886 else
887#endif
888 if (!S_ISDIR(st.st_mode))
889 continue;
890
891 struct NntpMboxData tmp_mdata = { 0 };
893 if (!mdata)
894 {
895 mdata = &tmp_mdata;
896 mdata->adata = adata;
897 mdata->group = group;
898 mdata->bcache = NULL;
899 }
900 else if (mdata->newsrc_ent || mdata->subscribed || c_save_unsubscribed)
901 {
902 continue;
903 }
904
906 if (S_ISDIR(st.st_mode))
907 {
908 rmdir(buf_string(file));
909 mutt_debug(LL_DEBUG2, "%s\n", buf_string(file));
910 }
911 }
912 closedir(dir);
913
914done:
915 buf_pool_release(&cache);
916 buf_pool_release(&file);
917}
int buf_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition buffer.c:161
void buf_fix_dptr(struct Buffer *buf)
Move the dptr to end of the Buffer.
Definition buffer.c:182
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 48 of file complete.c.

49{
51 struct NntpAccountData *adata = mod_data->current_news_srv;
52 size_t n = 0;
53 struct Buffer *filepart = buf_new(buf_string(buf));
54 bool init = false;
55
56 /* special case to handle when there is no filepart yet
57 * find the first subscribed newsgroup */
58 int len = buf_len(filepart);
59 if (len == 0)
60 {
61 for (; n < adata->groups_num; n++)
62 {
63 struct NntpMboxData *mdata = adata->groups_list[n];
64
65 if (mdata && mdata->subscribed)
66 {
67 buf_strcpy(filepart, mdata->group);
68 init = true;
69 n++;
70 break;
71 }
72 }
73 }
74
75 for (; n < adata->groups_num; n++)
76 {
77 struct NntpMboxData *mdata = adata->groups_list[n];
78
79 if (mdata && mdata->subscribed &&
80 mutt_strn_equal(mdata->group, buf_string(filepart), len))
81 {
82 if (init)
83 {
84 char *str = filepart->data;
85 size_t i;
86 for (i = 0; (str[i] != '\0') && mdata->group[i]; i++)
87 {
88 if (str[i] != mdata->group[i])
89 break;
90 }
91 str[i] = '\0';
92 buf_fix_dptr(filepart);
93 }
94 else
95 {
96 buf_strcpy(filepart, mdata->group);
97 init = true;
98 }
99 }
100 }
101
102 buf_copy(buf, filepart);
103 buf_free(&filepart);
104 return init ? 0 : -1;
105}
size_t buf_len(const struct Buffer *buf)
Calculate the length of a Buffer.
Definition buffer.c:491
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

◆ NntpRenderCallbacks

const struct ExpandoRenderCallback NntpRenderCallbacks[]
extern

Callbacks for Newsrc Expandos.

See also
NntpFormatDef, ExpandoDataNntp

Definition at line 157 of file expando_newsrc.c.

157 {
158 // clang-format off
160 { ED_NNTP, ED_NTP_PORT, NULL, nntp_port },
165 { -1, -1, NULL, NULL },
166 // clang-format on
167};
@ ED_NTP_SCHEMA
ConnAccount.account.
Definition connaccount.h:91
@ ED_NTP_USERNAME
ConnAccount.user.
Definition connaccount.h:93
@ ED_NTP_PORT_IF
ConnAccount.port.
Definition connaccount.h:90
@ ED_NTP_SERVER
ConnAccount.account.
Definition connaccount.h:92
@ ED_NTP_ACCOUNT
ConnAccount.account.
Definition connaccount.h:88
@ ED_NTP_PORT
ConnAccount.port.
Definition connaccount.h:89
@ 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 -.