[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 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 - Add *****SPAM***** to junk mail

Add *****SPAM***** to junk mail

Scripting questions and ideas

Moderators: Eric, Tomas, robin, Michael

Add *****SPAM***** to junk mail

Postby Hogyt » Sat Aug 28, 2004 7:01 am

Here's a little script that adds/removes some text followed by the spam score to the subject line of email. The screenshot below will explain it better.

Code: Select all
{ Script:  Spam to subject.poc v1.03 by Mat Bowen (Hogyt)
{ Purpose: Adds *****SPAM***** [spam score] [Bayes percentage] to the subject of email moved to the junk mailbox
{          and likewise removes the text when the email is moved out of the junk mailbox
{          Should be set up as an OnAdd event for all mailboxes
{ Updates: http://www.pocosystems.com/forum/viewtopic.php?t=503
{ Changes: v1.00 - Initial release
{          v1.01 - Added Bayes percentage
{                - Made scores optional
{                - Works with junk sub-mailboxes
{          v1.02 - Choose junk mailbox from a drop down list
{          v1.03 - Fixed bug with multiple X-Poco-Scored headers

  Set $OnErrorGoTo generalerror

{ Change the options in "Setup Script"
  External $userdata1 "Text to prefix the subject line of spam with" "*****SPAM*****"
  External $userdata2 "Include the total score (True or False)" True
  External $userdata3 "Include the Bayes percentage (True or False)" True
  External $userdata4 "The mailbox spam is sent to %mailboxes%" "Junk Mail"

  Set $spammessage $userdata1
  Set &includetotalscore $userdata2
  Set &includebayes $userdata3
  Set $junkmailbox $userdata4

  If #PocoScriptMode ! 101 Then wrongmode

{ Read the current subject header
  ReadHeader $subject "Subject:" %message

{ Remove previous subject line
  If $spammessage = "" Then removebrackets
  Set $spammess $spammessage
  AddStrings $spammess " "
  StringPos #pos $spammess $subject
  If #pos ! 1 Then checkmailbox
  SubStrings $subject $spammess

{ Count sets of square brackets to remove
:removebrackets
  Set #brackets 2
  If &includetotalscore Then includetotalscore
  Dec #brackets

:includetotalscore
  If &includebayes Then includebayes
  Dec #brackets

{ Remove sets of square brackets
:includebayes
  If #brackets < 1 Then checkmailbox
  StringPos #pos "[" $subject
  If #pos ! 1 Then checkmailbox
  StringPos #pos "] " $subject
  If #pos = 0 Then checkmailbox
  If #pos > 6 Then checkmailbox
  Inc #pos
  ChopString $subject 1 #pos
  Dec #brackets
  Goto includebayes

{ Check which mailbox we're in
:checkmailbox
  If $CurrentMailbox = $junkmailbox Then injunk
  AddStrings $junkmailbox \\
  StringPos #pos $junkmailbox $CurrentMailbox
  If #pos ! 1 Then replacesubject

{ We're in the Junk mailbox or a sub-mailbox so add text to the subject line
:injunk
  Set $newsubject $spammessage
  If $newsubject = "" Then nosubject
  AddStrings $newsubject " "

:nosubject
  Not &includetotalscore
  If &includetotalscore Then nototalscore

{ Extract score
  ReadHeader $pocoscored "X-Poco-Scored:" %message
  LineCount #lines $pocoscored
  If #lines < 1 Then nototalscore
  Dec #lines
  GetLine $lastpocoscored #lines $pocoscored
  If $lastpocoscored = "" Then nototalscore

{ Drop the + sign by converting string to integer
  Set #score $lastpocoscored
  AddStrings $newsubject "[" #score "] "

:nototalscore
  Not &includebayes
  If &includebayes Then nobayes

{ Extract Bayes score
  ReadHeader $pocobayes "X-Poco-Score-Detail:" %message
  If $pocobayes = "" Then nobayes
  StringPos #pos "P=" $pocobayes
  If #pos = 0 Then nobayes
  AddIntegers #pos 1
  ChopString $pocobayes 1 #pos
  StringPos #pos ";" $pocobayes
  If #pos < 2 Then nobayes
  CharCount #len $pocobayes
  ChopString $pocobayes #pos #len
  AddStrings $newsubject "[" $pocobayes "%] "

{ Add original subject line to the end of the new subject line
:nobayes
  AddStrings $newsubject $subject
  Set $subject $newsubject

:replacesubject
  AddHeader %message "Subject:" $subject
  Exit

{ We're running in the wrong mode
:wrongmode
  Set $message "The script \""
  AddStrings $message $PocoScriptName "\" must be run as an OnAdd event"
  MessageBox $message
  Exit

{ Error handler
:generalerror
  Set $message "An error has occurred in "
  AddStrings $message $PocoScriptName "\n$ErrorResult: " $ErrorResult "\n$ErrorLine: " $ErrorLine
  MessageBox $message
  Exit


Once it is working any email moved (either by hand or automatically) to the Junk Mail folder will appear as follows:
Image
Moving the mail to another folder will automatically tidy up the subject line. The first number in square brackets is the spam score (taken from the X-Poco-Scored header) and the second number is the Bayes percentage (taken from the X-Poco-Score-Detail header).

To set it up:
Create a new script with the code above. Go to Tools->Events and click on Add (for an OnAdd event) then New Event. For the event action select 'Run the following script' and select the above script. Leave 'Run only for specific mailbox' unticked so that it runs on all mailboxes. It should look like this:
Image

You can change the *****SPAM***** text to whatever you like in the "Setup Script" screen:
Image
You can also change whether the spam score and/or Bayes percentage is added to the subject line. Finally you can set the mailbox that receives your junk mail.

C'est tout :-D
Last edited by Hogyt on Thu Oct 14, 2004 12:11 pm, edited 5 times in total.
Mat
Hogyt
Poco Enthusiast
 
Posts: 241
Joined: Thu Jul 29, 2004 11:22 am
Location: England

Postby Eric » Sat Aug 28, 2004 7:17 am

Merci beaucoup, Mat. :wink:
Eric
 

Postby Hogyt » Sat Aug 28, 2004 7:28 am

My pleasure! If my French was better i'd give you a witty reply but alas i can barely remember the day of the week, let alone what i learnt in school over 10 years ago ;-)
Mat
Hogyt
Poco Enthusiast
 
Posts: 241
Joined: Thu Jul 29, 2004 11:22 am
Location: England

Postby tribble » Thu Sep 02, 2004 4:23 am

What happened to the Poco feature that did just that? It does not appear to be in either of the two current betas...
tribble
Poco Enthusiast
 
Posts: 430
Joined: Wed Jul 28, 2004 8:55 am

Postby Eric » Thu Sep 02, 2004 4:51 am

tribble wrote:What happened to the Poco feature that did just that?
:shock: Which feature, never saw it.
BTW Mat, it works like a charm. :D
Eric
 

Postby tribble » Thu Sep 02, 2004 4:54 am

In the previous Pocomail release, it would tag a spam message as spam (in the subject I believe). Since I started using Barca, I had forgotten about it but realzied it is not in the current releases/betas. The basic purpose was to help me identify the source of the routing to the junk folder (Bayes or other script).
tribble
Poco Enthusiast
 
Posts: 430
Joined: Wed Jul 28, 2004 8:55 am

Postby Hogyt » Thu Sep 02, 2004 4:57 am

Thanks Eric :)

I think the script needs to be ammended slightly to work with sub-mailboxes in the Junk mailbox. It may be useful if the subject line also displays the result of the Bayes test, that way we can see which spams Bayes missed at a glance and train it up a bit easier.
Mat
Hogyt
Poco Enthusiast
 
Posts: 241
Joined: Thu Jul 29, 2004 11:22 am
Location: England

Postby tribble » Thu Sep 02, 2004 8:08 am

I just confirmed this. PocoMail version 3.1, build 1880 would tag the subject line as: [Spam] Fill up on gas and pay nothing, [Spam] 5 day free trial, [Spam] We Bring People Together, etc.

PocoMail 3.2 stopped doing this.
tribble
Poco Enthusiast
 
Posts: 430
Joined: Wed Jul 28, 2004 8:55 am

Postby Eric » Thu Sep 02, 2004 8:20 am

tribble wrote:I just confirmed this.
Thanks, tribble, accept my apologies.
I think I've been using Barca too long to see the difference. :lol:
Eric
 

Postby tribble » Thu Sep 02, 2004 8:23 am

Apology? Trust me, it's not required. Have you seen how many mistakes I've made here? :-)
tribble
Poco Enthusiast
 
Posts: 430
Joined: Wed Jul 28, 2004 8:55 am

Postby Hogyt » Wed Sep 08, 2004 7:36 am

Updated to v1.01. This adds the Bayes percentage to the subject line and allows the scores to be optionally included. It also works with Junk Mail sub-mailboxes.
Mat
Hogyt
Poco Enthusiast
 
Posts: 241
Joined: Thu Jul 29, 2004 11:22 am
Location: England

Postby Michael » Thu Sep 09, 2004 4:29 pm

One small suggestion if I may, change the line:
Code: Select all
External $userdata4 "The mailbox spam is sent to (case sensitive)" "Junk Mail"
to
Code: Select all
External $userdata4 "The mailbox spam is sent to (case sensitive)%mailboxes%" "Junk Mail"
.

This will cause the mailboxes to be displayed in a drop down box.
Michael
Moderator
 
Posts: 866
Joined: Mon Jul 26, 2004 12:14 pm
Location: Victoria BC, Canada

Postby Hogyt » Thu Sep 09, 2004 8:17 pm

I've made the change. Thanks Michael!
Mat
Hogyt
Poco Enthusiast
 
Posts: 241
Joined: Thu Jul 29, 2004 11:22 am
Location: England

Postby Hogyt » Thu Oct 14, 2004 12:12 pm

Updated to v1.03. Fixed a harmless error message which was displayed if running incoming filters more than once on certain messages.
Mat
Hogyt
Poco Enthusiast
 
Posts: 241
Joined: Thu Jul 29, 2004 11:22 am
Location: England


Return to PocoScript Help and How-To

Who is online

Users browsing this forum: No registered users and 1 guest

cron