Source Code Cross Referenced for CommandHelper.java in  » Mail-Clients » columba-1.4 » org » columba » mail » spam » command » 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 » Mail Clients » columba 1.4 » org.columba.mail.spam.command 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        //The contents of this file are subject to the Mozilla Public License Version 1.1
002:        //(the "License"); you may not use this file except in compliance with the
003:        //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
004:        //
005:        //Software distributed under the License is distributed on an "AS IS" basis,
006:        //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
007:        //for the specific language governing rights and
008:        //limitations under the License.
009:        //
010:        //The Original Code is "The Columba Project"
011:        //
012:        //The Initial Developers of the Original Code are Frederik Dietz and Timo
013:        // Stich.
014:        //Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
015:        //
016:        //All Rights Reserved.
017:        package org.columba.mail.spam.command;
018:
019:        import java.io.ByteArrayInputStream;
020:        import java.io.InputStream;
021:        import java.io.SequenceInputStream;
022:        import java.util.Iterator;
023:        import java.util.List;
024:        import java.util.Vector;
025:
026:        import org.columba.mail.config.AccountItem;
027:        import org.columba.mail.config.MailConfig;
028:        import org.columba.mail.folder.IMailbox;
029:        import org.columba.ristretto.coder.Base64DecoderInputStream;
030:        import org.columba.ristretto.coder.QuotedPrintableDecoderInputStream;
031:        import org.columba.ristretto.message.Header;
032:        import org.columba.ristretto.message.MimeHeader;
033:        import org.columba.ristretto.message.MimePart;
034:        import org.columba.ristretto.message.MimeTree;
035:
036:        /**
037:         * Helper class provides methods for preparing email messages before getting
038:         * passed along to the spam filter.
039:         * 
040:         * @author fdietz
041:         */
042:        public final class CommandHelper {
043:
044:            /**
045:             * Return bodypart of message as inputstream.
046:             * <p>
047:             * Note, that this depends on wether the user prefers HTML or text messages.
048:             * <p>
049:             * Bodypart is decoded if necessary.
050:             * 
051:             * @param folder
052:             *            selected folder containing the message
053:             * @param uid
054:             *            ID of message
055:             * @return inputstream of message bodypart
056:             * @throws Exception
057:             */
058:            public static InputStream getBodyPart(IMailbox folder, Object uid)
059:                    throws Exception {
060:                MimeTree mimePartTree = folder.getMimePartTree(uid);
061:
062:                List l = mimePartTree.getLeafsWithContentType(mimePartTree
063:                        .getRootMimeNode(), "text");
064:                if (l.size() > 1) {
065:                    Vector streamList = new Vector();
066:                    Iterator it = l.iterator();
067:                    while (it.hasNext()) {
068:                        MimePart mp = (MimePart) it.next();
069:
070:                        InputStream s = getBodyPartStream(folder, uid, mp);
071:                        streamList.add(s);
072:                    }
073:
074:                    SequenceInputStream stream = new SequenceInputStream(
075:                            streamList.elements());
076:                    return stream;
077:                } else if (l.size() == 1) {
078:                    MimePart mp = (MimePart) l.get(0);
079:                    InputStream s = getBodyPartStream(folder, uid, mp);
080:                    return s;
081:                } else {
082:                    return new ByteArrayInputStream(new byte[0]);
083:
084:                }
085:
086:            }
087:
088:            /**
089:             * Get inputstream of bodypart.
090:             * <p>
091:             * Additionally decode inputstream.
092:             * 
093:             * @param folder
094:             *            selected folder
095:             * @param uid
096:             *            selected message UID
097:             * @param mp
098:             *            selected Mimepart
099:             * @return decoded inputstream
100:             * @throws Exception
101:             */
102:            private static InputStream getBodyPartStream(IMailbox folder,
103:                    Object uid, MimePart mp) throws Exception {
104:                InputStream bodyStream = folder.getMimePartBodyStream(uid, mp
105:                        .getAddress());
106:
107:                int encoding = mp.getHeader().getContentTransferEncoding();
108:
109:                switch (encoding) {
110:                case MimeHeader.QUOTED_PRINTABLE: {
111:                    bodyStream = new QuotedPrintableDecoderInputStream(
112:                            bodyStream);
113:
114:                    break;
115:                }
116:
117:                case MimeHeader.BASE64: {
118:                    bodyStream = new Base64DecoderInputStream(bodyStream);
119:
120:                    break;
121:                }
122:                }
123:
124:                return bodyStream;
125:            }
126:
127:            /**
128:             * Retrieve account this message is associated to.
129:             * 
130:             * @param folder
131:             *            selected folder
132:             * @param uid
133:             *            selected message
134:             * @return account item
135:             * @throws Exception
136:             */
137:            public static AccountItem retrieveAccountItem(IMailbox folder,
138:                    Object uid) throws Exception {
139:                AccountItem item = null;
140:
141:                Object accountUid = folder.getAttribute(uid,
142:                        "columba.accountuid");
143:                if (accountUid != null) {
144:                    // try to get account using the account ID
145:                    item = MailConfig.getInstance().getAccountList().uidGet(
146:                            ((Integer) accountUid).intValue());
147:
148:                }
149:
150:                if (item == null) {
151:                    // try to get the account using the email address
152:                    Header header = folder.getHeaderFields(uid,
153:                            new String[] { "To" });
154:
155:                    item = MailConfig.getInstance().getAccountList()
156:                            .getAccount(header.get("To"));
157:
158:                }
159:
160:                if (item == null) {
161:                    // use default account as fallback
162:
163:                    item = MailConfig.getInstance().getAccountList()
164:                            .getDefaultAccount();
165:                }
166:
167:                return item;
168:            }
169:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.