summaryrefslogtreecommitdiffstats
path: root/contrib/nvi/tcl_scripts/mailprocs.tcl
blob: eccb9cdfcf74137ed594fae35d7bd49a1f744634 (plain)
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
#	@(#)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
OpenPOWER on IntegriCloud