Add mixing program.
[easyotp.git] / cli.py
blob5282dfc1d9a9cde9bbd0adfed0e124e13666d66c
1 #!/bin/env python
2 # Created:20080603
3 # By Jeff Connelly
5 # CLI for EasyOTP
7 import SecureMail
8 import cotp
9 import getpass
10 import sys
11 import os
12 import time
14 ms = None
16 def help():
17 print """commands:
18 h Help
19 l List messages
20 q Quit
21 r# Read message number #
22 """
24 def main():
25 global ms
26 ms = SecureMail.SecureMail()
27 msgs = []
29 while True:
30 try:
31 line = raw_input(">> ")
32 except EOFError:
33 break
34 if len(line.strip()) == 0:
35 continue
37 if line[0] == "h":
38 help()
39 elif line[0] == "l":
40 print "Fetching messages..."
41 i = 0
42 for m in ms:
43 print i, m["sender"], m["subject"]
44 i += 1
45 elif line[0] == "q":
46 raise SystemExit
47 elif line[0] == "w":
48 to = raw_input("To: ")
49 subject = raw_input("Subject: ")
50 print "Enter body, ending with '.' on a line by itself."
51 body = ""
52 while True:
53 line = raw_input()
54 if line == ".":
55 break
56 body += line + "\r\n"
57 print ms.send(to, subject, body)
59 elif line[0] == "r":
60 try:
61 num = int(line[1:])
62 except:
63 print "Usage: r#"
64 continue
65 try:
66 msg = ms[num]
67 except:
68 print "Bad message number: %s" % (num,)
69 print "Are you sure it is listed with 'l'?"
70 print "Message count: %s" % (len(msgs),)
71 continue
73 print "From: %s" % (msg["sender"],)
74 print "Subject: %s" % (msg["subject"],)
75 print msg["body"]
76 else:
77 print "Unknown command, type h for help"
79 if __name__ == "__main__":
80 main()