def get(self): user = users.get_current_user() if user is None: self.abort(401) client_id = get_notification_client_id(user) token = channel.create_channel(client_id, 60) self.response.headers['Content-Type'] = 'application/json' self.response.write(json.dumps({'token': token}))
def receive(self, mail_message): email_pattern = re.compile(r'([\w\-\.]+@(\w[\w\-]+\.)+[\w\-]+)') match = email_pattern.findall(mail_message.sender) email_addr = match[0][0] if match else '' try: user = users.User(email_addr) user = self._reload_user(user) except users.UserNotFoundError: return self.error(403) title = mail_message.subject content = '' for content_t, body in mail_message.bodies('text/plain'): content += body.decode() attachments = getattr(mail_message, 'attachments', None) self._create_note(user, title, content, attachments) channel.send_message(get_notification_client_id(user), json.dumps("A new note was created! " "Refresh the page to see it."))
def receive(self, mail_message): email_pattern = re.compile(r'([\w\-\.]+@(\w[\w\-]+\.)+[\w\-]+)') match = email_pattern.findall(mail_message.sender) email_addr = match[0][0] if match else '' try: user = users.User(email_addr) user = self._reload_user(user) except users.UserNotFoundError: return self.error(403) title = mail_message.subject content = '' for content_t, body in mail_message.bodies('text/plain'): content += body.decode() attachments = getattr(mail_message, 'attachments', None) self._create_note(user, title, content, attachments) channel.send_message( get_notification_client_id(user), json.dumps("A new note was created! " "Refresh the page to see it."))