News::Article::Ref - reference functions for news articles
use News::Article::Ref; my $date = "Wed, 06 Mar 2002 11:23:10 -0600"; my $gooddate = News::Article::Ref->valid_date($date); my $messageid = '<email@example.com>'; my $goodmid = News::Article::Ref->valid_messageid($messageid);
Further functions are below.
News::Article::Ref is a module for determining if a news article is technically suited for Usenet - ie, it checks to see if it follows all of Usenet's technical rules, as set down in the RFCs. This is useful for moderation 'bots and other news processing.
The current specifications are based on a combination of RFC1036 and RFC1036bis. This probably isn't the best idea, but it works for now.
News::Article::Ref exports nothing.
The following methods validate the information already in a header - ie, they check to see if it's valid with current Usenet specifications. This may be more or less restrictive than any given news server will require, but it's a good general rule to follow the rules regardless.
Verifies that the CONTENTS of HEADER are valid. Checks From, Subject, Newsgroups, Message-ID, Path, Date, Followup-to, Expires, Reply-To, Sender, References, Control, Distribution, Summary, Approved, Lines, Organization, and Supersedes; all other headers are assumed to be unnecessary but okay.
Note that many of these functions are available below.
Takes an array of headers HEADERS, and verifies that together they make up a valid set of headers for a news article. This means, in general, that each header is valid, and that enough headers are there to be posted. Takes advantage of valid_headers(). Returns 1 if valid, 0 otherwise.
Verifies that BODY is a valid message body for the article. Currently just checks to make sure that there *is* a body; this may change later. Returns 1 if valid, 0 otherwise.
Takes a whole ARTICLE as input, and does both verify_headers() and verify_body() on it. Returns 1 if the article is valid, 0 otherwise.
Determines whether ID is a valid Message-ID, which is of the general form '<firstname.lastname@example.org>'. Returns 1 if yes, 0 otherwise.
Determines whether DATE is a valid Date header, which is of the general form 'Wed, 06 Mar 2002 11:23:10 -0600'. Returns 1 if yes, 0 otherwise.
Verifies that the email address is "valid" - not that it delivers, but that it follows the proper form. ADDRESS can take one of three forms:
email@example.com Tim Skirvin <firstname.lastname@example.org> email@example.com (Tim Skirvin)
Returns 1 if valid, 0 otherwise.
Determines if PATH is valid for the Path: header. Takes the form 'news.meat.net!news.killfile.org!local-form'. Returns 1 if valid, 0 otherwise.
Determines if the given GROUPNAME is a valid newsgroup name - letters and numbers only, with '.' as a separator. Returns 1 if valid, 0 otherwise.
Determines of NEWSGROUPS is a valid Newsgroups: header - each group name must be separated by only a comma, and new groups can be repeated. Returns 1 if valid, 0 otherwise.
Determines if SUBJECT is a valid subject header. This isn't too tough - it just has to be not blank. Returns 1 if valid, 0 otherwise.
Determines if LINE is a valid Control: header. This is fairly tricky, because there are many types of control headers:
cancel MESSAGEID ihave MESSAGEID [HOST] sendme MESSAGEID [HOST] newgroup GROUPNAME [moderated|unmoderated] rmgroup GROUPNAME sendsys version checkgroups
Returns 1 if valid, 0 otherwise.
The following methods can be used to create new data suitable for using in article headers.
Creates a valid message-ID based on PREFIX, DOMAIN, and the current time. Based on add_message_id() from News::Article.
Creates a valid Date: header from TIME (seconds since the epoch), or the current time if not offered. Based on add_date() from News::Article.
Put some clean_* functions somewhere - ie clean_date(), which would make a canonical date header for the article based on whatever it's offered. This wouldn't necessarily go in this module, though.
Include some debugging information, so that the user can determine *how* there were problems. This will involve some major re-writes.
Choose which RFC to follow.
Tim Skirvin <firstname.lastname@example.org>
This code may be distributed under the same terms as Perl itself.