Author sdgathman
Recipients barry, melicertes, sdgathman
Date 2008-01-10.16:34:08
SpamBayes Score 0.385614
Marked as misclassified No
Message-id <1199982849.83.0.98101676998.issue1025395@psf.upfronthosting.co.za>
In-reply-to
Content
# A quick and very dirty fix for common broken cases, with test cases.

import rfc822

def parseaddr(t):
  """Split email into Fullname and address.

  >>> parseaddr('user@example.com')
  ('', 'user@example.com')
  >>> parseaddr('"Full Name" <foo@example.com>')
  ('Full Name', 'foo@example.com')
  >>> parseaddr('spam@viagra.com <foo@example.com>')
  ('spam@viagra.com', 'foo@example.com')
  >>> parseaddr('"God" <@hop1.org,@hop2.net:jeff@spec.org>')
  ('God', 'jeff@spec.org')
  """
  #return email.Utils.parseaddr(t)
  res = rfc822.parseaddr(t)
  # dirty fix for some broken cases
  if not res[0]:
    pos = t.find('<')
    if pos > 0 and t[-1] == '>':
      addrspec = t[pos+1:-1]
      pos1 = addrspec.rfind(':')
      if pos1 > 0:
        addrspec = addrspec[pos1+1:]
      return rfc822.parseaddr('"%s" <%s>' % (t[:pos].strip(),addrspec))
  if not res[1]:
    pos = t.find('<')
    if pos > 0 and t[-1] == '>':
      addrspec = t[pos+1:-1]
      pos1 = addrspec.rfind(':')
      if pos1 > 0:
        addrspec = addrspec[pos1+1:]
      return rfc822.parseaddr('%s<%s>' % (t[:pos].strip(),addrspec))
  return res
History
Date User Action Args
2008-01-10 16:34:10sdgathmansetspambayes_score: 0.385614 -> 0.385614
recipients: + sdgathman, barry, melicertes
2008-01-10 16:34:09sdgathmansetspambayes_score: 0.385614 -> 0.385614
messageid: <1199982849.83.0.98101676998.issue1025395@psf.upfronthosting.co.za>
2008-01-10 16:34:08sdgathmanlinkissue1025395 messages
2008-01-10 16:34:08sdgathmancreate