How to use the imapclient.util.to_bytes function in IMAPClient

To help you get started, we’ve selected a few IMAPClient examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mjs / imapclient / imapclient / imapclient.py View on Github external
def _normalise_capabilites(self, raw_response):
        raw_response = to_bytes(raw_response)
        return tuple(raw_response.upper().split())
github mjs / imapclient / imapclient / imapclient.py View on Github external
def _gen_keys(self, k):
        yield k
        if isinstance(k, binary_type):
            yield to_unicode(k)
        else:
            yield to_bytes(k)
github mjs / imapclient / imapclient / imapclient.py View on Github external
def _normalise_search_criteria(criteria, charset=None):
    if not criteria:
        raise exceptions.InvalidCriteriaError('no criteria specified')
    if not charset:
        charset = 'us-ascii'

    if isinstance(criteria, (text_type, binary_type)):
        return [to_bytes(criteria, charset)]

    out = []
    for item in criteria:
        if isinstance(item, int):
            out.append(str(item).encode('ascii'))
        elif isinstance(item, (datetime, date)):
            out.append(format_criteria_date(item))
        elif isinstance(item, (list, tuple)):
            # Process nested criteria list and wrap in parens.
            inner = _normalise_search_criteria(item)
            inner[0] = b'(' + inner[0]
            inner[-1] = inner[-1] + b')'
            out.extend(inner) # flatten
        else:
            out.append(_quoted.maybe(to_bytes(item, charset)))
    return out
github mjs / imapclient / imapclient / imapclient.py View on Github external
Returns the APPEND response as returned by the server.
        """
        if msg_time:
            time_val = '"%s"' % datetime_to_INTERNALDATE(msg_time)
            if PY3:
                time_val = to_unicode(time_val)
            else:
                time_val = to_bytes(time_val)
        else:
            time_val = None
        return self._command_and_check('append',
                                       self._normalise_folder(folder),
                                       seq_to_parenstr(flags),
                                       time_val,
                                       to_bytes(msg),
                                       unpack=True)
github mjs / imapclient / imapclient / imapclient.py View on Github external
def get_quota_root(self, mailbox):
        """Get the quota roots for a mailbox.

        The IMAP server responds with the quota root and the quotas associated
        so there is usually no need to call `get_quota` after.

        See :rfc:`2087` for more details.

        Return a tuple of MailboxQuotaRoots and list of Quota associated
        """
        quota_root_rep = self._raw_command_untagged(
            b'GETQUOTAROOT', to_bytes(mailbox), uid=False,
            response_name='QUOTAROOT'
        )
        quota_rep = pop_with_default(self._imap.untagged_responses, 'QUOTA', [])
        quota_root_rep = parse_response(quota_root_rep)
        quota_root = MailboxQuotaRoots(
            to_unicode(quota_root_rep[0]),
            [to_unicode(q) for q in quota_root_rep[1:]]
        )
        return quota_root, _parse_quota(quota_rep)
github mjs / imapclient / imapclient / imapclient.py View on Github external
def has_capability(self, capability):
        """Return ``True`` if the IMAP server has the given *capability*.
        """
        # FIXME: this will not detect capabilities that are backwards
        # compatible with the current level. For instance the SORT
        # capabilities may in the future be named SORT2 which is
        # still compatible with the current standard and will not
        # be detected by this method.
        return to_bytes(capability).upper() in self.capabilities()
github mjs / imapclient / imapclient / imapclient.py View on Github external
def join_message_ids(messages):
    """Convert a sequence of messages ids or a single integer message id
    into an id byte string for use with IMAP commands
    """
    if isinstance(messages, (text_type, binary_type, integer_types)):
        messages = (to_bytes(messages),)
    return b','.join(_maybe_int_to_bytes(m) for m in messages)
github mjs / imapclient / imapclient / imapclient.py View on Github external
def _maybe_int_to_bytes(val):
    if isinstance(val, integer_types):
        return str(val).encode('us-ascii') if PY3 else str(val)
    return to_bytes(val)