Powered by CoCalc
1
#!/usr/bin/python
2
import os, string, sys
3
4
def get_list():
5
f = open("list","r").read()
6
list = []
7
for line in string.split(f, "\n"):
8
words = line.split()
9
if len(words) < 2:
10
continue
11
list.append([words[0], words[len(words)-1]])
12
return list
13
14
def mailall(filename):
15
msg = open(filename,"r").read()
16
if len(msg) < 100:
17
print "Message is too short; I refuse to send your message!"
18
sys.exit(1)
19
if msg[:3].upper() == "SU:":
20
i = string.find(msg,"\n")
21
subject = msg[4:i]
22
msg = msg[i+1:]
23
else:
24
print "Missing subject; I refuse to send your message!"
25
sys.exit(1)
26
27
for person in get_list():
28
name = person[0]
29
m = string.replace(msg, "NAME", name)
30
print "\n------------------------------------------"
31
print "Sending the following message to %s:\n%s"%(person[1],m)
32
mail = os.popen2('mail %s -s "%s"'%(person[1],subject))
33
mail[0].write(m)
34
mail[0].close()
35
36
if len(sys.argv) == 1:
37
print "Usage: " + sys.argv[0] + " filename\n"
38
sys.exit(1)
39
40
if not os.path.exists(sys.argv[1]):
41
print sys.argv[0] + ": File name found"
42
sys.exit(1)
43
44
mailall(sys.argv[1])
45