[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 - Newsletter Script

Newsletter Script

Scripting questions and ideas

Moderators: Eric, Tomas, robin, Michael

Newsletter Script

Postby SFCurley » Thu Sep 16, 2004 3:47 pm

I use the following script to have all of my newsletters moved into a specified mailbox. It can be run on all incoming mail, and compares the From field and the Subject field to a file containing a list of match phrases. If the match phrase appears at all in either the Subject field or the From field, the email is moved to the specified mailbox. The benefit of this approach is that if you have many different newsletters as I do, you don't need multiple email filters to move them into the target mailbox -- you just keep the list of key phrases in the input "match" file. I have also created a "Newsletter" button on my toolbar that opens this file for quick and easy access.

Please feel free to provide input and suggestions.

{ This script can be run on incoming or selected messages
{ and will read from a user-specified input "match" file.
{ If any of the lines in the input file are found to be
{ present in either the Subject or From field of the email
{ message, the message will then be moved to a user-specified
{ mailbox. Both the user-specified "match" file name and
{ the mailbox name can be changed in the Script Setup.
{ The match-file must be located in the main Poco
{ applicaiton directory.
{
{ This provides functionality similar to the %file% comparison
{ operation provided by PocoMail, but matches only one way --
{ i.e., the entire match line in the input file must be
{ present in the subject or the from fields for a match to be
{ found.
{
{ I use this script to sort all of my newsletters into a
{ Poco mailbox called "To Read".
{
{ You can have multiple versions of this script, with each
{ one's setup referencing a different match input file and
{ target mailbox. In this case, just copy and rename the
{ script in the Poco Script directory and change the Setup
{ Parameters accordingly for each different match/move.
{ The mailbox specified in the script setup must exist.
{ The input / match file should be saved in the /mail directory.
{
{ Written 08-12-04 by Sean Curley
{

External $userdata1 "Match Text File Name" #file.txt
Set $ifilename $userdata1

External $userdata2 "Mailbox to Move Matches Into" mailbox
Set $mailbox $userdata2

{ Verify that the specified Poco Mailbox exists

Set $mailboxfile $mailpath
AddStrings $mailboxfile $mailbox
AddStrings $mailboxfile ".mbx"
FileExists &mailboxexists $mailboxfile

{ Verify that the specified Match input file exists

Set $mfilename $mailpath
AddStrings $mfilename $ifilename
FileExists &mfileexists $mfilename

{ If either mailbox or file are missing go to error routine

Set &Error1 &mailboxexists
Set &Error2 &mfileexists
Not &Error1
Not &Error2
Or &Error1 &Error2
If &Error1 then FileError

{ Get Subject and From fields; convert to lowercase

ReadHeader $subject "Subject:" %message
Lowercase $subject

ReadHeader $from "From:" %message
Lowercase $from

{ Read input match file, convert to lowercase, trim,
{ and check that not empty

Set $OnErrorGoTo "FileError"
OpenBody $matchfile $mfilename
LowerCase $matchfile
TrimLines $matchfile
LineCount #linecount $matchfile
If #linecount < 1 then FileError

Set #loopcount 1

:FileLoop

Set #linepos #loopcount
SubIntegers #linepos 1

{ Read input line, convert to lowercase

GetLine $currentline #linepos $matchfile
Lowercase $currentline

{ If match found, go to Match move routine

If $currentline ^ $subject then Match
If $currentline ^ $from then Match

If #loopcount = #linecount then End
Inc #loopcount

Goto FileLoop

{ Match routine savies msg to specified mailbox,
{ checks if successful, { and then deletes from
{ initial mailbox

:Match
Set $OnErrorGoTo "MoveFailed"
SaveMessage %message $mailbox
DeleteMessage %message
Goto End

:FileError
MessageBox "Empty or Missing Match File and/or Mailbox"
Goto End

:MoveFailed
MessageBox "Could Not Move Message"

:End

Exit
SFCurley
 

Postby MarkB » Wed Sep 22, 2004 8:52 am

Hi. This can also be accomplished with a filter that searches From (or some other field) for %file%:"newsletters.txt".
MarkB
Poco Enthusiast
 
Posts: 217
Joined: Mon Aug 09, 2004 1:31 am
Location: Canada

Postby SFCurley » Wed Sep 22, 2004 9:17 am

It kind of does the same thing . . .

The problem with the %file% function, which I had been using before this script is that it does PARTIAL matches and it does the comparison both ways, so if I have the word "thing" in my #newsletter file, then when I get a junk email that has just the word "Hi" in the subject lines (as I often do), it would generate a match.

This script, by comparison, does full line matches and only does the comparison one way, so that the word "thing" has to be in either the subject line or the from field.
SFCurley
 

Postby MarkB » Wed Sep 22, 2004 9:35 am

Oh, sorry. That's amazing. My newsletters file contains lines with "free" (freebyte), "the", "new" (Scot's Newsletter), "in" (Windows), etc., and I've never once had a false positive.
MarkB
Poco Enthusiast
 
Posts: 217
Joined: Mon Aug 09, 2004 1:31 am
Location: Canada

Postby SFCurley » Wed Sep 22, 2004 9:52 am

It's because the word -- in the examples you cited -- "free", "in", "the" would have to be stand-alone words in the incoming subject line (if that's the field you're comparing on).

So, if you had the following line in your newsletter file:

"free newsletter" and the subject line on an incoming junk email had "free sex", the no match would be made. BUT if you had an email subject line that had only "free", then that would generate a match.

This wouldn't be a problem if the %file% function only matched one way, specifically, so that an entire line of the newsletter file had to be in, say, the subject field. However, it also matches the other way, too, so that if the whole subject line was ONLY the word "free" and that word appeared anywhere in the newsletter file, bingo! you'd have a match.

For me the most common problem was the word "hi" appearing by itself in a subject line, and those two letter together ("hi") appear in several lines in my newsletter file, albeit, in the middle of other words like "searcHIng", "coacHIng", and "tHIs".
SFCurley
 

Postby MarkB » Thu Sep 23, 2004 12:02 am

Ah. Thank you for your tolerance. That explains why the filter method never gives false positives for me --- because the unwanted search, the search for a complete From address within a line in the file, never succeeds unless the message is a newsletter. For example, the complete address "Lockergnome <list_admin@xxxxxxxxxxx.xxx>" will not be found in a line of the file unless I'm subscribed to Lockergnome.
MarkB
Poco Enthusiast
 
Posts: 217
Joined: Mon Aug 09, 2004 1:31 am
Location: Canada

Postby SFCurley » Thu Sep 23, 2004 1:29 am

No problem . . .glad it was helpful.
SFCurley
 


Return to PocoScript Help and How-To

Who is online

Users browsing this forum: No registered users and 1 guest

cron