def receive(self, mail_message):
		try:
			action = email.utils.parseaddr(mail_message.to)[1].split("@")[0]

			if action == "put":
				fr = email.utils.parseaddr(mail_message.sender)[1]

				user = models.Author.getByEmail(fr)

				if user is None or not user.canCreate:
					self.reply_error(mail_message, "User '%s' not authorised to create snippets." % fr)
					return

				title = mail_message.subject
				language = "text"

				if "[" in title:
					spl = title.rsplit("[", 1)
					title = spl[0].strip()
					language = spl[1].strip("]").strip()

				slug = main.slugify(title)

				lang = models.Language.lookup(language)

				if lang is None:
					self.reply_error(mail_message, "Language not recognised.")
					return

				if len(mail_message.attachments) < 1:
					self.reply_error(mail_message, "No files attached!")
					return

				filename = mail_message.attachments[0][0]
				filedata = mail_message.attachments[0][1].decode()

				description = ""
				for contenttype, body in mail_message.bodies('text/plain'):
					description = body.decode()
					break

				sn = models.Snippet(key_name=slug,
					title=title,
					fileName=filename,
					description=description,
					language=lang,
					createdBy=user,
					content=filedata)
				sn.put()

				self.reply_success(mail_message, sn)
		except:
			reply_error(mail_message, "Exception occurred: " + sys.exc_info()[0])
Пример #2
0
 def test_comma_punctuation(self):
     date = "2021-03-09"
     title = "Everything is broken, and it’s okay"
     expected = "content/links/2021-03-09-everything-is-broken-and-its-okay.md"
     output = slugify(date, title)
     self.assertEqual(expected, output)
Пример #3
0
 def test_percent_sign(self):
     date = "2020-10-02"
     title = "Why is 100% reliability the wrong target?"
     expected = "content/links/2020-10-02-why-is-100-reliability-the-wrong-target.md"
     output = slugify(date, title)
     self.assertEqual(expected, output)
Пример #4
0
 def test_em_dash_and_ellipsis(self):
     date = "2020-10-02"
     title = "SLO — From Nothing to… Production"
     expected = "content/links/2020-10-02-slo-from-nothing-to-production.md"
     output = slugify(date, title)
     self.assertEqual(expected, output)
Пример #5
0
 def test_question_mark(self):
     date = "2020-10-02"
     title = "how they test ?"
     expected = "content/links/2020-10-02-how-they-test.md"
     output = slugify(date, title)
     self.assertEqual(expected, output)
Пример #6
0
 def test_single_quote_utf(self):
     date = "2020-10-02"
     title = "Under Deconstruction: The State of Shopify’s Monolith"
     expected = "content/links/2020-10-02-under-deconstruction-the-state-of-shopifys-monolith.md"
     output = slugify(date, title)
     self.assertEqual(expected, output)
Пример #7
0
 def test_single_quote(self):
     date = "2020-10-02"
     title = "It's a title"
     expected = "content/links/2020-10-02-its-a-title.md"
     output = slugify(date, title)
     self.assertEqual(expected, output)
Пример #8
0
 def test_happy_path(self):
     date = "2020-10-02"
     title = "This is a title"
     expected = "content/links/2020-10-02-this-is-a-title.md"
     output = slugify(date, title)
     self.assertEqual(expected, output)
Пример #9
0
 def test_double_quote(self):
     date = "2020-10-02"
     title = "A review of \"How Complex Systems Fail\""
     expected = "cfp/2020-10-02-a-review-of-how-complex-systems-fail.md"
     output = slugify(date, title)
     self.assertEqual(expected, output)