0
는 :파이썬 정규식이 형식에서 바로 이메일 주소를 추출하려고
John Smith <[email protected]>
나는 다음의 모두를 시도하고 동일한 오류가 발생합니다 :
코드의IndexError: list index out of range
email_address = re.findall('(?<=\<)\[email protected][a-zA-Z]+\.[a-z]+(?=\>)', sender)[0]
email_address = re.findall('<([^>])>', sender)[0]
나머지 :
import webapp2
import logging
from google.appengine.ext.webapp import mail_handlers
from google.appengine.api import mail
import os
from main import WorkRequest
import re
class IncomingMailHandler(mail_handlers.InboundMailHandler):
def receive(self, message):
(encoding, payload) = list(message.bodies(content_type='text/plain'))[0]
body_text = payload.decode()
logging.info('Received email message from %s, subject "%s": %s' %
(message.sender, message.subject, body_text))
logging.info (message.sender)
logging.info(message.subject)
logging.info(body_text)
sender = str(message.sender)
email_address = re.findall('<([^>])>', sender)[0]
wr = WorkRequest()
wr.email = email_address
wr.userId = None
wr.title = message.subject
wr.content = body_text
wr.status = "OPEN"
wr.submission_type = "EMAIL"
wr.assigned_to = "UNASSIGNED"
wr.put()
application = webapp2.WSGIApplication([('/_ah/mail/.+', IncomingMailHandler)],debug=True)
아무도 도와 줄 수 있습니까? Python과 함께 Google App Engine을 사용하고 있습니다. 내 경우 첫 정규 표현식에서
당신은'인쇄 (보낸 사람) '할 당신의 질문에 출력을 추가 할 수 있습니까? – hansaplast
정규식이 잘 보입니다. "John Smith <[email protected]>" – hansaplast
에서 jsmith @ email.com을 가져옵니다. 첫 번째 정규식이 나에게 적합합니다 (발신자가'John Smith <[email protected]> >'). 닫는 대괄호 뒤에 더하기 기호를 추가하면 두 번째 방법이 작동합니다. –