Documentation
¶
Overview ¶
Package nntp implements a dependency-free NNTP (Usenet) read client following RFC 3977. It uses only the Go standard library (CGO_ENABLED=0) and speaks the command/response protocol over net/textproto.
The client is intended for reading: connecting, authenticating, selecting groups, listing overviews, fetching articles and enumerating newsgroups.
Index ¶
- type Article
- type Conn
- func (c *Conn) Article(msgIDorNum string) (*Article, error)
- func (c *Conn) Authenticate(user, pass string) error
- func (c *Conn) Capabilities() ([]string, error)
- func (c *Conn) Close() error
- func (c *Conn) Group(name string) (*Group, error)
- func (c *Conn) HasCapability(name string) bool
- func (c *Conn) Legacy() bool
- func (c *Conn) List(wildmat string) ([]NewsgroupInfo, error)
- func (c *Conn) ModeReader() error
- func (c *Conn) Over(low, high int) ([]Overview, error)
- type Group
- type NewsgroupInfo
- type Overview
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Conn ¶
type Conn struct {
// contains filtered or unexported fields
}
Conn is a connection to an NNTP server. It wraps a *textproto.Conn layered over the underlying net.Conn. A Conn is not safe for concurrent use.
Conn transparently bridges legacy NNRP servers (which predate RFC 3977 and reject CAPABILITIES) and modern servers (INN and the like). Capability negotiation is performed lazily and cached; see Capabilities, HasCapability and Legacy.
func Dial ¶
Dial connects (plaintext) to addr ("host:port"); if no port is present the default NNTP port 119 is used. The greeting is read and validated.
func DialTLS ¶
DialTLS connects with implicit TLS to addr; if no port is present the default NNTPS port 563 is used. tlsConfig may be nil, in which case the platform defaults are used.
func (*Conn) Article ¶
Article fetches a full article by message-id ("<...>") or by article number, using the ARTICLE command. Headers are split from the body on the first blank line and canonicalized.
func (*Conn) Authenticate ¶
Authenticate performs AUTHINFO USER/PASS authentication.
func (*Conn) Capabilities ¶ added in v0.2.0
Capabilities issues the CAPABILITIES command (RFC 3977 §5.2) and returns the raw capability lines advertised by the server (for example "VERSION 2", "AUTHINFO USER", "COMPRESS DEFLATE").
Legacy servers that predate RFC 3977 reject the command with 500, 501 or 480 (authentication required first). That is not treated as an error: Capabilities then returns an empty slice with a nil error and the connection enters legacy mode (see Legacy). The negotiated set is cached and reused by HasCapability and Legacy; it is refreshed after a successful AUTHINFO exchange, since a server may advertise different capabilities once the client is authenticated.
func (*Conn) Group ¶
Group selects the named newsgroup and returns its estimated article count and low/high water marks, parsed from a "211 count low high name" response.
func (*Conn) HasCapability ¶ added in v0.2.0
HasCapability reports whether the server advertised the named capability (matched case-insensitively against the first token of each capability line, e.g. "OVER", "HDR", "READER", "POST", "AUTHINFO", "COMPRESS"). It negotiates lazily on first use and returns false in legacy mode or if negotiation fails.
func (*Conn) Legacy ¶ added in v0.2.0
Legacy reports whether the server does not implement CAPABILITIES (RFC 3977) and is therefore driven in legacy NNRP mode. It negotiates lazily on first use.
func (*Conn) List ¶
func (c *Conn) List(wildmat string) ([]NewsgroupInfo, error)
List returns the available newsgroups via LIST ACTIVE. If wildmat is non-empty it is passed to the server to filter the result.
func (*Conn) ModeReader ¶ added in v0.2.0
ModeReader issues MODE READER (RFC 3977 §5.3), which some servers require before they enable reader commands. A 200 (posting allowed) or 201 (posting prohibited) reply is a success. Servers that do not implement the command answer 500/501; that is tolerated and treated as a no-op success, so calling ModeReader is always safe, including on servers that already greet in reader mode. Dial does not send MODE READER automatically, to preserve the exact on-the-wire behaviour existing callers rely on; call it explicitly when targeting a server that gates reader commands behind it.
func (*Conn) Over ¶
Over returns the overview (header summaries) for the inclusive article range low-high in the currently selected group. It uses the RFC 3977 OVER command and, if the server rejects it as unknown (500/501), transparently falls back to the legacy XOVER command, which has an identical response format.
type NewsgroupInfo ¶
NewsgroupInfo describes an available newsgroup as listed by LIST ACTIVE.
