Esempio n. 1
0
def process_email(email):
	"""
	Adds/Updates new tags
	"""
	# user never used the service before
	# so send him an email with instructions!
	if not find_user(email.sender):
		send_email(email.to, email.sender, "Welcome to thejimemail!", "These are the instructions!")
		
	# check if its a command to retrieve messages
	if '?' in email.subject:
		return return_tag_command(email.sender, email.subject.split('?')[0])

	tags = parse_subject(email.subject)

	user = email.sender
	body = ""
	for content_type, ebody in email.bodies('text/plain'):
		body += ebody.decode()

	# check if its a command to interact messages
	if 're:' in email.subject[0:3].lower():
		return update_tag(tag, body, True)

	# if tag exists, update it
	tag = find_tag(user, tags)
	if tag:
		if type(tag) == list():
			for t in tag:
				update_tag(t, body)
	else:	
		add_tag(user, tags, body)

	return None
def get_clean_body(email):
    bodies = email.bodies(content_type='text/plain') #generator
    
    allBodies = ""; numBodies=0
    for body in bodies:
        allBodies = allBodies + body[1].decode()
        numBodies += 1
        if isinstance(allBodies, unicode):
        	allBodies = allBodies.encode('utf-8')

    if numBodies > 1: logging.warn("recvd mail with %s bodies: %s" % (numBodies, email))
    return allBodies