Changelog¶
3.3.0 - 2026-11-12¶
Added¶
utils.parse_active_time(),utils.parse_newsgroup_description(),utils.parse_overview_fmt()andutils.parse_number_value()parse LIST ACTIVE.TIMES, LIST NEWSGROUPS, LIST OVERVIEW.FMT and HDR/XHDR/XPAT lines, likeutils.parse_newsgroup()does for LIST ACTIVE (#138).
Changed¶
Methods that return an iterator (
capabilities(),newgroups(),newnews(), thelist_*()methods,listgroup(),hdr()/xhdr()/xzhdr(),xover()/xzver()/over()andxpat()) send their command and read its status line when called, aslist()already did, instead of on the firstnext(). A reply error is raised by the call, and another command issued before the iterator is read raisesNNTPSyncError(#102, #138).
Security¶
Found by go-while.
Response lines longer than
max_line_length(64 KiB including CRLF by default; set it on the class or a client) raiseNNTPDataErrorand mark the connection out of sync, instead of being buffered without limit. This includes lines decompressed from COMPRESS DEFLATE, XFEATURE COMPRESS GZIP and XZVER/XZHDR, which are inflated at most 64 KiB at a time. Reading a long partial line is no longer quadratic (#148).A server answering 480 again after a successful login made the client log in and retry until
RecursionError. The command is now retried once, and a second 480 is raised (#146).login()checks that both AUTHINFO commands fit the 512-octet limit before sending anything. A password that was too long was refused only afterAUTHINFO USERwas sent, and the error contained it. Errors for AUTHINFO commands no longer show their arguments (#147).The default TLS context requires TLS 1.2 or newer. Python leaves the minimum to OpenSSL’s configuration, which may allow TLS 1.0 and 1.1. A given
ssl_contextis used as it is (#142).
Fixed¶
Found by go-while (#102).
3.2.0 added a second message-id pattern requiring
@, which replaced the RFC 3977 one: STAT, NEXT and LAST rejected valid message-ids without@(served by INN withlaxmid), andihave()accepted non-ASCII message-ids and ones over 250 octets. The RFC 3977 pattern is used everywhere again (#141).login()left an unexpected multi-line reply to AUTHINFO unread, so the next command read its data as a reply (#141).An iterator abandoned before
reconnect()no longer marks the new connection broken when it is closed or garbage-collected (#138).An empty line in a LIST NEWSGROUPS response raised
IndexErrorinstead ofNNTPDataError(#138).A LIST ACTIVE.TIMES timestamp too large for
datetimeraisedOverflowErrororOSErrorinstead ofNNTPDataError;utils.parse_epoch()raisesValueErrorfor it (#138).date()raisedNNTPDataErrorwhen the server added text after the date, which RFC 3977 allows (section 3.2), e.g.111 20240102030405 server time(#149).
3.2.0 - 2026-11-09¶
Changed¶
body(decode=True)andarticle(decode=True)raiseNNTPYEncErrorwhen the body has no=ybeginline, instead of returning plain text run through the yEnc decoder (#102).A 480 reply to
mode_reader()or a raw MODE READER is raised instead of logging in and repeating MODE READER, which RFC 4643 2.2 forbids. Calllogin()instead (#102).
Fixed¶
Found by go-while (#102).
An unexpected reply with a multi-line block (e.g. 222 to HEAD, or to the end of a POST) left the block unread, so the next command read a data line as its reply. The block is now read before
NNTPReplyErroris raised.command()only skipped the login before STARTTLS when the verb was exactlySTARTTLS;command(" STARTTLS ")orcommand("", "STARTTLS")still sent the credentials in clear text. Commands are now matched by their first word.A server answering AUTHINFO with 480 made the client log in again recursively, until
RecursionError.After a 480 to MODE READER while connecting, the client logs in and no longer repeats MODE READER (RFC 4643 2.2).
login()rejects a username or password containing CR, LF or NUL before sending anything, and raises rather than sending an emptyAUTHINFO PASS.Command arguments are encoded with the client’s
errorspolicy, so a group name read from LIST ACTIVE with non-UTF-8 bytes can be selected.A failing QUIT at the end of a
withblock no longer replaces the exception raised inside the block..coveragewas committed by mistake; it is now ignored.Text outside a yEnc block, such as a signature after
=yend, was decoded into the data. It is now dropped.yEnc detection needs
=ybeginat the start of the body; a plain body starting with=ybeginners guidewas treated as yEnc and raised.yEnc trailers must have a valid
size=; an invalidcrc32=,pcrc32=orpart=(e.g. 9 hex digits) is reported rather than ignored.XFEATURE COMPRESS GZIP TERMINATOR: when the end of the gzip stream arrived after the decompressed terminator, it was left unread and the next reply failed to parse.
XZVER/XZHDR: a DEFLATE stream that ends early raises
NNTPDataErrorinstead of silently dropping the last, partial row.post()returnedTruefor INN’s240 Article received <id>: the message-id was only looked for in the first word. It is now found anywhere in the reply.STAT, NEXT and LAST reject a negative article number or a missing or malformed message-id; LISTGROUP rejects article numbers below 1.
XHDR by message-id accepts the older
<id> valuerows, giving article number 0 as HDR does.NEWGROUPS and NEWNEWS zero-pad years before 1000 (
%Yis not padded on every platform).
3.1.0 - 2026-11-09¶
Added¶
login()logs in straight away instead of waiting for the server to ask; use it beforecompress()(RFC 4643).
Fixed¶
A 480 reply to STARTTLS no longer makes the client log in, which sent the password in clear text before TLS was set up.
article()detects yEnc from the body only, asbody()does; a “yEnc” Subject no longer forces decoding of a plain body.article()with a malformed article number in its 220 reply reads the article before raisingNNTPDataError, so the connection stays in sync.Only a permanent (5xx) error to LIST OVERVIEW.FMT selects the default overview format. Other errors are raised and the format is retried next time instead of the default being cached.
POST and IHAVE encode headers with the client’s
errorspolicy (surrogateescape), so headers read from an article can be sent back.Status lines must start with exactly three digits, 1xx to 5xx (RFC 3977). Codes such as
0411or+411raiseNNTPProtocolError.
3.0.0 - 2026-11-09¶
Breaking changes¶
The undocumented
PYNNTP_TLS_INSECUREenvironment variable, which disabled certificate checks, is gone. Pass anssl_contextinstead (#123).xpat()yields(article number, header value)likehdr(), not raw lines (#123).xfeature_compress_gzip()returnsNonerather thanTrue(#123).Command lines longer than 512 octets (RFC 3977) raise
ValueErrorinstead of being sent (#123).Requires Python 3.11 or newer; 3.9 and 3.10 are end-of-life (#114).
SSLModeis aStrEnum:str(SSLMode.IMPLICIT)is now"implicit"rather than"SSLMode.IMPLICIT". Comparisons with strings are unchanged (#114).list_active()andnewgroups()returned the low and high water marks swapped; RFC 3977 orders them high, low.Newsgroup.lowandNewsgroup.highare now correct (#111).body()andarticle()check yEnc data against its size and CRC and raiseNNTPYEncErroron a mismatch, instead of returning corrupt data. The decoded data is in the error’sdataattribute (#117).xover()returns “full” fields (such as Xref) without the header name, and keeps trailing empty fields.hdr(),xhdr()andxzhdr()values no longer end in CRLF (#112).post()raisesValueError, before sending anything, for header names or values that could inject headers or end the article (CR, LF or NUL other than a folded line) (#111).Unparseable responses to
date(),newgroups(),list_active(),head()andarticle()raiseNNTPDataErrorrather thanValueError(#118).HeaderDictiterates over plainstrnames (previously case-insensitive name objects), no longer raisesTypeErrorfor non-string names or values, and no longer compares equal to a list of pairs (#110).post()checks the whole body before sending anything: a line with CR or NUL raisesNNTPDataErrorand nothing is posted. Previously the article was posted, cut short before that line (#42).Commands containing CR, LF or NUL (for example in a group name or message-id) raise
ValueErrorinstead of being sent (#42).nntp.fifocontains onlyBytesFifowithwrite,read,readline,len()and iteration (#108).
Added¶
NNTPClient.from_url()connects from a URL such asnntps://user:password@news.example.com(schemesnntp,nntps/snewsandnntp+starttls). The query can settimeoutandreader; keyword arguments override the URL.portdefaults to 563 with implicit TLS (119 otherwise), andtimeoutaccepts a float orNone(#123).ssl_contextargument for TLS settings, such as a private CA (#123).command(..., expect=...)raisesNNTPReplyErrorfor any other reply (#123).HeaderDict,Newsgroup,RangeandSSLModeare exported fromnntp(#123).Type hints are shipped for type checkers (
py.typed), and the LICENSE is included in the sdist and wheel (#123).ihave()for the IHAVE command (#42).compress()for RFC 8054 COMPRESS DEFLATE, compressing the whole connection (#41).over(),stat()andlistgroup()for the RFC 3977 OVER, STAT and LISTGROUP commands (#43, #45, #46).reconnect()reopens the connection with the same settings (#116).NNTPYEncError, andNNTPSyncErrorexported fromnntp(#112, #117).Folded header values in
post()(#111).Tested on Python 3.11 to 3.15, including 3.14 free-threaded (#114, #115).
Fixed¶
An empty XZVER or XZHDR response raised
RuntimeError; it now yields nothing. XZVER/XZHDR trailers are also checked for size, likebody()(#123).unparse_range(True)returned"True"; booleans are now rejected (#123).STARTTLS: data arriving with the 382 reply, before TLS starts, is rejected rather than read later as if protected (#123).
A server asking for a login when no username is set no longer gets a bare
AUTHINFO USER(#123).LIST OVERVIEW.FMTaccepts:fullin any case (#123).Article lines starting with “.” were returned twice, which corrupted yEnc bodies (#107, issue #99).
gzip-compressed responses could be corrupted or hang when the terminator was split across reads (#107).
hdr()always failed: it expected reply 221, but HDR replies 225 (#43).newgroups()andnewnews()always failed: the timestamp used “UTC” where servers require “GMT” (#112).An abandoned or failed response left the connection unusable;
NNTPSyncErrornow says why, andreconnect()recovers (#116).Leaving a
withblock afterclose()orquit()raisedOSError(#112).The socket leaked when connecting failed (#112).
parse_date()accepted dates with extra digits, andparse_headers()failed on LF-only blank lines (#111).yEnc trailers with a CRC of fewer than 8 hex digits were rejected (#107).
Several
IndexErrorcrashes on empty status lines and replies (#112).
Performance¶
yEnc bodies are decoded a block at a time:
body()about 1.8x faster (#123).yEnc decoding about 4x faster (#107).
BytesFifoline reading linear rather than quadratic on large buffers (#108).HeaderDict2-6x faster; XOVER about 1.4x faster end to end (#110, #112).
2.0.1 - 2024-09-29¶
timeout,use_ssl,ssl_modeandreaderare keyword-only inNNTPClientandBaseNNTPClient(#49).
2.0.0 - 2024-09-29¶
Requires Python 3.9 or newer.
timeout,use_sslandreadermust be passed as keyword arguments.Type hints.
STARTTLS and implicit TLS via the
ssl_modeargument.Fixed newsgroup descriptions being truncated at the first space.
Older releases: https://github.com/greenbender/pynntp/releases