001    package railo.runtime.net.smtp;
002    
003    import java.io.IOException;
004    import java.io.InputStream;
005    import java.io.Serializable;
006    import java.net.URL;
007    
008    import railo.commons.io.IOUtil;
009    import railo.commons.io.res.Resource;
010    import railo.commons.lang.StringUtil;
011    import railo.runtime.type.List;
012    
013    public class Attachment implements Serializable {
014            
015    
016    
017            private String absolutePath;
018            private URL url;
019            private String type;
020            private String disposition;
021            private String contentID;
022            private String fileName;
023            private boolean removeAfterSend;
024    
025            public Attachment(Resource resource, String type, String disposition,String contentID, boolean removeAfterSend) {
026                    this.absolutePath=resource.getAbsolutePath();// do not store resource, this is pehrhaps not serialiable
027                    this.fileName=resource.getName();
028                    this.removeAfterSend=removeAfterSend;
029                    this.disposition=disposition;
030                    this.contentID=contentID;
031                    
032                    // type
033                    this.type=type;
034                    if(StringUtil.isEmpty(type)) {
035                            InputStream is=null;
036                            try {
037                                    type = IOUtil.getMymeType(is=resource.getInputStream(),null);
038                            } 
039                            catch (IOException e) {}
040                            finally {
041                                    IOUtil.closeEL(is);
042                            }
043                    }
044            }
045            
046            public Attachment(URL url) {
047                    this.url=url;
048                    
049                    // filename
050                    this. fileName=List.last(url.toExternalForm(), '/');
051                    if(StringUtil.isEmpty(this.fileName))this.fileName = "url.txt";
052                    
053                    try {
054                            type = IOUtil.getMymeType(url.openStream(), null);
055                    } catch (IOException e) {}      
056                    
057            }
058            
059            
060    
061            /**
062             * @return the url
063             */
064            public URL getURL() {
065                    return url;
066            }
067            /**
068             * @return the fileName
069             */
070            public String getFileName() {
071                    return fileName;
072            }
073    
074            /**
075             * @param fileName the fileName to set
076             */
077            public void setFileName(String fileName) {
078                    this.fileName = fileName;
079            }
080            
081            /* *
082             * @return the resource
083             * /
084            public Resource getResourcex() {
085                    return resource;
086            }*/
087            
088            public String getAbsolutePath(){
089                    return absolutePath;
090            }
091            
092            /**
093             * @return the removeAfterSend
094             */
095            public boolean isRemoveAfterSend() {
096                    return removeAfterSend;
097            }
098    
099            /**
100             * @param removeAfterSend the removeAfterSend to set
101             */
102            public void setRemoveAfterSend(boolean removeAfterSend) {
103                    this.removeAfterSend = removeAfterSend;
104            }
105    
106            //resource.getAbsolutePath()
107            /**
108             * @return the type
109             */
110            public String getType() {
111                    return type;
112            }
113    
114            /**
115             * @return the disposition
116             */
117            public String getDisposition() {
118                    return disposition;
119            }
120    
121            /**
122             * @return the contentID
123             */
124            public String getContentID() {
125                    return contentID;
126            }
127    }