001/** 002 * 003 * Copyright (c) 2014, the Railo Company Ltd. All rights reserved. 004 * 005 * This library is free software; you can redistribute it and/or 006 * modify it under the terms of the GNU Lesser General Public 007 * License as published by the Free Software Foundation; either 008 * version 2.1 of the License, or (at your option) any later version. 009 * 010 * This library is distributed in the hope that it will be useful, 011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 013 * Lesser General Public License for more details. 014 * 015 * You should have received a copy of the GNU Lesser General Public 016 * License along with this library. If not, see <http://www.gnu.org/licenses/>. 017 * 018 **/ 019package lucee.runtime.net.smtp; 020 021import java.io.IOException; 022import java.io.InputStream; 023import java.io.Serializable; 024import java.net.URL; 025 026import lucee.commons.io.IOUtil; 027import lucee.commons.io.res.Resource; 028import lucee.commons.lang.StringUtil; 029import lucee.runtime.type.util.ListUtil; 030 031public class Attachment implements Serializable { 032 033 034 035 private String absolutePath; 036 private URL url; 037 private String type; 038 private String disposition; 039 private String contentID; 040 private String fileName; 041 private boolean removeAfterSend; 042 043 public Attachment(Resource resource, String type, String disposition,String contentID, boolean removeAfterSend) { 044 this.absolutePath=resource.getAbsolutePath();// do not store resource, this is pehrhaps not serialiable 045 this.fileName=resource.getName(); 046 this.removeAfterSend=removeAfterSend; 047 this.disposition=disposition; 048 this.contentID=contentID; 049 050 // type 051 this.type=type; 052 if(StringUtil.isEmpty(type)) { 053 InputStream is=null; 054 try { 055 type = IOUtil.getMimeType(is=resource.getInputStream(),null); 056 } 057 catch (IOException e) {} 058 finally { 059 IOUtil.closeEL(is); 060 } 061 } 062 } 063 064 public Attachment(URL url) { 065 this.url=url; 066 067 // filename 068 this. fileName=ListUtil.last(url.toExternalForm(), '/'); 069 if(StringUtil.isEmpty(this.fileName))this.fileName = "url.txt"; 070 071 try { 072 type = IOUtil.getMimeType(url.openStream(), null); 073 } catch (IOException e) {} 074 075 } 076 077 078 079 /** 080 * @return the url 081 */ 082 public URL getURL() { 083 return url; 084 } 085 /** 086 * @return the fileName 087 */ 088 public String getFileName() { 089 return fileName; 090 } 091 092 /** 093 * @param fileName the fileName to set 094 */ 095 public void setFileName(String fileName) { 096 this.fileName = fileName; 097 } 098 099 /* * 100 * @return the resource 101 * / 102 public Resource getResourcex() { 103 return resource; 104 }*/ 105 106 public String getAbsolutePath(){ 107 return absolutePath; 108 } 109 110 /** 111 * @return the removeAfterSend 112 */ 113 public boolean isRemoveAfterSend() { 114 return removeAfterSend; 115 } 116 117 /** 118 * @param removeAfterSend the removeAfterSend to set 119 */ 120 public void setRemoveAfterSend(boolean removeAfterSend) { 121 this.removeAfterSend = removeAfterSend; 122 } 123 124 //resource.getAbsolutePath() 125 /** 126 * @return the type 127 */ 128 public String getType() { 129 return type; 130 } 131 132 /** 133 * @return the disposition 134 */ 135 public String getDisposition() { 136 return disposition; 137 } 138 139 /** 140 * @return the contentID 141 */ 142 public String getContentID() { 143 return contentID; 144 } 145}