Topica/Reply.pm

filter: Statementstmt 91.3% 21 / 23 Branchbran 50.0% 1 / 2 Conditioncond 25.0% 1 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 87.5% 7 / 8 Podpod 100% 7 / 7 totaltotal 80.4% 37 / 46 CC 4 SCAR 8.3
CC
4
Cov
79%
subject
6.0
email
2.1
parse
2.0
CRAP 2.3
« Topica/Mail.pm ↑ Summary Topica/Index.pm »
1 package WWW::Topica::Reply;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 =pod
6  
7 =head1 NAME
8  
9 WWW::Topica::Index - parse a single Topic mailing list index
10  
11 =head1 SYNOPSIS
12  
13 my $index = WWW::Topic::Index->new($index_html);
14
15 foreach my $message_id ($index->message_ids) {
16 # the mail has some information and also provides a link to the reply ...
17 my $mail = WWW::Topica::Mail->new($topica->fetch_mail($mess_id), $mess_id);
18 # which has other information (like the un-htmled mail and the email address) ...
19 my $reply = WWW::Topica::Reply->new($topica->fetch_reply($mail->id, $mail->eto), $mail->id, $mail->eto);
20 }
21
22 print "Next offset is ".$index->next."\n";
23 print "Previous offset is ".$index->prev."\n";
24  
25 =head1 DESCRIPTION
26  
27 Used to parse a single reply page from Topica.com's mailing list indexes.
28  
29 Reply pages have the body of the email (albeit quoted) and potentially a full email address.
30  
31 =head1 METHODS
32  
33 =cut
34  
35  
36 =head2 new <page html> <message id> <eto>
37  
38 Takes the html of the page, the eto and the message-id and parses the html.
39  
40 =cut
41  
42  
43 300 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
44 300 my ($class, $html, $id, $eto) = @_;
45
46 300 my $self = { id=>$id, eto=>$eto };
47
48 300 bless $self, $class;
49
50 300 $self->parse($html);
51
52 300 return $self;
53 }
54  
55  
56 =head2 parse <html>
57  
58 Parse the html to get the subject, email address and body of the email.
59  
60 =cut
61  
62 300 ▶sub parse {
Subroutine parse: called CC=2 SCAR=7.0
Pod documented
63 300 my ($self,$html) = @_;
64
65 300 (undef, $self->{email}) = ($html =~ m!<INPUT TYPE\="hidden" NAME\="eto"(.+?)SIZE\="-2">(.+?)</FONT>!s);
66 300 ($self->{subject}) = ($html =~ m!NAME\="subject" SIZE\=28 VALUE\="(.+?)"!s);
67 300 ($self->{body}) = ($html =~ m!<TEXTAREA NAME\="body" ROWS\=13 COLS\=70 WRAP\=AUTO>(.+?)</TEXTAREA>!s);
68  
69 300 ▶ return unless $self->{body};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"body"} 0 300 300
70  
71 # the body is quoted as if ready to reply. So we need to clean that up.
72 300 $self->{body} =~ s!^(.+?) wrote:!!sg;
73 300 $self->{body} =~ s!^>\s?!!msg;
74  
75
76 }
77  
78 =head2 id
79  
80 Get the message id
81  
82 =cut
83  
84 300 ▶sub id {
Subroutine id: called CC=1 SCAR=0.0
Pod documented
85 300 return $_[0]->{id};
86 }
87  
88 =head2 eto
89  
90 Get the message eto
91  
92 =cut
93  
94 300 ▶sub eto {
Subroutine eto: called CC=1 SCAR=0.0
Pod documented
95 300 return $_[0]->{eto};
96 }
97  
98 =head2 email
99  
100 Get the email address parsed out.
101  
102 =cut
103  
104 300 ▶sub email {
Subroutine email: called CC=2 SCAR=7.2
Pod documented
105 300 ▶ my $email = $_[0]->{email} || "";
Condition50%1/2
$_[0]{'email'} || ''
l!l
3000
MC/DC0%0/1
$_[0]{'email'} || ''
$_[0]{'email'}
Truth table50%1/2
A
A= $_[0]{'email'}
Aresult
11
00
106
107 300 return $email;
108 }
109  
110  
111 =head2 subject
112  
113 Get the email subject parsed out.
114  
115 =cut
116  
117 0 ▶sub subject {
Subroutine subject: not called CC=2 SCAR=17.9
Pod documented
118 0 ▶ my $subject = $_[0]->{subject} || "";
Condition0%0/2
$_[0]{'subject'} || ''
l!l
00
MC/DC0%0/1
$_[0]{'subject'} || ''
$_[0]{'subject'}
Truth table0%0/2
A
A= $_[0]{'subject'}
Aresult
11
00
119 0 return $subject;
120 }
121  
122 =head2 body
123  
124 Get the email body parsed out.
125  
126 =cut
127  
128 600 ▶sub body {
Subroutine body: called CC=1 SCAR=0.0
Pod documented
129 600 return $_[0]->{body};
130 }
131  
132  
133 1 1;
134  
135 =head1 AUTHOR
136  
137 Simon Wistow <simon@thegestalt.org>
138  
139 =head1 COPYRIGHT
140  
141 Copyright (c) 2004, Simon Wistow
142  
143 =cut
144  
145  
146  
147  
« Topica/Mail.pm ↑ Summary Topica/Index.pm »