Source Code Cross Referenced for FetchMailService.java in  » Chat » claros-intouch » org » claros » intouch » webmail » services » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Chat » claros intouch » org.claros.intouch.webmail.services 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.claros.intouch.webmail.services;
002:
003:        import java.io.IOException;
004:        import java.io.PrintWriter;
005:        import java.util.ArrayList;
006:        import java.util.List;
007:        import java.util.Locale;
008:
009:        import javax.servlet.ServletException;
010:        import javax.servlet.http.HttpServletRequest;
011:        import javax.servlet.http.HttpServletResponse;
012:
013:        import org.claros.commons.auth.models.AuthProfile;
014:        import org.claros.commons.mail.models.ConnectionMetaHandler;
015:        import org.claros.commons.mail.models.ConnectionProfile;
016:        import org.claros.commons.mail.models.Email;
017:        import org.claros.commons.mail.models.EmailPart;
018:        import org.claros.commons.mail.utility.Constants;
019:        import org.claros.intouch.common.services.BaseService;
020:        import org.claros.intouch.webmail.controllers.IconController;
021:        import org.claros.intouch.webmail.controllers.MailController;
022:        import org.claros.intouch.webmail.factory.MailControllerFactory;
023:        import org.claros.intouch.common.utility.Utility;
024:
025:        public class FetchMailService extends BaseService {
026:            private static Locale loc = new Locale("en", "US");
027:            private static final long serialVersionUID = 2997611737645527623L;
028:
029:            /**
030:             * The doPost method of the servlet. <br>
031:             *
032:             * This method is called when a form has its tag value method equals to post.
033:             * 
034:             * @param request the request send by the client to the server
035:             * @param response the response send by the server to the client
036:             * @throws ServletException if an error occurred
037:             * @throws IOException if an error occurred
038:             */
039:            public void doPost(HttpServletRequest request,
040:                    HttpServletResponse response) throws ServletException,
041:                    IOException {
042:
043:                response.setHeader("Expires", "-1");
044:                response.setHeader("Pragma", "no-cache");
045:                response.setHeader("Cache-control", "no-cache");
046:                response.setHeader("Content-Type", "text/html; charset=utf-8");
047:
048:                PrintWriter out = response.getWriter();
049:
050:                String msgId = request.getParameter("msgId");
051:                String folder = request.getParameter("folder");
052:
053:                AuthProfile auth = getAuthProfile(request);
054:                ConnectionMetaHandler handler = (ConnectionMetaHandler) request
055:                        .getSession().getAttribute("handler");
056:                ConnectionProfile profile = (ConnectionProfile) request
057:                        .getSession().getAttribute("profile");
058:
059:                MailControllerFactory factory = new MailControllerFactory(auth,
060:                        profile, handler, folder);
061:                MailController mailCont = factory.getMailController();
062:
063:                try {
064:                    Email email = mailCont.getEmailById(new Long(msgId));
065:                    request.getSession().setAttribute("email", email);
066:
067:                    String format = "html";
068:                    int i = -1;
069:                    if (format == null || format.equals("html")) {
070:                        i = findHtmlBody(email.getParts());
071:                    }
072:                    if (i == -1) {
073:                        i = findTextBody(email.getParts());
074:                    }
075:
076:                    String from = Utility
077:                            .htmlCheck(org.claros.commons.utility.Utility
078:                                    .updateTRChars(email.getBaseHeader()
079:                                            .getFromShown()));
080:                    String to = Utility
081:                            .htmlCheck(org.claros.commons.utility.Utility
082:                                    .updateTRChars(email.getBaseHeader()
083:                                            .getToShown()));
084:                    String cc = Utility
085:                            .htmlCheck(org.claros.commons.utility.Utility
086:                                    .updateTRChars(email.getBaseHeader()
087:                                            .getCcShown()));
088:                    String date = Utility.htmlCheck(email.getBaseHeader()
089:                            .getDateShown());
090:                    String subject = Utility
091:                            .htmlCheck(org.claros.commons.utility.Utility
092:                                    .updateTRChars(email.getBaseHeader()
093:                                            .getSubject()));
094:                    Boolean sendReceiptNotification = email.getBaseHeader()
095:                            .getRequestReceiptNotification();
096:                    String sendReceiptNotificationEmail = email.getBaseHeader()
097:                            .getReceiptNotificationEmail();
098:                    String notificationEmail = "";
099:
100:                    if (sendReceiptNotification != null
101:                            && sendReceiptNotification.booleanValue()
102:                            && sendReceiptNotificationEmail != null
103:                            && email.getBaseHeader().getUnread().booleanValue()) {
104:                        notificationEmail = org.claros.commons.utility.Utility
105:                                .convertTRCharsToHtmlSafe(sendReceiptNotificationEmail);
106:                    }
107:
108:                    if (profile.getProtocol().equals(Constants.POP3)) {
109:                        mailCont.markAsRead(new Long(msgId));
110:                    }
111:
112:                    if (from == null || from.equals("")) {
113:                        from = getText(request, "unknown.sender");
114:                    }
115:                    if (subject == null || subject.equals("")) {
116:                        subject = getText(request, "no.subject");
117:                    }
118:
119:                    out
120:                            .print("<div id='mailViewTitle' notificationEmail='"
121:                                    + notificationEmail
122:                                    + "' class='title' msgid='"
123:                                    + msgId
124:                                    + "' folder='"
125:                                    + folder
126:                                    + "'>"
127:                                    + "<div class='buttons'>"
128:                                    + "<table border='0' cellspacing='0' cellpadding='0'><tr><td nowrap='nowrap'>"
129:                                    + "	<div><a style='text-indent:0px;width:auto;overflow:visible;cursor:pointer;color:#5A799E;' href='javascript:;' onclick='toggleHeader()' id='headerChoose'>"
130:                                    + getText(request, "show.more.headers")
131:                                    + "</a>&nbsp;&nbsp;<img src='images/welcome-border.gif' height='10'/>&nbsp;&nbsp;</div>"
132:                                    + "</td><td nowrap='nowrap'>"
133:                                    + "		<a href='javascript:;' class='toggle on' title='"
134:                                    + getText(request, "toggle.list.on")
135:                                    + "'>"
136:                                    + getText(request, "toggle.list.on")
137:                                    + "</a>"
138:                                    + "		<a href='javascript:;' class='toggle off' title='"
139:                                    + getText(request, "toggle.list.off")
140:                                    + "'>"
141:                                    + getText(request, "toggle.list.off")
142:                                    + "</a><br/>"
143:                                    + "</td></tr></table>"
144:                                    + "</div>");
145:                    out.print("<p id='subjectHeader'><span class='subtitle'>"
146:                            + getText(request, "subject")
147:                            + ":</span><span>"
148:                            + org.claros.commons.utility.Utility
149:                                    .convertTRCharsToHtmlSafe(subject)
150:                            + "</span></p>"
151:                            + "<p id='fromHeader'><span class='subtitle'>"
152:                            + getText(request, "from")
153:                            + ":</span><span>"
154:                            + org.claros.commons.utility.Utility
155:                                    .convertTRCharsToHtmlSafe(from)
156:                            + "</span></p>");
157:
158:                    if (date != null && !date.equals("")) {
159:                        out
160:                                .print("<p style='display:none' id='dateHeader'><span class='subtitle'>"
161:                                        + getText(request, "date")
162:                                        + ":</span><span>"
163:                                        + date
164:                                        + "</span></p>");
165:                    }
166:                    if (to != null && !to.equals("")) {
167:                        out
168:                                .print("<p style='display:none' id='toHeader'><span class='subtitle'>"
169:                                        + getText(request, "to")
170:                                        + ":</span><span>" + to + "</span></p>");
171:                    }
172:                    if (cc != null && !cc.equals("")) {
173:                        out
174:                                .print("<p style='display:none' id='ccHeader'><span class='subtitle'>"
175:                                        + getText(request, "cc")
176:                                        + ":</span><span>" + cc + "</span></p>");
177:                    }
178:
179:                    // parts begin
180:                    List parts = email.getParts();
181:                    if (parts != null) {
182:                        if (parts.size() > 1 || i == -1) {
183:                            out.println("<p style='float:left'>");
184:                            EmailPart tmp = null;
185:                            String mime = null;
186:                            for (int j = 0; j < parts.size(); j++) {
187:                                tmp = (EmailPart) parts.get(j);
188:
189:                                mime = tmp.getContentType();
190:                                mime = mime.toLowerCase(loc).trim();
191:                                if (mime.indexOf(";") > 0) {
192:                                    mime = mime.substring(0, mime.indexOf(";"));
193:                                }
194:                                if (mime.indexOf(" ") > 0) {
195:                                    mime = mime.substring(0, mime.indexOf(" "));
196:                                }
197:                                String fileName = org.claros.commons.utility.Utility
198:                                        .updateTRChars(tmp.getFilename());
199:                                out
200:                                        .println("<img src='images/attachment-small.gif'/>&nbsp;<a href=\"javascript:;\" onclick=\"Dom.get('msgTextIframe').src = 'webmail/dumpPart.service?dl=false&partid="
201:                                                + j
202:                                                + "';menuLayers.hide();\" onmouseout=\"menuLayers.hide()\" onmouseover=\"menuLayers.show('attachmenu"
203:                                                + j
204:                                                + "', event)\" style='color:#5A799E;font-weight:bold;'>"
205:                                                + fileName + "</a>&nbsp;&nbsp;");
206:                                out.print("<div id='attachmenu" + j
207:                                        + "' class='menu'>");
208:                                out
209:                                        .print("<img src='images/mime/"
210:                                                + IconController.findIcon(tmp
211:                                                        .getContentType())
212:                                                + "' style='float:left;padding-bottom:20px;padding-right:8px;'/>");
213:                                out.print("<strong>"
214:                                        + getText(request, "file.name")
215:                                        + ":</strong>" + fileName + "<br/>");
216:                                out.print("<strong>"
217:                                        + getText(request, "mime.type")
218:                                        + ":</strong>" + mime + "<br/>");
219:                                out.print("<strong>" + getText(request, "size")
220:                                        + ":</strong>" + tmp.getSizeReadable()
221:                                        + "<br/><br/>");
222:                                out
223:                                        .print("<table border='0' cellspacing='1' cellpadding='5'>"
224:                                                + "<tr><td>"
225:                                                + "<table height='23' border='0' cellspacing='0' cellpadding='0' width='50'>"
226:                                                + "	<tr>"
227:                                                + "	  <td width='1%'><img src='images/button-left-bg.gif' width='9' height='23'/></td>"
228:                                                + "	  <td nowrap='nowrap' style='background-image: url(images/button-bg.gif);text-align:center;padding-left:15px;padding-right:15px;cursor:pointer' width='98%' height='23' onclick=\"menuLayers.hide();Dom.get('msgTextIframe').src = 'webmail/dumpPart.service?dl=true&partid="
229:                                                + j
230:                                                + "';\"'>"
231:                                                + getText(request, "save")
232:                                                + "</td>"
233:                                                + "	  <td width='1%'><img src='images/button-right-bg.gif' width='9' height='23'/></td>"
234:                                                + "	</tr>"
235:                                                + "</table>"
236:                                                + "</td>"
237:                                                + "<td>"
238:                                                + "<table height='23' border='0' cellspacing='0' cellpadding='0' width='50'>"
239:                                                + "	<tr>"
240:                                                + "	  <td width='1%'><img src='images/button-left-bg.gif' width='9' height='23'/></td>"
241:                                                + "	  <td nowrap='nowrap' style='background-image: url(images/button-bg.gif);text-align:center;padding-left:15px;padding-right:15px;cursor:pointer' width='98%' height='23' onclick=\"menuLayers.hide();Dom.get('msgTextIframe').src = 'webmail/dumpPart.service?dl=false&partid="
242:                                                + j
243:                                                + "';\">"
244:                                                + getText(request, "open")
245:                                                + "</td>"
246:                                                + "	  <td width='1%'><img src='images/button-right-bg.gif' width='9' height='23'/></td>"
247:                                                + "	</tr>"
248:                                                + "</table>"
249:                                                + "</td>"
250:                                                + "</tr>"
251:                                                + "</table>");
252:                                out.print("</div>");
253:                            }
254:                            out.println("</p>");
255:                        }
256:                    }
257:                    // parts end
258:
259:                    out
260:                            .print("</div>"
261:                                    + "<div id='msgText'>"
262:                                    + "<iframe id='msgTextIframe' align='center' frameborder='0' height='250' width='100%' style='font-size: 11px;font: arial, sans-serif;' scrolling='auto' src='webmail/dumpPart.service?partid="
263:                                    + i + "' width='100%' border='0'/>"
264:                                    + "</div>");
265:
266:                } catch (Exception e) {
267:                    e.printStackTrace();
268:                }
269:            }
270:
271:            /**
272:             * @param list
273:             * @return
274:             */
275:            private int findHtmlBody(ArrayList parts) {
276:                for (int i = 0; i < parts.size(); i++) {
277:                    EmailPart body = (EmailPart) parts.get(i);
278:                    String cType = body.getContentType();
279:                    if (cType.toLowerCase().startsWith("text/html")) {
280:                        return i;
281:                    }
282:                }
283:                return -1;
284:            }
285:
286:            private int findTextBody(ArrayList parts) {
287:                for (int i = 0; i < parts.size(); i++) {
288:                    EmailPart body = (EmailPart) parts.get(i);
289:                    String cType = body.getContentType();
290:                    if (cType.toLowerCase().startsWith("text/plain")) {
291:                        return i;
292:                    }
293:                }
294:                return -1;
295:            }
296:
297:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.