11/**
2- * Copyright (c) 2011-2012 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
@@ -61,6 +61,8 @@ public final class Marshaller
6161 public final static String CN_TO = "to" ;
6262 public final static String CN_CC = "cc" ;
6363 public final static String CN_BCC = "bcc" ;
64+ public final static String CN_REPLY_TO = "replyto" ;
65+ public final static String CN_MESSAGE_ID = "mid" ;
6466 public final static String CN_SUBJECT = "subject" ;
6567 public final static String CN_HTML_BODY = "html" ;
6668 public final static String CN_PLAIN_BODY = "plain" ;
@@ -93,15 +95,17 @@ protected static Message unmarshall(
9395
9496 for (HColumn <String , byte []> c : columns )
9597 {
96- if ( (c != null ) && ( c .getValue () != null )) {
97-
98+ if (c != null && c .getValue () != null )
99+ {
98100 // map columns to Message object
99101 if (c .getName ().equals (CN_DATE )) {
100102 message .setDate (dateSe .fromBytes (c .getValue ()));
101103 } else if (c .getName ().equals (CN_SIZE )) {
102104 message .setSize (longSe .fromBytes (c .getValue ()));
103105 } else if (c .getName ().equals (CN_SUBJECT )) {
104106 message .setSubject (strSe .fromBytes (c .getValue ()));
107+ } else if (c .getName ().equals (CN_MESSAGE_ID )) {
108+ message .setMessageId (strSe .fromBytes (c .getValue ()));
105109 } else if (c .getName ().equals (CN_FROM )) {
106110 message .setFrom (unserializeAddress (c .getValue ()));
107111 } else if (c .getName ().equals (CN_TO )) {
@@ -110,6 +114,8 @@ protected static Message unmarshall(
110114 message .setCc (unserializeAddress (c .getValue ()));
111115 } else if (c .getName ().equals (CN_BCC )) {
112116 message .setBcc (unserializeAddress (c .getValue ()));
117+ } else if (c .getName ().equals (CN_REPLY_TO )) {
118+ message .setReplyTo (unserializeAddress (c .getValue ()));
113119 } else if (c .getName ().equals (CN_BRI )) {
114120 message .setLocation (URI .create (
115121 strSe .fromBytes (c .getValue ())));
@@ -182,33 +188,42 @@ protected static List<HColumn<String, byte[]>> marshall(final Message m)
182188 columns .put (CN_BCC , serializeAddress (m .getBcc ()));
183189 }
184190
191+ if (m .getReplyTo () != null ) {
192+ columns .put (CN_REPLY_TO , serializeAddress (m .getReplyTo ()));
193+ }
194+
195+ if (m .getMessageId () != null ) {
196+ columns .put (CN_MESSAGE_ID , m .getMessageId ());
197+ }
198+
185199 if (m .getSubject () != null ) {
186200 columns .put (CN_SUBJECT , m .getSubject ());
187201 }
188202
189203 if (m .getLocation () != null ) {
190204 columns .put (CN_BRI , m .getLocation ().toString ());
191-
192205 }
193206
194207 if (m .getParts () != null ) {
195208 columns .put (CN_PARTS , JSONUtils .fromObject (m .getParts ()));
196209 }
197210
198211 // add markers
199- if (!m .getMarkers ().isEmpty ()) {
200- for (Marker marker : m .getMarkers ()) {
201- String cn = new StringBuilder (CN_MARKER_PREFIX )
202- .append (marker .toInt ()).toString ();
212+ if (!m .getMarkers ().isEmpty ())
213+ {
214+ for (Marker marker : m .getMarkers ())
215+ {
216+ String cn = CN_MARKER_PREFIX + marker .toInt ();
203217 columns .put (cn , new byte [0 ]);
204218 }
205219 }
206220
207221 // add labels
208- if (!m .getLabels ().isEmpty ()) {
209- for (Integer labelId : m .getLabels ()) {
210- String cn = new StringBuilder (CN_LABEL_PREFIX )
211- .append (labelId ).toString ();
222+ if (!m .getLabels ().isEmpty ())
223+ {
224+ for (Integer labelId : m .getLabels ())
225+ {
226+ String cn = CN_LABEL_PREFIX + labelId ;
212227 columns .put (cn , new byte [0 ]);
213228 }
214229 }
@@ -242,7 +257,8 @@ private static byte[] serializeAddress(final AddressList addresses)
242257 {
243258 List <String []> result = new ArrayList <String []>();
244259
245- for (Address address : addresses ) {
260+ for (Address address : addresses )
261+ {
246262 result .add (new String []{
247263 (address .getName () == null ? "" : address .getName ()),
248264 (address .getAddress () == null ? "" : address .getAddress ()) });
@@ -264,7 +280,7 @@ private static AddressList unserializeAddress(final byte[] val)
264280 List <List <String >> addresses = null ;
265281 addresses = JSONUtils .toObject (val , addresses );
266282
267- for (List <String > address : addresses ) {
283+ for (List <String > address : addresses ) {
268284 result .add (new Address (address .get (0 ), address .get (1 )));
269285 }
270286
@@ -284,7 +300,8 @@ protected static List<HColumn<String, byte[]>> mapToHColumns(
284300 List <HColumn <String , byte []>> columns =
285301 new ArrayList <HColumn <String , byte []>>(map .size ());
286302
287- for (Map .Entry <String , Object > a : map .entrySet ()) {
303+ for (Map .Entry <String , Object > a : map .entrySet ())
304+ {
288305 columns .add (createColumn (a .getKey (), SerializerTypeInferer
289306 .getSerializer (a .getValue ()).toBytes (a .getValue ()),
290307 strSe , byteSe ));
0 commit comments