Net::NNTP(3pm)
okay bestie, this is Net::NNTP(3pm) from the Perl Programmers Reference Guide, and it's literally the NNTP client glow-up you asked for ๐
โจ
๐ธ NAME
Net::NNTP - NNTP Client class
โจ SYNOPSIS
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 yes, bestie, it can do the secure vibe too ๐โจ
The Net::NNTP class is a subclass of Net::Cmd and (depending on availability) of IO::Socket::IP, IO::Socket::INET6 or IO::Socket::INET.
๐ง 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.
%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 thePeerAddroption inIO::Socket::INET, or a reference to an array with hosts to try in turn. Thehostmethod will return the value which was used to connect to the host.Portโ port to connect to. Default is119for plain NNTP and563for immediate SSL (nntps).SSLโ If the connection should be done from start with SSL, contrary to later upgrade withstarttls. You can use SSL arguments as documented inIO::Socket::SSL, but it will usually use the right arguments already.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 toSTDERR.Readerโ If the remote server is INN then initially the connection will be toinnd; by defaultNet::NNTPwill issue aMODE READERcommand so that the remote server becomesnnrpd. If theReaderoption is given with a value of zero, then this command will not be sent and the connection will be left talking toinnd.LocalAddrandLocalPortโ These parameters are passed directly toIO::Socketto allow binding the socket to a specific local address and port.Domainโ This parameter is passed directly toIO::Socketand makes it possible to enforce IPv4 connections even ifIO::Socket::IPis used as super class. AlternativelyFamilycan 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.
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. iykyk, the inheritance is doing main character energy ๐ซถ
๐งธ 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.
๐ฐ 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. no cap, check for that ๐จ
๐ body([{$msgid|$msgnum}[, [$fh]])
Like article but only fetches the body of the article.
๐ท๏ธ head([{$msgid|$msgnum}[, [$fh]])
Like article but only fetches the headers for the article.
๐ชข 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.
๐ 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".
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.
๐ 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.
๐ค 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 ๐ค
โช last()
Set the "current article pointer" to the previous article in the current newsgroup.
Returns the message-id of the article.
๐ฐ๏ธ 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.
๐ authinfo($user, $pass)
Authenticates to the server (using the original AUTHINFO USER / AUTHINFO PASS form, defined in RFC2980) using the supplied username and password.
โ ๏ธ bestie, 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. That is highkey not the vibe for secret passwords ๐
๐ 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.
๐ list()
Obtain information about all the active newsgroups. The result 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. iconic little hash situation, honestly ๐
๐ 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 returned will be limited to those created after $since and, if specified, in one of the distribution areas in $distributions.
๐ฐ 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.
โฉ next()
Set the "current article pointer" to the next article in the current newsgroup.
Returns the message-id of the article.
โ๏ธ 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. periodt, those headers are mandatory ๐ฌ
๐จ๏ธ 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.
๐ slave()
Tell the remote server that I am not a user client, but probably another news server.
๐ช 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 one ghosts you, it's not personal, bestie ๐
newsgroups([$pattern]) ๐ธ
okay so newsgroups hands you back a ref to a hash โ the keys are all the group names that match $pattern, or literally every group if you donโt pass a pattern. each value? thatโs the description text for the group. iconic.
distributions() ๐ซ
returns a ref to a hash where the keys are all the possible distribution names and the values are the distribution descriptions. cute.
distribution_patterns() ๐
returns a ref to an array where each element is itself an array ref with the three fields of a line from the distrib.pats list that some NNTP servers keep: a weight, a wildmat, and a value. the client can use that value to construct a Distribution header. fancy.
subscriptions() ๐ซถ
returns a ref to a list that contains a list of groups recommended for a new user to subscribe to. welcome to the group chat, bestie.
overview_fmt() ๐
returns a ref to an array containing the names of the fields returned by xover. iykyk.
active_times() ๐ฐ๏ธ
returns a ref to a hash where the keys are group names and each value is a ref to an array holding two things: the time the group was created, and an identifier โ possibly an Email address โ of the creator. lore.
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 ref to a hash where the keys are all the group names that match $pattern and each value is the description text for the group. same vibe as newsgroups but xgtitle-coded.
xhdr($header, $message_spec) ๐
obtain the header field $header for all the messages specified.
the return value will be a ref to a hash where the keys are the message numbers and each value contains the text of the requested header for that message. no cap.
xover($message_spec) ๐ฅ
the return value will be a ref to a hash where the keys are the message numbers and each value contains a ref to an array that contains the overview fields for that message.
the names of the fields can be obtained by calling overview_fmt. periodt.
xpath($message_id) ๐ง
returns the path name to the file on the server that contains the specified message. lowkey useful.
xpat($header, $pattern, $message_spec) ๐ฆ
the result is the same as xhdr except itโs restricted to headers where the text of the header matches $pattern. cute.
xrover($message_spec) ๐
the XROVER command returns reference information for the article(s) specified.
returns a ref to a HASH where the keys are the message numbers and the values are the References: lines from the articles. obsessed.
listgroup([$group]) ๐
returns a ref to a list of all the active messages in $group, or the current group if $group is not specified. main character energy.
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 do it and move on, bestie. ๐
๐ซ Unsupported ๐ซ
the following NNTP command are unsupported by the package, and there are no plans to do so. yes, thatโs the original grammar โ weโre keeping it.
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. donโt do the old thing, bestie. ๐
$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.
- an asterisk
*matches any sequence of zero or more characters. - a question mark
?matches any single character. - 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 if it 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 same as the logical not of the third operation, specified the same way as the third but with a caret
^at the beginning of the test string just inside the open square bracket. - 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 withaand ends withd.
โจ EXPORTS โจ
None. literally none. bye.
๐ KNOWN BUGS ๐
See https://rt.cpan.org/Dist/Display.html?Status=Active&Queue=libnet. thatโs the tea.
๐ SEE ALSO ๐
Net::Cmd, IO::Socket::SSL. go read those too, bestie.
๐ 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 ยฉ๏ธ
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. periodt.
๐ข VERSION ๐ข
Version 3.15.
๐ DATE ๐
20 March 2023.
๐ฐ๏ธ HISTORY ๐ฐ๏ธ
See the Changes file.
๐ and thatโs the whole page, bestie โ source/version perl v5.42.3, dated 2026-11-03, for Net::NNTP(3pm). slay. ๐
๐ฆ where this page comes from
- alpine 3.24: perl-doc 5.42.3-r0 ยท Artistic-1.0-Perl OR GPL-1.0-or-later
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms