|  | @@ -6,7 +6,10 @@ import imaplib
 | 
	
		
			
			| 6 | 6 |  import email
 | 
	
		
			
			| 7 | 7 |  import email.header
 | 
	
		
			
			| 8 | 8 |  from email.header import Header, decode_header, make_header
 | 
	
		
			
			|  | 9 | +import requests
 | 
	
		
			
			| 9 | 10 |  import datetime
 | 
	
		
			
			|  | 11 | +from tracim.controllers.events import VALID_TOKEN_VALUE
 | 
	
		
			
			|  | 12 | +import json
 | 
	
		
			
			| 10 | 13 |  
 | 
	
		
			
			| 11 | 14 |  TRACIM_SPECIAL_KEY_HEADER="X-Tracim-Key"
 | 
	
		
			
			| 12 | 15 |  
 | 
	
	
		
			
			|  | @@ -64,10 +67,12 @@ def get_tracim_content_key(mailData:dict) -> Union[str,None]:
 | 
	
		
			
			| 64 | 67 |      if key is None and 'to' in mailData:
 | 
	
		
			
			| 65 | 68 |          key = find_key_from_mail_adress(mailData['to'])
 | 
	
		
			
			| 66 | 69 |      if key is None and 'references' in mailData:
 | 
	
		
			
			| 67 |  | -        mail_adress = mailData['references'].split('>')[0].replace('<','')
 | 
	
		
			
			|  | 70 | +        mail_adress = mailData['references'].split('>')[0].replace('<', '')
 | 
	
		
			
			| 68 | 71 |          key = find_key_from_mail_adress(mail_adress)
 | 
	
		
			
			| 69 | 72 |      return key
 | 
	
		
			
			| 70 | 73 |  
 | 
	
		
			
			|  | 74 | +def get_email_address_from_header(header:str) -> str:
 | 
	
		
			
			|  | 75 | +    return header.split('<')[1].split('>')[0]
 | 
	
		
			
			| 71 | 76 |  
 | 
	
		
			
			| 72 | 77 |  def find_key_from_mail_adress(mail_address:str) -> Union[str,None]:
 | 
	
		
			
			| 73 | 78 |      """ Parse mail_adress-like string
 | 
	
	
		
			
			|  | @@ -166,5 +171,12 @@ class MailFetcher(object):
 | 
	
		
			
			| 166 | 171 |          while self._mails:
 | 
	
		
			
			| 167 | 172 |              mail = self._mails.pop()
 | 
	
		
			
			| 168 | 173 |              decoded_mail = decode_mail(mail)
 | 
	
		
			
			| 169 |  | -            key = get_tracim_content_key(decoded_mail)
 | 
	
		
			
			|  | 174 | +            msg = {"token" : VALID_TOKEN_VALUE,
 | 
	
		
			
			|  | 175 | +                   "user_mail" : get_email_address_from_header(decoded_mail['from']),
 | 
	
		
			
			|  | 176 | +                   "content_id" : get_tracim_content_key(decoded_mail),
 | 
	
		
			
			|  | 177 | +                   "payload": {
 | 
	
		
			
			|  | 178 | +                       "content": decoded_mail['body']
 | 
	
		
			
			|  | 179 | +                   }}
 | 
	
		
			
			|  | 180 | +
 | 
	
		
			
			|  | 181 | +            requests.post('http://localhost:8080/events',json=msg)
 | 
	
		
			
			| 170 | 182 |              pass
 |