use of com.zimbra.cs.mailbox.MailItem.CustomMetadata in project zm-mailbox by Zimbra.
the class SetCustomData method deserializeData.
@Override
protected void deserializeData(RedoLogInput in) throws IOException {
this.itemId = in.readInt();
this.type = MailItem.Type.of(in.readByte());
try {
String extendedKey = in.readUTF();
this.custom = new CustomMetadata(extendedKey, in.readUTF());
} catch (ServiceException e) {
mLog.warn("could not deserialize custom metadata for folder", e);
}
}
use of com.zimbra.cs.mailbox.MailItem.CustomMetadata in project zm-mailbox by Zimbra.
the class SetCustomMetadata method handle.
@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
ZimbraSoapContext zsc = getZimbraSoapContext(context);
Mailbox mbox = getRequestedMailbox(zsc);
OperationContext octxt = getOperationContext(zsc, context);
ItemIdFormatter ifmt = new ItemIdFormatter(zsc);
Element meta = request.getElement(MailConstants.E_METADATA);
String section = meta.getAttribute(MailConstants.A_SECTION);
section = section.trim();
if (section.length() == 0 || section.length() > 36)
throw ServiceException.INVALID_REQUEST("invalid length for custom metadata section name", null);
CustomMetadata custom = new CustomMetadata(section);
for (Element.KeyValuePair kvp : meta.listKeyValuePairs()) custom.put(kvp.getKey(), kvp.getValue());
ItemId iid = new ItemId(request.getAttribute(MailConstants.A_ID), zsc);
mbox.setCustomData(octxt, iid.getId(), MailItem.Type.UNKNOWN, custom);
Element response = zsc.createElement(MailConstants.SET_METADATA_RESPONSE);
response.addAttribute(MailConstants.A_ID, ifmt.formatItemId(iid));
return response;
}
use of com.zimbra.cs.mailbox.MailItem.CustomMetadata in project zm-mailbox by Zimbra.
the class CreateFolder method deserializeData.
@Override
protected void deserializeData(RedoLogInput in) throws IOException {
this.name = in.readUTF();
this.parentId = in.readInt();
if (getVersion().atLeast(1, 19)) {
this.attrs = in.readByte();
}
this.defaultView = MailItem.Type.of(in.readByte());
this.flags = in.readInt();
if (getVersion().atLeast(1, 27)) {
this.color = in.readLong();
} else {
this.color = in.readByte();
}
this.url = in.readUTF();
this.folderId = in.readInt();
if (getVersion().atLeast(1, 37)) {
this.folderUuid = in.readUTF();
}
if (getVersion().atLeast(1, 39)) {
if (in.readBoolean()) {
if (getVersion().atLeast(1, 40)) {
this.date = in.readLong();
} else {
this.date = ((long) in.readInt()) * 1000;
}
}
}
if (getVersion().atLeast(1, 41)) {
String section = in.readUTF();
if (section != null) {
try {
this.custom = new CustomMetadata(section, in.readUTF());
} catch (ServiceException e) {
mLog.warn("could not deserialize custom metadata for folder", e);
}
}
}
}
use of com.zimbra.cs.mailbox.MailItem.CustomMetadata in project zm-mailbox by Zimbra.
the class FolderTest method create.
@Test
public void create() throws Exception {
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
final String uuid = UUIDUtil.generateUUID();
final String url = "https://www.google.com/calendar/dav/YOUREMAIL@DOMAIN.COM/user";
final long date = ((System.currentTimeMillis() - Constants.MILLIS_PER_MONTH) / 1000) * 1000;
Folder.FolderOptions fopt = new Folder.FolderOptions();
fopt.setAttributes(Folder.FOLDER_DONT_TRACK_COUNTS);
fopt.setColor((byte) 3);
fopt.setCustomMetadata(new CustomMetadata("s", "d1:a1:be"));
fopt.setDate(date);
fopt.setDefaultView(MailItem.Type.CONTACT);
fopt.setFlags(Flag.BITMASK_CHECKED);
fopt.setUuid(uuid);
// setting folder sync URL triggers an error in MockProvisioning; comment out for now
// fopt.setUrl(url);
// create the folder and make sure all the options were applied
Folder folder = mbox.createFolder(null, "test", Mailbox.ID_FOLDER_CONTACTS, fopt);
Assert.assertEquals("correct name", "test", folder.getName());
Assert.assertEquals("correct parent", Mailbox.ID_FOLDER_CONTACTS, folder.getFolderId());
Assert.assertEquals("correct attributes", Folder.FOLDER_DONT_TRACK_COUNTS, folder.getAttributes());
Assert.assertEquals("correct color", 3, folder.getColor());
CustomMetadata custom = folder.getCustomData("s");
Assert.assertNotNull("custom data set", custom);
Assert.assertEquals("1 entry in custom data", 1, custom.size());
Assert.assertEquals("correct custom data", "b", custom.get("a"));
Assert.assertEquals("correct date", date, folder.getDate());
Assert.assertEquals("correct view", MailItem.Type.CONTACT, folder.getDefaultView());
Assert.assertEquals("correct flags", Flag.BITMASK_CHECKED, folder.getFlagBitmask());
Assert.assertEquals("correct uuid", uuid, folder.getUuid());
// Assert.assertEquals("correct url", url, folder.getUrl());
// check again after forcing a reload from disk, just in case
mbox.purge(MailItem.Type.FOLDER);
folder = mbox.getFolderById(null, folder.getId());
Assert.assertEquals("correct name", "test", folder.getName());
Assert.assertEquals("correct parent", Mailbox.ID_FOLDER_CONTACTS, folder.getFolderId());
Assert.assertEquals("correct attributes", Folder.FOLDER_DONT_TRACK_COUNTS, folder.getAttributes());
Assert.assertEquals("correct color", 3, folder.getColor());
custom = folder.getCustomData("s");
Assert.assertNotNull("custom data set", custom);
Assert.assertEquals("1 entry in custom data", 1, custom.size());
Assert.assertEquals("correct custom data", "b", custom.get("a"));
Assert.assertEquals("correct date", date, folder.getDate());
Assert.assertEquals("correct view", MailItem.Type.CONTACT, folder.getDefaultView());
Assert.assertEquals("correct flags", Flag.BITMASK_CHECKED, folder.getFlagBitmask());
Assert.assertEquals("correct uuid", uuid, folder.getUuid());
// Assert.assertEquals("correct url", url, folder.getUrl());
}
use of com.zimbra.cs.mailbox.MailItem.CustomMetadata in project zm-mailbox by Zimbra.
the class CreateMessage method deserializeData.
@Override
protected void deserializeData(RedoLogInput in) throws IOException {
mRcptEmail = in.readUTF();
if (getVersion().atLeast(1, 4)) {
mReceivedDate = in.readLong();
} else {
mReceivedDate = getTimestamp();
}
mShared = in.readBoolean();
mDigest = in.readUTF();
if (getVersion().atLeast(1, 42)) {
mMsgSize = in.readLong();
} else {
mMsgSize = in.readInt();
}
mMsgId = in.readInt();
mFolderId = in.readInt();
mConvId = in.readInt();
if (getVersion().atLeast(1, 5)) {
mConvFirstMsgId = in.readInt();
}
if (getVersion().atLeast(1, 32)) {
int mergeCount = in.readInt();
mMergedConvIds = new ArrayList<Integer>(mergeCount);
for (int i = 0; i < mergeCount; i++) {
mMergedConvIds.add(in.readInt());
}
}
mCalendarItemId = in.readInt();
if (getVersion().atLeast(1, 1)) {
mCalendarItemPartStat = in.readUTF();
}
mFlags = in.readInt();
mNoICal = in.readBoolean();
if (getVersion().atLeast(1, 33)) {
mTags = in.readUTFArray();
} else {
mTagIds = in.readUTF();
}
mPath = in.readUTF();
in.readShort();
if (getVersion().atLeast(1, 25)) {
String extendedKey = in.readUTF();
if (extendedKey != null) {
try {
mExtendedData = new CustomMetadata(extendedKey, in.readUTF());
} catch (ServiceException e) {
mLog.warn("could not deserialize custom metadata for message", e);
}
}
}
mMsgBodyType = in.readByte();
if (mMsgBodyType == MSGBODY_INLINE) {
int dataLength = in.readInt();
boolean inMemory = false;
try {
inMemory = dataLength <= StoreManager.getDiskStreamingThreshold();
} catch (ServiceException e) {
}
// mData must be the last thing deserialized. See comments in serializeData()
if (inMemory) {
byte[] data = new byte[dataLength];
in.readFully(data, 0, dataLength);
mData = new RedoableOpData(data);
} else {
long pos = in.getFilePointer();
mData = new RedoableOpData(new File(in.getPath()), pos, dataLength);
// Now that we have a stream to the data, skip to the next op.
int numSkipped = in.skipBytes(dataLength);
if (numSkipped != dataLength) {
String msg = String.format("Attempted to skip %d bytes at position %d in %s, but actually skipped %d.", dataLength, pos, in.getPath(), numSkipped);
throw new IOException(msg);
}
}
// Blob data must be the last thing deserialized. See comments in
// serializeData().
} else {
in.readShort();
}
}
Aggregations