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