001: package org.claros.commons.mail.models;
002:
003: import javax.activation.DataSource;
004:
005: import org.claros.commons.mail.utility.Utility;
006:
007: /**
008: * @author Umut Gokbayrak
009: */
010: public class EmailPart {
011: private int id;
012: private Object content;
013: private String disposition;
014: private String contentType;
015: private String contentId;
016: private long size;
017: private String sizeReadable;
018: private String filename;
019: private String shortname;
020: private DataSource dataSource;
021:
022: public EmailPart() {
023: super ();
024: }
025:
026: public int getId() {
027: return id;
028: }
029:
030: public void setId(int id) {
031: this .id = id;
032: }
033:
034: public Object getContent() {
035: return content;
036: }
037:
038: public void setContent(Object content) {
039: this .content = content;
040: }
041:
042: public String getDisposition() {
043: return disposition;
044: }
045:
046: public void setDisposition(String disposition) {
047: this .disposition = disposition;
048: }
049:
050: public String getContentType() {
051: return contentType;
052: }
053:
054: public void setContentType(String contentType) {
055: this .contentType = contentType;
056: }
057:
058: public String getContentId() {
059: return contentId;
060: }
061:
062: public void setContentId(String contentId) {
063: this .contentId = contentId;
064: }
065:
066: public long getSize() {
067: return size;
068: }
069:
070: public void setSize(long size) {
071: this .size = size;
072: this .sizeReadable = Utility.sizeToHumanReadable(size);
073: }
074:
075: /**
076: * @return
077: */
078: public String getFileName() {
079: return filename;
080: }
081:
082: /**
083: * @param string
084: */
085: public void setFileName(String string) {
086: filename = string;
087:
088: if (filename == null) {
089: if (getContentType().indexOf("text/html") >= 0) {
090: filename = "Html Body";
091: } else if (getContentType().indexOf("text/plain") >= 0) {
092: filename = "Text Body";
093: } else {
094: filename = "Body";
095: }
096: }
097: if (filename.length() > 9) {
098: shortname = filename.substring(0, 9) + "...";
099: } else {
100: shortname = filename;
101: }
102: }
103:
104: public boolean isPlainText() {
105: if (this .contentType != null
106: && this .contentType.indexOf("text/plain") >= 0) {
107: return true;
108: }
109: return false;
110: }
111:
112: public boolean isHTMLText() {
113: if (this .contentType != null
114: && this .contentType.indexOf("text/html") >= 0) {
115: return true;
116: }
117: return false;
118: }
119:
120: public boolean isImage() {
121: if (this .contentType != null
122: && this .contentType.indexOf("image/") >= 0) {
123: return true;
124: }
125: return false;
126: }
127:
128: public boolean isAudio() {
129: if (this .contentType != null
130: && this .contentType.indexOf("audio/") >= 0) {
131: return true;
132: }
133: return false;
134: }
135:
136: /**
137: * @return
138: */
139: public String getSizeReadable() {
140: return sizeReadable;
141: }
142:
143: /**
144: * @param string
145: */
146: public void setSizeReadable(String string) {
147: sizeReadable = string;
148: }
149:
150: /**
151: * @return
152: */
153: public String getFilename() {
154: return filename;
155: }
156:
157: /**
158: * @param string
159: */
160: public void setFilename(String string) {
161: filename = string;
162: }
163:
164: /**
165: * @return
166: */
167: public String getShortname() {
168: return shortname;
169: }
170:
171: /**
172: * @param string
173: */
174: public void setShortname(String string) {
175: shortname = string;
176: }
177:
178: /**
179: * @return
180: */
181: public DataSource getDataSource() {
182: return dataSource;
183: }
184:
185: /**
186: * @param source
187: */
188: public void setDataSource(DataSource source) {
189: dataSource = source;
190: }
191:
192: }
|