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.
952{
954 int rc;
958
959 if (!server || (*server == '\0'))
960 {
962 return NULL;
963 }
964
965
971
972 snprintf(file, sizeof(file), "%s%s", strstr(server, "://") ? "" : "news://", server);
974 if (!url || (url->
path && *url->
path) ||
977 {
979 mutt_error(
_(
"%s is an invalid news server specification"), server);
980 return NULL;
981 }
983 {
986 }
988
989
990 const char *
user = NULL;
991 const char *
pass = NULL;
993 {
996 }
998 {
1001 }
1002
1003
1005 if (!conn)
1006 return NULL;
1008 {
1011 }
1012
1013
1015
1017
1018
1021 if ((rc >= 0) && c_news_cache_dir)
1022 {
1025 {
1026 mutt_error(
_(
"Can't create %s: %s"), file, strerror(errno));
1027 }
1029 }
1030
1031
1032 if (rc >= 0)
1033 {
1042 }
1043 if (rc >= 0)
1044 {
1045
1047 {
1049 }
1050 else
1051 {
1052
1054 }
1055 }
1056
1057 if (rc >= 0)
1059
1060#ifdef USE_HCACHE
1061
1063 {
1064 struct dirent *de = NULL;
1066
1067 if (dir)
1068 {
1069 while ((de = readdir(dir)))
1070 {
1072 char *group = de->d_name;
1073
1074 char *p = group + strlen(group) - 7;
1076 continue;
1077 *p = '\0';
1080 continue;
1081
1083 if (!hc)
1084 continue;
1085
1086
1088 if (hdata)
1089 {
1090 anum_t first = 0, last = 0;
1091
1093 {
1095 {
1096 mdata->first_message = first;
1097 mdata->last_message = last;
1098 }
1100 {
1101 mdata->last_cached = last;
1103 }
1104 }
1106 }
1108 }
1109 closedir(dir);
1110 }
1111 }
1112#endif
1113
1114 if ((rc < 0) || !leave_lock)
1116
1117 if (rc < 0)
1118 {
1126 return NULL;
1127 }
1128
1130}
char * buf_strdup(const struct Buffer *buf)
Copy a Buffer's string.
const char * cs_subset_path(const struct ConfigSubset *sub, const char *name)
Get a path config item by name.
const struct Expando * cs_subset_expando(const struct ConfigSubset *sub, const char *name)
Get an Expando 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 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.
const struct ExpandoRenderCallback NntpRenderCallbacks[]
Callbacks for Newsrc Expandos.
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()
static const char * nntp_get_field(enum ConnAccountField field, void *gf_data)
Get connection login credentials - Implements ConnAccount::get_field() -.
#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.
void hcache_close(struct HeaderCache **ptr)
Multiplexor for StoreOps::close.
char * hcache_fetch_raw_str(struct HeaderCache *hc, const char *key, size_t keylen)
Fetch a string from the cache.
@ LL_DEBUG2
Log at debug level 2.
#define FREE(x)
Free memory and set the pointer to NULL.
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 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.
void expand_path(struct Buffer *buf, bool regex)
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 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.
struct Buffer * buf_pool_get(void)
Get a Buffer from the pool.
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
#define MUTT_FORMAT_NO_FLAGS
No flags are set.
int mutt_socket_close(struct Connection *conn)
Close a socket.
void * adata
Private data (for Mailbox backends)
String manipulation buffer.
size_t dsize
Length of data.
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)
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.
char ** env
Private copy of the environment variables.
struct ConfigSubset * sub
Inherited config items.
NNTP-specific Account data -.
struct HashTable * groups_hash
Hash Table: "newsgroup" -> NntpMboxData.
struct NntpMboxData ** groups_list
List of newsgroups.
char * authenticators
Authenticators list.
bool cacheable
Can be cached.
char * newsrc_file
Newsrc file path.
NNTP-specific Mailbox data -.
anum_t last_message
Last article number.
char * group
Name of newsgroup.
struct NntpAccountData * adata
Account data.
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://.