The script below will ease removal of the IP address of the current false positive message from SpamAddress.txt (or some other file). This script is intended to be run manually, such as from a button, not automatically, at least not without some modification.
The line numbers where the address is found can give some indication of when the most recent and oldest use of this address occurred. this isn't really necessary here, but I wanted to debug the technique for use elsewhere.
- Code: Select all
{ RemoveIPAdrFromFile - Version 1.10
{ Author: Scott Taylor - January 24, 2006
{ Also see scripts DisplayMostRecentIPAddress, MoveIPAddressToStartOfFile
{ and AddIPAdrToFile (formerly AddIPAdrToAdrFile).
{
{ Purpose: Remove all occurrences of the most recent IP address in the current message from the file containing
{ banned IP addresses. Note: This program is not limited to only using this file, but it is the original
{ purpose of this script. This script is intended top be run manually such as from a button.
{
{ Method: The script gets the most recent IP address of the current message, opens the specified file and
{ removes all occurrences of that IP address from the file, overwriting the original file with the remaining text.
{ Get the IP address from the current message
ReadAllHeaders $headers %message { put entire header of current message into variable "$headers"
Set $MostRecentIPAddr "" { clear variable $MostRecentIPAddr
LocateLine #z "Received:" $headers { finds the first occurrence of "Received:" in $headers
If #z < 0 Then NoIPAdr { skip adding new address if not found
GetLine $line #z $headers { put line number in $line
StringPos #z "[" $line { find opening bracket
If #z = 0 Then NoIPAdr { skip adding new address if not found
Dec #z { decrement to leave opening bracket
ChopString $line 1 #z { delete characters before opening bracket
StringPos #z "]" $line { find closing bracket
If #z = 0 Then NoIPAdr { skip adding new address if not found
Inc #z { increment to leave closing bracket
ChopString $line #z 9999 { delete everything after closing bracket
Set $MostRecentIPAddr $line { this is a bit redundant but I like the string name
{ Open the file [with the list of banned IP addresses]
Set $FileName "..\SpamAddress.txt" { use Pocomail main directory
OpenBody $ExistingAdrs $FileName { get existing file contents
{ initialize variables
Set #n 0 { counter to track how mnay times address is found
Set #x 0 { working copy of #n
Set $a "Newest occurrence found at line "
Set $b "Oldest occurrence found at line "
Set $c "Single occurrence found at line "
{ search for the IP address and delete all occurrences from the file
:SearchLoop
LocateLine #z $MostRecentIPAddr $ExistingAdrs { serach for IP address
If #z < 0 Then LoopDone { if not found quit
GetLine $line #z $ExistingAdrs { get line number, put in #z
DeleteLine $ExistingAdrs #z 1 { delete that line
Inc #n { increment counter
Set #x #z { save a copy of the line number
If #n ! 1 Then SearchLoop
AddStrings $a #x { save first occurrence in string $a (newest)
AddStrings $c #x { save first occurrence in string $c (single)
GoTo SearchLoop
:LoopDone
AddIntegers #x #n { add how many lines have been deleted (added v1.10)
Dec #x { do not include the current line (added v1.10)
AddStrings $b #x { save last occurrence in string $b (oldest)
{ Comment out the next line if you want to locate the addresses and not remove them (added v1.10)
SaveBody $ExistingAdrs $FileName { Save remaining text, overwritting the old file.
GoTo finish
:NoIPAdr
Set $msg "Received IP Address of current message not found" { insert error message
MessageBox $msg { display error message
GoTo Exit
:finish
Set $TmpName $Filename { make a working copy of the file name
ChopString $TmpName 1 3 { get rid of the leading "..\" to reduce confusion of message
Set $msg "Found "
AddStrings $msg #n " occurrences of IP address " $MostRecentIPAddr " in file " $TmpName
If #n ! 1 Then NotSingle { see if #n is not equal to 1
InsertLine $msg 99 $c { add single line number to end of message
GoToSkipLine
:NotSingle
If #n < 2 Then SkipLine
InsertLine $msg 99 $a { add newest line number to end of message
InsertLine $msg 99 $b { add oldest line number to end of message
:SkipLine
MessageBox $msg { display informative message
:Exit