| 1 | # -*- Perl -*- | ||||||||||||||||||||
| 2 | ########################################################################### | ||||||||||||||||||||
| 3 | # Written and maintained by Andrew Gierth <andrew@erlenstar.demon.co.uk> | ||||||||||||||||||||
| 4 | # | ||||||||||||||||||||
| 5 | # Copyright 1997 Andrew Gierth. Redistribution terms at end of file. | ||||||||||||||||||||
| 6 | # | ||||||||||||||||||||
| 7 | # $Id: AutoReply.pm 1.10 2001/11/08 14:10:12 andrew Exp $ | ||||||||||||||||||||
| 8 | # | ||||||||||||||||||||
| 9 | ########################################################################### | ||||||||||||||||||||
| 10 | # | ||||||||||||||||||||
| 11 | # Address, n. 1. A formal discourse, usually delivered to a person who has | ||||||||||||||||||||
| 12 | # something by a person who wants something that he has. | ||||||||||||||||||||
| 13 | # 2. The place at which one receives the delicate attentions | ||||||||||||||||||||
| 14 | # of creditors. | ||||||||||||||||||||
| 15 | # -- Ambrose Bierce | ||||||||||||||||||||
| 16 | # | ||||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | =head1 NAME | ||||||||||||||||||||
| 19 | |||||||||||||||||||||
| 20 | News::AutoReply - derivative of News::Article for generating autoreplies | ||||||||||||||||||||
| 21 | |||||||||||||||||||||
| 22 | =head1 SYNOPSIS | ||||||||||||||||||||
| 23 | |||||||||||||||||||||
| 24 | use News::AutoReply; | ||||||||||||||||||||
| 25 | |||||||||||||||||||||
| 26 | $reply = News::AutoReply->new($message); | ||||||||||||||||||||
| 27 | |||||||||||||||||||||
| 28 | =head1 DESCRIPTION | ||||||||||||||||||||
| 29 | |||||||||||||||||||||
| 30 | Like News::Article, but must be given a reference to another article | ||||||||||||||||||||
| 31 | at creation time - initialises To, In-Reply-To, References etc. | ||||||||||||||||||||
| 32 | correctly as an automatic reply. | ||||||||||||||||||||
| 33 | |||||||||||||||||||||
| 34 | =head1 USAGE | ||||||||||||||||||||
| 35 | |||||||||||||||||||||
| 36 | use News::AutoReply; | ||||||||||||||||||||
| 37 | |||||||||||||||||||||
| 38 | Exports nothing. | ||||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | =cut | ||||||||||||||||||||
| 41 | |||||||||||||||||||||
| 42 | package News::AutoReply; | ||||||||||||||||||||
| 43 | |||||||||||||||||||||
| 44 | 1 | ▶ | use News::Article; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 45 | 1 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 46 | 1 | ▶ | use vars qw(@ISA); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 47 | |||||||||||||||||||||
| 48 | 1 | @ISA = qw(News::Article); | |||||||||||||||||||
| 49 | |||||||||||||||||||||
| 50 | =head1 Constructor | ||||||||||||||||||||
| 51 | |||||||||||||||||||||
| 52 | =over 4 | ||||||||||||||||||||
| 53 | |||||||||||||||||||||
| 54 | =item new ( ORIGINAL ) | ||||||||||||||||||||
| 55 | |||||||||||||||||||||
| 56 | Construct an autoreply to a message, assuming that the Reply-To (if | ||||||||||||||||||||
| 57 | present, otherwise the From) header of C<ORIGINAL> is valid. | ||||||||||||||||||||
| 58 | |||||||||||||||||||||
| 59 | Returns a new Article object with no body or envelope sender, but with | ||||||||||||||||||||
| 60 | suitable headers. | ||||||||||||||||||||
| 61 | |||||||||||||||||||||
| 62 | If an environment variable LOOP is defined, it is used as the contents | ||||||||||||||||||||
| 63 | of an X-Loop header added to the reply (this is useful when using this | ||||||||||||||||||||
| 64 | code in progs launched from a procmail recipe). Always preserves X-Loop | ||||||||||||||||||||
| 65 | headers in the original. | ||||||||||||||||||||
| 66 | |||||||||||||||||||||
| 67 | The reference-folding code could probably be improved. | ||||||||||||||||||||
| 68 | |||||||||||||||||||||
| 69 | =cut | ||||||||||||||||||||
| 70 | |||||||||||||||||||||
| 71 | sub new | ||||||||||||||||||||
| 72 | 0 | ▶ | { | ||||||||||||||||||
|
Subroutine
new: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||
| 73 | 0 | my $class = shift; | |||||||||||||||||||
| 74 | 0 | my $src = shift; | |||||||||||||||||||
| 75 | |||||||||||||||||||||
| 76 | 0 | my $self = $class->SUPER::new(@_); | |||||||||||||||||||
| 77 | 0 | ▶ | return undef unless $self; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 78 | |||||||||||||||||||||
| 79 | 0 | $self->reply_init($src); | |||||||||||||||||||
| 80 | } | ||||||||||||||||||||
| 81 | |||||||||||||||||||||
| 82 | #-------------------------------------------------------------------------- | ||||||||||||||||||||
| 83 | # private. Factored out of new() so that FormReply etc. can inherit | ||||||||||||||||||||
| 84 | # this. | ||||||||||||||||||||
| 85 | |||||||||||||||||||||
| 86 | sub reply_init | ||||||||||||||||||||
| 87 | 0 | ▶ | { | ||||||||||||||||||
|
Subroutine
reply_init: not called CC=10 SCAR=47.0
Pod
undocumented
| |||||||||||||||||||||
| 88 | 0 | my $self = shift; | |||||||||||||||||||
| 89 | 0 | my $src = shift; | |||||||||||||||||||
| 90 | |||||||||||||||||||||
| 91 | 0 | ▶ | my $to = $src->header('reply-to') || $src->header('from'); | ||||||||||||||||||
|
Condition0%0/3
$src->header('reply-to') || $src->header('from')
MC/DC0%0/2
$src->header('reply-to') || $src->header('from')
$src->header('reply-to')
$src->header('from')
Truth table0%0/3
A || B
A= $src->header('reply-to')B= $src->header('from')
| |||||||||||||||||||||
| 92 | 0 | ▶ | return undef unless $to; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 93 | |||||||||||||||||||||
| 94 | 0 | $self->add_headers(to => $to); | |||||||||||||||||||
| 95 | 0 | $self->set_headers("x-loop" => [ $src->header("x-loop") ]); | |||||||||||||||||||
| 96 | 0 | ▶ | $self->add_headers("x-loop" => $ENV{LOOP}) if defined($ENV{LOOP}); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 97 | |||||||||||||||||||||
| 98 | 0 | ▶ | if (!defined($self->header("subject"))) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 99 | { | ||||||||||||||||||||
| 100 | 0 | ▶ | my $subj = $src->header("subject") || "(no subject)"; | ||||||||||||||||||
|
Condition0%0/2
$src->header('subject') || '(no subject)'
MC/DC0%0/1
$src->header('subject') || '(no subject)'
$src->header('subject')
Truth table0%0/2
A
A= $src->header('subject')
| |||||||||||||||||||||
| 101 | 0 | $subj =~ s/^(\s*[Rr][Ee]:\s+)?/Re: /; | |||||||||||||||||||
| 102 | 0 | $self->set_headers(subject => $subj); | |||||||||||||||||||
| 103 | } | ||||||||||||||||||||
| 104 | |||||||||||||||||||||
| 105 | 0 | my $srcid = $src->header("message-id"); | |||||||||||||||||||
| 106 | 0 | ▶ | $self->set_headers("in-reply-to" => $srcid) if $srcid; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 107 | |||||||||||||||||||||
| 108 | 0 | ▶ | my $refs = $src->header("references") || ''; | ||||||||||||||||||
|
Condition0%0/2
$src->header('references') || ''
MC/DC0%0/1
$src->header('references') || ''
$src->header('references')
Truth table0%0/2
A
A= $src->header('references')
| |||||||||||||||||||||
| 109 | 0 | my @refs = split(' ',$refs); | |||||||||||||||||||
| 110 | 0 | ▶ | push @refs,$srcid if $srcid; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 111 | 0 | ▶ | if ($refs = $self->fold_references(@refs)) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 112 | { | ||||||||||||||||||||
| 113 | 0 | $self->set_headers(references => $refs); | |||||||||||||||||||
| 114 | } | ||||||||||||||||||||
| 115 | |||||||||||||||||||||
| 116 | 0 | return $self; | |||||||||||||||||||
| 117 | } | ||||||||||||||||||||
| 118 | |||||||||||||||||||||
| 119 | #---------------------------------------------------------------------------- | ||||||||||||||||||||
| 120 | # private; called as a method to allow overriding if necessary. | ||||||||||||||||||||
| 121 | |||||||||||||||||||||
| 122 | sub fold_references | ||||||||||||||||||||
| 123 | 0 | ▶ | { | ||||||||||||||||||
|
Subroutine
fold_references: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||
| 124 | 0 | my $self = shift; | |||||||||||||||||||
| 125 | 0 | ▶ | my $refs = shift || ''; | ||||||||||||||||||
|
Condition0%0/2
shift() || ''
MC/DC0%0/1
shift() || ''
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||
| 126 | 0 | my $length = 4 + length($refs); | |||||||||||||||||||
| 127 | |||||||||||||||||||||
| 128 | 0 | ▶ | while (@_) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 129 | { | ||||||||||||||||||||
| 130 | 0 | my $ref = shift; | |||||||||||||||||||
| 131 | 0 | $length += 1 + length($ref); | |||||||||||||||||||
| 132 | 0 | ▶ | $refs .= ($length < 72) ? ' ' : "\n\t"; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 133 | 0 | $refs .= $ref; | |||||||||||||||||||
| 134 | 0 | ▶ | $length = length($ref) unless $length < 72; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 135 | } | ||||||||||||||||||||
| 136 | |||||||||||||||||||||
| 137 | 0 | $refs; | |||||||||||||||||||
| 138 | } | ||||||||||||||||||||
| 139 | |||||||||||||||||||||
| 140 | 1 | 1; | |||||||||||||||||||
| 141 | |||||||||||||||||||||
| 142 | __END__ | ||||||||||||||||||||