mhmsgextbody.pl untested

filter: Statementstmt 0.0% 0 / 69 Branchbran 0.0% 0 / 58 Conditioncond 0.0% 0 / 46 MC/DCmcdc 0.0% 0 / 22 Subroutinesub 0.0% 0 / 1 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 197 CC 30 SCAR 68.4
CC
30
Cov
0%
filter
930.0
CRAP 930.0
1 ##---------------------------------------------------------------------------##
2 ## File:
3 ## $Id: mhmsgextbody.pl,v 1.5 2005/04/27 18:23:57 ehood Exp $
4 ## Author:
5 ## Earl Hood mhonarc@mhonarc.org
6 ## Description:
7 ## Library defines routine to filter message/external-body parts to
8 ## HTML for MHonArc.
9 ## Filter routine can be registered with the following:
10 ## <MIMEFILTERS>
11 ## message/external-body;m2h_msg_extbody::filter;mhmsgextbody.pl
12 ## </MIMEFILTERS>
13 ##---------------------------------------------------------------------------##
14 ## MHonArc -- Internet mail-to-HTML converter
15 ## Copyright (C) 1999-2001,2005 Earl Hood, mhonarc@mhonarc.org
16 ##
17 ## This program is free software; you can redistribute it and/or modify
18 ## it under the terms of the GNU General Public License as published by
19 ## the Free Software Foundation; either version 2 of the License, or
20 ## (at your option) any later version.
21 ##
22 ## This program is distributed in the hope that it will be useful,
23 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
24 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 ## GNU General Public License for more details.
26 ##
27 ## You should have received a copy of the GNU General Public License
28 ## along with this program; if not, write to the Free Software
29 ## Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
30 ## 02111-1307, USA
31 ##---------------------------------------------------------------------------##
32  
33 package m2h_msg_extbody;
34  
35 ##---------------------------------------------------------------------------##
36 ## message/external-body filter for MHonArc.
37 ## The following filter arguments are recognized ($args):
38 ##
39 ## local-file Support local-file access-type. This option
40 ## is best used for internal local mail archives
41 ## where it is known that readers will have
42 ## direct access to the file.
43 ##
44 sub filter {
45 my ($fields, $data, $isdecode, $args) = @_;
46 $args = '' unless defined $args;
47  
48 # grab content-type
49 my $ctype = $fields->{'content-type'}[0];
50 return '' unless $ctype =~ /\S/;
51  
52 # parse argument string
53 my $b_lfile = $args =~ /\blocal-file\b/i;
54  
55 my $ret = '';
56 my $parms = readmail::MAILparse_parameter_str($ctype, 1);
57 my $access_type = lc $parms->{'access-type'}{'value'};
58 $access_type =~ s/\s//g;
59 my $cdesc = mhonarc::htmlize($fields->{'content-description'}[0]) || '';
60  
61 $$data =~ s/\A\s+//;
62 my $dfields = readmail::MAILread_header($data);
63 my $dctype = mhonarc::htmlize($dfields->{'content-type'}[0]) || '';
64 my $dmd5 = mhonarc::htmlize($dfields->{'content-md5'}[0]) || '';
65 my $size = mhonarc::htmlize($parms->{'size'}{'value'}) || '';
66 my $expires = mhonarc::htmlize($parms->{'expiration'}{'value'}) || '';
67 my $name = $parms->{'name'}{'value'} || '';
68  
69 ATYPE: {
70 ## FTP, TFTP, ANON-FTP
71 if ( $access_type eq 'ftp'
72 || $access_type eq 'anon-ftp'
73 || $access_type eq 'tftp'
74 || $access_type eq 'http'
75 || $access_type eq 'x-http') {
76  
77 my $site =
78 $parms->{'site'}{'value'}
79 || $parms->{'host'}{'value'}
80 || '';
81  
82 my $port = $parms->{'port'}{'value'} || '';
83 $port = ':' . $port if $port ne '';
84  
85 my $dir =
86 $parms->{'directory'}{'value'}
87 || $parms->{'path'}{'value'}
88 || '';
89 $dir = '/' . $dir unless $dir =~ m|^/| || $dir eq '';
90  
91 my $mode = $parms->{'mode'}{'value'} || '';
92  
93 my $proto =
94 ($access_type eq 'x-http' || $access_type eq 'http') ? 'http'
95 : ($access_type eq 'tftp') ? 'tftp'
96 : 'ftp';
97 my $url =
98 $proto . '://'
99 . mhonarc::urlize($site . $port)
100 . $dir . '/'
101 . mhonarc::urlize_path($name);
102 $ret = '<dl><dt>';
103 $ret .= qq|<em>$cdesc</em><br>\n| if $cdesc;
104 $ret .=
105 qq|<a rel="nofollow" href="$url">&lt;$url&gt;</a></dt><dd>\n|;
106 $ret .= qq|Content-type: <tt>$dctype</tt><br>\n|
107 if $dctype;
108 $ret .= qq|MD5: <tt>$dmd5</tt><br>\n|
109 if $dmd5;
110 $ret .= qq|Size: $size bytes<br>\n|
111 if $size;
112 $ret .= qq|Transfer-mode: <tt>$mode</tt><br>\n|
113 if $mode;
114 $ret .= qq|Expires: <tt>$expires</tt><br>\n|
115 if $expires;
116 $ret .= qq|Username/password may be required.<br>\n|
117 if $access_type eq 'ftp';
118 $ret .= "</dd></dl>\n";
119 last ATYPE;
120 }
121  
122 ## Local file
123 if ($access_type eq 'local-file') {
124 last ATYPE unless $b_lfile;
125 my $site = $parms->{'site'}{'value'} || '';
126 my $url = 'file://' . mhonarc::urlize_path($name);
127 $ret = '<dl><dt>';
128 $ret .= qq|<em>$cdesc</em><br>\n| if $cdesc;
129 $ret .=
130 qq|<a rel="nofollow" href="$url">&lt;$url&gt;</a></dt><dd>\n|;
131 $ret .= qq|Content-type: <tt>$dctype</tt><br>\n|
132 if $dctype;
133 $ret .= qq|MD5: <tt>$dmd5</tt><br>\n|
134 if $dmd5;
135 $ret .= qq|Size: $size bytes<br>\n| if $size;
136 $ret .= qq|Expires: <tt>$expires</tt><br>\n|
137 if $expires;
138 $ret .=
139 qq|File accessible from the following domain: |
140 . qq|$site<br>\n|
141 if $site;
142 $ret .= "</dd></dl>\n";
143 last ATYPE;
144 }
145  
146 ## Mail server
147 if ($access_type eq 'mail-server') {
148 # not supported
149 last ATYPE;
150 }
151  
152 ## URL
153 if ($access_type eq 'url') {
154 my $url = $parms->{'url'}{'value'};
155 $url =~ s/[\s<>]+//g;
156 $url =~ s/javascript/_javascript_/ig;
157 $ret = '<dl><dt>';
158 $ret .= qq|<em>$cdesc</em><br>\n| if $cdesc;
159 $ret .=
160 qq|<a rel="nofollow" href="$url">&lt;$url&gt;</a></dt><dd>\n|;
161 $ret .= qq|Content-type: <tt>$dctype</tt><br>\n|
162 if $dctype;
163 $ret .= qq|MD5: <tt>$dmd5</tt><br>\n|
164 if $dmd5;
165 $ret .= qq|Size: $size bytes<br>\n|
166 if $size;
167 $ret .= qq|Expires: <tt>$expires</tt><br>\n|
168 if $expires;
169 $ret .= "</dd></dl>\n";
170 last ATYPE;
171 }
172  
173 last ATYPE;
174 }
175  
176 ($ret);
177 }
178  
179 ##---------------------------------------------------------------------------##
180 1;