[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 - Script to forward messages and retain simple formatting

Script to forward messages and retain simple formatting

Scripting questions and ideas

Moderators: Eric, Tomas, robin, Michael

Script to forward messages and retain simple formatting

Postby Pete » Tue Mar 22, 2005 5:56 pm

This script follows from the discussion at:
http://pocosystems.com/forum/viewtopic.php?t=1693

If you read my posts in that topic, you'll discover that this script will not always retain all HTML formatting when forwarding messages. This appears to be a current limitation of PocoMail's composition window and/or HTML-editor component. As far as I know, there is nothing that a script can do to get around the issue.

However, until a new version of PocoMail/Barca is released that allows you to disable the quote character for forwarded messages (but not for replies), then this script allows you to achieve the same functionality while avoiding the need to continually change your quote-character settings in Options.

The basic idea is to add this script to your local Scripts folder then add a toolbar button to call it. Whenever you want to forward a message, you click on this toolbar button instead of using PocoMail's (or Barca's) version of the Forward command.

One thing that you will notice, whether you use this script or if you use PocoMail's Forward command (after disabling the quote character), is that the message will look better after you save it to the Draft mailbox or after you send it than it will while you're looking at it in the Composition Window.

This script should work with both plaintext messages and with styled messages. However, I didn't test it with "Plain & Styled" messages, and it might not work with them.

Code: Select all
{ Script:  Forward Message.poc
{ Author:  PJR
{ Revision History:
{    22 Mar 2005 - Initial version.
{    23 Mar 2005 - Fixed typo (changed < to >) in final StringPos command.
Set $OnErrorMessage ""
AddStrings $OnErrorMessage "Error in " $pocoScriptName
Set $OnErrorGoTo "POCO_ERROR"

{ Only allow script to run in manual mode
If #pocoScriptMode ! 5 Then DONE

{ Don't change the original message
SaveMessageToFile %message "forwardedMessage.tmp"
OpenMessage %newMsg "forwardedMessage.tmp"
DeleteFile "forwardedMessage.tmp"

{ Add "Fwd: " to Subject if necessary
ReadHeader $subject "Subject:" %newMsg
Set $lowercaseSubject $subject
Lowercase $lowercaseSubject
StringPos #index "fw:" $lowercaseSubject
If #index = 1 Then READ_MESSAGE
StringPos #index "fwd:" $lowercaseSubject
If #index = 1 Then READ_MESSAGE
Set $newSubject ""
AddStrings $newSubject "Fwd: " $subject
DeleteHeader "Subject:" %newMsg
AddHeader %newMsg "Subject:" $newSubject

{ Read the message body
:READ_MESSAGE
ReadRawBody $rawBody %newMsg
Set $rawBodyLowercase $rawBody
Lowercase $rawBodyLowercase
StringPos #bodyIndex "<body" $rawBodyLowercase
If #bodyIndex = 0 Then PLAINTEXT
Set $rawBodyTmp $rawBody
ChopString $rawBodyTmp 1 #bodyIndex
StringPos #tmpIndex ">" $rawBodyTmp
AddIntegers #bodyIndex #tmpIndex
AddIntegers #bodyIndex 2
Goto STYLED

{ #########   Plaintext   ######### }
:PLAINTEXT
Set $intro "\n\n\n--- Original Message ---\n"
ReadHeader $tmp "From:" %newMsg
AddStrings $intro "FROM: " $tmp "\n"
ReadHeader $tmp "To:" %newMsg
AddStrings $intro "TO: " $tmp "\n"
ReadHeader $tmp "CC:" %newMsg
If $tmp = "" Then PLAINTEXT_CONTINUE
AddStrings $intro "CC: " $tmp "\n"

:PLAINTEXT_CONTINUE
ReadHeader $tmp "Date:" %newMsg
AddStrings $intro "SENT: " $tmp "\n"
AddStrings $intro "SUBJECT: " $subject "\n\n"

InsertString $rawBody 0 $intro
AssignBody %newMsg $rawBody
Goto EDIT

{ #########   Styled   ######### }
:STYLED
Set $intro "<br><br><br>--- Original Message ---<br>"
ReadHeader $tmp "From:" %newMsg
Call ENCODE_CHARACTERS
AddStrings $intro "<b>From:</b> " $tmp "<br>"
ReadHeader $tmp "To:" %newMsg
Call ENCODE_CHARACTERS
AddStrings $intro "<b>To:</b> " $tmp "<br>"
ReadHeader $tmp "CC:" %newMsg
If $tmp = "" Then STYLED_CONTINUE
Call ENCODE_CHARACTERS
AddStrings $intro "<b>CC:</b> " $tmp "<br>"

:STYLED_CONTINUE
ReadHeader $tmp "Date:" %newMsg
AddStrings $intro "<b>Sent:</b> " $tmp "<br>"
Set $tmp $subject
Call ENCODE_CHARACTERS
AddStrings $intro "<b>Subject:</b> " $tmp "<br><br>"

InsertString $rawBody #bodyIndex $intro
AssignStyledBody %newMsg $rawBody

{ Let the user change the message as desired (or cancel the forwarding)
:EDIT
ClearTo %newMsg
ClearCC %newMsg
ClearBCC %newMsg
EditMessage %newMsg

:DONE
Exit

:POCO_ERROR
Exit

{ The following two routines use the already defined global variables!

:ENCODE_CHARACTERS

{ less-than sign
StringPos #index "<" $tmp
If #index = 0 Then ENCODE_GREATER_THAN_SIGN
ChopString $tmp #index 1
InsertString $tmp #index "&lt;"
Goto ENCODE_CHARACTERS

{ greater-than sign
:ENCODE_GREATER_THAN_SIGN
StringPos #index ">" $tmp
If #index = 0 Then Return
ChopString $tmp #index 1
InsertString $tmp #index "&gt;"
Goto ENCODE_GREATER_THAN_SIGN
Pete
 

Postby Pete » Wed Mar 23, 2005 7:19 am

I just fixed a typo (changed < to >) in the final StringPos command.
Pete
 


Return to PocoScript Help and How-To

Who is online

Users browsing this forum: No registered users and 1 guest

cron