Source Code Cross Referenced for SimpleBlackListManager.java in  » Web-Mail » jsmtpd » org » jsmtpd » plugins » filters » builtin » 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 » Web Mail » jsmtpd » org.jsmtpd.plugins.filters.builtin 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * 
003:         * Jsmtpd, Java SMTP daemon
004:         * Copyright (C) 2005  Jean-Francois POUX, jf.poux@laposte.net
005:         *
006:         * This program is free software; you can redistribute it and/or
007:         * modify it under the terms of the GNU General Public License
008:         * as published by the Free Software Foundation; either version 2
009:         * of the License, or (at your option) any later version.
010:         *
011:         * This program is distributed in the hope that it will be useful,
012:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
013:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
014:         * GNU General Public License for more details.
015:         *
016:         * You should have received a copy of the GNU General Public License
017:         * along with this program; if not, write to the Free Software
018:         * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
019:         *
020:         */
021:        package org.jsmtpd.plugins.filters.builtin;
022:
023:        import java.io.ByteArrayInputStream;
024:        import java.util.LinkedList;
025:
026:        import javax.mail.MessagingException;
027:        import javax.mail.internet.MimeMessage;
028:
029:        import org.apache.commons.logging.Log;
030:        import org.apache.commons.logging.LogFactory;
031:        import org.jsmtpd.config.ModuleNotFoundException;
032:        import org.jsmtpd.core.common.IGenericPlugin;
033:        import org.jsmtpd.core.common.PluginInitException;
034:        import org.jsmtpd.core.common.PluginStore;
035:        import org.jsmtpd.core.common.filter.FilterTreeFailureException;
036:        import org.jsmtpd.core.common.filter.FilterTreeSuccesException;
037:        import org.jsmtpd.core.common.filter.IFilter;
038:        import org.jsmtpd.core.mail.Email;
039:        import org.jsmtpd.core.mail.EmailAddress;
040:        import org.jsmtpd.core.mail.InvalidAddress;
041:        import org.jsmtpd.core.mail.Rcpt;
042:        import org.jsmtpd.core.send.QueueService;
043:        import org.jsmtpd.plugins.inputIPFilters.BlackList;
044:
045:        /**
046:         * @author Jean-Francois POUX
047:         */
048:        public class SimpleBlackListManager implements  IFilter {
049:
050:            String blackListPluginName = "";
051:            BlackList controlled = null;
052:
053:            String allowedSource = "";
054:            String managerMail = "";
055:            EmailAddress manMail = null;
056:            QueueService dsvc;
057:
058:            private Log log = LogFactory.getLog(SimpleBlackListManager.class);
059:
060:            public boolean doFilter(Email input)
061:                    throws FilterTreeFailureException,
062:                    FilterTreeSuccesException {
063:                // if mail is not from relayed domains, return true (continue process)
064:                // if mail is not for jsmtpd-blacklistmanager return true
065:                // If mail is not from admin ip adresses, return true
066:                // else : query the plugin manager for the plugin name
067:                // Then analyse the mail for command an execute it over the ip
068:                // send confirm message
069:                // return false (break of chain, don't deliver the mail)
070:
071:                if (!input.getReceivedFrom().equals(allowedSource))
072:                    return true; // Skip
073:
074:                if (!(input.getRcpt().size() != 1))
075:                    return true; // Skip
076:
077:                Rcpt tmp = (Rcpt) input.getRcpt().get(0);
078:                if (!tmp.getEmailAddress().equals(manMail))
079:                    return true;
080:
081:                try {
082:                    MimeMessage msg = new MimeMessage(null,
083:                            new ByteArrayInputStream(input.getDataAsByte()));
084:                    String command = msg.getSubject();
085:
086:                    if ((command == null) || (command.length() < 7))
087:                        return true;
088:
089:                    if (command.equals("add")) {
090:                        String ip = command.substring(4);
091:                        //controlled.addPermanentBL(ip, new Date(0));
092:                        log.info("IP address " + ip + " added to BlackList");
093:
094:                        LinkedList<String> mesgs = new LinkedList<String>();
095:                        mesgs.add("Sucessfully added IP " + ip
096:                                + " to blacklist manager");
097:                        mesgs.add("");
098:                        mesgs.add("This host can't connect now to Jsmtpd");
099:                        mesgs.add("");
100:
101:                        Email e = Email.createInternalMail(input.getFrom(),
102:                                "BlackList admin - added address", mesgs, null);
103:                        dsvc.queueMail(e);
104:                    }
105:
106:                    if (command.equals("remove")) {
107:                        String ip = command.substring(4);
108:                        //controlled.removePermanentBL(ip);
109:                        log
110:                                .info("IP address " + ip
111:                                        + " removed from BlackList");
112:
113:                    }
114:
115:                    return false; // Break of chain.
116:
117:                } catch (MessagingException e) {
118:                    log.error("Can't parse message " + input.getDiskName()
119:                            + " ", e);
120:                    return false;
121:                }
122:
123:                // transform to MimeMsg
124:                // Parse command
125:                //Create new Email with mmsg
126:                // Apply & confirm
127:
128:            }
129:
130:            public String getPluginName() {
131:                return "Email controlled BlackList manager";
132:            }
133:
134:            public void initPlugin() throws PluginInitException {
135:                PluginStore pluginStore = PluginStore.getInstance();
136:                IGenericPlugin query;
137:                try {
138:                    query = pluginStore
139:                            .getPluginByLogicalName(blackListPluginName);
140:                } catch (ModuleNotFoundException e) {
141:                    throw new PluginInitException(e);
142:                }
143:
144:                if (!(query instanceof  BlackList))
145:                    throw new PluginInitException("The plugin name "
146:                            + blackListPluginName + " is not controlable");
147:
148:                dsvc = QueueService.getInstance();
149:                controlled = (BlackList) query;
150:
151:                try {
152:                    manMail = EmailAddress.parseAddress(managerMail);
153:                } catch (InvalidAddress e1) {
154:                    throw new PluginInitException(e1);
155:                }
156:
157:            }
158:
159:            public void shutdownPlugin() {
160:
161:            }
162:
163:            public String getBlackListPluginName() {
164:                return blackListPluginName;
165:            }
166:
167:            public void setBlackListPluginName(String blackListPluginName) {
168:                this .blackListPluginName = blackListPluginName;
169:            }
170:
171:            public String getAllowedSource() {
172:                return allowedSource;
173:            }
174:
175:            public void setAllowedSource(String allowedSource) {
176:                this .allowedSource = allowedSource;
177:            }
178:
179:            public String getManagerMail() {
180:                return managerMail;
181:            }
182:
183:            public void setManagerMail(String managerMail) {
184:                this.managerMail = managerMail;
185:            }
186:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.