freebsd-skq/contrib/nvi/tcl_scripts/mailprocs.tcl
Peter Wemm b8ba871bd9 Import of nvi-1.79, minus a few bits that we dont need (eg: postscript
files, curses, db, regex etc that we already have).  The other glue will
follow shortly.

Obtained from: Keith Bostic <bostic@bostic.com>
1996-11-01 06:45:43 +00:00

116 lines
2.5 KiB
Tcl
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# @(#)mailprocs.tcl 8.3 (Berkeley) 4/29/96
#
proc validLine {} {
global viScreenId
set line [viGetLine $viScreenId [lindex [viGetCursor $viScreenId] 0]]
if {[string compare [lindex [split $line :] 0] "To"] == 0} {
set addrs [lindex [split $line :] 1]
foreach name [split $addrs ,] {
isValid [string trim $name]
}
}
}
proc valid {target} {
set found 0
set aliasFile [open "~/Mail/aliases" r]
while {[gets $aliasFile line] >= 0} {
set name [lindex [split $line :] 0]
set address [lindex [split $line :] 1]
if {[string compare $target $name] == 0} {
set found 1
break
}
}
close $aliasFile
if {$found == 1} {
return $address
} else {
return $found
}
}
proc isValid {target} {
global viScreenId
set address [valid $target]
if {$address != 0} {
viMsg $viScreenId "$target is [string trim $address]"
} else {
viMsg $viScreenId "$target not found"
}
}
proc isAliasedLine {} {
global viScreenId
set line [viGetLine $viScreenId [lindex [viGetCursor $viScreenId] 0]]
if {[string match [lindex [split $line :] 0] "*To"] == 0} {
set addrs [lindex [split $line :] 1]
foreach name [split $addrs ,] {
isAliased [string trim $name]
}
}
}
proc aliased {target} {
set found 0
set aliasFile [open "~/Mail/aliases" r]
while {[gets $aliasFile line] >= 0} {
set name [lindex [split $line :] 0]
set address [lindex [split $line :] 1]
if {[string compare $target [string trim $address]] == 0} {
set found 1
break
}
}
close $aliasFile
return $found
}
proc isAliased {target} {
global viScreenId
set found [aliased $target]
if {$found} {
viMsg $viScreenId "$target is aliased to [string trim $name]"
} else {
viMsg $viScreenId "$target not aliased"
}
}
proc appendAlias {target address} {
if {![aliased $target]} {
set aliasFile [open "~/Mail/aliases" a]
puts $aliasFile "$target: $address"
}
close $aliasFile
}
proc expand {} {
global viScreenId
set row [lindex [viGetCursor $viScreenId] 0]]
set column [lindex [viGetCursor $viScreenId] 1]]
set line [viGetLine $viScreenId $row]
while {$column < [string length $line] && \
[string index $line $column] != ' '} {
append $target [string index $line $column]
incr $column
}
set found [isValid $target]
}
proc cite {} {
global viScreenId
global viStartLine
global viStopLine
for {set i $viStartLine} {$i <= $viStopLine} {incr i} {
set newLine "> "
append newLine [viGetLine $viScreenId $i]
viSetLine $viScreenId $i $newLine
}
}
global viScreenId
viMapKey $viScreenId  isAliasedLine
viMapKey $viScreenId  validLine