NeoMutt  2020-11-20
Teaching an old dog new tricks
DOXYGEN
lib.h File Reference

Usenet network mailbox type; talk to an NNTP server. More...

#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <sys/types.h>
#include <time.h>
#include "core/lib.h"
#include "format_flags.h"
#include "mx.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  NntpAccountData
 NNTP-specific Account data -. More...
 
struct  NntpEmailData
 NNTP-specific Email data -. More...
 
struct  NntpAcache
 NNTP article cache. More...
 
struct  NewsrcEntry
 An entry in a .newsrc (subscribed newsgroups) More...
 
struct  NntpMboxData
 NNTP-specific Mailbox data -. More...
 

Macros

#define anum_t   uint32_t
 
#define ANUM   "%u"
 
#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. More...
 
struct NntpMboxDatamutt_newsgroup_subscribe (struct NntpAccountData *adata, char *group)
 Subscribe newsgroup. More...
 
struct NntpMboxDatamutt_newsgroup_unsubscribe (struct NntpAccountData *adata, char *group)
 Unsubscribe newsgroup. More...
 
struct NntpMboxDatamutt_newsgroup_catchup (struct Mailbox *m, struct NntpAccountData *adata, char *group)
 Catchup newsgroup. More...
 
struct NntpMboxDatamutt_newsgroup_uncatchup (struct Mailbox *m, struct NntpAccountData *adata, char *group)
 Uncatchup newsgroup. More...
 
int nntp_active_fetch (struct NntpAccountData *adata, bool mark_new)
 Fetch list of all newsgroups from server. More...
 
int nntp_newsrc_update (struct NntpAccountData *adata)
 Update .newsrc file. More...
 
int nntp_post (struct Mailbox *m, const char *msg)
 Post article. More...
 
int nntp_check_msgid (struct Mailbox *m, const char *msgid)
 Fetch article by Message-ID. More...
 
int nntp_check_children (struct Mailbox *m, const char *msgid)
 Fetch children of article with the Message-ID. More...
 
int nntp_newsrc_parse (struct NntpAccountData *adata)
 Parse .newsrc file. More...
 
void nntp_newsrc_close (struct NntpAccountData *adata)
 Unlock and close .newsrc file. More...
 
void nntp_mailbox (struct Mailbox *m, char *buf, size_t buflen)
 Get first newsgroup with new messages. More...
 
void nntp_expand_path (char *buf, size_t buflen, struct ConnAccount *acct)
 Make fully qualified url from newsgroup name. More...
 
void nntp_clear_cache (struct NntpAccountData *adata)
 Clear the NNTP cache. More...
 
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. More...
 
int nntp_compare_order (const void *a, const void *b)
 Sort to mailbox order - Implements sort_t. More...
 
enum MailboxType nntp_path_probe (const char *path, const struct stat *st)
 Is this an NNTP Mailbox? - Implements MxOps::path_probe() More...
 
const char * group_index_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)
 Format a string for the newsgroup menu - Implements format_t. More...
 
int nntp_complete (char *buf, size_t buflen)
 Auto-complete NNTP newsgroups. More...
 
bool config_init_nntp (struct ConfigSet *cs)
 Register nntp config variables - Implements module_init_config_t. More...
 

Variables

unsigned char C_CatchupNewsgroup
 Config: (nntp) Mark all articles as read when leaving a newsgroup. More...
 
unsigned char C_FollowupToPoster
 Config: (nntp) Reply to the poster if 'poster' is in the 'Followup-To' header. More...
 
char * C_GroupIndexFormat
 Config: (nntp) printf-like format string for the browser's display of newsgroups. More...
 
char * C_NewsServer
 Config: (nntp) Url of the news server. More...
 
char * C_NewsgroupsCharset
 Config: (nntp) Character set of newsgroups' descriptions. More...
 
unsigned char C_PostModerated
 Config: (nntp) Allow posting to moderated newsgroups. More...
 
bool C_ShowOnlyUnread
 Config: (nntp) Only show subscribed newsgroups with unread articles. More...
 
bool C_XCommentTo
 Config: (nntp) Add 'X-Comment-To' header that contains article author. More...
 
struct NntpAccountDataCurrentNewsSrv
 Current NNTP news server. More...
 
struct MxOps MxNntpOps
 NNTP Mailbox - Implements MxOps. More...
 

Detailed Description

Usenet network mailbox type; talk to an NNTP server.

Authors
  • Brandon Long
  • Andrej Gritsenko
  • Vsevolod Volkov

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   uint32_t

Definition at line 69 of file lib.h.

◆ ANUM

#define ANUM   "%u"

Definition at line 70 of file lib.h.

◆ NNTP_ACACHE_LEN

#define NNTP_ACACHE_LEN   10

Definition at line 133 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.

Definition at line 1008 of file newsrc.c.

1009 {
1010  char file[PATH_MAX];
1011  int rc;
1012  struct ConnAccount cac = { { 0 } };
1013  struct NntpAccountData *adata = NULL;
1014  struct Connection *conn = NULL;
1015 
1016  if (!server || (*server == '\0'))
1017  {
1018  mutt_error(_("No news server defined"));
1019  return NULL;
1020  }
1021 
1022  /* create account from news server url */
1023  cac.flags = 0;
1024  cac.port = NNTP_PORT;
1025  cac.type = MUTT_ACCT_TYPE_NNTP;
1026  cac.service = "nntp";
1027  cac.get_field = nntp_get_field;
1028 
1029  snprintf(file, sizeof(file), "%s%s", strstr(server, "://") ? "" : "news://", server);
1030  struct Url *url = url_parse(file);
1031  if (!url || (url->path && *url->path) ||
1032  !((url->scheme == U_NNTP) || (url->scheme == U_NNTPS)) || !url->host ||
1033  (mutt_account_fromurl(&cac, url) < 0))
1034  {
1035  url_free(&url);
1036  mutt_error(_("%s is an invalid news server specification"), server);
1037  return NULL;
1038  }
1039  if (url->scheme == U_NNTPS)
1040  {
1041  cac.flags |= MUTT_ACCT_SSL;
1042  cac.port = NNTP_SSL_PORT;
1043  }
1044  url_free(&url);
1045 
1046  /* find connection by account */
1047  conn = mutt_conn_find(&cac);
1048  if (!conn)
1049  return NULL;
1050  if (!(conn->account.flags & MUTT_ACCT_USER) && cac.flags & MUTT_ACCT_USER)
1051  {
1052  conn->account.flags |= MUTT_ACCT_USER;
1053  conn->account.user[0] = '\0';
1054  }
1055 
1056  /* news server already exists */
1057  // adata = conn->data;
1058  if (adata)
1059  {
1060  if (adata->status == NNTP_BYE)
1061  adata->status = NNTP_NONE;
1062  if (nntp_open_connection(adata) < 0)
1063  return NULL;
1064 
1065  rc = nntp_newsrc_parse(adata);
1066  if (rc < 0)
1067  return NULL;
1068 
1069  /* check for new newsgroups */
1070  if (!leave_lock && (nntp_check_new_groups(m, adata) < 0))
1071  rc = -1;
1072 
1073  /* .newsrc has been externally modified */
1074  if (rc > 0)
1075  nntp_clear_cache(adata);
1076  if ((rc < 0) || !leave_lock)
1077  nntp_newsrc_close(adata);
1078  return (rc < 0) ? NULL : adata;
1079  }
1080 
1081  /* new news server */
1082  adata = nntp_adata_new(conn);
1083 
1084  rc = nntp_open_connection(adata);
1085 
1086  /* try to create cache directory and enable caching */
1087  adata->cacheable = false;
1088  if ((rc >= 0) && C_NewsCacheDir)
1089  {
1090  cache_expand(file, sizeof(file), &conn->account, NULL);
1091  if (mutt_file_mkdir(file, S_IRWXU) < 0)
1092  {
1093  mutt_error(_("Can't create %s: %s"), file, strerror(errno));
1094  }
1095  adata->cacheable = true;
1096  }
1097 
1098  /* load .newsrc */
1099  if (rc >= 0)
1100  {
1101  mutt_expando_format(file, sizeof(file), 0, sizeof(file), NONULL(C_Newsrc),
1103  mutt_expand_path(file, sizeof(file));
1104  adata->newsrc_file = mutt_str_dup(file);
1105  rc = nntp_newsrc_parse(adata);
1106  }
1107  if (rc >= 0)
1108  {
1109  /* try to load list of newsgroups from cache */
1110  if (adata->cacheable && (active_get_cache(adata) == 0))
1111  rc = nntp_check_new_groups(m, adata);
1112 
1113  /* load list of newsgroups from server */
1114  else
1115  rc = nntp_active_fetch(adata, false);
1116  }
1117 
1118  if (rc >= 0)
1119  nntp_clear_cache(adata);
1120 
1121 #ifdef USE_HCACHE
1122  /* check cache files */
1123  if ((rc >= 0) && adata->cacheable)
1124  {
1125  struct dirent *entry = NULL;
1126  DIR *dp = opendir(file);
1127 
1128  if (dp)
1129  {
1130  while ((entry = readdir(dp)))
1131  {
1132  struct HeaderCache *hc = NULL;
1133  void *hdata = NULL;
1134  char *group = entry->d_name;
1135 
1136  char *p = group + strlen(group) - 7;
1137  if ((strlen(group) < 8) || (strcmp(p, ".hcache") != 0))
1138  continue;
1139  *p = '\0';
1140  struct NntpMboxData *mdata = mutt_hash_find(adata->groups_hash, group);
1141  if (!mdata)
1142  continue;
1143 
1144  hc = nntp_hcache_open(mdata);
1145  if (!hc)
1146  continue;
1147 
1148  /* fetch previous values of first and last */
1149  size_t dlen = 0;
1150  hdata = mutt_hcache_fetch_raw(hc, "index", 5, &dlen);
1151  if (hdata)
1152  {
1153  anum_t first, last;
1154 
1155  if (sscanf(hdata, ANUM " " ANUM, &first, &last) == 2)
1156  {
1157  if (mdata->deleted)
1158  {
1159  mdata->first_message = first;
1160  mdata->last_message = last;
1161  }
1162  if ((last >= mdata->first_message) && (last <= mdata->last_message))
1163  {
1164  mdata->last_cached = last;
1165  mutt_debug(LL_DEBUG2, "%s last_cached=%u\n", mdata->group, last);
1166  }
1167  }
1168  mutt_hcache_free_raw(hc, &hdata);
1169  }
1170  mutt_hcache_close(hc);
1171  }
1172  closedir(dp);
1173  }
1174  }
1175 #endif
1176 
1177  if ((rc < 0) || !leave_lock)
1178  nntp_newsrc_close(adata);
1179 
1180  if (rc < 0)
1181  {
1182  mutt_hash_free(&adata->groups_hash);
1183  FREE(&adata->groups_list);
1184  FREE(&adata->newsrc_file);
1185  FREE(&adata->authenticators);
1186  FREE(&adata);
1187  mutt_socket_close(conn);
1188  FREE(&conn);
1189  return NULL;
1190  }
1191 
1192  return adata;
1193 }
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:354
int mutt_account_fromurl(struct ConnAccount *cac, const struct Url *url)
Fill ConnAccount with information from url.
Definition: mutt_account.c:43
#define IP
Definition: set.h:54
#define NONULL(x)
Definition: string2.h:37
char * newsrc_file
Definition: lib.h:91
struct ConnAccount account
Account details: username, password, etc.
Definition: connection.h:36
void mutt_hash_free(struct HashTable **ptr)
Free a hash table.
Definition: hash.c:447
Disconnected from server.
Definition: private.h:44
A parsed URL proto://user:password@host:port/path?a=1&b=2
Definition: url.h:66
struct NntpAccountData * adata
Definition: lib.h:153
enum UrlScheme scheme
Scheme, e.g. U_SMTPS.
Definition: url.h:68
header cache structure
Definition: lib.h:85
An open network connection (socket)
Definition: connection.h:34
void nntp_clear_cache(struct NntpAccountData *adata)
Clear the NNTP cache.
Definition: newsrc.c:839
char user[128]
Username.
Definition: connaccount.h:55
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:370
#define _(a)
Definition: message.h:28
char * C_Newsrc
Config: (nntp) File containing list of subscribed newsgroups.
Definition: config.c:43
void url_free(struct Url **ptr)
Free the contents of a URL.
Definition: url.c:123
void mutt_hcache_free_raw(struct HeaderCache *hc, void **data)
Multiplexor for StoreOps::free.
Definition: hcache.c:512
#define MUTT_ACCT_USER
User field has been set.
Definition: connaccount.h:43
struct HashTable * groups_hash
Definition: lib.h:101
NNTP-specific Account data -.
Definition: lib.h:75
#define MUTT_FORMAT_NO_FLAGS
No flags are set.
Definition: format_flags.h:30
anum_t last_cached
Definition: lib.h:145
char * mutt_expand_path(char *buf, size_t buflen)
Create the canonical path.
Definition: muttlib.c:128
bool cacheable
Definition: lib.h:88
int nntp_active_fetch(struct NntpAccountData *adata, bool mark_new)
Fetch list of all newsgroups from server.
Definition: nntp.c:2052
Log at debug level 2.
Definition: logging.h:41
int mutt_file_mkdir(const char *path, mode_t mode)
Recursively create directories.
Definition: file.c:875
char * group
Definition: lib.h:140
void * mdata
Driver specific data.
Definition: mailbox.h:136
struct Connection * mutt_conn_find(const struct ConnAccount *cac)
Find a connection from a list.
Definition: mutt_socket.c:86
Url is nntps://.
Definition: url.h:41
unsigned short port
Port to connect to.
Definition: connaccount.h:57
const char *(* get_field)(enum ConnAccountField field, void *gf_data)
Function to get some login credentials.
Definition: connaccount.h:67
#define ANUM
Definition: lib.h:70
unsigned int status
Definition: lib.h:87
#define PATH_MAX
Definition: mutt.h:44
void * adata
Private data (for Mailbox backends)
Definition: account.h:43
struct HeaderCache * nntp_hcache_open(struct NntpMboxData *mdata)
Open newsgroup hcache.
Definition: newsrc.c:707
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.
Definition: newsrc.c:916
char * C_NewsCacheDir
Config: (nntp) Directory for cached news articles.
Definition: config.c:40
No connection to server.
Definition: private.h:42
unsigned char type
Connection type, e.g. MUTT_ACCT_TYPE_IMAP.
Definition: connaccount.h:58
char * host
Host.
Definition: url.h:71
static void cache_expand(char *dst, size_t dstlen, struct ConnAccount *cac, const char *src)
Make fully qualified cache file name.
Definition: newsrc.c:518
const char * service
Name of the service, e.g. "imap".
Definition: connaccount.h:60
Login details for a remote server.
Definition: connaccount.h:51
int mutt_socket_close(struct Connection *conn)
Close a socket.
Definition: socket.c:96
NNTP-specific Mailbox data -.
Definition: lib.h:138
int nntp_newsrc_parse(struct NntpAccountData *adata)
Parse .newsrc file.
Definition: newsrc.c:161
void nntp_newsrc_close(struct NntpAccountData *adata)
Unlock and close .newsrc file.
Definition: newsrc.c:117
char * path
Path.
Definition: url.h:73
Nntp (Usenet) Account.
Definition: mutt_account.h:40
void mutt_hcache_close(struct HeaderCache *hc)
Multiplexor for StoreOps::close.
Definition: hcache.c:417
char * authenticators
Definition: lib.h:92
bool deleted
Definition: lib.h:150
struct NntpAccountData * nntp_adata_new(struct Connection *conn)
Allocate and initialise a new NntpAccountData structure.
Definition: nntp.c:149
anum_t first_message
Definition: lib.h:142
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.
Definition: muttlib.c:772
Url is nntp://.
Definition: url.h:40
#define mutt_error(...)
Definition: logging.h:84
#define NNTP_SSL_PORT
Definition: private.h:35
void ** groups_list
Definition: lib.h:100
#define FREE(x)
Definition: memory.h:40
int nntp_check_new_groups(struct Mailbox *m, struct NntpAccountData *adata)
Check for new groups/articles in subscribed groups.
Definition: nntp.c:2119
#define mutt_debug(LEVEL,...)
Definition: logging.h:81
void * mutt_hcache_fetch_raw(struct HeaderCache *hc, const char *key, size_t keylen, size_t *dlen)
Fetch a message&#39;s header from the cache.
Definition: hcache.c:494
#define anum_t
Definition: lib.h:69
static const char * nntp_get_field(enum ConnAccountField field, void *gf_data)
Get connection login credentials - Implements ConnAccount::get_field()
Definition: newsrc.c:979
static int active_get_cache(struct NntpAccountData *adata)
Load list of all newsgroups from cache.
Definition: newsrc.c:614
#define NNTP_PORT
Definition: private.h:34
#define MUTT_ACCT_SSL
Account uses SSL/TLS.
Definition: connaccount.h:46
int nntp_open_connection(struct NntpAccountData *adata)
Connect to server, authenticate and get capabilities.
Definition: nntp.c:1806
MuttAccountFlags flags
Which fields are initialised, e.g. MUTT_ACCT_USER.
Definition: connaccount.h:59
struct Url * url_parse(const char *src)
Fill in Url.
Definition: url.c:234
anum_t last_message
Definition: lib.h:143
+ 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 1243 of file newsrc.c.

1244 {
1245  if (!adata || !adata->groups_hash || !group || (*group == '\0'))
1246  return NULL;
1247 
1248  struct NntpMboxData *mdata = mdata_find(adata, group);
1249  mdata->subscribed = true;
1250  if (!mdata->newsrc_ent)
1251  {
1252  mdata->newsrc_ent = mutt_mem_calloc(1, sizeof(struct NewsrcEntry));
1253  mdata->newsrc_len = 1;
1254  mdata->newsrc_ent[0].first = 1;
1255  mdata->newsrc_ent[0].last = 0;
1256  }
1257  return mdata;
1258 }
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:50
struct HashTable * groups_hash
Definition: lib.h:101
anum_t last
Definition: lib.h:129
bool subscribed
Definition: lib.h:147
An entry in a .newsrc (subscribed newsgroups)
Definition: lib.h:126
char * group
Definition: lib.h:140
void * mdata
Driver specific data.
Definition: mailbox.h:136
struct NewsrcEntry * newsrc_ent
Definition: lib.h:152
NNTP-specific Mailbox data -.
Definition: lib.h:138
unsigned int newsrc_len
Definition: lib.h:151
static struct NntpMboxData * mdata_find(struct NntpAccountData *adata, const char *group)
Find NntpMboxData for given newsgroup or add it.
Definition: newsrc.c:71
anum_t first
Definition: lib.h:128
+ 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 1267 of file newsrc.c.

1268 {
1269  if (!adata || !adata->groups_hash || !group || (*group == '\0'))
1270  return NULL;
1271 
1272  struct NntpMboxData *mdata = mutt_hash_find(adata->groups_hash, group);
1273  if (!mdata)
1274  return NULL;
1275 
1276  mdata->subscribed = false;
1277  if (!C_SaveUnsubscribed)
1278  {
1279  mdata->newsrc_len = 0;
1280  FREE(&mdata->newsrc_ent);
1281  }
1282  return mdata;
1283 }
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:354
bool C_SaveUnsubscribed
Config: (nntp) Save a list of unsubscribed newsgroups to the &#39;newsrc&#39;.
Definition: config.c:52
struct HashTable * groups_hash
Definition: lib.h:101
bool subscribed
Definition: lib.h:147
char * group
Definition: lib.h:140
void * mdata
Driver specific data.
Definition: mailbox.h:136
struct NewsrcEntry * newsrc_ent
Definition: lib.h:152
NNTP-specific Mailbox data -.
Definition: lib.h:138
unsigned int newsrc_len
Definition: lib.h:151
#define FREE(x)
Definition: memory.h:40
+ 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 1293 of file newsrc.c.

1295 {
1296  if (!adata || !adata->groups_hash || !group || (*group == '\0'))
1297  return NULL;
1298 
1299  struct NntpMboxData *mdata = mutt_hash_find(adata->groups_hash, group);
1300  if (!mdata)
1301  return NULL;
1302 
1303  if (mdata->newsrc_ent)
1304  {
1305  mutt_mem_realloc(&mdata->newsrc_ent, sizeof(struct NewsrcEntry));
1306  mdata->newsrc_len = 1;
1307  mdata->newsrc_ent[0].first = 1;
1308  mdata->newsrc_ent[0].last = mdata->last_message;
1309  }
1310  mdata->unread = 0;
1311  if (m && (m->mdata == mdata))
1312  {
1313  for (unsigned int i = 0; i < m->msg_count; i++)
1314  {
1315  struct Email *e = m->emails[i];
1316  if (!e)
1317  break;
1318  mutt_set_flag(m, e, MUTT_READ, true);
1319  }
1320  }
1321  return mdata;
1322 }
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:354
struct Email ** emails
Array of Emails.
Definition: mailbox.h:99
int msg_count
Total number of messages.
Definition: mailbox.h:91
#define mutt_set_flag(m, e, flag, bf)
Definition: protos.h:67
The envelope/body of an email.
Definition: email.h:37
struct HashTable * groups_hash
Definition: lib.h:101
anum_t last
Definition: lib.h:129
An entry in a .newsrc (subscribed newsgroups)
Definition: lib.h:126
char * group
Definition: lib.h:140
void * mdata
Driver specific data.
Definition: mailbox.h:136
void mutt_mem_realloc(void *ptr, size_t size)
Resize a block of memory on the heap.
Definition: memory.c:114
Messages that have been read.
Definition: mutt.h:96
struct NewsrcEntry * newsrc_ent
Definition: lib.h:152
NNTP-specific Mailbox data -.
Definition: lib.h:138
unsigned int newsrc_len
Definition: lib.h:151
anum_t unread
Definition: lib.h:146
anum_t first
Definition: lib.h:128
anum_t last_message
Definition: lib.h:143
+ 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 1332 of file newsrc.c.

1334 {
1335  if (!adata || !adata->groups_hash || !group || (*group == '\0'))
1336  return NULL;
1337 
1338  struct NntpMboxData *mdata = mutt_hash_find(adata->groups_hash, group);
1339  if (!mdata)
1340  return NULL;
1341 
1342  if (mdata->newsrc_ent)
1343  {
1344  mutt_mem_realloc(&mdata->newsrc_ent, sizeof(struct NewsrcEntry));
1345  mdata->newsrc_len = 1;
1346  mdata->newsrc_ent[0].first = 1;
1347  mdata->newsrc_ent[0].last = mdata->first_message - 1;
1348  }
1349  if (m && (m->mdata == mdata))
1350  {
1351  mdata->unread = m->msg_count;
1352  for (unsigned int i = 0; i < m->msg_count; i++)
1353  {
1354  struct Email *e = m->emails[i];
1355  if (!e)
1356  break;
1357  mutt_set_flag(m, e, MUTT_READ, false);
1358  }
1359  }
1360  else
1361  {
1362  mdata->unread = mdata->last_message;
1363  if (mdata->newsrc_ent)
1364  mdata->unread -= mdata->newsrc_ent[0].last;
1365  }
1366  return mdata;
1367 }
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:354
struct Email ** emails
Array of Emails.
Definition: mailbox.h:99
int msg_count
Total number of messages.
Definition: mailbox.h:91
#define mutt_set_flag(m, e, flag, bf)
Definition: protos.h:67
The envelope/body of an email.
Definition: email.h:37
struct HashTable * groups_hash
Definition: lib.h:101
anum_t last
Definition: lib.h:129
An entry in a .newsrc (subscribed newsgroups)
Definition: lib.h:126
char * group
Definition: lib.h:140
void * mdata
Driver specific data.
Definition: mailbox.h:136
void mutt_mem_realloc(void *ptr, size_t size)
Resize a block of memory on the heap.
Definition: memory.c:114
Messages that have been read.
Definition: mutt.h:96
struct NewsrcEntry * newsrc_ent
Definition: lib.h:152
NNTP-specific Mailbox data -.
Definition: lib.h:138
unsigned int newsrc_len
Definition: lib.h:151
anum_t first_message
Definition: lib.h:142
anum_t unread
Definition: lib.h:146
anum_t first
Definition: lib.h:128
anum_t last_message
Definition: lib.h:143
+ 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 2052 of file nntp.c.

2053 {
2054  struct NntpMboxData tmp_mdata = { 0 };
2055  char msg[256];
2056  char buf[1024];
2057  unsigned int i;
2058  int rc;
2059 
2060  snprintf(msg, sizeof(msg), _("Loading list of groups from server %s..."),
2061  adata->conn->account.host);
2062  mutt_message(msg);
2063  if (nntp_date(adata, &adata->newgroups_time) < 0)
2064  return -1;
2065 
2066  tmp_mdata.adata = adata;
2067  tmp_mdata.group = NULL;
2068  i = adata->groups_num;
2069  mutt_str_copy(buf, "LIST\r\n", sizeof(buf));
2070  rc = nntp_fetch_lines(&tmp_mdata, buf, sizeof(buf), msg, nntp_add_group, adata);
2071  if (rc)
2072  {
2073  if (rc > 0)
2074  {
2075  mutt_error("LIST: %s", buf);
2076  }
2077  return -1;
2078  }
2079 
2080  if (mark_new)
2081  {
2082  for (; i < adata->groups_num; i++)
2083  {
2084  struct NntpMboxData *mdata = adata->groups_list[i];
2085  mdata->has_new_mail = true;
2086  }
2087  }
2088 
2089  for (i = 0; i < adata->groups_num; i++)
2090  {
2091  struct NntpMboxData *mdata = adata->groups_list[i];
2092 
2093  if (mdata && mdata->deleted && !mdata->newsrc_ent)
2094  {
2095  nntp_delete_group_cache(mdata);
2096  mutt_hash_delete(adata->groups_hash, mdata->group, NULL);
2097  adata->groups_list[i] = NULL;
2098  }
2099  }
2100 
2102  rc = get_description(&tmp_mdata, "*", _("Loading descriptions..."));
2103 
2104  nntp_active_save_cache(adata);
2105  if (rc < 0)
2106  return -1;
2107  mutt_clear_error();
2108  return 0;
2109 }
bool has_new_mail
Definition: lib.h:148
struct ConnAccount account
Account details: username, password, etc.
Definition: connection.h:36
#define mutt_message(...)
Definition: logging.h:83
struct NntpAccountData * adata
Definition: lib.h:153
static int nntp_date(struct NntpAccountData *adata, time_t *now)
Get date and time from server.
Definition: nntp.c:1739
#define _(a)
Definition: message.h:28
int nntp_active_save_cache(struct NntpAccountData *adata)
Save list of all newsgroups to cache.
Definition: newsrc.c:648
void nntp_delete_group_cache(struct NntpMboxData *mdata)
Remove hcache and bcache of newsgroup.
Definition: newsrc.c:806
struct HashTable * groups_hash
Definition: lib.h:101
char host[128]
Server to login to.
Definition: connaccount.h:53
time_t newgroups_time
Definition: lib.h:96
char * group
Definition: lib.h:140
void mutt_clear_error(void)
Clear the message line (bottom line of screen)
Definition: mutt_logging.c:113
void * mdata
Driver specific data.
Definition: mailbox.h:136
unsigned int groups_num
Definition: lib.h:98
int nntp_add_group(char *line, void *data)
Parse newsgroup.
Definition: newsrc.c:573
static int get_description(struct NntpMboxData *mdata, const char *wildmat, const char *msg)
Fetch newsgroups descriptions.
Definition: nntp.c:981
struct NewsrcEntry * newsrc_ent
Definition: lib.h:152
NNTP-specific Mailbox data -.
Definition: lib.h:138
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:867
struct Connection * conn
Definition: lib.h:102
bool deleted
Definition: lib.h:150
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:716
#define mutt_error(...)
Definition: logging.h:84
void ** groups_list
Definition: lib.h:100
void mutt_hash_delete(struct HashTable *table, const char *strkey, const void *data)
Remove an element from a Hash Table.
Definition: hash.c:419
bool C_NntpLoadDescription
Config: (nntp) Load descriptions for newsgroups when adding to the list.
Definition: config.c:47
+ 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 439 of file newsrc.c.

440 {
441  if (!adata)
442  return -1;
443 
444  int rc = -1;
445 
446  size_t buflen = 10240;
447  char *buf = mutt_mem_calloc(1, buflen);
448  size_t off = 0;
449 
450  /* we will generate full newsrc here */
451  for (unsigned int i = 0; i < adata->groups_num; i++)
452  {
453  struct NntpMboxData *mdata = adata->groups_list[i];
454 
455  if (!mdata || !mdata->newsrc_ent)
456  continue;
457 
458  /* write newsgroup name */
459  if (off + strlen(mdata->group) + 3 > buflen)
460  {
461  buflen *= 2;
462  mutt_mem_realloc(&buf, buflen);
463  }
464  snprintf(buf + off, buflen - off, "%s%c ", mdata->group, mdata->subscribed ? ':' : '!');
465  off += strlen(buf + off);
466 
467  /* write entries */
468  for (unsigned int j = 0; j < mdata->newsrc_len; j++)
469  {
470  if (off + 1024 > buflen)
471  {
472  buflen *= 2;
473  mutt_mem_realloc(&buf, buflen);
474  }
475  if (j)
476  buf[off++] = ',';
477  if (mdata->newsrc_ent[j].first == mdata->newsrc_ent[j].last)
478  snprintf(buf + off, buflen - off, "%u", mdata->newsrc_ent[j].first);
479  else if (mdata->newsrc_ent[j].first < mdata->newsrc_ent[j].last)
480  {
481  snprintf(buf + off, buflen - off, "%u-%u", mdata->newsrc_ent[j].first,
482  mdata->newsrc_ent[j].last);
483  }
484  off += strlen(buf + off);
485  }
486  buf[off++] = '\n';
487  }
488  buf[off] = '\0';
489 
490  /* newrc being fully rewritten */
491  mutt_debug(LL_DEBUG1, "Updating %s\n", adata->newsrc_file);
492  if (adata->newsrc_file && (update_file(adata->newsrc_file, buf) == 0))
493  {
494  struct stat sb;
495 
496  rc = stat(adata->newsrc_file, &sb);
497  if (rc == 0)
498  {
499  adata->size = sb.st_size;
500  adata->mtime = sb.st_mtime;
501  }
502  else
503  {
504  mutt_perror(adata->newsrc_file);
505  }
506  }
507  FREE(&buf);
508  return rc;
509 }
char * newsrc_file
Definition: lib.h:91
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:50
#define mutt_perror(...)
Definition: logging.h:85
time_t mtime
Definition: lib.h:95
anum_t last
Definition: lib.h:129
bool subscribed
Definition: lib.h:147
static int update_file(char *filename, char *buf)
Update file with new contents.
Definition: newsrc.c:389
char * group
Definition: lib.h:140
void * mdata
Driver specific data.
Definition: mailbox.h:136
off_t size
Definition: lib.h:94
void mutt_mem_realloc(void *ptr, size_t size)
Resize a block of memory on the heap.
Definition: memory.c:114
unsigned int groups_num
Definition: lib.h:98
struct NewsrcEntry * newsrc_ent
Definition: lib.h:152
NNTP-specific Mailbox data -.
Definition: lib.h:138
unsigned int newsrc_len
Definition: lib.h:151
Log at debug level 1.
Definition: logging.h:40
void ** groups_list
Definition: lib.h:100
#define FREE(x)
Definition: memory.h:40
#define mutt_debug(LEVEL,...)
Definition: logging.h:81
anum_t first
Definition: lib.h:128
+ 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 1970 of file nntp.c.

1971 {
1972  struct NntpMboxData *mdata = NULL;
1973  struct NntpMboxData tmp_mdata = { 0 };
1974  char buf[1024];
1975 
1976  if (m && (m->type == MUTT_NNTP))
1977  mdata = m->mdata;
1978  else
1979  {
1981  if (!CurrentNewsSrv)
1982  return -1;
1983 
1984  mdata = &tmp_mdata;
1985  mdata->adata = CurrentNewsSrv;
1986  mdata->group = NULL;
1987  }
1988 
1989  FILE *fp = mutt_file_fopen(msg, "r");
1990  if (!fp)
1991  {
1992  mutt_perror(msg);
1993  return -1;
1994  }
1995 
1996  mutt_str_copy(buf, "POST\r\n", sizeof(buf));
1997  if (nntp_query(mdata, buf, sizeof(buf)) < 0)
1998  {
1999  mutt_file_fclose(&fp);
2000  return -1;
2001  }
2002  if (buf[0] != '3')
2003  {
2004  mutt_error(_("Can't post article: %s"), buf);
2005  mutt_file_fclose(&fp);
2006  return -1;
2007  }
2008 
2009  buf[0] = '.';
2010  buf[1] = '\0';
2011  while (fgets(buf + 1, sizeof(buf) - 2, fp))
2012  {
2013  size_t len = strlen(buf);
2014  if (buf[len - 1] == '\n')
2015  {
2016  buf[len - 1] = '\r';
2017  buf[len] = '\n';
2018  len++;
2019  buf[len] = '\0';
2020  }
2021  if (mutt_socket_send_d(mdata->adata->conn, (buf[1] == '.') ? buf : buf + 1,
2022  MUTT_SOCK_LOG_FULL) < 0)
2023  {
2024  mutt_file_fclose(&fp);
2025  return nntp_connect_error(mdata->adata);
2026  }
2027  }
2028  mutt_file_fclose(&fp);
2029 
2030  if (((buf[strlen(buf) - 1] != '\n') &&
2031  (mutt_socket_send_d(mdata->adata->conn, "\r\n", MUTT_SOCK_LOG_FULL) < 0)) ||
2032  (mutt_socket_send_d(mdata->adata->conn, ".\r\n", MUTT_SOCK_LOG_FULL) < 0) ||
2033  (mutt_socket_readln(buf, sizeof(buf), mdata->adata->conn) < 0))
2034  {
2035  return nntp_connect_error(mdata->adata);
2036  }
2037  if (buf[0] != '2')
2038  {
2039  mutt_error(_("Can't post article: %s"), buf);
2040  return -1;
2041  }
2042  return 0;
2043 }
enum MailboxType type
Mailbox type.
Definition: mailbox.h:105
#define mutt_perror(...)
Definition: logging.h:85
&#39;NNTP&#39; (Usenet) Mailbox type
Definition: mailbox.h:52
struct NntpAccountData * adata
Definition: lib.h:153
#define _(a)
Definition: message.h:28
static int nntp_connect_error(struct NntpAccountData *adata)
Signal a failed connection.
Definition: nntp.c:229
char * C_NewsServer
Config: (nntp) Url of the news server.
Definition: config.c:41
#define MUTT_SOCK_LOG_FULL
Definition: mutt_socket.h:31
int mutt_file_fclose(FILE **fp)
Close a FILE handle (and NULL the pointer)
Definition: file.c:153
#define mutt_socket_send_d(conn, buf, dbg)
Definition: mutt_socket.h:38
char * group
Definition: lib.h:140
void * mdata
Driver specific data.
Definition: mailbox.h:136
struct NntpAccountData * nntp_select_server(struct Mailbox *m, const char *server, bool leave_lock)
Open a connection to an NNTP server.
Definition: newsrc.c:1008
NNTP-specific Mailbox data -.
Definition: lib.h:138
#define mutt_socket_readln(buf, buflen, conn)
Definition: mutt_socket.h:36
struct Connection * conn
Definition: lib.h:102
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:790
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:716
#define mutt_error(...)
Definition: logging.h:84
FILE * mutt_file_fopen(const char *path, const char *mode)
Call fopen() safely.
Definition: file.c:588
struct NntpAccountData * CurrentNewsSrv
Current NNTP news server.
Definition: nntp.c:76
+ 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 2222 of file nntp.c.

2223 {
2224  if (!m)
2225  return -1;
2226 
2227  struct NntpMboxData *mdata = m->mdata;
2228  char buf[1024];
2229 
2230  FILE *fp = mutt_file_mkstemp();
2231  if (!fp)
2232  {
2233  mutt_perror(_("Can't create temporary file"));
2234  return -1;
2235  }
2236 
2237  snprintf(buf, sizeof(buf), "HEAD %s\r\n", msgid);
2238  int rc = nntp_fetch_lines(mdata, buf, sizeof(buf), NULL, fetch_tempfile, fp);
2239  if (rc)
2240  {
2241  mutt_file_fclose(&fp);
2242  if (rc < 0)
2243  return -1;
2244  if (mutt_str_startswith(buf, "430"))
2245  return 1;
2246  mutt_error("HEAD: %s", buf);
2247  return -1;
2248  }
2249 
2250  /* parse header */
2251  if (m->msg_count == m->email_max)
2252  mx_alloc_memory(m);
2253  m->emails[m->msg_count] = email_new();
2254  struct Email *e = m->emails[m->msg_count];
2255  e->edata = nntp_edata_new();
2257  e->env = mutt_rfc822_read_header(fp, e, false, false);
2258  mutt_file_fclose(&fp);
2259 
2260  /* get article number */
2261  if (e->env->xref)
2262  nntp_parse_xref(m, e);
2263  else
2264  {
2265  snprintf(buf, sizeof(buf), "STAT %s\r\n", msgid);
2266  if (nntp_query(mdata, buf, sizeof(buf)) < 0)
2267  {
2268  email_free(&e);
2269  return -1;
2270  }
2271  sscanf(buf + 4, ANUM, &nntp_edata_get(e)->article_num);
2272  }
2273 
2274  /* reset flags */
2275  e->read = false;
2276  e->old = false;
2277  e->deleted = false;
2278  e->changed = true;
2279  e->received = e->date_sent;
2280  e->index = m->msg_count++;
2282  return 0;
2283 }
struct Email ** emails
Array of Emails.
Definition: mailbox.h:99
int msg_count
Total number of messages.
Definition: mailbox.h:91
The envelope/body of an email.
Definition: email.h:37
#define mutt_perror(...)
Definition: logging.h:85
struct NntpEmailData * nntp_edata_get(struct Email *e)
Get the private data for this Email.
Definition: nntp.c:217
static void nntp_parse_xref(struct Mailbox *m, struct Email *e)
Parse cross-reference.
Definition: nntp.c:1013
char * xref
List of cross-references.
Definition: envelope.h:76
static int fetch_tempfile(char *line, void *data)
Write line to temporary file.
Definition: nntp.c:1054
void mx_alloc_memory(struct Mailbox *m)
Create storage for the emails.
Definition: mx.c:1230
#define _(a)
Definition: message.h:28
bool changed
Email has been edited.
Definition: email.h:48
Email list was changed.
Definition: mailbox.h:173
bool read
Email is read.
Definition: email.h:51
bool old
Email is seen, but unread.
Definition: email.h:50
int mutt_file_fclose(FILE **fp)
Close a FILE handle (and NULL the pointer)
Definition: file.c:153
struct Envelope * env
Envelope information.
Definition: email.h:90
void * mdata
Driver specific data.
Definition: mailbox.h:136
time_t date_sent
Time when the message was sent (UTC)
Definition: email.h:82
#define ANUM
Definition: lib.h:70
size_t mutt_str_startswith(const char *str, const char *prefix)
Check whether a string starts with a prefix.
Definition: string.c:160
int email_max
Number of pointers in emails.
Definition: mailbox.h:100
void(* edata_free)(void **ptr)
Free the private data attached to the Email.
Definition: email.h:117
#define mutt_file_mkstemp()
Definition: file.h:106
NNTP-specific Mailbox data -.
Definition: lib.h:138
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:867
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:790
static struct NntpEmailData * nntp_edata_new(void)
Create a new NntpEmailData for an Email.
Definition: nntp.c:207
bool deleted
Email is deleted.
Definition: email.h:45
void * edata
Driver-specific data.
Definition: email.h:111
#define mutt_error(...)
Definition: logging.h:84
int index
The absolute (unsorted) message number.
Definition: email.h:86
static void nntp_edata_free(void **ptr)
Free the private Email data - Implements Email::edata_free()
Definition: nntp.c:197
struct Email * email_new(void)
Create a new Email.
Definition: email.c:72
void email_free(struct Email **ptr)
Free an Email.
Definition: email.c:43
struct Envelope * mutt_rfc822_read_header(FILE *fp, struct Email *e, bool user_hdrs, bool weed)
parses an RFC822 header
Definition: parse.c:1111
void mailbox_changed(struct Mailbox *m, enum NotifyMailbox action)
Notify observers of a change to a Mailbox.
Definition: mailbox.c:177
time_t received
Time when the message was placed in the mailbox.
Definition: email.h:83
+ 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 2292 of file nntp.c.

2293 {
2294  if (!m)
2295  return -1;
2296 
2297  struct NntpMboxData *mdata = m->mdata;
2298  struct ChildCtx cc;
2299  char buf[256];
2300  int rc;
2301  void *hc = NULL;
2302 
2303  if (!mdata || !mdata->adata)
2304  return -1;
2305  if (mdata->first_message > mdata->last_loaded)
2306  return 0;
2307 
2308  /* init context */
2309  cc.mailbox = m;
2310  cc.num = 0;
2311  cc.max = 10;
2312  cc.child = mutt_mem_malloc(sizeof(anum_t) * cc.max);
2313 
2314  /* fetch numbers of child messages */
2315  snprintf(buf, sizeof(buf), "XPAT References %u-%u *%s*\r\n",
2316  mdata->first_message, mdata->last_loaded, msgid);
2317  rc = nntp_fetch_lines(mdata, buf, sizeof(buf), NULL, fetch_children, &cc);
2318  if (rc)
2319  {
2320  FREE(&cc.child);
2321  if (rc > 0)
2322  {
2323  if (!mutt_str_startswith(buf, "500"))
2324  mutt_error("XPAT: %s", buf);
2325  else
2326  {
2327  mutt_error(_("Unable to find child articles because server does not "
2328  "support XPAT command"));
2329  }
2330  }
2331  return -1;
2332  }
2333 
2334  /* fetch all found messages */
2335  bool verbose = m->verbose;
2336  m->verbose = false;
2337 #ifdef USE_HCACHE
2338  hc = nntp_hcache_open(mdata);
2339 #endif
2340  int old_msg_count = m->msg_count;
2341  for (int i = 0; i < cc.num; i++)
2342  {
2343  rc = nntp_fetch_headers(m, hc, cc.child[i], cc.child[i], true);
2344  if (rc < 0)
2345  break;
2346  }
2347  if (m->msg_count > old_msg_count)
2349 
2350 #ifdef USE_HCACHE
2351  mutt_hcache_close(hc);
2352 #endif
2353  m->verbose = verbose;
2354  FREE(&cc.child);
2355  return (rc < 0) ? -1 : 0;
2356 }
int msg_count
Total number of messages.
Definition: mailbox.h:91
static int nntp_fetch_headers(struct Mailbox *m, void *hc, anum_t first, anum_t last, bool restore)
Fetch headers.
Definition: nntp.c:1251
struct NntpAccountData * adata
Definition: lib.h:153
#define _(a)
Definition: message.h:28
Keep track of the children of an article.
Definition: nntp.c:104
Email list was changed.
Definition: mailbox.h:173
anum_t last_loaded
Definition: lib.h:144
void * mdata
Driver specific data.
Definition: mailbox.h:136
size_t mutt_str_startswith(const char *str, const char *prefix)
Check whether a string starts with a prefix.
Definition: string.c:160
void * mutt_mem_malloc(size_t size)
Allocate memory on the heap.
Definition: memory.c:90
struct HeaderCache * nntp_hcache_open(struct NntpMboxData *mdata)
Open newsgroup hcache.
Definition: newsrc.c:707
bool verbose
Display status messages?
Definition: mailbox.h:118
struct Mailbox * mailbox
Definition: nntp.c:106
NNTP-specific Mailbox data -.
Definition: lib.h:138
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:867
static int fetch_children(char *line, void *data)
Parse XPAT line.
Definition: nntp.c:1776
void mutt_hcache_close(struct HeaderCache *hc)
Multiplexor for StoreOps::close.
Definition: hcache.c:417
anum_t first_message
Definition: lib.h:142
#define mutt_error(...)
Definition: logging.h:84
#define FREE(x)
Definition: memory.h:40
#define anum_t
Definition: lib.h:69
void mailbox_changed(struct Mailbox *m, enum NotifyMailbox action)
Notify observers of a change to a Mailbox.
Definition: mailbox.c:177
+ 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 161 of file newsrc.c.

162 {
163  char *line = NULL;
164  struct stat sb;
165 
166  if (adata->fp_newsrc)
167  {
168  /* if we already have a handle, close it and reopen */
169  mutt_file_fclose(&adata->fp_newsrc);
170  }
171  else
172  {
173  /* if file doesn't exist, create it */
174  adata->fp_newsrc = mutt_file_fopen(adata->newsrc_file, "a");
175  mutt_file_fclose(&adata->fp_newsrc);
176  }
177 
178  /* open .newsrc */
179  adata->fp_newsrc = mutt_file_fopen(adata->newsrc_file, "r");
180  if (!adata->fp_newsrc)
181  {
182  mutt_perror(adata->newsrc_file);
183  return -1;
184  }
185 
186  /* lock it */
187  mutt_debug(LL_DEBUG1, "Locking %s\n", adata->newsrc_file);
188  if (mutt_file_lock(fileno(adata->fp_newsrc), false, true))
189  {
190  mutt_file_fclose(&adata->fp_newsrc);
191  return -1;
192  }
193 
194  if (stat(adata->newsrc_file, &sb) != 0)
195  {
196  mutt_perror(adata->newsrc_file);
197  nntp_newsrc_close(adata);
198  return -1;
199  }
200 
201  if ((adata->size == sb.st_size) && (adata->mtime == sb.st_mtime))
202  return 0;
203 
204  adata->size = sb.st_size;
205  adata->mtime = sb.st_mtime;
206  adata->newsrc_modified = true;
207  mutt_debug(LL_DEBUG1, "Parsing %s\n", adata->newsrc_file);
208 
209  /* .newsrc has been externally modified or hasn't been loaded yet */
210  for (unsigned int i = 0; i < adata->groups_num; i++)
211  {
212  struct NntpMboxData *mdata = adata->groups_list[i];
213  if (!mdata)
214  continue;
215 
216  mdata->subscribed = false;
217  mdata->newsrc_len = 0;
218  FREE(&mdata->newsrc_ent);
219  }
220 
221  line = mutt_mem_malloc(sb.st_size + 1);
222  while (sb.st_size && fgets(line, sb.st_size + 1, adata->fp_newsrc))
223  {
224  char *b = NULL, *h = NULL;
225  unsigned int j = 1;
226  bool subs = false;
227 
228  /* find end of newsgroup name */
229  char *p = strpbrk(line, ":!");
230  if (!p)
231  continue;
232 
233  /* ":" - subscribed, "!" - unsubscribed */
234  if (*p == ':')
235  subs = true;
236  *p++ = '\0';
237 
238  /* get newsgroup data */
239  struct NntpMboxData *mdata = mdata_find(adata, line);
240  FREE(&mdata->newsrc_ent);
241 
242  /* count number of entries */
243  b = p;
244  while (*b)
245  if (*b++ == ',')
246  j++;
247  mdata->newsrc_ent = mutt_mem_calloc(j, sizeof(struct NewsrcEntry));
248  mdata->subscribed = subs;
249 
250  /* parse entries */
251  j = 0;
252  while (p)
253  {
254  b = p;
255 
256  /* find end of entry */
257  p = strchr(p, ',');
258  if (p)
259  *p++ = '\0';
260 
261  /* first-last or single number */
262  h = strchr(b, '-');
263  if (h)
264  *h++ = '\0';
265  else
266  h = b;
267 
268  if ((sscanf(b, ANUM, &mdata->newsrc_ent[j].first) == 1) &&
269  (sscanf(h, ANUM, &mdata->newsrc_ent[j].last) == 1))
270  {
271  j++;
272  }
273  }
274  if (j == 0)
275  {
276  mdata->newsrc_ent[j].first = 1;
277  mdata->newsrc_ent[j].last = 0;
278  j++;
279  }
280  if (mdata->last_message == 0)
281  mdata->last_message = mdata->newsrc_ent[j - 1].last;
282  mdata->newsrc_len = j;
283  mutt_mem_realloc(&mdata->newsrc_ent, j * sizeof(struct NewsrcEntry));
284  nntp_group_unread_stat(mdata);
285  mutt_debug(LL_DEBUG2, "%s\n", mdata->group);
286  }
287  FREE(&line);
288  return 1;
289 }
char * newsrc_file
Definition: lib.h:91
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:50
#define mutt_perror(...)
Definition: logging.h:85
bool newsrc_modified
Definition: lib.h:89
time_t mtime
Definition: lib.h:95
anum_t last
Definition: lib.h:129
bool subscribed
Definition: lib.h:147
Log at debug level 2.
Definition: logging.h:41
int mutt_file_lock(int fd, bool excl, bool timeout)
(try to) lock a file using fcntl()
Definition: file.c:1175
An entry in a .newsrc (subscribed newsgroups)
Definition: lib.h:126
int mutt_file_fclose(FILE **fp)
Close a FILE handle (and NULL the pointer)
Definition: file.c:153
char * group
Definition: lib.h:140
void * mdata
Driver specific data.
Definition: mailbox.h:136
off_t size
Definition: lib.h:94
void mutt_mem_realloc(void *ptr, size_t size)
Resize a block of memory on the heap.
Definition: memory.c:114
#define ANUM
Definition: lib.h:70
void * mutt_mem_malloc(size_t size)
Allocate memory on the heap.
Definition: memory.c:90
unsigned int groups_num
Definition: lib.h:98
struct NewsrcEntry * newsrc_ent
Definition: lib.h:152
NNTP-specific Mailbox data -.
Definition: lib.h:138
unsigned int newsrc_len
Definition: lib.h:151
void nntp_newsrc_close(struct NntpAccountData *adata)
Unlock and close .newsrc file.
Definition: newsrc.c:117
static struct NntpMboxData * mdata_find(struct NntpAccountData *adata, const char *group)
Find NntpMboxData for given newsgroup or add it.
Definition: newsrc.c:71
Log at debug level 1.
Definition: logging.h:40
void ** groups_list
Definition: lib.h:100
void nntp_group_unread_stat(struct NntpMboxData *mdata)
Count number of unread articles using .newsrc data.
Definition: newsrc.c:131
FILE * fp_newsrc
Definition: lib.h:90
#define FREE(x)
Definition: memory.h:40
#define mutt_debug(LEVEL,...)
Definition: logging.h:81
FILE * mutt_file_fopen(const char *path, const char *mode)
Call fopen() safely.
Definition: file.c:588
anum_t first
Definition: lib.h:128
anum_t last_message
Definition: lib.h:143
+ 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 117 of file newsrc.c.

118 {
119  if (!adata->fp_newsrc)
120  return;
121 
122  mutt_debug(LL_DEBUG1, "Unlocking %s\n", adata->newsrc_file);
123  mutt_file_unlock(fileno(adata->fp_newsrc));
124  mutt_file_fclose(&adata->fp_newsrc);
125 }
char * newsrc_file
Definition: lib.h:91
int mutt_file_unlock(int fd)
Unlock a file previously locked by mutt_file_lock()
Definition: file.c:1223
int mutt_file_fclose(FILE **fp)
Close a FILE handle (and NULL the pointer)
Definition: file.c:153
Log at debug level 1.
Definition: logging.h:40
FILE * fp_newsrc
Definition: lib.h:90
#define mutt_debug(LEVEL,...)
Definition: logging.h:81
+ 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 1375 of file newsrc.c.

1376 {
1377  if (!m)
1378  return;
1379 
1380  for (unsigned int i = 0; i < CurrentNewsSrv->groups_num; i++)
1381  {
1383 
1384  if (!mdata || !mdata->subscribed || !mdata->unread)
1385  continue;
1386 
1387  if ((m->type == MUTT_NNTP) &&
1388  mutt_str_equal(mdata->group, ((struct NntpMboxData *) m->mdata)->group))
1389  {
1390  unsigned int unread = 0;
1391 
1392  for (unsigned int j = 0; j < m->msg_count; j++)
1393  {
1394  struct Email *e = m->emails[j];
1395  if (!e)
1396  break;
1397  if (!e->read && !e->deleted)
1398  unread++;
1399  }
1400  if (unread == 0)
1401  continue;
1402  }
1403  mutt_str_copy(buf, mdata->group, buflen);
1404  break;
1405  }
1406 }
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:871
struct Email ** emails
Array of Emails.
Definition: mailbox.h:99
enum MailboxType type
Mailbox type.
Definition: mailbox.h:105
int msg_count
Total number of messages.
Definition: mailbox.h:91
The envelope/body of an email.
Definition: email.h:37
&#39;NNTP&#39; (Usenet) Mailbox type
Definition: mailbox.h:52
bool subscribed
Definition: lib.h:147
bool read
Email is read.
Definition: email.h:51
char * group
Definition: lib.h:140
void * mdata
Driver specific data.
Definition: mailbox.h:136
unsigned int groups_num
Definition: lib.h:98
NNTP-specific Mailbox data -.
Definition: lib.h:138
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:716
bool deleted
Email is deleted.
Definition: email.h:45
anum_t unread
Definition: lib.h:146
void ** groups_list
Definition: lib.h:100
struct NntpAccountData * CurrentNewsSrv
Current NNTP news server.
Definition: nntp.c:76
+ 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  mutt_account_tourl(cac, &url);
562  url.path = mutt_str_dup(buf);
563  url_tostring(&url, buf, buflen, 0);
564  FREE(&url.path);
565 }
A parsed URL proto://user:password@host:port/path?a=1&b=2
Definition: url.h:66
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:370
void mutt_account_tourl(struct ConnAccount *cac, struct Url *url)
Fill URL with info from account.
Definition: mutt_account.c:79
char * path
Path.
Definition: url.h:73
#define FREE(x)
Definition: memory.h:40
int url_tostring(struct Url *url, char *dest, size_t len, int flags)
Output the URL string for a given Url object.
Definition: url.c:418
+ 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 839 of file newsrc.c.

840 {
841  char file[PATH_MAX];
842  char *fp = NULL;
843  struct dirent *entry = NULL;
844  DIR *dp = NULL;
845 
846  if (!adata || !adata->cacheable)
847  return;
848 
849  cache_expand(file, sizeof(file), &adata->conn->account, NULL);
850  dp = opendir(file);
851  if (dp)
852  {
853  mutt_strn_cat(file, sizeof(file), "/", 1);
854  fp = file + strlen(file);
855  while ((entry = readdir(dp)))
856  {
857  char *group = entry->d_name;
858  struct stat sb;
859  struct NntpMboxData *mdata = NULL;
860  struct NntpMboxData tmp_mdata;
861 
862  if (mutt_str_equal(group, ".") || mutt_str_equal(group, ".."))
863  continue;
864  *fp = '\0';
865  mutt_strn_cat(file, sizeof(file), group, strlen(group));
866  if (stat(file, &sb) != 0)
867  continue;
868 
869 #ifdef USE_HCACHE
870  if (S_ISREG(sb.st_mode))
871  {
872  char *ext = group + strlen(group) - 7;
873  if ((strlen(group) < 8) || !mutt_str_equal(ext, ".hcache"))
874  continue;
875  *ext = '\0';
876  }
877  else
878 #endif
879  if (!S_ISDIR(sb.st_mode))
880  continue;
881 
882  mdata = mutt_hash_find(adata->groups_hash, group);
883  if (!mdata)
884  {
885  mdata = &tmp_mdata;
886  mdata->adata = adata;
887  mdata->group = group;
888  mdata->bcache = NULL;
889  }
890  else if (mdata->newsrc_ent || mdata->subscribed || C_SaveUnsubscribed)
891  continue;
892 
894  if (S_ISDIR(sb.st_mode))
895  {
896  rmdir(file);
897  mutt_debug(LL_DEBUG2, "%s\n", file);
898  }
899  }
900  closedir(dp);
901  }
902 }
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:354
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:871
bool C_SaveUnsubscribed
Config: (nntp) Save a list of unsubscribed newsgroups to the &#39;newsrc&#39;.
Definition: config.c:52
struct ConnAccount account
Account details: username, password, etc.
Definition: connection.h:36
char * mutt_strn_cat(char *d, size_t l, const char *s, size_t sl)
Concatenate two strings.
Definition: string.c:414
struct NntpAccountData * adata
Definition: lib.h:153
void nntp_delete_group_cache(struct NntpMboxData *mdata)
Remove hcache and bcache of newsgroup.
Definition: newsrc.c:806
struct HashTable * groups_hash
Definition: lib.h:101
bool subscribed
Definition: lib.h:147
bool cacheable
Definition: lib.h:88
Log at debug level 2.
Definition: logging.h:41
char * group
Definition: lib.h:140
void * mdata
Driver specific data.
Definition: mailbox.h:136
struct BodyCache * bcache
Definition: lib.h:155
#define PATH_MAX
Definition: mutt.h:44
static void cache_expand(char *dst, size_t dstlen, struct ConnAccount *cac, const char *src)
Make fully qualified cache file name.
Definition: newsrc.c:518
struct NewsrcEntry * newsrc_ent
Definition: lib.h:152
NNTP-specific Mailbox data -.
Definition: lib.h:138
struct Connection * conn
Definition: lib.h:102
#define mutt_debug(LEVEL,...)
Definition: logging.h:81
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ nntp_format_str()

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.

Expando Description
%a Account url
%p Port
%P Port if specified
%s News server name
%S Url schema
%u Username

Definition at line 916 of file newsrc.c.

919 {
920  struct NntpAccountData *adata = (struct NntpAccountData *) data;
921  struct ConnAccount *cac = &adata->conn->account;
922  char fn[128], fmt[128];
923 
924  switch (op)
925  {
926  case 'a':
927  {
928  struct Url url = { 0 };
929  mutt_account_tourl(cac, &url);
930  url_tostring(&url, fn, sizeof(fn), U_PATH);
931  char *p = strchr(fn, '/');
932  if (p)
933  *p = '\0';
934  snprintf(fmt, sizeof(fmt), "%%%ss", prec);
935  snprintf(buf, buflen, fmt, fn);
936  break;
937  }
938  case 'p':
939  snprintf(fmt, sizeof(fmt), "%%%su", prec);
940  snprintf(buf, buflen, fmt, cac->port);
941  break;
942  case 'P':
943  *buf = '\0';
944  if (cac->flags & MUTT_ACCT_PORT)
945  {
946  snprintf(fmt, sizeof(fmt), "%%%su", prec);
947  snprintf(buf, buflen, fmt, cac->port);
948  }
949  break;
950  case 's':
951  mutt_str_copy(fn, cac->host, sizeof(fn));
952  mutt_str_lower(fn);
953  snprintf(fmt, sizeof(fmt), "%%%ss", prec);
954  snprintf(buf, buflen, fmt, fn);
955  break;
956  case 'S':
957  {
958  struct Url url = { 0 };
959  mutt_account_tourl(cac, &url);
960  url_tostring(&url, fn, sizeof(fn), U_PATH);
961  char *p = strchr(fn, ':');
962  if (p)
963  *p = '\0';
964  snprintf(fmt, sizeof(fmt), "%%%ss", prec);
965  snprintf(buf, buflen, fmt, fn);
966  break;
967  }
968  case 'u':
969  snprintf(fmt, sizeof(fmt), "%%%ss", prec);
970  snprintf(buf, buflen, fmt, cac->user);
971  break;
972  }
973  return src;
974 }
struct ConnAccount account
Account details: username, password, etc.
Definition: connection.h:36
A parsed URL proto://user:password@host:port/path?a=1&b=2
Definition: url.h:66
char user[128]
Username.
Definition: connaccount.h:55
NNTP-specific Account data -.
Definition: lib.h:75
void mutt_account_tourl(struct ConnAccount *cac, struct Url *url)
Fill URL with info from account.
Definition: mutt_account.c:79
char host[128]
Server to login to.
Definition: connaccount.h:53
char * mutt_str_lower(char *s)
Convert all characters in the string to lowercase.
Definition: string.c:504
unsigned short port
Port to connect to.
Definition: connaccount.h:57
#define MUTT_ACCT_PORT
Port field has been set.
Definition: connaccount.h:42
void * adata
Private data (for Mailbox backends)
Definition: account.h:43
Login details for a remote server.
Definition: connaccount.h:51
struct Connection * conn
Definition: lib.h:102
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:716
int url_tostring(struct Url *url, char *dest, size_t len, int flags)
Output the URL string for a given Url object.
Definition: url.c:418
char * src
Raw URL string.
Definition: url.h:75
#define U_PATH
Definition: url.h:48
MuttAccountFlags flags
Which fields are initialised, e.g. MUTT_ACCT_USER.
Definition: connaccount.h:59
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ nntp_compare_order()

int nntp_compare_order ( const void *  a,
const void *  b 
)

Sort to mailbox order - Implements sort_t.

Definition at line 2361 of file nntp.c.

2362 {
2363  const struct Email *ea = *(struct Email const *const *) a;
2364  const struct Email *eb = *(struct Email const *const *) b;
2365 
2366  anum_t na = nntp_edata_get((struct Email *) ea)->article_num;
2367  anum_t nb = nntp_edata_get((struct Email *) eb)->article_num;
2368  int result = (na == nb) ? 0 : (na > nb) ? 1 : -1;
2369  result = perform_auxsort(result, a, b);
2370  return SORT_CODE(result);
2371 }
The envelope/body of an email.
Definition: email.h:37
struct NntpEmailData * nntp_edata_get(struct Email *e)
Get the private data for this Email.
Definition: nntp.c:217
anum_t article_num
Definition: lib.h:110
#define SORT_CODE(x)
Definition: sort.h:40
int perform_auxsort(int retval, const void *a, const void *b)
Compare two emails using the auxiliary sort method.
Definition: sort.c:65
#define anum_t
Definition: lib.h:69
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ nntp_path_probe()

enum MailboxType nntp_path_probe ( const char *  path,
const struct stat *  st 
)

Is this an NNTP Mailbox? - Implements MxOps::path_probe()

Definition at line 2793 of file nntp.c.

2794 {
2795  if (mutt_istr_startswith(path, "news://"))
2796  return MUTT_NNTP;
2797 
2798  if (mutt_istr_startswith(path, "snews://"))
2799  return MUTT_NNTP;
2800 
2801  return MUTT_UNKNOWN;
2802 }
&#39;NNTP&#39; (Usenet) Mailbox type
Definition: mailbox.h:52
Mailbox wasn&#39;t recognised.
Definition: mailbox.h:47
size_t mutt_istr_startswith(const char *str, const char *prefix)
Check whether a string starts with a prefix, ignoring case.
Definition: string.c:172
char * path
Path of Email (for local Mailboxes)
Definition: email.h:92
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ group_index_format_str()

const char* group_index_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 
)

Format a string for the newsgroup menu - Implements format_t.

Expando Description
%C Current newsgroup number
%d Description of newsgroup (becomes from server)
%f Newsgroup name
%M - if newsgroup not allowed for direct post (moderated for example)
%N N if newsgroup is new, u if unsubscribed, blank otherwise
%n Number of new articles in newsgroup
%s Number of unread articles in newsgroup

Definition at line 52 of file browse.c.

56 {
57  char fn[128], fmt[128];
58  struct Folder *folder = (struct Folder *) data;
59 
60  switch (op)
61  {
62  case 'C':
63  snprintf(fmt, sizeof(fmt), "%%%sd", prec);
64  snprintf(buf, buflen, fmt, folder->num + 1);
65  break;
66 
67  case 'd':
68  if (folder->ff->nd->desc)
69  {
70  char *desc = mutt_str_dup(folder->ff->nd->desc);
74 
75  snprintf(fmt, sizeof(fmt), "%%%ss", prec);
76  snprintf(buf, buflen, fmt, desc);
77  FREE(&desc);
78  }
79  else
80  {
81  snprintf(fmt, sizeof(fmt), "%%%ss", prec);
82  snprintf(buf, buflen, fmt, "");
83  }
84  break;
85 
86  case 'f':
87  mutt_str_copy(fn, folder->ff->name, sizeof(fn));
88  snprintf(fmt, sizeof(fmt), "%%%ss", prec);
89  snprintf(buf, buflen, fmt, fn);
90  break;
91 
92  case 'M':
93  snprintf(fmt, sizeof(fmt), "%%%sc", prec);
94  if (folder->ff->nd->deleted)
95  snprintf(buf, buflen, fmt, 'D');
96  else
97  snprintf(buf, buflen, fmt, folder->ff->nd->allowed ? ' ' : '-');
98  break;
99 
100  case 'N':
101  snprintf(fmt, sizeof(fmt), "%%%sc", prec);
102  if (folder->ff->nd->subscribed)
103  snprintf(buf, buflen, fmt, ' ');
104  else
105  snprintf(buf, buflen, fmt, folder->ff->has_new_mail ? 'N' : 'u');
106  break;
107 
108  case 'n':
109  if (C_MarkOld && (folder->ff->nd->last_cached >= folder->ff->nd->first_message) &&
110  (folder->ff->nd->last_cached <= folder->ff->nd->last_message))
111  {
112  snprintf(fmt, sizeof(fmt), "%%%sd", prec);
113  snprintf(buf, buflen, fmt, folder->ff->nd->last_message - folder->ff->nd->last_cached);
114  }
115  else
116  {
117  snprintf(fmt, sizeof(fmt), "%%%sd", prec);
118  snprintf(buf, buflen, fmt, folder->ff->nd->unread);
119  }
120  break;
121 
122  case 's':
123  if (flags & MUTT_FORMAT_OPTIONAL)
124  {
125  if (folder->ff->nd->unread != 0)
126  {
127  mutt_expando_format(buf, buflen, col, cols, if_str,
128  group_index_format_str, data, flags);
129  }
130  else
131  {
132  mutt_expando_format(buf, buflen, col, cols, else_str,
133  group_index_format_str, data, flags);
134  }
135  }
136  else
137  {
138  snprintf(fmt, sizeof(fmt), "%%%sd", prec);
139  snprintf(buf, buflen, fmt, folder->ff->nd->unread);
140  }
141  break;
142  }
143  return src;
144 }
bool C_MarkOld
Config: Mark new emails as old when leaving the mailbox.
Definition: globals.c:36
int mutt_ch_convert_string(char **ps, const char *from, const char *to, int flags)
Convert a string between encodings.
Definition: charset.c:754
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:370
bool subscribed
Definition: lib.h:147
anum_t last_cached
Definition: lib.h:145
struct FolderFile * ff
Definition: browser.h:50
char * name
Definition: browser.h:66
int num
Definition: browser.h:51
const char * group_index_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)
Format a string for the newsgroup menu - Implements format_t.
Definition: browse.c:52
A folder/dir in the browser.
Definition: browser.h:48
#define MUTT_ICONV_HOOK_FROM
apply charset-hooks to fromcode
Definition: charset.h:72
bool allowed
Definition: lib.h:149
bool deleted
Definition: lib.h:150
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:716
anum_t first_message
Definition: lib.h:142
anum_t unread
Definition: lib.h:146
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.
Definition: muttlib.c:772
char * C_NewsgroupsCharset
Config: (nntp) Character set of newsgroups&#39; descriptions.
Definition: config.c:42
#define FREE(x)
Definition: memory.h:40
#define MUTT_FORMAT_OPTIONAL
Allow optional field processing.
Definition: format_flags.h:33
int mutt_mb_filter_unprintable(char **s)
Replace unprintable characters.
Definition: mbyte.c:424
struct NntpMboxData * nd
Definition: browser.h:84
char * C_Charset
Config: Default character set for displaying text on screen.
Definition: charset.c:53
char * desc
Definition: lib.h:141
anum_t last_message
Definition: lib.h:143
bool has_new_mail
true if mailbox has "new mail"
Definition: browser.h:69
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ nntp_complete()

int nntp_complete ( char *  buf,
size_t  buflen 
)

Auto-complete NNTP newsgroups.

Parameters
bufBuffer containing pathname
buflenLength of buffer
Return values
0Match found
-1No matches

XXX rules

Definition at line 45 of file complete.c.

46 {
48  size_t n = 0;
49  char filepart[PATH_MAX];
50  bool init = false;
51 
52  mutt_str_copy(filepart, buf, sizeof(filepart));
53 
54  /* special case to handle when there is no filepart yet
55  * find the first subscribed newsgroup */
56  int len = mutt_str_len(filepart);
57  if (len == 0)
58  {
59  for (; n < adata->groups_num; n++)
60  {
61  struct NntpMboxData *mdata = adata->groups_list[n];
62 
63  if (mdata && mdata->subscribed)
64  {
65  mutt_str_copy(filepart, mdata->group, sizeof(filepart));
66  init = true;
67  n++;
68  break;
69  }
70  }
71  }
72 
73  for (; n < adata->groups_num; n++)
74  {
75  struct NntpMboxData *mdata = adata->groups_list[n];
76 
77  if (mdata && mdata->subscribed && mutt_strn_equal(mdata->group, filepart, len))
78  {
79  if (init)
80  {
81  size_t i;
82  for (i = 0; filepart[i] && mdata->group[i]; i++)
83  {
84  if (filepart[i] != mdata->group[i])
85  break;
86  }
87  filepart[i] = '\0';
88  }
89  else
90  {
91  mutt_str_copy(filepart, mdata->group, sizeof(filepart));
92  init = true;
93  }
94  }
95  }
96 
97  mutt_str_copy(buf, filepart, buflen);
98  return init ? 0 : -1;
99 }
NNTP-specific Account data -.
Definition: lib.h:75
bool subscribed
Definition: lib.h:147
char * group
Definition: lib.h:140
void * mdata
Driver specific data.
Definition: mailbox.h:136
#define PATH_MAX
Definition: mutt.h:44
void * adata
Private data (for Mailbox backends)
Definition: account.h:43
unsigned int groups_num
Definition: lib.h:98
NNTP-specific Mailbox data -.
Definition: lib.h:138
bool mutt_strn_equal(const char *a, const char *b, size_t l)
Check for equality of two strings (to a maximum), safely.
Definition: string.c:593
size_t mutt_str_len(const char *a)
Calculate the length of a string, safely.
Definition: string.c:631
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:716
void ** groups_list
Definition: lib.h:100
struct NntpAccountData * CurrentNewsSrv
Current NNTP news server.
Definition: nntp.c:76
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ config_init_nntp()

bool config_init_nntp ( struct ConfigSet cs)

Register nntp config variables - Implements module_init_config_t.

Definition at line 124 of file config.c.

125 {
126  return cs_register_variables(cs, NntpVars, 0);
127 }
bool cs_register_variables(const struct ConfigSet *cs, struct ConfigDef vars[], int flags)
Register a set of config items.
Definition: set.c:286
struct ConfigDef NntpVars[]
Definition: config.c:58
+ Here is the call graph for this function:

Variable Documentation

◆ C_CatchupNewsgroup

unsigned char C_CatchupNewsgroup

Config: (nntp) Mark all articles as read when leaving a newsgroup.

Definition at line 37 of file config.c.

◆ C_FollowupToPoster

unsigned char C_FollowupToPoster

Config: (nntp) Reply to the poster if 'poster' is in the 'Followup-To' header.

Definition at line 38 of file config.c.

◆ C_GroupIndexFormat

char* C_GroupIndexFormat

Config: (nntp) printf-like format string for the browser's display of newsgroups.

Definition at line 39 of file config.c.

◆ C_NewsServer

char* C_NewsServer

Config: (nntp) Url of the news server.

Definition at line 41 of file config.c.

◆ C_NewsgroupsCharset

char* C_NewsgroupsCharset

Config: (nntp) Character set of newsgroups' descriptions.

Definition at line 42 of file config.c.

◆ C_PostModerated

unsigned char C_PostModerated

Config: (nntp) Allow posting to moderated newsgroups.

Definition at line 51 of file config.c.

◆ C_ShowOnlyUnread

bool C_ShowOnlyUnread

Config: (nntp) Only show subscribed newsgroups with unread articles.

Definition at line 54 of file config.c.

◆ C_XCommentTo

bool C_XCommentTo

Config: (nntp) Add 'X-Comment-To' header that contains article author.

Definition at line 55 of file config.c.

◆ CurrentNewsSrv

struct NntpAccountData* CurrentNewsSrv

Current NNTP news server.

Definition at line 76 of file nntp.c.

◆ MxNntpOps

struct MxOps MxNntpOps

NNTP Mailbox - Implements MxOps.

Definition at line 2834 of file nntp.c.