コード例 #1
0
    def clean_sender(self):
        """Cleans the :attr:`~askbot.forms.AskByEmail.sender` attribute

        If the field is valid, cleaned data will receive value ``email``
        """
        raw_email = self.cleaned_data['sender']
        email = extract_first_email_address(raw_email)
        if email is None:
            raise forms.ValidationError('Could not extract email address')
        self.cleaned_data['email'] = email
        return self.cleaned_data['sender']
コード例 #2
0
ファイル: forms.py プロジェクト: oloed/askbot-devel
    def clean_sender(self):
        """Cleans the :attr:`~askbot.forms.AskByEmail.sender` attribute

        If the field is valid, cleaned data will receive value ``email``
        """
        raw_email = self.cleaned_data['sender']
        email = extract_first_email_address(raw_email)
        if email is None:
            raise forms.ValidationError('Could not extract email address')
        self.cleaned_data['email'] = email
        return self.cleaned_data['sender']
コード例 #3
0
    def handle_noargs(self, **options):
        """reads all emails from the INBOX of
        imap server and posts questions based on
        those emails. Badly formatted questions are
        bounced, as well as emails from unknown users

        all messages are deleted thereafter
        """
        if not askbot_settings.ALLOW_ASKING_BY_EMAIL:
            raise CommandError('Asking by email is not enabled')

        #open imap server and select the inbox
        if django_settings.IMAP_USE_TLS:
            imap_getter = imaplib.IMAP4_SSL
        else:
            imap_getter = imaplib.IMAP4
        imap = imap_getter(django_settings.IMAP_HOST,
                           django_settings.IMAP_PORT)
        imap.login(django_settings.IMAP_HOST_USER,
                   django_settings.IMAP_HOST_PASSWORD)
        imap.select('INBOX')

        #get message ids
        junk, ids = imap.search(None, 'ALL')

        if len(ids[0].strip()) == 0:
            #with empty inbox - close and exit
            imap.close()
            imap.logout()
            return

        #for each id - read a message, parse it and post a question
        for msg_id in ids[0].split(' '):
            junk, data = imap.fetch(msg_id, '(RFC822)')
            #message_body = data[0][1]
            msg = email.message_from_string(data[0][1])
            imap.store(msg_id, '+FLAGS', '\\Deleted')
            try:
                (sender, subject, body) = parse_message(msg)
            except CannotParseEmail:
                continue

            sender = mail.extract_first_email_address(sender)
            mail.process_emailed_question(sender, subject, body)

        imap.expunge()
        imap.close()
        imap.logout()
コード例 #4
0
                (sender, subject, body) = parse_message(msg)
            except CannotParseEmail, e:
                continue
            data = {"sender": sender, "subject": subject, "body_text": body}
            form = AskByEmailForm(data)
            print data
            if form.is_valid():
                email_address = form.cleaned_data["email"]
                try:
                    user = models.User.objects.get(email__iexact=email_address)
                except models.User.DoesNotExist:
                    bounce_email(email_address, subject, reason="unknown_user")
                except models.User.MultipleObjectsReturned:
                    bounce_email(email_address, subject, reason="problem_posting")

                tagnames = form.cleaned_data["tagnames"]
                title = form.cleaned_data["title"]
                body_text = form.cleaned_data["body_text"]

                try:
                    user.post_question(title=title, tags=tagnames, body_text=body_text)
                except exceptions.PermissionDenied, e:
                    bounce_email(email_address, subject, reason="permission_denied", body_text=unicode(e))
            else:
                email_address = mail.extract_first_email_address(sender)
                if email_address:
                    bounce_email(email_address, subject, reason="problem_posting")
        imap.expunge()
        imap.close()
        imap.logout()
コード例 #5
0
                    user = models.User.objects.get(email__iexact=email_address)
                except models.User.DoesNotExist:
                    bounce_email(email_address, subject, reason='unknown_user')
                except models.User.MultipleObjectsReturned:
                    bounce_email(email_address,
                                 subject,
                                 reason='problem_posting')

                tagnames = form.cleaned_data['tagnames']
                title = form.cleaned_data['title']
                body_text = form.cleaned_data['body_text']

                try:
                    user.post_question(title=title,
                                       tags=tagnames,
                                       body_text=body_text)
                except exceptions.PermissionDenied, e:
                    bounce_email(email_address,
                                 subject,
                                 reason='permission_denied',
                                 body_text=unicode(e))
            else:
                email_address = mail.extract_first_email_address(sender)
                if email_address:
                    bounce_email(email_address,
                                 subject,
                                 reason='problem_posting')
        imap.expunge()
        imap.close()
        imap.logout()