[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4688: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3823)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4690: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3823)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4691: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3823)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4692: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3823)
Poco Forums • View topic - Classifications Script

Classifications Script

Scripting questions and ideas

Moderators: Eric, Tomas, robin, Michael

Classifications Script

Postby gavinjb » Thu Apr 20, 2006 8:41 am

This is my first script so any help would be appreciated.

I am trying to create a script which does a simplified version of popfile (I know I can't get the full functionality of popfile currently in Barca).

what I want to do is scan through the messages as they come into my inbox, and if they are in a particular address book or the domain is in a text file then add a extra line to the message header.

I have made a start and this is what I have done so far (After steeling a lot from add_sender_to_address_book. :D )

{ Get address from Reply-To header }
ReadHeader $email "Reply-To" %message

{ If there is no Reply-To header, get address from From header }
if $email = "" then GetFrom

GoTo ProcessAddress

:GetFrom
ReadHeader $email "From" %message

:ProcessAddress
{ need to check each of the filter text files to see if domain is in there }
{ and addressbooks for friends and work}

{ work }
IsAddressPresent &present $email "Work"
if &present then LeaveWork

{ friends }
IsAddressPresent &present $email "Address"
if &present then LeaveFriends


{ none found }
goto Leave

{ maybe possible to put this all into one }
:LeaveWork
AddHeader %message "X-Text-Classification: work"
goto Leave

:LeaveFriends
AddHeader %message "X-Text-Classification: friends"
goto Leave


:Leave
Exit

I have 2 problems though

1. is it possible to combine LeaveWork & LeaveFriedns (and any other categories subs I use) into one.

2. for each category I have a text file which contains a list of domains (a bit like the banned senders file), what I want to do is if address is not in address book read from these files and see if the domain is in them.

so for the work it would first check the work address book, and if not present would then check the work.txt file

Thanks,



Gavin,
gavinjb
Frequent Visitor
 
Posts: 56
Joined: Mon Jan 24, 2005 11:41 pm
Location: Reading, UK

Postby Michael » Thu Apr 20, 2006 6:08 pm

You could use subroutines to help here. For example:

Code: Select all
 { Get address from Reply-To header }
ReadHeader $email "Reply-To" %message

{ If there is no Reply-To header, get address from From header }
if $email = "" then GetFrom

GoTo ProcessAddress

:GetFrom
ReadHeader $email "From" %message

:ProcessAddress
{ need to check each of the filter text files to see if domain is in there }
{ and addressbooks for friends and work}
ExtractEMail $From

Set $Type "Work"
Call CheckClassification
If &Found Then Leave

Set $Type "Friends"
Call CheckClassification

:Leave
Exit

:CheckClassification
Set $AddressBook $Type
If $Type ! "Friends" Then CheckBook
Set $AddressBook "Address"

{  Check address book for presence of address }

IsAddressPresent &present $email $AddressBook
if &present then Classify

{  Check text file for domain }

{  Add code to extract domain here }
{  Probably call as an external subroutine. }
{  Return result in variable $Domain }

Set $File $AppPath {  Not sure if this is the default path
AddStrings $File $Type ".txt"
OpenBody $Domains $File
LowerCase $Domains
LowerCase $Domain
LinePos #ix $Domain $Domains
If #ix > -1 then Classify
Return

:Classify
AddHeader %message "X-Text-Classification:" $Type
Return


Warning: The above is "air-code", I haven't tested it and there may be syntax errors.
Michael
Moderator
 
Posts: 866
Joined: Mon Jul 26, 2004 12:14 pm
Location: Victoria BC, Canada

Postby gavinjb » Sat Apr 22, 2006 3:48 am

Thanks, I still need to do some work to add support for my other classifications, but I now have a good idea what needs to be done.
gavinjb
Frequent Visitor
 
Posts: 56
Joined: Mon Jan 24, 2005 11:41 pm
Location: Reading, UK

Postby gavinjb » Sat Apr 22, 2006 6:36 am

Well I have almost got it working, but have found an issue, I have added an External reference to the top, to hold the location of the domain text files. I have set the default to that of my setup.

Code: Select all
External $userdata1 "Please Enter path of Domain Files:" "C:\Documents and Settings\Gavin\My Documents\EMail\Barca\Scripts\Classify\"


But when I look at the ini file generated it misses the "\" off, and I obviously have issues with this in my scripts. Has anybody else had this issue or even better know how to resolve it. Could I have hit the limit for the length of the variable

Thanks,


Gavin,
gavinjb
Frequent Visitor
 
Posts: 56
Joined: Mon Jan 24, 2005 11:41 pm
Location: Reading, UK

Postby Michael » Sun Apr 23, 2006 3:02 am

The backslash is an escape character, either double them up or use forward slashes.
Michael
Moderator
 
Posts: 866
Joined: Mon Jul 26, 2004 12:14 pm
Location: Victoria BC, Canada

Postby gavinjb » Sun Apr 23, 2006 3:17 am

Thanks,

I Have made some additions to the script to extract the domain, but when I run the script I get an "List Index Out of Bounds (-1)" error on the following code

Code: Select all
Set $Type "work"
Call CheckClassification
If &Found Then Leave


I have tracked it down to the If &Found Then Leave line of code, any ideas.
gavinjb
Frequent Visitor
 
Posts: 56
Joined: Mon Jan 24, 2005 11:41 pm
Location: Reading, UK

Postby Michael » Sun Apr 23, 2006 4:13 am

I think I forgot to set the &Found variable in the example I posted. You will need to initialize it to False at the start of the subroutine and then set it to true if you classify the message. Note: This will mean that a message classified as "Work" will not also be classified as "Friends".
Michael
Moderator
 
Posts: 866
Joined: Mon Jul 26, 2004 12:14 pm
Location: Victoria BC, Canada

Postby gavinjb » Sun Apr 23, 2006 4:37 am

Heres my more or less finished version I hope

Code: Select all
{### classify_email }

{ Script will scan a message and add to message header }
{ X-Text-Classification: {classification Type found }

{Please note this script has only been tested on Barca 2 }

{ Usage: could be used manually or on incoming mail; }
{            when used manually, just select all messages }

External $userdata1 "Please Enter path of Domain Files:" "C:\Documents and Settings\Gavin\My Documents\EMail\Barca\Scripts\Classify\"

{ Get address from Reply-To header }
ReadHeader $email "Reply-To" %message

{ If there is no Reply-To header, get address from From header }
if $email = "" then GetFrom

GoTo ProcessAddress

:GetFrom
ReadHeader $email "From" %message

:ProcessAddress
{ need to check each of the filter text files to see if domain is in there }
{ and addressbooks for friends and work }
ExtractEMail $From

Set $Type "work"
Call CheckClassification
{If &Found Then Leave

Set $Type "friends"
Call CheckClassification
{If &Found Then Leave

Set $Type "accounts"
Call CheckClassification
{If &Found Then Leave

Set $Type "banking"
Call CheckClassification
{If &Found Then Leave

Set $Type "newsletters"
Call CheckClassification
{If &Found Then Leave

Set $Type "orders"
Call CheckClassification
{If &Found Then Leave

Set $Type "photography"
Call CheckClassification
{If &Found Then Leave

{ None found so set to other }
Set $Type "other"
Call Classify

:Leave
Exit

:CheckClassification
Set $AddressBook $Type
If $Type ! "Friends" Then CheckBook
Set $AddressBook "Address"

{  Check address book for presence of address }

IsAddressPresent &present $email $AddressBook
if &present then Classify

{  Check text file for domain }

{  extract domain name }
ReadHeader $domain "From" %message
ExtractEmail $domain

stringpos #a "@" $domain
chopstring $domain 1 #a
{  Probably call as an external subroutine. }
{  Return result in variable $Domain }

Set $File $userdata1
AddStrings $File $Type ".txt"
OpenBody $Domains $File
LowerCase $Domains
LowerCase $Domain
LinePos #ix $Domain $Domains
If #ix > -1 then Classify
Return

:CheckBook
Set $AddressBook $Type
Return

:Classify
AddHeader %message "X-Text-Classification:" $Type
MessageBox "success"
Call Leave


Only problem is that when I test it I get the success messagebox appearing on the screen, but when I look at the full header there is no "X-Text-Classification:", any ideas.

I removed the &Found as all I need to do if ClassClassification finds the domain is add the header and exit

Thanks,
gavinjb
Frequent Visitor
 
Posts: 56
Joined: Mon Jan 24, 2005 11:41 pm
Location: Reading, UK

Postby Michael » Sun Apr 23, 2006 5:09 am

If you are running the script against selected messages rather than incoming then you will have to save the message (and, once you've tested it, delete the prior copy).
Michael
Moderator
 
Posts: 866
Joined: Mon Jul 26, 2004 12:14 pm
Location: Victoria BC, Canada

Postby gavinjb » Sun Apr 23, 2006 7:33 am

Got it working at last, Michael thanks for all your help, I wouldn't have got this to work without all your valuable help :)

If any one is interested in doing anything simular here are all the scripts

Script 1 - Edit any of the required text files
Code: Select all
{### classify_edit }

{ Script will open Domain Text file in Notepad }

{Please note this script has only been tested on Barca 2 }

{ Usage: this Script is only for manual use }

External $userdata1 "Please Enter path of Domain Files:" "C:\Documents and Settings\Gavin\My Documents\EMail\Barca\Scripts\Classify\"
InputBox $userdata2 "Select Bucket to Edit...%var%" "Accounts|Banking|Friends|Newsletters|Orders|Photography|Work"

AddStrings $file1 $userdata1 $userdata2
AddStrings $file2 $file1  ".txt"
Execute $file2


Script 2 - Add Domain to Text File (in the end I decided to select which file for each message selected)

Code: Select all
{### classify_adddomain }

{ Script will add domain from selected email address to textfile }

{Please note this script has only been tested on Barca 2 }

{ Usage: this Script is only for manual use }

External $userdata1 "Please Enter path of Domain Files:" "C:\Documents and Settings\Gavin\My Documents\EMail\Barca\Scripts\Classify\"
InputBox $userdata2 "Select Bucket to Add Domain to...%var%" "Accounts|Banking|Friends|Newsletters|Orders|Photography|Work"

{ get domain name }
ReadHeader $header "From" %message
ExtractEmail $header

stringpos #a "@" $header
chopstring $header 1 #a

AddStrings $file1 $userdata1 $userdata2
AddStrings $file2 $file1  ".txt"
OpenBody $oldmessage $file2
AddStrings $oldmessage $header
SaveBody $oldmessage $file2


Script 3 - process messages and add line to header to allow filters to do what I want with them, you just have to set filters up exactly as you would with pop file

Code: Select all
{### classify_email }

{ Script will scan a message and add to message header }
{ X-Text-Classification: {classification Type found }

{Please note this script has only been tested on Barca 2 }

{ Usage: could be used manually or on incoming mail; }
{            when used manually, just select all messages }

External $userdata1 "Please Enter path of Domain Files:" "C:\Documents and Settings\Gavin\My Documents\EMail\Barca\Scripts\Classify\"

{ Get address from Reply-To header }
ReadHeader $email "Reply-To" %message

{ If there is no Reply-To header, get address from From header }
if $email = "" then GetFrom

GoTo ProcessAddress

:GetFrom
ReadHeader $email "From" %message

:ProcessAddress
{ need to check each of the filter text files to see if domain is in there }
{ and addressbooks for friends and work }
ExtractEMail $From

Set $Type "work"
Call CheckClassification
{If &Found Then Leave

Set $Type "friends"
Call CheckClassification
{If &Found Then Leave

Set $Type "accounts"
Call CheckClassification
{If &Found Then Leave

Set $Type "banking"
Call CheckClassification
{If &Found Then Leave

Set $Type "newsletters"
Call CheckClassification
{If &Found Then Leave

Set $Type "orders"
Call CheckClassification
{If &Found Then Leave

Set $Type "photography"
Call CheckClassification
{If &Found Then Leave

{ None found so set to other }
Set $Type "other"
Call Classify

:Leave
Exit

:CheckClassification
Set $AddressBook $Type
If $Type ! "Friends" Then CheckBook
Set $AddressBook "Address"

{  Check address book for presence of address }

:CheckAddressBook
IsAddressPresent &present $email $AddressBook
if &present then Classify

:CheckDomainFiles
{  Check text file for domain }

{  extract domain name }
ReadHeader $Domain "From" %message
ExtractEmail $Domain

stringpos #a "@" $Domain
chopstring $Domain 1 #a

{  Probably call as an external subroutine. }
{  Return result in variable $Domain }

Set $File $userdata1
AddStrings $File $Type ".txt"
OpenBody $Domains $File
LowerCase $Domains
LowerCase $Domain
LinePos #ix $Domain $Domains

If #ix > -1 then Classify
Return

:CheckBook
Set $AddressBook $Type
Call CheckAddressBook
Return

:Classify
AddHeader %message "X-Text-Classification:" $Type
Call Leave


I can now use barca on any machine, without having to setup popfile, and can also start using the internal junk filters (not that I get much spam :) ....yet!!)

The only thing that would be nice to have on the script, would be the ability to setup in a config file all the Buckets you want and the scripts read this and process of it, but as this does what I want I am not going to even contempt that...well maybe one day if I have lots of time on my hands
gavinjb
Frequent Visitor
 
Posts: 56
Joined: Mon Jan 24, 2005 11:41 pm
Location: Reading, UK


Return to PocoScript Help and How-To

Who is online

Users browsing this forum: No registered users and 3 guests

cron