From 9df0ccf6316b86d88afffd0ce50ba15da302c892 Mon Sep 17 00:00:00 2001 From: Jeff Connelly Date: Tue, 3 Jun 2008 18:30:38 -0700 Subject: [PATCH] Add a working (for reading, at least) command-line interface. --- EasyOTP-gui.py | 35 ++++++++++++++++++++++ EasyOTP.py | 31 ------------------- MailServers.py => SecureInbox.py | 5 ++-- cli.py | 65 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 103 insertions(+), 33 deletions(-) create mode 100644 EasyOTP-gui.py delete mode 100644 EasyOTP.py rename MailServers.py => SecureInbox.py (94%) create mode 100644 cli.py diff --git a/EasyOTP-gui.py b/EasyOTP-gui.py new file mode 100644 index 0000000..18a1915 --- /dev/null +++ b/EasyOTP-gui.py @@ -0,0 +1,35 @@ +#!/bin/env python +# Created:20080603 +# By Jeff Connelly +# +# GUI for EasyOTP TODO + +from Tkinter import * +import cotp +import MailServers + +class App(object): + def __init__(self, master): + frame = Frame(master) + frame.pack(expand=True, fill=BOTH) + + self.read = Button(frame, text="Read", command=self.read) + self.read.pack(side=LEFT) + + self.write = Button(frame, text="Write", command=self.write) + self.write.pack(side=LEFT) + + self.quit = Button(frame, text="Quit", command=frame.quit) + self.quit.pack(side=LEFT) + + def read(self): + print "read" + + def write(self): + print "write" + +root = Tk() +app = App(root) +root.title("EasyOTP") +root.mainloop() + diff --git a/EasyOTP.py b/EasyOTP.py deleted file mode 100644 index aa086de..0000000 --- a/EasyOTP.py +++ /dev/null @@ -1,31 +0,0 @@ -#!/bin/env python -import popen2 - -def decode(ct): - o, i, e = popen2.popen3("./cotp -d") - i.write(ct) - i.close() - pt = o.read() - errors = e.read() - if errors: - raise errors - return pt - -# TODO: support padname -def encode(pt): - o, i, e = popen2.popen3("./cotp -e") - i.write(pt) - i.close() - ct = o.read() - errors = e.read() - if errors: - raise errors - return ct - -if __name__ == "__main__": - ct = encode("hello world") - print ct - pt = decode(ct) - print ct - assert ct == "hello world", "decode failed to match" - diff --git a/MailServers.py b/SecureInbox.py similarity index 94% rename from MailServers.py rename to SecureInbox.py index 9d27868..60a35c7 100644 --- a/MailServers.py +++ b/SecureInbox.py @@ -8,8 +8,9 @@ import imaplib import getpass import email -class MailServers(object): +class SecureInbox(object): def __init__(self, username, password): + # IMAP SSL for incoming messages self.mail_in = imaplib.IMAP4_SSL("imap.gmail.com", 993) try: @@ -62,7 +63,7 @@ class MailServers(object): self.mail_in.logout() def main(): - ms = MailServers("shellreef", getpass.getpass()) + ms = SecureInbox("shellreef", getpass.getpass()) for m in ms.get_messages(): print m["sender"], m["subject"] diff --git a/cli.py b/cli.py new file mode 100644 index 0000000..a6932ad --- /dev/null +++ b/cli.py @@ -0,0 +1,65 @@ +#!/bin/env python +# Created:20080603 +# By Jeff Connelly +# +# CLI for EasyOTP + +import SecureInbox +import cotp +import getpass +import sys + +def help(): + print """commands: +h Help +l List messages +q Quit +r# Read message number # +""" + +def main(): + username = raw_input("Username: ") + ms = SecureInbox.SecureInbox(username, getpass.getpass()) + msgs = [] + while True: + try: + line = raw_input(">> ") + except EOFError: + break + if len(line.strip()) == 0: + continue + + if line[0] == "h": + help() + elif line[0] == "l": + print "Fetching messages..." + msgs = ms.get_messages() + i = 0 + for m in msgs: + print i, m["sender"], m["subject"] + i += 1 + elif line[0] == "q": + raise SystemExit + elif line[0] == "r": + num = int(line[1:]) + try: + msg = msgs[num] + except: + print "Bad message: %s" % (msg,) + print "Are you sure it is listed with 'l'?" + print "Message count: %s" % (len(msgs),) + continue + + print "From: %s" % (msg["sender"],) + print "Subject: %s" % (msg["subject"],) + print + try: + print cotp.decode(msg["body"]) + except: + print "Exception when decoding", sys.exc_info() + else: + print "Unknown command, type h for help" + +if __name__ == "__main__": + main() + -- 2.11.4.GIT