def receive(self, message): post = Post() html_bodies = message.bodies('text/html') img_links = [] video_links = [] for content_type, body in html_bodies: decoded_body = body.decode() img_links.extend(self.find_image_links(decoded_body)) video_links.extend(self.find_video_links(decoded_body)) if hasattr(message, "attachments") and message.attachments: post.attachments = [] for attachment in message.attachments: post.attachments.append(db.Blob(attachment[1].decode())) plaintext_bodies = message.bodies('text/plain') allBodies = '' for body in plaintext_bodies: allBodies = allBodies + body[1].decode() if hasattr(message, "subject"): subject, encoding = decode_header(message.subject)[0] post.caption = unicode(subject) post.author = message.sender post.content = allBodies post.images = img_links post.videos = video_links post.source = "email" post.put()
def receive(self, message): post = Post() html_bodies = message.bodies('text/html') img_links = [] video_links = [] for content_type, body in html_bodies: decoded_body = body.decode() img_links.extend(self.find_image_links(decoded_body)) video_links.extend(self.find_video_links(decoded_body)) if hasattr(message, "attachments") and message.attachments: post.attachments = [] for attachment in message.attachments: post.attachments.append(db.Blob(attachment[1].decode())) plaintext_bodies = message.bodies('text/plain') allBodies = ''; for body in plaintext_bodies: allBodies = allBodies + body[1].decode() if hasattr(message, "subject"): subject, encoding = decode_header(message.subject)[0] post.caption = unicode(subject) post.author = message.sender post.content = allBodies post.images = img_links post.videos = video_links post.source = "email" post.put()