Exemplo n.º 1
0
	def delete_post(self, post):
		images = UserImage.query(UserImage.date == post.date).fetch()

		for img in images:
			filestore.delete(img.serving_size_key)
			filestore.delete(img.original_size_key)
			img.key.delete()

		emails = RawMail.query(RawMail.date == post.date).fetch()
		for email in emails:
			email.delete()

		post.key.delete()
		PostCounter.get().decrement(post.date.year, post.date.month)
		
		logging.info('Deleted %s images, %s emails and 1 post from %s' % (len(images), len(emails), post.date.strftime('%Y-%m-%d')))
Exemplo n.º 2
0
	def delete_post(self, post):
		images = UserImage.query(UserImage.date == post.date).fetch()

		for img in images:
			filestore.delete(img.serving_size_key)
			filestore.delete(img.original_size_key)
			img.key.delete()

		emails = RawMail.query(RawMail.date == post.date).fetch()
		for email in emails:
			email.key.delete()

		post.key.delete()
		PostCounter.get().decrement(post.date.year, post.date.month)
		
		logging.info('Deleted %s images, %s emails and 1 post from %s' % (len(images), len(emails), post.date.strftime('%Y-%m-%d')))
Exemplo n.º 3
0
	def receive(self, mail_message):

		try:
			id = self.get_id(mail_message)

			if not id: 
				return
			
			slug = Slug.query(Slug.slug == id).get()

			if not slug:
				log_error('Invalid slug', 'Found no slug for id %s', id)
				return

			body_text, body_html = self.get_bodies(mail_message)

			raw_mail = RawMail(
				subject=mail_message.subject,
				sender=mail_message.sender,
				slug=id,
				date=slug.date,
				text=body_text,
				html=body_html
				)

			raw_mail.put()

			post = Post.query(Post.date == slug.date).get()
			is_new_post = post is None
			if is_new_post:
				post = Post(
					date=slug.date,
					source='email',
					has_images=False
				)

			#Now let's try parsing it into a good post...

			if body_html:
				post_text = strip_html(body_html) #Prefer html because then we don't get linebreak issues
				logging.info('Parsing post from html')
			else:
				post_text = body_text
				logging.info('Parsing post from plain text')

			if not post_text:
				raise Exception('No plain text body in email, html body can\'t be parsed yet!')

			try:
				email_index = post_text.index('post+%s@' % id)
				post_text = post_text[:email_index]
				newline_index = post_text.rstrip().rindex('\n')
				post_text = post_text[:newline_index].strip()
			except:
				logging.info('Failed to remove all crap from post')


			#Strip 'Sent from my iPhone' if it's there. There are probably endless other Sent from
			#we could handle, but hey, I have an iPhone so that's the one I care about...

			post_text = re.sub('\s*Sent from my iPhone\s*$', '', post_text)  
			post_text = post_text.rstrip()
			
			if post.text:
				post.text = post.text + '\r\n\r\n' + Post.seperator + '\r\n\r\n' + post_text
			else:
				post.text = post_text


			self.process_attachments(mail_message, post)

			post.put()

			if is_new_post:
				counter = PostCounter.get()
				counter.increment(post.date.year, post.date.month)
		except:
			log_error('Failed to parse incoming email', traceback.format_exc(6))
Exemplo n.º 4
0
    def receive(self, mail_message):

        try:
            id = self.get_id(mail_message)

            if not id:
                return

            slug = Slug.query(Slug.slug == id).get()

            if not slug:
                log_error('Invalid slug', 'Found no slug for id %s', id)
                return

            body_text, body_html = self.get_bodies(mail_message)

            raw_mail = RawMail(subject=mail_message.subject,
                               sender=mail_message.sender,
                               slug=id,
                               date=slug.date,
                               text=body_text,
                               html=body_html)

            raw_mail.put()

            post = Post.query(Post.date == slug.date).get()
            is_new_post = post is None
            if is_new_post:
                post = Post(date=slug.date, source='email', has_images=False)

            #Now let's try parsing it into a good post...

            if body_html:
                post_text = strip_html(
                    body_html
                )  #Prefer html because then we don't get linebreak issues
                logging.info('Parsing post from html')
            else:
                post_text = body_text
                logging.info('Parsing post from plain text')

            if not post_text:
                raise Exception(
                    'No plain text body in email, html body can\'t be parsed yet!'
                )

            try:
                email_index = post_text.index('post+%s@' % id)
                post_text = post_text[:email_index]
                newline_index = post_text.rstrip().rindex('\n')
                post_text = post_text[:newline_index].strip()
            except:
                logging.info('Failed to remove all crap from post')

            #Strip 'Sent from my iPhone' if it's there. There are probably endless other Sent from
            #we could handle, but hey, I have an iPhone so that's the one I care about...

            post_text = re.sub('\s*Sent from my iPhone\s*$', '', post_text)
            post_text = post_text.rstrip()

            if post.text:
                post.text = post.text + '\r\n\r\n' + Post.seperator + '\r\n\r\n' + post_text
            else:
                post.text = post_text

            self.process_attachments(mail_message, post)

            post.put()

            if is_new_post:
                counter = PostCounter.get()
                counter.increment(post.date.year, post.date.month)
        except:
            log_error('Failed to parse incoming email',
                      traceback.format_exc(6))