View on
MetaCPAN is shutting down
For details read Perl NOC. After June 25th this page will redirect to
Tim Skirvin > newslib > News::Article::Ref



Annotate this POD

View/Report Bugs
Module Version: 0.2   Source  


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 = '<godwin-20020306172310$>';
  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.


Validation Methods

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.

valid_header ( HEADER, CONTENTS )

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.

valid_headers ( HEADERS )

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.

valid_body ( BODY )

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.

valid_article ( ARTICLE )

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.

valid_messageid ( ID )

Determines whether ID is a valid Message-ID, which is of the general form '<>'. Returns 1 if yes, 0 otherwise.

valid_date ( DATE )

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.

valid_from ( ADDRESS )

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:
  Tim Skirvin <> (Tim Skirvin)

Returns 1 if valid, 0 otherwise.

valid_path ( PATH )

Determines if PATH is valid for the Path: header. Takes the form '!!local-form'. Returns 1 if valid, 0 otherwise.

valid_groupname ( GROUPNAME )

Determines if the given GROUPNAME is a valid newsgroup name - letters and numbers only, with '.' as a separator. Returns 1 if valid, 0 otherwise.

valid_newsgroups ( NEWSGROUPS )

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.

valid_subject ( SUBJECT )

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.

valid_control ( LINE )

Determines if LINE is a valid Control: header. This is fairly tricky, because there are many types of control headers:

  cancel MESSAGEID
  newgroup GROUPNAME [moderated|unmoderated]
  rmgroup GROUPNAME

Returns 1 if valid, 0 otherwise.

Create-New-Entry Methods

The following methods can be used to create new data suitable for using in article headers.

create_messageid ( [ PREFIX [, DOMAIN ]] )

Creates a valid message-ID based on PREFIX, DOMAIN, and the current time. Based on add_message_id() from News::Article.

create_date ( [TIME] )

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 <>


This code may be distributed under the same terms as Perl itself.

syntax highlighting: