コード例 #1
0
ファイル: encoding_test.py プロジェクト: nylas/flanker
def string_maxlinelen_test():
    """
    If the encoded string is longer then the maximum line length, which is 76,
    by default then it is broken down into lines. But a maximum line length
    value can be provided in the `maxlinelen` parameter.
    """
    eq_("very\n loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong",
        encode_string(None, "very loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"))

    eq_("very loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong",
        encode_string(None, "very loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong", maxlinelen=78))
コード例 #2
0
ファイル: address.py プロジェクト: syrusakbary/flanker
    def full_spec(self):
        """
        Returns an ASCII-compatable encoding of an email address or raises a
        ValueError. Display name and domain parts will be converted to
        ASCII-compatable encoding. The transformed address will be ASCII-only
        and RFC-2822 compliant.

           >>> EmailAddress("Ev K", "*****@*****.**").full_spec()
           'Ev K <*****@*****.**>'
           >>> EmailAddress("Жека", "*****@*****.**").full_spec()
           '=?utf-8?b?0JbQtdC60LA=?= <*****@*****.**>'
        """
        if not is_pure_ascii(self.mailbox):
            raise ValueError(
                'address {} has no ASCII-compatable encoding'.format(
                    self.address.encode('utf-8')))
        if not is_pure_ascii(self.hostname):
            try:
                ace_hostname = idna.encode(self.hostname)
            except idna.IDNAError:
                raise ValueError(
                    'address {} has no ASCII-compatable encoding'.format(
                        self.address.encode('utf-8')))
        else:
            ace_hostname = self.hostname
        if self.display_name:
            ace_display_name = smart_quote(
                encode_string(None,
                              self.display_name,
                              maxlinelen=MAX_ADDRESS_LENGTH))
            return u'{} <{}@{}>'.format(ace_display_name, self.mailbox,
                                        ace_hostname)
        return u'{}@{}'.format(self.mailbox, ace_hostname)
コード例 #3
0
def string_maxlinelen_test():
    """
    If the encoded string is longer then the maximum line length, which is 76,
    by default then it is broken down into lines. But a maximum line length
    value can be provided in the `maxlinelen` parameter.
    """
    eq_(
        "very\n loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong",
        encode_string(
            None,
            "very loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"
        ))

    eq_(
        "very loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong",
        encode_string(
            None,
            "very loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong",
            maxlinelen=78))
コード例 #4
0
def _get_full_spec_without_validation(name, email):
    """
    This function is the same as calling full_spec() on
    a Flanker address.EmailAddress object. This function exists
    because you can't construct a Flanker EmailAddress object with
    an invalid email address.
    """
    if name:
        encoded_name = smart_quote(
            encode_string(None, name, maxlinelen=MAX_ADDRESS_LENGTH))
        return '{0} <{1}>'.format(encoded_name, email)
    return u'{0}'.format(email)
コード例 #5
0
ファイル: message.py プロジェクト: nylas/sync-engine
def _get_full_spec_without_validation(name, email):
    """
    This function is the same as calling full_spec() on
    a Flanker address.EmailAddress object. This function exists
    because you can't construct a Flanker EmailAddress object with
    an invalid email address.
    """
    if name:
        encoded_name = smart_quote(encode_string(
            None, name, maxlinelen=MAX_ADDRESS_LENGTH))
        return '{0} <{1}>'.format(encoded_name, email)
    return u'{0}'.format(email)
コード例 #6
0
ファイル: address.py プロジェクト: hartym/flanker
    def full_spec(self):
        """
        Returns a full spec of an email address. Always in ASCII, RFC-2822
        compliant, safe to be included into MIME:

           >>> EmailAddress("Ev K", "*****@*****.**").full_spec()
           'Ev K <*****@*****.**>'
           >>> EmailAddress("Жека", "*****@*****.**").full_spec()
           '=?utf-8?b?0JbQtdC60LA=?= <*****@*****.**>'
        """
        if self.display_name:
            encoded_display_name = smart_quote(encode_string(
                None, self.display_name, maxlinelen=MAX_ADDRESS_LENGTH))
            return '{0} <{1}>'.format(encoded_display_name, self.address)
        return '{0}'.format(self.address)
コード例 #7
0
    def full_spec(self):
        """
        Returns a full spec of an email address. Always in ASCII, RFC-2822
        compliant, safe to be included into MIME:

           >>> EmailAddress("Ev K", "*****@*****.**").full_spec()
           'Ev K <*****@*****.**>'
           >>> EmailAddress("Жека", "*****@*****.**").full_spec()
           '=?utf-8?b?0JbQtdC60LA=?= <*****@*****.**>'
        """
        if self.display_name:
            encoded_display_name = smart_quote(encode_string(
                None, self.display_name, maxlinelen=MAX_ADDRESS_LENGTH))
            return '{0} <{1}>'.format(encoded_display_name, self.address)
        return u'{0}'.format(self.address)
コード例 #8
0
ファイル: parser.py プロジェクト: AnSavvides/flanker
    def _word_unicode(self):
        "Grammar: word-unicode -> unicode-atom | unicode-qstring"
        start_pos = self.stream.position

        # unicode atom
        uwrd = self.stream.get_token(UNI_ATOM)
        if uwrd and isinstance(uwrd, unicode) and not contains_control_chars(uwrd):
            return uwrd

        # unicode qstr
        uwrd = self.stream.get_token(UNI_QSTR, 'qstr')
        if uwrd and isinstance(uwrd, unicode) and not contains_control_chars(uwrd):
            return u'"{}"'.format(encode_string(None, uwrd))

        # rollback
        self.stream.position = start_pos
        return None
コード例 #9
0
ファイル: address.py プロジェクト: UtahDave/flanker
    def __init__(self, display_name, spec=None):
        if spec is None:
            spec = display_name
            display_name = None

        assert(spec)

        if display_name is None:
            self.display_name = u''
        else:
            self.display_name = encode_string(None, display_name)

        parts = spec.rsplit('@', 1)
        self.mailbox = parts[0]
        self.hostname = parts[1].lower()
        self.address = self.mailbox + "@" + self.hostname
        self.addr_type = self.Type.Email
コード例 #10
0
    def _word_unicode(self):
        "Grammar: word-unicode -> unicode-atom | unicode-qstring"
        start_pos = self.stream.position

        # unicode atom
        uwrd = self.stream.get_token(UNI_ATOM)
        if uwrd and isinstance(uwrd,
                               unicode) and not contains_control_chars(uwrd):
            return uwrd

        # unicode qstr
        uwrd = self.stream.get_token(UNI_QSTR, 'qstr')
        if uwrd and isinstance(uwrd,
                               unicode) and not contains_control_chars(uwrd):
            return u'"{0}"'.format(encode_string(None, uwrd))

        # rollback
        self.stream.position = start_pos
        return None
コード例 #11
0
 def ace_display_name(self):
     return smart_quote(
         encode_string(None,
                       self.display_name,
                       maxlinelen=MAX_ADDRESS_LENGTH))
コード例 #12
0
ファイル: address.py プロジェクト: nylas/flanker
 def ace_display_name(self):
     return encode_string(None, smart_quote(self.display_name),
                          maxlinelen=MAX_ADDRESS_LENGTH)