Open a connection to an NNTP server.
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.
1022{
1024 int rc;
1028
1029 if (!server || (*server == '\0'))
1030 {
1032 return NULL;
1033 }
1034
1035
1041
1042 snprintf(file, sizeof(file), "%s%s", strstr(server, "://") ? "" : "news://", server);
1044 if (!url || (url->
path && *url->
path) ||
1047 {
1049 mutt_error(
_(
"%s is an invalid news server specification"), server);
1050 return NULL;
1051 }
1053 {
1056 }
1058
1059
1060 const char *
user = NULL;
1061 const char *
pass = NULL;
1063 {
1066 }
1068 {
1071 }
1072
1073
1075 if (!conn)
1076 return NULL;
1078 {
1081 }
1082
1083
1085
1087
1088
1091 if ((rc >= 0) && c_news_cache_dir)
1092 {
1095 {
1096 mutt_error(
_(
"Can't create %s: %s"), file, strerror(errno));
1097 }
1099 }
1100
1101
1102 if (rc >= 0)
1103 {
1110 }
1111 if (rc >= 0)
1112 {
1113
1115 {
1117 }
1118 else
1119 {
1120
1122 }
1123 }
1124
1125 if (rc >= 0)
1127
1128#ifdef USE_HCACHE
1129
1131 {
1132 struct dirent *de = NULL;
1134
1135 if (dir)
1136 {
1137 while ((de = readdir(dir)))
1138 {
1140 char *group = de->d_name;
1141
1142 char *p = group + strlen(group) - 7;
1144 continue;
1145 *p = '\0';
1148 continue;
1149
1151 if (!hc)
1152 continue;
1153
1154
1156 if (hdata)
1157 {
1159
1160 if (sscanf(hdata,
ANUM " " ANUM, &first, &last) == 2)
1161 {
1163 {
1164 mdata->first_message = first;
1165 mdata->last_message = last;
1166 }
1168 {
1169 mdata->last_cached = last;
1171 }
1172 }
1174 }
1176 }
1177 closedir(dir);
1178 }
1179 }
1180#endif
1181
1182 if ((rc < 0) || !leave_lock)
1184
1185 if (rc < 0)
1186 {
1194 return NULL;
1195 }
1196
1198}
const char * cs_subset_path(const struct ConfigSubset *sub, const char *name)
Get a path config item by name.
#define MUTT_ACCT_SSL
Account uses SSL/TLS.
#define MUTT_ACCT_PASS
Password field has been set.
#define MUTT_ACCT_USER
User field has been set.
int mutt_file_mkdir(const char *path, mode_t mode)
Recursively create directories.
DIR * mutt_file_opendir(const char *path, enum MuttOpenDirMode mode)
Open a directory.
@ MUTT_OPENDIR_NONE
Plain opendir()
const char * nntp_format_str(char *buf, size_t buflen, size_t col, int cols, char op, const char *src, const char *prec, const char *if_str, const char *else_str, intptr_t data, MuttFormatFlags flags)
Expand the newsrc filename - Implements format_t -.
void mutt_expando_format(char *buf, size_t buflen, size_t col, int cols, const char *src, format_t callback, intptr_t data, MuttFormatFlags flags)
Expand expandos (x) in a string -.
#define mutt_debug(LEVEL,...)
void * mutt_hash_find(const struct HashTable *table, const char *strkey)
Find the HashElem data in a Hash Table element using a key.
void mutt_hash_free(struct HashTable **ptr)
Free a hash table.
char * hcache_fetch_str(struct HeaderCache *hc, const char *key, size_t keylen)
Fetch a string from the cache.
void hcache_close(struct HeaderCache **ptr)
Multiplexor for StoreOps::close.
@ LL_DEBUG2
Log at debug level 2.
char * mutt_str_dup(const char *str)
Copy a string, safely.
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
size_t mutt_str_copy(char *dest, const char *src, size_t dsize)
Copy a string into a buffer (guaranteeing NUL-termination)
int mutt_account_fromurl(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.
char * mutt_expand_path(char *buf, size_t buflen)
Create the canonical path.
struct HeaderCache * nntp_hcache_open(struct NntpMboxData *mdata)
Open newsgroup hcache.
void nntp_clear_cache(struct NntpAccountData *adata)
Clear the NNTP cache.
int nntp_newsrc_parse(struct NntpAccountData *adata)
Parse .newsrc file.
void nntp_newsrc_close(struct NntpAccountData *adata)
Unlock and close .newsrc file.
static const char * nntp_get_field(enum ConnAccountField field, void *gf_data)
Get connection login credentials - Implements ConnAccount::get_field()
static int active_get_cache(struct NntpAccountData *adata)
Load list of all newsgroups from cache.
static void cache_expand(char *dst, size_t dstlen, struct ConnAccount *cac, const char *src)
Make fully qualified cache file name.
struct NntpAccountData * nntp_adata_new(struct Connection *conn)
Allocate and initialise a new NntpAccountData structure.
int nntp_active_fetch(struct NntpAccountData *adata, bool mark_new)
Fetch list of all newsgroups from server.
int nntp_check_new_groups(struct Mailbox *m, struct NntpAccountData *adata)
Check for new groups/articles in subscribed groups.
int nntp_open_connection(struct NntpAccountData *adata)
Connect to server, authenticate and get capabilities.
int mutt_socket_close(struct Connection *conn)
Close a socket.
void * adata
Private data (for Mailbox backends)
Login details for a remote server.
const char * service
Name of the service, e.g. "imap".
const char *(* get_field)(enum ConnAccountField field, void *gf_data)
Function to get some login credentials.
unsigned char type
Connection type, e.g. MUTT_ACCT_TYPE_IMAP.
MuttAccountFlags flags
Which fields are initialised, e.g. MUTT_ACCT_USER.
unsigned short port
Port to connect to.
struct ConnAccount account
Account details: username, password, etc.
void * mdata
Driver specific data.
Container for Accounts, Notifications.
struct ConfigSubset * sub
Inherited config items.
NNTP-specific Account data -.
struct HashTable * groups_hash
Hash Table: "newsgroup" -> NntpMboxData.
NNTP-specific Mailbox data -.
char * group
Name of newsgroup.
struct NntpAccountData * adata
A parsed URL proto://user:password@host:port/path?a=1&b=2
enum UrlScheme scheme
Scheme, e.g. U_SMTPS.
struct Url * url_parse(const char *src)
Fill in Url.
void url_free(struct Url **ptr)
Free the contents of a URL.
@ U_NNTPS
Url is nntps://.