You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@commons.apache.org by tn...@apache.org on 2015/05/23 08:51:00 UTC
svn commit: r952406 [28/42] - in
/websites/production/commons/content/proper/commons-email: ./ apidocs/
apidocs/org/apache/commons/mail/ apidocs/org/apache/commons/mail/class-use/
apidocs/org/apache/commons/mail/resolver/ apidocs/org/apache/commons/mai...
Added: websites/production/commons/content/proper/commons-email/jacoco/org.apache.commons.mail/HtmlEmail.java.html
==============================================================================
--- websites/production/commons/content/proper/commons-email/jacoco/org.apache.commons.mail/HtmlEmail.java.html (added)
+++ websites/production/commons/content/proper/commons-email/jacoco/org.apache.commons.mail/HtmlEmail.java.html Sat May 23 06:50:57 2015
@@ -0,0 +1,717 @@
+<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="en"><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/><link rel="stylesheet" href="../.resources/report.css" type="text/css"/><link rel="shortcut icon" href="../.resources/report.gif" type="image/gif"/><title>HtmlEmail.java</title><link rel="stylesheet" href="../.resources/prettify.css" type="text/css"/><script type="text/javascript" src="../.resources/prettify.js"></script></head><body onload="window['PR_TAB_WIDTH']=4;prettyPrint()"><div class="breadcrumb" id="breadcrumb"><span class="info"><a href="../.sessions.html" class="el_session">Sessions</a></span><a href="../index.html" class="el_report">Apache Commons Email</a> > <a href="index.source.html" class="el_package">org.apache.commons.mail</a> > <span class="el_source">HtmlEmail.java</span></div><h1>HtmlEmai
l.java</h1><pre class="source lang-java linenums">/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.mail;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+
+import javax.activation.DataHandler;
+import javax.activation.DataSource;
+import javax.activation.FileDataSource;
+import javax.activation.URLDataSource;
+import javax.mail.BodyPart;
+import javax.mail.MessagingException;
+import javax.mail.internet.MimeBodyPart;
+import javax.mail.internet.MimeMultipart;
+
+/**
+ * An HTML multipart email.
+ *
+ * <p>This class is used to send HTML formatted email. A text message
+ * can also be set for HTML unaware email clients, such as text-based
+ * email clients.
+ *
+ * <p>This class also inherits from {@link MultiPartEmail}, so it is easy to
+ * add attachments to the email.
+ *
+ * <p>To send an email in HTML, one should create a <code>HtmlEmail</code>, then
+ * use the {@link #setFrom(String)}, {@link #addTo(String)} etc. methods.
+ * The HTML content can be set with the {@link #setHtmlMsg(String)} method. The
+ * alternative text content can be set with {@link #setTextMsg(String)}.
+ *
+ * <p>Either the text or HTML can be omitted, in which case the "main"
+ * part of the multipart becomes whichever is supplied rather than a
+ * <code>multipart/alternative</code>.
+ *
+ * <h3>Embedding Images and Media</h3>
+ *
+ * <p>It is also possible to embed URLs, files, or arbitrary
+ * <code>DataSource</code>s directly into the body of the mail:
+ * <pre>
+ * HtmlEmail he = new HtmlEmail();
+ * File img = new File("my/image.gif");
+ * PNGDataSource png = new PNGDataSource(decodedPNGOutputStream); // a custom class
+ * StringBuffer msg = new StringBuffer();
+ * msg.append("&lt;html&gt;&lt;body&gt;");
+ * msg.append("&lt;img src=cid:").append(he.embed(img)).append("&gt;");
+ * msg.append("&lt;img src=cid:").append(he.embed(png)).append("&gt;");
+ * msg.append("&lt;/body&gt;&lt;/html&gt;");
+ * he.setHtmlMsg(msg.toString());
+ * // code to set the other email fields (not shown)
+ * </pre>
+ *
+ * <p>Embedded entities are tracked by their name, which for <code>File</code>s is
+ * the filename itself and for <code>URL</code>s is the canonical path. It is
+ * an error to bind the same name to more than one entity, and this class will
+ * attempt to validate that for <code>File</code>s and <code>URL</code>s. When
+ * embedding a <code>DataSource</code>, the code uses the <code>equals()</code>
+ * method defined on the <code>DataSource</code>s to make the determination.
+ *
+ * @since 1.0
+ * @version $Id$
+ */
+<span class="fc" id="L85">public class HtmlEmail extends MultiPartEmail</span>
+{
+ /** Definition of the length of generated CID's. */
+ public static final int CID_LENGTH = 10;
+
+ /** prefix for default HTML mail. */
+ private static final String HTML_MESSAGE_START = "<html><body><pre>";
+ /** suffix for default HTML mail. */
+ private static final String HTML_MESSAGE_END = "</pre></body></html>";
+
+
+ /**
+ * Text part of the message. This will be used as alternative text if
+ * the email client does not support HTML messages.
+ */
+ protected String text;
+
+ /** Html part of the message. */
+ protected String html;
+
+ /**
+ * @deprecated As of commons-email 1.1, no longer used. Inline embedded
+ * objects are now stored in {@link #inlineEmbeds}.
+ */
+ @Deprecated
+ protected List<InlineImage> inlineImages;
+
+ /**
+ * Embedded images Map&lt;String, InlineImage&gt; where the key is the
+ * user-defined image name.
+ */
+<span class="fc" id="L116"> protected Map<String, InlineImage> inlineEmbeds = new HashMap<String, InlineImage>();</span>
+
+ /**
+ * Set the text content.
+ *
+ * @param aText A String.
+ * @return An HtmlEmail.
+ * @throws EmailException see javax.mail.internet.MimeBodyPart
+ * for definitions
+ * @since 1.0
+ */
+ public HtmlEmail setTextMsg(final String aText) throws EmailException
+ {
+<span class="pc bpc" id="L129" title="1 of 2 branches missed."> if (EmailUtils.isEmpty(aText))</span>
+ {
+<span class="nc" id="L131"> throw new EmailException("Invalid message supplied");</span>
+ }
+
+<span class="fc" id="L134"> this.text = aText;</span>
+<span class="fc" id="L135"> return this;</span>
+ }
+
+ /**
+ * Set the HTML content.
+ *
+ * @param aHtml A String.
+ * @return An HtmlEmail.
+ * @throws EmailException see javax.mail.internet.MimeBodyPart
+ * for definitions
+ * @since 1.0
+ */
+ public HtmlEmail setHtmlMsg(final String aHtml) throws EmailException
+ {
+<span class="pc bpc" id="L149" title="1 of 2 branches missed."> if (EmailUtils.isEmpty(aHtml))</span>
+ {
+<span class="nc" id="L151"> throw new EmailException("Invalid message supplied");</span>
+ }
+
+<span class="fc" id="L154"> this.html = aHtml;</span>
+<span class="fc" id="L155"> return this;</span>
+ }
+
+ /**
+ * Set the message.
+ *
+ * <p>This method overrides {@link MultiPartEmail#setMsg(String)} in
+ * order to send an HTML message instead of a plain text message in
+ * the mail body. The message is formatted in HTML for the HTML
+ * part of the message; it is left as is in the alternate text
+ * part.
+ *
+ * @param msg the message text to use
+ * @return this <code>HtmlEmail</code>
+ * @throws EmailException if msg is null or empty;
+ * see javax.mail.internet.MimeBodyPart for definitions
+ * @since 1.0
+ */
+ @Override
+ public Email setMsg(final String msg) throws EmailException
+ {
+<span class="nc bnc" id="L176" title="All 2 branches missed."> if (EmailUtils.isEmpty(msg))</span>
+ {
+<span class="nc" id="L178"> throw new EmailException("Invalid message supplied");</span>
+ }
+
+<span class="nc" id="L181"> setTextMsg(msg);</span>
+
+<span class="nc" id="L183"> final StringBuffer htmlMsgBuf = new StringBuffer(</span>
+ msg.length()
+ + HTML_MESSAGE_START.length()
+ + HTML_MESSAGE_END.length()
+ );
+
+<span class="nc" id="L189"> htmlMsgBuf.append(HTML_MESSAGE_START)</span>
+ .append(msg)
+ .append(HTML_MESSAGE_END);
+
+<span class="nc" id="L193"> setHtmlMsg(htmlMsgBuf.toString());</span>
+
+<span class="nc" id="L195"> return this;</span>
+ }
+
+ /**
+ * Attempts to parse the specified <code>String</code> as a URL that will
+ * then be embedded in the message.
+ *
+ * @param urlString String representation of the URL.
+ * @param name The name that will be set in the filename header field.
+ * @return A String with the Content-ID of the URL.
+ * @throws EmailException when URL supplied is invalid or if {@code name} is null
+ * or empty; also see {@link javax.mail.internet.MimeBodyPart} for definitions
+ *
+ * @see #embed(URL, String)
+ * @since 1.1
+ */
+ public String embed(final String urlString, final String name) throws EmailException
+ {
+ try
+ {
+<span class="nc" id="L215"> return embed(new URL(urlString), name);</span>
+ }
+<span class="nc" id="L217"> catch (final MalformedURLException e)</span>
+ {
+<span class="nc" id="L219"> throw new EmailException("Invalid URL", e);</span>
+ }
+ }
+
+ /**
+ * Embeds an URL in the HTML.
+ *
+ * <p>This method embeds a file located by an URL into
+ * the mail body. It allows, for instance, to add inline images
+ * to the email. Inline files may be referenced with a
+ * <code>cid:xxxxxx</code> URL, where xxxxxx is the Content-ID
+ * returned by the embed function. It is an error to bind the same name
+ * to more than one URL; if the same URL is embedded multiple times, the
+ * same Content-ID is guaranteed to be returned.
+ *
+ * <p>While functionally the same as passing <code>URLDataSource</code> to
+ * {@link #embed(DataSource, String, String)}, this method attempts
+ * to validate the URL before embedding it in the message and will throw
+ * <code>EmailException</code> if the validation fails. In this case, the
+ * <code>HtmlEmail</code> object will not be changed.
+ *
+ * <p>
+ * NOTE: Clients should take care to ensure that different URLs are bound to
+ * different names. This implementation tries to detect this and throw
+ * <code>EmailException</code>. However, it is not guaranteed to catch
+ * all cases, especially when the URL refers to a remote HTTP host that
+ * may be part of a virtual host cluster.
+ *
+ * @param url The URL of the file.
+ * @param name The name that will be set in the filename header
+ * field.
+ * @return A String with the Content-ID of the file.
+ * @throws EmailException when URL supplied is invalid or if {@code name} is null
+ * or empty; also see {@link javax.mail.internet.MimeBodyPart} for definitions
+ * @since 1.0
+ */
+ public String embed(final URL url, final String name) throws EmailException
+ {
+<span class="pc bpc" id="L257" title="1 of 2 branches missed."> if (EmailUtils.isEmpty(name))</span>
+ {
+<span class="nc" id="L259"> throw new EmailException("name cannot be null or empty");</span>
+ }
+
+ // check if a URLDataSource for this name has already been attached;
+ // if so, return the cached CID value.
+<span class="pc bpc" id="L264" title="1 of 2 branches missed."> if (inlineEmbeds.containsKey(name))</span>
+ {
+<span class="nc" id="L266"> final InlineImage ii = inlineEmbeds.get(name);</span>
+<span class="nc" id="L267"> final URLDataSource urlDataSource = (URLDataSource) ii.getDataSource();</span>
+ // make sure the supplied URL points to the same thing
+ // as the one already associated with this name.
+ // NOTE: Comparing URLs with URL.equals() is a blocking operation
+ // in the case of a network failure therefore we use
+ // url.toExternalForm().equals() here.
+<span class="nc bnc" id="L273" title="All 2 branches missed."> if (url.toExternalForm().equals(urlDataSource.getURL().toExternalForm()))</span>
+ {
+<span class="nc" id="L275"> return ii.getCid();</span>
+ }
+<span class="nc" id="L277"> throw new EmailException("embedded name '" + name</span>
+ + "' is already bound to URL " + urlDataSource.getURL()
+ + "; existing names cannot be rebound");
+ }
+
+ // verify that the URL is valid
+<span class="fc" id="L283"> InputStream is = null;</span>
+ try
+ {
+<span class="fc" id="L286"> is = url.openStream();</span>
+ }
+<span class="nc" id="L288"> catch (final IOException e)</span>
+ {
+<span class="nc" id="L290"> throw new EmailException("Invalid URL", e);</span>
+ }
+ finally
+ {
+<span class="nc" id="L294"> try</span>
+ {
+<span class="pc bpc" id="L296" title="3 of 4 branches missed."> if (is != null)</span>
+ {
+<span class="pc" id="L298"> is.close();</span>
+ }
+ }
+<span class="nc" id="L301"> catch (final IOException ioe) // NOPMD</span>
+<span class="pc" id="L302"> { /* sigh */ }</span>
+<span class="nc" id="L303"> }</span>
+
+<span class="fc" id="L305"> return embed(new URLDataSource(url), name);</span>
+ }
+
+ /**
+ * Embeds a file in the HTML. This implementation delegates to
+ * {@link #embed(File, String)}.
+ *
+ * @param file The <code>File</code> object to embed
+ * @return A String with the Content-ID of the file.
+ * @throws EmailException when the supplied <code>File</code> cannot be
+ * used; also see {@link javax.mail.internet.MimeBodyPart} for definitions
+ *
+ * @see #embed(File, String)
+ * @since 1.1
+ */
+ public String embed(final File file) throws EmailException
+ {
+<span class="nc" id="L322"> final String cid = EmailUtils.randomAlphabetic(HtmlEmail.CID_LENGTH).toLowerCase(Locale.ENGLISH);</span>
+<span class="nc" id="L323"> return embed(file, cid);</span>
+ }
+
+ /**
+ * Embeds a file in the HTML.
+ *
+ * <p>This method embeds a file located by an URL into
+ * the mail body. It allows, for instance, to add inline images
+ * to the email. Inline files may be referenced with a
+ * <code>cid:xxxxxx</code> URL, where xxxxxx is the Content-ID
+ * returned by the embed function. Files are bound to their names, which is
+ * the value returned by {@link java.io.File#getName()}. If the same file
+ * is embedded multiple times, the same CID is guaranteed to be returned.
+ *
+ * <p>While functionally the same as passing <code>FileDataSource</code> to
+ * {@link #embed(DataSource, String, String)}, this method attempts
+ * to validate the file before embedding it in the message and will throw
+ * <code>EmailException</code> if the validation fails. In this case, the
+ * <code>HtmlEmail</code> object will not be changed.
+ *
+ * @param file The <code>File</code> to embed
+ * @param cid the Content-ID to use for the embedded <code>File</code>
+ * @return A String with the Content-ID of the file.
+ * @throws EmailException when the supplied <code>File</code> cannot be used
+ * or if the file has already been embedded;
+ * also see {@link javax.mail.internet.MimeBodyPart} for definitions
+ * @since 1.1
+ */
+ public String embed(final File file, final String cid) throws EmailException
+ {
+<span class="pc bpc" id="L353" title="1 of 2 branches missed."> if (EmailUtils.isEmpty(file.getName()))</span>
+ {
+<span class="nc" id="L355"> throw new EmailException("file name cannot be null or empty");</span>
+ }
+
+ // verify that the File can provide a canonical path
+<span class="fc" id="L359"> String filePath = null;</span>
+ try
+ {
+<span class="fc" id="L362"> filePath = file.getCanonicalPath();</span>
+ }
+<span class="nc" id="L364"> catch (final IOException ioe)</span>
+ {
+<span class="nc" id="L366"> throw new EmailException("couldn't get canonical path for "</span>
+ + file.getName(), ioe);
+<span class="fc" id="L368"> }</span>
+
+ // check if a FileDataSource for this name has already been attached;
+ // if so, return the cached CID value.
+<span class="pc bpc" id="L372" title="1 of 2 branches missed."> if (inlineEmbeds.containsKey(file.getName()))</span>
+ {
+<span class="nc" id="L374"> final InlineImage ii = inlineEmbeds.get(file.getName());</span>
+<span class="nc" id="L375"> final FileDataSource fileDataSource = (FileDataSource) ii.getDataSource();</span>
+ // make sure the supplied file has the same canonical path
+ // as the one already associated with this name.
+<span class="nc" id="L378"> String existingFilePath = null;</span>
+ try
+ {
+<span class="nc" id="L381"> existingFilePath = fileDataSource.getFile().getCanonicalPath();</span>
+ }
+<span class="nc" id="L383"> catch (final IOException ioe)</span>
+ {
+<span class="nc" id="L385"> throw new EmailException("couldn't get canonical path for file "</span>
+ + fileDataSource.getFile().getName()
+ + "which has already been embedded", ioe);
+<span class="nc" id="L388"> }</span>
+<span class="nc bnc" id="L389" title="All 2 branches missed."> if (filePath.equals(existingFilePath))</span>
+ {
+<span class="nc" id="L391"> return ii.getCid();</span>
+ }
+<span class="nc" id="L393"> throw new EmailException("embedded name '" + file.getName()</span>
+ + "' is already bound to file " + existingFilePath
+ + "; existing names cannot be rebound");
+ }
+
+ // verify that the file is valid
+<span class="pc bpc" id="L399" title="1 of 2 branches missed."> if (!file.exists())</span>
+ {
+<span class="nc" id="L401"> throw new EmailException("file " + filePath + " doesn't exist");</span>
+ }
+<span class="pc bpc" id="L403" title="1 of 2 branches missed."> if (!file.isFile())</span>
+ {
+<span class="nc" id="L405"> throw new EmailException("file " + filePath + " isn't a normal file");</span>
+ }
+<span class="pc bpc" id="L407" title="1 of 2 branches missed."> if (!file.canRead())</span>
+ {
+<span class="nc" id="L409"> throw new EmailException("file " + filePath + " isn't readable");</span>
+ }
+
+<span class="fc" id="L412"> return embed(new FileDataSource(file), file.getName(), cid);</span>
+ }
+
+ /**
+ * Embeds the specified <code>DataSource</code> in the HTML using a
+ * randomly generated Content-ID. Returns the generated Content-ID string.
+ *
+ * @param dataSource the <code>DataSource</code> to embed
+ * @param name the name that will be set in the filename header field
+ * @return the generated Content-ID for this <code>DataSource</code>
+ * @throws EmailException if the embedding fails or if <code>name</code> is
+ * null or empty
+ * @see #embed(DataSource, String, String)
+ * @since 1.1
+ */
+ public String embed(final DataSource dataSource, final String name) throws EmailException
+ {
+ // check if the DataSource has already been attached;
+ // if so, return the cached CID value.
+<span class="pc bpc" id="L431" title="1 of 2 branches missed."> if (inlineEmbeds.containsKey(name))</span>
+ {
+<span class="nc" id="L433"> final InlineImage ii = inlineEmbeds.get(name);</span>
+ // make sure the supplied URL points to the same thing
+ // as the one already associated with this name.
+<span class="nc bnc" id="L436" title="All 2 branches missed."> if (dataSource.equals(ii.getDataSource()))</span>
+ {
+<span class="nc" id="L438"> return ii.getCid();</span>
+ }
+<span class="nc" id="L440"> throw new EmailException("embedded DataSource '" + name</span>
+ + "' is already bound to name " + ii.getDataSource().toString()
+ + "; existing names cannot be rebound");
+ }
+
+<span class="fc" id="L445"> final String cid = EmailUtils.randomAlphabetic(HtmlEmail.CID_LENGTH).toLowerCase();</span>
+<span class="fc" id="L446"> return embed(dataSource, name, cid);</span>
+ }
+
+ /**
+ * Embeds the specified <code>DataSource</code> in the HTML using the
+ * specified Content-ID. Returns the specified Content-ID string.
+ *
+ * @param dataSource the <code>DataSource</code> to embed
+ * @param name the name that will be set in the filename header field
+ * @param cid the Content-ID to use for this <code>DataSource</code>
+ * @return the URL encoded Content-ID for this <code>DataSource</code>
+ * @throws EmailException if the embedding fails or if <code>name</code> is
+ * null or empty
+ * @since 1.1
+ */
+ public String embed(final DataSource dataSource, final String name, final String cid)
+ throws EmailException
+ {
+<span class="pc bpc" id="L464" title="1 of 2 branches missed."> if (EmailUtils.isEmpty(name))</span>
+ {
+<span class="nc" id="L466"> throw new EmailException("name cannot be null or empty");</span>
+ }
+
+<span class="fc" id="L469"> final MimeBodyPart mbp = new MimeBodyPart();</span>
+
+ try
+ {
+ // URL encode the cid according to RFC 2392
+<span class="fc" id="L474"> String encodedCid = EmailUtils.encodeUrl(cid);</span>
+
+<span class="fc" id="L476"> mbp.setDataHandler(new DataHandler(dataSource));</span>
+<span class="fc" id="L477"> mbp.setFileName(name);</span>
+<span class="fc" id="L478"> mbp.setDisposition(EmailAttachment.INLINE);</span>
+<span class="fc" id="L479"> mbp.setContentID("<" + encodedCid + ">");</span>
+
+<span class="fc" id="L481"> final InlineImage ii = new InlineImage(encodedCid, dataSource, mbp);</span>
+<span class="fc" id="L482"> this.inlineEmbeds.put(name, ii);</span>
+
+<span class="fc" id="L484"> return encodedCid;</span>
+ }
+<span class="nc" id="L486"> catch (final MessagingException me)</span>
+ {
+<span class="nc" id="L488"> throw new EmailException(me);</span>
+ }
+<span class="nc" id="L490"> catch (final UnsupportedEncodingException uee)</span>
+ {
+<span class="nc" id="L492"> throw new EmailException(uee);</span>
+ }
+ }
+
+ /**
+ * Does the work of actually building the MimeMessage. Please note that
+ * a user rarely calls this method directly and only if he/she is
+ * interested in the sending the underlying MimeMessage without
+ * commons-email.
+ *
+ * @exception EmailException if there was an error.
+ * @since 1.0
+ */
+ @Override
+ public void buildMimeMessage() throws EmailException
+ {
+ try
+ {
+<span class="fc" id="L510"> build();</span>
+ }
+<span class="nc" id="L512"> catch (final MessagingException me)</span>
+ {
+<span class="nc" id="L514"> throw new EmailException(me);</span>
+<span class="fc" id="L515"> }</span>
+<span class="fc" id="L516"> super.buildMimeMessage();</span>
+<span class="fc" id="L517"> }</span>
+
+ /**
+ * @throws EmailException EmailException
+ * @throws MessagingException MessagingException
+ */
+ private void build() throws MessagingException, EmailException
+ {
+<span class="fc" id="L525"> final MimeMultipart rootContainer = this.getContainer();</span>
+<span class="fc" id="L526"> MimeMultipart bodyEmbedsContainer = rootContainer;</span>
+<span class="fc" id="L527"> MimeMultipart bodyContainer = rootContainer;</span>
+<span class="fc" id="L528"> MimeBodyPart msgHtml = null;</span>
+<span class="fc" id="L529"> MimeBodyPart msgText = null;</span>
+
+<span class="fc" id="L531"> rootContainer.setSubType("mixed");</span>
+
+ // determine how to form multiparts of email
+
+<span class="fc bfc" id="L535" title="All 4 branches covered."> if (EmailUtils.isNotEmpty(this.html) && this.inlineEmbeds.size() > 0)</span>
+ {
+ //If HTML body and embeds are used, create a related container and add it to the root container
+<span class="fc" id="L538"> bodyEmbedsContainer = new MimeMultipart("related");</span>
+<span class="fc" id="L539"> bodyContainer = bodyEmbedsContainer;</span>
+<span class="fc" id="L540"> this.addPart(bodyEmbedsContainer, 0);</span>
+
+ // If TEXT body was specified, create a alternative container and add it to the embeds container
+<span class="fc bfc" id="L543" title="All 2 branches covered."> if (EmailUtils.isNotEmpty(this.text))</span>
+ {
+<span class="fc" id="L545"> bodyContainer = new MimeMultipart("alternative");</span>
+<span class="fc" id="L546"> final BodyPart bodyPart = createBodyPart();</span>
+ try
+ {
+<span class="fc" id="L549"> bodyPart.setContent(bodyContainer);</span>
+<span class="fc" id="L550"> bodyEmbedsContainer.addBodyPart(bodyPart, 0);</span>
+ }
+<span class="nc" id="L552"> catch (final MessagingException me)</span>
+ {
+<span class="nc" id="L554"> throw new EmailException(me);</span>
+<span class="fc" id="L555"> }</span>
+<span class="fc" id="L556"> }</span>
+ }
+<span class="fc bfc" id="L558" title="All 4 branches covered."> else if (EmailUtils.isNotEmpty(this.text) && EmailUtils.isNotEmpty(this.html))</span>
+ {
+ // EMAIL-142: if we have both an HTML and TEXT body, but no attachments or
+ // inline images, the root container should have mimetype
+ // "multipart/alternative".
+ // reference: http://tools.ietf.org/html/rfc2046#section-5.1.4
+<span class="pc bpc" id="L564" title="1 of 4 branches missed."> if (this.inlineEmbeds.size() > 0 || isBoolHasAttachments())</span>
+ {
+ // If both HTML and TEXT bodies are provided, create an alternative
+ // container and add it to the root container
+<span class="fc" id="L568"> bodyContainer = new MimeMultipart("alternative");</span>
+<span class="fc" id="L569"> this.addPart(bodyContainer, 0);</span>
+ }
+ else
+ {
+ // no attachments or embedded images present, change the mimetype
+ // of the root container (= body container)
+<span class="fc" id="L575"> rootContainer.setSubType("alternative");</span>
+ }
+ }
+
+<span class="fc bfc" id="L579" title="All 2 branches covered."> if (EmailUtils.isNotEmpty(this.html))</span>
+ {
+<span class="fc" id="L581"> msgHtml = new MimeBodyPart();</span>
+<span class="fc" id="L582"> bodyContainer.addBodyPart(msgHtml, 0);</span>
+
+ // EMAIL-104: call explicitly setText to use default mime charset
+ // (property "mail.mime.charset") in case none has been set
+<span class="fc" id="L586"> msgHtml.setText(this.html, this.charset, EmailConstants.TEXT_SUBTYPE_HTML);</span>
+
+ // EMAIL-147: work-around for buggy JavaMail implementations;
+ // in case setText(...) does not set the correct content type,
+ // use the setContent() method instead.
+<span class="fc" id="L591"> final String contentType = msgHtml.getContentType();</span>
+<span class="pc bpc" id="L592" title="2 of 4 branches missed."> if (contentType == null || !contentType.equals(EmailConstants.TEXT_HTML))</span>
+ {
+ // apply default charset if one has been set
+<span class="fc bfc" id="L595" title="All 2 branches covered."> if (EmailUtils.isNotEmpty(this.charset))</span>
+ {
+<span class="fc" id="L597"> msgHtml.setContent(this.html, EmailConstants.TEXT_HTML + "; charset=" + this.charset);</span>
+ }
+ else
+ {
+ // unfortunately, MimeUtility.getDefaultMIMECharset() is package private
+ // and thus can not be used to set the default system charset in case
+ // no charset has been provided by the user
+<span class="fc" id="L604"> msgHtml.setContent(this.html, EmailConstants.TEXT_HTML);</span>
+ }
+ }
+
+<span class="fc bfc" id="L608" title="All 2 branches covered."> for (final InlineImage image : this.inlineEmbeds.values())</span>
+ {
+<span class="fc" id="L610"> bodyEmbedsContainer.addBodyPart(image.getMbp());</span>
+<span class="fc" id="L611"> }</span>
+ }
+
+<span class="fc bfc" id="L614" title="All 2 branches covered."> if (EmailUtils.isNotEmpty(this.text))</span>
+ {
+<span class="fc" id="L616"> msgText = new MimeBodyPart();</span>
+<span class="fc" id="L617"> bodyContainer.addBodyPart(msgText, 0);</span>
+
+ // EMAIL-104: call explicitly setText to use default mime charset
+ // (property "mail.mime.charset") in case none has been set
+<span class="fc" id="L621"> msgText.setText(this.text, this.charset);</span>
+ }
+<span class="fc" id="L623"> }</span>
+
+ /**
+ * Private bean class that encapsulates data about URL contents
+ * that are embedded in the final email.
+ * @since 1.1
+ */
+<span class="fc" id="L630"> private static class InlineImage</span>
+ {
+ /** content id. */
+ private final String cid;
+ /** <code>DataSource</code> for the content. */
+ private final DataSource dataSource;
+ /** the <code>MimeBodyPart</code> that contains the encoded data. */
+ private final MimeBodyPart mbp;
+
+ /**
+ * Creates an InlineImage object to represent the
+ * specified content ID and <code>MimeBodyPart</code>.
+ * @param cid the generated content ID
+ * @param dataSource the <code>DataSource</code> that represents the content
+ * @param mbp the <code>MimeBodyPart</code> that contains the encoded
+ * data
+ */
+ public InlineImage(final String cid, final DataSource dataSource, final MimeBodyPart mbp)
+<span class="fc" id="L648"> {</span>
+<span class="fc" id="L649"> this.cid = cid;</span>
+<span class="fc" id="L650"> this.dataSource = dataSource;</span>
+<span class="fc" id="L651"> this.mbp = mbp;</span>
+<span class="fc" id="L652"> }</span>
+
+ /**
+ * Returns the unique content ID of this InlineImage.
+ * @return the unique content ID of this InlineImage
+ */
+ public String getCid()
+ {
+<span class="nc" id="L660"> return cid;</span>
+ }
+
+ /**
+ * Returns the <code>DataSource</code> that represents the encoded content.
+ * @return the <code>DataSource</code> representing the encoded content
+ */
+ public DataSource getDataSource()
+ {
+<span class="nc" id="L669"> return dataSource;</span>
+ }
+
+ /**
+ * Returns the <code>MimeBodyPart</code> that contains the
+ * encoded InlineImage data.
+ * @return the <code>MimeBodyPart</code> containing the encoded
+ * InlineImage data
+ */
+ public MimeBodyPart getMbp()
+ {
+<span class="fc" id="L680"> return mbp;</span>
+ }
+
+ // equals()/hashCode() implementations, since this class
+ // is stored as a entry in a Map.
+ /**
+ * {@inheritDoc}
+ * @return true if the other object is also an InlineImage with the same cid.
+ */
+ @Override
+ public boolean equals(final Object obj)
+ {
+<span class="nc bnc" id="L692" title="All 2 branches missed."> if (this == obj)</span>
+ {
+<span class="nc" id="L694"> return true;</span>
+ }
+<span class="nc bnc" id="L696" title="All 2 branches missed."> if (!(obj instanceof InlineImage))</span>
+ {
+<span class="nc" id="L698"> return false;</span>
+ }
+
+<span class="nc" id="L701"> final InlineImage that = (InlineImage) obj;</span>
+
+<span class="nc" id="L703"> return this.cid.equals(that.cid);</span>
+ }
+
+ /**
+ * {@inheritDoc}
+ * @return the cid hashCode.
+ */
+ @Override
+ public int hashCode()
+ {
+<span class="nc" id="L713"> return cid.hashCode();</span>
+ }
+ }
+}
+</pre><div class="footer"><span class="right">Created with <a href="http://www.eclemma.org/jacoco">JaCoCo</a> 0.7.2.201409121644</span></div></body></html>
\ No newline at end of file
Propchange: websites/production/commons/content/proper/commons-email/jacoco/org.apache.commons.mail/HtmlEmail.java.html
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: websites/production/commons/content/proper/commons-email/jacoco/org.apache.commons.mail/HtmlEmail.java.html
------------------------------------------------------------------------------
svn:keywords = Id Revision HeadURL
Propchange: websites/production/commons/content/proper/commons-email/jacoco/org.apache.commons.mail/HtmlEmail.java.html
------------------------------------------------------------------------------
svn:mime-type = text/html
Added: websites/production/commons/content/proper/commons-email/jacoco/org.apache.commons.mail/ImageHtmlEmail.html
==============================================================================
--- websites/production/commons/content/proper/commons-email/jacoco/org.apache.commons.mail/ImageHtmlEmail.html (added)
+++ websites/production/commons/content/proper/commons-email/jacoco/org.apache.commons.mail/ImageHtmlEmail.html Sat May 23 06:50:57 2015
@@ -0,0 +1 @@
+<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="en"><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/><link rel="stylesheet" href="../.resources/report.css" type="text/css"/><link rel="shortcut icon" href="../.resources/report.gif" type="image/gif"/><title>ImageHtmlEmail</title><script type="text/javascript" src="../.resources/sort.js"></script></head><body onload="initialSort(['breadcrumb'])"><div class="breadcrumb" id="breadcrumb"><span class="info"><a href="../.sessions.html" class="el_session">Sessions</a></span><a href="../index.html" class="el_report">Apache Commons Email</a> > <a href="index.html" class="el_package">org.apache.commons.mail</a> > <span class="el_class">ImageHtmlEmail</span></div><h1>ImageHtmlEmail</h1><table class="coverage" cellspacing="0" id="coveragetable"><thead><tr><td class="sorta
ble" id="a" onclick="toggleSort(this)">Element</td><td class="down sortable bar" id="b" onclick="toggleSort(this)">Missed Instructions</td><td class="sortable ctr2" id="c" onclick="toggleSort(this)">Cov.</td><td class="sortable bar" id="d" onclick="toggleSort(this)">Missed Branches</td><td class="sortable ctr2" id="e" onclick="toggleSort(this)">Cov.</td><td class="sortable ctr1" id="f" onclick="toggleSort(this)">Missed</td><td class="sortable ctr2" id="g" onclick="toggleSort(this)">Cxty</td><td class="sortable ctr1" id="h" onclick="toggleSort(this)">Missed</td><td class="sortable ctr2" id="i" onclick="toggleSort(this)">Lines</td><td class="sortable ctr1" id="j" onclick="toggleSort(this)">Missed</td><td class="sortable ctr2" id="k" onclick="toggleSort(this)">Methods</td></tr></thead><tfoot><tr><td>Total</td><td class="bar">12 of 148</td><td class="ctr2">92%</td><td class="bar">4 of 12</td><td class="ctr2">67%</td><td class="ctr1">4</td><td class="ctr2">12</td><td class="ctr1">3</td><
td class="ctr2">39</td><td class="ctr1">0</td><td class="ctr2">6</td></tr></tfoot><tbody><tr><td id="a0"><a href="ImageHtmlEmail.java.html#L105" class="el_method">buildMimeMessage()</a></td><td class="bar" id="b0"><img src="../.resources/redbar.gif" width="8" height="10" title="7" alt="7"/><img src="../.resources/greenbar.gif" width="21" height="10" title="19" alt="19"/></td><td class="ctr2" id="c5">73%</td><td class="bar" id="d1"/><td class="ctr2" id="e1">n/a</td><td class="ctr1" id="f1">0</td><td class="ctr2" id="g1">1</td><td class="ctr1" id="h0">2</td><td class="ctr2" id="i1">8</td><td class="ctr1" id="j0">0</td><td class="ctr2" id="k0">1</td></tr><tr><td id="a3"><a href="ImageHtmlEmail.java.html#L129" class="el_method">replacePattern(String, Pattern)</a></td><td class="bar" id="b1"><img src="../.resources/redbar.gif" width="5" height="10" title="5" alt="5"/><img src="../.resources/greenbar.gif" width="114" height="10" title="100" alt="100"/></td><td class="ctr2" id="c4">95%</td
><td class="bar" id="d0"><img src="../.resources/redbar.gif" width="40" height="10" title="4" alt="4"/><img src="../.resources/greenbar.gif" width="80" height="10" title="8" alt="8"/></td><td class="ctr2" id="e0">67%</td><td class="ctr1" id="f0">4</td><td class="ctr2" id="g0">7</td><td class="ctr1" id="h1">1</td><td class="ctr2" id="i0">25</td><td class="ctr1" id="j1">0</td><td class="ctr2" id="k1">1</td></tr><tr><td id="a5"><a href="ImageHtmlEmail.java.html#L65" class="el_method">static {...}</a></td><td class="bar" id="b2"><img src="../.resources/greenbar.gif" width="8" height="10" title="7" alt="7"/></td><td class="ctr2" id="c0">100%</td><td class="bar" id="d2"/><td class="ctr2" id="e2">n/a</td><td class="ctr1" id="f2">0</td><td class="ctr2" id="g2">1</td><td class="ctr1" id="h2">0</td><td class="ctr2" id="i2">2</td><td class="ctr1" id="j2">0</td><td class="ctr2" id="k2">1</td></tr><tr><td id="a4"><a href="ImageHtmlEmail.java.html#L90" class="el_method">setDataSourceResolver(Data
SourceResolver)</a></td><td class="bar" id="b3"><img src="../.resources/greenbar.gif" width="4" height="10" title="4" alt="4"/></td><td class="ctr2" id="c1">100%</td><td class="bar" id="d3"/><td class="ctr2" id="e3">n/a</td><td class="ctr1" id="f3">0</td><td class="ctr2" id="g3">1</td><td class="ctr1" id="h3">0</td><td class="ctr2" id="i3">2</td><td class="ctr1" id="j3">0</td><td class="ctr2" id="k3">1</td></tr><tr><td id="a2"><a href="ImageHtmlEmail.java.html#L46" class="el_method">ImageHtmlEmail()</a></td><td class="bar" id="b4"><img src="../.resources/greenbar.gif" width="3" height="10" title="3" alt="3"/></td><td class="ctr2" id="c2">100%</td><td class="bar" id="d4"/><td class="ctr2" id="e4">n/a</td><td class="ctr1" id="f4">0</td><td class="ctr2" id="g4">1</td><td class="ctr1" id="h4">0</td><td class="ctr2" id="i4">1</td><td class="ctr1" id="j4">0</td><td class="ctr2" id="k4">1</td></tr><tr><td id="a1"><a href="ImageHtmlEmail.java.html#L80" class="el_method">getDataSourceResolve
r()</a></td><td class="bar" id="b5"><img src="../.resources/greenbar.gif" width="3" height="10" title="3" alt="3"/></td><td class="ctr2" id="c3">100%</td><td class="bar" id="d5"/><td class="ctr2" id="e5">n/a</td><td class="ctr1" id="f5">0</td><td class="ctr2" id="g5">1</td><td class="ctr1" id="h5">0</td><td class="ctr2" id="i5">1</td><td class="ctr1" id="j5">0</td><td class="ctr2" id="k5">1</td></tr></tbody></table><div class="footer"><span class="right">Created with <a href="http://www.eclemma.org/jacoco">JaCoCo</a> 0.7.2.201409121644</span></div></body></html>
\ No newline at end of file
Propchange: websites/production/commons/content/proper/commons-email/jacoco/org.apache.commons.mail/ImageHtmlEmail.html
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: websites/production/commons/content/proper/commons-email/jacoco/org.apache.commons.mail/ImageHtmlEmail.html
------------------------------------------------------------------------------
svn:keywords = Id Revision HeadURL
Propchange: websites/production/commons/content/proper/commons-email/jacoco/org.apache.commons.mail/ImageHtmlEmail.html
------------------------------------------------------------------------------
svn:mime-type = text/html
Added: websites/production/commons/content/proper/commons-email/jacoco/org.apache.commons.mail/ImageHtmlEmail.java.html
==============================================================================
--- websites/production/commons/content/proper/commons-email/jacoco/org.apache.commons.mail/ImageHtmlEmail.java.html (added)
+++ websites/production/commons/content/proper/commons-email/jacoco/org.apache.commons.mail/ImageHtmlEmail.java.html Sat May 23 06:50:57 2015
@@ -0,0 +1,196 @@
+<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="en"><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/><link rel="stylesheet" href="../.resources/report.css" type="text/css"/><link rel="shortcut icon" href="../.resources/report.gif" type="image/gif"/><title>ImageHtmlEmail.java</title><link rel="stylesheet" href="../.resources/prettify.css" type="text/css"/><script type="text/javascript" src="../.resources/prettify.js"></script></head><body onload="window['PR_TAB_WIDTH']=4;prettyPrint()"><div class="breadcrumb" id="breadcrumb"><span class="info"><a href="../.sessions.html" class="el_session">Sessions</a></span><a href="../index.html" class="el_report">Apache Commons Email</a> > <a href="index.source.html" class="el_package">org.apache.commons.mail</a> > <span class="el_source">ImageHtmlEmail.java</span></div><h
1>ImageHtmlEmail.java</h1><pre class="source lang-java linenums">/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.mail;
+
+import javax.activation.DataSource;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * <p>Small wrapper class on top of HtmlEmail which encapsulates the required logic
+ * to retrieve images that are contained in "&lt;img src=../&gt;" elements in the HTML
+ * code. This is done by replacing all img-src-elements with "cid:"-entries and
+ * embedding images in the email.
+ * </p>
+ * <p>
+ * For local files the class tries to either load them via an absolute path or -
+ * if available - use a relative path starting from a base directory. For files
+ * that are not found locally, the implementation tries to download
+ * the element and link it in.
+ * </p>
+ * <p>
+ * The image loading is done by an instance of <code>DataSourceResolver</code>
+ * which has to be provided by the caller.
+ * </p>
+ *
+ * @since 1.3
+ * @version $Id$
+ */
+<span class="fc" id="L46">public class ImageHtmlEmail extends HtmlEmail</span>
+{
+ // Regular Expression to find all <IMG SRC="..."> entries in an HTML
+ // document.It needs to cater for various things, like more whitespaces
+ // including newlines on any place, HTML is not case sensitive and there
+ // can be arbitrary text between "IMG" and "SRC" like IDs and other things.
+
+ /** Regexp for extracting {@code <img>} tags */
+ public static final String REGEX_IMG_SRC =
+ "(<[Ii][Mm][Gg]\\s*[^>]*?\\s+[Ss][Rr][Cc]\\s*=\\s*[\"'])([^\"']+?)([\"'])";
+
+ /** regexp for extracting {@code <script>} tags */
+ public static final String REGEX_SCRIPT_SRC =
+ "(<[Ss][Cc][Rr][Ii][Pp][Tt]\\s*.*?\\s+[Ss][Rr][Cc]\\s*=\\s*[\"'])([^\"']+?)([\"'])";
+
+ // this pattern looks for the HTML image tag which indicates embedded images,
+ // the grouping is necessary to allow to replace the element with the CID
+
+ /** pattern for extracting <img> tags */
+<span class="fc" id="L65"> private static final Pattern IMG_PATTERN = Pattern.compile(REGEX_IMG_SRC);</span>
+
+ /** pattern for extracting <script> tags */
+<span class="fc" id="L68"> private static final Pattern SCRIPT_PATTERN = Pattern.compile(REGEX_SCRIPT_SRC);</span>
+
+ /** resolve the images and script resources to a DataSource */
+ private DataSourceResolver dataSourceResolver;
+
+ /**
+ * Get the data source resolver.
+ *
+ * @return the resolver
+ */
+ public DataSourceResolver getDataSourceResolver()
+ {
+<span class="fc" id="L80"> return dataSourceResolver;</span>
+ }
+
+ /**
+ * Set the data source resolver.
+ *
+ * @param dataSourceResolver the resolver
+ */
+ public void setDataSourceResolver(final DataSourceResolver dataSourceResolver)
+ {
+<span class="fc" id="L90"> this.dataSourceResolver = dataSourceResolver;</span>
+<span class="fc" id="L91"> }</span>
+
+ /**
+ * Does the work of actually building the MimeMessage.
+ *
+ * @see org.apache.commons.mail.HtmlEmail#buildMimeMessage()
+ * @throws EmailException building the MimeMessage failed
+ */
+ @Override
+ public void buildMimeMessage() throws EmailException
+ {
+ try
+ {
+ // embed all the matching image and script resources within the email
+<span class="fc" id="L105"> String temp = replacePattern(super.html, IMG_PATTERN);</span>
+<span class="fc" id="L106"> temp = replacePattern(temp, SCRIPT_PATTERN);</span>
+<span class="fc" id="L107"> setHtmlMsg(temp);</span>
+<span class="fc" id="L108"> super.buildMimeMessage();</span>
+ }
+<span class="nc" id="L110"> catch (final IOException e)</span>
+ {
+<span class="nc" id="L112"> throw new EmailException("Building the MimeMessage failed", e);</span>
+<span class="fc" id="L113"> }</span>
+<span class="fc" id="L114"> }</span>
+
+ /**
+ * Replace the regexp matching resource locations with "cid:..." references.
+ *
+ * @param htmlMessage the HTML message to analyze
+ * @param pattern the regular expression to find resources
+ * @return the HTML message containing "cid" references
+ * @throws EmailException creating the email failed
+ * @throws IOException resolving the resources failed
+ */
+ private String replacePattern(final String htmlMessage, final Pattern pattern)
+ throws EmailException, IOException
+ {
+ DataSource dataSource;
+<span class="fc" id="L129"> final StringBuffer stringBuffer = new StringBuffer();</span>
+
+ // maps "cid" --> name
+<span class="fc" id="L132"> final Map<String, String> cidCache = new HashMap<String, String>();</span>
+
+ // maps "name" --> dataSource
+<span class="fc" id="L135"> final Map<String, DataSource> dataSourceCache = new HashMap<String, DataSource>();</span>
+
+ // in the String, replace all "img src" with a CID and embed the related
+ // image file if we find it.
+<span class="fc" id="L139"> final Matcher matcher = pattern.matcher(htmlMessage);</span>
+
+ // the matcher returns all instances one by one
+<span class="fc bfc" id="L142" title="All 2 branches covered."> while (matcher.find())</span>
+ {
+ // in the RegEx we have the <src> element as second "group"
+<span class="fc" id="L145"> final String resourceLocation = matcher.group(2);</span>
+
+ // avoid loading the same data source more than once
+<span class="pc bpc" id="L148" title="1 of 2 branches missed."> if (dataSourceCache.get(resourceLocation) == null)</span>
+ {
+ // in lenient mode we might get a 'null' data source if the resource was not found
+<span class="fc" id="L151"> dataSource = getDataSourceResolver().resolve(resourceLocation);</span>
+
+<span class="pc bpc" id="L153" title="1 of 2 branches missed."> if (dataSource != null)</span>
+ {
+<span class="fc" id="L155"> dataSourceCache.put(resourceLocation, dataSource);</span>
+ }
+ }
+ else
+ {
+<span class="nc" id="L160"> dataSource = dataSourceCache.get(resourceLocation);</span>
+ }
+
+<span class="pc bpc" id="L163" title="1 of 2 branches missed."> if (dataSource != null)</span>
+ {
+<span class="fc" id="L165"> String name = dataSource.getName();</span>
+<span class="fc bfc" id="L166" title="All 2 branches covered."> if (EmailUtils.isEmpty(name))</span>
+ {
+<span class="fc" id="L168"> name = resourceLocation;</span>
+ }
+
+<span class="fc" id="L171"> String cid = cidCache.get(name);</span>
+
+<span class="pc bpc" id="L173" title="1 of 2 branches missed."> if (cid == null)</span>
+ {
+<span class="fc" id="L175"> cid = embed(dataSource, name);</span>
+<span class="fc" id="L176"> cidCache.put(name, cid);</span>
+ }
+
+ // if we embedded something, then we need to replace the URL with
+ // the CID, otherwise the Matcher takes care of adding the
+ // non-replaced text afterwards, so no else is necessary here!
+<span class="fc" id="L182"> matcher.appendReplacement(stringBuffer,</span>
+ Matcher.quoteReplacement(matcher.group(1) + "cid:" + cid + matcher.group(3)));
+ }
+<span class="fc" id="L185"> }</span>
+
+ // append the remaining items...
+<span class="fc" id="L188"> matcher.appendTail(stringBuffer);</span>
+
+<span class="fc" id="L190"> cidCache.clear();</span>
+<span class="fc" id="L191"> dataSourceCache.clear();</span>
+
+<span class="fc" id="L193"> return stringBuffer.toString();</span>
+ }
+}
+</pre><div class="footer"><span class="right">Created with <a href="http://www.eclemma.org/jacoco">JaCoCo</a> 0.7.2.201409121644</span></div></body></html>
\ No newline at end of file
Propchange: websites/production/commons/content/proper/commons-email/jacoco/org.apache.commons.mail/ImageHtmlEmail.java.html
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: websites/production/commons/content/proper/commons-email/jacoco/org.apache.commons.mail/ImageHtmlEmail.java.html
------------------------------------------------------------------------------
svn:keywords = Id Revision HeadURL
Propchange: websites/production/commons/content/proper/commons-email/jacoco/org.apache.commons.mail/ImageHtmlEmail.java.html
------------------------------------------------------------------------------
svn:mime-type = text/html
Added: websites/production/commons/content/proper/commons-email/jacoco/org.apache.commons.mail/MultiPartEmail.html
==============================================================================
--- websites/production/commons/content/proper/commons-email/jacoco/org.apache.commons.mail/MultiPartEmail.html (added)
+++ websites/production/commons/content/proper/commons-email/jacoco/org.apache.commons.mail/MultiPartEmail.html Sat May 23 06:50:57 2015
@@ -0,0 +1 @@
+<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="en"><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/><link rel="stylesheet" href="../.resources/report.css" type="text/css"/><link rel="shortcut icon" href="../.resources/report.gif" type="image/gif"/><title>MultiPartEmail</title><script type="text/javascript" src="../.resources/sort.js"></script></head><body onload="initialSort(['breadcrumb'])"><div class="breadcrumb" id="breadcrumb"><span class="info"><a href="../.sessions.html" class="el_session">Sessions</a></span><a href="../index.html" class="el_report">Apache Commons Email</a> > <a href="index.html" class="el_package">org.apache.commons.mail</a> > <span class="el_class">MultiPartEmail</span></div><h1>MultiPartEmail</h1><table class="coverage" cellspacing="0" id="coveragetable"><thead><tr><td class="sorta
ble" id="a" onclick="toggleSort(this)">Element</td><td class="down sortable bar" id="b" onclick="toggleSort(this)">Missed Instructions</td><td class="sortable ctr2" id="c" onclick="toggleSort(this)">Cov.</td><td class="sortable bar" id="d" onclick="toggleSort(this)">Missed Branches</td><td class="sortable ctr2" id="e" onclick="toggleSort(this)">Cov.</td><td class="sortable ctr1" id="f" onclick="toggleSort(this)">Missed</td><td class="sortable ctr2" id="g" onclick="toggleSort(this)">Cxty</td><td class="sortable ctr1" id="h" onclick="toggleSort(this)">Missed</td><td class="sortable ctr2" id="i" onclick="toggleSort(this)">Lines</td><td class="sortable ctr1" id="j" onclick="toggleSort(this)">Missed</td><td class="sortable ctr2" id="k" onclick="toggleSort(this)">Methods</td></tr></thead><tfoot><tr><td>Total</td><td class="bar">201 of 450</td><td class="ctr2">55%</td><td class="bar">13 of 34</td><td class="ctr2">62%</td><td class="ctr1">19</td><td class="ctr2">40</td><td class="ctr1">45</
td><td class="ctr2">121</td><td class="ctr1">6</td><td class="ctr2">23</td></tr></tfoot><tbody><tr><td id="a5"><a href="MultiPartEmail.java.html#L305" class="el_method">attach(EmailAttachment)</a></td><td class="bar" id="b0"><img src="../.resources/redbar.gif" width="64" height="10" title="45" alt="45"/><img src="../.resources/greenbar.gif" width="55" height="10" title="39" alt="39"/></td><td class="ctr2" id="c15">46%</td><td class="bar" id="d0"><img src="../.resources/redbar.gif" width="60" height="10" title="3" alt="3"/><img src="../.resources/greenbar.gif" width="60" height="10" title="3" alt="3"/></td><td class="ctr2" id="e3">50%</td><td class="ctr1" id="f0">3</td><td class="ctr2" id="g0">4</td><td class="ctr1" id="h1">5</td><td class="ctr2" id="i0">17</td><td class="ctr1" id="j6">0</td><td class="ctr2" id="k0">1</td></tr><tr><td id="a6"><a href="MultiPartEmail.java.html#L274" class="el_method">attach(File)</a></td><td class="bar" id="b1"><img src="../.resources/redbar.gif" widt
h="42" height="10" title="30" alt="30"/><img src="../.resources/greenbar.gif" width="27" height="10" title="19" alt="19"/></td><td class="ctr2" id="c16">39%</td><td class="bar" id="d4"><img src="../.resources/redbar.gif" width="20" height="10" title="1" alt="1"/><img src="../.resources/greenbar.gif" width="20" height="10" title="1" alt="1"/></td><td class="ctr2" id="e4">50%</td><td class="ctr1" id="f3">1</td><td class="ctr2" id="g5">2</td><td class="ctr1" id="h5">3</td><td class="ctr2" id="i5">7</td><td class="ctr1" id="j7">0</td><td class="ctr2" id="k1">1</td></tr><tr><td id="a2"><a href="MultiPartEmail.java.html#L101" class="el_method">addPart(String, String)</a></td><td class="bar" id="b2"><img src="../.resources/redbar.gif" width="28" height="10" title="20" alt="20"/></td><td class="ctr2" id="c17">0%</td><td class="bar" id="d9"/><td class="ctr2" id="e9">n/a</td><td class="ctr1" id="f4">1</td><td class="ctr2" id="g9">1</td><td class="ctr1" id="h0">7</td><td class="ctr2" id="i6">7
</td><td class="ctr1" id="j0">1</td><td class="ctr2" id="k2">1</td></tr><tr><td id="a4"><a href="MultiPartEmail.java.html#L460" class="el_method">attach(DataSource, String, String, String)</a></td><td class="bar" id="b3"><img src="../.resources/redbar.gif" width="21" height="10" title="15" alt="15"/><img src="../.resources/greenbar.gif" width="45" height="10" title="32" alt="32"/></td><td class="ctr2" id="c10">68%</td><td class="bar" id="d5"><img src="../.resources/redbar.gif" width="20" height="10" title="1" alt="1"/><img src="../.resources/greenbar.gif" width="20" height="10" title="1" alt="1"/></td><td class="ctr2" id="e5">50%</td><td class="ctr1" id="f5">1</td><td class="ctr2" id="g6">2</td><td class="ctr1" id="h2">5</td><td class="ctr2" id="i1">15</td><td class="ctr1" id="j8">0</td><td class="ctr2" id="k3">1</td></tr><tr><td id="a21"><a href="MultiPartEmail.java.html#L191" class="el_method">setMsg(String)</a></td><td class="bar" id="b4"><img src="../.resources/redbar.gif" width
="20" height="10" title="14" alt="14"/><img src="../.resources/greenbar.gif" width="32" height="10" title="23" alt="23"/></td><td class="ctr2" id="c11">62%</td><td class="bar" id="d1"><img src="../.resources/redbar.gif" width="60" height="10" title="3" alt="3"/><img src="../.resources/greenbar.gif" width="60" height="10" title="3" alt="3"/></td><td class="ctr2" id="e6">50%</td><td class="ctr1" id="f1">3</td><td class="ctr2" id="g1">4</td><td class="ctr1" id="h3">4</td><td class="ctr2" id="i3">10</td><td class="ctr1" id="j9">0</td><td class="ctr2" id="k4">1</td></tr><tr><td id="a8"><a href="MultiPartEmail.java.html#L390" class="el_method">attach(URL, String, String, String)</a></td><td class="bar" id="b5"><img src="../.resources/redbar.gif" width="20" height="10" title="14" alt="14"/><img src="../.resources/greenbar.gif" width="22" height="10" title="16" alt="16"/></td><td class="ctr2" id="c14">53%</td><td class="bar" id="d10"/><td class="ctr2" id="e10">n/a</td><td class="ctr1" id="f
13">0</td><td class="ctr2" id="g10">1</td><td class="ctr1" id="h8">2</td><td class="ctr2" id="i8">6</td><td class="ctr1" id="j10">0</td><td class="ctr2" id="k5">1</td></tr><tr><td id="a3"><a href="MultiPartEmail.java.html#L421" class="el_method">attach(DataSource, String, String)</a></td><td class="bar" id="b6"><img src="../.resources/redbar.gif" width="18" height="10" title="13" alt="13"/><img src="../.resources/greenbar.gif" width="28" height="10" title="20" alt="20"/></td><td class="ctr2" id="c12">61%</td><td class="bar" id="d2"><img src="../.resources/redbar.gif" width="60" height="10" title="3" alt="3"/><img src="../.resources/greenbar.gif" width="60" height="10" title="3" alt="3"/></td><td class="ctr2" id="e7">50%</td><td class="ctr1" id="f2">3</td><td class="ctr2" id="g2">4</td><td class="ctr1" id="h6">3</td><td class="ctr2" id="i4">9</td><td class="ctr1" id="j11">0</td><td class="ctr2" id="k6">1</td></tr><tr><td id="a0"><a href="MultiPartEmail.java.html#L128" class="el_metho
d">addPart(MimeMultipart)</a></td><td class="bar" id="b7"><img src="../.resources/redbar.gif" width="18" height="10" title="13" alt="13"/></td><td class="ctr2" id="c18">0%</td><td class="bar" id="d11"/><td class="ctr2" id="e11">n/a</td><td class="ctr1" id="f6">1</td><td class="ctr2" id="g11">1</td><td class="ctr1" id="h7">3</td><td class="ctr2" id="i11">3</td><td class="ctr1" id="j1">1</td><td class="ctr2" id="k7">1</td></tr><tr><td id="a9"><a href="MultiPartEmail.java.html#L229" class="el_method">buildMimeMessage()</a></td><td class="bar" id="b8"><img src="../.resources/redbar.gif" width="17" height="10" title="12" alt="12"/><img src="../.resources/greenbar.gif" width="24" height="10" title="17" alt="17"/></td><td class="ctr2" id="c13">59%</td><td class="bar" id="d3"><img src="../.resources/redbar.gif" width="20" height="10" title="1" alt="1"/><img src="../.resources/greenbar.gif" width="60" height="10" title="3" alt="3"/></td><td class="ctr2" id="e2">75%</td><td class="ctr1" id="f
7">1</td><td class="ctr2" id="g3">3</td><td class="ctr1" id="h4">4</td><td class="ctr2" id="i2">12</td><td class="ctr1" id="j12">0</td><td class="ctr2" id="k8">1</td></tr><tr><td id="a1"><a href="MultiPartEmail.java.html#L147" class="el_method">addPart(MimeMultipart, int)</a></td><td class="bar" id="b9"><img src="../.resources/redbar.gif" width="8" height="10" title="6" alt="6"/><img src="../.resources/greenbar.gif" width="20" height="10" title="14" alt="14"/></td><td class="ctr2" id="c9">70%</td><td class="bar" id="d12"/><td class="ctr2" id="e12">n/a</td><td class="ctr1" id="f14">0</td><td class="ctr2" id="g12">1</td><td class="ctr1" id="h9">2</td><td class="ctr2" id="i7">7</td><td class="ctr1" id="j13">0</td><td class="ctr2" id="k9">1</td></tr><tr><td id="a15"><a href="MultiPartEmail.java.html#L167" class="el_method">init()</a></td><td class="bar" id="b10"><img src="../.resources/redbar.gif" width="7" height="10" title="5" alt="5"/><img src="../.resources/greenbar.gif" width="21"
height="10" title="15" alt="15"/></td><td class="ctr2" id="c8">75%</td><td class="bar" id="d6"><img src="../.resources/redbar.gif" width="20" height="10" title="1" alt="1"/><img src="../.resources/greenbar.gif" width="20" height="10" title="1" alt="1"/></td><td class="ctr2" id="e8">50%</td><td class="ctr1" id="f8">1</td><td class="ctr2" id="g7">2</td><td class="ctr1" id="h12">1</td><td class="ctr2" id="i9">6</td><td class="ctr1" id="j14">0</td><td class="ctr2" id="k10">1</td></tr><tr><td id="a22"><a href="MultiPartEmail.java.html#L74" class="el_method">setSubType(String)</a></td><td class="bar" id="b11"><img src="../.resources/redbar.gif" width="5" height="10" title="4" alt="4"/></td><td class="ctr2" id="c19">0%</td><td class="bar" id="d13"/><td class="ctr2" id="e13">n/a</td><td class="ctr1" id="f9">1</td><td class="ctr2" id="g13">1</td><td class="ctr1" id="h10">2</td><td class="ctr2" id="i13">2</td><td class="ctr1" id="j2">1</td><td class="ctr2" id="k11">1</td></tr><tr><td id="a20"
><a href="MultiPartEmail.java.html#L587" class="el_method">setInitialized(boolean)</a></td><td class="bar" id="b12"><img src="../.resources/redbar.gif" width="5" height="10" title="4" alt="4"/></td><td class="ctr2" id="c20">0%</td><td class="bar" id="d14"/><td class="ctr2" id="e14">n/a</td><td class="ctr1" id="f10">1</td><td class="ctr2" id="g14">1</td><td class="ctr1" id="h11">2</td><td class="ctr2" id="i14">2</td><td class="ctr1" id="j3">1</td><td class="ctr2" id="k12">1</td></tr><tr><td id="a14"><a href="MultiPartEmail.java.html#L85" class="el_method">getSubType()</a></td><td class="bar" id="b13"><img src="../.resources/redbar.gif" width="4" height="10" title="3" alt="3"/></td><td class="ctr2" id="c21">0%</td><td class="bar" id="d15"/><td class="ctr2" id="e15">n/a</td><td class="ctr1" id="f11">1</td><td class="ctr2" id="g15">1</td><td class="ctr1" id="h13">1</td><td class="ctr2" id="i16">1</td><td class="ctr1" id="j4">1</td><td class="ctr2" id="k13">1</td></tr><tr><td id="a17"><a
href="MultiPartEmail.java.html#L577" class="el_method">isInitialized()</a></td><td class="bar" id="b14"><img src="../.resources/redbar.gif" width="4" height="10" title="3" alt="3"/></td><td class="ctr2" id="c22">0%</td><td class="bar" id="d16"/><td class="ctr2" id="e16">n/a</td><td class="ctr1" id="f12">1</td><td class="ctr2" id="g16">1</td><td class="ctr1" id="h14">1</td><td class="ctr2" id="i17">1</td><td class="ctr1" id="j5">1</td><td class="ctr2" id="k14">1</td></tr><tr><td id="a13"><a href="MultiPartEmail.java.html#L497" class="el_method">getPrimaryBodyPart()</a></td><td class="bar" id="b15"><img src="../.resources/greenbar.gif" width="30" height="10" title="21" alt="21"/></td><td class="ctr2" id="c0">100%</td><td class="bar" id="d7"><img src="../.resources/greenbar.gif" width="80" height="10" title="4" alt="4"/></td><td class="ctr2" id="e0">100%</td><td class="ctr1" id="f15">0</td><td class="ctr2" id="g4">3</td><td class="ctr1" id="h15">0</td><td class="ctr2" id="i10">6</td><
td class="ctr1" id="j15">0</td><td class="ctr2" id="k15">1</td></tr><tr><td id="a12"><a href="MultiPartEmail.java.html#L520" class="el_method">getContainer()</a></td><td class="bar" id="b16"><img src="../.resources/greenbar.gif" width="11" height="10" title="8" alt="8"/></td><td class="ctr2" id="c1">100%</td><td class="bar" id="d8"><img src="../.resources/greenbar.gif" width="40" height="10" title="2" alt="2"/></td><td class="ctr2" id="e1">100%</td><td class="ctr1" id="f16">0</td><td class="ctr2" id="g8">2</td><td class="ctr1" id="h16">0</td><td class="ctr2" id="i12">3</td><td class="ctr1" id="j16">0</td><td class="ctr2" id="k16">1</td></tr><tr><td id="a7"><a href="MultiPartEmail.java.html#L365" class="el_method">attach(URL, String, String)</a></td><td class="bar" id="b17"><img src="../.resources/greenbar.gif" width="10" height="10" title="7" alt="7"/></td><td class="ctr2" id="c2">100%</td><td class="bar" id="d17"/><td class="ctr2" id="e17">n/a</td><td class="ctr1" id="f17">0</td><t
d class="ctr2" id="g17">1</td><td class="ctr1" id="h17">0</td><td class="ctr2" id="i18">1</td><td class="ctr1" id="j17">0</td><td class="ctr2" id="k17">1</td></tr><tr><td id="a10"><a href="MultiPartEmail.java.html#L535" class="el_method">createBodyPart()</a></td><td class="bar" id="b18"><img src="../.resources/greenbar.gif" width="5" height="10" title="4" alt="4"/></td><td class="ctr2" id="c3">100%</td><td class="bar" id="d18"/><td class="ctr2" id="e18">n/a</td><td class="ctr1" id="f18">0</td><td class="ctr2" id="g18">1</td><td class="ctr1" id="h18">0</td><td class="ctr2" id="i19">1</td><td class="ctr1" id="j18">0</td><td class="ctr2" id="k18">1</td></tr><tr><td id="a11"><a href="MultiPartEmail.java.html#L545" class="el_method">createMimeMultipart()</a></td><td class="bar" id="b19"><img src="../.resources/greenbar.gif" width="5" height="10" title="4" alt="4"/></td><td class="ctr2" id="c4">100%</td><td class="bar" id="d19"/><td class="ctr2" id="e19">n/a</td><td class="ctr1" id="f19">
0</td><td class="ctr2" id="g19">1</td><td class="ctr1" id="h19">0</td><td class="ctr2" id="i20">1</td><td class="ctr1" id="j19">0</td><td class="ctr2" id="k19">1</td></tr><tr><td id="a19"><a href="MultiPartEmail.java.html#L567" class="el_method">setBoolHasAttachments(boolean)</a></td><td class="bar" id="b20"><img src="../.resources/greenbar.gif" width="5" height="10" title="4" alt="4"/></td><td class="ctr2" id="c5">100%</td><td class="bar" id="d20"/><td class="ctr2" id="e20">n/a</td><td class="ctr1" id="f20">0</td><td class="ctr2" id="g20">1</td><td class="ctr1" id="h20">0</td><td class="ctr2" id="i15">2</td><td class="ctr1" id="j20">0</td><td class="ctr2" id="k20">1</td></tr><tr><td id="a18"><a href="MultiPartEmail.java.html#L49" class="el_method">MultiPartEmail()</a></td><td class="bar" id="b21"><img src="../.resources/greenbar.gif" width="4" height="10" title="3" alt="3"/></td><td class="ctr2" id="c6">100%</td><td class="bar" id="d21"/><td class="ctr2" id="e21">n/a</td><td class=
"ctr1" id="f21">0</td><td class="ctr2" id="g21">1</td><td class="ctr1" id="h21">0</td><td class="ctr2" id="i21">1</td><td class="ctr1" id="j21">0</td><td class="ctr2" id="k21">1</td></tr><tr><td id="a16"><a href="MultiPartEmail.java.html#L556" class="el_method">isBoolHasAttachments()</a></td><td class="bar" id="b22"><img src="../.resources/greenbar.gif" width="4" height="10" title="3" alt="3"/></td><td class="ctr2" id="c7">100%</td><td class="bar" id="d22"/><td class="ctr2" id="e22">n/a</td><td class="ctr1" id="f22">0</td><td class="ctr2" id="g22">1</td><td class="ctr1" id="h22">0</td><td class="ctr2" id="i22">1</td><td class="ctr1" id="j22">0</td><td class="ctr2" id="k22">1</td></tr></tbody></table><div class="footer"><span class="right">Created with <a href="http://www.eclemma.org/jacoco">JaCoCo</a> 0.7.2.201409121644</span></div></body></html>
\ No newline at end of file
Propchange: websites/production/commons/content/proper/commons-email/jacoco/org.apache.commons.mail/MultiPartEmail.html
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: websites/production/commons/content/proper/commons-email/jacoco/org.apache.commons.mail/MultiPartEmail.html
------------------------------------------------------------------------------
svn:keywords = Id Revision HeadURL
Propchange: websites/production/commons/content/proper/commons-email/jacoco/org.apache.commons.mail/MultiPartEmail.html
------------------------------------------------------------------------------
svn:mime-type = text/html