Debian Codegraph @

Article.pm

raw ◀ ▶
Source reconstructed at patch state 0 of 2 — not the installed (fully patched) source.
2 Debian patches touch this file
1 # -*- Perl -*-
2 ###########################################################################
3 # Written and maintained by Andrew Gierth <[email protected]>
4 # Thanks to Russ Allbery <[email protected]> for comment and significant
5 # contributions.
6 #
7 # Copyright 1997 Andrew Gierth. Redistribution terms at end of file.
8 #
9 # $Id: Article.pm 1.27 2002/08/11 22:51:38 andrew Exp $
10 #
11 # TODO:
12 # - better way of handling the system-dependent configuration
13 # - reformat source for 80 columns :-)
14 #
15 ###########################################################################
16 #
17 # Envelope, n. The coffin of a document; the scabbard of a bill; the husk
18 # of a remittance; the bed-gown of a love-letter.
19 # -- Ambrose Bierce
20 #
21
22 =head1 NAME
23
24 News::Article - Object for handling Usenet articles in mail or news form.
25
26 =head1 SYNOPSIS
27
28 use News::Article;
29
30 See below for functions available.
31
32 =head1 DESCRIPTION
33
34 An object for representing a Usenet article (or a mail
35 message). Primarily written for use with mail2news and/or moderation
36 programs. (Not really intended for transit use.)
37
38 =head1 USAGE
39
40 use News::Article;
41
42 Article exports nothing.
43
44 Article objects must be created with the I<new> method.
45
46 =cut
47
48 package News::Article;
49
50 use strict;
51 use SelfLoader;
52
53 use vars qw($VERSION @SENDMAIL %SPECIAL %UNIQUE);
54 use subs qw(canonical fix_envelope source_init);
55
56 ($VERSION = (split (' ', q$Revision: 1.27 $ ))[1]) =~ s/\.(\d)$/.0$1/;
57
58 ###########################################################################
59 # System-dependent configuration
60 #
61 # How to mail an article. The code assumes that this is a
62 # sendmail-workalike; i.e. can accept envelope recipients as arguments
63 # or -t to parse the headers for recipients. Also uses -f to set the
64 # envelope sender (this may cause problems on pre-V8 sendmails if
65 # used by an untrusted user).
66
67 @SENDMAIL = ((grep { -x $_ }
68 qw(/usr/sbin/sendmail /usr/lib/sendmail /bin/false))[0],
69 qw(-oi -oem));
70
71 # End of system-dependent configuration
72 ###########################################################################
73 # Constant data
74 #
75 # Words to treat specially when canonifying header names
76
77 %SPECIAL = map { lc $_ => $_ }
78 qw(- _ ID PGP UIDL MIME NNTP SMTP IP URL HTTP WWW MimeOLE);
79
80 # RFC1036 (and news generally) is much less tolerant of multiple
81 # fields than RFC822. 822 allows for multiple message-ids, which is
82 # arguably seriously broken, so we ignore that. We list here only the
83 # most significant news fields; handling the rest sensibly is up to
84 # the caller.
85
86 %UNIQUE = map { $_ => 1 }
87 qw(date followup-to from message-id newsgroups path reply-to
88 subject sender);
89
90 # Description of internal storage:
91 #
92 # $self->{Headers}
93 #
94 # A hash of header names to values. The value stored
95 # is always a reference to an array of values. The value stored
96 # always includes embedded newlines and whitespace, but not the
97 # header name or leading whitespace after the colon. There is no
98 # trailing newline on the value.
99 #
100 # $self->{RawHeaders}
101 #
102 # Array of headers as read from external source. One header per
103 # element, with embedded newlines preserved (but trailing ones
104 # removed).
105 #
106 # $self->{HeaderSeq}
107 #
108 # Only set if headers have been read in; array of canonical header
109 # names, in the order they were read in. Used to derive this from
110 # RawHeaders, but that's wrong if read_headers has been called more
111 # than once.
112 #
113 # $self->{Envelope}
114 #
115 # Envelope From address. Set from a Unix-style "From " header on
116 # read. When sending mail, the value here is used (unless undefined)
117 # as the envelope sender.
118 #
119 # $self->{Body}
120 #
121 # Array of text lines forming the body. Never contains embedded
122 # newlines.
123 #
124 # $self->{Sendmail}
125 #
126 # What to use to send mail.
127 #
128 # $self->{HdrsFirst}, $self->{HdrsEnd}, $self->{HdrsLast}
129 #
130 # settings of headers_first, headers_next and headers_last
131 #
132
133 ###########################################################################
134 # CONSTRUCTION
135 ###########################################################################
136
137 =head2 Article Methods
138
139 =over 4
140
141 =item new ()
142
143 =item new ( SOURCE [,MAXSIZE [,MAXHEADS]] )
144
145 Use this to create a new Article object. Makes an empty article if no
146 parameters are specified, otherwise reads in an article from C<SOURCE>
147 as for C<read>.
148
149 =cut
150
151 sub new
152 {
153 my $proto = shift;
154 my $class = ref($proto) || $proto;
155 my $self = {
156 Headers => {},
157 RawHeaders => [],
158 Envelope => undef,
159 Sendmail => [ @SENDMAIL ],
160 Body => [],
161 };
162 bless $self,$class;
163
164 if (@_)
165 {
166 return undef unless defined ($_[0]);
167 $self->read(@_) or return undef;
168 }
169
170 $self;
171 }
172
173 # this shouldn't be needed. But SelfLoader tries to load it in derived
174 # modules if it's not found here, and those modules may not have __DATA__
175 # tokens, leading to rude error messages.
176
177 sub DESTROY {}
178
179 SelfLoader->load_stubs();
180
181 1;
182
183 __DATA__
184
185 #--------------------------------------------------------------------------
186
187 =item clone ()
188
189 Create a new Article as an exact clone of the current one.
190 Returns a ref to the new object.
191
192 =cut
193
194 sub clone
195 {
196 my $src = shift;
197 my $class = ref($src);
198 my $headers = {};
199 my $obj = {
200 Headers => $headers,
201 RawHeaders => [ @{$src->{RawHeaders}} ],
202 HeaderSeq => [ defined($src->{HeaderSeq}) ? @{$src->{HeaderSeq}} : () ],
203 Envelope => $src->{Envelope},
204 Sendmail => [ @{$src->{Sendmail}} ],
205 Body => [ @{$src->{Body}} ],
206 };
207
208 # must deep-copy the headers hash elements, otherwise they
209 # get shared with rather messy results.
210
211 for (keys %{$src->{Headers}})
212 {
213 $headers->{$_} = [ @{$src->{Headers}{$_}} ];
214 }
215
216 # copy default header sequence info too
217
218 for (qw(HdrsFirst HdrsEnd HdrsLast))
219 {
220 $obj->{$_} = [ @{$src->{$_}} ] if defined($src->{$_});
221 }
222
223 return bless $obj,$class;
224 }
225
226 ###########################################################################
227 # HEADER MANIPULATION
228 ###########################################################################
229
230 =item envelope ( [SENDER] )
231
232 If C<SENDER> is specified, sets the envelope sender to the specified
233 value (which will then subsequently be used if the article is mailed).
234 Returns the (new or current) envelope sender in any case.
235
236 =cut
237
238 sub envelope
239 {
240 my $self = shift;
241 return $self->{Envelope} = shift if (@_);
242 $self->{Envelope};
243 }
244
245 #--------------------------------------------------------------------------
246
247 =item rawheaders ()
248
249 Returns a list (or a reference to an array if in scalar context) of
250 the original header lines of the article, as read from the input
251 source. Terminating newlines are not included. (Continued headers are
252 returned as single strings with embedded newlines.)
253
254 =cut
255
256 sub rawheaders
257 {
258 my $self = shift;
259 wantarray ? @{$self->{RawHeaders}} : $self->{RawHeaders};
260 }
261
262 #--------------------------------------------------------------------------
263
264 =item header_names ()
265
266 Returns a list of the names of all headers currently present
267 in the article.
268
269 =cut
270
271 sub header_names
272 {
273 my $self = shift;
274 keys %{$self->{Headers}};
275 }
276
277 #--------------------------------------------------------------------------
278
279 =item headers ([FIRST [,NEXT [,LAST]]])
280
281 Returns a list of all header strings with no terminating
282 newlines. Continued headers will have embedded newlines.
283
284 FIRST, NEXT and LAST are optional references to arrays of header
285 names. The order of the returned headers is as follows:
286
287 - headers specified by FIRST (one value only per name)
288 - headers in the order originally read in (if any)
289 - headers specified by NEXT (one value only per name)
290 - any remaining headers not named in LAST, sorted by name
291 - headers named in LAST (all values)
292
293 LAST overrides the original order of headers, but NEXT does not.
294 Headers named in LAST will also be grouped together by header name.
295
296 =cut
297
298 sub headers
299 {
300 my $self = shift;
301 my $hdrs = $self->{Headers};
302 my @preseq = map { canonical $_ } @{shift || $self->{HdrsFirst} || []};
303 my @addseq = map { canonical $_ } @{shift || $self->{HdrsEnd} || []};
304 my @postseq = map { canonical $_ } @{shift || $self->{HdrsLast} || []};
305 my %postseq = map { $_ => 1 } @postseq;
306
307 # this hash gets all the headers in the form that we will use to
308 # output them. Each value is an array of strings of the form
309 # "Header-Name: value". The keys are in canonical rather than
310 # internal form.
311 my %tmph = map { my $h = canonical($_);
312 ($h, [ map { $h.": ".$_ } @{$hdrs->{$_}} ])
313 } keys %$hdrs;
314
315 # original sequence of headers (if any) excluding those we wish
316 # to force to the end.
317 my @seq = grep { !$postseq{$_} } @{$self->{HeaderSeq} || []};
318
319 # build the required list
320 ((map { my $v = $tmph{$_}; $v && @$v ? shift(@$v) : (); } @preseq),
321 (map { my $v = $tmph{$_}; $v && @$v ? shift(@$v) : (); } @seq),
322 (map { my $v = $tmph{$_}; $v && @$v ? shift(@$v) : (); } @addseq),
323 (map { my $v = $tmph{$_}; $v && @$v ? (@{$tmph{$_}}) : () }
324 sort grep { !$postseq{$_} } keys %tmph),
325 (map { my $v = $tmph{$_}; $v && @$v ? (@{$tmph{$_}}) : () } @postseq));
326 }
327
328 # the above is admittedly somewhat hairy.
329
330 #sub headers
331 #{
332 # my $headers = $_[0]{Headers};
333 # map {
334 # my $header = canonical($_);
335 # map { $header.": ".$_ } @{$headers->{$_}};
336 # } keys %$headers;
337 #}
338
339 =item headers_first (HDR...)
340
341 Set default ordering for headers().
342
343 =cut
344
345 sub headers_first
346 {
347 shift->{HdrsFirst} = [ @_ ];
348 }
349
350 =item headers_next (HDR...)
351
352 Set default ordering for headers().
353
354 =cut
355
356 sub headers_next
357 {
358 shift->{HdrsEnd} = [ @_ ];
359 }
360
361 =item headers_last (HDR...)
362
363 Set default ordering for headers().
364
365 =cut
366
367 sub headers_last
368 {
369 shift->{HdrsLast} = [ @_ ];
370 }
371
372 #--------------------------------------------------------------------------
373
374 =item set_headers ( NAME, VALUE [, NAME, VALUE [...]] )
375
376 For each header name supplied, replace any current occurences of the
377 header with the specified value(s). Each value may be a single scalar,
378 or a reference to an array of values. Returns undef without completing
379 the assignments if any attempt is made to supply multiple values for a
380 unique header. Undef or empty values cause the header to be deleted.
381 (If an array is supplied, it is not copied. This is probably a mistake
382 and should not be relied on.)
383
384 =cut
385
386 sub set_headers
387 {
388 my $self = shift;
389
390 while (@_)
391 {
392 my $name = lc shift;
393 my $val = shift;
394
395 delete $self->{Headers}{$name} and next
396 if !defined($val) || (ref($val) && @$val < 1);
397
398 $val = [ $val ] unless ref($val);
399
400 return undef if $UNIQUE{$name} && @$val > 1;
401
402 $self->{Headers}{$name} = $val;
403 }
404
405 1;
406 }
407
408 #--------------------------------------------------------------------------
409
410 =item add_headers ( NAME, VALUE [, NAME, VALUE [...]] )
411
412 Add new header values without affecting existing ones. Each value is
413 either a single scalar, or a reference to an array of values. Returns
414 undef without completing if any attempt is made to supply duplicate
415 values for a unique header. (If an array reference is supplied, the
416 array is copied.)
417
418 =cut
419
420 sub add_headers
421 {
422 my $self = shift;
423
424 while (@_)
425 {
426 my $name = lc shift;
427 my $val = shift;
428 next unless defined($val);
429
430 $val = [ $val ] unless ref($val);
431 my $curval = \@{$self->{Headers}{$name}}; # magic
432
433 return undef if ($UNIQUE{$name} && (@$val + @$curval > 1));
434
435 push @$curval,@$val;
436 }
437 }
438
439 # explanation of 'magic': $curval gets a reference to an array which
440 # is also referred to by $self->{Headers}{$name} - *even* if there was
441 # no previous value for $self->{Headers}{$name} (if necessary, a new
442 # anon array springs into existence)
443
444 #--------------------------------------------------------------------------
445
446 =item drop_headers ( NAME [, NAME [...]] )
447
448 Delete all values of the specified header(s).
449
450 =cut
451
452 sub drop_headers
453 {
454 my $self = shift;
455 for (@_)
456 {
457 delete $self->{Headers}{lc $_};
458 }
459 }
460
461 #--------------------------------------------------------------------------
462
463 =item header ( NAME )
464
465 Returns a list of values for the specified header. Returns a null list
466 if the header does not exist. In scalar context, returns the first
467 value found or undef.
468
469 =cut
470
471 sub header
472 {
473 my $self = shift;
474 my $name = lc shift;
475 my $val = $self->{Headers}{$name};
476
477 return defined($val) ? @$val : () if wantarray;
478 return $val->[0];
479 }
480
481 #--------------------------------------------------------------------------
482
483 =item rename_header ( SRC, DEST [, ACTION] )
484
485 Transform the name of a header without touching the value. Fails
486 if the source header does not exist. Returns undef on failure,
487 true on success.
488
489 Optional ACTION (may be "drop", "clobber", "add", or "fail"
490 (default)), specifies what to do if both source and destination exist:
491
492 ACTION PREVIOUS DEST
493 drop unchanged (SRC dropped)
494 clobber dropped (SRC replaces DEST)
495 add preserved (SRC added to DEST)
496 fail unchanged (operation fails)
497
498 =cut
499
500 sub rename_header
501 {
502 my $self = shift;
503 my $oldname = lc shift;
504 my $newname = lc shift;
505 my $action = shift || 'fail';
506
507 return undef unless exists($self->{Headers}{$oldname});
508
509 if (exists($self->{Headers}{$newname}))
510 {
511 return undef if $action eq 'fail';
512 }
513 else
514 {
515 $action = 'clobber';
516 }
517
518 my $oldval = delete $self->{Headers}{$oldname};
519
520 if ($action eq 'clobber') { $self->{Headers}{$newname} = $oldval; }
521 elsif ($action eq 'add') { $self->add_headers($newname, $oldval); }
522
523 1;
524 }
525
526 ###########################################################################
527 # ARTICLE BODY
528 ###########################################################################
529
530 =item body ()
531
532 Return the body of the article as a list of lines (no newlines),
533 or a reference to an array in scalar context (the array may be
534 modified in this case).
535
536 =cut
537
538 sub body
539 {
540 wantarray ? @{$_[0]->{Body}} : $_[0]->{Body};
541 }
542
543 #--------------------------------------------------------------------------
544
545 =item lines ()
546
547 Returns the number of lines in the article body.
548
549 =cut
550
551 sub lines
552 {
553 my $self = shift;
554 scalar(@{$self->{Body}});
555 }
556
557 #--------------------------------------------------------------------------
558
559 =item bytes ()
560
561 Returns the total size of the article body, not counting newlines.
562
563 =cut
564
565 sub bytes
566 {
567 my $self = shift;
568 my $total = 0;
569 for (@{$self->{Body}})
570 {
571 $total += length($_);
572 }
573 $total;
574 }
575
576 #--------------------------------------------------------------------------
577
578 =item set_body ( BODY )
579
580 Replace the current article body with the specified text. Expects a
581 list, each item of which is either one line, or multiple lines
582 separated by newlines. (Trailing newlines on the values are ignored.)
583
584 =cut
585
586 sub set_body
587 {
588 my $self = shift;
589 $self->{Body} = [];
590 $self->add_body(@_);
591 }
592
593 #--------------------------------------------------------------------------
594
595 =item add_body ( BODY )
596
597 Append the specified text to the current article body. Expects a
598 list, each item of which is either one line, or multiple lines
599 separated by newlines, or a reference to an array of lines. (Trailing
600 newlines on the values are ignored.)
601
602 =cut
603
604 sub add_body
605 {
606 my $self = shift;
607 my $body = $self->{Body};
608
609 for (@_)
610 {
611 if (ref($_))
612 {
613 $self->add_body(@$_);
614 }
615 else
616 {
617 my @lines = split(/\n/);
618 push @$body,@lines ? @lines : "";
619 }
620 }
621 }
622
623 #--------------------------------------------------------------------------
624
625 =item trim_blank_lines ()
626
627 Remove any trailing blank lines from the article body. Returns the
628 number of lines removed.
629
630 =cut
631
632 sub trim_blank_lines
633 {
634 my $body = shift->{Body};
635 my $n = 0;
636 while (@$body && $body->[$#$body] =~ /^\s*$/) { pop @$body; ++$n; }
637 return $n;
638 }
639
640 ###########################################################################
641 # INPUT FUNCTIONS
642 ###########################################################################
643
644 =item read_headers ( SOURCE, MAXSIZE )
645
646 Read article headers (terminated by an empty line) from the specified
647 source (see C<read> for defintion of allowed sources).
648
649 Gives up (returning undef) if more than MAXSIZE bytes are read. Returns
650 the amount read.
651
652 =cut
653
654 sub read_headers
655 {
656 my ($self, $source, $maxsz) = @_;
657 my $last = undef;
658 my $first = 1;
659 my $hhead = {};
660 my $name;
661 my $val;
662 my $size = 0;
663
664 # Nuke the body and hashed headers - always.
665
666 $self->{Body} = [];
667 $self->{Headers} = $hhead;
668
669 my $hseq = $self->{HeaderSeq} = [];
670
671 # If we have read some raw headers already, append a marker. This
672 # is partly to cope with C-news/ANU-news moderator mail, where the
673 # news article is encapsulated in a mail message rather than
674 # simply mailed, but we don't want to lose the mail path.
675
676 my $head = $self->{RawHeaders};
677 push @$head,"X-More-Headers: ----" if @$head;
678
679 # Set up the data source.
680
681 $source = source_init($source);
682 return undef unless defined($source);
683
684 my $line;
685
686 while (defined($line = &$source()))
687 {
688 # size limit
689
690 return undef if ($size += length($line)) > $maxsz;
691
692 chomp $line;
693 last if $line eq '';
694
695 for (split(/\n/,$line))
696 {
697 # lines of whitespace only are allowed in continuations - but
698 # we drop them as they serve no useful purpose
699 # XXX - what about signatures? not an issue for pgpmoose or
700 # signcontrol, neither of which allow continuations in
701 # signed headers at all, but could become an issue in the
702 # future - in which case this behaviour would have to be
703 # removed
704 next if /^\s*$/;
705
706 # Envelope From (unix-style). Must be the first line, and we trim
707 # off the timestamp if present
708
709 if (!$last && /^From (.*)$/)
710 {
711 $self->{Envelope} = fix_envelope($1);
712 next;
713 }
714
715 # Ignore bogus extra >From lines (procmail has a bad habit of adding
716 # these, unpredictably, unless you recompile it to trust everybody)
717 next if /^>From /;
718
719 # continuation line? If so, append to most recent data
720 if (/^\s/)
721 {
722 if (ref($last))
723 {
724 $head->[$#$head] .= "\n".$_;
725 $last->[$#$last] .= "\n".$_;
726 }
727 next;
728 }
729
730 # Extract header name and value. If the name looks
731 # unreasonable, hack around it to make the problem easily
732 # visible. We are deliberately over-strict in the allowed
733 # format of names (the RFCs allow any printable ASCII char
734 # other than whitespace or ':' in header names, but in
735 # practice only alphanumerics, '-' and (rarely) '_' are
736 # found). We lose any superfluous whitespace after the ':'
737 # here (only likely to be noticable for Subject lines).
738
739 if (/^([\w-]+):\s+(.*)$/)
740 {
741 $val = $2;
742 $name = lc $1;
743 }
744 else
745 {
746 $val = $_;
747 $name = "x-broken-header";
748 }
749
750 # Tack raw header onto array of raw headers
751
752 push @$hseq,canonical($name);
753 push @$head,$_;
754
755 # Add header to hash. Roughly equivalent to add_header, but
756 # handles duplicate unique headers silently
757
758 $last = \@{$hhead->{$name}};
759 push @$last,$val unless $UNIQUE{$name} && @$last;
760 }
761 }
762
763 $size;
764 }
765
766 #--------------------------------------------------------------------------
767
768 =item read_body ( SOURCE, MAXSIZE )
769
770 Read an article body from the specified source (see C<read>). Stops at
771 end of file; fails (returning undef) if MAXSIZE is reached prior to
772 that point. Returns the number of bytes read (may be 0 if the body is
773 null).
774
775 Trailing blank lines are NOT removed (an incompatible, but regrettably
776 necessary, change from previous versions); see trim_blank_lines if you
777 need to do that.
778
779 =cut
780
781 sub read_body
782 {
783 my ($self, $source, $maxsize) = @_;
784 my $size = 0;
785
786 # Set up the data source.
787
788 $source = source_init($source);
789 return undef unless defined($source);
790
791 my $body = $self->{Body} = [];
792 my $line;
793
794 while (defined($line = &$source()))
795 {
796 return undef if ($size += length($line)) > $maxsize;
797 chomp $line;
798 push @$body,"" unless $line;
799
800 for (split(/\n/,$line,-1))
801 {
802 push @$body,$_;
803 }
804 }
805
806 # return the article size
807 $size;
808 }
809
810 #--------------------------------------------------------------------------
811
812 =item read ( SOURCE [,MAXSIZE [,MAXHEADS]] )
813
814 Reads in an article from C<SOURCE>.
815
816 C<SOURCE> may be any of the following:
817
818 - a CODE ref, which is called to return lines or chunks of data
819
820 - an ARRAY ref, assumed to contain a list of lines with optional
821 line terminators
822
823 - a SCALAR ref, assumed to contain text with embedded newlines
824
825 - a scalar, assumed to be a filename, which is opened and read
826
827 - anything else is assumed to be a glob, reference to a glob,
828 or reference to a filehandle, and is read from accordingly
829
830 When reading in articles, C<MAXHEADS> is the maximum header size to
831 read (default 8k), and C<MAXSIZE> is the maximum article body size
832 (default 256k). If C<MAXSIZE> is explicitly specified as 0, then no
833 attempt at reading the body is made. Returns the total number of bytes
834 read, or undef if either limit is reached or no headers were found.
835
836 =cut
837
838 sub read
839 {
840 my ($self, $source, $maxsize, $maxhead) = @_;
841 my $hsize = 0;
842 my $bsize = 0;
843
844 $maxhead = 8192 unless $maxhead;
845 $maxsize = 262144 unless defined($maxsize);
846
847 # Set up the data source.
848
849 $source = source_init($source);
850 return undef unless defined($source);
851
852 $hsize = $self->read_headers($source,$maxhead)
853 or return undef;
854
855 if ($maxsize)
856 {
857 $bsize = $self->read_body($source,$maxsize);
858 return undef unless defined($bsize);
859 }
860
861 $hsize + $bsize;
862 }
863
864 ###########################################################################
865 # OUTPUT FUNCTIONS
866 ###########################################################################
867
868 =item write ( FILE )
869
870 Write the entire article to the specified filehandle reference.
871
872 =cut
873
874 sub write
875 {
876 my ($self, $fh) = @_;
877 print $fh join("\n", $self->headers(), "", @{$self->{Body}}, "");
878 }
879
880 =item write_unique_file ( DIR [,MODE] )
881
882 Write the article to a (hopefully) uniquely-named file in the
883 specified directory. The file is written under a temporary name (with
884 a leading period) and relinked when complete. Returns 1 if successful,
885 otherwise undef.
886
887 MODE is the access mode to use for the created file (default 644);
888 this will be modified in turn by the current umask.
889
890 The implementation is careful to avoid losing the file or clobbering
891 existing files even in the case of a name collision, but relies on
892 POSIX link() semantics and may fail on lesser operating systems
893 (or buggy NFS implementations).
894
895 =cut
896
897 sub write_unique_file;
898
899 use POSIX qw(:errno_h);
900 use Fcntl;
901 use FileHandle ();
902
903 ; sub write_unique_file
904 {
905 my ($self, $dir, $mode) = @_;
906
907 return undef unless defined($dir) and length($dir);
908 $mode = 0644 unless defined($mode);
909
910 my ($name,$tname,$fh);
911
912 do
913 {
914 $tname = $name = $self->_unique_name();
915 $tname =~ s/^././;
916 $fh = FileHandle->new("$dir/$tname", O_CREAT|O_EXCL|O_WRONLY, $mode);
917 }
918 while (!$fh && $! == &EEXIST);
919 return undef unless $fh;
920
921 my $success;
922
923 if ($self->write($fh) && $fh->close())
924 {
925 while (!link("$dir/$tname","$dir/$name") && $! == &EEXIST)
926 {
927 $name = $self->_unique_name();
928 }
929 $success = 1;
930 }
931
932 unlink("$dir/$tname");
933 return $success;
934 }
935
936 #--------------------------------------------------------------------------
937
938 =item write_original ( FILE )
939
940 Write the original headers followed by the article body to the
941 specified filehandle reference.
942
943 =cut
944
945 sub write_original
946 {
947 my ($self, $fh) = @_;
948 print $fh join("\n", @{$self->{RawHeaders}}, "", @{$self->{Body}}, "");
949 }
950
951 ###########################################################################
952 # MAIL FUNCTIONS
953 ###########################################################################
954
955 =item sendmail ( [COMMAND] )
956
957 Get or set the command and options that will be used to mail the
958 article. Defaults to a system dependent value such as
959 /usr/sbin/sendmail -oi -oem
960
961 =cut
962
963 sub sendmail
964 {
965 my $self = shift;
966 $self->{Sendmail} = [ @_ ] if (@_);
967 @{$self->{Sendmail}};
968 }
969
970 #--------------------------------------------------------------------------
971
972 =item mail ( [RECIPIENTS...] )
973
974 Mails the article to the specified list of recipients, or to the
975 addressed recipients in the header (To, Cc, Bcc) if none are supplied.
976 Attempts to set the envelope sender to the stored envelope sender, if
977 set, so unset that before mailing if you do not want this behavior.
978
979 =cut
980
981 sub mail;
982
983 use FileHandle ();
984 use IPC::Open3 qw(open3);
985
986 ; sub mail
987 {
988 my ($self, @recipients) = @_;
989 my @command = @{$self->{Sendmail}};
990 push @command,'-f',$self->{Envelope} if (defined($self->{Envelope}));
991 push @command, @recipients ? @recipients : '-t';
992
993 my $sendmail = FileHandle->new();
994 my $errors = FileHandle->new();
995
996 eval { open3 ($sendmail, $errors, $errors, @command) };
997 if ($@) { return undef }
998
999 local $SIG{PIPE} = 'IGNORE';
1000
1001 $self->write($sendmail);
1002 close $sendmail;
1003
1004 # Check the return status of sendmail to see if we were successful.
1005 $? == 0;
1006 }
1007
1008 ###########################################################################
1009 # NEWS FUNCTIONS
1010 ###########################################################################
1011
1012 =item post ( [CONN] )
1013
1014 Post the article. Avoids inews due to undesirable header munging and
1015 unwarranted complaints to stderr. Takes an optional parameter which is
1016 a Net::NNTP reference. If supplied, posts the article to it;
1017 otherwise opens a new reader connection and posts to that.
1018
1019 Throws an exception containing the error message on failure.
1020
1021 =cut
1022
1023 sub post;
1024
1025 use Net::NNTP ();
1026
1027 ; sub post
1028 {
1029 my $self = shift;
1030 my $server = shift;
1031
1032 if (!$server)
1033 {
1034 $server = Net::NNTP->new();
1035 die "Unable to connect to server" unless $server;
1036 $server->reader();
1037 }
1038
1039 $server->post(join("\n", $self->headers(), "", @{$self->{Body}}))
1040 or die $server->code().' '.($server->message())[-1];
1041
1042 1;
1043 }
1044
1045 =item ihave ( [CONN] )
1046
1047 Inject the article. Takes an optional parameter which is a Net::NNTP
1048 reference. If supplied, posts the article to it; otherwise opens a
1049 new transport connection and posts to that. All required headers must
1050 already be present, including Path and Message-ID.
1051
1052 Throws an exception containing the error message on failure.
1053
1054 =cut
1055
1056 sub ihave;
1057
1058 use Net::NNTP ();
1059
1060 ; sub ihave
1061 {
1062 my $self = shift;
1063 my $server = shift;
1064
1065 my $msgid = $self->header('message-id');
1066 die "Article contains no message-id" unless $msgid;
1067
1068 if (!$server)
1069 {
1070 $server = Net::NNTP->new();
1071 die "Unable to connect to server" unless $server;
1072 }
1073
1074 $server->ihave($msgid, join("\n", $self->headers(), "", @{$self->{Body}}))
1075 or die $server->code().' '.($server->message())[-1];
1076
1077 1;
1078 }
1079
1080 #--------------------------------------------------------------------------
1081
1082 =item add_message_id ( [PREFIX [, DOMAIN] ] )
1083
1084 If the current article lacks a message-id, then create one.
1085
1086 =cut
1087
1088 sub add_message_id;
1089
1090 use Net::Domain qw(hostfqdn);
1091
1092 ; sub add_message_id
1093 {
1094 my $self = shift;
1095 return undef if $self->{Headers}{'message-id'};
1096
1097 my $prefix = shift || '';
1098 my $domain = shift || hostfqdn() || 'broken-configuration';
1099 my ($sec,$min,$hr,$mday,$mon,$year) = gmtime(time);
1100 ++$mon;
1101 $self->set_headers('message-id',
1102 sprintf('<%s%04d%02d%02d%02d%02d%02d$%04x@%s>',
1103 $prefix,
1104 $year+1900, $mon, $mday, $hr, $min, $sec,
1105 0xFFFF & (rand(32768) ^ $$), $domain));
1106 }
1107
1108 #--------------------------------------------------------------------------
1109
1110 =item add_date ( [TIME] )
1111
1112 If the current article lacks a date, then add one (in local time).
1113 If TIME is specified (numerical Unix time), it is used instead of the
1114 current time.
1115
1116 =cut
1117
1118 sub add_date
1119 {
1120 my $self = shift;
1121 return undef if $self->{Headers}{'date'};
1122
1123 my $now = shift || time;
1124 my ($sec,$min,$hr,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($now);
1125 my ($gsec,$gmin,$ghr,$gmday) = gmtime($now);
1126
1127 # mystic incantations to calculate zone offset from difference
1128 # between UTC and local time. Assumes that difference is not more
1129 # than a full day (saves having to take months into consideration).
1130 # ANSI is apparently going to add a spec to strftime() to do this,
1131 # but that isn't yet commonly available.
1132
1133 use integer;
1134 $gmday = $mday + ($mday <=> $gmday) if (abs($mday-$gmday) > 1);
1135 my $tzdiff = 24*60*($mday-$gmday) + 60*($hr-$ghr) + ($min-$gmin);
1136 my $tz = sprintf("%+04.4d", $tzdiff + ($tzdiff/60*40));
1137
1138 $mon = (qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec))[$mon];
1139 $wday = (qw(Sun Mon Tue Wed Thu Fri Sat Sun))[$wday];
1140 $year += 1900;
1141 $self->set_headers('date',
1142 sprintf("%s, %02d %s %d %02d:%02d:%02d %s",
1143 $wday,$mday,$mon,$year,$hr,$min,$sec,$tz));
1144 }
1145
1146
1147 ###########################################################################
1148 # AUTHENTICATION FUNCTIONS
1149 ###########################################################################
1150
1151 # Internal function used by PGPMoose sign/verify code
1152
1153 sub pgpmoose_canon_headers
1154 {
1155 my ($self, $bug_compatible) = @_;
1156
1157 # Now, put together all of the stuff we need to sign. First, we need a
1158 # list of newsgroups, sorted.
1159
1160 my $headers = $self->header('newsgroups');
1161 $headers =~ s/\s//g;
1162 $headers = join("\n", (sort split(/,+/, $headers)), '');
1163
1164 # Next we need an array of headers: From, Subject, and Message-ID in
1165 # that order, killing initial and final whitespace and any spaces after
1166 # colons.
1167 # PGPMoose V1.1 has a gross bug: it includes, as though they were headers,
1168 # any body lines that look like headers. Do this only if $bug_compatible
1169
1170 my %heads = map { ($_, [ $self->header($_) ]) } qw(from subject message-id);
1171
1172 if ($bug_compatible)
1173 {
1174 for (@{$self->{Body}})
1175 {
1176 /^from: *(.*)$/i && push @{$heads{from}},$1;
1177 /^subject: *(.*)$/i && push @{$heads{subject}},$1;
1178 /^message-id: *(.*)$/i && push @{$heads{'message-id'}},$1;
1179 }
1180 }
1181
1182 for (@heads{'from','subject','message-id'})
1183 {
1184 for (@$_)
1185 {
1186 s/\n.*//;
1187 s/^ +//;
1188 s/\s*$/\n/;
1189 s/: +/:/g;
1190 $headers .= $_;
1191 }
1192 }
1193
1194 $headers;
1195 }
1196
1197 =item sign_pgpmoose ( GROUP, PASSPHRASE [, KEYID] )
1198
1199 Signs the article according to the PGPMoose spec. We require that pgp be
1200 on the path to do this. Takes a "group" which can be either a newsgroup
1201 or an address, a PGP password, and an optional key id and returns a null
1202 list on success, the PGP error output as a list on failure.
1203
1204 If the key id is omitted, we will assume that if the group is an e-mail
1205 address, the key id is that address surrounded by <>, and otherwise the
1206 key id will be the group with a space on either side. This is so that one
1207 can help PGP distinguish between the keys for (say) mod.config and
1208 mod.config.status. The PGP key id should be something like:
1209
1210 Moderator of group.name <[email protected]>
1211
1212 The article to be signed must already have all of the headers needed by
1213 PGPMoose (Newsgroups, From, Subject) or this will fail. Message-ID is
1214 added if necessary.
1215
1216 =cut
1217
1218 sub sign_pgpmoose;
1219
1220 use PGP::Sign qw(pgp_sign pgp_verify pgp_error);
1221
1222 ; sub sign_pgpmoose
1223 {
1224 my ($self, $group, $passphrase, $keyid) = @_;
1225
1226 # If we don't have a key id, try to generate one from the group.
1227 # Surround it by angle brackets if it's an e-mail address or by spaces
1228 # if it's a group.
1229
1230 $keyid = ($group =~ /\@/) ? "<$group>" : " $group "
1231 unless (defined $keyid);
1232
1233 # Check to make sure we have the required headers.
1234 for (qw(newsgroups from subject))
1235 {
1236 return ("Required header $_ missing")
1237 unless $self->{Headers}{$_};
1238 }
1239
1240 $self->add_message_id() unless $self->{Headers}{'message-id'};
1241
1242 # Now, put together all of the stuff we need to sign.
1243 # XXX generate V1.1 bug-compatible version for now.
1244
1245 my $headers = $self->pgpmoose_canon_headers(1);
1246
1247 # Finally, we need to give it the body of the article, making the
1248 # following transformations:
1249 #
1250 # - Lines consisting solely of spaces are deleted.
1251 # - A leading "--" is replaced by "- --"
1252 # - A leading "from" (case-insensitive) has > prepended.
1253 # - A leading "subject" (case-insensitive) has > prepended.
1254 # - A leading single "." is changed to "..".
1255 # - All trailing whitespace on a line is removed.
1256 #
1257 # The easy way to do this is to define an anonymous sub that sends back
1258 # a line at a time. That way, we don't end up wasting memory by storing
1259 # two copies of the article body (which could potentially be long).
1260 my $body;
1261 {
1262 my $line = 0;
1263 $body = sub {
1264 my $text;
1265 do
1266 {
1267 $text = $self->{Body}[$line++];
1268 return undef unless defined $text;
1269 } while ($text =~ /^ *$/);
1270 $text =~ s/^--/- --/;
1271 $text =~ s/^(from|subject)/>$1/i;
1272 $text =~ s/^\.($|[^.])/..$1/;
1273 $text =~ s/\s+$//;
1274 $text . "\n";
1275 }
1276 }
1277
1278 # Now, actually calculate the signature and add it to the headers.
1279 my $signature = pgp_sign ($keyid, $passphrase, $headers, $body);
1280 return pgp_error
1281 unless defined($signature);
1282
1283 $signature =~ s/\n(.)/\n\t$1/g;
1284 $self->add_headers('x-auth', "PGPMoose V1.1 PGP $group\n\t$signature");
1285 return ();
1286 }
1287
1288 #--------------------------------------------------------------------------
1289
1290 =item verify_pgpmoose ( GROUP )
1291
1292 Verifies an article signature according to the PGPMoose spec. We
1293 require that pgp be on the path to do this. Takes a "group" which can
1294 be either a newsgroup or an address, and an optional key id.
1295
1296 Looks for a X-Auth header matching the specified group or address, and
1297 if found, checks the validity of the signature. If successful, returns
1298 the signer identity (from the PGP output), otherwise returns false.
1299
1300 =cut
1301
1302 sub verify_pgpmoose;
1303
1304 use PGP::Sign qw(pgp_sign pgp_verify pgp_error);
1305
1306 ; sub verify_pgpmoose
1307 {
1308 my ($self, $group, $keyid) = @_;
1309
1310 my $sig = (grep(/^ PGPMoose \s+ V\d\.\d \s+ PGP \s+ \Q$group\E \n /isx,
1311 $self->header('x-auth')))[0];
1312
1313 return undef unless $sig;
1314
1315 my ($ver) = $sig =~ /^ PGPMoose \s+ V(\d\.\d) \s+/isx;
1316
1317 $sig =~ s/[^\n]*\n//;
1318 $sig =~ s/\t//g;
1319
1320 # Now, put together all of the stuff we need to sign.
1321 # XXX Optimistically, assume that pmcanon will be fixed after 1.1.
1322
1323 my $headers = $self->pgpmoose_canon_headers($ver eq '1.1');
1324
1325 # Finally, we need to give it the body of the article, making the
1326 # following transformations:
1327 #
1328 # - Lines consisting solely of spaces are deleted.
1329 # - A leading "--" is replaced by "- --"
1330 # - A leading "from" (case-insensitive) has > prepended.
1331 # - A leading "subject" (case-insensitive) has > prepended.
1332 # - A leading single "." is changed to "..".
1333 # - All trailing whitespace on a line is removed.
1334 #
1335 # The easy way to do this is to define an anonymous sub that sends back
1336 # a line at a time. That way, we don't end up wasting memory by storing
1337 # two copies of the article body (which could potentially be long).
1338 my $body;
1339 {
1340 my $line = 0;
1341 $body = sub {
1342 my $text;
1343 do
1344 {
1345 $text = $self->{Body}[$line++];
1346 return undef unless defined $text;
1347 } while ($text =~ /^ *$/);
1348 $text =~ s/^--/- --/;
1349 $text =~ s/^(from|subject)/>$1/i;
1350 $text =~ s/^\.($|[^.])/..$1/;
1351 $text =~ s/\s+$//;
1352 $text . "\n";
1353 }
1354 }
1355
1356 pgp_verify ($sig, undef, $headers, $body);
1357 }
1358
1359 #--------------------------------------------------------------------------
1360
1361 =item sign_control ( KEYID, PASSPHRASE [, HEADER [...] ] )
1362
1363 Signs the article in the manner used for control messages. This is
1364 derived from signcontrol, written by David Lawrence, but with fewer sanity
1365 checks since we assume people know what they're doing. Caveat programmer.
1366
1367 We take a key id, a PGP password, and an optional list of extra
1368 headers to add to the signature. By default, Subject, Control,
1369 Message-ID, Date, From, and Sender are signed. Any signed header that
1370 isn't present in the article will be signed with an empty value. Date
1371 and Message-ID are automatically added if needed.
1372
1373 =cut
1374
1375 sub sign_control;
1376
1377 use PGP::Sign qw(pgp_sign pgp_verify pgp_error);
1378
1379 ; sub sign_control
1380 {
1381 my ($self, $keyid, $passphrase, @extra) = @_;
1382 my @headers = qw(subject control message-id date from sender);
1383 push @headers, map {lc $_} @extra;
1384
1385 # Check to make sure we have the required headers.
1386 for (qw(subject control from))
1387 {
1388 return ("Required header $_ missing")
1389 unless $self->{Headers}{$_};
1390 }
1391
1392 $self->add_message_id('cmsg-') unless $self->{Headers}{'message-id'};
1393 $self->add_date();
1394
1395 # We have to sign the list of headers and each header on a seperate
1396 # line. Note that the verification code doesn't support continuation
1397 # headers, so be careful not to use them when calling this method.
1398
1399 my $signheads = join (',', map { canonical $_ } @headers);
1400 my @sign;
1401 push (@sign, 'X-Signed-Headers: ' . $signheads . "\n");
1402 for (@headers)
1403 {
1404 push (@sign, (canonical $_).": ".($self->header($_) || '')."\n");
1405 }
1406
1407 # Now send everything to PGP to sign. We have to add a new line to the
1408 # end of every line of the body, since we're storing it without them.
1409 # Make sure we munge for attached signatures, since pgpverify tests with
1410 # an attached signature.
1411 local $PGP::Sign::MUNGE = 1;
1412 my $body;
1413 {
1414 my $line = 0;
1415 $body = sub {
1416 my $text = $self->{Body}[$line++];
1417 defined $text ? $text . "\n" : undef;
1418 }
1419 }
1420 my ($signature, $version) =
1421 pgp_sign ($keyid, $passphrase, \@sign, "\n", $body);
1422 return pgp_error
1423 unless defined($signature);
1424
1425 # Add tabs after the newlines and add the signature to the headers.
1426 $signature =~ s/\n(.)/\n\t$1/g;
1427
1428 # Fix up version field (needed for at least PGP 6.5.1i)
1429 $version =~ s/^[PGpg]+\s+//; # remove initial PGP or GPG or whatever
1430 $version =~ s/\s+/_/g; # convert any remaining whitespace
1431
1432 $self->add_headers('x-pgp-sig', "$version $signheads\n\t$signature");
1433 return ();
1434 }
1435
1436 ###########################################################################
1437 # INTERNAL METHODS
1438 ###########################################################################
1439
1440 # Unique name generator for write_unique_file. This is called as a method
1441 # to allow it to be overridden (should anyone want to). The implementation
1442 # specifically takes account of the possibility of multiple calls in quick
1443 # succession from the same process (and possibly different objects, which
1444 # is why $unique_count is not an instance variable).
1445
1446 sub _unique_name;
1447
1448 my $unique_count = "aa";
1449
1450 ; sub _unique_name
1451 {
1452 my $name = sprintf("%08x%04x%2s",
1453 time & 0xffffffff,
1454 $$ & 0xffff,
1455 $unique_count);
1456 $unique_count = "aa" if (length(++$unique_count) > 2);
1457 return $name;
1458 }
1459
1460 ###########################################################################
1461 # INTERNAL FUNCTIONS
1462 ###########################################################################
1463
1464 # really ought to convert some of these to methods.
1465
1466 # Convert a header name to canonical capitalisation. We keep the header
1467 # names in lowercase internally to simplify, but prefer to emit standard-
1468 # looking forms on output.
1469
1470 sub canonical
1471 {
1472 my $name = lc shift;
1473 join('',map { ($SPECIAL{$_} || ucfirst $_); } split(/([_-])/,$name));
1474 }
1475
1476 # Fix up an envelope sender taken from a Unix-style "From" line.
1477
1478 # This isn't guaranteed to work due to variations in From line
1479 # format. An explicit decision has been made to trust the
1480 # header format *rather than* the sanity of the envelope
1481 # address, because we have no control over the latter, whereas
1482 # the former is generated by local software and therefore
1483 # should be fixable if it is too insane.
1484
1485 # Theory:
1486 # If there's a timestamp (check for MMM DDD NN HH:MM) then remove
1487 # it and everything following it. Otherwise remove any trailing
1488 # text resembling 'remote from ...'.
1489 # Then remove trailing spaces from the result and return it.
1490
1491 sub fix_envelope
1492 {
1493 my $from = shift;
1494
1495 $from =~ s/\s \w\w\w \s \w\w\w \s [\d\s]\d \s \d\d:\d\d(:\d\d)? \s .*? $//x
1496 or $from =~ s/\s remote \s from \s .* $//x;
1497
1498 $from =~ s/\s+$//;
1499
1500 return $from;
1501 }
1502
1503 # Initialise a data source; returns a CODE ref with which to
1504 # read from that source.
1505 #
1506 # Allowed sources are:
1507 # GLOBs or unknown refs are assumed to be filehandles or equivalent.
1508 # ARRAY refs (treated as a list of lines)
1509 # SCALAR refs (treated as text)
1510 # SCALARs (treated as filenames)
1511 # CODE refs are left unchanged
1512
1513 sub source_init_filehandle;
1514
1515 use FileHandle ();
1516
1517 ; sub source_init_filehandle
1518 {
1519 return FileHandle->new(shift);
1520 }
1521
1522 sub source_init
1523 {
1524 my $source = shift;
1525
1526 if (ref(\$source) ne 'GLOB')
1527 {
1528 return $source if (ref($source) eq 'CODE');
1529
1530 if (ref($source) eq 'ARRAY')
1531 {
1532 my $index = 0;
1533 return sub { $source->[$index++] };
1534 }
1535
1536 if (ref($source) eq 'SCALAR')
1537 {
1538 my $pos = 0;
1539 return sub { return undef unless $pos < length($$source);
1540 my $tmp = $pos;
1541 $pos = 1 + index($$source,"\n",$tmp);
1542 if ($pos <= $tmp)
1543 {
1544 $pos = 1 + length($$source);
1545 return substr($$source,$tmp);
1546 }
1547 else
1548 {
1549 return substr($$source,$tmp,($pos - $tmp));
1550 }
1551 };
1552 }
1553
1554 if (!ref($source))
1555 {
1556 $source = source_init_filehandle("<$source");
1557 return undef unless $source;
1558 }
1559 }
1560
1561 return sub { scalar(<$source>) };
1562 }
1563
1564 ###########################################################################
1565 # THE END
1566 ###########################################################################
1567
1568 1;
1569
1570 __END__
1571
1572 ###########################################################################
1573
1574 =head1 CAVEATS
1575
1576 This module is not fully transparent. In particular:
1577
1578 =over 4
1579
1580 =item -
1581
1582 Case of headers is smashed
1583
1584 =item -
1585
1586 improper duplicate headers may be discarded
1587
1588 =item -
1589
1590 Broken or dubious header names are not preserved
1591
1592 =back
1593
1594 These factors make it undesirable to use this module in news transit
1595 applications.
1596
1597 =head1 AUTHOR
1598
1599 Written by Andrew Gierth <[email protected]>
1600
1601 Thanks to Russ Allbery <[email protected]> for comments and
1602 suggestions.
1603
1604 =head1 COPYRIGHT
1605
1606 Copyright 1997-2002 Andrew Gierth <[email protected]>
1607
1608 This code may be used and/or distributed under the same terms as Perl
1609 itself.
1610
1611 =cut
1612
1613 ###########################################################################
1614 #
1615 # Random Comments
1616 #
1617 # Consistency: I'd like to drop the use of FileHandle in favour of the
1618 # IO::* modules, but I don't want to completely break with 5.003 at this
1619 # stage (though I no longer test with 5.003, so there is no guarantee that
1620 # it works at all).
1621 #
1622 # Use of $_; at present, I'm confining it to for() and map{} / grep{}
1623 # constructs (where it is implicitly localised).
1624 #
1625 # SelfLoader: the use of funky indenting to do deferred 'use' statements
1626 # and other compile-time stuff seems to me to be over-kludgy. It's merely
1627 # an artifact of SelfLoader's fairly simplistic method of locating the
1628 # start and end of each function.
1629 #
1630 # Net::Domain seems to do poorly on BSD systems without permanent
1631 # connectivity (hangs in domainname() doing unnecessary DNS lookups).
1632 # Must take that up with the maintainer at some stage if it hasn't
1633 # already been fixed.
1634 #
1635 # indirect-object vs. method call syntax for ctors: I still can't decide
1636 # which I prefer. I've removed all the IO ones for now.
1637 #
1638 #
1639
1640 ###########################################################################
1641 #
1642 # $Log: Article.pm $
1643 # Revision 1.27 2002/08/11 22:51:38 andrew
1644 # no changes, other than copyright date, this is just to bumb the version no.
1645 #
1646 # Revision 1.26 2001/11/08 14:11:43 andrew
1647 # remove stray spaces from unique filenames
1648 #
1649 # Revision 1.25 2001/04/20 12:11:31 andrew
1650 # handle PGP versions that put spaces in the version field, in sign_control
1651 #
1652 # Revision 1.24 2001/01/18 09:48:44 andrew
1653 # work around a SelfLoader issue.
1654 # Allow $obj->new() to work as well as CLASS->new()
1655 #
1656 # Revision 1.23 2000/04/14 15:11:49 andrew
1657 # handle newlines in body better
1658 #
1659 # Revision 1.22 2000/04/02 12:02:27 andrew
1660 # add parameter to add_date
1661 #
1662 # Revision 1.21 1998/10/21 03:15:31 andrew
1663 # Doc tweaks and minor cleanup.
1664 # Improvements to write_unique_file to handle collisions.
1665 #
1666 # Revision 1.20 1998/10/18 06:01:00 andrew
1667 # Speedup to source_init when FileHandle is not required
1668 #
1669 # Revision 1.19 1998/10/18 05:41:32 andrew
1670 # Added write_unique_file
1671 #
1672 # Revision 1.18 1998/10/18 03:42:19 andrew
1673 # read_body no longer strips blank lines.
1674 # trim_blank_lines added to compensate.
1675 # Added IP, HTTP and URL to list of abbreviations used in canonical
1676 # headers.
1677 # Original sequence of headers is handled slightly differently.
1678 #
1679 # Revision 1.17 1998/07/05 18:03:05 andrew
1680 # Fix the PGPMoose bug-compatible code to handle tabs the same
1681 # way as the reference code
1682 #
1683 # Revision 1.16 1998/07/05 08:40:18 andrew
1684 # Bugfix to read(SCALAR) not to drop characters.
1685 #
1686 # Rehash the PGPMoose code to correctly emulate the disgusting bug in
1687 # PGPMoose V1.1 which treats body lines as though they were headers.
1688 #
1689 # Revision 1.15 1998/02/26 00:50:46 andrew
1690 # Cleanup:
1691 # - remove "use English"
1692 # - use Selfloader to cut startup time
1693 # - minor mods (in sign_control and sign_pgpmoose) to avoid pulling
1694 # in selfloaded sub add_message_id unless needed
1695 # - change read_header to keep first copy of duplicate unique header,
1696 # rather than last copy
1697 #
1698 # Revision 1.14 1997/12/29 14:35:26 andrew
1699 # Fixed order-reverse problem in headers() (oops)
1700 #
1701 # Revision 1.13 1997/12/27 23:19:07 andrew
1702 # Missing 'x' flag on extended regexp in fix_envelope
1703 #
1704 # Revision 1.12 1997/12/13 13:00:52 andrew
1705 # Changed add_date to use local time and add timezone offset
1706 #
1707 # Revision 1.11 1997/12/12 11:42:34 andrew
1708 # corrections to header ordering code
1709 #
1710 # Revision 1.10 1997/12/12 11:09:30 andrew
1711 # Added header ordering stuff
1712 #
1713 # Revision 1.9 1997/12/10 19:20:54 andrew
1714 # added ihave
1715 #
1716 # Revision 1.8 1997/11/08 17:51:45 andrew
1717 # Typos, and handling of error return in post().
1718 #
1719 # Revision 1.7 1997/10/22 20:59:27 andrew
1720 # Clean up distribution terms for release
1721 #
1722 # Revision 1.6 1997/10/22 19:54:41 andrew
1723 # Fixed old typo in RCS revision keyword
1724 #
1725 # Revision 1.5 1997/08/31 01:35:25 andrew
1726 # Added obligatory quotation :-)
1727 #
1728 # Revision 1.4 1997/08/29 03:31:07 andrew
1729 # Fix typo in previous mod
1730 #
1731 # Revision 1.3 1997/08/29 00:34:28 andrew
1732 # Update for latest PGP::Sign (v0.08).
1733 # Add reference handling to add_body().
1734 # Allow -f '' in mail().
1735 #
1736 # Revision 1.2 1997/07/30 12:13:11 andrew
1737 # cleanup (no changes)
1738 #
1739 # Revision 1.1 1997/07/29 15:20:40 andrew
1740 # Initial revision
1741 #
1742 #
1743 #
1744 ###########################################################################
1745
1746