use of com.zimbra.cs.mailbox.MailItem.CustomMetadata.CustomMetadataList in project zm-mailbox by Zimbra.
the class Contact method encodeMetadata.
static Metadata encodeMetadata(Metadata meta, Color color, int metaVersion, int version, CustomMetadataList extended, Map<String, String> fields, List<Attachment> attachments) {
meta.put(Metadata.FN_FIELDS, new Metadata(fields));
if (attachments != null && !attachments.isEmpty()) {
MetadataList mlist = new MetadataList();
for (Attachment attach : attachments) mlist.add(attach.asMetadata());
meta.put(Metadata.FN_ATTACHMENTS, mlist);
}
return MailItem.encodeMetadata(meta, color, null, metaVersion, version, extended);
}
use of com.zimbra.cs.mailbox.MailItem.CustomMetadata.CustomMetadataList in project zm-mailbox by Zimbra.
the class Conversation method create.
static Conversation create(Mailbox mbox, int id, Message... msgs) throws ServiceException {
if (ZimbraLog.mailop.isDebugEnabled()) {
StringBuilder msgIds = new StringBuilder();
for (int i = 0; i < msgs.length; i++) {
msgIds.append(i > 0 ? "," : "").append(msgs[i].getId());
}
ZimbraLog.mailop.debug("Adding Conversation: id=%d, message(s): %s.", id, msgIds);
}
assert (id != Mailbox.ID_AUTO_INCREMENT && msgs.length > 0);
Arrays.sort(msgs, new Message.SortDateAscending());
int date = 0, unread = 0, flags = 0;
CustomMetadataList extended = null;
Set<String> tags = new HashSet<String>();
for (int i = 0; i < msgs.length; i++) {
Message msg = msgs[i];
if (msg == null) {
throw ServiceException.FAILURE("null Message in list", null);
}
date = Math.max(date, msg.mData.date);
unread += msg.mData.unreadCount;
flags |= msg.mData.getFlags();
for (String tag : msg.mData.getTags()) {
tags.add(tag);
}
extended = MetadataCallback.duringConversationAdd(extended, msg);
}
UnderlyingData data = new UnderlyingData();
data.id = id;
data.type = Type.CONVERSATION.toByte();
data.folderId = Mailbox.ID_FOLDER_CONVERSATIONS;
data.setSubject(msgs.length > 0 ? msgs[0].getSubject() : "");
data.date = date;
data.size = msgs.length;
data.unreadCount = unread;
data.setFlags(flags);
data.setTags(new Tag.NormalizedTags(tags));
data.metadata = encodeMetadata(DEFAULT_COLOR_RGB, 1, 1, extended, new SenderList(msgs));
data.contentChanged(mbox);
new DbMailItem(mbox).create(data);
Conversation conv = new Conversation(mbox, data);
conv.finishCreation(null);
DbMailItem.setParent(msgs, conv);
for (int i = 0; i < msgs.length; i++) {
mbox.markItemModified(msgs[i], Change.PARENT);
msgs[i].mData.parentId = id;
msgs[i].metadataChanged();
}
return conv;
}
use of com.zimbra.cs.mailbox.MailItem.CustomMetadata.CustomMetadataList in project zm-mailbox by Zimbra.
the class Document method prepareCreate.
protected static UnderlyingData prepareCreate(MailItem.Type type, int id, String uuid, Folder folder, String name, String mimeType, ParsedDocument pd, Metadata meta, CustomMetadata custom, int flags, boolean skipParsing) throws ServiceException {
if (folder == null || !folder.canContain(Type.DOCUMENT)) {
throw MailServiceException.CANNOT_CONTAIN();
}
if (!folder.canAccess(ACL.RIGHT_INSERT)) {
throw ServiceException.PERM_DENIED("you do not have the required rights on the folder");
}
name = validateItemName(name);
CustomMetadataList extended = (custom == null ? null : custom.asList());
Mailbox mbox = folder.getMailbox();
UnderlyingData data = new UnderlyingData();
data.uuid = uuid;
data.id = id;
data.type = type.toByte();
data.folderId = folder.getId();
if (!folder.inSpam() || mbox.getAccount().getBooleanAttr(Provisioning.A_zimbraJunkMessagesIndexingEnabled, false)) {
data.indexId = IndexStatus.DEFERRED.id();
}
data.imapId = id;
data.date = (int) (pd.getCreatedDate() / 1000L);
data.size = pd.getSize();
data.name = name;
data.setSubject(name);
data.setBlobDigest(pd.getDigest());
data.metadata = encodeMetadata(meta, DEFAULT_COLOR_RGB, 1, 1, extended, mimeType, pd.getCreator(), skipParsing ? null : pd.getFragment(), null, 0, pd.getDescription(), pd.isDescriptionEnabled(), null).toString();
data.setFlags(flags);
return data;
}
use of com.zimbra.cs.mailbox.MailItem.CustomMetadata.CustomMetadataList in project zm-mailbox by Zimbra.
the class Message method encodeMetadata.
static Metadata encodeMetadata(Metadata meta, Color color, int metaVersion, int version, CustomMetadataList extended, String sender, String recipients, String fragment, String subject, String rawSubj, DraftInfo dinfo, List<CalendarItemInfo> calItemInfos, String calIntendedFor) {
// try to figure out a simple way to make the raw subject from the normalized one
String prefix = null;
if (rawSubj == null || rawSubj.equals(subject)) {
rawSubj = null;
} else if (rawSubj.endsWith(subject)) {
prefix = rawSubj.substring(0, rawSubj.length() - subject.length());
rawSubj = null;
}
meta.put(Metadata.FN_SENDER, sender);
meta.put(Metadata.FN_RECIPIENTS, recipients);
meta.put(Metadata.FN_FRAGMENT, fragment);
meta.put(Metadata.FN_PREFIX, prefix);
meta.put(Metadata.FN_RAW_SUBJ, rawSubj);
if (calItemInfos != null) {
MetadataList mdList = new MetadataList();
for (CalendarItemInfo info : calItemInfos) {
mdList.add(info.encodeMetadata());
}
meta.put(Metadata.FN_CALITEM_IDS, mdList);
}
meta.put(Metadata.FN_CAL_INTENDED_FOR, calIntendedFor);
if (dinfo != null) {
Metadata dmeta = new Metadata();
dmeta.put(Metadata.FN_REPLY_ORIG, dinfo.origId);
dmeta.put(Metadata.FN_REPLY_TYPE, dinfo.replyType);
dmeta.put(Metadata.FN_IDENTITY_ID, dinfo.identityId);
dmeta.put(Metadata.FN_ACCOUNT_ID, dinfo.accountId);
dmeta.put(Metadata.FN_AUTO_SEND_TIME, dinfo.autoSendTime);
meta.put(Metadata.FN_DRAFT, dmeta);
}
return MailItem.encodeMetadata(meta, color, null, metaVersion, version, extended);
}
use of com.zimbra.cs.mailbox.MailItem.CustomMetadata.CustomMetadataList in project zm-mailbox by Zimbra.
the class VirtualConversation method wrapMessage.
private static UnderlyingData wrapMessage(Message msg) {
CustomMetadataList extended = MetadataCallback.duringConversationAdd(null, msg);
UnderlyingData data = new UnderlyingData();
data.id = -msg.getId();
data.type = Type.VIRTUAL_CONVERSATION.toByte();
data.folderId = Mailbox.ID_FOLDER_CONVERSATIONS;
data.setSubject(msg.getSubject());
data.date = (int) (msg.getDate() / 1000);
data.modMetadata = msg.getSavedSequence();
data.modContent = msg.getSavedSequence();
data.size = 1;
data.unreadCount = msg.getUnreadCount();
data.setFlags(msg.getInternalFlagBitmask());
data.setTags(new Tag.NormalizedTags(msg.getTags()));
data.metadata = encodeMetadata(DEFAULT_COLOR_RGB, 1, 1, extended, new SenderList(msg));
return data;
}
Aggregations