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


001:        // The contents of this file are subject to the Mozilla Public License Version
002:        // 1.1
003:        //(the "License"); you may not use this file except in compliance with the
004:        //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
005:        //
006:        //Software distributed under the License is distributed on an "AS IS" basis,
007:        //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
008:        //for the specific language governing rights and
009:        //limitations under the License.
010:        //
011:        //The Original Code is "The Columba Project"
012:        //
013:        //The Initial Developers of the Original Code are Frederik Dietz and Timo
014:        // Stich.
015:        //Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
016:        //
017:        //All Rights Reserved.
018:        package org.columba.mail.filter.plugins;
019:
020:        import org.columba.core.filter.AbstractFilter;
021:        import org.columba.core.filter.FilterCriteria;
022:        import org.columba.core.filter.IFilterCriteria;
023:        import org.columba.core.folder.api.IFolder;
024:        import org.columba.mail.filter.MailFilterCriteria;
025:        import org.columba.mail.folder.IMailbox;
026:        import org.columba.ristretto.coder.EncodedWord;
027:        import org.columba.ristretto.message.Header;
028:
029:        /**
030:         * Search for a string in a certain headerfield.
031:         * <p>
032:         * "headerfield" is for example Subject <br>
033:         * "criteria" can be "contains" or "contains not" <br>
034:         * "pattern" specifies the search string <br>
035:         * 
036:         * @author fdietz
037:         */
038:        public class HeaderfieldFilter extends AbstractFilter {
039:
040:            // get headerfield to search in (for example: Subject)
041:            private String headerfield;
042:
043:            // string to search
044:            private String pattern;
045:
046:            private int condition;
047:
048:            /**
049:             * Constructor for HeaderfieldFilter.
050:             * 
051:             * @param filter
052:             */
053:            public HeaderfieldFilter() {
054:                super ();
055:            }
056:
057:            /**
058:             * 
059:             * Check if the requested headerfield contains the search string and return
060:             * true if match was found, otherwise return false
061:             * 
062:             * @see org.columba.core.filter.AbstractFilter#process(org.columba.mail.folder.Folder,
063:             *      java.lang.Object, org.columba.mail.filter.Filter)
064:             */
065:            public boolean process(IFolder folder, Object uid) throws Exception {
066:                // get message header
067:                Header header = ((IMailbox) folder).getHeaderFields(uid,
068:                        new String[] { headerfield });
069:
070:                if (header == null) {
071:                    return false;
072:                }
073:
074:                String headerItem = (String) header.get(headerfield);
075:                // cancel if headerfield doesn't exist
076:                if (headerItem == null)
077:                    return false;
078:
079:                // decode headerfield
080:                headerItem = EncodedWord.decode(headerItem).toString();
081:
082:                // see if theirs a match
083:                boolean result = match(headerItem, condition, pattern);
084:
085:                return result;
086:            }
087:
088:            /**
089:             * 
090:             * check if a match exists in the requested headerfield
091:             * 
092:             * @param headerItem
093:             *            String to specify headerfield (example:Subject)
094:             * @param condition
095:             *            contains, contains not
096:             * @param pattern
097:             *            search string
098:             * 
099:             * @return boolean return true if match was found, otherwise return false
100:             */
101:            protected boolean match(String headerItem, int condition,
102:                    String pattern) {
103:                boolean result = false;
104:
105:                // skip if message doesn't contain the requested headerfield
106:                if (headerItem == null) {
107:                    return false;
108:                }
109:
110:                switch (condition) {
111:                case FilterCriteria.CONTAINS:
112:
113:                    if (headerItem.toLowerCase().indexOf(pattern.toLowerCase()) != -1) {
114:                        result = true;
115:                    }
116:
117:                    break;
118:
119:                case FilterCriteria.CONTAINS_NOT:
120:
121:                    if (headerItem.toLowerCase().indexOf(pattern.toLowerCase()) == -1) {
122:                        result = true;
123:                    }
124:
125:                    break;
126:
127:                case FilterCriteria.IS:
128:
129:                    if (headerItem.equalsIgnoreCase(pattern)) {
130:                        result = true;
131:                    }
132:
133:                    break;
134:
135:                case FilterCriteria.IS_NOT:
136:
137:                    if (!headerItem.equalsIgnoreCase(pattern)) {
138:                        result = true;
139:                    }
140:
141:                    break;
142:
143:                case FilterCriteria.BEGINS_WITH:
144:
145:                    if (headerItem.toLowerCase().startsWith(
146:                            pattern.toLowerCase())) {
147:                        result = true;
148:                    }
149:
150:                    break;
151:
152:                case FilterCriteria.ENDS_WITH:
153:
154:                    if (headerItem.toLowerCase()
155:                            .endsWith(pattern.toLowerCase())) {
156:                        result = true;
157:                    }
158:
159:                    break;
160:                }
161:
162:                return result;
163:            }
164:
165:            /**
166:             * @see org.columba.core.filter.AbstractFilter#setUp(org.columba.mail.filter.FilterCriteria)
167:             */
168:            public void setUp(IFilterCriteria f) {
169:
170:                // get headerfield to search in (for example: Subject)
171:                headerfield = new MailFilterCriteria(f).getHeaderfieldString();
172:
173:                // string to search
174:                pattern = f.getPatternString();
175:
176:                // get condition and convert it to constant as defined in
177:                // FilterCriteria
178:                condition = f.getCriteria();
179:            }
180:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.