Exemple #1
0
	def post(self):
		file_info = self.get_file_infos()[0]
		self.response.headers['Content-Type'] = "application/json"
		year = self.request.get('year')
		month = self.request.get('month')
		day = self.request.get('day')
		date = datetime.datetime(int(year), int(month), int(day))

		if file_info.content_type.lower() not in ('image/jpeg', 'image/jpg', 'image/png', 'image/gif', 'image/bmp'):
			return self.response.write(json.dumps({"status" : "error", "message" : "Unsupported content type: " + file_info.content_type}))

		bytes = filestore.read(file_info.gs_object_name)
		existing_images = [u.filename for u in UserImage.query(UserImage.date == date).fetch()]

		filename = UserImage.create_image_name(file_info.filename, date, existing_images)
		img = UserImage()
		img.import_image(filename, file_info.filename, bytes, date)
		img.put()
		filestore.delete(file_info.gs_object_name)
		#If there's a post here we should add the image...
		post = Post.query(Post.date == date).get()
		if post:
			post.has_images = True
			if post.images is None:
				post.images = []
			post.images.append(filename)
			post.put()

		self.response.write(json.dumps({"status" : "ok", "filename" : filename}))
Exemple #2
0
	def process_attachments(self, mail_message, post):
		attachments = []

		try:
			attachments = mail_message.attachments
		except exceptions.AttributeError:
			pass #No attachments, then the attribute doesn't even exist :/

		if attachments:
			logging.info('Received %s attachment(s)' % len(attachments))
		
		for original_filename, encoded_payload in attachments:
			logging.info('Processing attachment: %s' % original_filename)

			if re.search('\\.(jpe?g|png|bmp|gif)$', original_filename.lower()):
				if post.images is None:
					post.images = []

				bytes = encoded_payload.payload
				if encoded_payload.encoding:
					bytes = bytes.decode(encoded_payload.encoding)
				
				post.has_images = True
				user_image = UserImage()
				img_name = UserImage.create_image_name(original_filename, post.date, post.images)
				user_image.import_image(img_name, original_filename, bytes, post.date)
				post.images.append(img_name)
				user_image.put()

			else:
				logging.warning('Received unsupported attachment, %s' % original_filename)
Exemple #3
0
	def post(self):
		file_info = self.get_file_infos()[0]
		self.response.headers['Content-Type'] = "application/json"
		year = self.request.get('year')
		month = self.request.get('month')
		day = self.request.get('day')
		date = datetime.datetime(int(year), int(month), int(day))

		if file_info.content_type.lower() not in ('image/jpeg', 'image/jpg', 'image/png', 'image/gif', 'image/bmp'):
			return self.response.write(json.dumps({"status" : "error", "message" : "Unsupported content type: " + file_info.content_type}))

		bytes = filestore.read(file_info.gs_object_name)
		existing_images = [u.filename for u in UserImage.query(UserImage.date == date).fetch()]

		filename = UserImage.create_image_name(file_info.filename, date, existing_images)
		img = UserImage()
		img.import_image(filename, file_info.filename, bytes, date, None)
		img.put()
		filestore.delete(file_info.gs_object_name)
		#If there's a post here we should add the image...
		post = Post.query(Post.date == date).get()
		if post:
			post.has_images = True
			if post.images is None:
				post.images = []
			post.images.append(filename)
			post.put()

		self.response.write(json.dumps({"status" : "ok", "filename" : filename}))
Exemple #4
0
    def process_attachments(self, mail_message, post):
        attachments = []

        try:
            attachments = mail_message.attachments
        except exceptions.AttributeError:
            pass  #No attachments, then the attribute doesn't even exist :/

        if attachments:
            logging.info('Received %s attachment(s)' % len(attachments))

        for attachment in attachments:

            original_filename = attachment.filename
            encoded_payload = attachment.payload
            content_id = attachment.content_id
            if content_id:
                content_id = content_id.replace('<', '').replace(
                    '>', ''
                )  # Don't want these around the id, messes with our tag handling
            logging.info('Processing attachment: %s' % original_filename)

            if re.search('\\.(jpe?g|png|bmp|gif)$', original_filename.lower()):
                if post.images is None:
                    post.images = []

                bytes = encoded_payload.payload
                if encoded_payload.encoding:
                    bytes = bytes.decode(encoded_payload.encoding)

                post.has_images = True
                user_image = UserImage()
                img_name = UserImage.create_image_name(original_filename,
                                                       post.date, post.images)
                user_image.import_image(img_name, original_filename, bytes,
                                        post.date, content_id)
                post.images.append(img_name)

                user_image.is_inline = False
                if content_id:
                    placeholder = '$IMG:' + content_id
                    if placeholder in post.text:
                        user_image.is_inline = True
                        #Ok, lets put in a filename instead of the content_id
                        post.text = post.text.replace(placeholder,
                                                      '$IMG:' + img_name)

                user_image.put()

            else:
                logging.warning('Received unsupported attachment, %s' %
                                original_filename)
Exemple #5
0
	def process_attachments(self, mail_message, post):
		attachments = []

		try:
			attachments = mail_message.attachments
		except exceptions.AttributeError:
			pass #No attachments, then the attribute doesn't even exist :/

		if attachments:
			logging.info('Received %s attachment(s)' % len(attachments))
		
		for attachment in attachments:
			
 			original_filename = attachment.filename
 			encoded_payload = attachment.payload
 			content_id = attachment.content_id
 			if content_id:
 				content_id = content_id.replace('<', '').replace('>', '') # Don't want these around the id, messes with our tag handling
			logging.info('Processing attachment: %s' % original_filename)

			if re.search('\\.(jpe?g|png|bmp|gif)$', original_filename.lower()):
				if post.images is None:
					post.images = []

				bytes = encoded_payload.payload
				if encoded_payload.encoding:
					bytes = bytes.decode(encoded_payload.encoding)
				
				post.has_images = True
				user_image = UserImage()
				img_name = UserImage.create_image_name(original_filename, post.date, post.images)
				user_image.import_image(img_name, original_filename, bytes, post.date, content_id)
				post.images.append(img_name)
				
				user_image.is_inline = False
				if content_id:
					placeholder = '$IMG:' + content_id
					if placeholder in post.text:
						user_image.is_inline = True
						#Ok, lets put in a filename instead of the content_id
						post.text = post.text.replace(placeholder, '$IMG:' + img_name)
				
				user_image.put()

			else:
				logging.warning('Received unsupported attachment, %s' % original_filename)