113
113
'date': message.get('date'),
114
114
'from': message.get('from'),
115
115
'subject': message.get('subject'),
116
'message-id': message.get('message-id'),
119
def _trim(self, sequence, end):
125
def get_messages(self, archive_uuid, order, count, memo, backward=False):
118
def get_messages(self, archive_uuid, order, count, start):
126
119
if order in ("date", "-date"):
127
120
reversed = order[0] == '-'
129
122
raise AssertionError("Unsupported order.")
131
memo = uuid.UUID(memo)
132
# Get up to n+1 messages from the memo: the last item of the
133
# previous batch (because that's where the memo starts) + this
141
123
pairs = self.archive_messages.get(
142
archive_uuid, column_count=count + 1, column_start=start,
143
column_finish=finish, column_reversed=reversed).items()
144
if memo and len(pairs) and pairs[0][0] <= memo:
145
pairs = self._trim(pairs, False ^ backward)
146
elif len(pairs) > count:
147
pairs = self._trim(pairs, True ^ backward)
150
return (None, [], None)
152
assert 0 < len(pairs) <= count
124
archive_uuid, column_count=count + 1,
125
column_start=start, column_reversed=reversed).items()
154
126
ids = [v for k, v in pairs]
155
127
messages = self.messages.multiget(
156
ids, columns=['date', 'from', 'subject', 'message-id'])
128
ids, columns=['date', 'from', 'subject'])
129
actual_count = len(pairs)
130
if len(pairs) > count:
131
assert len(pairs) == count + 1
133
next_memo = str(pairs[count][0])
160
[self._format_message(messages[id]) for id in ids],
137
[self._format_message(messages[id]) for id in ids[:actual_count]],