EmailAttachment.java

  1. /*
  2.  * Licensed to the Apache Software Foundation (ASF) under one or more
  3.  * contributor license agreements.  See the NOTICE file distributed with
  4.  * this work for additional information regarding copyright ownership.
  5.  * The ASF licenses this file to You under the Apache License, Version 2.0
  6.  * (the "License"); you may not use this file except in compliance with
  7.  * the License.  You may obtain a copy of the License at
  8.  *
  9.  *     http://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  * Unless required by applicable law or agreed to in writing, software
  12.  * distributed under the License is distributed on an "AS IS" BASIS,
  13.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  * See the License for the specific language governing permissions and
  15.  * limitations under the License.
  16.  */
  17. package org.apache.commons.mail2.javax;

  18. import java.net.URL;

  19. /**
  20.  * This class models an email attachment. Used by {@link MultiPartEmail}.
  21.  *
  22.  * @since 1.0
  23.  */
  24. public class EmailAttachment {

  25.     /** Definition of the part being an attachment. */
  26.     public static final String ATTACHMENT = javax.mail.Part.ATTACHMENT;

  27.     /** Definition of the part being inline. */
  28.     public static final String INLINE = javax.mail.Part.INLINE;

  29.     /** The name of this attachment. */
  30.     private String name = "";

  31.     /** The description of this attachment. */
  32.     private String description = "";

  33.     /** The path to this attachment (ie c:/path/to/file.jpg). */
  34.     private String path = "";

  35.     /** The HttpURI where the file can be got. */
  36.     private URL url;

  37.     /** The disposition. */
  38.     private String disposition = ATTACHMENT;

  39.     /**
  40.      * Constructs a new instance.
  41.      */
  42.     public EmailAttachment() {
  43.         // empty
  44.     }

  45.     /**
  46.      * Gets the description.
  47.      *
  48.      * @return A String.
  49.      * @since 1.0
  50.      */
  51.     public String getDescription() {
  52.         return description;
  53.     }

  54.     /**
  55.      * Gets the disposition.
  56.      *
  57.      * @return A String.
  58.      * @since 1.0
  59.      */
  60.     public String getDisposition() {
  61.         return disposition;
  62.     }

  63.     /**
  64.      * Gets the name.
  65.      *
  66.      * @return A String.
  67.      * @since 1.0
  68.      */
  69.     public String getName() {
  70.         return name;
  71.     }

  72.     /**
  73.      * Gets the path.
  74.      *
  75.      * @return A String.
  76.      * @since 1.0
  77.      */
  78.     public String getPath() {
  79.         return path;
  80.     }

  81.     /**
  82.      * Gets the URL.
  83.      *
  84.      * @return A URL.
  85.      * @since 1.0
  86.      */
  87.     public URL getURL() {
  88.         return url;
  89.     }

  90.     /**
  91.      * Sets the description.
  92.      *
  93.      * @param desc A String.
  94.      * @since 1.0
  95.      */
  96.     public void setDescription(final String desc) {
  97.         this.description = desc;
  98.     }

  99.     /**
  100.      * Sets the disposition.
  101.      *
  102.      * @param aDisposition A String.
  103.      * @since 1.0
  104.      */
  105.     public void setDisposition(final String aDisposition) {
  106.         this.disposition = aDisposition;
  107.     }

  108.     /**
  109.      * Sets the name.
  110.      *
  111.      * @param aName A String.
  112.      * @since 1.0
  113.      */
  114.     public void setName(final String aName) {
  115.         this.name = aName;
  116.     }

  117.     /**
  118.      * Sets the path to the attachment. The path can be absolute or relative and should include the file name.
  119.      * <p>
  120.      * Example: /home/user/images/image.jpg<br>
  121.      * Example: images/image.jpg
  122.      *
  123.      * @param aPath A String.
  124.      * @since 1.0
  125.      */
  126.     public void setPath(final String aPath) {
  127.         this.path = aPath;
  128.     }

  129.     /**
  130.      * Sets the URL.
  131.      *
  132.      * @param aUrl A URL.
  133.      * @since 1.0
  134.      */
  135.     public void setURL(final URL aUrl) {
  136.         this.url = aUrl;
  137.     }
  138. }