[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 - Save a message to disk

Save a message to disk

Scripting questions and ideas

Moderators: Eric, Tomas, robin, Michael

Save a message to disk

Postby peritek » Thu Dec 08, 2005 3:23 pm

I know I can attach a script to a rule based on any field in a message but, I don't understand pocoscript and it's a bit beyond me.

I basically created a rule that searches for a specific string in the subject line and then runs a script but I can't write the script to save my life.

Can anyone help to write a script that saves the message that my rule found to disk? I know that the subject might be the same so the message would have to be saved with the filename being the time and date to be unique.

Kind regards.
peritek
Poco Tourist
 
Posts: 38
Joined: Thu Aug 26, 2004 12:34 am

Postby Michael » Thu Dec 08, 2005 6:46 pm

The following script should do this for you. I have only done rudimentary testing of it. You will need to use the "Setup Script" tab (in the script editor) to set the path and extension to be used.
Code: Select all
External $Path "Path to save file to:" "C:/Temp/"
External $Extension "Extension to use:" "txt"
ReadHeader $Subject "Subject" %Message
GetDate $Today
GetTime $Now
AddStrings $FileName $Subject "-" $Today "-" $Now
Set $BadChars "/:"
:BadCharLoop1
  If $BadChars = "" Then LeaveSlashLoop
  Set $Char $BadChars
  ChopString $Char 2 99
  ChopString $BadChars 1 1
:BadCharLoop2
  StringPos #ix $Char $FileName
  If #ix = 0 Then BadCharLoop1
  Set $Temp $FileName
  ChopString $FileName #ix 999999
  ChopString $Temp 1 #ix
  AddStrings $FileName $Temp
  GoTo BadCharLoop2
:LeaveSlashLoop
AddStrings $Path $FileName "." $Extension
SaveMessageToFile %Message $Path
Michael
Moderator
 
Posts: 866
Joined: Mon Jul 26, 2004 12:14 pm
Location: Victoria BC, Canada

Postby peritek » Thu Dec 08, 2005 8:26 pm

Just tested this and it works great, simplies my life enormously.

Is there any way to save a message without the header part?

I think I'm going to need some serious teaching for this stuff. Not that I get any time working in my current compiler that is:):)
peritek
Poco Tourist
 
Posts: 38
Joined: Thu Aug 26, 2004 12:34 am

Postby Michael » Mon Dec 12, 2005 5:22 pm

You would have to extract the body using the ReadBody command (or ReadRawBody for styled messages if you want to preserve the styling) and then save the body to the file using the "SaveBody" command.

It gets more complicated if you want to save some of the header information such as the subject. Basically then you would have to loop through the headers deciding which ones you want to keep and copy them to the extracted body before saving the message.
Michael
Moderator
 
Posts: 866
Joined: Mon Jul 26, 2004 12:14 pm
Location: Victoria BC, Canada

Postby peritek » Mon Dec 12, 2005 5:42 pm

Michael wrote:You would have to extract the body using the ReadBody command (or ReadRawBody for styled messages if you want to preserve the styling) and then save the body to the file using the "SaveBody" command.

It gets more complicated if you want to save some of the header information such as the subject. Basically then you would have to loop through the headers deciding which ones you want to keep and copy them to the extracted body before saving the message.


I just want to save the body, with no header information in it at all. But I'm sorry to say that I don't follow that script at all, so can't modify it (Looks as if it would take me months and months.....) to learn:):) (assuming that I could)

I can tie my shoelaces at the moment, but that's about it.
peritek
Poco Tourist
 
Posts: 38
Joined: Thu Aug 26, 2004 12:34 am

Postby Michael » Tue Dec 13, 2005 3:27 am

If the message is styled do you want to save the styling codes or just the text of the message (saving only the text will take less space and be more readable if you are viewing the message in notepad, saving styling information will make the message look more like it was when you viewed it with Poco). Discarding styling can also result in text moving around from it's apparent positioni.
Michael
Moderator
 
Posts: 866
Joined: Mon Jul 26, 2004 12:14 pm
Location: Victoria BC, Canada

Just the text

Postby peritek » Tue Dec 13, 2005 11:03 am

Styling isn't important to me. Often, the kind of messages I get just need to be saved cleanly so I can act on them!
peritek
Poco Tourist
 
Posts: 38
Joined: Thu Aug 26, 2004 12:34 am

Postby Michael » Tue Dec 13, 2005 3:41 pm

Try replacing the "SaveMessageToFile %Message $Path" command with:
Code: Select all
ReadBody $Body %Message
SaveBody $Body $Path


Note: This will lose ALL the header information including subject, sender, recipients, date, etc.

PS: I have not tested this change.
Michael
Moderator
 
Posts: 866
Joined: Mon Jul 26, 2004 12:14 pm
Location: Victoria BC, Canada

Absolutely perfect!!

Postby peritek » Tue Dec 13, 2005 7:26 pm

Thank you so much Michael, this will make my next task very easy. If I can ever help you out somehow, think of something!
peritek
Poco Tourist
 
Posts: 38
Joined: Thu Aug 26, 2004 12:34 am

Just thought of a question:):)

Postby peritek » Tue Aug 01, 2006 2:26 am

It's nearly a year later and I just thought of a question.

Is there a way of including the sender's name in the body of the script with a keyword such as SENDER:sender's name

or save the text file to disk with the sender's name as the filename and the time and date of the message embedded in the body with keywords. TIME:02:12
DATE:12/24/2007

Sorry to be a nuisance. Trying to make a little appointment manager in my current compiler. THen I have to train my wife (Daugher and friends as welll I suppose) in the format I need them to post the messages in :D :D :D :D :D
peritek
Poco Tourist
 
Posts: 38
Joined: Thu Aug 26, 2004 12:34 am

Postby Michael » Tue Aug 01, 2006 3:21 pm

The following is untested, please be sure to test it first.

To extract the sender's name and put it into the body of the file use something like:
Code: Select all
ReadHeader $From "From:" %Message
ExtractName $From
Set $FromInfo "From: "
AddStrings $FromInfo $From
Set $Data $FromInfo
ReadBody $Body %Message
AppendBody $FromInfo $Body
SaveBody $Body $Path


Note: This replaces the portion of the script with the ReadBody and SaveBody commands I posted on Dec 13 at 7:41pm.

Extracting the date and time the message was sent into separate fields is considerably more difficult. You need to read the Date header (simple enough) but then you need to parse the information to extract the date and time values. You would start with:
Code: Select all
ReadHeader $SentInfo "Date:" %Message
Then you will need to trim blanks and search for the appropriate delimiters between the portions of the date field. If you want to use the date and time you read the message then it is considerably easier, simply use the GetDate and GetTime commands within PocoScript.
Michael
Moderator
 
Posts: 866
Joined: Mon Jul 26, 2004 12:14 pm
Location: Victoria BC, Canada

Thank you kind sir!

Postby peritek » Tue Aug 01, 2006 3:58 pm

My tiny brain is so full of my current compiler that I don't have the brain cells to follow pocoscript at the moment (Feeeble of me I know).

Thanks for taking the trouble to do this, it is much appreciated.

PeriTek
peritek
Poco Tourist
 
Posts: 38
Joined: Thu Aug 26, 2004 12:34 am

Tested so far..

Postby peritek » Wed Aug 02, 2006 3:32 pm

And seems to be working. Thanks for the great help Michael, it is greatly appreciated.

Now I can concentrate an merging my current 8 projects into one (ooooh, my aching back and eyes).

Yes, I do know what Slaven goes through each day!!!!!
peritek
Poco Tourist
 
Posts: 38
Joined: Thu Aug 26, 2004 12:34 am


Return to PocoScript Help and How-To

Who is online

Users browsing this forum: No registered users and 0 guests

cron