@Test public void tooLongSender() throws Exception { Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID); Map<String, Object> fields = new HashMap<String, Object>(); fields.put(ContactConstants.A_firstName, Strings.repeat("F", 129)); Contact contact = mbox.createContact(null, new ParsedContact(fields), Mailbox.ID_FOLDER_CONTACTS, null); DbConnection conn = DbPool.getConnection(mbox); Assert.assertEquals( Strings.repeat("F", 128), DbUtil.executeQuery( conn, "SELECT sender FROM mboxgroup1.mail_item WHERE mailbox_id = ? AND id = ?", mbox.getId(), contact.getId()) .getString(1)); fields.put(ContactConstants.A_firstName, null); fields.put(ContactConstants.A_lastName, Strings.repeat("L", 129)); mbox.modifyContact(null, contact.getId(), new ParsedContact(fields)); Assert.assertEquals( Strings.repeat("L", 128), DbUtil.executeQuery( conn, "SELECT sender FROM mboxgroup1.mail_item WHERE mailbox_id = ? AND id = ?", mbox.getId(), contact.getId()) .getString(1)); conn.closeQuietly(); }
@Test public void spaceInFirstName() throws Exception { Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID); Map<String, Object> fields = new HashMap<String, Object>(); fields.put(ContactConstants.A_firstName, "First Second Third Forth"); fields.put(ContactConstants.A_lastName, "Last"); fields.put(ContactConstants.A_email, "*****@*****.**"); mbox.createContact(null, new ParsedContact(fields), Mailbox.ID_FOLDER_CONTACTS, null); ContactAutoComplete autocomplete = new ContactAutoComplete(mbox.getAccount(), new OperationContext(mbox)); Assert.assertEquals( 1, autocomplete.query("first second third forth", null, 100).entries.size()); }
/** Confirms that locator is not set for contacts. */ @Test public void locator() throws Exception { // Create contact. Map<String, String> attrs = Maps.newHashMap(); attrs.put(ContactConstants.A_fullName, "Volume Id"); Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID); mbox.createContact(null, new ParsedContact(attrs), Mailbox.ID_FOLDER_CONTACTS, null); // Check volume id in database. String sql = String.format( "SELECT COUNT(*) FROM %s WHERE type = %d AND blob_digest IS NULL AND locator IS NOT NULL", DbMailItem.getMailItemTableName(mbox), MailItem.Type.CONTACT.toByte()); DbResults results = DbUtil.executeQuery(sql); Assert.assertEquals("Found non-null locator values for contacts", 0, results.getInt(1)); }
@Test public void reservedQueryTerm() throws Exception { Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID); Map<String, Object> fields = new HashMap<String, Object>(); fields.put(ContactConstants.A_firstName, "not and or"); fields.put(ContactConstants.A_lastName, "subject: from:"); fields.put(ContactConstants.A_email, "*****@*****.**"); mbox.createContact(null, new ParsedContact(fields), Mailbox.ID_FOLDER_CONTACTS, null); ContactAutoComplete autocomplete = new ContactAutoComplete(mbox.getAccount(), new OperationContext(mbox)); Assert.assertEquals(1, autocomplete.query("not", null, 100).entries.size()); Assert.assertEquals(1, autocomplete.query("not and", null, 100).entries.size()); Assert.assertEquals(1, autocomplete.query("not and or", null, 100).entries.size()); Assert.assertEquals(1, autocomplete.query("subject:", null, 100).entries.size()); Assert.assertEquals(1, autocomplete.query("subject: from:", null, 100).entries.size()); }
/** * Bug 77746 Test that VCARD formatting escapes ';' and ',' chars which are part of name * components */ @Test public void semiColonAndCommaInName() throws Exception { Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID); Map<String, Object> fields = new HashMap<String, Object>(); fields.put(ContactConstants.A_lastName, "Last"); fields.put(ContactConstants.A_firstName, "First ; SemiColon"); fields.put(ContactConstants.A_middleName, "Middle , Comma"); fields.put(ContactConstants.A_namePrefix, "Ms."); Contact contact = mbox.createContact(null, new ParsedContact(fields), Mailbox.ID_FOLDER_CONTACTS, null); VCard vcard = VCard.formatContact(contact); String vcardAsString = vcard.getFormatted(); String expectedPattern = "N:Last;First \\; SemiColon;Middle \\, Comma;Ms.;"; String assertMsg = String.format("Vcard\n%s\nshould contain string [%s]", vcardAsString, expectedPattern); Assert.assertTrue(assertMsg, vcardAsString.contains(expectedPattern)); }
@Test public void existsInContacts() throws Exception { Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID); mbox.createContact( null, new ParsedContact(Collections.singletonMap(ContactConstants.A_email, "*****@*****.**")), Mailbox.ID_FOLDER_CONTACTS, null); MailboxTestUtil.index(mbox); Assert.assertTrue( mbox.index.existsInContacts( ImmutableList.of( new InternetAddress("Test <*****@*****.**>"), new InternetAddress("Test <*****@*****.**>")))); Assert.assertFalse( mbox.index.existsInContacts( ImmutableList.of( new InternetAddress("Test <*****@*****.**>"), new InternetAddress("Test <*****@*****.**>")))); }
/** Tests Invalid image attachment (bug 71868). */ @Test public void modifyInvalidImageAttachment() throws Exception { // Create a contact with an attachment. Map<String, String> attrs = new HashMap<String, String>(); attrs.put("fullName", "Contact Initial Content"); byte[] attachData = "attachment 1".getBytes(); Attachment attachment1 = new Attachment(attachData, "image/png", "customField", "image.png"); Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID); Contact contact = mbox.createContact( null, new ParsedContact(attrs, Lists.newArrayList(attachment1)), Mailbox.ID_FOLDER_CONTACTS, null); Attachment attachment2 = new Attachment(attachData, "image/png", "image", "image2.png"); try { ParsedContact pc = new ParsedContact(contact) .modify(new ParsedContact.FieldDeltaList(), Lists.newArrayList(attachment2)); } catch (ServiceException se) { Assert.assertEquals("check the INVALID_IMAGE exception", "mail.INVALID_IMAGE", se.getCode()); } }
/** Modify Contact having an attachment (bug 70488). */ @Test public void modifyContactHavingAttachment() throws Exception { // Create a contact with an attachment. Map<String, String> attrs = new HashMap<String, String>(); attrs.put("fullName", "Contact Initial Content"); byte[] attachData = "attachment 1".getBytes(); Attachment textAttachment = new Attachment(attachData, "text/plain", "customField", "file.txt"); Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID); Contact contact = mbox.createContact( null, new ParsedContact(attrs, Lists.newArrayList(textAttachment)), Mailbox.ID_FOLDER_CONTACTS, null); ParsedContact pc = new ParsedContact(contact) .modify(new ParsedContact.FieldDeltaList(), new ArrayList<Attachment>()); MimeMessage mm = new Mime.FixedMimeMessage(JMSession.getSession(), pc.getContentStream()); MimePart mp = Mime.getMimePart(mm, "1"); Assert.assertEquals("text/plain", mp.getContentType()); Assert.assertEquals("attachment 1", mp.getContent()); }
/** Tests {@link Attachment#getContent()} (bug 36974). */ @Test public void getAttachmentContent() throws Exception { // Create a contact with an attachment. Map<String, String> attrs = new HashMap<String, String>(); attrs.put("fullName", "Get Attachment Content"); byte[] attachData = "attachment 1".getBytes(); Attachment textAttachment = new Attachment(attachData, "text/plain", "customField", "text.txt"); Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID); mbox.createContact( null, new ParsedContact(attrs, Lists.newArrayList(textAttachment)), Mailbox.ID_FOLDER_CONTACTS, null); // Call getContent() on all attachments. for (Contact contact : mbox.getContactList(null, Mailbox.ID_FOLDER_CONTACTS)) { List<Attachment> attachments = contact.getAttachments(); for (Attachment attach : attachments) { attach.getContent(); } } }