Topica/Mail.pm

filter: Statementstmt 88.8% 24 / 27 Branchbran 50.0% 1 / 2 Conditioncond 37.5% 3 / 8 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 88.8% 8 / 9 Podpod 100% 8 / 8 totaltotal 75.8% 44 / 58 CC 6 SCAR 8.4
CC
6
Cov
76%
body
6.0
date
2.1
subject
2.1
CRAP 2.3
« Topica.pm ↑ Summary Topica/Reply.pm »
1 package WWW::Topica::Mail;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 =pod
6  
7 =head1 NAME
8  
9 WWW::Topica::Mail - parse a single Topica mailing list mail
10  
11 =head1 SYNOPSIS
12  
13 my $index = WWW::Topic::Index->new($index_html);
14
15 foreach my $mess_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 message page from Topica.com's mailing list indexes.
28  
29 Message pages have the subject and the date and time of the mail being sent as
30 well as a full name of each sender.
31  
32 =head1 METHODS
33  
34 =cut
35  
36  
37 =head2 new <page html> <id>
38  
39 Takes the page html and the message-id and parses the html.
40  
41 =cut
42  
43  
44 300 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
45 300 my ($class, $html, $id) = @_;
46
47 300 my $self = { id => $id };
48
49 300 bless $self, $class;
50
51 300 $self->parse($html);
52
53 300 return $self;
54 }
55  
56  
57 =head2 parse <html>
58  
59 Parse the html to get message ids and next & prev offsets.
60  
61 =cut
62  
63 300 ▶sub parse {
Subroutine parse: called CC=2 SCAR=7.1
Pod documented
64 300 my ($self, $html) = @_;
65  
66
67 300 ($self->{eto},undef,$self->{from}) = ($html =~ m!window.open\('/lists/[^/]+/read/post.html\?mode\=replytosender\&mid=\d+\&eto\=([^']+)'(.+?)return true">(.+?)</A>!s);
68 300 ▶ if (!defined $self->{eto}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"eto"}) 0 300 300
69 0 ($self->{from}) = ($html =~ m!<FONT FACE\="Geneva,Verdana,Sans-Serif" SIZE\="-2">&nbsp;([^<]+)</FONT>!s);
70 }
71 300 (undef,$self->{date}) = ($html =~ m!http://lists.topica.com/lists/read/images/icon_clock.gif(.+?)<NOBR>(.+?)&nbsp;<\/NOBR>!s);
72 300 (undef, $self->{subject}) = ($html =~ m!<FONT CLASS\="headline"(.+?)COLOR="#990099"><B>(.+?)</B>!s);
73 300 ($self->{body}) = ($html =~ m! <FONT FACE\="Geneva,Verdana,Sans-Serif" SIZE\="-2">(.+?)</FONT>!s);
74  
75 }
76  
77 =head2 id
78  
79 Get the id of this mail
80  
81 =cut
82  
83 300 ▶sub id {
Subroutine id: called CC=1 SCAR=0.0
Pod documented
84 300 return $_[0]->{id};
85 }
86  
87 =head2 eto
88  
89 Get the eto of the next reply we need to get
90  
91 =cut
92  
93 1200 ▶sub eto {
Subroutine eto: called CC=1 SCAR=0.0
Pod documented
94 1200 my $self = shift;
95
96 1200 return $self->{eto};
97  
98 }
99  
100 =head2 date
101  
102 Get the date of this mail
103  
104 =cut
105  
106 300 ▶sub date {
Subroutine date: called CC=2 SCAR=7.2
Pod documented
107 300 ▶ my $date = $_[0]->{date} || "";
Condition50%1/2
$_[0]{'date'} || ''
l!l
3000
MC/DC0%0/1
$_[0]{'date'} || ''
$_[0]{'date'}
Truth table50%1/2
A
A= $_[0]{'date'}
Aresult
11
00
108
109 300 return $date;
110 }
111  
112 =head2 subject
113  
114 The subject of the mail
115  
116 =cut
117  
118 300 ▶sub subject {
Subroutine subject: called CC=2 SCAR=7.2
Pod documented
119 300 ▶ my $subject = $_[0]->{subject} || "";
Condition50%1/2
$_[0]{'subject'} || ''
l!l
3000
MC/DC0%0/1
$_[0]{'subject'} || ''
$_[0]{'subject'}
Truth table50%1/2
A
A= $_[0]{'subject'}
Aresult
11
00
120 300 return $subject;
121 }
122  
123 =head2 from
124  
125 Get the name of the person it was from
126  
127 =cut
128  
129 300 ▶sub from {
Subroutine from: called CC=2 SCAR=7.2
Pod documented
130 300 ▶ my $from = $_[0]->{from} || "";
Condition50%1/2
$_[0]{'from'} || ''
l!l
3000
MC/DC0%0/1
$_[0]{'from'} || ''
$_[0]{'from'}
Truth table50%1/2
A
A= $_[0]{'from'}
Aresult
11
00
131 300 return $from;
132 }
133  
134 =head2 body
135  
136 Get the body of the mail.
137  
138 =cut
139  
140 0 ▶sub body {
Subroutine body: not called CC=2 SCAR=17.9
Pod documented
141 0 ▶ my $body = $_[0]->{body} || "";
Condition0%0/2
$_[0]{'body'} || ''
l!l
00
MC/DC0%0/1
$_[0]{'body'} || ''
$_[0]{'body'}
Truth table0%0/2
A
A= $_[0]{'body'}
Aresult
11
00
142 0 return $body;
143 }
144  
145 1 1;
146  
147 =head1 AUTHOR
148  
149 Simon Wistow <simon@thegestalt.org>
150  
151 =head1 COPYRIGHT
152  
153 Copyright (c) 2004, Simon Wistow
154  
155 =cut
156  
157  
158  
« Topica.pm ↑ Summary Topica/Reply.pm »