def receive(self, message): # TODO: Add supports for project-(.*) and person-(.*) logging.info("Received a message to: " + message.to) logging.info("Received a message from: " + message.sender) to_p = re.compile(r'(?<=entry-)(.*?)(?=@)') # TODO: And post-fixs to_m = to_p.search(message.to) if not to_m: logging.info("No valid email address in 'to'. Try search 'cc'.") to_m = to_p.search(message.cc) if to_m: key = to_m.group() entry = models.Entry.get(key) if entry: plaintext_bodies = message.bodies('text/plain') text = "" for content_type, body in plaintext_bodies: text = text + body.decode() # So we get texts. logging.info("Original texts: \n" + text) text= remove_quotes(text) # Remove quotes. logging.info("Clean texts: \n" + text) from_p = re.compile(r'(?<=(\<))(.*?)(?=@' + settings.DOMAIN + ')') # TODO: Bug: pure email address can't match. from_m = from_p.search(message.sender) if from_m: id = from_m.group() logging.info("Sender identified: %s" % id) person = models.Person.get_by_key_name(id) handlers.new_story(self, text, entry=entry, type="comment", person=person) logging.info("Delivered an update to entry-%s" % key) else: logging.error("Email delivery failed: Invalid sender.") else: logging.error("Email delivery failed: Can't find the entry") else: logging.error("Email delivery failed: No valid email address found.")
def get(self): entries = models.Entry.all() for entry in entries: if entry.delayed: handlers.new_story(self, "This is delayed", entry=entry)