Java Doc for ClamAVScan.java in  » Net » james-2.3.1 » org » apache » james » transport » mailets » 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 » Net » james 2.3.1 » org.apache.james.transport.mailets 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   org.apache.mailet.GenericMailet
      org.apache.james.transport.mailets.ClamAVScan

ClamAVScan
public class ClamAVScan extends GenericMailet (Code)

Does an antivirus scan check using a ClamAV daemon (CLAMD)

Interacts directly with the daemon using the "stream" method, which should have the lowest possible overhead.

The CLAMD daemon will typically reside on localhost, but could reside on a different host. It may also consist on a set of multiple daemons, each residing on a different server and on different IP number. In such case a DNS host name with multiple IP addresses (round-robin load sharing) is supported by the mailet (but on the same port number).

Handles the following init parameters:

  • <debug>.
  • <host>: the host name of the server where CLAMD runs. It can either be a machine name, such as "java.sun.com", or a textual representation of its IP address. If a literal IP address is supplied, only the validity of the address format is checked. If the machine name resolves to multiple IP addresses, round-robin load sharing will be used. The default is localhost.
  • <port>: the port on which CLAMD listens. The default is 3310.
  • <maxPings>: the maximum number of connection retries during startup. If the value is 0 no startup test will be done. The default is 6.
  • <pingIntervalMilli>: the interval (in milliseconds) between each connection retry during startup. The default is 30000 (30 seconds).
  • <streamBufferSize>: the BufferedOutputStream buffer size to use writing to the stream connection. The default is 8192.

The actions performed are as follows:

  • During initialization:
    1. Gets all config.xml parameters, handling the defaults;
    2. resolves the <host> parameter, creating the round-robin IP list;
    3. connects to CLAMD at the first IP in the round-robin list, on the specified <port>;
    4. if unsuccessful, retries every <pingIntervalMilli> milliseconds up to <maxPings> times;
    5. sends a PING request;
    6. waits for a PONG answer;
    7. repeats steps 3-6 for every other IP resolved.
  • For every mail
    1. connects to CLAMD at the "next" IP in the round-robin list, on the specified <port>, and increments the "next" index; if the connection request is not accepted tries with the next one in the list unless all of them have failed;
    2. sends a "STREAM" request;
    3. parses the "PORT streamPort" answer obtaining the port number;
    4. makes a second connection (the stream connection) to CLAMD at the same host (or IP) on the streamPort just obtained;
    5. sends the mime message to CLAMD (using MimeMessage.writeTo(OutputStream) ) through the stream connection;
    6. closes the stream connection;
    7. gets the "OK" or "... FOUND" answer from the main connection;
    8. closes the main connection;
    9. sets the "org.apache.james.infected" mail attribute to either "true" or "false";
    10. adds the "X-MessageIsInfected" header to either "true" or "false";

Some notes regarding clamav.conf:

  • LocalSocket must be commented out
  • TCPSocket must be set to a port# (typically 3310)
  • StreamMaxLength must be >= the James config.xml parameter <maxmessagesize> in SMTP <handler>
  • MaxThreads should? be >= the James config.xml parameter <threads> in <spoolmanager>
  • ScanMail must be uncommented

Here follows an example of config.xml definitions deploying CLAMD on localhost, and handling the infected messages:


 ...
 <!-- Do an antivirus scan -->
 <mailet match="All" class="ClamAVScan" onMailetException="ignore"/>
 <!-- If infected go to virus processor -->
 <mailet match="HasMailAttributeWithValue=org.apache.james.infected, true" class="ToProcessor">
 <processor> virus </processor>
 </mailet>
 <!-- Check attachment extensions for possible viruses -->
 <mailet match="AttachmentFileNameIs=-d -z *.exe *.com *.bat *.cmd *.pif *.scr *.vbs *.avi *.mp3 *.mpeg *.shs" class="ToProcessor">
 <processor> bad-extensions </processor>
 </mailet>
 ...
 <!-- Messages containing viruses -->
 <processor name="virus">
 <!-- To avoid a loop while bouncing -->
 <mailet match="All" class="SetMailAttribute">
 <org.apache.james.infected>true, bouncing</org.apache.james.infected>
 </mailet>
 <mailet match="SMTPAuthSuccessful" class="Bounce">
 <sender>bounce-admin@xxx.com</sender>
 <inline>heads</inline>
 <attachment>none</attachment>
 <notice> Warning: We were unable to deliver the message below because it was found infected by virus(es). </notice>
 </mailet>
 <!--
 <mailet match="All" class="ToRepository">
 <repositoryPath>file://var/mail/infected/</repositoryPath>
 </mailet>
 -->
 <mailet match="All" class="Null" />
 </processor>
 

version:
   2.2.1
since:
   2.2.1
See Also:    ClamAV Home Page
See Also:    ClamAV For Windows




Method Summary
final protected  voidcheckInitParameters(String[] allowedArray)
     Checks if there are unallowed init parameters specified in the configuration file against the String[] allowedInitParameters.
protected  InetAddressgetAddresses(int index)
     Indexed getter for property addresses.
Parameters:
  index - Index of the property.
protected  InetAddress[]getAddresses()
     Getter for property addresses.
public  intgetAddressesCount()
     Getter for property addressesCount.
protected  String[]getAllowedInitParameters()
     Gets the expected init parameters.
protected  SocketgetClamdSocket()
     Gets a Socket connected to CLAMD.
public  StringgetHost()
     Getter for property host.
public  StringgetMailetInfo()
     Return a string describing this mailet.
public  intgetMaxPings()
     Getter for property maxPings.
protected synchronized  InetAddressgetNextAddress()
     Getter for property nextAddress.
public  intgetPingIntervalMilli()
     Getter for property pingIntervalMilli.
public  intgetPort()
     Getter for property port.
public  intgetStreamBufferSize()
     Getter for property streamBufferSize.
final protected  intgetStreamPortFromAnswer(String answer)
     Parses the answer from a STREAM request and gets the port number.
public  voidinit()
     Mailet initialization routine.
protected  voidinitDebug()
     Initializer for property debug.
protected  voidinitHost()
     Initializer for property host.
protected  voidinitMaxPings()
     Initializer for property maxPings.
protected  voidinitPingIntervalMilli()
     Initializer for property pingIntervalMilli.
protected  voidinitPort()
     Initializer for property port.
protected  voidinitStreamBufferSize()
     Initializer for property streamBufferSize.
public  booleanisDebug()
     Getter for property debug.
protected  voidping()
     Tries to "ping" all the CLAMD daemons to check if they are up and accepting requests.
protected  voidping(InetAddress address)
     Tries (and retries as specified up to 'getMaxPings()') to "ping" the specified CLAMD daemon to check if it is up and accepting requests.
final protected  voidsaveChanges(MimeMessage message)
     Saves changes resetting the original message id.
public  voidservice(Mail mail)
     Scans the mail.
protected  voidsetAddresses(InetAddress[] addresses)
     Setter for property addresses.
public  voidsetDebug(boolean debug)
     Setter for property debug.
public  voidsetHost(String host)
     Setter for property host.
public  voidsetMaxPings(int maxPings)
     Setter for property maxPings.
public  voidsetPingIntervalMilli(int pingIntervalMilli)
     Setter for property pingIntervalMilli.
public  voidsetPort(int port)
     Setter for property port.
public  voidsetStreamBufferSize(int streamBufferSize)
     Setter for property streamBufferSize.



Method Detail
checkInitParameters
final protected void checkInitParameters(String[] allowedArray) throws MessagingException(Code)
Checks if there are unallowed init parameters specified in the configuration file against the String[] allowedInitParameters.
Parameters:
  allowedArray - array of strings containing the allowed parameter names
throws:
  MessagingException - if an unknown parameter name is found



getAddresses
protected InetAddress getAddresses(int index)(Code)
Indexed getter for property addresses.
Parameters:
  index - Index of the property. Value of the property at index.



getAddresses
protected InetAddress[] getAddresses()(Code)
Getter for property addresses. Value of property addresses.



getAddressesCount
public int getAddressesCount()(Code)
Getter for property addressesCount. Value of property addressesCount.



getAllowedInitParameters
protected String[] getAllowedInitParameters()(Code)
Gets the expected init parameters.



getClamdSocket
protected Socket getClamdSocket() throws MessagingException(Code)
Gets a Socket connected to CLAMD. Will loop though the round-robin address list until the first one accepts the connection. a socket connected to CLAMD
throws:
  MessagingException - if no CLAMD in the round-robin address list has accepted the connection



getHost
public String getHost()(Code)
Getter for property host. Value of property host.



getMailetInfo
public String getMailetInfo()(Code)
Return a string describing this mailet. a string describing this mailet



getMaxPings
public int getMaxPings()(Code)
Getter for property maxPings. Value of property maxPings.



getNextAddress
protected synchronized InetAddress getNextAddress()(Code)
Getter for property nextAddress. Gets the address of the next CLAMD server to connect to in this round, using round-robin. Increments the nextAddressIndex for the next round. Value of property address.



getPingIntervalMilli
public int getPingIntervalMilli()(Code)
Getter for property pingIntervalMilli. Value of property pingIntervalMilli.



getPort
public int getPort()(Code)
Getter for property port. Value of property port.



getStreamBufferSize
public int getStreamBufferSize()(Code)
Getter for property streamBufferSize. Value of property streamBufferSize.



getStreamPortFromAnswer
final protected int getStreamPortFromAnswer(String answer) throws ConnectException(Code)
Parses the answer from a STREAM request and gets the port number.
Parameters:
  answer - the answer from CLAMD containing the port number the port number for streaming out the data to scan



init
public void init() throws MessagingException(Code)
Mailet initialization routine.



initDebug
protected void initDebug()(Code)
Initializer for property debug.



initHost
protected void initHost() throws UnknownHostException(Code)
Initializer for property host.
throws:
  UnknownHostException - if unable to resolve the host name, or if invalid



initMaxPings
protected void initMaxPings()(Code)
Initializer for property maxPings.



initPingIntervalMilli
protected void initPingIntervalMilli()(Code)
Initializer for property pingIntervalMilli.



initPort
protected void initPort()(Code)
Initializer for property port.



initStreamBufferSize
protected void initStreamBufferSize()(Code)
Initializer for property streamBufferSize.



isDebug
public boolean isDebug()(Code)
Getter for property debug. Value of property debug.



ping
protected void ping() throws Exception(Code)
Tries to "ping" all the CLAMD daemons to check if they are up and accepting requests.



ping
protected void ping(InetAddress address) throws Exception(Code)
Tries (and retries as specified up to 'getMaxPings()') to "ping" the specified CLAMD daemon to check if it is up and accepting requests.
Parameters:
  address - the address to "ping"



saveChanges
final protected void saveChanges(MimeMessage message) throws MessagingException(Code)
Saves changes resetting the original message id.
Parameters:
  message - the message to save



service
public void service(Mail mail) throws MessagingException(Code)
Scans the mail.
Parameters:
  mail - the mail to scan
throws:
  MessagingException - if a problem arises



setAddresses
protected void setAddresses(InetAddress[] addresses)(Code)
Setter for property addresses.
Parameters:
  addresses - New value of property addresses.



setDebug
public void setDebug(boolean debug)(Code)
Setter for property debug.
Parameters:
  debug - New value of property debug.



setHost
public void setHost(String host) throws UnknownHostException(Code)
Setter for property host. Resolves also the host name into the corresponding IP addresses, issues a ClamAVScan.setAddresses and resets the nextAddressIndex variable to 0 for dealing with round-robin.
Parameters:
  host - New value of property host.
throws:
  UnknownHostException - if unable to resolve the host name, or if invalid



setMaxPings
public void setMaxPings(int maxPings)(Code)
Setter for property maxPings.
Parameters:
  maxPings - New value of property maxPings.



setPingIntervalMilli
public void setPingIntervalMilli(int pingIntervalMilli)(Code)
Setter for property pingIntervalMilli.
Parameters:
  pingIntervalMilli - New value of property pingIntervalMilli.



setPort
public void setPort(int port)(Code)
Setter for property port.
Parameters:
  port - New value of property port.



setStreamBufferSize
public void setStreamBufferSize(int streamBufferSize)(Code)
Setter for property streamBufferSize.
Parameters:
  streamBufferSize - New value of property streamBufferSize.



Methods inherited from org.apache.mailet.GenericMailet
public void destroy()(Code)(Java Doc)
public String getInitParameter(String name)(Code)(Java Doc)
public String getInitParameter(String name, String defValue)(Code)(Java Doc)
public Iterator getInitParameterNames()(Code)(Java Doc)
public MailetConfig getMailetConfig()(Code)(Java Doc)
public MailetContext getMailetContext()(Code)(Java Doc)
public String getMailetInfo()(Code)(Java Doc)
public String getMailetName()(Code)(Java Doc)
public void init(MailetConfig newConfig) throws MessagingException(Code)(Java Doc)
public void init() throws MessagingException(Code)(Java Doc)
public void log(String message)(Code)(Java Doc)
public void log(String message, Throwable t)(Code)(Java Doc)
abstract public void service(Mail mail) throws javax.mail.MessagingException(Code)(Java Doc)

Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.