Release 0.8.2 (Maintenance Release)
[usenet/yapfaq.git] / yapfaq.pl
CommitLineData
dc88d139
TH
1#! /usr/bin/perl -W
2#
aa2b0bc1 3# yapfaq Version 0.8.2 by Thomas Hochstein
7aaba0e0 4# (Original author: Marc Brockschmidt)
dc88d139 5#
7aaba0e0 6# This script posts any project described in its config-file. Most people
dc88d139
TH
7# will use it in combination with cron(8).
8#
9# Copyright (C) 2003 Marc Brockschmidt <marc@marcbrockschmidt.de>
7aaba0e0 10# Copyright (c) 2010 Thomas Hochstein <thh@inter.net>
dc88d139
TH
11#
12# It can be redistributed and/or modified under the same terms under
13# which Perl itself is published.
14
aa2b0bc1 15our $VERSION = "0.8.2";
dc88d139 16
605916ef
TH
17# Please do not change this setting!
18# You may override the default .rc file (.yapfaqrc) by using "-c .rc file"
d60c2d5f 19my $RCFile = '.yapfaqrc';
605916ef 20# Valid configuration variables for use in a .rc file
39cb5672 21my @ValidConfVars = ('NNTPServer','NNTPUser','NNTPPass','Sender','ConfigFile','Program');
d60c2d5f 22
605916ef
TH
23################################### Defaults ###################################
24# Please do not change anything in here!
25# Use a runtime configuration file (.yapfaqrc by default) to override defaults.
7ef63844 26my %Config = (NNTPServer => "",
2507947f
TH
27 NNTPUser => "",
28 NNTPPass => "",
29 Sender => "",
39cb5672
TH
30 ConfigFile => "yapfaq.cfg",
31 Program => "");
dc88d139 32
605916ef 33################################# Main program #################################
dc88d139
TH
34
35use strict;
36use Net::NNTP;
40847f71 37use Net::Domain qw(hostfqdn);
dc88d139
TH
38use Date::Calc qw(Add_Delta_YM Add_Delta_Days Delta_Days Today);
39use Fcntl ':flock'; # import LOCK_* constants
4251e545 40use Getopt::Std;
bdbb9d70 41$Getopt::Std::STANDARD_HELP_VERSION = 1;
dc88d139
TH
42my ($TDY, $TDM, $TDD) = Today(); #TD: Today's date
43
b9550622 44# read commandline options
4251e545 45my %Options;
86c0a100 46getopts('Vhvpdt:f:c:s:', \%Options);
b9550622 47# -V: print version / copyright information
a052296f 48if ($Options{'V'}) {
bdbb9d70 49 print "$0 v $VERSION\nCopyright (c) 2003 Marc Brockschmidt <marc\@marcbrockschmidt.de>\nCopyright (c) 2010 Thomas Hochstein <thh\@inter.net>\n";
a052296f
TH
50 print "This program is free software; you may redistribute it and/or modify it under the same terms as Perl itself.\n";
51 exit(0);
52}
b9550622 53# -h: feed myself to perldoc
4251e545 54if ($Options{'h'}) {
ae3b1b79 55 exec ('perldoc', $0);
4251e545
TH
56 exit(0);
57};
b9550622 58# -f: set $Faq
4251e545
TH
59my ($Faq) = $Options{'f'} if ($Options{'f'});
60
d60c2d5f 61# read runtime configuration (configuration variables)
86c0a100
TH
62$RCFile = $Options{'c'} if ($Options{'c'});
63if (-f $RCFile) {
64 readrc (\$RCFile,\%Config);
65} else {
66 warn "$0: W: .rc file $RCFile does not exist!\n";
67}
d60c2d5f 68
ba8ae1cf 69$Options{'s'} = $Config{'Program'} if (defined($Config{'Program'}) && $Config{'Program'} && !defined($Options{'s'}));
39cb5672 70
b9550622 71# read configuration (configured FAQs)
dc88d139 72my @Config;
2507947f 73readconfig (\$Config{'ConfigFile'}, \@Config, \$Faq);
dc88d139 74
b9550622
TH
75# for each FAQ:
76# - parse configuration
77# - read status data
78# - if FAQ is due: call postfaq()
dc88d139
TH
79foreach (@Config) {
80 my ($LPD,$LPM,$LPY) = (01, 01, 0001); #LP: Last posting-date
81 my ($NPY,$NPM,$NPD); #NP: Next posting-date
82 my $SupersedeMID;
83
0c6ebe78 84 my ($ActName,$File,$PFreq,$Expire) =($$_{'name'},$$_{'file'},$$_{'posting-frequency'},$$_{'expires'});
dc88d139
TH
85 my ($From,$Subject,$NG,$Fup2)=($$_{'from'},$$_{'subject'},$$_{'ngs'},$$_{'fup2'});
86 my ($MIDF,$ReplyTo,$ExtHea)=($$_{'mid-format'},$$_{'reply-to'},$$_{'extraheader'});
87 my ($Supersede) =($$_{'supersede'});
4251e545 88
b9550622 89 # -f: loop if not FAQ to post
4251e545
TH
90 next if (defined($Faq) && $ActName ne $Faq);
91
b9550622 92 # read status data
dc88d139
TH
93 if (open (FH, "<$File.cfg")) {
94 while(<FH>){
95 if (/##;; Lastpost:\s*(\d{1,2})\.(\d{1,2})\.(\d{2}(\d{2})?)/){
96 ($LPD, $LPM, $LPY) = ($1, $2, $3);
97 } elsif (/^##;;\s*LastMID:\s*(<\S+@\S+>)\s*$/) {
98 $SupersedeMID = $1;
99 }
100 }
101 close FH;
102 } else {
74407146 103 warn "$0: W: Couldn't open $File.cfg: $!\n";
dc88d139
TH
104 }
105
106 $SupersedeMID = "" unless $Supersede;
107
0c6ebe78
TH
108 ($NPY,$NPM,$NPD) = calcdelta ($LPY,$LPM,$LPD,$PFreq);
109
b9550622 110 # if FAQ is due: get it out
4251e545
TH
111 if (Delta_Days($NPY,$NPM,$NPD,$TDY,$TDM,$TDD) >= 0 or ($Options{'p'})) {
112 if($Options{'d'}) {
113 print "$ActName: Would be posted now (but running in simulation mode [$0 -d]).\n" if $Options{'v'};
114 } else {
2507947f 115 postfaq(\$ActName,\$File,\$From,\$Subject,\$NG,\$Fup2,\$MIDF,\$ExtHea,\$Config{'Sender'},\$TDY,\$TDM,\$TDD,\$ReplyTo,\$SupersedeMID,\$Expire);
4251e545
TH
116 }
117 } elsif($Options{'v'}) {
118 print "$ActName: Nothing to do.\n";
dc88d139
TH
119 }
120}
121
122exit;
123
d60c2d5f
TH
124#################################### readrc ####################################
125# Takes a filename and the reference to an array which contains the valid options
126
127sub readrc{
128 my ($File, $Config) = @_;
129
130 print "Reading $$File.\n" if($Options{'v'});
131
132 open FH, "<$$File" or die "$0: Can't open $$File: $!";
133 while (<FH>) {
134 if (/^\s*(\S+)\s*=\s*'?(.*?)'?\s*(#.*$|$)/) {
135 if (grep(/$1/,@ValidConfVars)) {
136 $$Config{$1} = $2 if $2 ne '';
137 } else {
138 warn "$0: W: $1 is not a valid configuration variable (reading from $$File)\n";
139 }
140 }
141 }
142}
143
dc88d139 144################################## readconfig ##################################
4251e545
TH
145# Takes a filename, a reference to an array, which will hold hashes with
146# the data from $File, and - optionally - the name of the (single) FAQ to post
dc88d139
TH
147
148sub readconfig{
4251e545 149 my ($File, $Config, $Faq) = @_;
dc88d139
TH
150 my ($LastEntry, $Error, $i) = ('','',0);
151
b802358a 152 print "Reading configuration from $$File.\n" if($Options{'v'});
4251e545 153
74407146 154 open FH, "<$$File" or die "$0: E: Can't open $$File: $!";
dc88d139 155 while (<FH>) {
4251e545 156 next if (defined($$Faq) && !/^\s*=====\s*$/ && defined($$Config[$i]{'name'}) && $$Config[$i]{'name'} ne $$Faq );
dc88d139
TH
157 if (/^(\s*(\S+)\s*=\s*'?(.*?)'?\s*(#.*$|$)|^(.*?)'?\s*(#.*$|$))/ && not /^\s*$/) {
158 $LastEntry = lc($2) if $2;
159 $$Config[$i]{$LastEntry} .= $3 if $3;
160 $$Config[$i]{$LastEntry} .= "\n$5" if $5 && $5;
161 }
162 if (/^\s*=====\s*$/) {
163 $i++;
164 }
165 }
166 close FH;
167
168 #Check saved values:
169 for $i (0..$i){
4251e545 170 next if (defined($$Faq) && defined($$Config[$i]{'name'}) && $$Config[$i]{'name'} ne $$Faq );
dbca4ad8
TH
171 unless(defined($$Config[$i]{'name'}) && $$Config[$i]{'name'} =~ /^\S+$/) {
172 $Error .= "E: The name of your project \"$$Config[$i]{'name'}\" is not defined or contains whitespaces.\n"
dc88d139 173 }
dbca4ad8
TH
174 unless(defined($$Config[$i]{'file'}) && -f $$Config[$i]{'file'}) {
175 $Error .= "E: The file to post for your project \"$$Config[$i]{'name'}\" is not defined or does not exist.\n"
176 }
177 unless(defined($$Config[$i]{'from'}) && $$Config[$i]{'from'} =~ /\S+\@(\S+\.)?\S{2,}\.\S{2,}/) {
178 $Error .= "E: The From header for your project \"$$Config[$i]{'name'}\" seems to be incorrect.\n"
179 }
180 unless(defined($$Config[$i]{'ngs'}) && $$Config[$i]{'ngs'} =~ /^\S+$/) {
181 $Error .= "E: The Newsgroups header for your project \"$$Config[$i]{'name'}\" is not defined or contains whitespaces.\n"
182 }
183 unless(defined($$Config[$i]{'subject'})) {
184 $Error .= "E: The Subject header for your project \"$$Config[$i]{'name'}\" is not defined.\n"
dc88d139
TH
185 }
186 unless(!$$Config[$i]{'fup2'} || $$Config[$i]{'fup2'} =~ /^\S+$/) {
dbca4ad8 187 $Error .= "E: The Followup-To header for your project \"$$Config[$i]{'name'}\" contains whitespaces.\n"
dc88d139 188 }
dbca4ad8 189 unless(defined($$Config[$i]{'posting-frequency'}) && $$Config[$i]{'posting-frequency'} =~ /^\s*\d+\s*[dwmy]\s*$/) {
74407146 190 $Error .= "E: The Posting-frequency for your project \"$$Config[$i]{'name'}\" is invalid.\n"
dc88d139 191 }
5ddba442 192 unless(!$$Config[$i]{'expires'} || $$Config[$i]{'expires'} =~ /^\s*\d+\s*[dwmy]\s*$/) {
ac69c3ee
TH
193 warn "$0: W: The Expires for your project \"$$Config[$i]{'name'}\" is invalid - set to 3 month.\n";
194 $$Config[$i]{'expires'} = '3m'; # set default (3 month) if expires is unset or invalid
0c6ebe78 195 }
8f067a2f 196 unless(!$$Config[$i]{'mid-format'} || $$Config[$i]{'mid-format'} =~ /^<\S+\@(\S+\.)?\S{2,}\.\S{2,}>/) {
ac69c3ee
TH
197 warn "$0: W: The Message-ID format for your project \"$$Config[$i]{'name'}\" seems to be invalid - set to default.\n";
198 $$Config[$i]{'mid-format'} = '<%n-%d.%m.%y@'.hostfqdn.'>'; # set default if mid-format is invalid
40847f71 199 }
dc88d139 200 }
dbca4ad8 201 $Error .= "-" x 25 . 'program terminated' . "-" x 25 . "\n" if $Error;
dc88d139
TH
202 die $Error if $Error;
203}
204
0c6ebe78
TH
205################################# calcdelta #################################
206# Takes a date (year, month and day) and a time period (1d, 1w, 1m, 1y, ...)
207# and adds the latter to the former
208
209sub calcdelta {
210 my ($Year, $Month, $Day, $Period) = @_;
211 my ($NYear, $NMonth, $NDay);
212
213 if ($Period =~ /(\d+)\s*([dw])/) { # Is counted in days or weeks: Use Add_Delta_Days.
214 ($NYear, $NMonth, $NDay) = Add_Delta_Days($Year, $Month, $Day, (($2 eq "w")?$1 * 7: $1 * 1));
215 } elsif ($Period =~ /(\d+)\s*([my])/) { #Is counted in months or years: Use Add_Delta_YM
216 ($NYear, $NMonth, $NDay) = Add_Delta_YM($Year, $Month, $Day, (($2 eq "m")?(0,$1):($1,0)));
217 }
218 return ($NYear, $NMonth, $NDay);
219}
5a6670c7
TH
220
221################################ updatestatus ###############################
222# Takes a MID and a status file name
223# and writes status information to disk
224
225sub updatestatus {
226 my ($ActName, $File, $date, $MID) = @_;
227
228 print "$$ActName: Save status information.\n" if($Options{'v'});
229
230 open (FH, ">$$File.cfg") or die "$0: E: Can't open $$File.cfg: $!";
231 print FH "##;; Lastpost: $date\n";
232 print FH "##;; LastMID: $MID\n";
233 close FH;
234}
0c6ebe78 235
dc88d139
TH
236################################## postfaq ##################################
237# Takes a filename and many other vars.
238#
239# It reads the data-file $File and then posts the article.
240
241sub postfaq {
0c6ebe78 242 my ($ActName,$File,$From,$Subject,$NG,$Fup2,$MIDF,$ExtraHeaders,$Sender,$TDY,$TDM,$TDD,$ReplyTo,$Supersedes,$Expire) = @_;
dc88d139
TH
243 my (@Header,@Body,$MID,$InRealBody,$LastModified);
244
366322b2 245 print "$$ActName: Preparing to post.\n" if($Options{'v'});
4251e545 246
dc88d139
TH
247 #Prepare MID:
248 $$TDM = ($$TDM < 10 && $$TDM !~ /^0/) ? "0" . $$TDM : $$TDM;
249 $$TDD = ($$TDD < 10 && $$TDD !~ /^0/) ? "0" . $$TDD : $$TDD;
13ce8c26 250 my $Timestamp = time;
dc88d139
TH
251
252 $MID = $$MIDF;
ac69c3ee 253 $MID = '<%n-%d.%m.%y@'.hostfqdn.'>' if !defined($MID); # set to default if unset
dc88d139
TH
254 $MID =~ s/\%n/$$ActName/g;
255 $MID =~ s/\%d/$$TDD/g;
256 $MID =~ s/\%m/$$TDM/g;
257 $MID =~ s/\%y/$$TDY/g;
13ce8c26 258 $MID =~ s/\%t/$Timestamp/g;
dc88d139 259
dc88d139
TH
260 #Now get the body:
261 open (FH, "<$$File");
262 while (<FH>){
263 s/\r//;
264 push (@Body, $_), next if $InRealBody;
265 $InRealBody++ if /^$/;
2ae816cb 266 $LastModified = $1 if /^Last-modified:\s*(\S+)\s*$/i;
dc88d139
TH
267 push @Body, $_;
268 }
269 close FH;
270 push @Body, "\n" if ($Body[-1] ne "\n");
271
272 #Create Date- and Expires-Header:
273 my @time = localtime;
274 my $ss = ($time[0]<10) ? "0" . $time[0] : $time[0];
275 my $mm = ($time[1]<10) ? "0" . $time[1] : $time[1];
276 my $hh = ($time[2]<10) ? "0" . $time[2] : $time[2];
277 my $day = $time[3];
278 my $month = ($time[4]+1<10) ? "0" . ($time[4]+1) : $time[4]+1;
279 my $monthN = ("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")[$time[4]];
280 my $wday = ("Sun","Mon","Tue","Wed","Thu","Fri","Sat")[$time[6]];
281 my $year = (1900 + $time[5]);
282 my $tz = $time[8] ? " +0200" : " +0100";
7823ece9
TH
283
284 $$Expire = '3m' if !$$Expire; # set default if unset: 3 month
285
0c6ebe78 286 my ($expY,$expM,$expD) = calcdelta ($year,$month,$day,$$Expire);
dc88d139
TH
287 my $expmonthN = ("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")[$expM-1];
288
289 my $date = "$day $monthN $year " . $hh . ":" . $mm . ":" . $ss . $tz;
290 my $expdate = "$expD $expmonthN $expY $hh:$mm:$ss$tz";
0c6ebe78 291
dc88d139
TH
292 #Replace %LM by the content of the news.answer-pseudo-header Last-modified:
293 if ($LastModified) {
294 $$Subject =~ s/\%LM/$LastModified/;
295 }
296
4251e545
TH
297 # Test mode?
298 if($Options{'t'} and $Options{'t'} !~ /console/i) {
299 $$NG = $Options{'t'};
300 }
301
dc88d139
TH
302 #Now create the complete Header:
303 push @Header, "From: $$From\n";
304 push @Header, "Newsgroups: $$NG\n";
305 push @Header, "Followup-To: $$Fup2\n" if $$Fup2;
306 push @Header, "Subject: $$Subject\n";
307 push @Header, "Message-ID: $MID\n";
308 push @Header, "Supersedes: $$Supersedes\n" if $$Supersedes;
309 push @Header, "Date: $date\n";
310 push @Header, "Expires: $expdate\n";
311 push @Header, "Sender: $$Sender\n" if $$Sender;
312 push @Header, "Mime-Version: 1.0\n";
313 push @Header, "Reply-To: $$ReplyTo\n" if $$ReplyTo;
314 push @Header, "Content-Type: text/plain; charset=ISO-8859-15\n";
315 push @Header, "Content-Transfer-Encoding: 8bit\n";
bdbb9d70 316 push @Header, "User-Agent: yapfaq/$VERSION\n";
dc88d139
TH
317 if ($$ExtraHeaders) {
318 push @Header, "$_\n" for (split /\n/, $$ExtraHeaders);
319 }
320
0e741504
TH
321 my @Article = (@Header, "\n", @Body);
322
b9550622 323 # post article
366322b2 324 print "$$ActName: Posting article ...\n" if($Options{'v'});
5a6670c7
TH
325 my $failure = post(\@Article);
326
327 if ($failure) {
328 print "$$ActName: Posting failed, ERROR.dat may have more information.\n" if($Options{'v'} && (!defined($Options{'t'}) || $Options{'t'} !~ /console/i));
329 } else {
330 updatestatus($ActName, $File, "$day.$month.$year", $MID) if !defined($Options{'t'});
331 }
dc88d139
TH
332}
333
334################################## post ##################################
335# Takes a complete article (Header and Body).
336#
337# It opens a connection to $NNTPServer and posts the message.
338
339sub post {
340 my ($ArticleR) = @_;
5a6670c7 341 my ($failure) = -1;
dc88d139 342
5a6670c7 343 # test mode - print article to console
4251e545 344 if(defined($Options{'t'}) and $Options{'t'} =~ /console/i) {
55bfbd3c 345 print "-----BEGIN--------------------------------------------------\n";
5a6670c7 346 print @$ArticleR;
55bfbd3c 347 print "------END---------------------------------------------------\n";
5a6670c7
TH
348 # pipe article to script
349 } elsif(defined($Options{'s'})) {
b855559e
TH
350 open (POST, "| $Options{'s'}") or die "$0: E: Cannot fork $Options{'s'}: $!\n";
351 print POST @$ArticleR;
352 close POST;
5a6670c7
TH
353 if ($? == 0) {
354 $failure = 0;
355 } else {
356 warn "$0: W: $Options{'s'} exited with status ", ($? >> 8), "\n";
357 $failure = $?;
358 }
359 # post article
360 } else {
361 my $NewsConnection = Net::NNTP->new($Config{'NNTPServer'}, Reader => 1) or die "$0: E: Can't connect to news server '$Config{'NNTPServer'}'!\n";
362 $NewsConnection->authinfo ($Config{'NNTPUser'}, $Config{'NNTPPass'}) if (defined($Config{'NNTPUser'}));
363 $NewsConnection->post();
364 $NewsConnection->datasend (@$ArticleR);
365 $NewsConnection->dataend();
366
367 if ($NewsConnection->ok()) {
368 $failure = 0;
369 # Posting failed? Save to ERROR.dat
370 } else {
371 warn "$0: W: Posting failed!\n";
372 open FH, ">>ERROR.dat";
373 print FH "\nPosting failed! Saving to ERROR.dat. Response from news server:\n";
374 print FH $NewsConnection->code();
375 print FH $NewsConnection->message();
376 print FH "\n";
377 print FH @$ArticleR;
378 print FH "-" x 80, "\n";
379 close FH;
380 }
381 $NewsConnection->quit();
dc88d139 382 }
5a6670c7 383 return $failure;
dc88d139
TH
384}
385
272b0243
TH
386__END__
387
388################################ Documentation #################################
389
390=head1 NAME
391
392yapfaq - Post Usenet FAQs I<(yet another postfaq)>
393
394=head1 SYNOPSIS
395
9817f98a 396B<yapfaq> [B<-Vhvpd>] [B<-t> I<newsgroups> | CONSOLE] [B<-f> I<project name>] [B<-s> I<program>] [B<-c> I<.rc file>]
272b0243
TH
397
398=head1 REQUIREMENTS
399
400=over 2
401
402=item -
403
404Perl 5.8 or later
405
406=item -
407
408Net::NNTP
409
410=item -
411
412Date::Calc
413
414=item -
415
416Getopt::Std
417
418=back
419
420Furthermore you need access to a news server to actually post FAQs.
421
422=head1 DESCRIPTION
423
424B<yapfaq> posts (one or more) FAQs to Usenet with a certain posting
425frequency (every n days, weeks, months or years), adding all necessary
426headers as defined in its config file (by default F<yapfaq.cfg>).
427
428=head2 Configuration
429
430F<yapfaq.cfg> consists of one or more blocks, separated by C<=====> on
431a single line, each containing the configuration for one FAQ as a set
227afd47
TH
432of definitions in the form of I<param = value>. Everything after a "#"
433sign is ignored so you may comment your configuration file.
272b0243
TH
434
435=over 4
436
437=item B<Name> = I<project name>
438
439A name referring to your FAQ, also used for generation of a Message-ID.
440
441This value must be set.
442
443=item B<File> = I<file name>
444
445A file containing the message body of your FAQ and all pseudo headers
446(subheaders in the news.answers style).
447
448This value must be set.
449
450=item B<Posting-frequency> = I<time period>
451
452The posting frequency defines how often your FAQ will be posted.
453B<yapfaq> will only post your FAQ if this period of time has passed
454since the last posting.
455
456You can declare that time period either in I<B<d>ays> or I<B<w>weeks>
457or I<B<m>onths> or I<B<y>ears>.
458
459This value must be set.
460
ac69c3ee 461=item B<Expires> = I<time period> (optional)
272b0243
TH
462
463The period of time after which your message will expire. An Expires
464header will be calculated adding this time period to today's date.
465
466You can declare this time period either in I<B<d>ays> or I<B<w>weeks>
467or I<B<m>onths> or I<B<y>ears>.
468
ac69c3ee 469This setting is optional; the default is 3 months.
272b0243
TH
470
471=item B<From> = I<author>
472
473The author of your FAQ as it will appear in the From header of the
474message.
475
476This value must be set.
477
478=item B<Subject> = I<subject>
479
480The title of your FAQ as it will appear in the Subject header of the
481message.
482
483You may use the special string C<%LM> which will be replaced with
484the contents of the Last-Modified subheader in your I<File>.
485
486This value must be set.
487
488=item B<NGs> = I<newsgroups>
489
490A comma-separated list of newsgroup(s) to post your FAQ to as it will
491appear in the Newsgroups header of the message.
492
493This value must be set.
494
ac69c3ee 495=item B<Fup2> = I<newsgroup | poster> (optional)
272b0243
TH
496
497A comma-separated list of newsgroup(s) or the special string I<poster>
498as it will appear in the Followup-To header of the message.
499
500This setting is optional.
501
ac69c3ee 502=item B<MID-Format> = I<pattern> (optional)
272b0243
TH
503
504A pattern from which the message ID is generated as it will appear in
505the Message-ID header of the message.
506
507You may use the special strings C<%n> for the I<Name> of your project,
13ce8c26
TH
508C<%d> for the date the message is posted, C<%m> for the month, C<%y>
509for the year and C<%t> for a time stamp (number of seconds since the
510epoch), respectively.
272b0243 511
ac69c3ee
TH
512This setting is optional; the default is '<%n-%d.%m.%y@I<YOURHOST>>'
513where I<YOURHOST> is the fully qualified domain name (FQDN) of the
514host B<yapfaq> is running on. Obviously that will only work if you
515have defined a reasonable hostname that the hostfqdn() function of
516Net::Domain can return.
272b0243 517
ac69c3ee 518=item B<Supersede> = I<yes> (optional)
272b0243
TH
519
520Add Supersedes header to the message containing the Message-ID header
521of the last posting.
522
523This setting is optional; you should set it to yes or leave it out.
524
ac69c3ee 525=item B<ExtraHeader> = I<additional headers> (optional)
272b0243
TH
526
527The contents of I<ExtraHeader> is added verbatim to the headers of
528your message so you can add custom headers like Approved.
529
530This setting is optional.
531
532=back
533
227afd47 534=head3 Example configuration file
272b0243
TH
535
536 # name of your project
537 Name = 'testpost'
538
539 # file to post (complete body and pseudo-headers)
540 # ($File.cfg contains data on last posting and last MID)
541 File = 'test.txt'
542
543 # how often your project should be posted
544 # use (d)ay OR (w)eek OR (m)onth OR (y)ear
545 Posting-frequency = '1d'
546
547 # time period after which the posting should expire
548 # use (d)ay OR (w)eek OR (m)onth OR (y)ear
ac69c3ee 549 # Expires = '3m'
272b0243
TH
550
551 # header "From:"
552 From = 'test@domain.invalid'
553
554 # header "Subject:"
555 # (may contain "%LM" which will be replaced by the contents of the
556 # Last-Modified pseudo header).
557 Subject = 'test noreply ignore'
558
559 # comma-separated list of newsgroup(s) to post to
560 # (header "Newsgroups:")
561 NGs = 'de.test'
562
563 # header "Followup-To:"
ac69c3ee 564 # Fup2 = 'poster'
272b0243
TH
565
566 # Message-ID ("%n" is $Name)
ac69c3ee 567 # MID-Format = '<%n-%d.%m.%y@domain.invalid>'
272b0243
TH
568
569 # Supersede last posting?
570 Supersede = yes
571
572 # extra headers (appended verbatim)
573 # use this for custom headers like "Approved:"
574 ExtraHeader = 'Approved: moderator@domain.invalid
575 X-Header: Some text'
576
577 # other projects may follow separated with "====="
578 =====
579
580 Name = 'othertest'
581 File = 'test.txt'
582 Posting-frequency = '2m'
583 From = 'My Name <my.name@domain.invalid>'
584 Subject = 'Test of yapfag <%LM>'
585 NGs = 'de.test,de.alt.test'
586 Fup2 = 'de.test'
587 MID-Format = '<%n-%m.%y@domain.invalid>'
588 Supersede = yes
589
227afd47
TH
590=head3 Status Information
591
272b0243
TH
592Information about the last post and about how to form message IDs for
593posts is stored in a file named F<I<project name>.cfg> which will be
594generated if it does not exist. Each of those status files will
595contain two lines, the first being the date of the last time the FAQ
596was posted and the second being the message ID of that incarnation.
597
227afd47
TH
598=head2 Runtime Configuration
599
600Apart from configuring which FAQ(s) to post you may (re)set some
601runtime configuration variables via the .rcfile (by default
602F<.yapfaqrc>). F<.yapfaqrc> must contain one definition in the form of
603I<param = value> on each line; everything after a "#" sign is ignored.
604
605If you omit some settings they will be set to default values hardcoded
606in F<yapfaq.pl>.
607
608B<Please note that all parameter names are case-sensitive!>
609
610=over 4
611
612=item B<NNTPServer> = I<NNTP server> (mandatory)
613
614Host name of the NNTP server to post to. Must be set (or omitted; the
615default is "localhost"); if set to en empty string, B<yapfaq> falls
616back to Perl's build-in defaults (contents of environment variables
617NNTPSERVER and NEWSHOST; if not set, default from Net::Config; if not
618set, "news" is used).
619
620=item B<NNTPUser> = I<user name> (optional)
621
622User name used for authentication with the NNTP server (I<AUTHINFO
623USER>).
624
625This setting is optional; if it is not set, I<NNTPPass> is ignored and
626no authentication is tried.
627
628=item B<NNTPPass> = I<password> (optional)
629
630Password used for authentication with the NNTP server (I<AUTHINFO
631PASS>).
632
633This setting is optional; it must be set if I<NNTPUser> is present.
634
635=item B<Sender> = I<Sender header> (optional)
636
637The Sender header that will be added to every posted message.
638
639This setting is optional.
640
641=item B<ConfigFile> = I<configuration file> (mandatory)
642
643The configuration file defining the FAQ(s) to post. Must be set (or
644omitted; the default is "yapfaq.cfg").
645
39cb5672
TH
646=item B<Program> = I<file name> (optional)
647
648A program the article is piped to instead of posting it to Usenet.
649See option "-f" below (which takes preference).
650
651This setting is optional.
652
227afd47
TH
653=back
654
655=head3 Example runtime configuration file
656
657 NNTPServer = 'localhost'
658 NNTPUser = ''
659 NNTPPass = ''
660 Sender = ''
661 ConfigFile = 'yapfaq.cfg'
39cb5672 662 Program = ''
227afd47
TH
663
664=head3 Using more than one runtime configuration
665
666You may use more than one runtime configuration file with the B<-c>
667option (see below).
668
272b0243
TH
669=head1 OPTIONS
670
671=over 3
672
a052296f
TH
673=item B<-V> (version)
674
675Print out version and copyright information on B<yapfaq> and exit.
676
272b0243
TH
677=item B<-h> (help)
678
ae3b1b79 679Print this man page and exit.
272b0243
TH
680
681=item B<-v> (verbose)
682
683Print out status information while running to STDOUT.
684
685=item B<-p> (post unconditionally)
686
687Post (all) FAQs unconditionally ignoring the posting frequency setting.
688
689You may want to use this with the B<-f> option (see below).
690
691=item B<-d> (dry run)
692
693Start B<yapfaq> in simulation mode, i.e. don't post anything and don't
694update any status information.
695
696=item B<-t> I<newsgroup(s) | CONSOLE> (test)
697
698Don't post to the newsgroups defined in F<yqpfaq.cfg>, but to the
699newsgroups given after B<-t> as a comma-separated list or print the
700FAQs to STDOUT separated by lines of dashes if the special string
701C<CONSOLE> is given. This can be used to preview what B<yapfaq> would
702do without embarassing yourself on Usenet. The status files are not
703updated when this option is given.
704
705You may want to use this with the B<-f> option (see below).
706
707=item B<-f> I<project name>
708
709Just deal with one FAQ only.
710
711By default B<yapfaq> will work on all FAQs that are defined in
712F<yapfaq.cfg>, check whether they are due for posting and - if they
713are - post them. Consequently when the B<-p> option is set all FAQs
714will be posted unconditionally. That may not be what you want to
715achieve, so you can limit the operation of B<yapfaq> to the named FAQ
716only.
717
b855559e
TH
718=item B<-s> I<program> (pipe to script)
719
720Instead of posting the article(s) to Usenet pipe them to the external
721I<program> on STDIN (which may post the article(s) then). A return
722value of 0 will be considered success.
723
0e741504
TH
724For example, you may want to use the I<inews> utility from the INN package
725or the much more powerful replacement I<tinews.pl> from
726I<ftp://ftp.tin.org/tin/tools/tinews.pl> which is able to sign postings.
727
39cb5672
TH
728If I<Program> is also defined in the runtime configuration file (by default
729F<.yapfaqrc>), B<-s> takes preference.
730
227afd47
TH
731=item B<-c> I<.rc file>
732
733Load another runtime configuration file (.rc file) than F<.yaofaq.rc>.
734
735You may for example define another usenet server to post your FAQ(s)
736to or load another configuration file defining (an)other FAQ(s).
737
272b0243
TH
738=back
739
740=head1 EXAMPLES
741
742Post all FAQs that are due for posting:
743
744 yapfaq
745
746Do a dry run, showing which FAQs would be posted:
747
748 yapfaq -dv
749
750Do a test run and print on STDOUT what the FAQ I<myfaq> would look
751like when posted, regardless whether it is due for posting or not:
752
753 yapfaq -pt CONSOLE -f myfaq
754
755Do a "real" test run and post the FAQ I<myfaq> to I<de.test>, but only
756if it is due:
757
758 yapfaq -t de.test -f myfaq
759
9817f98a
TH
760Post all FAQs (that are due for posting) using inews from INN:
761
762 yapfaq -s inews
763
764Do a dry run using a runtime configuration from .alternaterc, showing
765which FAQs would be posted:
766
767 yapfaq -dvc .alternaterc
768
272b0243
TH
769=head1 ENVIRONMENT
770
9817f98a
TH
771=over 4
772
773=item NNTPSERVER
774
775The default NNTP server to post to, used by the Net::NNTP module. You
776can also specify the server using the runtime configuration file (by
777default F<.yapfaqrc>).
778
779=back
272b0243
TH
780
781=head1 FILES
782
783=over 4
784
785=item F<yapfaq.pl>
786
787The script itself.
788
227afd47
TH
789=item F<.yapfaqrc>
790
791Runtime configuration file for B<yapfaq>.
792
272b0243
TH
793=item F<yapfaq.cfg>
794
795Configuration file for B<yapfaq>.
796
797=item F<*.cfg>
798
799Status data on FAQs.
800
801The status files will be created on successful posting if they don't
802already exist. The first line of the file will be the date of the last
803time the FAQ was posted and the second line will be the message ID of
804the last post of that FAQ.
805
806=back
807
808=head1 BUGS
809
2d8e5cdb
TH
810Please report any bugs or feature request to the author or use the
811bug tracker at L<http://bugs.th-h.de/>!
272b0243
TH
812
813=head1 SEE ALSO
814
815L<http://th-h.de/download/scripts.php> will have the current
816version of this program.
817
2d8e5cdb
TH
818This program is maintained using the Git version control system. You
819may clone L<git://code.th-h.de/usenet/yapfaq.git> to check out the
820current development tree or browse it on the web via
821L<http://code.th-h.de/?p=usenet/yapfaq.git>.
822
272b0243
TH
823=head1 AUTHOR
824
825Thomas Hochstein <thh@inter.net>
826
227afd47 827Original author (up to version 0.5b, dating from 2003):
272b0243
TH
828Marc Brockschmidt <marc@marcbrockschmidt.de>
829
272b0243
TH
830=head1 COPYRIGHT AND LICENSE
831
832Copyright (c) 2003 Marc Brockschmidt <marc@marcbrockschmidt.de>
833
834Copyright (c) 2010 Thomas Hochstein <thh@inter.net>
835
836This program is free software; you may redistribute it and/or modify it
837under the same terms as Perl itself.
838
839=cut
This page took 0.066678 seconds and 4 git commands to generate.