'Parse an RFC 2822 addr-spec.'

def getaddrspec(self):

    aslist = []
    self.gotonext()
    while (self.pos < len(self.field)):
        preserve_ws = True
        if (self.field[self.pos] == '.'):
            if (aslist and (not aslist[(-1)].strip())):
                aslist.pop()
            aslist.append('.')
            self.pos += 1
            preserve_ws = False
        elif (self.field[self.pos] == '"'):
            aslist.append(('"%s"' % quote(self.getquote())))
        elif (self.field[self.pos] in self.atomends):
            if (aslist and (not aslist[(-1)].strip())):
                aslist.pop()
            break
        else:
            aslist.append(self.getatom())
        ws = self.gotonext()
        if (preserve_ws and ws):
            aslist.append(ws)
    if ((self.pos >= len(self.field)) or (self.field[self.pos] != '@')):
        return EMPTYSTRING.join(aslist)
    aslist.append('@')
    self.pos += 1
    self.gotonext()
    return (EMPTYSTRING.join(aslist) + self.getdomain())
