def test_sanitize_params_throws_error_if_required_param_not_in_params(
            self):
        allowed_args = ["foo", "dog"]
        params = {"foo": "bar", "cat": "pants", "dog": "shirt"}

        with self.assertRaises(ArgumentError):
            helpers.sanitize_params(params,
                                    all_args=allowed_args,
                                    required_args=["fish"])
    def test_sanitize_params_throws_error_if_required_param_not_in_params(self):
        allowed_args = ["foo", "dog"]
        params = {
            "foo": "bar",
            "cat": "pants",
            "dog": "shirt"
        }

        with self.assertRaises(ArgumentError):
            helpers.sanitize_params(params, all_args=allowed_args, required_args=["fish"])
    def get_contacts(self, **params):
        """List contacts in an account.

        Documentation: http://context.io/docs/2.0/accounts/contacts#get

        Optional Arguments:
            search: string - String identifying the name or the email address
                of the contact(s) you are looking for.
            active_before: integer (unix time) - Only include contacts
                included in at least one email dated before a given time. This
                parameter should be a standard unix timestamp
            active_after: integer (unix time) - Only include contacts included
                in at least one email dated after a given time. This parameter
                should be a standard unix timestamp
            sort_by: string - The field by which to sort the returned results.
                Possible values are email, count, received_count and sent_count
            sort_order: string - The sort order of the returned results.
                Possible values are asc and desc
            limit: integer - The maximum number of results to return.
            offset: integer - Start the list at this offset (zero-based).

        Returns:
            A list of Contact objects
        """
        all_args = [
            'search', 'active_before', 'active_after', 'limit', 'offset',
            'sort_by', 'sort_order'
        ]

        params = helpers.sanitize_params(params, all_args)
        contacts = self._request_uri("contacts", params=params)

        return [Contact(self, obj) for obj in contacts.get('matches')]
    def post_flag(self, **params):
        """Set message flags for a given email.

        Also, populates/updates self.flags with the new data.

        Optional Arguments:
            seen: integer - Message has been read. Set this parameter to 1 to
                set the flag, 0 to unset it.
            answered: integer - Message has been answered. Set this parameter
                to 1 to set the flag, 0 to unset it.
            flagged: integer - Message is "flagged" for urgent/special
                attention. Set this parameter to 1 to set the flag, 0 to unset
                it.
            deleted: integer - Message is "deleted" for later removal. An
                alternative way of deleting messages is to move it to the
                Trash folder. Set this parameter to 1 to set the flag, 0 to
                unset it.
            draft: integer - Message has not completed composition (marked as
                a draft). Set this parameter to 1 to set the flag, 0 to unset
                it.

        Returns:
            Bool, after setting self.flags.
        """
        all_args = ["seen", "answered", "flagged", "deleted", "draft"]
        params = helpers.sanitize_params(params, all_args)

        data = self._request_uri("flags", method="POST", params=params)
        status = bool(data["success"])

        if status:
            self.flags = data["flags"]

        return status
    def get_body(self, **params):
        """Fetch the message body of a given email.

        This method sets self.body, and returns a data structure.

        Documentation: http://context.io/docs/2.0/accounts/messages/body#get

        Optional Arguments:
            type: string - Many emails are sent with both rich text and plain
                text versions in the message body and by default, the response
                of this call will include both. It is possible to only get
                either the plain or rich text version by setting the type
                parameter to text/plain or text/html respectively.

        Returns:
            a list of dictionaries, data format below

            [
              {
                "type": string - MIME type of message part being fetched,
                "charset": string - encoding of the characters in the part of
                    message,
                "content": string - the actual content of the message part
                    being pulled,
                "body_section": number - indicating position of the part in
                    the body structure,
              }
            ]
        """
        all_args = ['type']
        params = helpers.sanitize_params(params, all_args)
        self.body = self._request_uri("body", params=params)
        return self.body
Beispiel #6
0
    def get_sources(self, **params):
        """Lists IMAP sources assigned for an account.

        GET method for sources resource.

        Documentation: http://context.io/docs/2.0/accounts/sources#get

        Optional Arguments:
            status: string - Only return sources whose status is of a specific
                value. Possible statuses are: INVALID_CREDENTIALS,
                CONNECTION_IMPOSSIBLE, NO_ACCESS_TO_ALL_MAIL, OK,
                TEMP_DISABLED, and DISABLED
            status_ok: integer - Set to 0 to get sources that are not working
                correctly. Set to 1 to get those that are.

        Returns:
            A list of Source objects
        """
        all_args = ['status', 'status_ok']
        params = helpers.sanitize_params(params, all_args)

        return [
            Source(self, obj)
            for obj in self._request_uri("sources", params=params)
        ]
    def post_flag(self, **params):
        """Set message flags for a given email.

        Also, populates/updates self.flags with the new data.

        Optional Arguments:
            seen: integer - Message has been read. Set this parameter to 1 to
                set the flag, 0 to unset it.
            answered: integer - Message has been answered. Set this parameter
                to 1 to set the flag, 0 to unset it.
            flagged: integer - Message is "flagged" for urgent/special
                attention. Set this parameter to 1 to set the flag, 0 to unset
                it.
            deleted: integer - Message is "deleted" for later removal. An
                alternative way of deleting messages is to move it to the
                Trash folder. Set this parameter to 1 to set the flag, 0 to
                unset it.
            draft: integer - Message has not completed composition (marked as
                a draft). Set this parameter to 1 to set the flag, 0 to unset
                it.

        Returns:
            Bool, after setting self.flags.
        """
        all_args = ["seen", "answered", "flagged", "deleted", "draft"]
        params = helpers.sanitize_params(params, all_args)

        data = self._request_uri("flags", method="POST", params=params)
        status = bool(data["success"])

        if status:
            self.flags = data["flags"]

        return status
Beispiel #8
0
    def get_contacts(self, **params):
        """List contacts in an account.

        Documentation: http://context.io/docs/2.0/accounts/contacts#get

        Optional Arguments:
            search: string - String identifying the name or the email address
                of the contact(s) you are looking for.
            active_before: integer (unix time) - Only include contacts
                included in at least one email dated before a given time. This
                parameter should be a standard unix timestamp
            active_after: integer (unix time) - Only include contacts included
                in at least one email dated after a given time. This parameter
                should be a standard unix timestamp
            sort_by: string - The field by which to sort the returned results.
                Possible values are email, count, received_count and sent_count
            sort_order: string - The sort order of the returned results.
                Possible values are asc and desc
            limit: integer - The maximum number of results to return.
            offset: integer - Start the list at this offset (zero-based).

        Returns:
            A list of Contact objects
        """
        all_args = [
            'search', 'active_before', 'active_after', 'limit', 'offset',
            'sort_by', 'sort_order'
        ]

        params = helpers.sanitize_params(params, all_args)
        contacts = self._request_uri("contacts", params=params)

        return [Contact(self, obj) for obj in contacts.get('matches')]
Beispiel #9
0
    def get_discovery(self, **params):
        """Attempts to discover IMAP settings for a given email address.

        2.0
        Documentation: http://context.io/docs/2.0/discovery

        Lite
        Documentation: http://context.io/lite.0/discovery

        Required Arguments:
            source_type: string - The type of source you want to discover
                settings for. Right now, the only supported source type is IMAP
            email: string - An email address you want to discover IMAP
                settings for. Make sure source_type is set to IMAP.

        Returns:
            A Discovery object.
        """
        if 'source_type' not in params:
            params['source_type'] = 'IMAP'

        all_args = req_args = ['source_type', 'email']

        params = helpers.sanitize_params(params, all_args, req_args)

        return Discovery(self, self._request_uri('discovery', params=params))
    def test_sanitize_params_ignores_params_that_are_set_to_None(self):
        allowed_args = ["foo", "dog"]
        params = {"foo": None, "dog": "shirt"}

        cleaned_params = helpers.sanitize_params(params, all_args=allowed_args)

        self.assertEqual({"dog": "shirt"}, cleaned_params)
Beispiel #11
0
    def get_discovery(self, **params):
        """Attempts to discover IMAP settings for a given email address.

        2.0
        Documentation: http://context.io/docs/2.0/discovery

        Lite
        Documentation: http://context.io/lite.0/discovery

        Required Arguments:
            source_type: string - The type of source you want to discover
                settings for. Right now, the only supported source type is IMAP
            email: string - An email address you want to discover IMAP
                settings for. Make sure source_type is set to IMAP.

        Returns:
            A Discovery object.
        """
        if 'source_type' not in params:
            params['source_type'] = 'IMAP'

        all_args = req_args = ['source_type', 'email']

        params = helpers.sanitize_params(params, all_args, req_args)

        return Discovery(self, self._request_uri('discovery', params=params))
Beispiel #12
0
    def get_body(self, **params):
        """Fetch the message body of a given email.

        This method sets self.body, and returns a data structure.

        Documentation: http://context.io/docs/2.0/accounts/messages/body#get

        Optional Arguments:
            type: string - Many emails are sent with both rich text and plain
                text versions in the message body and by default, the response
                of this call will include both. It is possible to only get
                either the plain or rich text version by setting the type
                parameter to text/plain or text/html respectively.

        Returns:
            a list of dictionaries, data format below

            [
              {
                "type": string - MIME type of message part being fetched,
                "charset": string - encoding of the characters in the part of
                    message,
                "content": string - the actual content of the message part
                    being pulled,
                "body_section": number - indicating position of the part in
                    the body structure,
              }
            ]
        """
        all_args = ['type']
        params = helpers.sanitize_params(params, all_args)
        self.body = self._request_uri("body", params=params)
        return self.body
Beispiel #13
0
    def post_connect_token(self, **kwargs):
        req_args = ["callback_url"]
        all_args = ["email", "first_name", "last_name", "status_callback_url"] + req_args

        params = sanitize_params(kwargs, all_args, req_args)

        return super(Lite, self).post_connect_token(**params)
Beispiel #14
0
    def get_accounts(self, **params):
        """List of Accounts.

        GET method for the accounts resource.

        Documentation: http://context.io/docs/2.0/accounts#get

        Optional Arguments:
            email: string - Only return account associated
                to this email address
            status: string - Only return accounts with sources
                whose status is of a specific value. If an account has many
                sources, only those matching the given value will be
                included in the response. Possible statuses are:
                INVALID_CREDENTIALS, CONNECTION_IMPOSSIBLE,
                NO_ACCESS_TO_ALL_MAIL, OK, TEMP_DISABLED and DISABLED
            status_ok: int - Only return accounts with sources
                whose status is of a specific value. If an account has many
                sources, only those matching the given value will be included
                in the response. Possible statuses are: INVALID_CREDENTIALS,
                CONNECTION_IMPOSSIBLE, NO_ACCESS_TO_ALL_MAIL, OK, TEMP_DISABLED
                and DISABLED
            limit: int - The maximum number of results to return
            offset: int - Start the list at this offset (zero-based)

        Returns:
            A list of Account objects
        """
        all_args = ["email", "status", "status_ok", "limit", "offset"]

        params = helpers.sanitize_params(params, all_args)
        return [Account(self, obj) for obj in self._request_uri("accounts", params=params)]
    def test_sanitize_params_removes_unwanted_params(self):
        allowed_args = ["foo", "dog"]
        params = {"foo": "bar", "cat": "pants", "dog": "shirt"}

        self.assertEqual({
            "foo": "bar",
            "dog": "shirt"
        }, helpers.sanitize_params(params, all_args=allowed_args))
    def post(self, uri="", return_bool=True, params={}, headers={}, all_args=[], required_args=[]):
        params = helpers.sanitize_params(params, all_args, required_args)
        response = self._request_uri(uri, method="POST", params=params, headers=headers)

        if return_bool:
            return bool(response['success'])

        return response
Beispiel #17
0
    def get_users(self, **kwargs):
        all_args = ["email", "status", "status_ok", "limit", "offset"]

        params = sanitize_params(kwargs, all_args)
        return [
            User(self, obj)
            for obj in self._request_uri("users", params=params)
        ]
Beispiel #18
0
    def post_connect_token(self, **kwargs):
        req_args = ["callback_url"]
        all_args = ["email", "first_name", "last_name", "status_callback_url"
                    ] + req_args

        params = sanitize_params(kwargs, all_args, req_args)

        return super(Lite, self).post_connect_token(**params)
    def get(self, uri="", return_bool=True, params={}, all_args=[], required_args=[]):
        response = self._request_uri(uri, params=helpers.sanitize_params(params, all_args, required_args))
        self.__init__(self.parent, response)

        if return_bool:
            return True

        return response
Beispiel #20
0
    def get_email_accounts(self, **params):
        all_args = ["status", "status_ok"]

        params = sanitize_params(params, all_args)

        return [
            EmailAccount(self, obj)
            for obj in self._request_uri("email_accounts", params=params)
        ]
    def test_sanitize_params_ignores_params_that_are_set_to_None(self):
        allowed_args = ["foo", "dog"]
        params = {
            "foo": None,
            "dog": "shirt"
        }

        cleaned_params = helpers.sanitize_params(params, all_args=allowed_args)

        self.assertEqual({"dog": "shirt"}, cleaned_params)
Beispiel #22
0
    def get_thread(self, **params):
        """List other messages in the same thread as this message.

        Documentation: http://context.io/docs/2.0/accounts/messages/thread#get

        Optional Arguments:
            include_body: integer - Set to 1 to include message bodies in the
                result. Since message bodies must be retrieved from the IMAP
                server, expect a performance hit when setting this parameter.
            include_headers: mixed - Can be set to 0 (default), 1 or raw. If
                set to 1, complete message headers, parsed into an array, are
                included in the results. If set to raw, the headers are also
                included but as a raw unparsed string. Since full original
                headers bodies must be retrieved from the IMAP server, expect
                a performance hit when setting this parameter.
            include_flags: integer - Set to 1 to include IMAP flags of
                messages in the result. Since message flags must be retrieved
                from the IMAP server, expect a performance hit when setting
                this parameter.
            body_type: string - Used when include_body is set to get only body
                parts of a given MIME-type (for example text/html)
            limit: integer - The maximum number of messages to include in the
                messages property of the response.
            offset: integer - Start the list of messages at this offset
                (zero-based).

        Returns:
            a Thread object. Unless we can't find a thread id, then just the
                response
        """
        all_args = [
            "include_body", "include_headers", "include_flags", "body_type",
            "limit", "offset"
        ]
        params = helpers.sanitize_params(params, all_args)

        data = self._request_uri("thread", params=params)

        # try to find the gmail_thread_id
        gmail_thread_id = None
        messages = data.get("messages")
        if messages is not None:
            first_message = messages[0]
            gmail_thread_id = first_message.get("gmail_thread_id")
            if gmail_thread_id:
                data["gmail_thread_id"] = "gm-{0}".format(gmail_thread_id)

        self.thread = Thread(self.parent, data) if gmail_thread_id else data

        # if we have the subject, set thread.subject
        if self.subject and self.thread:
            self.thread.subject = self.subject

        return self.thread
Beispiel #23
0
    def get_thread(self, **params):
        """List other messages in the same thread as this message.

        Documentation: http://context.io/docs/2.0/accounts/messages/thread#get

        Optional Arguments:
            include_body: integer - Set to 1 to include message bodies in the
                result. Since message bodies must be retrieved from the IMAP
                server, expect a performance hit when setting this parameter.
            include_headers: mixed - Can be set to 0 (default), 1 or raw. If
                set to 1, complete message headers, parsed into an array, are
                included in the results. If set to raw, the headers are also
                included but as a raw unparsed string. Since full original
                headers bodies must be retrieved from the IMAP server, expect
                a performance hit when setting this parameter.
            include_flags: integer - Set to 1 to include IMAP flags of
                messages in the result. Since message flags must be retrieved
                from the IMAP server, expect a performance hit when setting
                this parameter.
            body_type: string - Used when include_body is set to get only body
                parts of a given MIME-type (for example text/html)
            limit: integer - The maximum number of messages to include in the
                messages property of the response.
            offset: integer - Start the list of messages at this offset
                (zero-based).

        Returns:
            a Thread object. Unless we can't find a thread id, then just the
                response
        """
        all_args = [
            "include_body", "include_headers", "include_flags", "body_type",
            "limit", "offset"
        ]
        params = helpers.sanitize_params(params, all_args)

        data = self._request_uri("thread", params=params)

        # try to find the gmail_thread_id
        gmail_thread_id = None
        messages = data.get("messages")
        if messages is not None:
            first_message = messages[0]
            gmail_thread_id = first_message.get("gmail_thread_id")
            if gmail_thread_id:
                data["gmail_thread_id"] = "gm-{0}".format(gmail_thread_id)

        self.thread = Thread(self.parent, data) if gmail_thread_id else data

        # if we have the subject, set thread.subject
        if self.subject and self.thread:
            self.thread.subject = self.subject

        return self.thread
    def test_sanitize_params_removes_unwanted_params(self):
        allowed_args = ["foo", "dog"]
        params = {
            "foo": "bar",
            "cat": "pants",
            "dog": "shirt"
        }

        self.assertEqual(
            {"foo": "bar", "dog": "shirt"},
            helpers.sanitize_params(params, all_args=allowed_args)
        )
Beispiel #25
0
    def post_user(self, **kwargs):
        req_args = ["email", "server", "username", "use_ssl", "port", "type"]

        if check_for_account_credentials(kwargs):
            all_args = [
                "password", "provider_refresh_token", "provider_consumer_key", "migrate_account_id",
                "first_name", "last_name"
            ] + req_args

            params = sanitize_params(kwargs, all_args, req_args)

            return User(self, self._request_uri("users", method="POST", params=params))
Beispiel #26
0
    def post_user(self, **kwargs):
        req_args = ["email", "server", "username", "use_ssl", "port", "type"]

        if check_for_account_credentials(kwargs):
            all_args = [
                "password", "provider_refresh_token", "provider_consumer_key",
                "migrate_account_id", "first_name", "last_name"
            ] + req_args

            params = sanitize_params(kwargs, all_args, req_args)

            return User(
                self, self._request_uri("users", method="POST", params=params))
    def get(self,
            uri="",
            return_bool=True,
            params={},
            all_args=[],
            required_args=[]):
        response = self._request_uri(uri,
                                     params=helpers.sanitize_params(
                                         params, all_args, required_args))
        self.__init__(self.parent, response)

        if return_bool:
            return True

        return response
Beispiel #28
0
    def get_files(self, **params):
        """List files exchanges with a contact.

        Documentation: http://context.io/docs/2.0/accounts/contacts/files#get

        Optional Arguments:
            limit: integer - The maximum number of results to return.
            offset: integer - Start the list at this offset (zero-based).

        Returns:
            A list of File objects
        """
        all_args = ['limit', 'offset']
        params = helpers.sanitize_params(params, all_args)

        return [File(self.parent, obj) for obj in self._request_uri('files', params=params)]
Beispiel #29
0
    def post_oauth_provider(self, **params):
        """Add a new OAuth provider.

        Required Arguments:
            type: string -  Identification of the OAuth provider. This must be
                either GMAIL_OAUTH2 and MSLIVECONNECT.
            provider_consumer_key: string - The OAuth consumer key
            provider_consumer_secret: string - The OAuth consumer secret

        Returns:
            a dictionary
        """
        all_args = req_args = ["type", "provider_consumer_key", "provider_consumer_secret"]

        params = helpers.sanitize_params(params, all_args, req_args)

        return self._request_uri("oauth_providers", method="POST", params=params)
Beispiel #30
0
    def get_messages(self, **params):
        """Get current listings of email messages in a given folder.

        NOTE: this gets all messages including since last sync. It's fresher,
            but expect slower performance than using Account.get_messages()

        Documentation:
            http://context.io/docs/2.0/accounts/sources/folders/messages#get

        Optional Arguments:
            include_thread_size: integer - Set to 1 to include thread size in
                the result.
            include_body: integer - Set to 1 to include message bodies in the
                result. Since message bodies must be retrieved from the IMAP
                server, expect a performance hit when setting this parameter.
            body_type: string - Used when include_body is set to get only body
                parts of a given MIME-type (for example text/html)
            include_headers: mixed - Can be set to 0 (default), 1 or raw. If
                set to 1, complete message headers, parsed into an array, are
                included in the results. If set to raw, the headers are also
                included but as a raw unparsed string. Since full original
                headers bodies must be retrieved from the IMAP server, expect
                a performance hit when setting this parameter.
            include_flags: integer - Set to 1 to include IMAP flags for this
                message in the result. Since message flags must be retrieved
                from the IMAP server, expect a performance hit when setting
                this parameter.
            flag_seen: integer - Set to 1 to restrict list to messages having
                the \Seen flag set, set to 0 to have the messages with that
                flag unset (ie. list unread messages in the folder).
            limit: integer - The maximum number of results to return.
            offset: integer - Start the list at this offset (zero-based).

        Returns:
            a list of Message objects.
        """
        all_args = [
            "include_thread_size", "include_body", "body_type",
            "include_headers", "include_flags", "flag_seen", "limit", "offset"
        ]
        params = helpers.sanitize_params(params, all_args)

        return [
            Message(self, obj)
            for obj in self._request_uri('messages', params=params)
        ]
Beispiel #31
0
    def get_messages(self, **params):
        """Get current listings of email messages in a given folder.

        NOTE: this gets all messages including since last sync. It's fresher,
            but expect slower performance than using Account.get_messages()

        Documentation:
            http://context.io/docs/2.0/accounts/sources/folders/messages#get

        Optional Arguments:
            include_thread_size: integer - Set to 1 to include thread size in
                the result.
            include_body: integer - Set to 1 to include message bodies in the
                result. Since message bodies must be retrieved from the IMAP
                server, expect a performance hit when setting this parameter.
            body_type: string - Used when include_body is set to get only body
                parts of a given MIME-type (for example text/html)
            include_headers: mixed - Can be set to 0 (default), 1 or raw. If
                set to 1, complete message headers, parsed into an array, are
                included in the results. If set to raw, the headers are also
                included but as a raw unparsed string. Since full original
                headers bodies must be retrieved from the IMAP server, expect
                a performance hit when setting this parameter.
            include_flags: integer - Set to 1 to include IMAP flags for this
                message in the result. Since message flags must be retrieved
                from the IMAP server, expect a performance hit when setting
                this parameter.
            flag_seen: integer - Set to 1 to restrict list to messages having
                the \Seen flag set, set to 0 to have the messages with that
                flag unset (ie. list unread messages in the folder).
            limit: integer - The maximum number of results to return.
            offset: integer - Start the list at this offset (zero-based).

        Returns:
            a list of Message objects.
        """
        all_args = [
            "include_thread_size", "include_body",
            "body_type", "include_headers", "include_flags", "flag_seen",
            "limit", "offset"
        ]
        params = helpers.sanitize_params(params, all_args)

        return [
            Message(self, obj) for obj in self._request_uri('messages', params=params)
        ]
    def post(self,
             uri="",
             return_bool=True,
             params={},
             headers={},
             all_args=[],
             required_args=[]):
        params = helpers.sanitize_params(params, all_args, required_args)
        response = self._request_uri(uri,
                                     method="POST",
                                     params=params,
                                     headers=headers)

        if return_bool:
            return bool(response['success'])

        return response
Beispiel #33
0
    def get_folders(self, **params):
        """Get list of folders in an IMAP source.

        Documentation: http://context.io/docs/2.0/accounts/sources/folders#get

        Optional Arguments:
            include_extended_counts: integer -

        Returns:
            A list of Folder objects.
        """
        all_args = ["include_extended_counts"]
        params = helpers.sanitize_params(params, all_args)

        return [
            Folder(self, obj)
            for obj in self._request_uri("folders", params=params)
        ]
Beispiel #34
0
    def put(self, **params):
        """Create a folder on an IMAP source.

        Documentation:
            http://context.io/docs/2.0/accounts/sources/folders#id-put

        Optional Arguments:
            delim: string - If / isn't fancy enough as a hierarchy delimiter
                when specifying the folder you want to create, you're free to
                use what you want, just make sure you set this delim parameter
                to tell us what you're using.

        Returns:
            Bool
        """
        all_args = ["delim"]
        params = helpers.sanitize_params(params, all_args)
        status = self._request_uri(method="PUT", params=params)
        return bool(status["success"])
Beispiel #35
0
    def post_folder(self, **params):
        """Edits the folders a message is in.

        This call supports adding and/or removing more than one folder
            simultaneously using the [] suffix to the parameter name.

        Documentation:
            http://context.io/docs/2.0/accounts/messages/folders#post

        Optional Arguments:
            add: string - New folder this message should appear in.
            remove: string - Folder this message should be removed from.

        Returns:
            Bool
        """
        all_args = ['add', 'remove', 'add[]', 'remove[]']
        params = helpers.sanitize_params(params, all_args)
        return super(Message, self).post("folders", params=params)
Beispiel #36
0
    def get_files(self, **params):
        """List files exchanges with a contact.

        Documentation: http://context.io/docs/2.0/accounts/contacts/files#get

        Optional Arguments:
            limit: integer - The maximum number of results to return.
            offset: integer - Start the list at this offset (zero-based).

        Returns:
            A list of File objects
        """
        all_args = ['limit', 'offset']
        params = helpers.sanitize_params(params, all_args)

        return [
            File(self.parent, obj)
            for obj in self._request_uri('files', params=params)
        ]
Beispiel #37
0
    def put(self, **params):
        """Create a folder on an IMAP source.

        Documentation:
            http://context.io/docs/2.0/accounts/sources/folders#id-put

        Optional Arguments:
            delim: string - If / isn't fancy enough as a hierarchy delimiter
                when specifying the folder you want to create, you're free to
                use what you want, just make sure you set this delim parameter
                to tell us what you're using.

        Returns:
            Bool
        """
        all_args = ["delim"]
        params = helpers.sanitize_params(params, all_args)
        status = self._request_uri(method="PUT", params=params)
        return bool(status["success"])
Beispiel #38
0
    def post_folder(self, **params):
        """Edits the folders a message is in.

        This call supports adding and/or removing more than one folder
            simultaneously using the [] suffix to the parameter name.

        Documentation:
            http://context.io/docs/2.0/accounts/messages/folders#post

        Optional Arguments:
            add: string - New folder this message should appear in.
            remove: string - Folder this message should be removed from.

        Returns:
            Bool
        """
        all_args = ['add', 'remove', 'add[]', 'remove[]']
        params = helpers.sanitize_params(params, all_args)
        return super(Message, self).post("folders", params=params)
Beispiel #39
0
    def post_email_account(self, **kwargs):
        req_args = ["email", "server", "username", "use_ssl", "port", "type"]

        all_args = req_args + ["status_callback_url", "password"]

        email_account = super(User, self).post(
            uri="email_accounts", params=kwargs, return_bool=False, all_args=all_args,
            required_args=req_args
        )

        if bool(email_account["success"]) is False:
            return False

        return EmailAccount(self, email_account)

        if check_for_account_credentials(kwargs):
            all_args = ["migrate_account_id", "first_name", "last_name"] + req_args
            params = sanitize_params(kwargs, all_args, req_args)

            return User(self, self._request_uri("users", method="POST", params=params))
Beispiel #40
0
    def post_oauth_provider(self, **params):
        """Add a new OAuth provider.

        Required Arguments:
            type: string -  Identification of the OAuth provider. This must be
                either GMAIL_OAUTH2 and MSLIVECONNECT.
            provider_consumer_key: string - The OAuth consumer key
            provider_consumer_secret: string - The OAuth consumer secret

        Returns:
            a dictionary
        """
        all_args = req_args = [
            "type", "provider_consumer_key", "provider_consumer_secret"
        ]

        params = helpers.sanitize_params(params, all_args, req_args)

        return self._request_uri("oauth_providers",
                                 method="POST",
                                 params=params)
Beispiel #41
0
    def get_sources(self, **params):
        """Lists IMAP sources assigned for an account.

        GET method for sources resource.

        Documentation: http://context.io/docs/2.0/accounts/sources#get

        Optional Arguments:
            status: string - Only return sources whose status is of a specific
                value. Possible statuses are: INVALID_CREDENTIALS,
                CONNECTION_IMPOSSIBLE, NO_ACCESS_TO_ALL_MAIL, OK,
                TEMP_DISABLED, and DISABLED
            status_ok: integer - Set to 0 to get sources that are not working
                correctly. Set to 1 to get those that are.

        Returns:
            A list of Source objects
        """
        all_args = ['status', 'status_ok']
        params = helpers.sanitize_params(params, all_args)

        return [Source(self, obj) for obj in self._request_uri("sources", params=params)]
Beispiel #42
0
    def get_headers(self, **params):
        """Get complete headers for a message.

        Documentation: http://context.io/docs/2.0/accounts/messages/headers#get

        Optional Arguments:
            raw: integer - By default, this returns messages headers parsed
                into an array. Set this parameter to 1 to get raw unparsed
                headers.

        Returns:
            Dict, data structure below.

            {
              Name-Of-Header: array - Values for that header (some headers can
                  appear more than once in the message source),
              ...
            }
        """
        all_args = ['raw']
        params = helpers.sanitize_params(params, all_args)
        self.headers = self._request_uri('headers', params=params)
        return self.headers
Beispiel #43
0
    def post_email_account(self, **kwargs):
        req_args = ["email", "server", "username", "use_ssl", "port", "type"]

        all_args = req_args + ["status_callback_url"]

        email_account = super(User, self).post(uri="email_accounts",
                                               params=kwargs,
                                               return_bool=False,
                                               all_args=all_args,
                                               required_args=req_args)

        if bool(email_account["success"]) is False:
            return False

        return EmailAccount(self, email_account)

        if check_for_account_credentials(kwargs):
            all_args = ["migrate_account_id", "first_name", "last_name"
                        ] + req_args
            params = sanitize_params(kwargs, all_args, req_args)

            return User(
                self, self._request_uri("users", method="POST", params=params))
Beispiel #44
0
    def get_headers(self, **params):
        """Get complete headers for a message.

        Documentation: http://context.io/docs/2.0/accounts/messages/headers#get

        Optional Arguments:
            raw: integer - By default, this returns messages headers parsed
                into an array. Set this parameter to 1 to get raw unparsed
                headers.

        Returns:
            Dict, data structure below.

            {
              Name-Of-Header: array - Values for that header (some headers can
                  appear more than once in the message source),
              ...
            }
        """
        all_args = ['raw']
        params = helpers.sanitize_params(params, all_args)
        self.headers = self._request_uri('headers', params=params)
        return self.headers
Beispiel #45
0
    def post_connect_token(self, **params):
        """Obtain a new connect_token for an IMAP source.

        * Note: unused connect tokens are purged after 24 hours.

        Documentation: http://context.io/docs/2.0/accounts/sources/connect_tokens#post

        Required Arguments:
            callback_url: string (url) - When the user's mailbox is connected
                to your API key, the browser will call this url (GET). This
                call will have a parameter called contextio_token indicating
                the connect_token related to this callback. You can then do a
                get on this connect_token to obtain details about the account
                and source created through that token and save that account id
                in your own user data.

        Returns:
            A dictionary (data format below)

            {
              "success": string - true if connect_token was successfully
                  created, false otherwise,
              "token": string - Id of the token,
              "resource_url": string - URL to of the token,
              "browser_redirect_url": string - Redirect the user's browser to
                  this URL to have them connect their mailbox through this
                  token
            }
        """
        all_args = req_args = ['callback_url']

        params = helpers.sanitize_params(params, all_args, req_args)

        return self._request_uri('connect_tokens',
                                 method='POST',
                                 params=params)
Beispiel #46
0
    def get_threads(self, **params):
        """List threads where contact is present.

        Documentation: http://context.io/docs/2.0/accounts/contacts/threads#get

        Optional Arguments:
            limit: integer - The maximum number of results to return.
            offset: integer - Start the list at this offset (zero-based).

        Returns:
            A list of Thread objects.
        """
        all_args = ['limit', 'offset']
        params = helpers.sanitize_params(params, all_args)

        thread_urls = self._request_uri('threads', params=params)
        objs = []

        # isolate just the gmail_thread_id so we can instantiate Thread objects
        for thread_url in thread_urls:
            url_components = thread_url.split('/')
            objs.append({'gmail_thread_id': url_components[-1]})

        return [Thread(self.parent, obj) for obj in objs]
Beispiel #47
0
    def get_threads(self, **params):
        """List threads where contact is present.

        Documentation: http://context.io/docs/2.0/accounts/contacts/threads#get

        Optional Arguments:
            limit: integer - The maximum number of results to return.
            offset: integer - Start the list at this offset (zero-based).

        Returns:
            A list of Thread objects.
        """
        all_args = ['limit', 'offset']
        params = helpers.sanitize_params(params, all_args)

        thread_urls = self._request_uri('threads', params=params)
        objs = []

        # isolate just the gmail_thread_id so we can instantiate Thread objects
        for thread_url in thread_urls:
            url_components = thread_url.split('/')
            objs.append({'gmail_thread_id': url_components[-1]})

        return [Thread(self.parent, obj) for obj in objs]
Beispiel #48
0
    def post_connect_token(self, **params):
        """Obtain a new connect token.

        2.0
        Documentation: http://context.io/docs/2.0/connect_tokens#post

        Lite
        Documentation: http://context.io/docs/lite/connect_tokens#post

        Required Arguments:
            callback_url: string (url) - When the user's mailbox is connected
                to your API key, the browser will call this url (GET). This
                call will have a parameter called contextio_token indicating
                the connect_token related to this callback. You can then do a
                get on this connect_token to obtain details about the account
                and source created through that token and save that account id
                in your own user data.

        Optional Arguments:
            email: string - The email address of the account to be added. If
                specified, the first step of the connect UI where users are
                prompted for their email address, first name and last name is
                skipped.
            first_name: string - First name of the account holder.
            last_name: string - Last name of the account holder.
            source_callback_url: string - If specified, we'll make a POST
                request to this URL when the initial sync is completed.
            source_sync_all_folders: integer - By default, we filter out some
                folders like 'Deleted Items' and 'Drafts'. Set this parameter
                to 1 to turn off this filtering and show every single folder.
            source_sync_flags: integer - By default, we don't synchronize IMAP
                flags. Set this parameter to 1 to turn on IMAP flag syncing
                for the 'seen' and 'flagged' flags.
            source_raw_file_list: integer - By default, we filter out files
                like signature images from the files list. Set this parameter
                to 1 to turn off this filtering and show every single file
                attachment.
            status_callback_url: string (url) - If specified, we'll make a POST
            request to this URL if the connection status of the source changes.

        Returns:
            A dictionary, data format below

            {
              "success": string - true if connect_token was successfully
                  created, false otherwise,
              "token": string - Id of the token,
              "resource_url": string - URL to of the token,
              "browser_redirect_url": string - Redirect the user's browser to
                  this URL to have them connect their mailbox through this
                  token
            }
        """
        req_args = ["callback_url"]
        all_args = [
            "callback_url", "email", "first_name", "last_name",
            "source_callback_url", "source_sync_all_folders",
            "source_sync_flags", "source_raw_file_list", "status_callback_url"
        ]

        params = helpers.sanitize_params(params, all_args, req_args)
        return super(V2_0, self).post_connect_token(**params)
Beispiel #49
0
 def delete_read(self, **params):
     all_args = ["delimiter"]
     params = helpers.sanitize_params(params, all_args)
     return super(Message, self).delete("read")
Beispiel #50
0
    def get_threads(self, **params):
        """List of threads on an account.

        Documentation: http://context.io/docs/2.0/accounts/threads#get

        Optional Arguments:
            subject: string - Get threads with messages whose subject matches
                this search string. To use regular expressions instead of
                simple string matching, make sure the string starts and ends
                with /.
            email: string - Email address of the contact for whom you want the
                latest threads. This value is interpreted as received from
                email X, sent to email X or sent by anyone to both email X and
                the source owner.
            to: string - Get threads with at least one message sent to this
                email address.
            sender: string - Get threads with at least one message sent from
                this email address.
            cc: string - Get threads with at least one message having this
                email address CC'ed.
            bcc: string - Get threads with at least one message having this
                email address BCC'ed.
            folder: string - Filter threads by the folder (or Gmail label).
                This parameter can be the complete folder name with the
                appropriate hierarchy delimiter for the mail server being
                queried (eg. Inbox/My folder) or the "symbolic name" of the
                folder (eg. \Starred). The symbolic name refers to attributes
                used to refer to special use folders in a language-independant
                way. See http://code.google.com/apis/gmail/imap/#xlist (Gmail
                specific) and RFC-6154.
            indexed_before: integer (unix time) - Get threads with at least
                one message indexed before this timestamp. This is not the
                same as the date of the email, it is the time Context.IO
                indexed this message.
            indexed_after: integer (unix time) - Get threads with at least one
                message indexed after this timestamp. This is not the same as
                the date of the email, it is the time Context.IO indexed this
                message.
            active_before: integer (unix time) - Get threads with at least one
                message dated before this timestamp. The value this filter is
                applied to is the Date: header of the message which refers to
                the time the message is sent from the origin.
            active_after: integer (unix time) - Get threads with at least one
                message dated after this timestamp. The value this filter is
                applied to is the Date: header of the message which refers to
                the time the message is sent from the origin.
            started_before: integer (unix time) - Get threads whose first
                message is dated before this timestamp. The value this filter
                is applied to is the Date: header of the message which refers
                to the time the message is sent from the origin.
            started_after: integer (unix time) - Get threads whose first
                message is dated after this timestamp. The value this filter
                is applied to is the Date: header of the message which refers
                to the time the message is sent from the origin.
            limit: integer - The maximum number of results to return.
            offset: integer - Start the list at this offset (zero-based).

        Returns:
            A list of Thread objects (nearly empty thread objects). Use the
                Thread.get() method to populate the object.
        """
        all_args = [
            'subject', 'email', 'to', 'sender', 'from_', 'cc', 'bcc', 'folder',
            'indexed_before', 'indexed_after', 'active_before', 'active_after',
            'started_before', 'started_after', 'limit', 'offset'
        ]
        params = helpers.sanitize_params(params, all_args)

        # workaround to send param "from" even though it's a reserved keyword
        # in python
        if 'sender' in params:
            params['from'] = params['sender']
            del params['sender']

        if 'from_' in params:
            params['from'] = params['from_']
            del params['from_']

        thread_urls = self._request_uri('threads', params=params)
        objs = []

        # isolate just the gmail_thread_id so we can instantiate Thread objects
        for thread_url in thread_urls:
            url_components = thread_url.split('/')
            objs.append({'gmail_thread_id': url_components[-1]})

        return [Thread(self, obj) for obj in objs]
Beispiel #51
0
    def get_messages(self, **params):
        """List email messages for an account.

        GET method for the messages resource.

        Each of the email, to, from, cc and bcc parameters can be set to a
        comma-separated list of email addresses. These multiple addresses
        are treated as an OR combination.

        You can set more than one parameter when doing this call. Multiple
        parameters are treated as an AND combination.

        Optional Arguments:
            subject: string - Get messages whose subject matches this search
                string. To use regular expressions instead of simple string
                matching, make sure the string starts and ends with /.
            email: string - Email address of the contact for whom you want the
                latest messages exchanged with. By "exchanged with contact X"
                we mean any email received from contact X, sent to contact X
                or sent by anyone to both contact X and the source owner.
            to: string - Email address of a contact messages have been sent to.
            sender: string - Email address of a contact messages have been
                received from. Same as "from" in documentation. "from" is a
                python keyword and we can't use that...
            cc: string - Email address of a contact CC'ed on the messages.
            bcc: string - Email address of a contact BCC'ed on the messages.
            folder: string - Filter messages by the folder (or Gmail label).
                This parameter can be the complete folder name with the
                appropriate hierarchy delimiter for the mail server being
                queried (eg. Inbox/My folder) or the "symbolic name" of the
                folder (eg. \Starred). The symbolic name refers to attributes
                used to refer to special use folders in a language-independant
                way. See http://code.google.com/apis/gmail/imap/#xlist
                (Gmail specific) and RFC-6154.
            source: string - Filter messages by the account source label.
            file_name: string - Search for files based on their name. You can
                filter names using typical shell wildcards such as *, ? and []
                or regular expressions by enclosing the search expression in a
                leading / and trailing /. For example, *.pdf would give you
                all PDF files while /\.jpe?g$/ would return all files whose
                name ends with .jpg or .jpeg
            file_size_min: integer - Search for files based on their size (in bytes).
            file_size_max: integer - Search for files based on their size (in bytes).
            date_before: integer (unix time) - Only include messages before a
                given timestamp. The value this filter is applied to is the
                Date: header of the message which refers to the time the
                message is sent from the origin.
            date_after: integer (unix time) - Only include messages after a
                given timestamp. The value this filter is applied to is the
                Date: header of the message which refers to the time the
                message is sent from the origin.
            indexed_before: integer (unix time) - Only include messages
                indexed before a given timestamp. This is not the same as the
                date of the email, it is the time Context.IO indexed this
                message.
            indexed_after: integer (unix time) - Only include messages indexed
                after a given timestamp. This is not the same as the date of
                the email, it is the time Context.IO indexed this message.
            include_thread_size: integer - Set to 1 to include thread size in the result.
            include_body: integer - Set to 1 to include message bodies in the
                result. Since message bodies must be retrieved from the IMAP
                server, expect a performance hit when setting this parameter.
            include_headers: mixed - Can be set to 0 (default), 1 or raw. If
                set to 1, complete message headers, parsed into an array, are
                included in the results. If set to raw, the headers are also
                included but as a raw unparsed string. Since full original
                headers bodies must be retrieved from the IMAP server, expect
                a performance hit when setting this parameter.
            include_flags: integer - Set to 1 to include IMAP flags of
                messages in the result. Since message flags must be retrieved
                from the IMAP server, expect a performance hit when setting
                this parameter.
            body_type: string - Used when include_body is set to get only body
                parts of a given MIME-type (for example text/html)
            include_source: integer - Set to 1 to include message sources in the
                result. Since message sources must be retrieved from the IMAP server,
                expect a performance hit when setting this parameter.
            sort_order: string - The sort order of the returned results.
                Possible values are asc and desc
            limit: integer - The maximum number of results to return.
            offset: integer - Start the list at this offset (zero-based).

        Returns:
            A list of Message objects.
        """
        all_args = [
            "subject", "email", "to", "sender", "from_", "cc", "bcc", "folder",
            "date_before", "date_after", "indexed_before", "indexed_after",
            "include_thread_size", "include_body", "source", "file_name",
            "file_size_min", "file_size_max", "include_source",
            "include_headers", "include_flags", "body_type", "sort_order",
            "limit", "offset"
        ]

        params = helpers.sanitize_params(params, all_args)

        # workaround to send param "from" even though it's a reserved keyword
        # in python
        if 'sender' in params:
            params['from'] = params['sender']
            del params['sender']

        if 'from_' in params:
            params['from'] = params['from_']
            del params['from_']

        return [
            Message(self, obj)
            for obj in self._request_uri('messages', params=params)
        ]
Beispiel #52
0
    def get_files(self, **params):
        """List of files found as email attachments.

        GET method for the files resource.

        Documentation: http://context.io/docs/2.0/accounts/files

        Each of the email, to, from, cc and bcc parameters can be set to a
        comma-separated list of email addresses. These multiple addresses
        are treated as an OR combination.

        You can set more than one parameter when doing this call. Multiple
        parameters are treated as an AND combination.

        Optional Arguments:
            file_name: string - Search for files based on their name. You can
                filter names using typical shell wildcards such as *, ? and []
                or regular expressions by enclosing the search expression in a
                leading / and trailing /. For example, *.pdf would give you
                all PDF files while /\.jpe?g$/ would return all files whose
                name ends with .jpg or .jpeg
            file_size_min: integer - Search for files based on their size (in bytes).
            file_size_max: integer - Search for files based on their size (in bytes).
            email: string - Email address of the contact for whom you want the
                latest files exchanged with. By "exchanged with contact X" we
                mean any email received from contact X, sent to contact X or
                sent by anyone to both contact X and the source owner.
            to: string - Email address of a contact files have been sent to.
            from: string - Email address of a contact files have been received
                from.
            cc: string - Email address of a contact CC'ed on the messages.
            bcc: string - Email address of a contact BCC'ed on the messages.
            date_before: integer (unix time) - Only include files attached to
                messages sent before a given timestamp. The value this filter
                is applied to is the Date: header of the message which refers
                to the time the message is sent from the origin.
            date_after: integer (unix time) - Only include files attached to
                messages sent after a given timestamp. The value this filter
                is applied to is the Date: header of the message which refers
                to the time the message is sent from the origin.
            indexed_before: integer (unix time) - Only include files attached
                to messages indexed before a given timestamp. This is not the
                same as the date of the email, it is the time Context.IO
                indexed this message.
            indexed_after: integer (unix time) - Only include files attached
                to messages indexed after a given timestamp. This is not the
                same as the date of the email, it is the time Context.IO
                indexed this message.
            source: string - Filter messages by the account source label.
            sort_order: string - The sort order of the returned results.
                Possible values are asc and desc
            limit: integer - The maximum number of results to return.
            offset: integer - Start the list at this offset (zero-based).

        Returns:
            A list of File objects
        """
        all_args = [
            'file_name', 'file_size_min', 'file_size_max', 'email', 'to',
            'from', 'cc', 'bcc', 'date_before', 'date_after', 'indexed_before',
            'indexed_after', 'source', 'limit', 'offset'
        ]

        params = helpers.sanitize_params(params, all_args)

        return [
            File(self, obj)
            for obj in self._request_uri('files', params=params)
        ]
Beispiel #53
0
    def get_users(self, **kwargs):
        all_args = ["email", "status", "status_ok", "limit", "offset"]

        params = sanitize_params(kwargs, all_args)
        return [User(self, obj) for obj in self._request_uri("users", params=params)]
Beispiel #54
0
    def get_files(self, **params):
        """List of files found as email attachments.

        GET method for the files resource.

        Documentation: http://context.io/docs/2.0/accounts/files

        Each of the email, to, from, cc and bcc parameters can be set to a
        comma-separated list of email addresses. These multiple addresses
        are treated as an OR combination.

        You can set more than one parameter when doing this call. Multiple
        parameters are treated as an AND combination.

        Optional Arguments:
            file_name: string - Search for files based on their name. You can
                filter names using typical shell wildcards such as *, ? and []
                or regular expressions by enclosing the search expression in a
                leading / and trailing /. For example, *.pdf would give you
                all PDF files while /\.jpe?g$/ would return all files whose
                name ends with .jpg or .jpeg
            file_size_min: integer - Search for files based on their size (in bytes).
            file_size_max: integer - Search for files based on their size (in bytes).
            email: string - Email address of the contact for whom you want the
                latest files exchanged with. By "exchanged with contact X" we
                mean any email received from contact X, sent to contact X or
                sent by anyone to both contact X and the source owner.
            to: string - Email address of a contact files have been sent to.
            from: string - Email address of a contact files have been received
                from.
            cc: string - Email address of a contact CC'ed on the messages.
            bcc: string - Email address of a contact BCC'ed on the messages.
            date_before: integer (unix time) - Only include files attached to
                messages sent before a given timestamp. The value this filter
                is applied to is the Date: header of the message which refers
                to the time the message is sent from the origin.
            date_after: integer (unix time) - Only include files attached to
                messages sent after a given timestamp. The value this filter
                is applied to is the Date: header of the message which refers
                to the time the message is sent from the origin.
            indexed_before: integer (unix time) - Only include files attached
                to messages indexed before a given timestamp. This is not the
                same as the date of the email, it is the time Context.IO
                indexed this message.
            indexed_after: integer (unix time) - Only include files attached
                to messages indexed after a given timestamp. This is not the
                same as the date of the email, it is the time Context.IO
                indexed this message.
            source: string - Filter messages by the account source label.
            sort_order: string - The sort order of the returned results.
                Possible values are asc and desc
            limit: integer - The maximum number of results to return.
            offset: integer - Start the list at this offset (zero-based).

        Returns:
            A list of File objects
        """
        all_args = [
            'file_name', 'file_size_min', 'file_size_max', 'email', 'to', 'from', 'cc', 'bcc',
            'date_before', 'date_after', 'indexed_before', 'indexed_after', 'source', 'limit',
            'offset'
        ]

        params = helpers.sanitize_params(params, all_args)

        return [File(self, obj) for obj in self._request_uri('files', params=params)]
Beispiel #55
0
    def get_messages(self, **params):
        """List email messages for an account.

        GET method for the messages resource.

        Each of the email, to, from, cc and bcc parameters can be set to a
        comma-separated list of email addresses. These multiple addresses
        are treated as an OR combination.

        You can set more than one parameter when doing this call. Multiple
        parameters are treated as an AND combination.

        Optional Arguments:
            subject: string - Get messages whose subject matches this search
                string. To use regular expressions instead of simple string
                matching, make sure the string starts and ends with /.
            email: string - Email address of the contact for whom you want the
                latest messages exchanged with. By "exchanged with contact X"
                we mean any email received from contact X, sent to contact X
                or sent by anyone to both contact X and the source owner.
            to: string - Email address of a contact messages have been sent to.
            sender: string - Email address of a contact messages have been
                received from. Same as "from" in documentation. "from" is a
                python keyword and we can't use that...
            cc: string - Email address of a contact CC'ed on the messages.
            bcc: string - Email address of a contact BCC'ed on the messages.
            folder: string - Filter messages by the folder (or Gmail label).
                This parameter can be the complete folder name with the
                appropriate hierarchy delimiter for the mail server being
                queried (eg. Inbox/My folder) or the "symbolic name" of the
                folder (eg. \Starred). The symbolic name refers to attributes
                used to refer to special use folders in a language-independant
                way. See http://code.google.com/apis/gmail/imap/#xlist
                (Gmail specific) and RFC-6154.
            source: string - Filter messages by the account source label.
            file_name: string - Search for files based on their name. You can
                filter names using typical shell wildcards such as *, ? and []
                or regular expressions by enclosing the search expression in a
                leading / and trailing /. For example, *.pdf would give you
                all PDF files while /\.jpe?g$/ would return all files whose
                name ends with .jpg or .jpeg
            file_size_min: integer - Search for files based on their size (in bytes).
            file_size_max: integer - Search for files based on their size (in bytes).
            date_before: integer (unix time) - Only include messages before a
                given timestamp. The value this filter is applied to is the
                Date: header of the message which refers to the time the
                message is sent from the origin.
            date_after: integer (unix time) - Only include messages after a
                given timestamp. The value this filter is applied to is the
                Date: header of the message which refers to the time the
                message is sent from the origin.
            indexed_before: integer (unix time) - Only include messages
                indexed before a given timestamp. This is not the same as the
                date of the email, it is the time Context.IO indexed this
                message.
            indexed_after: integer (unix time) - Only include messages indexed
                after a given timestamp. This is not the same as the date of
                the email, it is the time Context.IO indexed this message.
            include_thread_size: integer - Set to 1 to include thread size in the result.
            include_body: integer - Set to 1 to include message bodies in the
                result. Since message bodies must be retrieved from the IMAP
                server, expect a performance hit when setting this parameter.
            include_headers: mixed - Can be set to 0 (default), 1 or raw. If
                set to 1, complete message headers, parsed into an array, are
                included in the results. If set to raw, the headers are also
                included but as a raw unparsed string. Since full original
                headers bodies must be retrieved from the IMAP server, expect
                a performance hit when setting this parameter.
            include_flags: integer - Set to 1 to include IMAP flags of
                messages in the result. Since message flags must be retrieved
                from the IMAP server, expect a performance hit when setting
                this parameter.
            body_type: string - Used when include_body is set to get only body
                parts of a given MIME-type (for example text/html)
            include_source: integer - Set to 1 to include message sources in the
                result. Since message sources must be retrieved from the IMAP server,
                expect a performance hit when setting this parameter.
            sort_order: string - The sort order of the returned results.
                Possible values are asc and desc
            limit: integer - The maximum number of results to return.
            offset: integer - Start the list at this offset (zero-based).

        Returns:
            A list of Message objects.
        """
        all_args = [
            "subject", "email", "to", "sender", "from_", "cc", "bcc", "folder", "date_before",
            "date_after", "indexed_before", "indexed_after", "include_thread_size", "include_body",
            "source", "file_name", "file_size_min", "file_size_max", "include_source",
            "include_headers", "include_flags", "body_type", "sort_order",
            "limit", "offset"
        ]

        params = helpers.sanitize_params(params, all_args)

        # workaround to send param "from" even though it's a reserved keyword
        # in python
        if 'sender' in params:
            params['from'] = params['sender']
            del params['sender']

        if 'from_' in params:
            params['from'] = params['from_']
            del params['from_']

        return [
            Message(self, obj) for obj in self._request_uri('messages', params=params)]
Beispiel #56
0
    def post_account(self, **params):
        """Add a new account.

        POST method for the accounts resource.

        You can optionally pass in the params to simultaneously add a source
        with just this one call. In order to accomplish this you must include all of the
        required parameters to create a source AS WELL AS one of the following:
            - the password for the source
            - the provider_refresh_token AND provider_consumer_key

            *see https://context.io/docs/2.0/accounts/sources#post for more information*

        Documentation: http://context.io/docs/2.0/accounts#post

        Required Arguments:
            email: string - The primary email address of the account holder.
            migrate_account_id: string - Existing user_id (from lite) you want
               to migrate to 2.0. Either migrate_account_id or email must be specified

        Optional Arguments:
            first_name: string - First name of the account holder.
            last_name: string - Last name of the account holder.

        If adding a source in the same call:
        Required Arguments:
            server: string - Name or IP of the IMAP server, eg. imap.gmail.com
            username: string - The username used to authenticate an IMAP
                connection. On some servers, this is the same thing as
                the primary email address.
            use_ssl: integer - Set to 1 if you want SSL encryption to
                be used when opening connections to the IMAP server. Any
                other value will be considered as "do not use SSL"
            port: integer - Port number to connect to on the server. Keep in
                mind that most IMAP servers will have one port for standard
                connection and another one for encrypted connection (see
                use-ssl parameter above)
            type: string - Currently, the only supported type is IMAP

        Optional Arguments:
            origin_ip: string - IP address of the end user requesting the account
                to be created
            expunge_on_deleted_flag: integer - By default, we don't filter out messages
                flagged as deleted. Set this parameter to 1 to turn on this filtering.
            sync_all_folders: integer - By default, we filter out some folders like
                'Deleted Items' and 'Drafts'. Set this parameter to 1 to turn off this
                filtering and show every single folder.
            sync_folders: string - By default, we filter out some folders like
                'Deleted Items' and 'Drafts'. Set this parameter to
                'All,Trash' to show the 'Deleted Items' folder.
            sync_flags:  integer By default, we don't synchronize IMAP flags.
                Set this parameter to 1 to turn on IMAP flag syncing for the 'seen' and
                'flagged' flags.
            raw_file_list: integer - By default, we filter out files like
                signature images or those winmail.dat files form the files
                list. Set this parameter to 1 to turn off this filtering and
                show every single file attachments.
            password: string - Password for authentication on the IMAP server.
                Ignored if any of the provider_* parameters are set below.
            provider_refresh_token: An OAuth2 refresh token obtained from the
                IMAP account provider to be used to authenticate on this email
                account.
            provider_consumer_key: string - The OAuth consumer key used to
                obtain the the token and token secret above for that account.
                That consumer key and secret must be configured in your
                Context.IO account.
            callback_url: string (url) - If specified, we'll make a POST
                request to this URL when the initial sync is completed.
                status_callback_url: string (url) - If specified, we'll make a POST
                request to this URL if the connection status of the source changes.

        Returns:
            An Account object
        """
        req_args = ["email"]
        all_args = ["email", "migrate_account_id", "first_name", "last_name", "server",
            "username", "use_ssl", "port", "type", "origin_ip", "expunge_on_deleted_flag",
            "sync_all_folders", "sync_folders", "sync_flags", "raw_file_list", "password",
            "provider_refresh_token", "provider_consumer_key", "callback_url", "status_callback_url"
        ]

        params = helpers.sanitize_params(params, all_args, req_args)

        return Account(self, self._request_uri("accounts", method="POST", params=params))
Beispiel #57
0
    def get_threads(self, **params):
        """List of threads on an account.

        Documentation: http://context.io/docs/2.0/accounts/threads#get

        Optional Arguments:
            subject: string - Get threads with messages whose subject matches
                this search string. To use regular expressions instead of
                simple string matching, make sure the string starts and ends
                with /.
            email: string - Email address of the contact for whom you want the
                latest threads. This value is interpreted as received from
                email X, sent to email X or sent by anyone to both email X and
                the source owner.
            to: string - Get threads with at least one message sent to this
                email address.
            sender: string - Get threads with at least one message sent from
                this email address.
            cc: string - Get threads with at least one message having this
                email address CC'ed.
            bcc: string - Get threads with at least one message having this
                email address BCC'ed.
            folder: string - Filter threads by the folder (or Gmail label).
                This parameter can be the complete folder name with the
                appropriate hierarchy delimiter for the mail server being
                queried (eg. Inbox/My folder) or the "symbolic name" of the
                folder (eg. \Starred). The symbolic name refers to attributes
                used to refer to special use folders in a language-independant
                way. See http://code.google.com/apis/gmail/imap/#xlist (Gmail
                specific) and RFC-6154.
            indexed_before: integer (unix time) - Get threads with at least
                one message indexed before this timestamp. This is not the
                same as the date of the email, it is the time Context.IO
                indexed this message.
            indexed_after: integer (unix time) - Get threads with at least one
                message indexed after this timestamp. This is not the same as
                the date of the email, it is the time Context.IO indexed this
                message.
            active_before: integer (unix time) - Get threads with at least one
                message dated before this timestamp. The value this filter is
                applied to is the Date: header of the message which refers to
                the time the message is sent from the origin.
            active_after: integer (unix time) - Get threads with at least one
                message dated after this timestamp. The value this filter is
                applied to is the Date: header of the message which refers to
                the time the message is sent from the origin.
            started_before: integer (unix time) - Get threads whose first
                message is dated before this timestamp. The value this filter
                is applied to is the Date: header of the message which refers
                to the time the message is sent from the origin.
            started_after: integer (unix time) - Get threads whose first
                message is dated after this timestamp. The value this filter
                is applied to is the Date: header of the message which refers
                to the time the message is sent from the origin.
            limit: integer - The maximum number of results to return.
            offset: integer - Start the list at this offset (zero-based).

        Returns:
            A list of Thread objects (nearly empty thread objects). Use the
                Thread.get() method to populate the object.
        """
        all_args = [
            'subject', 'email', 'to', 'sender', 'from_', 'cc', 'bcc', 'folder',
            'indexed_before', 'indexed_after', 'active_before', 'active_after',
            'started_before', 'started_after', 'limit', 'offset'
        ]
        params = helpers.sanitize_params(params, all_args)

        # workaround to send param "from" even though it's a reserved keyword
        # in python
        if 'sender' in params:
            params['from'] = params['sender']
            del params['sender']

        if 'from_' in params:
            params['from'] = params['from_']
            del params['from_']

        thread_urls = self._request_uri('threads', params=params)
        objs = []

        # isolate just the gmail_thread_id so we can instantiate Thread objects
        for thread_url in thread_urls:
            url_components = thread_url.split('/')
            objs.append({'gmail_thread_id': url_components[-1]})

        return [Thread(self, obj) for obj in objs]
Beispiel #58
0
    def get_email_accounts(self, **params):
        all_args = ["status", "status_ok"]

        params = sanitize_params(params, all_args)

        return [EmailAccount(self, obj) for obj in self._request_uri("email_accounts", params=params)]