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