Skip to content
This repository was archived by the owner on Jun 7, 2023. It is now read-only.

Commit 07bacff

Browse files
author
Rustam Aliyev
committed
Optionally get message bodies along with metadata. #50
1 parent e5b0d5c commit 07bacff

File tree

6 files changed

+31
-12
lines changed

6 files changed

+31
-12
lines changed

itests/src/test/java/com/elasticinbox/itests/RestV2IT.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright (c) 2011-2013 Optimax Software Ltd.
2+
* Copyright (c) 2011-2014 Optimax Software Ltd.
33
* All rights reserved.
44
*
55
* Redistribution and use in source and binary forms, with or without
@@ -342,13 +342,29 @@ public void messageAddListViewDeletePurgeTest() throws IOException
342342
body(messageId + ".to.address", hasItems(containsString("@"))).
343343
body(messageId + ".replyTo.address", hasItems(containsString("@"))).
344344
body(messageId + ".messageId", containsString("@elasticinbox")).
345-
body(messageId + ".subject", is(notNullValue())).
345+
body(messageId + ".subject", not(isEmptyOrNullString())).
346+
body(messageId, not(hasKey("htmlBody"))).
347+
body(messageId, not(hasKey("plainBody"))).
346348
body(messageId, not(hasKey("bcc"))).
347349
when().
348350
get(REST_PATH + "/mailbox/label/{labelId}?metadata=true&count=2&start={messageId}");
349351

350352
logger.info("Message List with Metadata Test OK");
351353

354+
// check message list with bodies
355+
messageId = messages.get("headers").toString();
356+
given().
357+
pathParam("labelId", labelId).
358+
pathParam("messageId", messageId).
359+
expect().
360+
statusCode(200).and().
361+
body(messageId + ".htmlBody", not(isEmptyOrNullString())).
362+
body(messageId + ".plainBody", not(isEmptyOrNullString())).
363+
when().
364+
get(REST_PATH + "/mailbox/label/{labelId}?metadata=true&includebody=true&count=2&start={messageId}");
365+
366+
logger.info("Message List with Metadata & Bodies Test OK");
367+
352368
// check parsed message
353369
messageId = messages.get("headers").toString();
354370
given().

itests/src/test/resources/elasticinbox.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ database_driver: cassandra
3838
# Note: When no HTML message body available in HTML store mode, ElasticInbox
3939
# will automatically fallback to PLAIN text mode and store available PLAIN text.
4040
store_html_message: true
41-
store_plain_message: false
41+
store_plain_message: true
4242

4343
# Maximum blob size in bytes which can be stored in the database.
4444
# Blobs larger than this value will be stored with the deafult blob profile (blobstore_write_profile).

modules/core/src/main/java/com/elasticinbox/core/MessageDAO.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,12 @@ public List<UUID> getMessageIds(Mailbox mailbox, int labelId, UUID start,
120120
* Number of message IDs to retrieve.
121121
* @param reverse
122122
* Defines order of the retrieval.
123+
* @param includeBody
124+
* If true, return plainBody and htmlBody as a part of metadata.
123125
* @return
124126
*/
125-
public Map<UUID, Message> getMessageIdsWithHeaders(Mailbox mailbox, int labelId,
126-
UUID start, int count, boolean reverse);
127+
public Map<UUID, Message> getMessageIdsWithMetadata(Mailbox mailbox, int labelId,
128+
UUID start, int count, boolean reverse, boolean includeBody);
127129

128130
/**
129131
* Modify message labels and markers.

modules/core/src/main/java/com/elasticinbox/core/cassandra/CassandraMessageDAO.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,13 +111,13 @@ public BlobDataSource getRaw(final Mailbox mailbox, final UUID messageId)
111111
}
112112

113113
@Override
114-
public Map<UUID, Message> getMessageIdsWithHeaders(final Mailbox mailbox,
115-
final int labelId, final UUID start, final int count, boolean reverse)
114+
public Map<UUID, Message> getMessageIdsWithMetadata(final Mailbox mailbox,
115+
final int labelId, final UUID start, final int count, boolean reverse, boolean includeBody)
116116
{
117117
List<UUID> messageIds =
118118
getMessageIds(mailbox, labelId, start, count, reverse);
119119

120-
return MessagePersistence.fetch(mailbox.getId(), messageIds, false);
120+
return MessagePersistence.fetch(mailbox.getId(), messageIds, includeBody);
121121
}
122122

123123
@Override

modules/pop3/src/main/java/com/elasticinbox/pop3/server/handler/ElasticInboxMailboxHandler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,8 @@ public InputStream getMessageHeaders(String uid) throws IOException
153153
private List<MessageMetaData> getPOP3MessageList()
154154
{
155155
// get list of messages
156-
Map<UUID, Message> messages = dao.getMessageIdsWithHeaders(
157-
mailbox, ReservedLabels.POP3.getId(), null, MAX_POP3_SESSION_MESSAGES, true);
156+
Map<UUID, Message> messages = dao.getMessageIdsWithMetadata(
157+
mailbox, ReservedLabels.POP3.getId(), null, MAX_POP3_SESSION_MESSAGES, true, false);
158158

159159
// convert to James Protocols list
160160
List<MessageMetaData> list = new ArrayList<MessageMetaData>(messages.size());

modules/rest/src/main/java/com/elasticinbox/rest/v2/LabelResource.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ public Response getMessages(
105105
@PathParam("domain") String domain,
106106
@PathParam("id") Integer labelId,
107107
@QueryParam("metadata") @DefaultValue("false") boolean withMetadata,
108+
@QueryParam("includebody") @DefaultValue("false") boolean includeBody,
108109
@QueryParam("reverse") @DefaultValue("true") boolean reverse,
109110
@QueryParam("start") UUID start,
110111
@QueryParam("count") @DefaultValue("50") int count)
@@ -114,8 +115,8 @@ public Response getMessages(
114115

115116
try {
116117
if (withMetadata) {
117-
response = JSONUtils.fromObject(messageDAO.getMessageIdsWithHeaders(mailbox,
118-
labelId, start, count, reverse));
118+
response = JSONUtils.fromObject(messageDAO.getMessageIdsWithMetadata(mailbox,
119+
labelId, start, count, reverse, includeBody));
119120
} else {
120121
response = JSONUtils.fromObject(messageDAO.getMessageIds(mailbox,
121122
labelId, start, count, reverse));

0 commit comments

Comments
 (0)