-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaddressbook.py
57 lines (40 loc) · 1.43 KB
/
addressbook.py
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
import functions
def getAddresses():
addressBook = open(functions.HOME + "/.sendmail_mailinglist")
lines = addressBook.read().split("\n")
addressBook.close()
addresses = []
for address in lines:
if address.startswith("+"):
addresses.append(address[1:])
return addresses
def printAddresses(numbering):
if numbering not in ["numbers", "middle-dot", "minus-sign"]:
raise ValueError("numbering argument has to bei one of ['numbers', 'middle-dot', 'minus-sign']")
lines = getAddresses()
if numbering == "numbers":
for number, line in enumerate(lines):
print(number, ": ", line, sep="")
return number
else:
if numbering == "minus-sign":
numbering = "- "
else:
numbering = "· "
for line in lines:
print(numbering, line, sep="")
return True
def removeAddress(i: int):
addresses = getAddresses()
tmp_addresses = ["+" + addresses[i]]
new_addresses = set(addresses) - set(tmp_addresses)
addressBook = open(functions.HOME + "/.sendmail_mailinglist", "w")
for address in new_addresses:
addressBook.write("{addr}\n".format(addr=address))
addressBook.close()
return True
def addAddress(address):
addressBook = open(functions.HOME + "/.sendmail_mailinglist", "a")
addressBook.write("+{addr}\n".format(addr=address))
addressBook.close()
return True