NeoMutt  2024-11-14-138-ge5ca67
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? - Implements MxOps::path_probe() -.
 
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 62 of file lib.h.

◆ ANUM_FMT

#define ANUM_FMT   "%ld"

Definition at line 63 of file lib.h.

◆ NNTP_ACACHE_LEN

#define NNTP_ACACHE_LEN   10

Definition at line 84 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 945 of file newsrc.c.

946{
947 char file[PATH_MAX] = { 0 };
948 int rc;
949 struct ConnAccount cac = { { 0 } };
950 struct NntpAccountData *adata = NULL;
951 struct Connection *conn = NULL;
952
953 if (!server || (*server == '\0'))
954 {
955 mutt_error(_("No news server defined"));
956 return NULL;
957 }
958
959 /* create account from news server url */
960 cac.flags = 0;
961 cac.port = NNTP_PORT;
963 cac.service = "nntp";
965
966 snprintf(file, sizeof(file), "%s%s", strstr(server, "://") ? "" : "news://", server);
967 struct Url *url = url_parse(file);
968 if (!url || (url->path && *url->path) ||
969 !((url->scheme == U_NNTP) || (url->scheme == U_NNTPS)) || !url->host ||
970 (account_from_url(&cac, url) < 0))
971 {
972 url_free(&url);
973 mutt_error(_("%s is an invalid news server specification"), server);
974 return NULL;
975 }
976 if (url->scheme == U_NNTPS)
977 {
978 cac.flags |= MUTT_ACCT_SSL;
979 cac.port = NNTP_SSL_PORT;
980 }
981 url_free(&url);
982
983 // If nntp_user and nntp_pass are specified in the config, use them to find the connection
984 const char *user = NULL;
985 const char *pass = NULL;
986 if ((user = cac.get_field(MUTT_CA_USER, NULL)))
987 {
988 mutt_str_copy(cac.user, user, sizeof(cac.user));
989 cac.flags |= MUTT_ACCT_USER;
990 }
991 if ((pass = cac.get_field(MUTT_CA_PASS, NULL)))
992 {
993 mutt_str_copy(cac.pass, pass, sizeof(cac.pass));
994 cac.flags |= MUTT_ACCT_PASS;
995 }
996
997 /* find connection by account */
998 conn = mutt_conn_find(&cac);
999 if (!conn)
1000 return NULL;
1001 if (!(conn->account.flags & MUTT_ACCT_USER) && cac.flags & MUTT_ACCT_USER)
1002 {
1003 conn->account.flags |= MUTT_ACCT_USER;
1004 conn->account.user[0] = '\0';
1005 }
1006
1007 /* new news server */
1008 adata = nntp_adata_new(conn);
1009
1010 rc = nntp_open_connection(adata);
1011
1012 /* try to create cache directory and enable caching */
1013 adata->cacheable = false;
1014 const char *const c_news_cache_dir = cs_subset_path(NeoMutt->sub, "news_cache_dir");
1015 if ((rc >= 0) && c_news_cache_dir)
1016 {
1017 cache_expand(file, sizeof(file), &conn->account, NULL);
1018 if (mutt_file_mkdir(file, S_IRWXU) < 0)
1019 {
1020 mutt_error(_("Can't create %s: %s"), file, strerror(errno));
1021 }
1022 adata->cacheable = true;
1023 }
1024
1025 /* load .newsrc */
1026 if (rc >= 0)
1027 {
1028 const struct Expando *c_newsrc = cs_subset_expando(NeoMutt->sub, "newsrc");
1029 struct Buffer *buf = buf_pool_get();
1031 buf->dsize, buf);
1032 buf_expand_path(buf);
1033 adata->newsrc_file = buf_strdup(buf);
1034 buf_pool_release(&buf);
1035 rc = nntp_newsrc_parse(adata);
1036 }
1037 if (rc >= 0)
1038 {
1039 /* try to load list of newsgroups from cache */
1040 if (adata->cacheable && (active_get_cache(adata) == 0))
1041 {
1042 rc = nntp_check_new_groups(m, adata);
1043 }
1044 else
1045 {
1046 /* load list of newsgroups from server */
1047 rc = nntp_active_fetch(adata, false);
1048 }
1049 }
1050
1051 if (rc >= 0)
1052 nntp_clear_cache(adata);
1053
1054#ifdef USE_HCACHE
1055 /* check cache files */
1056 if ((rc >= 0) && adata->cacheable)
1057 {
1058 struct dirent *de = NULL;
1059 DIR *dir = mutt_file_opendir(file, MUTT_OPENDIR_NONE);
1060
1061 if (dir)
1062 {
1063 while ((de = readdir(dir)))
1064 {
1065 struct HeaderCache *hc = NULL;
1066 char *group = de->d_name;
1067
1068 char *p = group + strlen(group) - 7;
1069 if ((strlen(group) < 8) || !mutt_str_equal(p, ".hcache"))
1070 continue;
1071 *p = '\0';
1073 if (!mdata)
1074 continue;
1075
1076 hc = nntp_hcache_open(mdata);
1077 if (!hc)
1078 continue;
1079
1080 /* fetch previous values of first and last */
1081 char *hdata = hcache_fetch_raw_str(hc, "index", 5);
1082 if (hdata)
1083 {
1084 anum_t first = 0, last = 0;
1085
1086 if (sscanf(hdata, ANUM_FMT " " ANUM_FMT, &first, &last) == 2)
1087 {
1088 if (mdata->deleted)
1089 {
1090 mdata->first_message = first;
1091 mdata->last_message = last;
1092 }
1093 if ((last >= mdata->first_message) && (last <= mdata->last_message))
1094 {
1095 mdata->last_cached = last;
1096 mutt_debug(LL_DEBUG2, "%s last_cached=" ANUM_FMT "\n", mdata->group, last);
1097 }
1098 }
1099 FREE(&hdata);
1100 }
1101 hcache_close(&hc);
1102 }
1103 closedir(dir);
1104 }
1105 }
1106#endif
1107
1108 if ((rc < 0) || !leave_lock)
1110
1111 if (rc < 0)
1112 {
1117 FREE(&adata);
1118 mutt_socket_close(conn);
1119 FREE(&conn);
1120 return NULL;
1121 }
1122
1123 return adata;
1124}
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.
Definition: config_type.c:357
@ 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, 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:974
DIR * mutt_file_opendir(const char *path, enum MuttOpenDirMode mode)
Open a directory.
Definition: file.c:642
@ 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:914
#define mutt_error(...)
Definition: logging2.h:92
#define mutt_debug(LEVEL,...)
Definition: logging2.h:89
void * mutt_hash_find(const struct HashTable *table, const char *strkey)
Find the HashElem data in a Hash Table element using a key.
Definition: hash.c:362
void mutt_hash_free(struct HashTable **ptr)
Free a hash table.
Definition: hash.c:457
void hcache_close(struct HeaderCache **ptr)
Multiplexor for StoreOps::close.
Definition: hcache.c:542
char * hcache_fetch_raw_str(struct HeaderCache *hc, const char *key, size_t keylen)
Fetch a string from the cache.
Definition: hcache.c:652
@ LL_DEBUG2
Log at debug level 2.
Definition: logging2.h:44
#define FREE(x)
Definition: memory.h:55
#define _(a)
Definition: message.h:28
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:660
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:581
#define PATH_MAX
Definition: mutt.h:42
int account_from_url(struct ConnAccount *cac, const struct Url *url)
Fill ConnAccount with information from url.
Definition: mutt_account.c:44
@ MUTT_ACCT_TYPE_NNTP
Nntp (Usenet) Account.
Definition: mutt_account.h:39
struct Connection * mutt_conn_find(const struct ConnAccount *cac)
Find a connection from a list.
Definition: mutt_socket.c:89
void buf_expand_path(struct Buffer *buf)
Create the canonical path.
Definition: muttlib.c:315
struct HeaderCache * nntp_hcache_open(struct NntpMboxData *mdata)
Open newsgroup hcache.
Definition: newsrc.c:707
void nntp_clear_cache(struct NntpAccountData *adata)
Clear the NNTP cache.
Definition: newsrc.c:841
int nntp_newsrc_parse(struct NntpAccountData *adata)
Parse .newsrc file.
Definition: newsrc.c:164
void nntp_newsrc_close(struct NntpAccountData *adata)
Unlock and close .newsrc file.
Definition: newsrc.c:120
static int active_get_cache(struct NntpAccountData *adata)
Load list of all newsgroups from cache.
Definition: newsrc.c:613
static void cache_expand(char *dst, size_t dstlen, struct ConnAccount *cac, const char *src)
Make fully qualified cache file name.
Definition: newsrc.c:524
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:63
#define anum_t
Definition: lib.h:62
#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:1766
struct Buffer * buf_pool_get(void)
Get a Buffer from the pool.
Definition: pool.c:82
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
Definition: pool.c:96
#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:86
void * mdata
Driver specific data.
Definition: mailbox.h:132
Container for Accounts, Notifications.
Definition: neomutt.h:42
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:46
NNTP-specific Account data -.
Definition: adata.h:36
struct HashTable * groups_hash
Hash Table: "newsgroup" -> NntpMboxData.
Definition: adata.h:61
struct NntpMboxData ** groups_list
Definition: adata.h:60
char * authenticators
Definition: adata.h:52
bool cacheable
Definition: adata.h:48
char * newsrc_file
Definition: adata.h:51
NNTP-specific Mailbox data -.
Definition: mdata.h:34
anum_t last_message
Definition: mdata.h:38
char * group
Name of newsgroup.
Definition: mdata.h:35
struct NntpAccountData * adata
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 1175 of file newsrc.c.

1176{
1177 if (!adata || !adata->groups_hash || !group || (*group == '\0'))
1178 return NULL;
1179
1181 mdata->subscribed = true;
1182 if (!mdata->newsrc_ent)
1183 {
1184 mdata->newsrc_ent = MUTT_MEM_CALLOC(1, struct NewsrcEntry);
1185 mdata->newsrc_len = 1;
1186 mdata->newsrc_ent[0].first = 1;
1187 mdata->newsrc_ent[0].last = 0;
1188 }
1189 return mdata;
1190}
#define MUTT_MEM_CALLOC(n, type)
Definition: memory.h:40
static struct NntpMboxData * mdata_find(struct NntpAccountData *adata, const char *group)
Find NntpMboxData for given newsgroup or add it.
Definition: newsrc.c:74
An entry in a .newsrc (subscribed newsgroups)
Definition: lib.h:78
+ 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 1199 of file newsrc.c.

1200{
1201 if (!adata || !adata->groups_hash || !group || (*group == '\0'))
1202 return NULL;
1203
1205 if (!mdata)
1206 return NULL;
1207
1208 mdata->subscribed = false;
1209 const bool c_save_unsubscribed = cs_subset_bool(NeoMutt->sub, "save_unsubscribed");
1210 if (!c_save_unsubscribed)
1211 {
1212 mdata->newsrc_len = 0;
1213 FREE(&mdata->newsrc_ent);
1214 }
1215 return mdata;
1216}
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 1226 of file newsrc.c.

1228{
1229 if (!adata || !adata->groups_hash || !group || (*group == '\0'))
1230 return NULL;
1231
1233 if (!mdata)
1234 return NULL;
1235
1236 if (mdata->newsrc_ent)
1237 {
1238 MUTT_MEM_REALLOC(&mdata->newsrc_ent, 1, struct NewsrcEntry);
1239 mdata->newsrc_len = 1;
1240 mdata->newsrc_ent[0].first = 1;
1241 mdata->newsrc_ent[0].last = mdata->last_message;
1242 }
1243 mdata->unread = 0;
1244 if (m && (m->mdata == mdata))
1245 {
1246 for (unsigned int i = 0; i < m->msg_count; i++)
1247 {
1248 struct Email *e = m->emails[i];
1249 if (!e)
1250 break;
1251 mutt_set_flag(m, e, MUTT_READ, true, true);
1252 }
1253 }
1254 return mdata;
1255}
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:57
#define MUTT_MEM_REALLOC(pptr, n, type)
Definition: memory.h:43
@ MUTT_READ
Messages that have been read.
Definition: mutt.h:73
The envelope/body of an email.
Definition: email.h:39
int msg_count
Total number of messages.
Definition: mailbox.h:88
struct Email ** emails
Array of Emails.
Definition: mailbox.h:96
+ 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 1265 of file newsrc.c.

1267{
1268 if (!adata || !adata->groups_hash || !group || (*group == '\0'))
1269 return NULL;
1270
1272 if (!mdata)
1273 return NULL;
1274
1275 if (mdata->newsrc_ent)
1276 {
1277 MUTT_MEM_REALLOC(&mdata->newsrc_ent, 1, struct NewsrcEntry);
1278 mdata->newsrc_len = 1;
1279 mdata->newsrc_ent[0].first = 1;
1280 mdata->newsrc_ent[0].last = mdata->first_message - 1;
1281 }
1282 if (m && (m->mdata == mdata))
1283 {
1284 mdata->unread = m->msg_count;
1285 for (unsigned int i = 0; i < m->msg_count; i++)
1286 {
1287 struct Email *e = m->emails[i];
1288 if (!e)
1289 break;
1290 mutt_set_flag(m, e, MUTT_READ, false, true);
1291 }
1292 }
1293 else
1294 {
1295 mdata->unread = mdata->last_message;
1296 if (mdata->newsrc_ent)
1297 mdata->unread -= mdata->newsrc_ent[0].last;
1298 }
1299 return mdata;
1300}
anum_t last
Last article number in run.
Definition: lib.h:80
struct NewsrcEntry * newsrc_ent
Definition: mdata.h:47
anum_t unread
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:91
void mutt_hash_delete(struct HashTable *table, const char *strkey, const void *data)
Remove an element from a Hash Table.
Definition: hash.c:427
void mutt_clear_error(void)
Clear the message line (bottom line of screen)
Definition: mutt_logging.c:74
void nntp_delete_group_cache(struct NntpMboxData *mdata)
Remove hcache and bcache of newsgroup.
Definition: newsrc.c:808
int nntp_add_group(char *line, void *data)
Parse newsgroup.
Definition: newsrc.c:572
int nntp_active_save_cache(struct NntpAccountData *adata)
Save list of all newsgroups to cache.
Definition: newsrc.c:647
static int nntp_date(struct NntpAccountData *adata, time_t *now)
Get date and time from server.
Definition: nntp.c:1699
static int nntp_fetch_lines(struct NntpMboxData *mdata, char *query, size_t qlen, const char *msg, int(*func)(char *, void *), void *data)
Read lines, calling a callback function for each.
Definition: nntp.c:814
static int get_description(struct NntpMboxData *mdata, const char *wildmat, const char *msg)
Fetch newsgroups descriptions.
Definition: nntp.c:936
char host[128]
Server to login to.
Definition: connaccount.h:54
time_t newgroups_time
Definition: adata.h:56
struct Connection * conn
Connection to NNTP Server.
Definition: adata.h:62
unsigned int groups_num
Definition: adata.h:58
+ 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 443 of file newsrc.c.

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

1947{
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 CurrentNewsSrv = nntp_select_server(m, c_news_server, false);
1961 if (!CurrentNewsSrv)
1962 goto done;
1963
1964 mdata = &tmp_mdata;
1965 mdata->adata = CurrentNewsSrv;
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:49
#define mutt_file_fclose(FP)
Definition: file.h:138
#define mutt_file_fopen(PATH, MODE)
Definition: file.h:137
struct NntpAccountData * nntp_select_server(struct Mailbox *m, const char *server, bool leave_lock)
Open a connection to an NNTP server.
Definition: newsrc.c:945
static int nntp_connect_error(struct NntpAccountData *adata)
Signal a failed connection.
Definition: nntp.c:127
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:730
struct NntpAccountData * CurrentNewsSrv
Current news server.
Definition: nntp.c:77
#define MUTT_SOCK_LOG_FULL
Definition: socket.h:54
#define mutt_socket_readln(buf, buflen, conn)
Definition: socket.h:56
#define mutt_socket_send_d(conn, buf, dbg)
Definition: socket.h:58
enum MailboxType type
Mailbox type.
Definition: mailbox.h:102
+ 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:233
@ NT_MAILBOX_INVALID
Email list was changed.
Definition: mailbox.h:189
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:1205
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:230
void mx_alloc_memory(struct Mailbox *m, int req_size)
Create storage for the emails.
Definition: mx.c:1206
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:1009
static void nntp_parse_xref(struct Mailbox *m, struct Email *e)
Parse cross-reference.
Definition: nntp.c:968
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:41
static int fetch_children(char *line, void *data)
Parse XPAT line.
Definition: nntp.c:1736
static int nntp_fetch_headers(struct Mailbox *m, void *hc, anum_t first, anum_t last, bool restore)
Fetch headers.
Definition: nntp.c:1204
Keep track of the children of an article.
Definition: nntp.c:107
anum_t * child
Definition: nntp.c:111
struct Mailbox * mailbox
Definition: nntp.c:108
unsigned int max
Definition: nntp.c:110
unsigned int num
Definition: nntp.c:109
bool verbose
Display status messages?
Definition: mailbox.h:117
anum_t last_loaded
Definition: mdata.h:39
anum_t first_message
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 164 of file newsrc.c.

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

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

1309{
1310 if (!m)
1311 return;
1312
1313 for (unsigned int i = 0; i < CurrentNewsSrv->groups_num; i++)
1314 {
1316
1317 if (!mdata || !mdata->subscribed || !mdata->unread)
1318 continue;
1319
1320 if ((m->type == MUTT_NNTP) &&
1321 mutt_str_equal(mdata->group, ((struct NntpMboxData *) m->mdata)->group))
1322 {
1323 unsigned int unread = 0;
1324
1325 for (unsigned int j = 0; j < m->msg_count; j++)
1326 {
1327 struct Email *e = m->emails[j];
1328 if (!e)
1329 break;
1330 if (!e->read && !e->deleted)
1331 unread++;
1332 }
1333 if (unread == 0)
1334 continue;
1335 }
1336 mutt_str_copy(buf, mdata->group, buflen);
1337 break;
1338 }
1339}
struct NntpAccountData * CurrentNewsSrv
Current NNTP news server.
Definition: nntp.c:77
+ 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 556 of file newsrc.c.

557{
558 struct Url url = { 0 };
559
560 account_to_url(cac, &url);
561 url.path = mutt_str_dup(buf);
562 url_tostring(&url, buf, buflen, U_NO_FLAGS);
563 FREE(&url.path);
564}
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:253
void account_to_url(struct ConnAccount *cac, struct Url *url)
Fill URL with info from account.
Definition: mutt_account.c:80
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
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 841 of file newsrc.c.

842{
843 if (!adata || !adata->cacheable)
844 return;
845
846 struct dirent *de = NULL;
847 DIR *dir = NULL;
848 struct Buffer *cache = buf_pool_get();
849 struct Buffer *file = buf_pool_get();
850
851 cache_expand(cache->data, cache->dsize, &adata->conn->account, NULL);
853 if (!dir)
854 goto done;
855
856 buf_addch(cache, '/');
857 const bool c_save_unsubscribed = cs_subset_bool(NeoMutt->sub, "save_unsubscribed");
858
859 while ((de = readdir(dir)))
860 {
861 char *group = de->d_name;
862 if (mutt_str_equal(group, ".") || mutt_str_equal(group, ".."))
863 continue;
864
865 buf_printf(file, "%s%s", buf_string(cache), group);
866 struct stat st = { 0 };
867 if (stat(buf_string(file), &st) != 0)
868 continue;
869
870#ifdef USE_HCACHE
871 if (S_ISREG(st.st_mode))
872 {
873 char *ext = group + strlen(group) - 7;
874 if ((strlen(group) < 8) || !mutt_str_equal(ext, ".hcache"))
875 continue;
876 *ext = '\0';
877 }
878 else
879#endif
880 if (!S_ISDIR(st.st_mode))
881 continue;
882
883 struct NntpMboxData tmp_mdata = { 0 };
885 if (!mdata)
886 {
887 mdata = &tmp_mdata;
888 mdata->adata = adata;
889 mdata->group = group;
890 mdata->bcache = NULL;
891 }
892 else if (mdata->newsrc_ent || mdata->subscribed || c_save_unsubscribed)
893 {
894 continue;
895 }
896
898 if (S_ISDIR(st.st_mode))
899 {
900 rmdir(buf_string(file));
901 mutt_debug(LL_DEBUG2, "%s\n", buf_string(file));
902 }
903 }
904 closedir(dir);
905
906done:
907 buf_pool_release(&cache);
908 buf_pool_release(&file);
909}
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:425
+ 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 77 of file nntp.c.

◆ NntpRenderCallbacks

const struct ExpandoRenderCallback NntpRenderCallbacks[]
extern

Callbacks for Newsrc Expandos.

See also
NntpFormatDef, ExpandoDataNntp

Definition at line 162 of file expando_newsrc.c.