You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@spamassassin.apache.org by Nick Radov <NR...@axolotl.com> on 2007/01/02 19:35:11 UTC

RelayCountry plugin doesn't add header

I am running SpamAssassin 3.1.7 in serial mode on Windows 2003. I would 
like to use the RelayCountry plugin and have enabled it as described on 
this web page: <http://wiki.apache.org/spamassassin/RelayCountryPlugin>. 
But when I ran a test message through, the X-Relay-Countries header wasn't 
added. Can anyone suggest how to fix this?

The IP::Country::Fast module is installed. And here is a filtered excerpt 
from the SpamAssassin debugging output which seems to show the plugin is 
being loaded correctly. 

[18136] dbg: plugin: loading Mail::SpamAssassin::Plugin::RelayCountry from 
@INC
[18136] dbg: plugin: registered 
Mail::SpamAssassin::Plugin::RelayCountry=HASH(0x29b40b0)
[18136] dbg: plugin: 
Mail::SpamAssassin::Plugin::RelayCountry=HASH(0x29b40b0) implements 
'extract_metadata'
[18136] dbg: plugin: 
Mail::SpamAssassin::Plugin::RelayCountry=HASH(0x29b40b0) implements 
'parsed_metadata'

The particular test message that I used has this Received header.

Received: from 14.9.17.81.nexcom.ru ([81.17.9.14])
          by ax7.axolotl.com (Lotus Domino Release 7.0.2)
          with ESMTP id 2006122820563462-40926 ;
          Thu, 28 Dec 2006 20:56:34 -0800 

I did a manual whois lookup on IP address 81.17.9.14 and it is registered 
to Russia, so I think I should get a "X-Relay-Countries: RU" header. But 
it doesn't work.

Re: RelayCountry plugin doesn't add header

Posted by Alan Munday <sp...@brightheadtechnology.com>.
Nick Radov wrote the following on 02/01/2007 18:35:
> I am running SpamAssassin 3.1.7 in serial mode on Windows 2003. I would 
> like to use the RelayCountry plugin and have enabled it as described on 
> this web page: <http://wiki.apache.org/spamassassin/RelayCountryPlugin>. 
> But when I ran a test message through, the X-Relay-Countries header wasn't 
> added. Can anyone suggest how to fix this?
> 
> The IP::Country::Fast module is installed. And here is a filtered excerpt 
> from the SpamAssassin debugging output which seems to show the plugin is 
> being loaded correctly. 
> 
> [18136] dbg: plugin: loading Mail::SpamAssassin::Plugin::RelayCountry from 
> @INC
> [18136] dbg: plugin: registered 
> Mail::SpamAssassin::Plugin::RelayCountry=HASH(0x29b40b0)
> [18136] dbg: plugin: 
> Mail::SpamAssassin::Plugin::RelayCountry=HASH(0x29b40b0) implements 
> 'extract_metadata'
> [18136] dbg: plugin: 
> Mail::SpamAssassin::Plugin::RelayCountry=HASH(0x29b40b0) implements 
> 'parsed_metadata'
> 
> The particular test message that I used has this Received header.
> 
> Received: from 14.9.17.81.nexcom.ru ([81.17.9.14])
>           by ax7.axolotl.com (Lotus Domino Release 7.0.2)
>           with ESMTP id 2006122820 <http://www.snapanumber.com/>563462-40926 ;
>           Thu, 28 Dec 2006 20:56:34 -0800 
> 
> I did a manual whois lookup on IP address 81.17.9.14 and it is registered 
> to Russia, so I think I should get a "X-Relay-Countries: RU" header. But 
> it doesn't work.


If you just want a header added with the relay countries listed then you'll need to patch SA (3.1x) see the wiki (or review recent threads here).


Otherwise you need to specify in either local.cf or a dedicated conf file those countries you want to see in the headers and with which score.

To test these I wrote a simple script (I'm no programmer) below which writes Relay_Countries.cf which you can put in your spamassassin directory. You can enable/disable each entry by toggling the value of the 1st field and adjust the scores by amending the last field. You can then tweak to just track those countries you are interested in. I did include all the country codes as listed on the ISO site.

Alan




#! /bin/bash

echo start


# shopt -s -o xtrace


OUTPUT_FILE=Relay_Countries.cf
OUTPUT_DIR=.
#OUTPUT_DIR=/etc/mail/spamassassin


#
# Fields:  
#
USE=1		# yes=1, no=0
CODE=2		# Country Code
DESCRIPTION=3	# Description
SCORE=4		# Score

NUM_FIELDS=4

#
# Data:
#
COUNTRY[1]=1~"AD"~"Andorra"~0.001
COUNTRY[2]=1~"AE"~"United Arab Emirates"~0.001
COUNTRY[3]=1~"AF"~"Afghanistan"~0.001
COUNTRY[4]=1~"AG"~"Antigua and Barbuda"~0.001
COUNTRY[5]=1~"AI"~"Anguilla"~0.001
COUNTRY[6]=1~"AL"~"Albania"~0.001
COUNTRY[7]=1~"AM"~"Armenia"~0.001
COUNTRY[8]=1~"AN"~"Netherlands Antilles"~0.001
COUNTRY[9]=1~"AO"~"Angola"~0.001
COUNTRY[10]=1~"AQ"~"Antarctica"~0.001
COUNTRY[11]=1~"AR"~"Argentina"~0.001
COUNTRY[12]=1~"AS"~"American Samoa"~0.001
COUNTRY[13]=1~"AT"~"Austria"~0.001
COUNTRY[14]=1~"AU"~"Australia"~0.001
COUNTRY[15]=1~"AW"~"Aruba"~0.001
COUNTRY[16]=1~"AX"~"Åland Islands"~0.001
COUNTRY[17]=1~"AZ"~"Azerbaijan"~0.001
COUNTRY[18]=1~"BA"~"Bosnia and Herzegovina"~0.001
COUNTRY[19]=1~"BB"~"Barbados"~0.001
COUNTRY[20]=1~"BD"~"Bangladesh"~0.001
COUNTRY[21]=1~"BE"~"Belgium"~0.001
COUNTRY[22]=1~"BF"~"Burkina Faso"~0.001
COUNTRY[23]=1~"BG"~"Bulgaria"~0.001
COUNTRY[24]=1~"BH"~"Bahrain"~0.001
COUNTRY[25]=1~"BI"~"Burundi"~0.001
COUNTRY[26]=1~"BJ"~"Benin"~0.001
COUNTRY[27]=1~"BM"~"Bermuda"~0.001
COUNTRY[28]=1~"BN"~"Brunei Darussalam"~0.001
COUNTRY[29]=1~"BO"~"Bolivia"~0.001
COUNTRY[30]=1~"BR"~"Brazil"~0.001
COUNTRY[31]=1~"BS"~"Bahamas"~0.001
COUNTRY[32]=1~"BT"~"Bhutan"~0.001
COUNTRY[33]=1~"BV"~"Bouvet Island"~0.001
COUNTRY[34]=1~"BW"~"Botswana"~0.001
COUNTRY[35]=1~"BY"~"Belarus"~0.001
COUNTRY[36]=1~"BZ"~"Belize"~0.001
COUNTRY[37]=1~"CA"~"Canada"~0.001
COUNTRY[38]=1~"CC"~"Cocos (Keeling) Islands"~0.001
COUNTRY[39]=1~"CD"~"Congo, the Democratic Republic of the"~0.001
COUNTRY[40]=1~"CF"~"Central African Republic"~0.001
COUNTRY[41]=1~"CG"~"Congo"~0.001
COUNTRY[42]=1~"CH"~"Switzerland"~0.001
COUNTRY[43]=1~"CI"~"Côte d'Ivoire"~0.001
COUNTRY[44]=1~"CK"~"Cook Islands"~0.001
COUNTRY[45]=1~"CL"~"Chile"~0.001
COUNTRY[46]=1~"CM"~"Cameroon"~0.001
COUNTRY[47]=1~"CN"~"China"~0.001
COUNTRY[48]=1~"CO"~"Colombia"~0.001
COUNTRY[49]=1~"CR"~"Costa Rica"~0.001
COUNTRY[50]=1~"CU"~"Cuba"~0.001
COUNTRY[51]=1~"CV"~"Cape Verde"~0.001
COUNTRY[52]=1~"CX"~"Christmas Island"~0.001
COUNTRY[53]=1~"CY"~"Cyprus"~0.001
COUNTRY[54]=1~"CZ"~"Czech Republic"~0.001
COUNTRY[55]=1~"DE"~"Germany"~0.001
COUNTRY[56]=1~"DJ"~"Djibouti"~0.001
COUNTRY[57]=1~"DK"~"Denmark"~0.001
COUNTRY[58]=1~"DM"~"Dominica"~0.001
COUNTRY[59]=1~"DO"~"Dominican Republic"~0.001
COUNTRY[60]=1~"DZ"~"Algeria"~0.001
COUNTRY[61]=1~"EC"~"Ecuador"~0.001
COUNTRY[62]=1~"EE"~"Estonia"~0.001
COUNTRY[63]=1~"EG"~"Egypt"~0.001
COUNTRY[64]=1~"EH"~"Western Sahara"~0.001
COUNTRY[65]=1~"ER"~"Eritrea"~0.001
COUNTRY[66]=1~"ES"~"Spain"~0.001
COUNTRY[67]=1~"ET"~"Ethiopia"~0.001
COUNTRY[68]=1~"FI"~"Finland"~0.001
COUNTRY[69]=1~"FJ"~"Fiji"~0.001
COUNTRY[70]=1~"FK"~"Falkland Islands (Malvinas)"~0.001
COUNTRY[71]=1~"FM"~"Micronesia, Federated States of"~0.001
COUNTRY[72]=1~"FO"~"Faroe Islands"~0.001
COUNTRY[73]=1~"FR"~"France"~0.001
COUNTRY[74]=1~"GA"~"Gabon"~0.001
COUNTRY[75]=1~"GB"~"United Kingdom"~0.001
COUNTRY[76]=1~"GD"~"Grenada"~0.001
COUNTRY[77]=1~"GE"~"Georgia"~0.001
COUNTRY[78]=1~"GF"~"French Guiana"~0.001
COUNTRY[79]=1~"GG"~"Guernsey"~0.001
COUNTRY[80]=1~"GH"~"Ghana"~0.001
COUNTRY[81]=1~"GI"~"Gibraltar"~0.001
COUNTRY[82]=1~"GL"~"Greenland"~0.001
COUNTRY[83]=1~"GM"~"Gambia"~0.001
COUNTRY[84]=1~"GN"~"Guinea"~0.001
COUNTRY[85]=1~"GP"~"Guadeloupe"~0.001
COUNTRY[86]=1~"GQ"~"Equatorial Guinea"~0.001
COUNTRY[87]=1~"GR"~"Greece"~0.001
COUNTRY[88]=1~"GS"~"South Georgia and the South Sandwich Islands"~0.001
COUNTRY[89]=1~"GT"~"Guatemala"~0.001
COUNTRY[90]=1~"GU"~"Guam"~0.001
COUNTRY[91]=1~"GW"~"Guinea-Bissau"~0.001
COUNTRY[92]=1~"GY"~"Guyana"~0.001
COUNTRY[93]=1~"HK"~"Hong Kong"~0.001
COUNTRY[94]=1~"HM"~"Heard Island and McDonald Islands"~0.001
COUNTRY[95]=1~"HN"~"Honduras"~0.001
COUNTRY[96]=1~"HR"~"Croatia"~0.001
COUNTRY[97]=1~"HT"~"Haiti"~0.001
COUNTRY[98]=1~"HU"~"Hungary"~0.001
COUNTRY[99]=1~"ID"~"Indonesia"~0.001
COUNTRY[100]=1~"IE"~"Ireland"~0.001
COUNTRY[101]=1~"IL"~"Israel"~0.001
COUNTRY[102]=1~"IM"~"Isle of Man"~0.001
COUNTRY[103]=1~"IN"~"India"~0.001
COUNTRY[104]=1~"IO"~"British Indian Ocean Territory"~0.001
COUNTRY[105]=1~"IQ"~"Iraq"~0.001
COUNTRY[106]=1~"IR"~"Iran, Islamic Republic of"~0.001
COUNTRY[107]=1~"IS"~"Iceland"~0.001
COUNTRY[108]=1~"IT"~"Italy"~0.001
COUNTRY[109]=1~"JE"~"Jersey"~0.001
COUNTRY[110]=1~"JM"~"Jamaica"~0.001
COUNTRY[111]=1~"JO"~"Jordan"~0.001
COUNTRY[112]=1~"JP"~"Japan"~0.001
COUNTRY[113]=1~"KE"~"Kenya"~0.001
COUNTRY[114]=1~"KG"~"Kyrgyzstan"~0.001
COUNTRY[115]=1~"KH"~"Cambodia"~0.001
COUNTRY[116]=1~"KI"~"Kiribati"~0.001
COUNTRY[117]=1~"KM"~"Comoros"~0.001
COUNTRY[118]=1~"KN"~"Saint Kitts and Nevis"~0.001
COUNTRY[119]=1~"KP"~"Korea, Democratic People's Republic of"~0.001
COUNTRY[120]=1~"KR"~"Korea, Republic of"~0.001
COUNTRY[121]=1~"KW"~"Kuwait"~0.001
COUNTRY[122]=1~"KY"~"Cayman Islands"~0.001
COUNTRY[123]=1~"KZ"~"Kazakhstan"~0.001
COUNTRY[124]=1~"LA"~"Lao People's Democratic Republic"~0.001
COUNTRY[125]=1~"LB"~"Lebanon"~0.001
COUNTRY[126]=1~"LC"~"Saint Lucia"~0.001
COUNTRY[127]=1~"LI"~"Liechtenstein"~0.001
COUNTRY[128]=1~"LK"~"Sri Lanka"~0.001
COUNTRY[129]=1~"LR"~"Liberia"~0.001
COUNTRY[130]=1~"LS"~"Lesotho"~0.001
COUNTRY[131]=1~"LT"~"Lithuania"~0.001
COUNTRY[132]=1~"LU"~"Luxembourg"~0.001
COUNTRY[133]=1~"LV"~"Latvia"~0.001
COUNTRY[134]=1~"LY"~"Libyan Arab Jamahiriya"~0.001
COUNTRY[135]=1~"MA"~"Morocco"~0.001
COUNTRY[136]=1~"MC"~"Monaco"~0.001
COUNTRY[137]=1~"MD"~"Moldova, Republic of"~0.001
COUNTRY[138]=1~"ME"~"Montenegro"~0.001
COUNTRY[139]=1~"MG"~"Madagascar"~0.001
COUNTRY[140]=1~"MH"~"Marshall Islands"~0.001
COUNTRY[141]=1~"MK"~"Macedonia, the former Yugoslav Republic of"~0.001
COUNTRY[142]=1~"ML"~"Mali"~0.001
COUNTRY[143]=1~"MM"~"Myanmar"~0.001
COUNTRY[144]=1~"MN"~"Mongolia"~0.001
COUNTRY[145]=1~"MO"~"Macao"~0.001
COUNTRY[146]=1~"MP"~"Northern Mariana Islands"~0.001
COUNTRY[147]=1~"MQ"~"Martinique"~0.001
COUNTRY[148]=1~"MR"~"Mauritania"~0.001
COUNTRY[149]=1~"MS"~"Montserrat"~0.001
COUNTRY[150]=1~"MT"~"Malta"~0.001
COUNTRY[151]=1~"MU"~"Mauritius"~0.001
COUNTRY[152]=1~"MV"~"Maldives"~0.001
COUNTRY[153]=1~"MW"~"Malawi"~0.001
COUNTRY[154]=1~"MX"~"Mexico"~0.001
COUNTRY[155]=1~"MY"~"Malaysia"~0.001
COUNTRY[156]=1~"MZ"~"Mozambique"~0.001
COUNTRY[157]=1~"NA"~"Namibia"~0.001
COUNTRY[158]=1~"NC"~"New Caledonia"~0.001
COUNTRY[159]=1~"NE"~"Niger"~0.001
COUNTRY[160]=1~"NF"~"Norfolk Island"~0.001
COUNTRY[161]=1~"NG"~"Nigeria"~0.001
COUNTRY[162]=1~"NI"~"Nicaragua"~0.001
COUNTRY[163]=1~"NL"~"Netherlands"~0.001
COUNTRY[164]=1~"NO"~"Norway"~0.001
COUNTRY[165]=1~"NP"~"Nepal"~0.001
COUNTRY[166]=1~"NR"~"Nauru"~0.001
COUNTRY[167]=1~"NU"~"Niue"~0.001
COUNTRY[168]=1~"NZ"~"New Zealand"~0.001
COUNTRY[169]=1~"OM"~"Oman"~0.001
COUNTRY[170]=1~"PA"~"Panama"~0.001
COUNTRY[171]=1~"PE"~"Peru"~0.001
COUNTRY[172]=1~"PF"~"French Polynesia"~0.001
COUNTRY[173]=1~"PG"~"Papua New Guinea"~0.001
COUNTRY[174]=1~"PH"~"Philippines"~0.001
COUNTRY[175]=1~"PK"~"Pakistan"~0.001
COUNTRY[176]=1~"PL"~"Poland"~0.001
COUNTRY[177]=1~"PM"~"Saint Pierre and Miquelon"~0.001
COUNTRY[178]=1~"PN"~"Pitcairn"~0.001
COUNTRY[179]=1~"PR"~"Puerto Rico"~0.001
COUNTRY[180]=1~"PS"~"Palestinian Territory, Occupied"~0.001
COUNTRY[181]=1~"PT"~"Portugal"~0.001
COUNTRY[182]=1~"PW"~"Palau"~0.001
COUNTRY[183]=1~"PY"~"Paraguay"~0.001
COUNTRY[184]=1~"QA"~"Qatar"~0.001
COUNTRY[185]=1~"RE"~"Réunion"~0.001
COUNTRY[186]=1~"RO"~"Romania"~0.001
COUNTRY[187]=1~"RS"~"Serbia"~0.001
COUNTRY[188]=1~"RU"~"Russian Federation"~0.001
COUNTRY[189]=1~"RW"~"Rwanda"~0.001
COUNTRY[190]=1~"SA"~"Saudi Arabia"~0.001
COUNTRY[191]=1~"SB"~"Solomon Islands"~0.001
COUNTRY[192]=1~"SC"~"Seychelles"~0.001
COUNTRY[193]=1~"SD"~"Sudan"~0.001
COUNTRY[194]=1~"SE"~"Sweden"~0.001
COUNTRY[195]=1~"SG"~"Singapore"~0.001
COUNTRY[196]=1~"SH"~"Saint Helena"~0.001
COUNTRY[197]=1~"SI"~"Slovenia"~0.001
COUNTRY[198]=1~"SJ"~"Svalbard and Jan Mayen"~0.001
COUNTRY[199]=1~"SK"~"Slovakia"~0.001
COUNTRY[200]=1~"SL"~"Sierra Leone"~0.001
COUNTRY[201]=1~"SM"~"San Marino"~0.001
COUNTRY[202]=1~"SN"~"Senegal"~0.001
COUNTRY[203]=1~"SO"~"Somalia"~0.001
COUNTRY[204]=1~"SR"~"Suriname"~0.001
COUNTRY[205]=1~"ST"~"Sao Tome and Principe"~0.001
COUNTRY[206]=1~"SV"~"El Salvador"~0.001
COUNTRY[207]=1~"SY"~"Syrian Arab Republic"~0.001
COUNTRY[208]=1~"SZ"~"Swaziland"~0.001
COUNTRY[209]=1~"TC"~"Turks and Caicos Islands"~0.001
COUNTRY[210]=1~"TD"~"Chad"~0.001
COUNTRY[211]=1~"TF"~"French Southern Territories"~0.001
COUNTRY[212]=1~"TG"~"Togo"~0.001
COUNTRY[213]=1~"TH"~"Thailand"~0.001
COUNTRY[214]=1~"TJ"~"Tajikistan"~0.001
COUNTRY[215]=1~"TK"~"Tokelau"~0.001
COUNTRY[216]=1~"TL"~"Timor-Leste"~0.001
COUNTRY[217]=1~"TM"~"Turkmenistan"~0.001
COUNTRY[218]=1~"TN"~"Tunisia"~0.001
COUNTRY[219]=1~"TO"~"Tonga"~0.001
COUNTRY[220]=1~"TR"~"Turkey"~0.001
COUNTRY[221]=1~"TT"~"Trinidad and Tobago"~0.001
COUNTRY[222]=1~"TV"~"Tuvalu"~0.001
COUNTRY[223]=1~"TW"~"Taiwan, Province of China"~0.001
COUNTRY[224]=1~"TZ"~"Tanzania, United Republic of"~0.001
COUNTRY[225]=1~"UA"~"Ukraine"~0.001
COUNTRY[226]=1~"UG"~"Uganda"~0.001
COUNTRY[227]=1~"UM"~"United States Minor Outlying Islands"~0.001
COUNTRY[228]=1~"US"~"United States"~0.001
COUNTRY[229]=1~"UY"~"Uruguay"~0.001
COUNTRY[230]=1~"UZ"~"Uzbekistan"~0.001
COUNTRY[231]=1~"VA"~"Holy See (Vatican City State)"~0.001
COUNTRY[232]=1~"VC"~"Saint Vincent and the Grenadines"~0.001
COUNTRY[233]=1~"VE"~"Venezuela"~0.001
COUNTRY[234]=1~"VG"~"Virgin Islands, British"~0.001
COUNTRY[235]=1~"VI"~"Virgin Islands, U.S."~0.001
COUNTRY[236]=1~"VN"~"Viet Nam"~0.001
COUNTRY[237]=1~"VU"~"Vanuatu"~0.001
COUNTRY[238]=1~"WF"~"Wallis and Futuna"~0.001
COUNTRY[239]=1~"WS"~"Samoa"~0.001
COUNTRY[240]=1~"YE"~"Yemen"~0.001
COUNTRY[241]=1~"YT"~"Mayotte"~0.001
COUNTRY[242]=1~"ZA"~"South Africa"~0.001
COUNTRY[243]=1~"ZM"~"Zambia"~0.001
COUNTRY[244]=1~"ZW"~"Zimbabwe"~0.001

NUM_COUNTRIES=${#COUNTRY[*]}


function Read_Record {
	
	RECORD=${COUNTRY[$COUNT]}
	
	for (( FIELD=1 ; $FIELD<=$NUM_FIELDS ; FIELD++ ))
	do
		DATA[$FIELD]=${RECORD%%~*}
		RECORD="${RECORD#*~}"
	done
}

function Write_Record {

	if [ ${DATA[$USE]} -eq 1 ]
	then
		cat >>$OUTPUT_DIR/$OUTPUT_FILE <<-EOF
		header          RELAY_COUNTRY_${DATA[$CODE]}	X-Relay-Countries =~/\b${DATA[$CODE]}\b/
		describe        RELAY_COUNTRY_${DATA[$CODE]}	Relayed through ${DATA[$DESCRIPTION]}
		score           RELAY_COUNTRY_${DATA[$CODE]}	${DATA[$SCORE]}
	
		EOF
	fi
}


for (( COUNT=1 ; $COUNT<=$NUM_COUNTRIES ; COUNT++ ))
do
	Read_Record 
	Write_Record
done

echo finished

exit 0