How To: Configure Procmailrc to Reduce Spam

Last Monday in IIIT Linux Users Group (LUG) meeting, I gave a small presentation regarding how to configure .procmailrc to make very effective filters.

Procmail is a mail delivery agent or mail filter which is widely used on Unix systems to process incoming mails. It is automatically invoked by the mail transport agents like Sendmail whenever there is an incoming mail. Procmail has the power to process all the incoming mails based on the recipes provided by the user and deliver them to the provided destination(either a mail folder or email id or something else like a file or stdout and many more).

Procmail by default searches for a configuration file named .procmailrc in user’s home directory. All the recipes, global variables and other things are provided here by the user to let Procmail know what to do.

Here is an example .procmailrc

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# .procmailrc 
 
PATH = $PATH
MAILDIR = $HOME/mail
DEFAULT = $HOME/mbox
SHELL = /bin/bash
 
# Backup for testing mode.
#:0 c # Uncomment for testing mode
#Backup
 
:0: # Spam mails should go to Spam folder
* ^(From|Cc|To).*(hi5.com|auctionit|newegg|voilin|mingle)
Spam
 
:0: # Spam mails should go to Spam folder
* ^Subject:.*(Goonj|Spam|Disarmed|Pictures|Re\. Pictures|Sperm|Penis|Viagra|Filename|voilin)
Spam
 
:0: # Mail from Fedora mailing list should go to Fedora
* ^(From|Cc|To).*(fedora-devel|fedorawiki-noreply|bugzilla)
Fedora
 
:0: # Mail from yum mailing list should go to Yum
* ^(From|Cc|To).*yum-devel*
Yum
 
:0: # Mail from/to lug should go to LUG folder
* ^(From|Cc|To).*lug@students.iiit.ac.in
LUG
 
:0: # Lost found mails should go to LostFound folder
* ^Subject:.*(lost|found)
LostFound
 
:0: # Mail from/to life should go to Life folder
* ^(From|Cc|To).*life@students*
Life
 
:0: # Birc mails should go to BIRC folder
* ^(From|Cc|To).*birc@students*
${HOME}/mbox
 
:0: # Mail from/to course should go to Courses folder
* ^(From|Cc|To).*(ec5303|cs3600|cs3150|cs3350|cs3155|cs4460|cs4110)
{
	:0 c
	! kulbirsaini25@gmail.com
 
	:0:
	Courses
}
 
:0: # Mail from/to clubs should go to Clubs folder
* ^(From|Cc|To).*(agents|campusgreen|campusgreenclub|cybergames|dpscm|guitar|music|nss|photography|quizzers|signet|sigops|videography|movie)
Clubs
 
:0: # Mail from/to clubs should go to Clubs folder
* ^Subject:.*(agents|campusgreen|dance|cybergames|dpscm|guitar|music|nss|photography|quizzers|signet|sigops|videography|movie)
Clubs
 
:0: # House mails should go to House folder
* ^Subject:.*(IBCT|House|Tournament|Champion|championship|Inter\ House|chess|cultural|basket|cricket|foot|ball|Physical|PEC|carrom|dumb|TT|IHFT)
House
 
:0: # Mails from Physical Education Center
* ^(From|Cc|To).*pec@iiit.ac.in
House
 
:0: # Returned mail transcriptions to Bounced folder
* ^Subject:.*(Returned mail: see transcript for details|could not deliver mail|bounced|could not send message for past)
Trash
 
:0: # Mails from TopCoder should go to TopCoder folder
* ^(From|Cc|To).*topcoder*
Trash
 
:0: # Default
* ^(From|Cc|To).*
{
	:0 c
	! kulbirsaini25@gmail.com
 
	:0:
	${HOME}/mbox
}

The top few lines are global variables which you need to declare so that Procmail can detect your default mailbox and mail folders, path etc.

These are configured in accordance with the Students mail server at IIIT-H. These global variable declarations are followed by the recipes which guide Procmail to process the incoming mails.

The usual syntax of a recipe is

1
2
3
:0 [flags] [: [lock-file]]
zero or more conditions
one action line or nested actions

Lets start with the conditions line with second recipe from above image. ‘*’ specifies the start of the action line. This ‘*’ is followed by a regular expression which Procmail egreps in the header by default. ‘^’ in regular expression species the start of the line. Then all the mail which are from/to/cced to mail ids which contain auctionit or newegg or violin . e.g. newegg@newegg.com. The condition can span only one line. You can’t write comment in the action line otherwise Procmail will treat it as a part of regular expression. Anywhere else all the characters that follows a ‘#’ in a line are treated as comments or are ignored by the Procmail while processing mails.

Then comes the action line. There can only be action line per recipe unless and until its not nested. Action line may be just a mail folder name or path (relative or absolute). Spam means that all the mails satisfying the regular expression in condition line will be delivered to the Spam mail folder.

The action lines can be nested as in the last recipe in the above image. Procmail can support any level of nesting but the nesting should be proper.

The action line may also be used to forward mails to some other email id. ‘!’ is used in starting of the line followed by the email id to forward the mail.

Now some tips about the first line in the recipe. ‘:0’ is must. But optional flags may be specified. The second ‘:’ asks Procmail to use a lock-file. The need of lock-file is because if your mail account is being swamped with a lot of mails. The Sendmail invokes one copy of Procmail per incoming mail. In that case if two or more Procmail processes try to write the same mail folder, there will be conflicts. So, using the second ‘:’ protect the same mail folder from being written by the two different Procmail processes.

Procmail processes .procmailrc in top-down fashion and stops whenever it finds a matching regular expression in any of the recipes. But you may make it work further buy using the flag ‘c’ as in last recipe. If flag ‘c’ is specified, it will create a carbon copy and give it to the both recipes.

I think thats enough. If you want to explore Procmail more, read man page ‘procmailrc’ and for example procmailrcs read ‘procmailex’ man page.

You can use my procmailrc if you are interested. Find it here.

 

Bye Bye Windows

A ruff day again … but a day I think I’ll remember for long or may be forever … the day of change … the day you grow up and take decision not to mess up your life anymore …

well, ORB posted some pics of a game here (intranet link) and I just asked about the minimum hardware configuration for running the game. His reply was minimum requirements for u is first start using windows“. well, I use linux most of the times but I have windows xp as well, though sitting idle on my hdd. I didn’t a expect a comment like that.

As I am leaving for home on 10th of this month, I switched to windows. I started writing some data onto DVDs for taking them along with me. While writing the first DVD, it failed at 95%. Suddenly, I got an idea that I would take my hard disk instead of writing the DVDs this time. I’ll buy a SATA to USB converter and transfer the data through USB. So, started collecting the data. While downloading a movie from some ftp, a virus came over and attacked my pc. Strange virus!!! whenever I open any window with title having any of the words task manager, antivirus, virus, norton, symantec, mcaffee etc., it just minimize the window and kill the process immediately. ohh !!! I tried all the ways I know or I could have, but in vain.

So, thought of formatting my windows partition and reinstall the windows. Booted from the xp cd and …. and black screen …. ohh god … i have got this SATA-II hdd. shit!!! Technology is just to fool humans not to help in the real sense. The windows xp doesn’t install on sata hard disks.

To get through, I had two ways … either I go by the long, irritating way of patching the xp iso with sata drivers or format the entire hdd and create one single partition using Partition Magic and then install the xp. Tried patching first … long long process … gave up early … and there is not point in formatting the entire hdd for the crappy os. The best thing is that Fedora 7 is out with a great support for virtualization.

So, I have finally decided to kick windows out of my hdd forever or as long as possible and keep only Fedora. I will really miss AOE but I can’t live with the threats anymore.

I remember a line from one of our English books “Calamity will come and teach them by torture.”. I think this is going to happen to everyone sometime down the line.

So, from now on, I am totally free and secure.

 

How To: Install and Configure NVIDIA Drivers and Beryl

Well, finally I realized the power of my onboard graphics card … too lazy to realize even this (it took me a year to realize this obvious fact). I downloaded the latest nVidia drivers from here and also upgrade to the kernel-2.6.20-1.2944.fc6. You can get it from any site which provides rpms or you can install is using yum. Not to forget I did it on Fedora Core 6 – Zod. So, here goes the exact procedure.

Warning: Take a backup of your /etc/X11/xorg.conf file before experimenting with 3D desktop. It help in case of X server crashes.

1. Download the latest nVidia drivers from here.

2. Upgrade to kernel-2.6.20-1.2944.fc6

(a)Download rpms kernel-2.6.20-1.2944.fc6.i686.rpm and kernel-devel-2.6.20-1.2944.fc6.i686.rpm and install using

[root@zod saini] rpm -ivh kernel* [Enter]

OR
(b)

[root@zod saini] yum install kernel-2.6.20-1.2944.fc6 [Enter]

3. Reboot and switch to the newly installed kernel.

4. Login as root and delete the temp file for xserver

[root@zod saini] rm -f /tmp/.X0.lock [Enter]

5. Install the nVidia drivers

[root@zod saini] bash NVIDIA-Linux-x86-1.0-9755-pkg1.run --kernel-source-path=/usr/src/kernels/2.6.20-1.2944.fc6-i686/ [Enter]

A user interface(I don’t know what to call it, graphical user interface on command line) will appear, answer the basic questions and you are done.

6. run this command

[root@zod saini] nvidia-xconfig [Enter]

7. Open your /etc/X11/xorg.conf file in you favourite(Vim) editor and edit it as follows …

Add these lines to the “screen” section

1
2
Option     "AddARGBGLXVisuals" "True"
Option     "DisableGLXRootClipping" "True"

and Add this line to the “Device Section”

Option         "TripleBuffer" "true"

or you can use my xorg.conf with appropriate modifications.

8. Now install Beryl + emerald or compiz

(a) Get rpms from any site which supplies rpms for packages in fedora and install

[root@zod saini] rpm -ivh beryl-* emerald-* [Enter]

OR

[root@zod saini]  rpm -ivh compiz-* [Enter]

(b) There is always a short cut

[root@zod saini]  yum install beryl* emerald* [Enter]

OR

[root@zod saini]  yum install compiz* [Enter]

9. Now logout and login again and run command beryl-manager or compiz and you are done with installing beryl/compiz with latest nVidia drivers. Enjoy the 3D desktop.

10. If in the above process your X-server crashes, press Ctrl-Alt-F1 and login as root, replace your existing /etc/X11/xorg.conf file with the backup you took in the beginning and do startx.

I installed the above packages on Fedora Core 6, the Hardware is Nvidia Ge Force 6100 onboard.

Here are some screenshot of my 3D Desktop ( They can also be seen here ).

 

QuadKonsole – Programme Better

Well, the era of Quad Core computing is approaching fast. But everybody can’t just enjoy the computing powers of those high end processors due to very high cost and maintenance(power supply and heat) problems. If you are a programmer and and use linux, then you can at least have a Quad Core Konsole. I found a small application here which can change the way you program and can make programming very easy and fast. It has four konsoles tiled in one single window and comes with very easy navigation controls. You may want to give it a try. Below is a screenshot of QuadKonsole.

Quad Core Konsole

Quad Core Konsole

 

Hack: Mange Fluctuating Wireless

I am trying this small script with a so called gui 😉 . This helps managing my wireless in the extreme conditions. Just a shell script. Run the script as root otherwise it’ll not work.

Get the script here or copy the code below.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/bin/bash
#
#	Author - Kulbir Saini, IIIT Hyderabad.
#	Home - http://saini.co.in/
#	KWirelessManger - Just for fun.(It works ... its not just fun).
#
 
#Give the popup life.
POPUP_LIFE="10"
#kdialog --passivepopup "Welcome to 'KWirelessManager'"  ${POPUP_LIFE} &
#Give your device name for proceeding further. It may be one of wlan0, ra0, eth0, ipw2200 etc...
WLAN_DEVICE="wlan0"
#Give your WLAN host to be connected.
WLAN_HOST="IIIT WLAN"
CONNECTED=0
while [[ 1 ]];
do
	iwlist ${WLAN_DEVICE} scanning 2> /dev/null > /tmp/iwlist.aps
	grep -e "Cell" /tmp/iwlist.aps | tr " " "\t" | cut -f15 > /tmp/iwlist.apadd
	ACCESS_POINTS_IN_RANGE=`wc -l /tmp/iwlist.apadd`
	for ACCESS_POINT_ADDRESS in `cat /tmp/iwlist.apadd`
	do
		iwconfig ${WLAN_DEVICE} ap ${ACCESS_POINT_ADDRESS}
		#kdialog --passivepopup "Connceting to Access Point ${ACCESS_POINT_ADDRESS} ..." ${POPUP_LIFE} &
		echo "Connceting to Access Point ${ACCESS_POINT_ADDRESS} ..."
		WLAN_STATUS=`service network restart | tail -1 | grep "FAILED"`
		if [[ ${WLAN_STATUS} == "" ]];
		then
			#kdialog --passivepopup "You are connected to ${WLAN_HOST}." ${POPUP_LIFE} &
			echo "You are connected to ${WLAN_HOST}."
			CONNECTED=1
			break
		else
			#kdialog --passivepopup "Failed to connect to the Access Point ${ACCESS_POINT_ADDRESS} :(" ${POPUP_LIFE} &
			echo "Failed to connect to the Access Point ${ACCESS_POINT_ADDRESS} :("
			CONNECTED=0
		fi
	done
	if [[ ${CONNECTED} == 1 ]];
	then
		sleep 180;
	fi
done

Please suggest any optimization and do tell if u like it.