Parse an RFC 2822 addr-spec.
(self)
| 363 | return adlist |
| 364 | |
| 365 | def getaddrspec(self): |
| 366 | """Parse an RFC 2822 addr-spec.""" |
| 367 | aslist = [] |
| 368 | |
| 369 | self.gotonext() |
| 370 | while self.pos < len(self.field): |
| 371 | preserve_ws = True |
| 372 | if self.field[self.pos] == '.': |
| 373 | if aslist and not aslist[-1].strip(): |
| 374 | aslist.pop() |
| 375 | aslist.append('.') |
| 376 | self.pos += 1 |
| 377 | preserve_ws = False |
| 378 | elif self.field[self.pos] == '"': |
| 379 | aslist.append('"%s"' % quote(self.getquote())) |
| 380 | elif self.field[self.pos] in self.atomends: |
| 381 | if aslist and not aslist[-1].strip(): |
| 382 | aslist.pop() |
| 383 | break |
| 384 | else: |
| 385 | aslist.append(self.getatom()) |
| 386 | ws = self.gotonext() |
| 387 | if preserve_ws and ws: |
| 388 | aslist.append(ws) |
| 389 | |
| 390 | if self.pos >= len(self.field) or self.field[self.pos] != '@': |
| 391 | return EMPTYSTRING.join(aslist) |
| 392 | |
| 393 | aslist.append('@') |
| 394 | self.pos += 1 |
| 395 | self.gotonext() |
| 396 | domain = self.getdomain() |
| 397 | if not domain: |
| 398 | # Invalid domain, return an empty address instead of returning a |
| 399 | # local part to denote failed parsing. |
| 400 | return EMPTYSTRING |
| 401 | return EMPTYSTRING.join(aslist) + domain |
| 402 | |
| 403 | def getdomain(self): |
| 404 | """Get the complete domain name from an address.""" |