Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Starting to emerge

  • Loading branch information...
commit 4401e03694984ddf8b80186098ced533be364c69 1 parent 8cc34a7
@aallai authored
View
21 config.py
@@ -1,12 +1,13 @@
-config = {}
-def read_configuration(file) :
-
- global config
- file = open(file, 'r')
-
- # ignores blank lines and lines starting with a #
- config = {line.split('=')[0].strip() : line.split('=')[1].strip() for line in filter(lambda x : x.split()[0].strip() != '#', filter(lambda x : x.strip(), file.read().split('\n')))}
-
-
+# rudimentary config file, you shouldn't anything here but feel free to change the values
+# this get imported as a python module, so the syntax has to be right
+config = {
+ 'smtp_server' : 'smtp.gmail.com',
+ 'smtp_user' : 'comp535test@gmail.com',
+ 'smtp_passwd' : 'assignment3',
+ 'default_mtu' : 16,
+ 'user_db' : './users.db',
+ 'inbox' : './inbox',
+}
+
View
8 config.txt
@@ -1,8 +0,0 @@
-
-# rudimentary config file, you shouldn't delete any lines here but feel free to change the values
-
-smtp_server = smtp.gmail.com
-smtp_user = comp535test@gmail.com
-smtp_passwd = assignment3
-default_mtu = 16
-users_file = users.db
View
1  core.py
@@ -4,7 +4,6 @@
import time
from config import config
-
'''
Functions to send and receive messages using the protocol
'''
View
26 mediums.py
@@ -4,9 +4,8 @@
import poplib
import re
from config import config
-
+
# base class for transmission medium
-# just a draft for now
class Medium(object) :
@@ -34,6 +33,12 @@ def receive(self, key) :
maybe a dictionary of lists of tuples, { mid : [(seq1, data1), ... (seqn, datan)] } ?
'''
+ def tostring(self) :
+
+ '''
+ So we can print medium settings.
+ '''
+
class EmailError(Exception) :
'''
@@ -98,7 +103,13 @@ def fetch_mail(self) :
return ls
except imaplib.IMAP4.error, e :
- raise EmailError(e.message)
+ raise EmailError(e.message)
+
+ def tostring(self) :
+
+ string = '\n\t'.join(['IMAP Server\n{', 'host -> %s', 'port -> %s', 'user -> %s', 'password -> %s', 'SSL encrypted? -> %s\n}'])
+
+ return string % (self.host, self.port, self.user, self.passwd, str(self.use_ssl))
class PopServer(MailboxServer) :
@@ -141,7 +152,11 @@ def fetch_mail(self) :
except poplib.error_proto, e :
raise EmailError(e.message)
+ def tostring(self) :
+ string = '\n\t'.join(['POP Server\n{', 'host -> %s', 'port -> %s', 'user -> %s', 'password -> %s', 'SSL encrypted? -> %s\n}'])
+
+ return string % (self.host, self.port, self.user, self.passwd, str(self.use_ssl))
class EmailMedium(Medium) :
@@ -158,6 +173,11 @@ def __init__(self, address, mailbox_server=None) :
self.mailbox_server = mailbox_server
+ def tostring(self) :
+
+ str = '\n\t'.join(['Email Medium\n{', 'address -> %s', 'mtu -> %s', 'server -> %s\n}'])
+
+ return str % (self.address, self.mtu, re.sub('\n', '\n\t', self.mailbox_server.tostring()))
def send(self, data, mid, seq, key) :
View
92 smail.py 100644 → 100755
@@ -1,9 +1,101 @@
+#!/usr/bin/python
+
import sys
+import pickle
+import os
+from config import config
+from core import *
+
+
+users = None
+
def main(argv) :
+ setup()
+ while True :
+ menu = '''
+Welcome!
+
+1 Retreive messages
+2 Send a message
+3 Exit
+
+'''
+
+ try :
+ action = int(raw_input(menu))
+ print
+
+ if action == 1 :
+ retreive_messages()
+
+
+ except ValueError :
+ bogus_input()
+
+
+def bogus_input() :
+ sys.err.write('\nEnter a valid choice from the menu.\n')
+
+# check for config files and inbox folder, do some sanity checks
+def setup() :
+
+ global users
+
+ if not os.access(config['inbox'], os.W_OK) :
+ if os.path.exists(config['inbox']) :
+ sys.exit('Inbox directory exists but is inaccessible, exiting.')
+ else :
+ print 'Creating inbox folder'
+ os.mkdir(config['inbox'])
+
+
+
+ if os.access(config['user_db'], os.R_OK) :
+
+ try :
+ users = pickle.load(open(config['user_db'], 'r'))
+ except pickle.UnpicklingError, e :
+ sys.exit('Error reading contact list file : \n' + e.message)
+
+ else :
+ if os.path.exists(config['user.db']) :
+ sys.exit('User list file exists but is inaccessible, exiting.')
+
+ # create new userlist object
+ print 'Creating new user list'
+ users = UserList()
+
+
+def retreive_messages() :
+
+ print 'Retreiving messages...'
+
+ d = receive(users.local_user)
+
+ # only display new messages
+ new = { mid : data for mid, data in d.items() if mid not in os.listdir(config['inbox']) }
+
+ # no new messages
+ if not new :
+ print 'No new messages.'
+ return
+
+ print 'Storing new messages in inbox'
+
+ for mid, data in new.items() :
+ f = open(os.path.join(config['inbox'], mid), 'w')
+ f.write(data)
+ f.close
+ for mid, data in new.items() :
+ print
+ print 'Message ID -> ' + mid
+ print
+ print data
+
if __name__ == '__main__' :
main(sys.argv)
View
80 users.db
@@ -0,0 +1,80 @@
+ccopy_reg
+_reconstructor
+p0
+(cusers
+UserList
+p1
+c__builtin__
+object
+p2
+Ntp3
+Rp4
+(dp5
+S'remote_users'
+p6
+(lp7
+g0
+(cusers
+User
+p8
+g2
+Ntp9
+Rp10
+(dp11
+S'mlist'
+p12
+(lp13
+g0
+(cmediums
+EmailMedium
+p14
+g2
+Ntp15
+Rp16
+(dp17
+S'mailbox_server'
+p18
+g0
+(cmediums
+ImapServer
+p19
+g2
+Ntp20
+Rp21
+(dp22
+S'passwd'
+p23
+S'assignment3'
+p24
+sS'use_ssl'
+p25
+I01
+sS'host'
+p26
+S'imap.gmail.com'
+p27
+sS'port'
+p28
+I993
+sS'user'
+p29
+S'comp535test@gmail.com'
+p30
+sbsS'mtu'
+p31
+I1024
+sS'address'
+p32
+S'comp535test@gmail.com'
+p33
+sbasS'name'
+p34
+S'alex'
+p35
+sS'key'
+p36
+g35
+sbasS'local_user'
+p37
+g10
+sb.
View
2  contacts.py → users.py
@@ -22,5 +22,5 @@ def __init__(self) :
{ user.name : user_object }
'''
- self.local_users = {}
+ self.local_user = None
self.remote_users = {}
Please sign in to comment.
Something went wrong with that request. Please try again.