How To Scan For Viruses in Your Email When Using Apple Mail
Wed 16 September 2009 #code
There’s more than way to go about it, but I prefer using the open source ClamAV and a script that runs to scan each email as it comes in.
- Install ClamAV. I used MacPorts to install it:
sudo port install clamav
- Make sure all the ClamAV binaries are in your PATH. Chances are if you’re using MacPorts, you’ve already taken care of that.
- Configure freshclam and clamd. Since I used MacPorts to install ClamAV, this consisted of…
- rename the example conf files in /opt/local/etc:
mv example-freshclam.conf freshclam.conf;
mv example-clamd.conf clamd.conf
- read the conf files and edit them as appropriate, then add the line
NotifyClamd /opt/local/etc/clamd.conf (substituting the full path to your clamd.conf file) to the end of freshclam.conf so that clamd knows about it when freshclam has updated the virus definitions
- run freshclam to see if it works
- notice that it doesn’t work because it needs permissions to certain
sudo chown -R <clamav user> <directory>…the directory you need to update will be clear based on the error message, the user that freshclam and clamd run under is configured in the conf files. In the MacPorts case its ‘clamav’.
- rinse and repeat until freshclam works
- run clamd to see if it works
- fix its permissions too
- run clamdscan to check that it can scan some files using clamdscan
- Create launchd items for freshclam and clamd. Freshclam should run every 168 hours or so. Clamd should run all the time. I recommend using Lingon to configure your launchd items.
- Reboot. Check to see that clamd is running. Fix it if its not.
- Install Growl.
- Install GrowlNotify. It’s in the Extras folder of the Growl installer.
- Make sure GrowlNotify is in your PATH.
- Install Mpack. With MacPorts its:
sudo port install mpack
- Make sure Mpack is in your PATH.
Setup the antivirus script
- Download the antivirus script I updated (fixed it to work with Snow Leopard, added Growl support, removed Stuffit support). A big thank you to the original authors!
- Move the script to your ~/Library/Scripts directory.
- Edit the script, updating the configuration options at the top of the file.
- Create a local mail folder called ‘Infected’ in Apple Mail.
- Create a rule in Apple Mail that runs the script on all email messages.
- Try emailing yourself a test virus and verify that your antivirus script sends a Growl alert and moves the message to the infected folder.