use of com.zimbra.cs.mailbox.Contact in project zm-mailbox by Zimbra.
the class ToXML method encodeContactGroup.
private static void encodeContactGroup(Element elem, ContactGroup contactGroup, Collection<String> memberAttrFilter, ItemIdFormatter ifmt, OperationContext octxt, boolean summary, int fields) throws ServiceException {
for (ContactGroup.Member member : contactGroup.getMembers(true)) {
Element eMember = elem.addNonUniqueElement(MailConstants.E_CONTACT_GROUP_MEMBER);
encodeContactGroupMemberBasic(eMember, member);
Object derefedMember = member.getDerefedObj();
if (derefedMember != null) {
if (derefedMember instanceof String) {
// inline member, do nothing
} else if (derefedMember instanceof Contact) {
// only expand one level for now.
// If this member is a group, do not create/pass down a ContactGroup object from the member.
encodeContact(eMember, ifmt, octxt, (Contact) derefedMember, summary, memberAttrFilter, fields);
} else if (derefedMember instanceof GalContact) {
encodeGalContact(eMember, (GalContact) derefedMember, memberAttrFilter);
} else if (derefedMember instanceof Element) {
// proxied GAL or Contact entry
Element eContact = (Element) derefedMember;
if (memberAttrFilter != null) {
for (Element eAttr : eContact.listElements()) {
String name = eAttr.getAttribute(MailConstants.A_ATTRIBUTE_NAME, null);
if (!memberAttrFilter.contains(name)) {
eAttr.detach();
}
}
}
eMember.addNonUniqueElement(eContact);
}
}
}
}
use of com.zimbra.cs.mailbox.Contact in project zm-mailbox by Zimbra.
the class ContactAction method handleContact.
private ItemActionResult handleContact(Map<String, Object> context, Element request, String operation) throws ServiceException, SoapFaultException {
Element action = request.getElement(MailConstants.E_ACTION);
ZimbraSoapContext zsc = getZimbraSoapContext(context);
Mailbox mbox = getRequestedMailbox(zsc);
OperationContext octxt = getOperationContext(zsc, context);
// figure out which items are local and which ones are remote, and proxy accordingly
ArrayList<Integer> local = new ArrayList<Integer>();
HashMap<String, StringBuilder> remote = new HashMap<String, StringBuilder>();
partitionItems(zsc, action.getAttribute(MailConstants.A_ID), local, remote);
ItemActionResult successes = proxyRemoteItems(action, remote, request, context);
if (!local.isEmpty()) {
ItemActionResult localResults;
if (operation.equals(OP_UPDATE)) {
// duplicating code from ItemAction.java for now...
String folderId = action.getAttribute(MailConstants.A_FOLDER, null);
ItemId iidFolder = new ItemId(folderId == null ? "-1" : folderId, zsc);
if (!iidFolder.belongsTo(mbox)) {
throw ServiceException.INVALID_REQUEST("cannot move item between mailboxes", null);
} else if (folderId != null && iidFolder.getId() <= 0) {
throw MailServiceException.NO_SUCH_FOLDER(iidFolder.getId());
}
String flags = action.getAttribute(MailConstants.A_FLAGS, null);
String[] tags = TagUtil.parseTags(action, mbox, octxt);
Color color = getColor(action);
ParsedContact pc = null;
if (!action.listElements(MailConstants.E_ATTRIBUTE).isEmpty()) {
Contact cn = local.size() == 1 ? mbox.getContactById(octxt, local.get(0)) : null;
Pair<Map<String, Object>, List<Attachment>> cdata = CreateContact.parseContact(action, zsc, octxt, cn);
pc = new ParsedContact(cdata.getFirst(), cdata.getSecond());
}
localResults = ContactActionHelper.UPDATE(zsc, octxt, mbox, local, iidFolder, flags, tags, color, pc).getResult();
} else {
throw ServiceException.INVALID_REQUEST("unknown operation: " + operation, null);
}
successes.appendSuccessIds(localResults.getSuccessIds());
}
return successes;
}
use of com.zimbra.cs.mailbox.Contact in project zm-mailbox by Zimbra.
the class ExportContacts 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);
ExportContactsRequest req = zsc.elementToJaxb(request);
String folder = req.getFolderId();
ItemId iidFolder = folder == null ? null : new ItemId(folder, zsc);
String ct = req.getContentType();
if (ct == null)
throw ServiceException.INVALID_REQUEST("content type missing", null);
if (!ct.equals("csv"))
throw ServiceException.INVALID_REQUEST("unsupported content type: " + ct, null);
String format = req.getCsvFormat();
String locale = req.getCsvLocale();
String separator = req.getCsvDelimiter();
Character sepChar = null;
if ((separator != null) && (separator.length() > 0))
sepChar = separator.charAt(0);
List<Contact> contacts = mbox.getContactList(octxt, iidFolder != null ? iidFolder.getId() : -1);
StringBuilder sb = new StringBuilder();
if (contacts == null)
contacts = new ArrayList<Contact>();
try {
ContactCSV contactCSV = new ContactCSV(mbox, octxt);
contactCSV.toCSV(format, locale, sepChar, contacts.iterator(), sb);
} catch (ContactCSV.ParseException e) {
throw MailServiceException.UNABLE_TO_EXPORT_CONTACTS(e.getMessage(), e);
}
ExportContactsResponse resp = new ExportContactsResponse(sb.toString());
return zsc.jaxbToElement(resp);
}
use of com.zimbra.cs.mailbox.Contact in project zm-mailbox by Zimbra.
the class VcfFormatter method formatCallback.
@Override
public void formatCallback(UserServletContext context) throws IOException, ServiceException {
Charset charset = context.getCharset();
Iterator<? extends MailItem> iterator = null;
try {
iterator = getMailItems(context, getDefaultStartTime(), getDefaultEndTime(), Integer.MAX_VALUE);
String filename = context.target instanceof Contact ? ((Contact) context.target).getFileAsString() : "contacts";
String cd = HttpUtil.createContentDisposition(context.req, Part.ATTACHMENT, filename + ".vcf");
context.resp.addHeader("Content-Disposition", cd);
// for backward compatibility
context.resp.setContentType(MimeConstants.CT_TEXT_VCARD_LEGACY);
context.resp.setCharacterEncoding(charset.name());
int count = 0;
while (iterator.hasNext()) {
MailItem item = iterator.next();
if (!(item instanceof Contact))
continue;
VCard vcf = VCard.formatContact((Contact) item);
context.resp.getOutputStream().write(vcf.getFormatted().getBytes(charset));
count++;
}
} finally {
if (iterator instanceof QueryResultIterator)
((QueryResultIterator) iterator).finished();
}
}
use of com.zimbra.cs.mailbox.Contact in project zm-mailbox by Zimbra.
the class ArchiveFormatter method findContact.
/**
* Find a contact in contact list of a mailbox
* @param octxt The operation context
* @param mbox The mailbox
* @param ct The contact that is to be searched
* @param fldr The folder in which contact should be searched
* @return The contact if it exists in the contact list else return null
*/
private Contact findContact(OperationContext octxt, Mailbox mbox, Contact ct, Folder fldr) {
int folderId = fldr.getId();
List<Contact> contactList = contacts.get(folderId);
if (contactList == null) {
try {
contactList = mbox.getContactList(octxt, folderId);
contacts.put(folderId, contactList);
} catch (ServiceException e) {
ZimbraLog.mailbox.info("unable to get contact list for mailbox %s", mbox.getId());
return null;
}
}
for (Contact contact : contactList) {
HashSet<String> emailAdresses = new HashSet<String>(contact.getEmailAddresses());
for (String emailId : ct.getEmailAddresses()) {
if (emailAdresses.contains(emailId)) {
return contact;
}
}
}
return null;
}
Aggregations