Message with Maildir-specific properties.
| 1606 | |
| 1607 | |
| 1608 | class MaildirMessage(Message): |
| 1609 | """Message with Maildir-specific properties.""" |
| 1610 | |
| 1611 | _type_specific_attributes = ['_subdir', '_info', '_date'] |
| 1612 | |
| 1613 | def __init__(self, message=None): |
| 1614 | """Initialize a MaildirMessage instance.""" |
| 1615 | self._subdir = 'new' |
| 1616 | self._info = '' |
| 1617 | self._date = time.time() |
| 1618 | Message.__init__(self, message) |
| 1619 | |
| 1620 | def get_subdir(self): |
| 1621 | """Return 'new' or 'cur'.""" |
| 1622 | return self._subdir |
| 1623 | |
| 1624 | def set_subdir(self, subdir): |
| 1625 | """Set subdir to 'new' or 'cur'.""" |
| 1626 | if subdir == 'new' or subdir == 'cur': |
| 1627 | self._subdir = subdir |
| 1628 | else: |
| 1629 | raise ValueError("subdir must be 'new' or 'cur': %s" % subdir) |
| 1630 | |
| 1631 | def get_flags(self): |
| 1632 | """Return as a string the flags that are set.""" |
| 1633 | if self._info.startswith('2,'): |
| 1634 | return self._info[2:] |
| 1635 | else: |
| 1636 | return '' |
| 1637 | |
| 1638 | def set_flags(self, flags): |
| 1639 | """Set the given flags and unset all others.""" |
| 1640 | self._info = '2,' + ''.join(sorted(flags)) |
| 1641 | |
| 1642 | def add_flag(self, flag): |
| 1643 | """Set the given flag(s) without changing others.""" |
| 1644 | self.set_flags(''.join(set(self.get_flags()) | set(flag))) |
| 1645 | |
| 1646 | def remove_flag(self, flag): |
| 1647 | """Unset the given string flag(s) without changing others.""" |
| 1648 | if self.get_flags(): |
| 1649 | self.set_flags(''.join(set(self.get_flags()) - set(flag))) |
| 1650 | |
| 1651 | def get_date(self): |
| 1652 | """Return delivery date of message, in seconds since the epoch.""" |
| 1653 | return self._date |
| 1654 | |
| 1655 | def set_date(self, date): |
| 1656 | """Set delivery date of message, in seconds since the epoch.""" |
| 1657 | try: |
| 1658 | self._date = float(date) |
| 1659 | except ValueError: |
| 1660 | raise TypeError("can't convert to float: %s" % date) from None |
| 1661 | |
| 1662 | def get_info(self): |
| 1663 | """Get the message's "info" as a string.""" |
| 1664 | return self._info |
| 1665 |
no outgoing calls
no test coverage detected
searching dependent graphs…