Beispiel #1
0
def format_output(transaction_data, include_body):
    response = {
        'id': transaction_data['public_id'],
        'object': 'message',
        'ns': transaction_data['namespace_public_id'],
        'subject': transaction_data['subject'],
        'from': transaction_data['from_addr'],
        'to': transaction_data['to_addr'],
        'cc': transaction_data['cc_addr'],
        'bcc': transaction_data['bcc_addr'],
        'date': transaction_data['received_date'],
        'thread': transaction_data['thread']['id'],
        'size': transaction_data['size'],
        # TODO(emfree): also store block/attachment info.
    }
    if include_body:
        response['body'] = transaction_data['sanitized_body']
    return cereal(response)
Beispiel #2
0
def format_output(transaction_data, include_body):
    response = {
        'id': transaction_data['public_id'],
        'object': 'message',
        'ns': transaction_data['namespace_public_id'],
        'subject': transaction_data['subject'],
        'from': transaction_data['from_addr'],
        'to': transaction_data['to_addr'],
        'cc': transaction_data['cc_addr'],
        'bcc': transaction_data['bcc_addr'],
        'date': transaction_data['received_date'],
        'thread': transaction_data['thread']['id'],
        'size': transaction_data['size'],
        # TODO(emfree): also store block/attachment info.
    }
    if include_body:
        response['body'] = transaction_data['sanitized_body']
    return cereal(response)
Beispiel #3
0
    def register_hook(self, namespace_id, parameters):
        """Register a new webhook.

        Parameters
        ----------
        namespace_id: int
            ID for the namespace to apply the webhook on.
        parameters: dictionary
            Dictionary of the hook parameters.
        """
        with session_scope() as db_session:
            lens = Lens(
                namespace_id=namespace_id,
                subject=parameters.get('subject'),
                thread_public_id=parameters.get('thread'),
                to_addr=parameters.get('to'),
                from_addr=parameters.get('from'),
                cc_addr=parameters.get('cc'),
                bcc_addr=parameters.get('bcc'),
                any_email=parameters.get('any_email'),
                started_before=parameters.get('started_before'),
                started_after=parameters.get('started_after'),
                last_message_before=parameters.get('last_message_before'),
                last_message_after=parameters.get('last_message_after'),
                filename=parameters.get('filename'))

            hook = Webhook(
                namespace_id=namespace_id,
                lens=lens,
                callback_url=parameters.get('callback_url'),
                failure_notify_url=parameters.get('failure_notify_url'),
                include_body=parameters.get('include_body', False),
                active=parameters.get('active', True),
                min_processed_id=self.minimum_id)

            db_session.add(hook)
            db_session.add(lens)
            db_session.commit()
            if hook.active:
                worker = WebhookWorker(hook)
                self.workers[namespace_id].add(worker)
                if not worker.started:
                    worker.start()
            return cereal(hook, pretty=True)
Beispiel #4
0
    def register_hook(self, namespace_id, parameters):
        """Register a new webhook.

        Parameters
        ----------
        namespace_id: int
            ID for the namespace to apply the webhook on.
        parameters: dictionary
            Dictionary of the hook parameters.
        """
        with session_scope() as db_session:
            lens = Lens(
                namespace_id=namespace_id,
                subject=parameters.get('subject'),
                thread_public_id=parameters.get('thread'),
                to_addr=parameters.get('to'),
                from_addr=parameters.get('from'),
                cc_addr=parameters.get('cc'),
                bcc_addr=parameters.get('bcc'),
                any_email=parameters.get('any_email'),
                started_before=parameters.get('started_before'),
                started_after=parameters.get('started_after'),
                last_message_before=parameters.get('last_message_before'),
                last_message_after=parameters.get('last_message_after'),
                filename=parameters.get('filename'))

            hook = Webhook(
                namespace_id=namespace_id,
                lens=lens,
                callback_url=parameters.get('callback_url'),
                failure_notify_url=parameters.get('failure_notify_url'),
                include_body=parameters.get('include_body', False),
                active=parameters.get('active', True),
                min_processed_id=self.minimum_id)

            db_session.add(hook)
            db_session.add(lens)
            db_session.commit()
            if hook.active:
                worker = WebhookWorker(hook)
                self.workers[namespace_id].add(worker)
                if not worker.started:
                    worker.start()
            return cereal(hook, pretty=True)