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.
1020{
1022 int rc;
1026
1027 if (!server || (*server == '\0'))
1028 {
1030 return NULL;
1031 }
1032
1033
1039
1040 snprintf(file, sizeof(file), "%s%s", strstr(server, "://") ? "" : "news://", server);
1042 if (!url || (url->
path && *url->
path) ||
1045 {
1047 mutt_error(
_(
"%s is an invalid news server specification"), server);
1048 return NULL;
1049 }
1051 {
1054 }
1056
1057
1058 const char *
user = NULL;
1059 const char *
pass = NULL;
1061 {
1064 }
1066 {
1069 }
1070
1071
1073 if (!conn)
1074 return NULL;
1076 {
1079 }
1080
1081
1082
1083 if (adata)
1084 {
1088 return NULL;
1089
1091 if (rc < 0)
1092 return NULL;
1093
1094
1096 rc = -1;
1097
1098
1099 if (rc > 0)
1101 if ((rc < 0) || !leave_lock)
1103 return (rc < 0) ? NULL : adata;
1104 }
1105
1106
1108
1110
1111
1114 if ((rc >= 0) && c_news_cache_dir)
1115 {
1118 {
1119 mutt_error(
_(
"Can't create %s: %s"), file, strerror(errno));
1120 }
1122 }
1123
1124
1125 if (rc >= 0)
1126 {
1133 }
1134 if (rc >= 0)
1135 {
1136
1139
1140
1141 else
1143 }
1144
1145 if (rc >= 0)
1147
1148#ifdef USE_HCACHE
1149
1151 {
1152 struct dirent *entry = NULL;
1154
1155 if (dp)
1156 {
1157 while ((entry = readdir(dp)))
1158 {
1160 char *hdata = NULL;
1161 char *group = entry->d_name;
1162
1163 char *p = group + strlen(group) - 7;
1164 if ((strlen(group) < 8) || (strcmp(p, ".hcache") != 0))
1165 continue;
1166 *p = '\0';
1169 continue;
1170
1172 if (!hc)
1173 continue;
1174
1175
1176 size_t dlen = 0;
1178 if (hdata)
1179 {
1181
1182 if ((dlen > 0) && (hdata[dlen - 1] == '\0') &&
1183 sscanf(hdata,
ANUM " " ANUM, &first, &last) == 2)
1184 {
1186 {
1187 mdata->first_message = first;
1188 mdata->last_message = last;
1189 }
1191 {
1192 mdata->last_cached = last;
1194 }
1195 }
1197 }
1199 }
1200 closedir(dp);
1201 }
1202 }
1203#endif
1204
1205 if ((rc < 0) || !leave_lock)
1207
1208 if (rc < 0)
1209 {
1217 return NULL;
1218 }
1219
1221}
#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.
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 -.
void mutt_hash_free(struct HashTable **ptr)
Free a hash table.
void mutt_hcache_close(struct HeaderCache *hc)
Multiplexor for StoreOps::close.
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.
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.
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.
@ NNTP_NONE
No connection to server.
@ NNTP_BYE
Disconnected 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.
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.
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://.