Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

premier send qui marche\!

  • Loading branch information...
commit 2bc52a97362921ed7630164abb16172096cc3fdd 1 parent 36a4a55
@aallai authored
Showing with 40 additions and 15 deletions.
  1. +12 −0 config.py
  2. +3 −0  config.txt
  3. +5 −3 core.py
  4. +20 −12 mediums.py
View
12 config.py
@@ -0,0 +1,12 @@
+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')))}
+
+
+
View
3  config.txt
@@ -0,0 +1,3 @@
+smtp_server = smtp.gmail.com
+smtp_user = comp535test@gmail.com
+smtp_passwd = assignment3
View
8 core.py
@@ -31,12 +31,12 @@ def send(medium_list, data, sender_key, receiver_key) :
segments = []
for i in xrange(data_len / min_mtu) :
- segments += (i, data[i*min_mtu : i*min_mtu + min_mtu])
+ segments += [ (i, data[i*min_mtu : i*min_mtu + min_mtu]) ]
seq_len = len(segments)
if (data_len % min_mtu != 0) :
- segments += (seq_len, data[seq_len * min_mtu :])
+ segments += [ (seq_len, data[seq_len * min_mtu :]) ]
seq_len += 1
messages_per_medium = len(segments) / med_len
@@ -54,8 +54,10 @@ def send(medium_list, data, sender_key, receiver_key) :
def send_range(medium, segments, key, mid) :
+ print segments
+
for seq, segment in segments :
- medium.send(segment, seq, mid, key)
+ medium.send(segment, mid, seq, key)
def receive(medium_list, receiver_key) :
View
32 mediums.py
@@ -1,6 +1,7 @@
import smtplib
import imaplib
import poplib
+from config import config
POP = 0
IMAP = 1
@@ -50,36 +51,43 @@ class EmailMedium(Medium) :
Represents an email account to which messages can be sent (and possbly received if we have the password for it).
'''
- # use POP as default, some webmail services don't offer IMAP
+ '''
+CEST LE BORDEL ICITTE
+ '''
- def __init__(self, address, passwd=None, proto=None) :
+ def __init__(self, address, recv_server=None, passwd=None, proto=None) :
-
# MTU depends on smtp settings of server... maybe we should connect here and figure it out
- self.addr = address
+ self.address = address
self.mtu = 2048 # temporary
- # I am thinking of using the same class to represent
- # the local users account (for which we need a password)
- # and other users account, in which case we will never receive..
- # not the cleanest thig ever
- if passwd and proto :
+ if recv_server and passwd and proto :
if proto != IMAP and proto != POP :
return None
+ self.server = recv_server
self.passwd = passwd
self.proto = proto
else :
+ self.server = None
self.passwd = None
self.proto = None
def send(self, data, mid, seq, key) :
+
+ # not sure this works with every smtp server
+
+ server = smtplib.SMTP(config['smtp_server'])
+ server.starttls()
+ server.login(config['smtp_user'], config['smtp_passwd'])
+
+
+ msg = '\n'.join([key, mid + ' ' + str(seq), data])
+
+ server.sendmail(self.address, self.address, msg)
- '''
- Make a header and use smtp to send the data
- '''
def receive(self, key) :
Please sign in to comment.
Something went wrong with that request. Please try again.