This file is indexed.

/usr/share/tkrat2.2/html.tcl is in tkrat 1:2.2cvs20100105-true-dfsg-6.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
# html.tcl --
#
# This file contains code which handles the actual displaying of an HTML
# message or attachment
#
#
#  TkRat software and its included text is Copyright 1996-2000 by
#  Martin Forssén
#
#  The full text of the legal notice is contained in the file called
#  COPYRIGHT, included with this distribution.

# Don't fail if the http package isn't available. It'll just fail when it
# comes time to fetch the image
catch {package require http}

bind HtmlClip <Motion> {
    global htmlWinCursor
    set parent [winfo parent %W]
    set url [$parent href %x %y] 
    if {![info exists htmlWinCursor($parent)]} {
	set htmlWinCursor($parent) [lindex [$parent configure -cursor] end]
    }
    if {[string length $url] > 0} {
	if {[string length $htmlWinCursor($parent)] == 0} {
	    set htmlWinCursor($parent) "hand2"
	    $parent configure -cursor $htmlWinCursor($parent)
	}
    } else {
	if {[string length $htmlWinCursor($parent)] > 0} {
	    set htmlWinCursor($parent) ""
	    $parent configure -cursor {}
	}
    }
}
bind HtmlClip <Button-1> {
    set ::htmlWinClick [[winfo parent %W] href %x %y]
}
bind HtmlClip <ButtonRelease-1> {
    if { ![string compare $::htmlWinClick [[winfo parent %W] href %x %y]]} {
	set url $::htmlWinClick
	RatShowURLLaunch $url [winfo parent [winfo parent %W]]
    }
}
bind Html <Destroy> {
	ClearHtmlImages %W
}


# Contains the list of most recently used images
set htmlImageList [list]

# ShowTextHtml2 --
#
# Show text/html entities, should handle different fonts...
#
# Arguments:
# handler -	The handler which identifies the show text widget
# body    -	The bodypart to show
# msg     -	The message name
proc ShowTextHtml2 {handler body msg} {
    global idCnt
    upvar \#0 $handler fh \
        msgInfo_$msg msgInfo

    set tag t[incr idCnt]
    if {[info tclversion] < 8.5} {
        set frame [frame $handler.f[incr idCnt] -width [winfo width $handler]\
                       -height [winfo height $handler] -cursor left_ptr]
        set htmlwin $frame.html
    } else {
        set htmlwin $handler.f[incr idCnt]
    }
    # -base foo is there because if it is removed, Tkhtml crashes. When the
    # bug is fixed, it can be removed.
    html $htmlwin -base "foo" \
        -fontcommand HtmlFontCmd \
        -resolvercommand HtmlResolverCmd \
        -imagecommand [list HtmlImageCmd $htmlwin] \
        -background [$handler cget -background] \
        -width [winfo width $handler] \
        -exportselection true \
        -bd 0
    $htmlwin parse [$body data false]
    # Now that the data is parsed, check if there is a base set
    set base [$htmlwin token find base]
    if {[llength $base] > 0} {
	# Ok, the correct base is the first one found. Since it is a list, get
	# it.
	set base [lindex $base 0]
	# The base will be right after the href argument
	set idx [lsearch $base href]
	incr idx
	# Get the real base
	set base [lrange $base $idx $idx]
	# set the base of the widget with the correct version now
	$htmlwin configure -base $base
    }
    $handler insert insert " " "Center $tag"
    if {[info tclversion] < 8.5} {
        $htmlwin configure \
            -xscrollcommand [list $frame.xscroll set] \
            -yscrollcommand [list $frame.yscroll set]
        set yscroll [scrollbar $frame.yscroll -command [list $htmlwin yview]]
        set xscroll [scrollbar $frame.xscroll -command [list $htmlwin xview] \
                         -orient horizontal]
        bind $frame <Destroy> {
            bind [winfo parent %W] <Configure> {}
        }
        grid $htmlwin -row 0 -column 0 -sticky news
        grid $yscroll -row 0 -column 1 -sticky ns
        grid $xscroll -row 1 -column 0 -sticky ew
        grid columnconfigure $frame 0 -weight 1
        grid rowconfigure $frame 0 -weight 1
        grid propagate $frame 0
        $handler window create insert -window $frame
        set binding [list ResizeFrame $frame $handler -1 -1 \
                         $xscroll $yscroll]
        if {[string first $binding [bind $handler <Configure>]] == -1} {
            bind $handler <Configure> +$binding
        }
    } else {
        $handler window create insert -window $htmlwin

        # This is ugly. For some reason does the widget not know its size
        # when the Configure event arrives here. But after a short delay
        # it does.
        bind $htmlwin <Configure> {after 100 {HtmlReconfHeight %W}}
    }
    $handler insert insert "\n" $tag
    $handler tag bind $tag <3> "tk_popup $fh(struct_menu) %X %Y \
				 \[lsearch \[set ${handler}(struct_list)\] \
				 $body\]"
    bind $htmlwin.x <3> "tk_popup $fh(struct_menu) %X %Y \
			  \[lsearch \[set ${handler}(struct_list)\] \
			  $body\]"

    lappend fh(width_adjust) $htmlwin
}

# HtmlReconfHeight --
#
# Reconfigures the height of the html widget to whatever is needed to
# show the text
#
# Arguments:
# w - html widget

proc HtmlReconfHeight {w} {
    if {[winfo exists $w]} {
        set h [lindex [$w coords] 1]
        $w configure -height $h
    }
}


# HtmlFontCmd --
#
# Selects font sizes when dislaying html messages
#
# Arguments:
# size: Size of font to display
# args: Other font modifiers (italic bold or fixed)
proc HtmlFontCmd {size args} {
    global option

    # Default family and sizes
    set f $option(font_family_prop)
    foreach s {8 9 10 12 14 18 24} {
        lappend sizelist [expr $s+$option(font_size)-12]
    }
    # Default weight is Normal
    set w normal
    # Default angle is roman
    set a roman

    foreach o $args {
        if {[string equal "fixed" "$o"]} {
            set f $option(font_family_fixed)
        } elseif {[string equal "bold" "$o"]} {
            set w bold
        } elseif {[string equal "italic" "$o"]} {
            set a italic
        }
    }
    # Make sure the list is long enough. If it isn't, use the last value
    if {[llength $sizelist] < $size} {
	set size end
    } else {
	# Decrease the size since the lowest value allowed is 1 and
	# list indices start at 0
	incr size -1
    }
    # Ugh. RatCreateFont already constructs all the components of the font. So
    # we're actually removing information and adding it back just to change the
    # size. Maybe there's a better way.
    return [list [lindex $f 1] [lindex $sizelist $size] $a $w]
}

# HtmlImageCmd --
#
# Fetches and creates an image to display in a HTML message
#
# Arguments:
# frm: The HTML widget used to display images
# src: SRC element of the <IMG> tag
# width: width of the image (added automatically, could be empty)
# height: height of the image (added automatically, could be empty)
# args: Other attributes given to the <IMG> tag
#
# Returns:
#   The name of an image if it could be constructed correctly, an empty string
#   otherwise
proc HtmlImageCmd {frm src width height args} {
    global htmlImageList
    global htmlImageArray
    global HtmlImages
    
    # Don't do anything if the html widget has been destroyed
    if {![winfo exists $frm]} {
	return
    }

    # Check cached images
    if {[lsearch $htmlImageList $src] != -1} {
	return $htmlImageArray($src)
    }

    if {[string match foo/cid:* $src]} {
        set filename [HtmlGetEmbeddedImage $src]
    } else {
        set filename [HtmlGetExternalImage $frm $src $width $height]
    }

    if {"" == $filename} {
        return ""
    }
    
    if {[catch {image create photo -file $filename} img]} {
	file delete -force -- $filename
        set retVal ""
    } else {
	lappend htmlImageList $src
	set htmlImageArray($src) $img
	file delete -force -- $filename
	# Make sure the window still exists before displaying
	if {[winfo exists $frm]} {
	    lappend HtmlImages($frm) $img
	    set retVal $img
	} else {
	    # Otherwise, delete the image
	    image delete $img
	    return
	}
    }
    
    return $retVal
}

# HtmlGetEmbeddedImage --
#
# Extract an image from an related bodypart
#
# Arguments:
# src: SRC element of the <IMG> tag
#
# Returns:
#   The name of a file which contains the image data. Or an empty string
#   if no image was downloaded.
proc HtmlGetEmbeddedImage {src} {
    global related option rat_tmp

    if {![regsub "foo/cid:" $src {} id]
        || ![info exists related($id)]} {
        return ""
    }

    set filename $rat_tmp/rat.[RatGenId]
    set fid [open $filename w 0600]
    fconfigure $fid -encoding binary
    $related($id) saveData $fid false false
    close $fid

    return $filename
}

# HtmlGetExternalImage --
#
# Fetches an external image to display in a HTML message
#
# Arguments:
# frm: The HTML widget used to display images
# src: SRC element of the <IMG> tag
# width: width of the image (added automatically, could be empty)
# height: height of the image (added automatically, could be empty)
#
# Returns:
#   The name of a file which contains the image data. Or an empty string
#   if no image was downloaded.
proc HtmlGetExternalImage {frm src width height} {
    global option rat_tmp

    if {$option(html_show_images) == 0} {
        return ""
    }
    
    if {$width < $option(html_min_image_size) 
	&& $height < $option(html_min_image_size)} {
        # Images that are too small may signal some spam-type of stuff
	return ""
    }

    if {![string match http://* $src]} {
	if {![string match http://* [$frm cget -base]]} {
            # Can't get image because it isn't http
	    return ""
	} else {
	    set src [$frm cget -base]/$src
	}
    }
    
    if {[catch {::http::geturl $src} token]} {
	return ""
    }
    
    set filename $rat_tmp/rat.[RatGenId]
    set fid [open $filename w 0600]
    fconfigure $fid -encoding binary
    puts -nonewline $fid [::http::data $token]
    close $fid

    return $filename
}

# HtmlResolverCmd --
#
# URL resolver for HTML links
#
# Arguments:
# base: The base URI
# uri: the new URI
#
# Returns:
#   The URL if it starts with http://, otherwise returns foo
proc HtmlResolverCmd {base uri} {
    if {[string match http://* $uri]} {
	return $uri
    }
    return $base/$uri
}

# ClearHtmlImages --
#
# Delete images loaded by the HTML widget
#
# Arguments:
# w: Name of widget containing the images
#
# Returns:
# Nothing
proc ClearHtmlImages {w} {
    global HtmlImages

    if {![info exists HtmlImages($w)]} {
	return
    }

    foreach img $HtmlImages($w) {
	catch {image delete $img}
    }
    unset HtmlImages($w)
    return "foo"
}