9
from grackle.error import (
11
UnsupportedDisplayType,
10
class UnsupportedDisplayType(Exception):
11
"""Raised when an Unsupported display_type is requested."""
14
class UnsupportedOrder(Exception):
15
"""Raised when an Unsupported order is requested."""
18
SUPPORTED_DISPLAY_TYPES = (
65
74
raise Exception('!!')
67
def get_messages(self, archive_id, message_ids=None, date_range=None,
68
limit=None, memo=None, order=None, headers=None,
69
include_hidden=False, max_body_length=None,
76
def get_messages(self, archive_id, message_ids=None, limit=None,
77
memo=None, order=None, headers=None, display_type='all',
78
max_body_length=None, include_hidden=False):
71
79
"""Retrieve specified messages.
73
81
:param archive_id: The archive to retrieve messages from.
74
82
:param message_ids: (optional) Retrieve only messages with these ids.
75
:param date_range: Retrieve the messages from or between a range of
76
dates. Example: 2012-01-01..2012-01-31 retrieve all the messages
77
between the 01 and 31 of January, including message from 01
79
83
:param limit: The maximum number of messages to return. The server
80
84
may, at its discretion, return fewer.
81
85
:param memo: (optional) Opaque identifier describing the position in
88
92
:param headers: The headers to include in the message. Only headers
89
93
actually present in the message will be provided. If unspecified,
90
94
most headers will be included.
95
:param display_type: Adjust the message content to meet the needs of
96
the intended display. Valid values are:
97
all: (the default) include all message content.
98
text-only: include only plain/text parts; exclude all other parts.
99
headers-only: include only the message headers.
91
100
:param max_body_length: The maximum length for a message's body. When
92
101
multiple messages are nested (as with a thread), this applies to
93
102
each message's body, not the aggregate length of all messages'
95
104
:param include_hidden: If true, include messages that have been
96
105
flagged "hidden" in the results.
97
:param display_type: Adjust the message content to meet the needs of
98
the intended display. Valid values are:
99
all: (the default) include all message content.
100
text-only: include only plain/text parts; exclude all other parts.
101
headers-only: include only the message headers.
104
108
if message_ids is not None:
105
109
parameters['message_ids'] = message_ids
106
if date_range is not None:
107
parameters['date_range'] = date_range
108
110
if limit is not None:
109
111
parameters['limit'] = limit
110
112
if memo is not None:
113
115
parameters['order'] = order
114
116
if headers is not None:
115
117
parameters['headers'] = headers
118
if display_type not in SUPPORTED_DISPLAY_TYPES:
119
raise UnsupportedDisplayType
116
120
if max_body_length is not None:
117
121
parameters['max_body_length'] = max_body_length
118
parameters['display_type'] = display_type
119
122
parameters['include_hidden'] = include_hidden
120
123
query = {'parameters': simplejson.dumps(parameters)}
121
124
response = self._method_archive('GET', archive_id, query)
122
125
if response.status == httplib.BAD_REQUEST:
123
if response.reason == UnsupportedOrder.__doc__:
124
raise UnsupportedOrder
125
elif response.reason == UnsupportedDisplayType.__doc__:
126
raise UnsupportedDisplayType
127
elif response.reason == UnparsableDateRange.__doc__:
128
raise UnparsableDateRange
130
raise ValueError('Bad request')
126
raise UnsupportedOrder
131
127
data = response.read()
132
128
return simplejson.loads(data)