home *** CD-ROM | disk | FTP | other *** search
/ Freelog Special Edition 1: Linux / CD1.iso / doc / HOWTO / mini / Mail2News < prev    next >
Text File  |  1998-10-14  |  12KB  |  307 lines

  1.   Mail2News Mini-Howto
  2.   Robert Hart, InterWeft IT Consultants Melbourne, Australia
  3.   iweft@ipax.com.au
  4.   v1.0, 4 November 1996
  5.  
  6.   This document describes how to set up your news server and the
  7.   mail2news.pl software to link mailing lists to local news groups.
  8.  
  9.   1.  Copyright and such
  10.  
  11.   The copyright of this document is retained by the author. Permission
  12.   is granted to distribute the document by electronic means and on CDs
  13.   provided that it is kept entirely in its original format. Permission
  14.   is also granted to print a copy of this document for personal use.
  15.  
  16.   The republishing of this document in part or in whole without the
  17.   permission of the copyright holder by any means other than as noted
  18.   above is prohibited.
  19.  
  20.   This document is directly supported by InterWeft IT Consultants
  21.   (Melbourne, Australia).
  22.  
  23.   The latest version of this document is available at the InterWeft WWW
  24.   site at InterWeft IT Consultants <http://203.29.72.65/>.
  25.  
  26.   2.  Introduction
  27.  
  28.   Most Internet sites are always seeking ways to improve the usage of
  29.   the limited bandwidth awailable across their link to the Internet.
  30.  
  31.   Should more than one user subscribe to the same mailing list, there is
  32.   going to be traffic duplication. If there are a number of such
  33.   duplications - or the traffic on the lists is high, the consumption of
  34.   bandwidth increases.
  35.  
  36.   By subscribing the site to a list (if this is allowed by the list
  37.   owner) and 'gating' the email traffic to the local news server, it is
  38.   possible to make mailing lists accessible to all site users, or, using
  39.   the security features of 'innd', to limit the access to certain users.
  40.  
  41.   Such a site subscription (particularly if there are a number of high
  42.   traffic lists) can make worthwhile savings in bandwidth usage.
  43.  
  44.   Reading list traffic in news reader also offers users the advantages
  45.   of threading (which is not available in many mail user agents) and
  46.   keeps their mail 'inbox' free for possibly more urgent, personal
  47.   email.
  48.  
  49.   This mini-HOWTO describes setting up the 'mail2news.pl' script to
  50.   accomplish this.
  51.  
  52.   2.1.  Finding mail2news.pl
  53.  
  54.   The author has been unable to find mail2news.pl on CPAN (the
  55.   Comprehensive Perl Archive Network) - but it may just have been
  56.   overlooked. It is however on sunsite.unc.edu - somewhere - and also on
  57.   ftp.redhat.com.
  58.  
  59.   As this Perl script is not lengthy, it is appended to this howto.
  60.  
  61.   3.  Overview of the system
  62.  
  63.   It is probably easiest to understand how this system works by tracking
  64.   a message from the mailing list to the newsgroup and then a message
  65.   posted to the local newsgroup (gated to the mailing list) and see how
  66.   they are handled.
  67.  
  68.   3.1.  Mail from the mailing list
  69.  
  70.   Mail from the mailing list is sent to all subscribed mail addresses. A
  71.   special mail alias is subscribed to the mailing list in question and
  72.   so all traffic to and from the list is sent by the list server to this
  73.   address.
  74.  
  75.   When mail from the mailing list arrives at the local machine, the mail
  76.   alias pipes the incoming message to mail2news.pl. The mail alias also
  77.   specifies the destination (local) newsgroup.
  78.  
  79.   The mail2news.pl script processes the message, applying news headers
  80.   and then uses rnews or inews to post the message to the newsgroup.
  81.  
  82.   3.2.  Messages posted to the local newsgroup
  83.  
  84.   The local newsgroup is set up as a moderated group, as this allows us
  85.   to take advantage of the email capabilities of innd. Any messages
  86.   posted to a moderated group are not immediately submitted to the
  87.   group. Instead, messages are emailed to the moderator of the group.
  88.  
  89.   By declaring the moderator of the local newsgroup to be mailing list
  90.   address, all locally posted messages to the newsgroup are
  91.   automatically mailed out to the mailing list by innd and only appear
  92.   once they have been received back through mail2news.pl which adds the
  93.   necessary 'approved' line to the messages and are thus acceptable to
  94.   innd for posting to the newsgroup.
  95.  
  96.   4.  Setting up mail2news
  97.  
  98.   Put the mail2news.pl script in a suitable location. I favour
  99.   /usr/local/scripts, but the location is up to you.
  100.  
  101.   You will need to edit script as follows:-
  102.  
  103.   ╖  At the top of the script, make sure you are pointing at the local
  104.      Perl binary
  105.  
  106.      ___________________________________________________________________
  107.      #!/usr/bin/perl
  108.      # point at the correct location of perl
  109.      ___________________________________________________________________
  110.  
  111.   ╖  I had problems with the three following lines. Commenting them out
  112.      does not cause a problem.
  113.  
  114.      ___________________________________________________________________
  115.      ( $version  ) = $] =~ /(\d+\.\d+).*\nPatch level/;
  116.      die "$program: requires at least version 3 of perl\n"
  117.              if $version < 3;
  118.      ___________________________________________________________________
  119.  
  120.   ╖  Edit the following lines to point at the posting program (I use
  121.      rnews) and you news host:-
  122.  
  123.      ___________________________________________________________________
  124.      # $inews = "/usr/bin/inews";
  125.      # $iopts = "-h -o \"mail2news gateway\"";
  126.      $inews = "/usr/bin/rnews";
  127.      $iopts = "";
  128.      $postinghost = "your.news.server";   # points at your news server
  129.      ___________________________________________________________________
  130.  
  131.   ╖  Make sure that the script is exectuable (mode 755).
  132.  
  133.   5.  Establishing the mail aliases
  134.  
  135.   Edit /etc/aliases to create entries for the mailing list(s) you wish
  136.   to pipe into news. Each entry should be of the form:-
  137.  
  138.   ______________________________________________________________________
  139.   <subscribed email address to list>: \
  140.           "| /usr/local/scripts/mail2news.pl <local news group name>"
  141.   <code>
  142.  
  143.   <p>
  144.   So for example if the email address to which email from the list is to
  145.   be sent (the subscribed mail address) is <tt/site_list/ and the local
  146.   newsgroup to which mail is to be posted is <tt/local.site.group/, the
  147.   alias would be
  148.  
  149.   <code>
  150.   # The site subscription address for blah-blah@some.mailing.list
  151.   site_list: "| /usr/local/scripts/mail2news.pl local.site.group"
  152.   ______________________________________________________________________
  153.  
  154.   Make an entry for each mailing list that is to be gated to oyur local
  155.   news server and and then run newaliases.
  156.  
  157.   6.  Setting up the news groups and news server (innd)
  158.  
  159.   Using ctlinnd, create the newsgroups on your news server. Remember,
  160.   these are to be local news groups, so start them with a distinctive
  161.   name so you can filter them out from your news distributions (in your
  162.   newsfeeds file).
  163.  
  164.   You also need to tell innd that the group is moderated (by using
  165.   ctlinnd). Remember, innd is very sensitive to file ownership and
  166.   permissions, so you need to interct at this level with innd as the
  167.   news user. Indicating a moderated group is done by specifying m to the
  168.   newgroup command.
  169.  
  170.   ______________________________________________________________________
  171.           ctlinnd newgroup <newgroup name> m <newsadmin>
  172.   ______________________________________________________________________
  173.  
  174.   The m tells innd that the group is moderated.
  175.  
  176.   Edit your newsfeeds file to make sure that these local groups are not
  177.   distributed (unless you specificaly wish this to occur).
  178.  
  179.   For example, if your mailing list is called local.site.group, then you
  180.   would probably want to add !local* to the second field of your up (and
  181.   possibly your down) stream news sites in your newsfeeds file.
  182.  
  183.   Now, in order to ensure that user messages are sent to the list
  184.   automatically by innd, edit /etc/news/moderators to include a line
  185.   declaring the mailing list email address as the moderator.
  186.  
  187.   ______________________________________________________________________
  188.   some.site.list:list@mail.list.site
  189.   ______________________________________________________________________
  190.  
  191.   7.  Subscribing the mail2 news alias to the mailing list
  192.  
  193.   You now need to subscribe the mail alias to the mailing list. Check
  194.   with the mailing list information as to how to subscribe. Some mailing
  195.   lists allow you to subscribe an email address that is different from
  196.   the address from which the subscription comes (they check back to the
  197.   address to be subscribed for confirmation before actually subscribing
  198.   that address).
  199.  
  200.   Other mailing lists do not permit this. So you may need to 'forge' a
  201.   subscription request. There are many ways of doing this. One of the
  202.   easiest is to use Netscape mail set up (temporarily) with the address
  203.   to which the mailing list is to send the mail.
  204.  
  205.   After subscribing, you should see a 'welcome' message of some kind
  206.   from the list server in the news group - in which case all is well and
  207.   you can now test the other direction by posting a news message to your
  208.   new list.
  209.  
  210.   The message should *NOT* appear in the newsgroup at once. It should
  211.   get sent out by mail and then received back and posted to the news
  212.   group.
  213.  
  214.   If this works, you have succeed in getting the list gated to news.
  215.  
  216.   8.  If it doesn't work...
  217.  
  218.   If things don't work, you need to track through the path the messages
  219.   are taking to see exactly where things are breaking down. Useful tools
  220.   here are the mail and news logs.
  221.  
  222.   Robert Hart
  223.   Melbourne, Victoria, Australia October 1996
  224.  
  225.   9.  The mail2news.pl script
  226.  
  227.   ______________________________________________________________________
  228.   #!/usr/bin/perl
  229.  
  230.   ($program = $0) =~ s%.*/%%;
  231.  
  232.   #( $version  ) = $] =~ /(\d+\.\d+).*\nPatch level/;
  233.   #die "$program: requires at least version 3 of perl\n"
  234.   #        if $version < 3;
  235.  
  236.   # $inews = "/usr/bin/inews";
  237.   # $iopts = "-h -o \"mail2news gateway\"";
  238.   $inews = "/usr/bin/rnews";
  239.   $iopts = "";
  240.   $postinghost = "your.news.server";
  241.  
  242.   if ($#ARGV < 0) {
  243.       # $newsgroup = "test";
  244.       # we'll expect the newsgroup line in the body
  245.   } elsif ($#ARGV == 0) {
  246.       $newsgroup = $ARGV[0];
  247.   } else {
  248.       die "usage: $program [newsgroup]\n";
  249.   }
  250.  
  251.   # in case inews dumps core or something crazy
  252.   $SIG{'PIPE'} = "plumber";
  253.   sub plumber { die "$program: \"$inews\" died prematurely!\n"; }
  254.  
  255.   open (INEWS, "| $inews $iopts") ||
  256.       die "$program: can't run $inews\n";
  257.  
  258.   # header munging loop
  259.   while (<STDIN>) {
  260.      last if /^$/;
  261.  
  262.      # transform real from: line back to icky style
  263.      s/^From:\s+(.*) <(.*)>/From: $2 ($1)/;
  264.  
  265.      s/Message-Id/Message-ID/;
  266.  
  267.      # transform from_ line to path header; also works locally
  268.      s/^From\s+(\S+)@(\S+).*/Path: $2!$1/
  269.        || s/^From\s+(\S+)[^@]*$/Path: $1\n/;
  270.  
  271.      print INEWS
  272.   #       if /^(Date|From|Subject|Path|Newsgroups|Organization|Message-ID):/i;
  273.      if /^(Date|From|Subject|Path|Newsgroups|Message-ID):/i;
  274.      $saw_subject |= ( $+ eq 'Subject' );
  275.  
  276.      $saw_msgid |= ( $+ eq 'Message-ID' );
  277.  
  278.   #   $saw_newsgroup |= ( $+ eq 'Newsgroups' );
  279.   }
  280.  
  281.   warn "$program: didn't expect newsgroup in both headers and ARGV\n"
  282.       if $newsgroup && $saw_newsgroup;
  283.  
  284.   die "$program: didn't get newsgroup from either headers or ARGV\n"
  285.       unless $newsgroup || $saw_newsgroup;
  286.  
  287.   $approved = $newsgroup;
  288.   $approved =~ s/\./'-'/eg;
  289.  
  290.   ($sec,$min,$hour,$mday,$mon,$year)=localtime(time);
  291.   $madeupid = "\<$year$mon$mday.$hour$min$sec.$$\@kepler.hedland.edu.au\>";
  292.  
  293.   printf INEWS "Newsgroups: %s\n", $newsgroup if $newsgroup;
  294.   printf INEWS "Approved: %s\@kepler.hedland.edu.au\n", $approved;
  295.   print  INEWS "Subject: Untitled\n" unless $saw_subject;
  296.   printf INEWS "Message-ID: %s\n", $madeupid unless $saw_msgid;
  297.   printf INEWS "NNTP-Posting-Host: %s\n", $postinghost;
  298.   print  INEWS "Organisation: (mail2news gateway)\n";
  299.   print  INEWS "\n";
  300.  
  301.   print INEWS while <STDIN>;   # gobble rest of message
  302.  
  303.   close INEWS;
  304.   exit $?;
  305.   ______________________________________________________________________
  306.  
  307.