/usr/lib/exmh/uri.tcl is in exmh 1:2.8.0-5.
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 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 | # uri.tcl
#
# A little support for Uniform Resource Identifiers.
#
# martin hamilton <martin@mrrl.lut.ac.uk>
# &
# John Robert LoVerso <loverso@osf.org>
# Toivo Pedaste <toivo@ucs.uwa.edu.au>
# Fred Douglis <douglis@research.att.com>
proc URI_Init {} {
global env uri
if [info exists uri(init)] {
return
}
set uri(init) 1
Preferences_Add "WWW" \
"These options control how exmh deals with Uniform Resource
Identifiers, e.g. World-Wide Web URLs. You can arrange for URLs
embedded in messages to be turned into hyperlinks, and there is an
option to decipher the experimental X-URL (or X-URI) header. This may be used
by the sender of a message to include contact information, such as
the address of their World-Wide Web homepage. You can add this
header to your messages by editing compcomps, replcomps and so on." {
{uri(scanForXURIs) uriScanForXURIs ON {Scan for X-URL: headers}
"This tells exmh whether to look for X-URL (or X_URI) headers in messages when
you read them."}
{uri(scanForURIs) uriScanForURIs OFF {Scan for URLs in messages}
"This tells exmh whether to look for URL in the bodies of messages.
If you turn it on, any URLs it finds will be turned into buttons
which you can click on to launch a viewer application. NB - this can
slow down message displaying somewhat."}
{uri(scanLimit) uriScanLimit 1000 {Max lines to scan for URL}
"This limits the number of lines scanned for embedded URLs,
which can run slowly on large messages. Set to a number of lines,
or to the keyword \"end\" to scan the whole message."}
{uri(scanSoftLimit) uriScanSoftLimit 1000 {Stop button max lines}
"If the number of lines to scan is more than this soft limit, then
a stop button is displayed so you can terminate URL scanning before
it completes.."}
{uri(viewer) uriViewer {CHOICE netscape Mosaic exmh webtk surfit tclcmd} {URL Viewer}
"The Mosaic and netscape options attempt to connect to a running
instance of these programs. webtk and surfit are Tcl/Tk web browsers.
The exmh option uses the built-in HTML viewer.
The tclcmd option lets you define your
own Tcl command to display the URL. Use the variable $xuri
for the URL to display."}
{uri(viewHtml) mimeShowHtml {CHOICE inline defer external} {How to display text/html}
"There are three ways to display text/html message parts:
inline - display text/html directly in the message window.
defer - use buttons to display in an external viewer.
external - display text/html immediatly, using an external viewer."}
{uri(deferDisplaysInline) deferDisplaysInline OFF {Defer displays inline}
"If enabled, defer also shows text/html inline."}
{uri(mosaicApp) uriMosaicApp {Mosaic} {Mosaic program name}
"This is the name of the binary program that corresponds to the
Mosaic viewer option. For example, some sites use \"xmosaic\"."}
{uri(netscapeCmd) uriNetscapeCmd {} {Netscape command}
"This is the netscape command used to contact netscape and/or start it up.
The -remote openURL($xuri) is removed in order to start up netscape.
Various examples might be:
netscape -display :0.1 -remote openURL($xuri,new-window)
/somewhere/weird/netscape -install -remote openURL($xuri,noraise)"}
{uri(tclCmd) uriTclCmd {NetRemote $xuri} {Tcl Command to view URL}
"This is the Tcl command used if you select the \"tclcmd\" browser option.
The variable \$xuri gets replaced with the URL. If you want to run
an external program, use the \"exec\" Tcl command."}
{uri(logOnEnter) uriLogOnEnter ON {Show selected URL}
"With 'Show selected URL' enabled exmh will display
the coresponding URL if you move with the mouse on an
activated (looks like a button) X-Face or URL in the
message text.
NOTE: When you change the option you have to rescan your
current message or read another one to de/active
the option."}
}
# Convert viewHtml from boolean to choice
switch $uri(viewHtml) {
1 -
0 {
set uri(viewHtml) inline
}
}
# Nuke old "other" viewer option.
if {[string compare $uri(viewer) "other"] == 0} {
set viewerApp [option get . uriViewerApp {}]
if {[string length $viewerApp]} {
set uri(viewer) tclcmd
set uri(tclCmd) "exec $viewerApp"
} else {
set uri(viewer) netscape
}
}
if [catch {package require netscape_remote}] {
Exmh_Debug "No netscape_remote package"
} else {
Exmh_Debug "Using netscape_remote package"
}
# Fix up netscape command from the old flags argument
set flags [option get . uriNetscapeFlags {}]
set cmd $uri(netscapeCmd)
if {[string length $cmd] && [string match *$flags* $cmd]} {
# flags already in the command
} else {
if {![regexp {^([^ ]+)[ ]?(.*)$} $cmd x program args]} {
set program netscape
set args {-remote openURL($xuri)}
}
set uri(netscapeCmd) "$program $flags $args"
}
}
proc Uri_ShowPart { tkw part } {
global uri mimeHdr
switch -- $uri(viewHtml) {
defer {
set start [$tkw index insert]
$tkw insert insert "View HTML contents with "
if {$uri(viewer) == "other"} {
$tkw insert insert $uri(viewerApp)
} else {
$tkw insert insert $uri(viewer)
}
set end [$tkw index insert]
$tkw insert insert "\n"
TextButtonRange $tkw $start $end [list Uri_ShowPartDirect $tkw $part]
MimeMenuAdd $part checkbutton \
-label "Display HTML inline" \
-command [list busy MimeRedisplayPart $tkw $part] \
-variable mimeHdr($part,display)
if {$mimeHdr($part,display)} {
uplevel {
if [info exists mimeHdr($part,hdr,content-base)] {
set var(S_url) $mimeHdr($part,hdr,content-base)
} else {
set var(S_url) file:$mimeHdr($part,file)
}
if [catch {open $mimeHdr($part,file)} in] {
$tkw insert insert "Cannot open temp file: $in\n"
} else {
set html [read $in]
close $in
if [regexp -nocase <frameset $html] {
$tkw insert insert "Frames will not display inline\n"
} else {
$tkw config -wrap word
Html_DisplayInline $tkw $var(S_url) $html
}
}
}
} else {
$tkw insert insert ". . .\t"
MimeInsertNote $tkw [MimeLabel $part part] \
"Invoke menu with right button."
}
}
external {
Uri_ShowPartDirect $tkw $part
}
inline -
default {
Html_MimeShow $tkw $part
}
}
}
proc Uri_ShowPartDirect { tkw part } {
global mimeHdr mime
set fileName $mimeHdr($part,file)
File_Delete [Env_Tmp]/exmh.[pid].html
# Please avoid "file link" until we commit to Tcl 8.4
if [catch {exec ln $fileName [Env_Tmp]/exmh.[pid].html}] {
file copy $fileName [Env_Tmp]/exmh.[pid].html
}
set fileName [Env_Tmp]/exmh.[pid].html
Exmh_Status "HTML Load $fileName"
$tkw insert insert "Viewing HTML ...\n"
URI_StartViewer file://localhost$fileName
}
proc URI_StartViewer {xuri} {
global uri auto_index
regsub -nocase "URL:" $xuri {} xuri
string trimright $xuri "."
if [regexp {^mailto:(.*)$} $xuri x address] {
Msg_Mailto $xuri
return
}
regsub -all {[][$\\,~ ]} $xuri {[scan \\& %c x ; format "%%%02x" $x]} xuri
set xuri [subst $xuri]
Exmh_Status "$uri(viewer) $xuri"
if [catch {
switch -- $uri(viewer) {
Mosaic { Mosaic_Load $xuri}
netscape {
set rmtcmd $uri(netscapeCmd)
set sendargs {openURL($xuri)}
regexp {openURL\(.*\)} $rmtcmd sendargs
set sendargs [subst $sendargs]
regsub -- {-remote openURL\(.*\)} $rmtcmd {} startcmd
Exmh_Debug rmtcmd $rmtcmd \n sendargs $sendargs \n startcmd $startcmd
if {([info commands info-netscape] == "info-netscape") ||
[info exists auto_index(info-netscape)]} {
# Use send-netscape extension
if [llength [info-netscape list]] {
send-netscape $sendargs
} else {
eval exec $startcmd { $xuri & }
Exmh_Status "Starting netscape"
}
} elseif {[ catch {eval exec $rmtcmd >& /dev/null} tmp ]} {
if [catch {
eval exec $startcmd { $xuri & }
Exmh_Status "Starting netscape"
} err] {
Exmh_Status "netscape: $err"
}
}
}
surfit -
webedit -
webtk {
set interps [winfo interps]
if {$uri(viewer) == "surfit" } {
set dispFunc "surfit_create_window"
} else {
set dispFunc "Url_DisplayNew"
}
set ix [lsearch -glob $interps $uri(viewer)*]
if {$ix >= 0} {
set interp [lindex $interps $ix]
} else {
Exmh_Status "$uri(viewer) is not running"
return
}
if [catch {send -async $interp [list $dispFunc $xuri]} err] {
Exmh_Status $err
} else {
Exmh_Status "Viewing URL with $uri(viewer)"
}
}
exmh {
Html_Window $xuri
}
tclcmd {
Exmh_Debug [subst $uri(tclCmd)]
eval $uri(tclCmd)
}
}
} err] {
Exmh_Status $err
}
}
proc URI_OpenSelection {} {
if [catch {selection get} xuri] {
return
}
URI_StartViewer $xuri
}
proc Hook_MsgShowParseUri {msgPath hmm} {
global uri exwin mimeHdr
foreach hdr {x-uri x-url} {
if {[info exists mimeHdr(0=1,hdr,$hdr)] && $uri(scanForXURIs)} {
set temp_uri [MsgParseFrom $mimeHdr(0=1,hdr,$hdr) noaddr]
}
}
if [info exists temp_uri] {
regsub -all "\[ \t\n\]" $temp_uri {} temp_uri
set but [Faces_Button [list URI_StartViewer $temp_uri]]
global exmh
$but config -bitmap @$exmh(bitmaps)/url.bitmap
if $uri(logOnEnter) {
regsub -all % $temp_uri %% temp_uri
bind $but <Enter> [list Exmh_Status "X-URL:\t$temp_uri"]
bind $but <Leave> [list Exmh_Status ""]
}
} else {
Uri_ClearCurrent
}
if !$uri(scanForURIs) {
return
}
URI_ScanMsg $exwin(mtext) $uri(scanLimit)
}
proc Uri_ClearCurrent {} {
Faces_ClearButton
}
proc Hook_MsgClipParseUri {msgPath t} {
global uri exwin
if !$uri(scanForURIs) {
return
}
URI_ScanMsg $t $uri(scanLimit)
}
proc URI_ActiveText { w start end URI} {
global uri
# Spaces are optional around the edges of the URI in the <a href> context
set URI [string trim $URI]
# quote percents in URLs because they appear in binding commands
regsub -all % $URI %% URI
set id [TextButtonRange $w $start $end [list URI_StartViewer $URI]]
if $uri(logOnEnter) {
$w tag bind $id <Any-Enter> [list +Exmh_Status "X-URL:\t$URI"]
$w tag bind $id <Any-Leave> [list +Exmh_Status ""]
}
update idletasks
return $id
}
proc URI_ScanMsg { {w {}} {limit end} } {
global uri exwin
if {$w == {}} {
set w $exwin(mtext)
}
set x [lindex [$w config -cursor] 4]
$w config -cursor watch
set grab 0
set uri(stop) 0
scan [$w index end] %d lnum
set limit [string trim $limit]
if {$limit != "end"} {
if {$limit > $lnum} {
set limit $lnum.0
} else {
set limit $limit.0
}
}
if {$lnum > $uri(scanSoftLimit) && ($uri(scanSoftLimit) < $limit)} {
set g $w.ustop
if [winfo exists $g] {
destroy $g
}
frame $g -bd 4 -relief raised
set f [frame $g.pad -bd 20]
set msg [Widget_Message $f msg -text "$lnum Lines to scan" -aspect 1000]
Widget_AddBut $f stop STOP {set uri(stop) 1} {top padx 2 pady 2 filly}
bind $f.stop <Any-Key> {set uri(stop) 1 ; Exmh_Status Stop warn}
bind $g <Destroy> {set uri(stop) 1 ; Exmh_Status Stop warn}
pack $f
Widget_PlaceDialog $w $g
Visibility_Wait $f.stop
catch {
focus $f.stop
grab $f.stop
}
set grab 1
}
Exmh_Debug "URI_ScanMsg $limit"
set multiline 0
set hit 0
set protocol (ftp|http|https|gopher|nntp|telnet|wais|file|prospero|finger|urn|mailto|news|solo|x500)
# the following pattern runs extremely slowly if there are long,
# unbroken character sequences in a message.
# set protocol {[A-Za-z_]+[-A-Za-z0-9_]*}
for {set i 0} {[$w compare $i.0 < $limit]} {if {! $hit} {incr i}} {
if {! $hit} {
set begin 0
set text [$w get $i.0 "$i.0 lineend"]
} else {
# Look for more on the same line
set text [string range $text $begin end]
}
set hit 0
if {$grab && $i && (($i % 20) == 0)} {
$msg config -text "Scanned $i of $lnum"
update
}
if {$uri(stop)} {
break
}
######
# In this loop $i is the current line,
# $text is the remaining part of the line
# $begin is the offset of $text within the line
#
#######
# match URIs continued from the previous line (begin is zero)
if $multiline {
set right [string first ">" $text]
if {$right != -1} {
Exmh_Debug Regexp0 right=$right begin=$begin
set last $i.$right
regsub -all "\n" [$w get $mstart $last] {} temp_uri
URI_ActiveText $w $mstart $last $temp_uri
set begin $right
set text [string range $text $right end]
set multiline 0
set hit 1
}
# note: we will continue to look until a close is found
continue
}
# Each regexp clause must set:
# hit to 1 if it matched
# start to the index within the text line to begin highlight
# end to end index within the text line to end highlight
# temp_uri to the value of the URL.
if {[regexp -indices "<$protocol:\[^>)\]+>" $text indices] == 1} {
# check for URIs like <protocol: > present
Exmh_Debug Regexp1 $indices
set start [expr [lindex $indices 0] + 1]
set end [expr [lindex $indices 1] -1]
set hit 1
} elseif {[regexp -indices -nocase {<a href=([^>]+)>([^<]*)(</a>)?} \
$text indices i1 i2] == 1} {
# match real HTML links
Exmh_Debug Regexp2 $indices $i1 $i2
set temp_uri [string trim [string range $text [lindex $i1 0] [lindex $i1 1]] {"}]
set text [string range $text [lindex $indices 1] end]
$w configure -state normal
$w delete $i.[expr $begin + [lindex $i2 1] + 1] \
$i.[expr $begin + [lindex $indices 1] + 1]
$w delete $i.[expr $begin + [lindex $indices 0]] \
$i.[expr $begin + [lindex $i2 0]]
$w configure -state disabled
set start [expr $begin + [lindex $indices 0]]
set end [expr $begin + [lindex $indices 0] + [lindex $i2 1] - [lindex $i2 0] + 1]
URI_ActiveText $w $i.$start $i.$end $temp_uri
set begin $end
set hit 1
# Continue because we have set up begin and text properly
continue
} elseif {[regexp -indices -nocase "<(urn|url|uri)\[: \]\[^>\]+>" $text indices] == 1} {
# match URIs wholly contained on one line
Exmh_Debug Regexp3 $indices
set start [expr [lindex $indices 0] + 1]
set end [expr [lindex $indices 1] - 1]
set hit 1
} elseif {[regexp -indices "$protocol:/+\[^ \n\t\]+\[^ \n\t,\.\)>\'\"\]" \
$text indices] == 1} {
# check for unencapsulated URIs by protocol if no < > present
Exmh_Debug Regexp4 $indices
set start [lindex $indices 0]
set end [lindex $indices 1]
set hit 1
} elseif {[regexp -indices -nocase \
"(urn|mailto|news|solo|x500):\[^ \n\t\)\]*\[^ \n\r\)\.\]" \
$text indices] == 1} {
Exmh_Debug Regexp5 $indices
set start [lindex $indices 0]
set end [lindex $indices 1]
set hit 1
} elseif {[regexp -indices -nocase "<(urn|url|uri)\[: \]" $text indices] == 1} {
# match the start of a URI which is broken over more than one line
# must include <URN or <URL
Exmh_Debug Regexp6 $indices
set mstart $i.[expr [lindex $indices 0] + $begin + 1]
set multiline 1
}
if {$hit} {
# Found a URL - handle the offset between $text and the text widget line
set temp_uri [string range $text $start $end]
URI_ActiveText $w $i.[expr $begin+$start] $i.[expr $begin+$end] $temp_uri
set begin [expr $begin + $end]
set text [string range $text $end end]
}
}
if {$grab} {
catch {grab release $g.stop}
Exmh_Focus
destroy $g
}
$w config -cursor $x
}
proc Mime_ShowUri {tkw part} {
global mimeHdr mime miscRE
MimeWithDisplayHiding $tkw $part {
set subtype [file tail $mimeHdr($part,type)]
Mime_WithTextFile fileIO $tkw $part {
set url [read $fileIO]
set start [$tkw index insert]
$tkw insert insert $url
set end [$tkw index insert]
$tkw insert insert \n
URI_ActiveText $tkw $start $end $url
}
}
return 1
}
|