Spam Filtering with Qmail, Procmail, and SpamAssassin in Plesk 9+
A while back, Chris Beach published a hack for spam filtering with Qmail, Procmail, and SpamAssassin in a Plesk installation. Even though Plesk usies SpamAssassin to tag emails as spam, it doesn’t filter spam emails out of the inbox prior to delivery. Chris’ hack used procmail to read the spam level of an email and deliver spam emails to a dedicated Spam folder.
Starting with version 9.0, Plesk switched from using custom, Plesk-only installations of programs like SpamAssassin to using system-wide installations of these programs. As a result of the switch, it’s now easier to upgrade these programs independently of Plesk. Unfortunately, the switch also breaks hacks like the one above.
This hack re-enables spam filtering in Plesk 9+.
.qmail
Each user has a custom .qmail file located in /var/qmail/mailnames/YOURDOMAIN/USER/.qmail. Qmail reads this file each time it processes an email for delivery. Qmail doesn’t do anything useful to the email other than deliver it, so we’ll need to send the email to procmail for processing.
By default, the .qmail file looks like this:
| /usr/bin/deliverquota ./Maildir
This delivers an email to USER’s mailbox while respecting any existing quotas placed on the size of the mailbox.
Change the .qmail file to this:
|preline /usr/bin/procmail -m -o .procmailrc
Qmail now passes the email off to procmail.
.procmailrc
In the same directory, create a .procmailrc file if it does not exist. Put the following code into the .procmailrc file (make sure to replace YOURDOMAIN and USER with the proper values:
DEFAULT=${MAILDIR}/
SPAMDIR=${MAILDIR}/.Spam/
TRASHDIR=${MAILDIR}/.Trash/
# RECIPE 1 — Pipe message to SpamAssassin
# The "f" flag indicates to procmail that this pipe recipe is a "filter" which "delivers" filtered emails to the specified command, here SpamAssassin, and ends prevents further processing of the email by procmail
# The "w" flag indicates to procmail that it should wait for the piped command to return before it further processes the email
# The "-R" flag tells SpamAssassin to provide a spam report for all emails
# Use "-r" instead to generate a report only for spam emails
# SpamAssassin outputs the spam report for the email to stdout, but we can redirect this data to an environmental variable for later use by procmail by prepending the pipe with VARIABLE=
:0 fw
REPORT=| /usr/bin/spamc -R
# RECIPE 2 — Append the spam report to the email
# We use formail to add the spam report as a header to the email message
# We can refer to the variable storing the spam report by using the "$" symbol right before the variable
:0 fw
*
| formail -I "X-Spam-Report: $REPORT"
# RECIPE 3 — Delete Obvious Spam
# Any message with a ridiculously high spam level is simply deleted without wasting the user’s time or space.
# Tweak the number of "\*"’s as needed.
:0 f:
* ^X-Spam-Level: \*\*\*\*\*
/dev/null
# RECIPE 4 — Deliver potential false-positives and other low-rated spam to the Spam folder
:0 f:
* ^X-Spam-Status: Yes.*
${SPAMDIR}
# Everything else goes through!
# This section is actually redundant, since procmail will deliver the email to the user’s inbox once it runs out of recipes to apply.
# You may want to use deliverquota here instead because procmail will not honor any mailbox quotas when it delivers the message.
:0:
*
${DEFAULT}
Tags: plesk, procmail, qmail, spam, spamassassin
Running Skyfire on the iPAQ 211 (or any Windows Mobile 6 PDA)
Skyfire rocks. For those of us running devices pre-6.1, Skyfire is the only option for Silverlight streaming Hulu. Unfortunately, Skyfire doesn’t work in Classic (Pocket PC) versions of Windows Mobile. Even though this flavor of WinMo shares all the functionality of the Professional flavor–absent the Phone and SMS functionality–Skyfire checks for Phone.dll when launched. Skyfire doesn’t actually use Phone.dll beyond this initial check; it’s possible to rename the file once Skyfire has launched. WinMo Classic doesn’t ship with Phone.dll, so Skyfire throws an error and refuses to run.
The solution?
1) Find a copy of Phone.dll using Google. (Hint: check out the xda-developers forum.)
2) Copy Phone.dll to your DEVICE\Windows directory.
3) Run Skyfire.
4) The first time Skyfire runs, you may get an alert dialog from WinMo asking you for permission to run Phone.dll. Click “Yes” so that Skyfire can use Phone.dll.
That’s it! Skyfire no longer throws a hissy fit when launched. A quick visit to Hulu and YouTube will confirm that streaming Flash video works just fine. Silverlight should also work fine: try playing Line Rider Online on your PDA!
Tags: gadget, ipaq, skyfire, void-your-warranty, windows mobile
Setting Up Mono and mod_mono in Plesk 8.6
Mono is the the open-source version of the Microsoft’s .NET runtime. Mono runs on Linux, Unix, BSD, Solaris, and Windows. Mod_mono and XSP are Mono components that bring ASP.NET functionality to non-Microsoft servers. For an example of an ASP.NET page running, in Mono, check out Hello World, 2!
Getting Mono up and running in a Plesk system is suprisingly easy. I use CentOS, which is a Fedora-based system. Consequently, these instructions are geared toward CentOS Plesk systems. However, with the exception of steps 1 and 2, these instructions should work for any Linux-based Plesk system.
0) SSH into your server.
1) Add the Mono repository to your yum repositories.
In CentOS, yum stores a list of its repositories in /etc/yum.repos.d, so adding the Mono repository is as easy as downloading the mono.repo file to this directory.
wget http://ftp.novell.com/pub/mono/download-stable/rhel-4-i386/mono.repo
2) Install Mono, XSP, and mod_mono.
yum install xsp
yum install mod_mono
3) Configure Apache to use mod_mono.
Switch to the httpd customized configuration directory. In most Plesk systems, this should be located at /etc/httpd/conf.d.
vi mod_mono.conf
In vi, or your favorite command line editor, paste the following:
LoadModule mono_module modules/mod_mono.so
AddType application/x-asp-net .aspx
AddType application/x-asp-net .asmx
AddType application/x-asp-net .ashx
AddType application/x-asp-net .asax
AddType application/x-asp-net .ascx
AddType application/x-asp-net .soap
AddType application/x-asp-net .rem
AddType application/x-asp-net .axd
AddType application/x-asp-net .cs
AddType application/x-asp-net .config
AddType application/x-asp-net .Config
AddType application/x-asp-net .dll
DirectoryIndex index.aspx
DirectoryIndex Default.aspx
DirectoryIndex default.aspx
</IfModule>
Save the file.
4) Restart Apache
From your Plesk control panel, go to the Server>Services page. Restart the Web Server (Apache). You can also restart Apache from the command line.
/usr/local/psa/admin/sbin/websrvmng –restart
5) Wait a few minutes.
Plesk doesn’t restart immediatly, despite what the Plesk control panel (or the command prompt) may tell you.
6) Create a test ASP.Net page
<html>
<script language="C#" runat="server">
void Page_Load(object sender, EventArgs e)
{
Response.Write("<br>Hello World! (Response.Write)<br>");
lbHelloWorld.Text = "Hello World! (HTML element changed.)";
}
</script>
<body>
<asp:label id="lbHelloWorld" runat="server" />
</body>
</html>
7) That’s it!
- Some caveats:
- The default configuration for mod_mono uses the Mono binaries compatible with .Net 1.1. These binaries don’t support VB.
- Mod_mono is slow. It does not yet support pre-compiled binaries.
Tags: apache, asp.net, c#, centos, mono, plesk, yum
XNA 2D Camera Tutorial
I’ve just posted a tutorial on creating a 2D camera for XNA. The XNA2dCamera class provides a clean, simple interface to camera functionality in 2-D games. It handles translation, rotation, and scaling/zoom with ease. Most importantly, the class is graphics-engine agnostic, so it can be used for platformer engines, puzzle game engines, and isometric engines.
The full contents of the XNA2dCamera class are on the last page of the tutorial.
Read the XNA 2D Camera tutorial.
Tags: 2d, C#, game programming, graphics, Programming, sample code, tutorial, XNA
Creating a FontCombBox for the ToolStrip in C#
Word’s font selection combobox displays a preview of each font. It’s a great feature which makes it much easier for a user to select a font. Instead of going through each font one-by-one to see what the font looks like, the user can see the results for all installed fonts in one fell swoop.
Accomplishing this feat using C# in .NET 1.0 and 1.1 was no easy feat. The length of many older code samples easily reached into the hundreds of lines. .NET 2.0 introduced new controls and features that made the job much easier.
The C# .NET 2.0 solution only requires one class and less than 40 lines of code. All we need to do is handle several of the events thrown by the ToolStripComboBox’s underlying ComboBox control. My solution extends the ToolStripComboBox, but you can accomplish the same thing without extending the control.
Read the rest of this entry »
Tags: c#, code, custom control, Programming, sample code, tutorial