|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.mailet.GenericMailet org.apache.james.transport.mailets.ClamAVScan
public class ClamAVScan
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:
config.xml
parameters, handling the defaults;<host>
parameter, creating the round-robin IP list;<port>
;<pingIntervalMilli>
milliseconds up to
<maxPings>
times;PING
request;PONG
answer;<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;STREAM
" request;PORT streamPort
" answer obtaining the port number;MimeMessage.writeTo(OutputStream)
)
through the stream connection;OK
" or "... FOUND
" answer from the main connection;org.apache.james.infected
" mail attribute to either
"true
" or "false
";X-MessageIsInfected
" header to either
"true
" or "false
";Some notes regarding clamav.conf:
LocalSocket
must be commented outTCPSocket
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 uncommentedHere 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>
Constructor Summary | |
---|---|
ClamAVScan()
|
Method Summary | |
---|---|
protected void |
checkInitParameters(java.lang.String[] allowedArray)
Checks if there are unallowed init parameters specified in the configuration file against the String[] allowedInitParameters. |
protected java.net.InetAddress[] |
getAddresses()
Getter for property addresses. |
protected java.net.InetAddress |
getAddresses(int index)
Indexed getter for property addresses. |
int |
getAddressesCount()
Getter for property addressesCount. |
protected java.lang.String[] |
getAllowedInitParameters()
Gets the expected init parameters. |
protected java.net.Socket |
getClamdSocket()
Gets a Socket connected to CLAMD. |
java.lang.String |
getHost()
Getter for property host. |
java.lang.String |
getMailetInfo()
Return a string describing this mailet. |
int |
getMaxPings()
Getter for property maxPings. |
protected java.net.InetAddress |
getNextAddress()
Getter for property nextAddress. |
int |
getPingIntervalMilli()
Getter for property pingIntervalMilli. |
int |
getPort()
Getter for property port. |
int |
getStreamBufferSize()
Getter for property streamBufferSize. |
protected int |
getStreamPortFromAnswer(java.lang.String answer)
Parses the answer from a STREAM request and gets the port number. |
void |
init()
Mailet initialization routine. |
protected void |
initDebug()
Initializer for property debug. |
protected void |
initHost()
Initializer for property host. |
protected void |
initMaxPings()
Initializer for property maxPings. |
protected void |
initPingIntervalMilli()
Initializer for property pingIntervalMilli. |
protected void |
initPort()
Initializer for property port. |
protected void |
initStreamBufferSize()
Initializer for property streamBufferSize. |
boolean |
isDebug()
Getter for property debug. |
protected void |
ping()
Tries to "ping" all the CLAMD daemons to check if they are up and accepting requests. |
protected void |
ping(java.net.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. |
protected void |
saveChanges(javax.mail.internet.MimeMessage message)
Saves changes resetting the original message id. |
void |
service(Mail mail)
Scans the mail. |
protected void |
setAddresses(java.net.InetAddress[] addresses)
Setter for property addresses. |
void |
setDebug(boolean debug)
Setter for property debug. |
void |
setHost(java.lang.String host)
Setter for property host. |
void |
setMaxPings(int maxPings)
Setter for property maxPings. |
void |
setPingIntervalMilli(int pingIntervalMilli)
Setter for property pingIntervalMilli. |
void |
setPort(int port)
Setter for property port. |
void |
setStreamBufferSize(int streamBufferSize)
Setter for property streamBufferSize. |
Methods inherited from class org.apache.mailet.GenericMailet |
---|
destroy, getInitParameter, getInitParameter, getInitParameterNames, getMailetConfig, getMailetContext, getMailetName, init, log, log |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public ClamAVScan()
Method Detail |
---|
public java.lang.String getMailetInfo()
getMailetInfo
in interface Mailet
getMailetInfo
in class GenericMailet
protected java.lang.String[] getAllowedInitParameters()
protected void initDebug()
public boolean isDebug()
public void setDebug(boolean debug)
debug
- New value of property debug.protected void initHost() throws java.net.UnknownHostException
java.net.UnknownHostException
- if unable to resolve the host name, or if invalidpublic java.lang.String getHost()
public void setHost(java.lang.String host) throws java.net.UnknownHostException
setAddresses(java.net.InetAddress[])
and resets the nextAddressIndex
variable to 0 for dealing with round-robin.
host
- New value of property host.
java.net.UnknownHostException
- if unable to resolve the host name, or if invalidprotected void initPort()
public int getPort()
public void setPort(int port)
port
- New value of property port.protected void initMaxPings()
public int getMaxPings()
public void setMaxPings(int maxPings)
maxPings
- New value of property maxPings.protected void initPingIntervalMilli()
public int getPingIntervalMilli()
public void setPingIntervalMilli(int pingIntervalMilli)
pingIntervalMilli
- New value of property pingIntervalMilli.protected void initStreamBufferSize()
public int getStreamBufferSize()
public void setStreamBufferSize(int streamBufferSize)
streamBufferSize
- New value of property streamBufferSize.protected java.net.InetAddress getAddresses(int index)
index
- Index of the property.
index
.protected java.net.InetAddress[] getAddresses()
protected void setAddresses(java.net.InetAddress[] addresses)
addresses
- New value of property addresses.protected java.net.InetAddress getNextAddress()
public int getAddressesCount()
protected java.net.Socket getClamdSocket() throws javax.mail.MessagingException
javax.mail.MessagingException
- if no CLAMD in the round-robin address list has accepted the connectionpublic void init() throws javax.mail.MessagingException
init
in class GenericMailet
javax.mail.MessagingException
- if an exception occurs that interrupts the mailet's normal operationpublic void service(Mail mail) throws javax.mail.MessagingException
service
in interface Mailet
service
in class GenericMailet
mail
- the mail to scan
javax.mail.MessagingException
- if a problem arisesprotected final void checkInitParameters(java.lang.String[] allowedArray) throws javax.mail.MessagingException
allowedArray
- array of strings containing the allowed parameter names
javax.mail.MessagingException
- if an unknown parameter name is foundprotected void ping() throws java.lang.Exception
java.lang.Exception
protected void ping(java.net.InetAddress address) throws java.lang.Exception
address
- the address to "ping"
java.lang.Exception
protected final int getStreamPortFromAnswer(java.lang.String answer) throws java.net.ConnectException
answer
- the answer from CLAMD containing the port number
java.net.ConnectException
protected final void saveChanges(javax.mail.internet.MimeMessage message) throws javax.mail.MessagingException
message
- the message to save
javax.mail.MessagingException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |