예제 #1
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()
예제 #2
0
def ASK(message, host = None, addr = None):
    if addr.startswith('reply-'):
        return
    parts = get_parts(message)
    from_address = message.From
    subject = message['Subject']#why lamson does not give it normally?
    if addr == 'ask':
        mail.process_emailed_question(from_address, subject, parts)
    else:
        if askbot_settings.GROUP_EMAIL_ADDRESSES_ENABLED == False:
            return
        try:
            group_tag = Tag.group_tags.get(
                deleted = False,
                name__iexact = addr
            )
            mail.process_emailed_question(
                from_address, subject, parts, tags = [group_tag.name, ]
            )
        except Tag.DoesNotExist:
            #do nothing because this handler will match all emails
            return
        except Tag.MultipleObjectsReturned:
            return
예제 #3
0
def ASK(message, host = None):
    body = get_body(message)
    attachments = get_attachments(message)
    from_address = message.From
    subject = message['Subject']#why lamson does not give it normally?
    mail.process_emailed_question(from_address, subject, body, attachments)