#!/usr/bin/perl

use strict;
use warnings;

my $POPHOST    = 'my.mail.server.com';
my $POPPORT    = 110;
my $POPTIMEOUT = 60;
my $POPUSERID  = 'myuserid';
my $POPPASSWD  = 'topsecret';
my $NNTPSERVER = 'localhost';

use Net::POP3;
use Mail::Internet;

    # Verbindung zum POP-Server aufbauen
my $pop = Net::POP3->new($POPHOST, 
                         Timeout => $POPTIMEOUT, 
                         Port    => $POPPORT);

die "Cannot connect to $POPHOST ($pop)\n" unless $pop;
    
my $nof_messages = $pop->login($POPUSERID, 
                               $POPPASSWD) or
    die "$POPHOST rejected our login\n";

    # Wortlos abbrechen, falls keine Nachrichten
    # vorliegen 
exit 0 if $nof_messages == 0;

foreach my $mesgno (keys %{$pop->list()}) {

    my $message = $pop->get($mesgno);
    my $mail = Mail::Internet->new($message);

        # Newsgroups-Header einfügen
    $mail->add("Newsgroups", "p5p");

        # An den Newsserver senden
    $mail->nntppost(Host => $NNTPSERVER) or
        warn "Cannot post to news server";

    $pop->delete($mesgno);
}

$pop->quit();
