final String encodedCid = EmailUtils.encodeUrl(cid);
@Test public void testUrlEncoding() throws UnsupportedEncodingException { assertEquals("abcdefg", EmailUtils.encodeUrl("abcdefg")); assertEquals("0123456789", EmailUtils.encodeUrl("0123456789")); assertEquals("Test%20CID", EmailUtils.encodeUrl("Test CID")); assertEquals("joe.doe@apache.org", EmailUtils.encodeUrl("joe.doe@apache.org")); assertEquals("joe+doe@apache.org", EmailUtils.encodeUrl("joe+doe@apache.org")); assertEquals("peter%26paul%26mary@oldmusic.org", EmailUtils.encodeUrl("peter&paul&mary@oldmusic.org")); } }
final String encodedCid = EmailUtils.encodeUrl(cid);
/** * Test that the specified Content-ID is used when embedding a File * object in an HtmlEmail. * * Rolled back the changes since they broke real emails therefore * the test is currently disabled. * * see https://issues.apache.org/jira/browse/EMAIL-101 */ @Test public void testEmbedFileWithCID() throws Exception { // ==================================================================== // Test Success // ==================================================================== final File file = File.createTempFile("testEmbedFile", "txt"); file.deleteOnExit(); final String testCid = "Test CID"; final String encodedCid = EmailUtils.encodeUrl(testCid); // if we embed a new file, do we get the content ID we specified back? final String strEmbed = this.email.embed(file, testCid); assertNotNull(strEmbed); assertEquals("didn't get same CID when embedding with a specified CID", encodedCid, strEmbed); // if we embed the same file again, do we get the same content ID // back? final String returnedCid = this.email.embed(file); assertEquals("didn't get same CID after embedding same file twice", encodedCid, returnedCid); }