def get(self, emailid): logging.info('downloading zip file for email: ' + emailid) emailid = str(emailid).strip() if emailid and emailid != '': email = Email.get(emailid) if email: logging.info('email attachments count: ' + str(len(email.attachments))) # create the zip stream zipstream=StringIO() zfile = zipfile.ZipFile(zipstream,"w") for attachment in email.attachments: file_attachment = Files.get(attachment) if file_attachment: zfile = self.addFile(zfile, file_attachment.name, file_attachment.content) zfile.close() zipstream.seek(0) self.response.headers['Content-Type'] = 'application/zip' self.response.headers['Content-Disposition'] = 'attachment; filename="attachments.zip"' #self.response.out.write(zfile.content) while True: buf = zipstream.read(2048) if buf == "": break self.response.out.write(buf)
def get(self, email_id): logging.info('MailDetailsPage processing') logging.info('email_id: ' + email_id) email_id = str(email_id).strip() if email_id and email_id != '': logging.info('valid email_id') user = users.get_current_user() email = Email.get(email_id) if email: logging.info('attachments') email._files = None if email.attachments: if len(email.attachments) > 0: email._files = [] for i in range(len(email.attachments)): file = Files.get(email.attachments[i]) email._files.append(file) logging.info('file.name : ' + file.name) template_values = { 'home_url': '/home', 'email_url': '/mail', 'nickname': user.nickname(), 'logout_url': users.create_logout_url("/"), 'email': email } self.template_values = template_values self.render('mail_details.html')
def get(self, email_id): logging.info('MailDetailsPage processing') logging.info('email_id: ' + email_id) email_id = str(email_id).strip() if email_id and email_id != '': logging.info('valid email_id') user = users.get_current_user() email = Email.get(email_id) if email: logging.info('attachments') email._files = None if email.attachments: if len(email.attachments) > 0: email._files = [] for i in range(len(email.attachments)): file = Files.get(email.attachments[i]) email._files.append(file) logging.info('file.name : ' + file.name) template_values = { 'home_url' : '/home', 'email_url' : '/mail', 'nickname' : user.nickname(), 'logout_url': users.create_logout_url("/"), 'email': email } self.template_values = template_values self.render('mail_details.html')
def get(self, emailid): logging.info('downloading zip file for email: ' + emailid) emailid = str(emailid).strip() if emailid and emailid != '': email = Email.get(emailid) if email: logging.info('email attachments count: ' + str(len(email.attachments))) # create the zip stream zipstream = StringIO() zfile = zipfile.ZipFile(zipstream, "w") for attachment in email.attachments: file_attachment = Files.get(attachment) if file_attachment: zfile = self.addFile(zfile, file_attachment.name, file_attachment.content) zfile.close() zipstream.seek(0) self.response.headers['Content-Type'] = 'application/zip' self.response.headers[ 'Content-Disposition'] = 'attachment; filename="attachments.zip"' #self.response.out.write(zfile.content) while True: buf = zipstream.read(2048) if buf == "": break self.response.out.write(buf)
def get(self, fileid): logging.info('downloading: ' + fileid) fileid = str(fileid).strip() if fileid and fileid != '': file = Files.get(fileid) if file: self.response.headers['Content-Type'] = 'application/octet-stream' self.response.headers['Content-Disposition'] = 'attachment; filename="' + file.name + '"' self.response.out.write(file.content)
def get(self, fileid): logging.info('downloading: ' + fileid) fileid = str(fileid).strip() if fileid and fileid != '': file = Files.get(fileid) if file: self.response.headers[ 'Content-Type'] = 'application/octet-stream' self.response.headers[ 'Content-Disposition'] = 'attachment; filename="' + file.name + '"' self.response.out.write(file.content)
def receive(self, mail_message): logging.info("Received a message from: " + str(mail_message.sender)) to_email_parsed = str(mail_message.to) to_email_parsed = parse_email(to_email_parsed) logging.info("to email trimmed: " + to_email_parsed) user = check_user_registered_by_email(to_email_parsed) html_body = '' plain_body = '' bodies = mail_message.bodies() for content_type, body in bodies: if body.encoding == '8bit': body.encoding = '7bit' #test for html content if content_type == "text/html": #parse html result html_body += body.decode() logging.info('body text/html') if content_type == "text/plain": plain_body += body.decode() logging.info('body text/plain') from_email_parsed = mail_message.sender from_email_parsed = parse_email(from_email_parsed) if from_email_parsed == '*****@*****.**': self.check_if_confirmation_mail(plain_body, html_body) if not user: logging.info('check_user_registered_by_email is FALSE; from : ' + from_email_parsed) else: logging.info('check_user_registered_by_email is TRUE') params = {} if hasattr(mail_message, 'sender'): params['sender'] = mail_message.sender if hasattr(mail_message, 'to'): params['to'] = mail_message.to if hasattr(mail_message, 'cc'): params['cc'] = mail_message.cc if hasattr(mail_message, 'bcc'): params['bcc'] = mail_message.bcc if hasattr(mail_message, 'reply_to'): params['reply_to'] = mail_message.reply_to if hasattr(mail_message, 'subject'): params['subject'] = mail_message.subject if hasattr(mail_message, 'body'): params['body'] = plain_body if hasattr(mail_message, 'html'): params['html'] = html_body params['user'] = user attachments = [] if hasattr(mail_message, 'attachments'): for (name, content) in mail_message.attachments: logging.info('new attachment name : ' + name) try: new_file = Files(name=name, content=db.Blob(content.decode())) attachments.append(new_file) #new_file.put() #attachments.append(new_file.key()) except: logging.info('decoding content failed') #if len(attachments) <> 0: #params['attachments'] = attachments new_email = Email(**params) #try: #new_email.put() #except: #logging.info('html_body: ' + html_body) #logging.info('plain_body: ' + plain_body) mem_key = datetime.datetime.now() mem_key = str(mem_key.year) + str(mem_key.month) + str( mem_key.day) + str(mem_key.hour) + str(mem_key.minute) + str( mem_key.second) + str(mem_key.microsecond) memcache.add(key=mem_key, value={ 'email': new_email, 'files': attachments }) taskqueue.add(url='/task_put_email', params={'mem_key': mem_key}) logging.info('new email mem_key : ' + str(mem_key))