Advertisement
etidbury

extract_sender function in um_mail.py

Apr 21st, 2015
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.79 KB | None | 0 0
  1. def extract_sender(value):
  2.  
  3.     value=re.sub('[^@\s.A-Za-z0-9_\-]', '', str(value)) #1. filter out any characters that arent '@',[space],a numerical or alpha numerical character
  4.     emailpos=value.find('@') #2. get the index position of where @ is situated in the filtered value
  5.     spacebeforeemail=value.rfind(' ',0,emailpos) #3. get the index of the space before the email
  6.  
  7.     fe=value[spacebeforeemail:] #4. get the spliced value from the space before the email and the end of the value
  8.     fe=re.sub('[^@.A-Za-z0-9_\-]', '', fe) #5. filter out the random spaces and any other characters that are not acceptable for an email value.
  9.  
  10.     if (len(fe)<4):#5. determine whether the spliced value is an email or not
  11.         result=value
  12.     else: #if not, print out the the unspliced value
  13.         result=fe
  14.  
  15.     return result
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement