/[cvs]/nfo/perl/libs/Mail/Audit/Dispatch/Newsgate.pm
ViewVC logotype

Contents of /nfo/perl/libs/Mail/Audit/Dispatch/Newsgate.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (show annotations)
Thu Jan 30 23:28:11 2003 UTC (21 years, 5 months ago) by root
Branch: MAIN
CVS Tags: HEAD
+ initial commit

1 package Mail::Audit::Dispatch::Newsgate;
2
3 use strict;
4 use warnings;
5
6 use mixin::with qw( Mail::Audit::Dispatch );
7
8
9 use Data::Dumper;
10 use Net::NNTP;
11 use News::Article;
12
13
14 my $connInfo = {
15 host => 'news.netfrag.org',
16 user => 'collector',
17 pass => 'col5%',
18 };
19
20 sub Newsgate {
21 my $self = shift;
22 $self->{newsgroup} = shift;
23 $self->{newsgroup} ||= '';
24 $self->report( __PACKAGE__ . "->Newsgate( newsgroup=$self->{newsgroup} )" );
25 $self->connect();
26 $self->post();
27 $self->disconnect();
28 }
29
30 sub connect {
31 my $self = shift;
32
33 # $self->report("before");
34
35 # connect to the (possibly remote) news-server
36 $self->{nntp} = Net::NNTP->new( $connInfo->{host} ) or die("could not connect to nntp!");
37
38 # $self->report("after");
39
40 # authenticate with nntp-server
41 $self->{nntp}->authinfo( $connInfo->{user}, $connInfo->{pass} );
42 }
43
44 sub post {
45 my $self = shift;
46
47 my $from = $self->{incoming}->from;
48 my $data = $self->{incoming}->{obj}->as_string();
49 #my $data = $self->{incoming}->{obj}->as_mbox_string();
50
51 $self->{newsgroup} ||= 'alt.test';
52 $from ||= 'collector@netfrag.org';
53
54 my @data_arr = split(/\n/, $data);
55
56 #print Dumper(@data_arr);
57
58 # $self->report("1");
59
60 # build news-message
61 #my $msg_nntp = News::Article->new( \$data );
62 my $msg_nntp = News::Article->new( \@data_arr ) or die("could not build news-article!");
63
64 # $self->report("2");
65
66 if (!$msg_nntp) {
67 $self->report("ERROR while building news-article.");
68 return;
69 }
70
71 #print Dumper($msg_nntp);
72 #print Dumper($msg_nntp->header('Received'));
73
74 my @Received = $msg_nntp->header('Received');
75
76 $msg_nntp->set_headers(
77 'Newsgroups' => $self->{newsgroup},
78 'X-Received' => \@Received,
79 # 'Received' => undef,
80 # 'From', $from,
81 # 'Subject', $self->{incoming}->subject,
82 );
83
84 $msg_nntp->drop_headers(
85 'Received',
86 );
87
88 #my $hds = $msg_nntp->rawheaders();
89 #print Dumper($hds);
90
91 shift @{$msg_nntp->{HeaderSeq}};
92 shift @{$msg_nntp->{HeaderSeq}};
93 shift @{$msg_nntp->{HeaderSeq}};
94
95 # tracing
96 #print Dumper($msg_nntp);
97 #exit;
98
99 # $self->report("3");
100
101 # post message to news-server
102
103 #$self->report("@INC");
104 $self->report("trying to post");
105 $msg_nntp->post( $self->{nntp} );
106 $self->report("post successful");
107
108 #sleep 3;
109
110 # $self->report("4");
111
112 }
113
114 sub disconnect {
115 my $self = shift;
116 # disconnect from news-server
117 $self->{nntp}->quit;
118 # $self->report("5");
119 }
120
121 1;

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed