1#	Id: mailprocs.tcl,v 8.3 1996/04/29 12:31:35 bostic Exp  (Berkeley) Date: 1996/04/29 12:31:35
2#
3proc validLine {} {
4	global viScreenId
5	set line [viGetLine $viScreenId [lindex [viGetCursor $viScreenId] 0]]
6	if {[string compare [lindex [split $line :] 0]	"To"] == 0} {
7		set addrs [lindex [split $line :] 1]
8		foreach name [split $addrs ,] {
9			isValid [string trim $name]
10		}
11	}
12}
13
14proc valid {target} {
15	set found 0
16	set aliasFile [open "~/Mail/aliases" r]
17	while {[gets $aliasFile line] >= 0} {
18		set name [lindex [split $line :] 0]
19		set address [lindex [split $line :] 1]
20		if {[string compare $target $name] == 0} {
21			set found 1
22			break
23		}
24	}
25	close $aliasFile
26	if {$found == 1} {
27		return $address
28	} else {
29		return $found
30	}
31}
32
33proc isValid {target} {
34	global viScreenId
35	set address [valid $target]
36	if {$address != 0} {
37		viMsg $viScreenId "$target is [string trim $address]"
38	} else {
39		viMsg $viScreenId "$target not found"
40	}
41}
42
43proc isAliasedLine {} {
44	global viScreenId
45	set line [viGetLine $viScreenId [lindex [viGetCursor $viScreenId] 0]]
46	if {[string match [lindex [split $line :] 0] "*To"] == 0} {
47		set addrs [lindex [split $line :] 1]
48		foreach name [split $addrs ,] {
49			isAliased [string trim $name]
50		}
51	}
52}
53
54proc aliased {target} {
55	set found 0
56	set aliasFile [open "~/Mail/aliases" r]
57	while {[gets $aliasFile line] >= 0} {
58		set name [lindex [split $line :] 0]
59		set address [lindex [split $line :] 1]
60		if {[string compare $target [string trim $address]] == 0} {
61			set found 1
62			break
63		}
64	}
65	close $aliasFile
66
67	return $found
68}
69
70proc isAliased {target} {
71	global viScreenId
72	set found [aliased $target]
73
74	if {$found} {
75		viMsg $viScreenId "$target is aliased to [string trim $name]"
76	} else {
77		viMsg $viScreenId "$target not aliased"
78	}
79}
80
81proc appendAlias {target address} {
82	if {![aliased $target]} {
83		set aliasFile [open "~/Mail/aliases" a]
84		puts $aliasFile "$target: $address"
85	}
86	close $aliasFile
87}
88
89proc expand {} {
90	global viScreenId
91	set row [lindex [viGetCursor $viScreenId] 0]]
92	set column [lindex [viGetCursor $viScreenId] 1]]
93	set line [viGetLine $viScreenId $row]
94	while {$column < [string length $line] && \
95		[string index $line $column] != ' '} {
96		append $target [string index $line $column]
97		incr $column
98	}
99	set found [isValid $target]
100}
101
102proc cite {} {
103	global viScreenId
104	global viStartLine
105	global viStopLine
106	for {set i $viStartLine} {$i <= $viStopLine} {incr i} {
107		set newLine "> "
108		append newLine [viGetLine $viScreenId $i]
109		viSetLine $viScreenId $i $newLine
110	}
111}
112
113global viScreenId
114viMapKey $viScreenId  isAliasedLine
115viMapKey $viScreenId  validLine
116