def create_articles(self, emails):
        """Attempts to post new articles based on parsed email messages"""

        created = []
        site = Site.objects.get_current()

        ack = self.config.get('acknowledge', False)
        autopost = self.config.get('autopost', False)

        # make sure we have a valid default markup
        markup = self.config.get('markup', MARKUP_HTML)
        if markup not in (MARKUP_HTML, MARKUP_MARKDOWN, MARKUP_REST, MARKUP_TEXTILE):
            markup = MARKUP_HTML

        for num, email in emails.iteritems():

            name, sender = parseaddr(email['From'])

            try:
                author = User.objects.get(email=sender, is_active=True)
            except User.DoesNotExist:
                # unauthorized sender
                self.log('Not processing message from unauthorized sender.', 0)
                continue

            # get the attributes for the article
            title = email.get('Subject', '--- article from email ---')

            content = self.get_email_content(email)
            try:
                # try to grab the timestamp from the email message
                publish_date = datetime.fromtimestamp(time.mktime(parsedate(email['Date'])))
            except StandardError, err:
                self.log("An error occurred when I tried to convert the email's timestamp into a datetime object: %s" % (err,))
                publish_date = datetime.now()

            # post the article
            article = Article(
                author=author,
                title=title,
                content=content,
                markup=markup,
                publish_date=publish_date,
                is_active=autopost,
            )

            try:
                article.save()
                self.log('Article created.')
            except StandardError, err:
                # log it and move on to the next message
                self.log('Error creating article: %s' % (err,), 0)
                continue
            else:

                # handle attachments
                if email.is_multipart():
                    files = [pl for pl in email.get_payload() if pl.get_filename() is not None]
                    for att in files:
                        obj = Attachment(
                            article=article,
                            caption=att.get_filename(),
                        )
                        obj.attachment.save(obj.caption, ChunkyString(att.get_payload()))
                        obj.save()

                created.append(num)

            if ack:
                # notify the user when the article is posted
                subject = u'%s: %s' % (_("Article Posted"), title)
                message = _("""Your email (%(title)s) has been posted as an article on %(site_name)s.

    http://%(domain)s%(article_url)s""") % {
                    'title': title,
                    'site_name': site.name,
                    'domain': site.domain,
                    'article_url': article.get_absolute_url(),
                }

                self.log('Sending acknowledgment email to %s' - (author.email,))
                author.email_user(subject, message)

        return created
dataset/ETHPy150Open codekoala/django-articles/articles/management/commands/check_for_articles_from_email.py/Command.create_articles/operator `%` -> `-`