use of com.zimbra.cs.mailbox.Contact.Attachment in project zm-mailbox by Zimbra.
the class ParsedContact method analyzeContact.
private void analyzeContact(Account acct, boolean indexAttachments) throws ServiceException {
if (indexDocs != null) {
return;
}
indexDocs = new ArrayList<IndexDocument>();
StringBuilder attachContent = new StringBuilder();
ServiceException conversionError = null;
if (contactAttachments != null) {
for (Attachment attach : contactAttachments) {
try {
analyzeAttachment(attach, attachContent, indexAttachments);
} catch (MimeHandlerException e) {
String part = attach.getPartName();
String ctype = attach.getContentType();
ZimbraLog.index.warn("Parse error on attachment " + part + " (" + ctype + ")", e);
if (conversionError == null && ConversionException.isTemporaryCauseOf(e)) {
conversionError = ServiceException.FAILURE("failed to analyze part", e.getCause());
mHasTemporaryAnalysisFailure = true;
}
} catch (ObjectHandlerException e) {
String part = attach.getPartName();
String ctype = attach.getContentType();
ZimbraLog.index.warn("Parse error on attachment " + part + " (" + ctype + ")", e);
}
}
}
indexDocs.add(getPrimaryDocument(acct, attachContent.toString()));
}
use of com.zimbra.cs.mailbox.Contact.Attachment in project zm-mailbox by Zimbra.
the class TestContacts method testServerAttachment.
/**
* Tests the server-side {@link Attachment} class.
*/
@Test
public void testServerAttachment() throws Exception {
// Specify the attachment size.
byte[] data = "test".getBytes();
ByteArrayDataSource ds = new ByteArrayDataSource(data, "text/plain");
ds.setName("attachment.txt");
DataHandler dh = new DataHandler(ds);
Attachment attach = new Attachment(dh, "attachment", data.length);
// Don't specify the attachment size.
attach = new Attachment(dh, "attachment");
checkServerAttachment(data, attach);
// Create attachment from byte[].
attach = new Attachment(data, "text/plain", "attachment", "attachment.txt");
checkServerAttachment(data, attach);
}
use of com.zimbra.cs.mailbox.Contact.Attachment in project zm-mailbox by Zimbra.
the class TestContacts method testMoveContact.
@Test
public void testMoveContact() throws Exception {
ZMailbox zmbx = TestUtil.getZMailbox(USER_NAME);
Account acct = Provisioning.getInstance().get(Key.AccountBy.name, TestUtil.getAddress(USER_NAME));
// Create a contact with an attachment.
Map<String, String> attrs = new HashMap<String, String>();
attrs.put("fullName", NAME_PREFIX + " testMoveContact");
String attachment1Text = "attachment 1";
int timeout = (int) Constants.MILLIS_PER_MINUTE;
String folderId = Integer.toString(Mailbox.ID_FOLDER_CONTACTS);
String attachment1Id = zmbx.uploadAttachment("file1.txt", attachment1Text.getBytes(), "text/plain", timeout);
Map<String, ZAttachmentInfo> attachments = new HashMap<String, ZAttachmentInfo>();
ZAttachmentInfo info = new ZAttachmentInfo().setAttachmentId(attachment1Id);
attachments.put("file1", info);
ZContact contact = zmbx.createContact(folderId, null, attrs, attachments);
//bug 80659 add an attribute after initial save so rev changes
attrs = new HashMap<String, String>();
attrs.put("phone", NAME_PREFIX + " testMoveContact");
zmbx.modifyContact(contact.getId(), false, attrs);
Account acct2 = Provisioning.getInstance().get(Key.AccountBy.name, TestUtil.getAddress(USER2_NAME));
Mailbox remoteMbox = MailboxManager.getInstance().getMailboxByAccount(acct2);
Mailbox mbox1 = MailboxManager.getInstance().getMailboxByAccount(acct);
remoteMbox.grantAccess(null, Mailbox.ID_FOLDER_CONTACTS, acct.getId(), ACL.GRANTEE_USER, (short) (ACL.RIGHT_READ | ACL.RIGHT_WRITE | ACL.RIGHT_INSERT), null);
mbox1.grantAccess(null, Mailbox.ID_FOLDER_CONTACTS, acct2.getId(), ACL.GRANTEE_USER, (short) (ACL.RIGHT_READ | ACL.RIGHT_WRITE | ACL.RIGHT_INSERT), null);
// move the contact to user2
zmbx.moveContact(contact.getId(), acct2.getId() + ":" + Mailbox.ID_FOLDER_CONTACTS);
ZMailbox remoteZmbx = TestUtil.getZMailbox(USER2_NAME);
String idStr = TestUtil.search(remoteZmbx, "in:Contacts testMoveContact", ZSearchParams.TYPE_CONTACT).get(0);
Contact ct = remoteMbox.getContactById(null, Integer.parseInt(idStr));
// make sure contact has attachment
List<Attachment> list = ct.getAttachments();
Assert.assertFalse(list.isEmpty());
Attachment att = list.get(0);
Assert.assertEquals("file1.txt", att.getFilename());
Assert.assertEquals("text/plain", att.getContentType());
Assert.assertEquals("attachment 1", new String(att.getContent()));
// move the contact back to user1
remoteZmbx.moveContact(String.valueOf(ct.getId()), acct.getId() + ":" + Mailbox.ID_FOLDER_CONTACTS);
// reset the access
remoteMbox.revokeAccess(null, Mailbox.ID_FOLDER_CONTACTS, acct.getId());
mbox1.revokeAccess(null, Mailbox.ID_FOLDER_CONTACTS, acct2.getId());
idStr = TestUtil.search(zmbx, "in:Contacts testMoveContact", ZSearchParams.TYPE_CONTACT).get(0);
ct = mbox1.getContactById(null, Integer.parseInt(idStr));
// make sure contact has attachment
list = ct.getAttachments();
Assert.assertFalse(list.isEmpty());
att = list.get(0);
Assert.assertEquals("file1.txt", att.getFilename());
Assert.assertEquals("text/plain", att.getContentType());
Assert.assertEquals("attachment 1", new String(att.getContent()));
}
Aggregations