def ASK(message, host = None, addr = None): """lamson handler for asking by email, to the forum in general and to a specific group""" #we need to exclude some other emails by prefix if addr.startswith('reply-'): return if addr.startswith('welcome-'): return parts = get_parts(message) from_address = message.From #why lamson does not give it normally? subject = message['Subject'].strip('\n\t ') body_text, stored_files, unused = mail.process_parts(parts) if addr == 'ask': mail.process_emailed_question( from_address, subject, body_text, stored_files ) else: #this is the Ask the group branch if askbot_settings.GROUP_EMAIL_ADDRESSES_ENABLED == False: return try: group = Group.objects.get(name__iexact=addr) mail.process_emailed_question( from_address, subject, body_text, stored_files, group_id = group.id ) except Group.DoesNotExist: #do nothing because this handler will match all emails return except Tag.MultipleObjectsReturned: return
def ASK(message, host=None, addr=None): """lamson handler for asking by email, to the forum in general and to a specific group""" #we need to exclude some other emails by prefix if addr.startswith('reply-'): return if addr.startswith('welcome-'): return parts = get_parts(message) from_address = message.From #why lamson does not give it normally? subject = message['Subject'].strip('\n\t ') body_text, stored_files, unused = mail.process_parts(parts) if addr == 'ask': mail.process_emailed_question(from_address, subject, body_text, stored_files) 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, body_text, stored_files, tags=[ group_tag.name, ]) except Tag.DoesNotExist: #do nothing because this handler will match all emails return except Tag.MultipleObjectsReturned: return
def ASK(message, host=None, addr=None): """lamson handler for asking by email, to the forum in general and to a specific group""" # we need to exclude some other emails by prefix if addr.startswith("reply-"): return if addr.startswith("welcome-"): return parts = get_parts(message) from_address = message.From # why lamson does not give it normally? subject = message["Subject"].strip("\n\t ") body_text, stored_files, unused = mail.process_parts(parts) if addr == "ask": mail.process_emailed_question(from_address, subject, body_text, stored_files) 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, body_text, stored_files, tags=[group_tag.name]) except Tag.DoesNotExist: # do nothing because this handler will match all emails return except Tag.MultipleObjectsReturned: return
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()
def ASK(message, host = None, addr = None): """lamson handler for asking by email, to the forum in general and to a specific group""" #we need to exclude some other emails by prefix if addr.startswith('reply-'): return if addr.startswith('welcome-'): return parts = get_parts(message) from_address = message.From if DEBUG_EMAIL: sys.stderr.write( (u'Received email from %s\n' % from_address).encode('utf-8') ) #why lamson does not give it normally? subject = message['Subject'].strip('\n\t ') body_text, stored_files, unused = mail.process_parts(parts) if addr == 'ask': mail.process_emailed_question( from_address, subject, body_text, stored_files ) else: #this is the Ask the group branch if askbot_settings.GROUP_EMAIL_ADDRESSES_ENABLED == False: return try: group = Group.objects.get(name__iexact=addr) mail.process_emailed_question( from_address, subject, body_text, stored_files, group_id = group.id ) except Group.DoesNotExist: #do nothing because this handler will match all emails return except Tag.MultipleObjectsReturned: return