Пример #1
0
    def __init__(self, raw=None, decoded_name=None, address=None):
        super(EmailAddress, self).__init__()

        if not raw is None:
            assert decoded_name is None and address is None

            if isinstance(raw, tuple):
                raw_str = formataddr(raw)
            elif isinstance(raw, str):
                raw_str = raw
            else:
                raise Exception('')

            self._raw = raw_str
            (encoded_name, address) = getaddresses([raw_str])[0]
            self._name_chunk = EmailHeaderChunk(raw=encoded_name)
            self._address = address
        else:
            assert not address is None
            if decoded_name is None:
                decoded_name = ''

            self._name_chunk = EmailHeaderChunk(decoded=u'')
            self._name_chunk.text = decoded_name
            self._address = address
Пример #2
0
    def __init__(self, name, raw):
        super(EmailMessageHeaderProxy, self).__init__()
        assert isinstance(raw, str)
        assert isinstance(name, str)

        self._name = name
        self._header_chunk = EmailHeaderChunk(raw=raw)
Пример #3
0
class EmailAddress(NotifyChanged):
    def __init__(self, raw=None, decoded_name=None, address=None):
        super(EmailAddress, self).__init__()

        if not raw is None:
            assert decoded_name is None and address is None

            if isinstance(raw, tuple):
                raw_str = formataddr(raw)
            elif isinstance(raw, str):
                raw_str = raw
            else:
                raise Exception('')

            self._raw = raw_str
            (encoded_name, address) = getaddresses([raw_str])[0]
            self._name_chunk = EmailHeaderChunk(raw=encoded_name)
            self._address = address
        else:
            assert not address is None
            if decoded_name is None:
                decoded_name = ''

            self._name_chunk = EmailHeaderChunk(decoded=u'')
            self._name_chunk.text = decoded_name
            self._address = address

    @property
    def name(self):
        return self._name_chunk.text

    @name.setter
    def name(self, value):
        if isinstance(value, unicode):
            self._name_chunk.text = value
        else:
            self._name_chunk.text = unicode(value.decode('utf-8'))

        self.on_changed()

    @property
    def address(self):
        return self._address

    @address.setter
    def address(self, value):
        self._address = value

        self.on_changed()

    def format(self):
        return formataddr((self._name_chunk.get_raw(), self.address))

    def __repr__(self):
        if self.name:
            return '"{0}" <{1}>'.encode('utf-8').format(self.name.encode('utf-8'),
                                                        unicode(self.address.encode('utf-8')))
        else:
            return '<{0}>'.encode('utf-8').format(unicode(self.address.encode('utf-8')))
Пример #4
0
class EmailMessageHeaderProxy(NotifyChanged):
    def __init__(self, name, raw):
        super(EmailMessageHeaderProxy, self).__init__()
        assert isinstance(raw, str)
        assert isinstance(name, str)

        self._name = name
        self._header_chunk = EmailHeaderChunk(raw=raw)

    @property
    def name(self):
        return self._name

    @property
    def raw(self):
        return self._header_chunk.get_raw()

    @raw.setter
    def raw(self, value):
        if self.raw == value:
            return

        self._header_chunk.set_raw(value)
        self.on_changed()

    @property
    def text(self):
        return self._header_chunk.text

    def set_text(self, value):
        if self.text == value:
            return

        self._header_chunk.text = value
        self.on_changed()

    @text.setter
    def text(self, value):
        if value is self.text:
            return

        self._header_chunk.text = value
        self.on_changed()