NeoMutt  2021-02-05-89-gabe350
Teaching an old dog new tricks
DOXYGEN
private.h File Reference
#include <stdint.h>
#include "lib.h"
#include "hcache/lib.h"
+ Include dependency graph for private.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define NNTP_PORT   119
 
#define NNTP_SSL_PORT   563
 

Enumerations

enum  NntpStatus { NNTP_NONE = 0, NNTP_OK, NNTP_BYE }
 NNTP server return values. More...
 

Functions

void nntp_acache_free (struct NntpMboxData *mdata)
 Remove all temporarily cache files. More...
 
int nntp_active_save_cache (struct NntpAccountData *adata)
 Save list of all newsgroups to cache. More...
 
int nntp_add_group (char *line, void *data)
 Parse newsgroup. More...
 
void nntp_article_status (struct Mailbox *m, struct Email *e, char *group, anum_t anum)
 Get status of articles from .newsrc. More...
 
void nntp_bcache_update (struct NntpMboxData *mdata)
 Remove stale cached messages. More...
 
int nntp_check_new_groups (struct Mailbox *m, struct NntpAccountData *adata)
 Check for new groups/articles in subscribed groups. More...
 
void nntp_delete_group_cache (struct NntpMboxData *mdata)
 Remove hcache and bcache of newsgroup. More...
 
void nntp_group_unread_stat (struct NntpMboxData *mdata)
 Count number of unread articles using .newsrc data. More...
 
void nntp_hash_destructor_t (int type, void *obj, intptr_t data)
 
void nntp_hashelem_free (int type, void *obj, intptr_t data)
 Free our hash table data - Implements hash_hdata_free_t. More...
 
struct HeaderCachenntp_hcache_open (struct NntpMboxData *mdata)
 Open newsgroup hcache. More...
 
void nntp_hcache_update (struct NntpMboxData *mdata, struct HeaderCache *hc)
 Remove stale cached headers. More...
 
void nntp_newsrc_gen_entries (struct Mailbox *m)
 Generate array of .newsrc entries. More...
 
int nntp_open_connection (struct NntpAccountData *adata)
 Connect to server, authenticate and get capabilities. More...
 

Variables

char * C_NewsCacheDir
 Config: (nntp) Directory for cached news articles. More...
 
char * C_Newsrc
 Config: (nntp) File containing list of subscribed newsgroups. More...
 
char * C_NntpAuthenticators
 Config: (nntp) Allowed authentication methods. More...
 
short C_NntpContext
 Config: (nntp) Maximum number of articles to list (0 for all articles) More...
 
bool C_NntpListgroup
 Config: (nntp) Check all articles when opening a newsgroup. More...
 
bool C_NntpLoadDescription
 Config: (nntp) Load descriptions for newsgroups when adding to the list. More...
 
char * C_NntpPass
 Config: (nntp) Password for the news server. More...
 
short C_NntpPoll
 Config: (nntp) Interval between checks for new posts. More...
 
char * C_NntpUser
 Config: (nntp) Username for the news server. More...
 
bool C_SaveUnsubscribed
 Config: (nntp) Save a list of unsubscribed newsgroups to the 'newsrc'. More...
 
bool C_ShowNewNews
 Config: (nntp) Check for new newsgroups when entering the browser. More...
 

Detailed Description

Usenet network mailbox type; talk to an NNTP server

Authors
  • Richard Russon

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 private.h.

Macro Definition Documentation

◆ NNTP_PORT

#define NNTP_PORT   119

Definition at line 34 of file private.h.

◆ NNTP_SSL_PORT

#define NNTP_SSL_PORT   563

Definition at line 35 of file private.h.

Enumeration Type Documentation

◆ NntpStatus

enum NntpStatus

NNTP server return values.

Enumerator
NNTP_NONE 

No connection to server.

NNTP_OK 

Connected to server.

NNTP_BYE 

Disconnected from server.

Definition at line 40 of file private.h.

41 {
42  NNTP_NONE = 0,
43  NNTP_OK,
44  NNTP_BYE,
45 };

Function Documentation

◆ nntp_acache_free()

void nntp_acache_free ( struct NntpMboxData mdata)

Remove all temporarily cache files.

Parameters
mdataNNTP Mailbox data

Definition at line 104 of file newsrc.c.

105 {
106  for (int i = 0; i < NNTP_ACACHE_LEN; i++)
107  {
108  if (mdata->acache[i].path)
109  {
110  unlink(mdata->acache[i].path);
111  FREE(&mdata->acache[i].path);
112  }
113  }
114 }
+ Here is the caller graph for this function:

◆ nntp_active_save_cache()

int nntp_active_save_cache ( struct NntpAccountData adata)

Save list of all newsgroups to cache.

Parameters
adataNNTP server
Return values
0Success
-1Failure

Definition at line 651 of file newsrc.c.

652 {
653  if (!adata->cacheable)
654  return 0;
655 
656  size_t buflen = 10240;
657  char *buf = mutt_mem_calloc(1, buflen);
658  snprintf(buf, buflen, "%lu\n", (unsigned long) adata->newgroups_time);
659  size_t off = strlen(buf);
660 
661  for (unsigned int i = 0; i < adata->groups_num; i++)
662  {
663  struct NntpMboxData *mdata = adata->groups_list[i];
664 
665  if (!mdata || mdata->deleted)
666  continue;
667 
668  if ((off + strlen(mdata->group) + (mdata->desc ? strlen(mdata->desc) : 0) + 50) > buflen)
669  {
670  buflen *= 2;
671  mutt_mem_realloc(&buf, buflen);
672  }
673  snprintf(buf + off, buflen - off, "%s %u %u %c%s%s\n", mdata->group,
674  mdata->last_message, mdata->first_message, mdata->allowed ? 'y' : 'n',
675  mdata->desc ? " " : "", mdata->desc ? mdata->desc : "");
676  off += strlen(buf + off);
677  }
678 
679  char file[PATH_MAX];
680  cache_expand(file, sizeof(file), &adata->conn->account, ".active");
681  mutt_debug(LL_DEBUG1, "Updating %s\n", file);
682  int rc = update_file(file, buf);
683  FREE(&buf);
684  return rc;
685 }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ nntp_add_group()

int nntp_add_group ( char *  line,
void *  data 
)

Parse newsgroup.

Parameters
lineString to parse
dataNNTP data
Return values
0Always

Definition at line 576 of file newsrc.c.

577 {
578  struct NntpAccountData *adata = data;
579  struct NntpMboxData *mdata = NULL;
580  char group[1024] = { 0 };
581  char desc[8192] = { 0 };
582  char mod;
583  anum_t first, last;
584 
585  if (!adata || !line)
586  return 0;
587 
588  /* These sscanf limits must match the sizes of the group and desc arrays */
589  if (sscanf(line, "%1023s " ANUM " " ANUM " %c %8191[^\n]", group, &last,
590  &first, &mod, desc) < 4)
591  {
592  mutt_debug(LL_DEBUG2, "Can't parse server line: %s\n", line);
593  return 0;
594  }
595 
597  mdata->deleted = false;
598  mdata->first_message = first;
599  mdata->last_message = last;
600  mdata->allowed = (mod == 'y') || (mod == 'm');
601  mutt_str_replace(&mdata->desc, desc);
602  if (mdata->newsrc_ent || (mdata->last_cached != 0))
604  else if (mdata->last_message && (mdata->first_message <= mdata->last_message))
605  mdata->unread = mdata->last_message - mdata->first_message + 1;
606  else
607  mdata->unread = 0;
608  return 0;
609 }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ nntp_article_status()

void nntp_article_status ( struct Mailbox m,
struct Email e,
char *  group,
anum_t  anum 
)

Get status of articles from .newsrc.

Parameters
mMailbox
eEmail
groupNewsgroup
anumArticle number

Full status flags are not supported by nntp, but we can fake some of them: Read = a read message number is in the .newsrc New = not read and not cached Old = not read but cached

Definition at line 1211 of file newsrc.c.

1212 {
1213  struct NntpMboxData *mdata = m->mdata;
1214 
1215  if (group)
1216  mdata = mutt_hash_find(mdata->adata->groups_hash, group);
1217 
1218  if (!mdata)
1219  return;
1220 
1221  for (unsigned int i = 0; i < mdata->newsrc_len; i++)
1222  {
1223  if ((anum >= mdata->newsrc_ent[i].first) && (anum <= mdata->newsrc_ent[i].last))
1224  {
1225  /* can't use mutt_set_flag() because ctx_update() didn't get called yet */
1226  e->read = true;
1227  return;
1228  }
1229  }
1230 
1231  /* article was not cached yet, it's new */
1232  if (anum > mdata->last_cached)
1233  return;
1234 
1235  /* article isn't read but cached, it's old */
1236  if (C_MarkOld)
1237  e->old = true;
1238 }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ nntp_bcache_update()

void nntp_bcache_update ( struct NntpMboxData mdata)

Remove stale cached messages.

Parameters
mdataNNTP Mailbox data

Definition at line 800 of file newsrc.c.

801 {
803 }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ nntp_check_new_groups()

int nntp_check_new_groups ( struct Mailbox m,
struct NntpAccountData adata 
)

Check for new groups/articles in subscribed groups.

Parameters
mMailbox
adataNNTP server
Return values
1New groups found
0No new groups
-1Error

Definition at line 2015 of file nntp.c.

2016 {
2017  struct NntpMboxData tmp_mdata = { 0 };
2018  time_t now;
2019  char buf[1024];
2020  char *msg = _("Checking for new newsgroups...");
2021  unsigned int i;
2022  int rc, update_active = false;
2023 
2024  if (!adata || !adata->newgroups_time)
2025  return -1;
2026 
2027  /* check subscribed newsgroups for new articles */
2028  if (C_ShowNewNews)
2029  {
2030  mutt_message(_("Checking for new messages..."));
2031  for (i = 0; i < adata->groups_num; i++)
2032  {
2033  struct NntpMboxData *mdata = adata->groups_list[i];
2034 
2035  if (mdata && mdata->subscribed)
2036  {
2037  rc = nntp_group_poll(mdata, true);
2038  if (rc < 0)
2039  return -1;
2040  if (rc > 0)
2041  update_active = true;
2042  }
2043  }
2044  }
2045  else if (adata->newgroups_time)
2046  return 0;
2047 
2048  /* get list of new groups */
2049  mutt_message(msg);
2050  if (nntp_date(adata, &now) < 0)
2051  return -1;
2052  tmp_mdata.adata = adata;
2053  if (m && m->mdata)
2054  tmp_mdata.group = ((struct NntpMboxData *) m->mdata)->group;
2055  else
2056  tmp_mdata.group = NULL;
2057  i = adata->groups_num;
2058  struct tm tm = mutt_date_gmtime(adata->newgroups_time);
2059  snprintf(buf, sizeof(buf), "NEWGROUPS %02d%02d%02d %02d%02d%02d GMT\r\n",
2060  tm.tm_year % 100, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
2061  rc = nntp_fetch_lines(&tmp_mdata, buf, sizeof(buf), msg, nntp_add_group, adata);
2062  if (rc)
2063  {
2064  if (rc > 0)
2065  {
2066  mutt_error("NEWGROUPS: %s", buf);
2067  }
2068  return -1;
2069  }
2070 
2071  /* new groups found */
2072  rc = 0;
2073  if (adata->groups_num != i)
2074  {
2075  int groups_num = i;
2076 
2077  adata->newgroups_time = now;
2078  for (; i < adata->groups_num; i++)
2079  {
2080  struct NntpMboxData *mdata = adata->groups_list[i];
2081  mdata->has_new_mail = true;
2082  }
2083 
2084  /* loading descriptions */
2086  {
2087  unsigned int count = 0;
2088  struct Progress progress;
2089 
2090  mutt_progress_init(&progress, _("Loading descriptions..."),
2091  MUTT_PROGRESS_READ, adata->groups_num - i);
2092  for (i = groups_num; i < adata->groups_num; i++)
2093  {
2094  struct NntpMboxData *mdata = adata->groups_list[i];
2095 
2096  if (get_description(mdata, NULL, NULL) < 0)
2097  return -1;
2098  mutt_progress_update(&progress, ++count, -1);
2099  }
2100  }
2101  update_active = true;
2102  rc = 1;
2103  }
2104  if (update_active)
2106  mutt_clear_error();
2107  return rc;
2108 }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ nntp_delete_group_cache()

void nntp_delete_group_cache ( struct NntpMboxData mdata)

Remove hcache and bcache of newsgroup.

Parameters
mdataNNTP Mailbox data

Definition at line 809 of file newsrc.c.

810 {
811  if (!mdata || !mdata->adata || !mdata->adata->cacheable)
812  return;
813 
814 #ifdef USE_HCACHE
815  struct Buffer file = mutt_buffer_make(PATH_MAX);
816  nntp_hcache_namer(mdata->group, &file);
817  cache_expand(file.data, file.dsize, &mdata->adata->conn->account,
818  mutt_buffer_string(&file));
819  unlink(mutt_buffer_string(&file));
820  mdata->last_cached = 0;
821  mutt_debug(LL_DEBUG2, "%s\n", mutt_buffer_string(&file));
822  mutt_buffer_dealloc(&file);
823 #endif
824 
825  if (!mdata->bcache)
826  {
827  mdata->bcache = mutt_bcache_open(&mdata->adata->conn->account, mdata->group);
828  }
829  if (mdata->bcache)
830  {
831  mutt_debug(LL_DEBUG2, "%s/*\n", mdata->group);
833  mutt_bcache_close(&mdata->bcache);
834  }
835 }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ nntp_group_unread_stat()

void nntp_group_unread_stat ( struct NntpMboxData mdata)

Count number of unread articles using .newsrc data.

Parameters
mdataNNTP Mailbox data

Definition at line 134 of file newsrc.c.

135 {
136  mdata->unread = 0;
137  if ((mdata->last_message == 0) ||
138  (mdata->first_message > mdata->last_message) || !mdata->newsrc_ent)
139  {
140  return;
141  }
142 
143  mdata->unread = mdata->last_message - mdata->first_message + 1;
144  for (unsigned int i = 0; i < mdata->newsrc_len; i++)
145  {
146  anum_t first = mdata->newsrc_ent[i].first;
147  if (first < mdata->first_message)
148  first = mdata->first_message;
149  anum_t last = mdata->newsrc_ent[i].last;
150  if (last > mdata->last_message)
151  last = mdata->last_message;
152  if (first <= last)
153  mdata->unread -= last - first + 1;
154  }
155 }
+ Here is the caller graph for this function:

◆ nntp_hash_destructor_t()

void nntp_hash_destructor_t ( int  type,
void *  obj,
intptr_t  data 
)

◆ nntp_hashelem_free()

void nntp_hashelem_free ( int  type,
void *  obj,
intptr_t  data 
)

Free our hash table data - Implements hash_hdata_free_t.

Definition at line 118 of file nntp.c.

119 {
120  nntp_mdata_free(&obj);
121 }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ nntp_hcache_open()

struct HeaderCache* nntp_hcache_open ( struct NntpMboxData mdata)

Open newsgroup hcache.

Parameters
mdataNNTP Mailbox data
Return values
ptrHeader cache
NULLError

Definition at line 710 of file newsrc.c.

711 {
712  struct Url url = { 0 };
713  char file[PATH_MAX];
714 
715  if (!mdata->adata || !mdata->adata->cacheable || !mdata->adata->conn ||
716  !mdata->group || !(mdata->newsrc_ent || mdata->subscribed || C_SaveUnsubscribed))
717  {
718  return NULL;
719  }
720 
721  mutt_account_tourl(&mdata->adata->conn->account, &url);
722  url.path = mdata->group;
723  url_tostring(&url, file, sizeof(file), U_PATH);
725 }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ nntp_hcache_update()

void nntp_hcache_update ( struct NntpMboxData mdata,
struct HeaderCache hc 
)

Remove stale cached headers.

Parameters
mdataNNTP Mailbox data
hcHeader cache

Definition at line 732 of file newsrc.c.

733 {
734  if (!hc)
735  return;
736 
737  char buf[32];
738  bool old = false;
739  anum_t first = 0, last = 0;
740 
741  /* fetch previous values of first and last */
742  size_t dlen = 0;
743  void *hdata = mutt_hcache_fetch_raw(hc, "index", 5, &dlen);
744  if (hdata)
745  {
746  mutt_debug(LL_DEBUG2, "mutt_hcache_fetch index: %s\n", (char *) hdata);
747  if (sscanf(hdata, ANUM " " ANUM, &first, &last) == 2)
748  {
749  old = true;
750  mdata->last_cached = last;
751 
752  /* clean removed headers from cache */
753  for (anum_t current = first; current <= last; current++)
754  {
755  if ((current >= mdata->first_message) && (current <= mdata->last_message))
756  continue;
757 
758  snprintf(buf, sizeof(buf), "%u", current);
759  mutt_debug(LL_DEBUG2, "mutt_hcache_delete_record %s\n", buf);
760  mutt_hcache_delete_record(hc, buf, strlen(buf));
761  }
762  }
763  mutt_hcache_free_raw(hc, &hdata);
764  }
765 
766  /* store current values of first and last */
767  if (!old || (mdata->first_message != first) || (mdata->last_message != last))
768  {
769  snprintf(buf, sizeof(buf), "%u %u", mdata->first_message, mdata->last_message);
770  mutt_debug(LL_DEBUG2, "mutt_hcache_store index: %s\n", buf);
771  mutt_hcache_store_raw(hc, "index", 5, buf, strlen(buf) + 1);
772  }
773 }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ nntp_newsrc_gen_entries()

void nntp_newsrc_gen_entries ( struct Mailbox m)

Generate array of .newsrc entries.

Parameters
mMailbox

Definition at line 298 of file newsrc.c.

299 {
300  if (!m)
301  return;
302 
303  struct NntpMboxData *mdata = m->mdata;
304  anum_t last = 0, first = 1;
305  bool series;
306  enum SortType save_sort = SORT_ORDER;
307  unsigned int entries;
308 
309  if (C_Sort != SORT_ORDER)
310  {
311  save_sort = C_Sort;
312  C_Sort = SORT_ORDER;
314  }
315 
316  entries = mdata->newsrc_len;
317  if (!entries)
318  {
319  entries = 5;
320  mdata->newsrc_ent = mutt_mem_calloc(entries, sizeof(struct NewsrcEntry));
321  }
322 
323  /* Set up to fake initial sequence from 1 to the article before the
324  * first article in our list */
325  mdata->newsrc_len = 0;
326  series = true;
327  for (int i = 0; i < m->msg_count; i++)
328  {
329  struct Email *e = m->emails[i];
330  if (!e)
331  break;
332 
333  /* search for first unread */
334  if (series)
335  {
336  /* We don't actually check sequential order, since we mark
337  * "missing" entries as read/deleted */
338  last = nntp_edata_get(e)->article_num;
339  if ((last >= mdata->first_message) && !e->deleted && !e->read)
340  {
341  if (mdata->newsrc_len >= entries)
342  {
343  entries *= 2;
344  mutt_mem_realloc(&mdata->newsrc_ent, entries * sizeof(struct NewsrcEntry));
345  }
346  mdata->newsrc_ent[mdata->newsrc_len].first = first;
347  mdata->newsrc_ent[mdata->newsrc_len].last = last - 1;
348  mdata->newsrc_len++;
349  series = false;
350  }
351  }
352 
353  /* search for first read */
354  else
355  {
356  if (e->deleted || e->read)
357  {
358  first = last + 1;
359  series = true;
360  }
361  last = nntp_edata_get(e)->article_num;
362  }
363  }
364 
365  if (series && (first <= mdata->last_loaded))
366  {
367  if (mdata->newsrc_len >= entries)
368  {
369  entries++;
370  mutt_mem_realloc(&mdata->newsrc_ent, entries * sizeof(struct NewsrcEntry));
371  }
372  mdata->newsrc_ent[mdata->newsrc_len].first = first;
373  mdata->newsrc_ent[mdata->newsrc_len].last = mdata->last_loaded;
374  mdata->newsrc_len++;
375  }
376  mutt_mem_realloc(&mdata->newsrc_ent, mdata->newsrc_len * sizeof(struct NewsrcEntry));
377 
378  if (save_sort != C_Sort)
379  {
380  C_Sort = save_sort;
382  }
383 }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ nntp_open_connection()

int nntp_open_connection ( struct NntpAccountData adata)

Connect to server, authenticate and get capabilities.

Parameters
adataNNTP server
Return values
0Success
-1Failure

Definition at line 1702 of file nntp.c.

1703 {
1704  struct Connection *conn = adata->conn;
1705  char buf[256];
1706  int cap;
1707  bool posting = false, auth = true;
1708 
1709  if (adata->status == NNTP_OK)
1710  return 0;
1711  if (adata->status == NNTP_BYE)
1712  return -1;
1713  adata->status = NNTP_NONE;
1714 
1715  if (mutt_socket_open(conn) < 0)
1716  return -1;
1717 
1718  if (mutt_socket_readln(buf, sizeof(buf), conn) < 0)
1719  return nntp_connect_error(adata);
1720 
1721  if (mutt_str_startswith(buf, "200"))
1722  posting = true;
1723  else if (!mutt_str_startswith(buf, "201"))
1724  {
1725  mutt_socket_close(conn);
1727  mutt_error("%s", buf);
1728  return -1;
1729  }
1730 
1731  /* get initial capabilities */
1732  cap = nntp_capabilities(adata);
1733  if (cap < 0)
1734  return -1;
1735 
1736  /* tell news server to switch to mode reader if it isn't so */
1737  if (cap > 0)
1738  {
1739  if ((mutt_socket_send(conn, "MODE READER\r\n") < 0) ||
1740  (mutt_socket_readln(buf, sizeof(buf), conn) < 0))
1741  {
1742  return nntp_connect_error(adata);
1743  }
1744 
1745  if (mutt_str_startswith(buf, "200"))
1746  posting = true;
1747  else if (mutt_str_startswith(buf, "201"))
1748  posting = false;
1749  /* error if has capabilities, ignore result if no capabilities */
1750  else if (adata->hasCAPABILITIES)
1751  {
1752  mutt_socket_close(conn);
1753  mutt_error(_("Could not switch to reader mode"));
1754  return -1;
1755  }
1756 
1757  /* recheck capabilities after MODE READER */
1758  if (adata->hasCAPABILITIES)
1759  {
1760  cap = nntp_capabilities(adata);
1761  if (cap < 0)
1762  return -1;
1763  }
1764  }
1765 
1766  mutt_message(_("Connected to %s. %s"), conn->account.host,
1767  posting ? _("Posting is ok") : _("Posting is NOT ok"));
1768  mutt_sleep(1);
1769 
1770 #ifdef USE_SSL
1771  /* Attempt STARTTLS if available and desired. */
1772  if ((adata->use_tls != 1) && (adata->hasSTARTTLS || C_SslForceTls))
1773  {
1774  if (adata->use_tls == 0)
1775  {
1776  adata->use_tls =
1777  C_SslForceTls ||
1779  _("Secure connection with TLS?")) == MUTT_YES) ?
1780  2 :
1781  1;
1782  }
1783  if (adata->use_tls == 2)
1784  {
1785  if ((mutt_socket_send(conn, "STARTTLS\r\n") < 0) ||
1786  (mutt_socket_readln(buf, sizeof(buf), conn) < 0))
1787  {
1788  return nntp_connect_error(adata);
1789  }
1790  // Clear any data after the STARTTLS acknowledgement
1791  mutt_socket_empty(conn);
1792  if (!mutt_str_startswith(buf, "382"))
1793  {
1794  adata->use_tls = 0;
1795  mutt_error("STARTTLS: %s", buf);
1796  }
1797  else if (mutt_ssl_starttls(conn))
1798  {
1799  adata->use_tls = 0;
1800  adata->status = NNTP_NONE;
1801  mutt_socket_close(adata->conn);
1802  mutt_error(_("Could not negotiate TLS connection"));
1803  return -1;
1804  }
1805  else
1806  {
1807  /* recheck capabilities after STARTTLS */
1808  cap = nntp_capabilities(adata);
1809  if (cap < 0)
1810  return -1;
1811  }
1812  }
1813  }
1814 #endif
1815 
1816  /* authentication required? */
1817  if (conn->account.flags & MUTT_ACCT_USER)
1818  {
1819  if (!conn->account.user[0])
1820  auth = false;
1821  }
1822  else
1823  {
1824  if ((mutt_socket_send(conn, "STAT\r\n") < 0) ||
1825  (mutt_socket_readln(buf, sizeof(buf), conn) < 0))
1826  {
1827  return nntp_connect_error(adata);
1828  }
1829  if (!mutt_str_startswith(buf, "480"))
1830  auth = false;
1831  }
1832 
1833  /* authenticate */
1834  if (auth && (nntp_auth(adata) < 0))
1835  return -1;
1836 
1837  /* get final capabilities after authentication */
1838  if (adata->hasCAPABILITIES && (auth || (cap > 0)))
1839  {
1840  cap = nntp_capabilities(adata);
1841  if (cap < 0)
1842  return -1;
1843  if (cap > 0)
1844  {
1845  mutt_socket_close(conn);
1846  mutt_error(_("Could not switch to reader mode"));
1847  return -1;
1848  }
1849  }
1850 
1851  /* attempt features */
1852  if (nntp_attempt_features(adata) < 0)
1853  return -1;
1854 
1855  adata->status = NNTP_OK;
1856  return 0;
1857 }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ C_NewsCacheDir

char* C_NewsCacheDir

Config: (nntp) Directory for cached news articles.

Definition at line 40 of file config.c.

◆ C_Newsrc

char* C_Newsrc

Config: (nntp) File containing list of subscribed newsgroups.

Definition at line 43 of file config.c.

◆ C_NntpAuthenticators

char* C_NntpAuthenticators

Config: (nntp) Allowed authentication methods.

Definition at line 44 of file config.c.

◆ C_NntpContext

short C_NntpContext

Config: (nntp) Maximum number of articles to list (0 for all articles)

Definition at line 45 of file config.c.

◆ C_NntpListgroup

bool C_NntpListgroup

Config: (nntp) Check all articles when opening a newsgroup.

Definition at line 46 of file config.c.

◆ C_NntpLoadDescription

bool C_NntpLoadDescription

Config: (nntp) Load descriptions for newsgroups when adding to the list.

Definition at line 47 of file config.c.

◆ C_NntpPass

char* C_NntpPass

Config: (nntp) Password for the news server.

Definition at line 48 of file config.c.

◆ C_NntpPoll

short C_NntpPoll

Config: (nntp) Interval between checks for new posts.

Definition at line 49 of file config.c.

◆ C_NntpUser

char* C_NntpUser

Config: (nntp) Username for the news server.

Definition at line 50 of file config.c.

◆ C_SaveUnsubscribed

bool C_SaveUnsubscribed

Config: (nntp) Save a list of unsubscribed newsgroups to the 'newsrc'.

Definition at line 52 of file config.c.

◆ C_ShowNewNews

bool C_ShowNewNews

Config: (nntp) Check for new newsgroups when entering the browser.

Definition at line 53 of file config.c.

NntpAccountData::cacheable
bool cacheable
Definition: adata.h:46
C_SslForceTls
bool C_SslForceTls
Config: (ssl) Require TLS encryption for all connections.
Definition: config.c:46
NntpMboxData::unread
anum_t unread
Definition: mdata.h:39
NntpMboxData::group
char * group
Definition: mdata.h:33
mutt_hcache_open
struct HeaderCache * mutt_hcache_open(const char *path, const char *folder, hcache_namer_t namer)
Multiplexor for StoreOps::open.
Definition: hcache.c:322
Connection
An open network connection (socket)
Definition: connection.h:34
mutt_bcache_open
struct BodyCache * mutt_bcache_open(struct ConnAccount *account, const char *mailbox)
Open an Email-Body Cache.
Definition: bcache.c:144
nntp_connect_error
static int nntp_connect_error(struct NntpAccountData *adata)
Signal a failed connection.
Definition: nntp.c:128
ConnAccount::host
char host[128]
Server to login to.
Definition: connaccount.h:53
mdata_find
static struct NntpMboxData * mdata_find(struct NntpAccountData *adata, const char *group)
Find NntpMboxData for given newsgroup or add it.
Definition: newsrc.c:74
mutt_mem_calloc
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:50
NntpAccountData::status
unsigned int status
Definition: adata.h:45
_
#define _(a)
Definition: message.h:28
nntp_add_group
int nntp_add_group(char *line, void *data)
Parse newsgroup.
Definition: newsrc.c:576
Mailbox::emails
struct Email ** emails
Array of Emails.
Definition: mailbox.h:99
mutt_hcache_store_raw
int mutt_hcache_store_raw(struct HeaderCache *hc, const char *key, size_t keylen, void *data, size_t dlen)
store a key / data pair
Definition: hcache.c:584
Buffer
String manipulation buffer.
Definition: buffer.h:33
NntpAccountData::groups_num
unsigned int groups_num
Definition: adata.h:56
Connection::account
struct ConnAccount account
Account details: username, password, etc.
Definition: connection.h:36
mutt_socket_empty
void mutt_socket_empty(struct Connection *conn)
Clear out any queued data.
Definition: socket.c:312
mutt_buffer_dealloc
void mutt_buffer_dealloc(struct Buffer *buf)
Release the memory allocated by a buffer.
Definition: buffer.c:294
nntp_capabilities
static int nntp_capabilities(struct NntpAccountData *adata)
Get capabilities.
Definition: nntp.c:142
C_SslStarttls
unsigned char C_SslStarttls
Config: (ssl) Use STARTTLS on servers advertising the capability.
Definition: config.c:47
cache_expand
static void cache_expand(char *dst, size_t dstlen, struct ConnAccount *cac, const char *src)
Make fully qualified cache file name.
Definition: newsrc.c:521
nntp_edata_get
struct NntpEmailData * nntp_edata_get(struct Email *e)
Get the private data for this Email.
Definition: edata.c:57
mutt_account_tourl
void mutt_account_tourl(struct ConnAccount *cac, struct Url *url)
Fill URL with info from account.
Definition: mutt_account.c:79
NntpMboxData::bcache
struct BodyCache * bcache
Definition: mdata.h:48
ANUM
#define ANUM
Definition: lib.h:73
SortType
SortType
Methods for sorting.
Definition: sort2.h:43
update_file
static int update_file(char *filename, char *buf)
Update file with new contents.
Definition: newsrc.c:392
mutt_socket_close
int mutt_socket_close(struct Connection *conn)
Close a socket.
Definition: socket.c:96
MUTT_YES
@ MUTT_YES
User answered 'Yes', or assume 'Yes'.
Definition: quad.h:40
NntpMboxData::desc
char * desc
Definition: mdata.h:34
LL_DEBUG1
@ LL_DEBUG1
Log at debug level 1.
Definition: logging.h:40
NntpAccountData::groups_list
void ** groups_list
Definition: adata.h:58
FREE
#define FREE(x)
Definition: memory.h:40
C_ShowNewNews
bool C_ShowNewNews
Config: (nntp) Check for new newsgroups when entering the browser.
Definition: config.c:53
get_description
static int get_description(struct NntpMboxData *mdata, const char *wildmat, const char *msg)
Fetch newsgroups descriptions.
Definition: nntp.c:880
mutt_socket_readln
#define mutt_socket_readln(buf, buflen, conn)
Definition: mutt_socket.h:36
Buffer::dsize
size_t dsize
Length of data.
Definition: buffer.h:37
NntpMboxData::first_message
anum_t first_message
Definition: mdata.h:35
PATH_MAX
#define PATH_MAX
Definition: mutt.h:44
mutt_sleep
void mutt_sleep(short s)
Sleep for a while.
Definition: muttlib.c:1448
nntp_group_poll
static int nntp_group_poll(struct NntpMboxData *mdata, bool update_stat)
Check newsgroup for new articles.
Definition: nntp.c:1382
NntpAccountData::conn
struct Connection * conn
Definition: adata.h:60
NntpMboxData::adata
struct NntpAccountData * adata
Definition: mdata.h:46
mutt_hash_find
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
NewsrcEntry::last
anum_t last
Definition: lib.h:90
Email::old
bool old
Email is seen, but unread.
Definition: email.h:50
mutt_progress_init
void mutt_progress_init(struct Progress *progress, const char *msg, enum ProgressType type, size_t size)
Set up a progress bar.
Definition: progress.c:153
query_quadoption
enum QuadOption query_quadoption(enum QuadOption opt, const char *prompt)
Ask the user a quad-question.
Definition: curs_lib.c:518
NNTP_NONE
@ NNTP_NONE
No connection to server.
Definition: private.h:42
NntpAccountData::hasCAPABILITIES
bool hasCAPABILITIES
Definition: adata.h:35
Mailbox::mdata
void * mdata
Driver specific data.
Definition: mailbox.h:136
url_tostring
int url_tostring(struct Url *url, char *dest, size_t len, uint8_t flags)
Output the URL string for a given Url object.
Definition: url.c:418
U_PATH
#define U_PATH
Definition: url.h:49
NntpAccountData::use_tls
unsigned int use_tls
Definition: adata.h:44
Progress
A progress bar.
Definition: progress.h:50
Url
A parsed URL proto://user:password@host:port/path?a=1&b=2
Definition: url.h:67
NntpMboxData::newsrc_len
unsigned int newsrc_len
Definition: mdata.h:44
Mailbox::msg_count
int msg_count
Total number of messages.
Definition: mailbox.h:91
nntp_bcache_delete
static int nntp_bcache_delete(const char *id, struct BodyCache *bcache, void *data)
Remove bcache file - Implements bcache_list_t.
Definition: newsrc.c:780
mutt_clear_error
void mutt_clear_error(void)
Clear the message line (bottom line of screen)
Definition: mutt_logging.c:113
nntp_attempt_features
static int nntp_attempt_features(struct NntpAccountData *adata)
Detect supported commands.
Definition: nntp.c:245
NntpMboxData::last_message
anum_t last_message
Definition: mdata.h:36
mutt_hcache_free_raw
void mutt_hcache_free_raw(struct HeaderCache *hc, void **data)
Multiplexor for StoreOps::free.
Definition: hcache.c:514
C_SaveUnsubscribed
bool C_SaveUnsubscribed
Config: (nntp) Save a list of unsubscribed newsgroups to the 'newsrc'.
Definition: config.c:52
NntpMboxData::newsrc_ent
struct NewsrcEntry * newsrc_ent
Definition: mdata.h:45
mutt_socket_send
#define mutt_socket_send(conn, buf)
Definition: mutt_socket.h:37
MUTT_PROGRESS_READ
@ MUTT_PROGRESS_READ
Progress tracks elements, according to $read_inc
Definition: progress.h:42
nntp_fetch_lines
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:766
mutt_mem_realloc
void mutt_mem_realloc(void *ptr, size_t size)
Resize a block of memory on the heap.
Definition: memory.c:114
mutt_debug
#define mutt_debug(LEVEL,...)
Definition: logging.h:81
mutt_bcache_close
void mutt_bcache_close(struct BodyCache **bcache)
Close an Email-Body Cache.
Definition: bcache.c:165
anum_t
#define anum_t
Definition: lib.h:72
mutt_bcache_list
int mutt_bcache_list(struct BodyCache *bcache, bcache_list_t want_id, void *data)
Find matching entries in the Body Cache.
Definition: bcache.c:330
NewsrcEntry
An entry in a .newsrc (subscribed newsgroups)
Definition: lib.h:87
MUTT_ACCT_USER
#define MUTT_ACCT_USER
User field has been set.
Definition: connaccount.h:43
mutt_buffer_string
static const char * mutt_buffer_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition: buffer.h:77
nntp_mdata_free
void nntp_mdata_free(void **ptr)
Free the private Mailbox data - Implements Mailbox::mdata_free()
Definition: mdata.c:37
ConnAccount::flags
MuttAccountFlags flags
Which fields are initialised, e.g. MUTT_ACCT_USER.
Definition: connaccount.h:59
NntpMboxData::last_loaded
anum_t last_loaded
Definition: mdata.h:37
SORT_ORDER
@ SORT_ORDER
Sort by the order the messages appear in the mailbox.
Definition: sort2.h:50
nntp_group_unread_stat
void nntp_group_unread_stat(struct NntpMboxData *mdata)
Count number of unread articles using .newsrc data.
Definition: newsrc.c:134
mutt_str_replace
char * mutt_str_replace(char **p, const char *s)
Replace one string with another.
Definition: string.c:446
NNTP_BYE
@ NNTP_BYE
Disconnected from server.
Definition: private.h:44
NntpMboxData::acache
struct NntpAcache acache[NNTP_ACACHE_LEN]
Definition: mdata.h:47
NntpMboxData::subscribed
bool subscribed
Definition: mdata.h:40
Email::deleted
bool deleted
Email is deleted.
Definition: email.h:45
NewsrcEntry::first
anum_t first
Definition: lib.h:89
NntpAccountData
NNTP-specific Account data -.
Definition: adata.h:33
mutt_socket_open
int mutt_socket_open(struct Connection *conn)
Simple wrapper.
Definition: socket.c:75
C_Sort
WHERE short C_Sort
Config: Sort method for the index.
Definition: sort.h:60
C_NntpLoadDescription
bool C_NntpLoadDescription
Config: (nntp) Load descriptions for newsgroups when adding to the list.
Definition: config.c:47
mutt_str_remove_trailing_ws
void mutt_str_remove_trailing_ws(char *s)
Trim trailing whitespace from a string.
Definition: string.c:700
C_NewsCacheDir
char * C_NewsCacheDir
Config: (nntp) Directory for cached news articles.
Definition: config.c:40
mutt_hcache_delete_record
int mutt_hcache_delete_record(struct HeaderCache *hc, const char *key, size_t keylen)
Multiplexor for StoreOps::delete_record.
Definition: hcache.c:604
mutt_date_gmtime
struct tm mutt_date_gmtime(time_t t)
Converts calendar time to a broken-down time structure expressed in UTC timezone.
Definition: date.c:661
mailbox_changed
void mailbox_changed(struct Mailbox *m, enum NotifyMailbox action)
Notify observers of a change to a Mailbox.
Definition: mailbox.c:186
Account::adata
void * adata
Private data (for Mailbox backends)
Definition: account.h:43
NntpMboxData::last_cached
anum_t last_cached
Definition: mdata.h:38
C_MarkOld
bool C_MarkOld
Config: Mark new emails as old when leaving the mailbox.
Definition: globals.c:36
NntpEmailData::article_num
anum_t article_num
Definition: edata.h:33
mutt_progress_update
void mutt_progress_update(struct Progress *progress, size_t pos, int percent)
Update the state of the progress bar.
Definition: progress.c:212
Url::path
char * path
Path.
Definition: url.h:74
mutt_hcache_fetch_raw
void * mutt_hcache_fetch_raw(struct HeaderCache *hc, const char *key, size_t keylen, size_t *dlen)
Fetch a message's header from the cache.
Definition: hcache.c:496
Buffer::data
char * data
Pointer to data.
Definition: buffer.h:35
Email
The envelope/body of an email.
Definition: email.h:37
mutt_ssl_starttls
int mutt_ssl_starttls(struct Connection *conn)
Negotiate TLS over an already opened connection.
Definition: gnutls.c:1136
mutt_str_startswith
size_t mutt_str_startswith(const char *str, const char *prefix)
Check whether a string starts with a prefix.
Definition: string.c:160
mutt_message
#define mutt_message(...)
Definition: logging.h:83
NNTP_OK
@ NNTP_OK
Connected to server.
Definition: private.h:43
NNTP_ACACHE_LEN
#define NNTP_ACACHE_LEN
Definition: lib.h:94
NntpAccountData::hasSTARTTLS
bool hasSTARTTLS
Definition: adata.h:36
nntp_date
static int nntp_date(struct NntpAccountData *adata, time_t *now)
Get date and time from server.
Definition: nntp.c:1635
mutt_buffer_make
struct Buffer mutt_buffer_make(size_t size)
Make a new buffer on the stack.
Definition: buffer.c:61
NT_MAILBOX_RESORT
@ NT_MAILBOX_RESORT
Email list needs resorting.
Definition: mailbox.h:174
nntp_active_save_cache
int nntp_active_save_cache(struct NntpAccountData *adata)
Save list of all newsgroups to cache.
Definition: newsrc.c:651
nntp_auth
static int nntp_auth(struct NntpAccountData *adata)
Get login, password and authenticate.
Definition: nntp.c:427
Email::read
bool read
Email is read.
Definition: email.h:51
NntpAccountData::newgroups_time
time_t newgroups_time
Definition: adata.h:54
ConnAccount::user
char user[128]
Username.
Definition: connaccount.h:55
nntp_hcache_namer
static void nntp_hcache_namer(const char *path, struct Buffer *dest)
Compose hcache file names - Implements hcache_namer_t.
Definition: newsrc.c:691
LL_DEBUG2
@ LL_DEBUG2
Log at debug level 2.
Definition: logging.h:41
NntpMboxData
NNTP-specific Mailbox data -.
Definition: mdata.h:31
NntpAcache::path
char * path
Definition: lib.h:81
mutt_error
#define mutt_error(...)
Definition: logging.h:84