Net::NNTP(3perl)

okay bestie, welcome to the Net::NNTP glow-up from the Perl Programmers Reference Guide, section 3perl ๐Ÿ‘‘. This is your group-chat guide to talking to NNTP servers, and yes, we're keeping every single technical crumb, because facts are sacred and vibes are immaculate ๐Ÿ’….

โœจ NAME โœจ

Net::NNTP โ€” NNTP Client class ๐Ÿฆ‹

๐ŸŒˆ SYNOPSIS ๐ŸŒˆ

Here's the tea, in code form โ˜•:

use Net::NNTP;

$nntp = Net::NNTP->new("some.host.name");
$nntp->quit;

# start with SSL, e.g. nntps
$nntp = Net::NNTP->new("some.host.name", SSL => 1);

# start with plain and upgrade to SSL
$nntp = Net::NNTP->new("some.host.name");
$nntp->starttls;

๐Ÿ’– DESCRIPTION ๐Ÿ’–

Net::NNTP is a class implementing a simple NNTP client in Perl as described in RFC977 and RFC4642. With IO::Socket::SSL installed it also provides support for implicit and explicit TLS encryption, i.e. NNTPS or NNTP+STARTTLS. So like, it can do the secure thing and the upgrade thing, periodt ๐Ÿ”.

The Net::NNTP class is a subclass of Net::Cmd and (depending on avaibility) of IO::Socket::IP, IO::Socket::INET6 or IO::Socket::INET. Yes, "avaibility" โ€” we don't fix typos in this house, we honor them ๐Ÿ™ˆ.

๐ŸŽ€ Class Methods ๐ŸŽ€

๐ŸŒธ new([$host][, %options]) ๐ŸŒธ

This is the constructor for a new Net::NNTP object. $host is the name of the remote host to which a NNTP connection is required. If not given then it may be passed as the Host option described below. If no host is passed then two environment variables are checked, first NNTPSERVER then NEWSHOST, then Net::Config is checked, and if a host is not found then news is used. The fallback chain is giving "we'll find somebody, don't worry" ๐Ÿ˜Œ.

%options are passed in a hash like fashion, using key and value pairs. Possible options are:

  • Host โ€” NNTP host to connect to. It may be a single scalar, as defined for the PeerAddr option in IO::Socket::INET, or a reference to an array with hosts to try in turn. The host method will return the value which was used to connect to the host. So if you gave it a list, it tells you which one actually picked up the phone ๐Ÿ“ž.
  • Port โ€” port to connect to. Default - 119 for plain NNTP and 563 for immediate SSL (nntps). 119 for the unbothered era, 563 for the secure era ๐Ÿ”’.
  • SSL โ€” If the connection should be done from start with SSL, contrary to later upgrade with starttls. You can use SSL arguments as documented in IO::Socket::SSL, but it will usually use the right arguments already. It's giving "I already know what I'm doing" ๐Ÿ’….
  • Timeout โ€” Maximum time, in seconds, to wait for a response from the NNTP server, a value of zero will cause all IO operations to block. (default: 120)
  • Debug โ€” Enable the printing of debugging information to STDERR
  • Reader โ€” If the remote server is INN then initially the connection will be to innd, by default Net::NNTP will issue a MODE READER command so that the remote server becomes nnrpd. If the Reader option is given with a value of zero, then this command will not be sent and the connection will be left talking to innd. So Reader => 0 is the "don't switch, I'm good" option โœ‹.
  • LocalAddr and LocalPort โ€” These parameters are passed directly to IO::Socket to allow binding the socket to a specific local address and port.
  • Domain โ€” This parameter is passed directly to IO::Socket and makes it possible to enforce IPv4 connections even if IO::Socket::IP is used as super class. Alternatively Family can be used.

๐Ÿฆ‹ Object Methods ๐Ÿฆ‹

Unless otherwise stated all methods return either a true or false value, with true meaning that the operation was a success. When a method states that it returns a value, failure will be returned as undef or an empty list. So true = slay, false/undef/empty = it didn't eat ๐Ÿ˜ญ.

Net::NNTP inherits from Net::Cmd so methods defined in Net::Cmd may be used to send commands to the remote NNTP server in addition to the methods documented here. Inheritance is real, bestie ๐Ÿงฌ.

host()

Returns the value used by the constructor, and passed to IO::Socket::INET, to connect to the host.

starttls()

Upgrade existing plain connection to SSL. Any arguments necessary for SSL must be given in new already. So don't try to sneak SSL args in here, they had to be there from the start, no cap ๐Ÿšซ.

article([{$msgid|$msgnum}[, $fh]])

Retrieve the header, a blank line, then the body (text) of the specified article.

If $fh is specified then it is expected to be a valid filehandle and the result will be printed to it, on success a true value will be returned. If $fh is not specified then the return value, on success, will be a reference to an array containing the article requested, each entry in the array will contain one line of the article.

If no arguments are passed then the current article in the currently selected newsgroup is fetched.

$msgnum is a numeric id of an article in the current newsgroup, and will change the current article pointer. $msgid is the message id of an article as shown in that article's header. It is anticipated that the client will obtain the $msgid from a list provided by the newnews command, from references contained within another article, or from the message-id provided in the response to some other commands.

If there is an error then undef will be returned. So like, if it's not giving, you get undef ๐Ÿ’€.

body([{$msgid|$msgnum}[, [$fh]])

Like article but only fetches the body of the article. Just the body, not the whole meal ๐Ÿ“.

head([{$msgid|$msgnum}[, [$fh]])

Like article but only fetches the headers for the article. Just the header, the intro card ๐Ÿ’Œ.

articlefh([{$msgid|$msgnum}])

bodyfh([{$msgid|$msgnum}])

headfh([{$msgid|$msgnum}])

These are similar to article(), body() and head(), but rather than returning the requested data directly, they return a tied filehandle from which to read the article. Tied filehandle? Lowkey iconic, you read it like a file ๐Ÿ“–.

nntpstat([{$msgid|$msgnum}])

The nntpstat command is similar to the article command except that no text is returned. When selecting by message number within a group, the nntpstat command serves to set the "current article pointer" without sending text.

Using the nntpstat command to select by message-id is valid but of questionable value, since a selection by message-id does not alter the "current article pointer". So it works, but it's giving "why though?" ๐Ÿค”.

Returns the message-id of the "current article".

group([$group])

Set and/or get the current group. If $group is not given then information is returned on the current group.

In a scalar context it returns the group name.

In an array context the return value is a list containing, the number of articles in the group, the number of the first article, the number of the last article and the group name. Context really said "I contain multitudes" โœจ.

help()

Request help text (a short summary of commands that are understood by this implementation) from the server. Returns the text or undef upon failure. The server's little cheat sheet, bestie ๐Ÿ“.

ihave($msgid[, $message])

The ihave command informs the server that the client has an article whose id is $msgid. If the server desires a copy of that article and $message has been given then it will be sent.

Returns true if the server desires the article and $message was successfully sent, if specified.

If $message is not specified then the message must be sent using the datasend and dataend methods from Net::Cmd

$message can be either an array of lines or a reference to an array and must be encoded by the caller to octets of whatever encoding is required, e.g. by using the Encode module's encode() function. Encoding is on you, no cap ๐Ÿงฌ.

last()

Set the "current article pointer" to the previous article in the current newsgroup.

Returns the message-id of the article. Back it up, back it up ๐Ÿ”™.

date()

Returns the date on the remote server. This date will be in a UNIX time format (seconds since 1970)

postok()

postok will return true if the servers initial response indicated that it will allow posting. So it's the vibe check for "can I post?" โœ….

authinfo($user, $pass)

Authenticates to the server (using the original AUTHINFO USER / AUTHINFO PASS form, defined in RFC2980) using the supplied username and password. Please note that the password is sent in clear text to the server. This command should not be used with valuable passwords unless the connection to the server is somehow protected. โš ๏ธ Clear text, bestie! Do not send your precious password into the void unless the connection is protected, fr fr.

authinfo_simple($user, $pass)

Authenticates to the server (using the proposed NNTP V2 AUTHINFO SIMPLE form, defined and deprecated in RFC2980) using the supplied username and password. As with authinfo the password is sent in clear text. Also deprecated, so it's giving "vintage, but maybe not in the good way" ๐Ÿ•ฐ๏ธ.

list()

Obtain information about all the active newsgroups. The results is a reference to a hash where the key is a group name and each value is a reference to an array. The elements in this array are:- the last article number in the group, the first article number in the group and any information flags about the group. So hash of arrays, very demure, very mindful ๐ŸŽ€.

newgroups($since[, $distributions])

$since is a time value and $distributions is either a distribution pattern or a reference to a list of distribution patterns. The result is the same as list, but the groups return will be limited to those created after $since and, if specified, in one of the distribution areas in $distributions. Fresh groups only, filtered by time and distribution โœจ.

newnews($since[, $groups[, $distributions]])

$since is a time value. $groups is either a group pattern or a reference to a list of group patterns. $distributions is either a distribution pattern or a reference to a list of distribution patterns.

Returns a reference to a list which contains the message-ids of all news posted after $since, that are in a groups which matched $groups and a distribution which matches $distributions. It's the "what's new, pussycat?" but for NNTP ๐Ÿฑ.

next()

Set the "current article pointer" to the next article in the current newsgroup.

Returns the message-id of the article. Onward, bestie โžก๏ธ.

post([$message])

Post a new article to the news server. If $message is specified and posting is allowed then the message will be sent.

If $message is not specified then the message must be sent using the datasend and dataend methods from Net::Cmd

$message can be either an array of lines or a reference to an array and must be encoded by the caller to octets of whatever encoding is required, e.g. by using the Encode module's encode() function.

The message, either sent via datasend or as the $message parameter, must be in the format as described by RFC822 and must contain From:, Newsgroups: and Subject: headers. No From:, Newsgroups:, and Subject:? It's not posting, periodt ๐Ÿ“ฎ.

postfh()

Post a new article to the news server using a tied filehandle. If posting is allowed, this method will return a tied filehandle that you can print() the contents of the article to be posted. You must explicitly close() the filehandle when you are finished posting the article, and the return value from the close() call will indicate whether the message was successfully posted. Close it yourself, bestie โ€” the close() return value is the receipt ๐Ÿงพ.

slave()

Tell the remote server that I am not a user client, but probably another news server. Not like that, it's a protocol thing ๐Ÿ’€.

quit()

Quit the remote server and close the socket connection.

can_inet6()

Returns whether we can use IPv6.

can_ssl()

Returns whether we can use SSL.

๐Ÿš€ Extension Methods ๐Ÿš€

These methods use commands that are not part of the RFC977 documentation. Some servers may not support all of them. So if your server is giving "never heard of her", that's why ๐Ÿ™ˆ.

newsgroups([$pattern])

okay so this one hands you back a reference to a hash, right? The keys are all the group names that match $pattern, or literally all of the groups if you don't pass a pattern. And each value is the description text for that group. it's giving directory vibes โœจ

distributions()

Returns a reference to a hash. Keys = all the possible distribution names. Values = the distribution descriptions. lowkey useful for knowing what distributions exist ๐Ÿ’…

distribution_patterns()

Returns a reference to an array. Each element is itself an array reference, and it has the three fields of a line from the distrib.pats list that some NNTP servers maintain. Those three fields are: a weight, a wildmat, and a value. The client may use that value to construct a Distribution header. periodt.

subscriptions()

Returns a reference to a list. The list contains groups that are recommended for a new user to subscribe to. it's giving starter pack energy ๐ŸŽ€

overview_fmt()

Returns a reference to an array which contains the names of the fields returned by "xover". basically tells you what columns you're gonna get from xover ๐ŸŒธ

active_times()

Returns a reference to a hash. Keys = group names. Each value = a reference to an array containing the time the group was created and an identifier (possibly an Email address) of the creator. no cap.

active([$pattern])

Similar to "list" but only active groups that match the pattern are returned. $pattern can be a group pattern. slay.

xgtitle($pattern)

Returns a reference to a hash. Keys = all the group names which match $pattern. Values = the description text for the group. it's the same vibe as newsgroups but with a pattern? actually yes.

"xhdr($header, $message_spec)"

Obtain the header field $header for all the messages specified.

The return value will be a reference to a hash where the keys are the message numbers and each value contains the text of the requested header for that message. iconic.

xover($message_spec)

The return value will be a reference to a hash where the keys are the message numbers and each value contains a reference to an array which contains the overview fields for that message.

The names of the fields can be obtained by calling overview_fmt. bestie that's the cheat code ๐Ÿ”ฅ

xpath($message_id)

Returns the path name to the file on the server which contains the specified message. literally the path.

"xpat($header, $pattern, $message_spec)"

The result is the same as "xhdr" except it will be restricted to headers where the text of the header matches $pattern. so xhdr but with a pattern filter โœจ

xrover($message_spec)

The XROVER command returns reference information for the article(s) specified.

Returns a reference to a HASH where the keys are the message numbers and the values are the References: lines from the articles. hashtag HASH energy ๐Ÿ’…

listgroup([$group])

Returns a reference to a list of all the active messages in $group, or the current group if $group is not specified. got it.

reader()

Tell the server that you are a reader and not another server.

This is required by some servers. For example if you are connecting to an INN server and you have transfer permission your connection will be connected to the transfer daemon, not the NNTP daemon. Issuing this command will cause the transfer daemon to hand over control to the NNTP daemon.

Some servers do not understand this command, but issuing it and ignoring the response is harmless. so like, try it, it's fine ๐Ÿ™ˆ


Unsupported ๐Ÿšซ

The following NNTP command are unsupported by the package, and there are no plans to do so.

AUTHINFO GENERIC
XTHREAD
XSEARCH
XINDEX

Definitions ๐Ÿ“–

$message_spec

$message_spec is either a single message-id, a single message number, or a reference to a list of two message numbers.

If $message_spec is a reference to a list of two message numbers and the second number in a range is less than or equal to the first then the range represents all messages in the group after the first message number.

NOTE: For compatibility reasons only with earlier versions of Net::NNTP a message spec can be passed as a list of two numbers, this is deprecated and a reference to the list should now be passed.

$pattern

The "NNTP" protocol uses the "WILDMAT" format for patterns. The WILDMAT format was first developed by Rich Salz based on the format used in the UNIX find command to articulate file names. It was developed to provide a uniform mechanism for matching patterns in the same manner that the UNIX shell matches filenames.

Patterns are implicitly anchored at the beginning and end of each string when testing for a match.

There are five pattern matching operations other than a strict one-to-one match between the pattern and the source to be checked for a match.

The first is an asterisk "*" to match any sequence of zero or more characters.

The second is a question mark "?" to match any single character. The third specifies a specific set of characters.

The set is specified as a list of characters, or as a range of characters where the beginning and end of the range are separated by a minus (or dash) character, or as any combination of lists and ranges. The dash can also be included in the set as a character it if is the beginning or end of the set. This set is enclosed in square brackets. The close square bracket "]" may be used in a set if it is the first character in the set.

The fourth operation is the same as the logical not of the third operation and is specified the same way as the third with the addition of a caret character "^" at the beginning of the test string just inside the open square bracket.

The final operation uses the backslash character to invalidate the special meaning of an open square bracket "[", the asterisk, backslash or the question mark. Two backslashes in sequence will result in the evaluation of the backslash as a character with no special meaning.

Examples

  • "[^]-]" โ€” matches any single character other than a close square bracket or a minus sign/dash.
  • *bdc โ€” matches any string that ends with the string "bdc" including the string "bdc" (without quotes).
  • "[0-9a-zA-Z]" โ€” matches any single printable alphanumeric ASCII character.
  • "a??d" โ€” matches any four character string which begins with a and ends with d.

โœจ EXPORTS โœจ

None.


๐Ÿ’€ KNOWN BUGS ๐Ÿ’€

See <https://rt.cpan.org/Dist/Display.html?Status=Active&Queue=libnet>.


๐Ÿ‘€ SEE ALSO ๐Ÿ‘€

Net::Cmd, IO::Socket::SSL.


โœ๏ธ AUTHOR โœ๏ธ

Graham Barr <gbarr@pobox.com <mailto:gbarr@pobox.com>>.

Steve Hay <shay@cpan.org <mailto:shay@cpan.org>> is now maintaining libnet as of version 1.22_02.


Copyright (C) 1995-1997 Graham Barr. All rights reserved.

Copyright (C) 2013-2016, 2020 Steve Hay. All rights reserved.


๐Ÿ“œ LICENCE ๐Ÿ“œ

This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself, i.e. under the terms of either the GNU General Public License or the Artistic License, as specified in the LICENCE file.


๐Ÿ”ข VERSION ๐Ÿ”ข

Version 3.15


๐Ÿ“… DATE ๐Ÿ“…

20 March 2023


๐Ÿ“š HISTORY ๐Ÿ“š

See the Changes file.


okay bestie that's the whole entire page ๐Ÿ’– this was Net::NNTP(3perl) from perl v5.44.0, dated 2026-10-17 โ€” slay and goodbye โœจ

๐Ÿ“ฆ where this page comes from
  • arch rolling: perl 5.44.0-1 ยท Artistic-1.0-Perl AND GPL-1.0-or-later
  • ๐Ÿ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms