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.

 

How To: Configure Wireless with Ralink (rt2500) Level One WNC 0301 in Fedora 7

If you are searching for wireless lan configuration in Fedora Core 6, a detailed description is available here. Though Fedora 7 – Moonshine detect the Ralink rt2500 Level One WNC-0301 wireless lan card, the network doesn’t work properly with default drivers. You may be able to connect sometime, but some other time it may not function properly. Because ralink drivers are not yet stable. See the discussions here. So, here is a step by step complete reference to how to make it work properly.

Step 1: Download the latest CVS release of Ralink rt2500 drivers from here.

Step 2: Unload the kernel module for rt2500 drivers

[root@bordeaux kulbirsaini] rmmod rt2500pci [Enter]

Step 3: Go to the directory /lib/modules/2.6.21-1.3194.fc7/kernel/drivers/net/wireless/mac80211/rt2x00 and take backup of the current rt2500pci driver module.

[root@bordeaux rt2x00] mv rt2500pci.ko back.rt2500pci.ko [Enter]

Step 4: Untar the download driver tar ball and change to the directory ./rt2500-cvs-XXXXXXXXXX/Module/

1
2
[root@bordeaux Module] make [Enter]
[root@bordeaux Module] make install-fedora [Enter]

Step 5: Open /etc/modprobe.conf file and add a line

alias wlan0 rt2500

Save the file and load the rt2500 driver.

[root@bordeaux kulbirsaini] modprobe rt2500 [Enter]

Step 6: Go to the directory /etc/sysconfig/network-scripts/ and create a file named ifcfg-wmaster0. Copy the contents of ifcfg-wlan0 to the ifcfg-wmaster0. If you don’t have ifcfg-wlan0 file, then issue command ‘neat’ as root and add new wireless device with appropriate configurations and ifcfg-wlan0 will be created in the process.

Step 7: Activate the device, what else ???

PS1 : You can refer to my ifcfg-wlan0 and ifcfg-wmaster0 files.

PS2 : You can ask for more details on any issues in the any of the above steps.

 

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 ).

 

How To: Configure Wireless with Ralink (rt2500) Level One WNC-0301 in Fedora Core 6

Well … Yesterday I switched from Fedora Core 4 to Fedora Core 6. The main problem was the wireless lan. As I was using ndiswrapper for wlan in FC4, I tried compiling it for FC6. But FC6 doesn’t have build packages so it didn’t work out. Then I installed the kernel-devel packages from here. Now the build packages were not a problem. I installed ndiswrapper from here. Now while installing ndiswrapper it gave an error that your kernel is using 4k stack, while for windows driver you need to have a kernel with 16k stack. I googled and searched the 16k stack version for my kernel but didnt get one. I used to download 16k stack kernel from here. But 16k stack kernel is not yet out for FC6. So its almost impossible for me to get ndiswrapper to work if I dont want to mess up with the patched and all.

Then I thought of using the native drivers for rt2500 (Level One wnc-0301). I downloaded the drivers from here.
The step by step installation is here ….

Step 0

Install the kernel-devel package from the above specified site.

[root@localhost ~]# rpm -ivh kernel-devel-yourkernel.rpm

Step 1

Untar the drivers.

[root@localhost ~]# tar -xvzf rt2500-1.1.0-b4.tar.gz

Step 2

Change the directory to Module

[root@localhost ~]# cd rt2500-1.1.0-b4/Module/

Step 3

compile the modules

[root@localhost ~]# make

If this gives error like this

1
2
3
4
5
6
7
8
9
make[1]: Entering directory '/usr/src/kernels/2.6.18-1.2798.fc6-xen-i686'
CC [M]  /home2/Softwares/Drivers/rt2500-1.1.0-b4/Module/rtmp_main.o
In file included from /home2/Softwares/Drivers/rt2500-1.1.0-b4/Module/rtmp_main.c:50:
/home2/Softwares/Drivers/rt2500-1.1.0-b4/Module/rt_config.h:58:40: error: linux/config.h: No such file or directory
make[2]: *** [/home2/Softwares/Drivers/rt2500-1.1.0-b4/Module/rtmp_main.o] Error 1
make[1]: *** [_module_/home2/Softwares/Drivers/rt2500-1.1.0-b4/Module] Error 2
make[1]: Leaving directory '/usr/src/kernels/2.6.18-1.2798.fc6-xen-i686'
rt2500.ko failed to build!
make: *** [module] Error 1

Then open the file rt_config.h and comment the line #include<linux/config.h> and again compile by issuing make.
If you get a different error try to debug if you know c-programming a bit.
Step 4. [Do as root]
Install the module

[root@localhost ~]# make install-fedora

Step 5 [Do as root]

Configure the wlan card.

[root@localhost ~]# neat

Now select a new connection and wireless and the the Ralink driver. Thats it. Activate the wlan0.

Hope this help a bit.
More suggestions are welcome.

Edit : If you are looking for wireless configuration in Fedora 7, here is a reference.

 

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.