[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 - Fix Outgoing HTML.poc

Fix Outgoing HTML.poc

Scripting questions and ideas

Moderators: Eric, Tomas, robin, Michael

Fix Outgoing HTML.poc

Postby Pete » Sat Dec 25, 2004 6:52 am

I introduced this script in the middle of this discussion:
http://pocosystems.com/forum/viewtopic.php?p=7787#7787

I suggest that you read the notes at the beginning of the script if you're going to use it.

Code: Select all
{  Script: Fix Outgoing HTML.poc
{  Author: PJR
{ History: 25 Dec 2004 - Initial release.
{          13 Mar 2005 - As of build 2112, PocoMail uses <div> tags instead of
{                        <p> tags, so changed this script accordingly.
{
{ Notes:
{    * Before you run this script or add an Outgoing filter for it, you need
{      to update the "Setup Script" options at "Tools > Scripts" so that
{      it knows your default font family and size.
{    * This script was designed to be run on Outgoing Styled messages.
{      For testing purposes, you can also run it against new messages that you
{      create and save in the Draft mailbox.
{    * This script probably won't work as desired with messages that are in
{      Plain & Styled format.  At the least, it might discard the Plain part.
{      I don't use this format, so you would have to test it yourself with such
{      messages.
{    * This could be the least efficient PocoScript ever written.  :-)
{      The problem is that it needs to do multiple search-and-replace
{      operations on the HTML and I'm not convinced that there's an
{      efficient way to do this with PocoScript.  Also, attempting to change
{      the script to make it more efficient would probably add
{      significantly to its complexity without making it significantly faster.
{      For the record, it runs fast enough for me.  I rarely write long
{      emails and my computer is fast.  Plus, I'm hoping that the script will
{      become unnecessary as PocoMail matures.
{    * You can change the script to use your own attributes for
{      horizontal-rule tags (<hr>).  Also, during composition of an email,
{      you can align the <hr> that you type in the same way that
{      you align any other text.  The resulting horizontal rule will be
{      aligned accordingly after the script runs.
{    * If you change your default font family and/or size, you might have to
{      change it in all of these places:
{
{         * The settings for this script via the Setup Script tab at
{           "Tools > Scripts"
{
{         * "Tools > Customize > Display Fonts"
{
{         * "Tools > Options > Default Body Format"
{
{         * Any templates that you use.
{
{
{    * If there's a will, there's a way.  :-)

Set $OnErrorMessage ""
AddStrings $OnErrorMessage "Error in " $pocoScriptName
Set $OnErrorGoTo "POCO_ERROR"

If #pocoScriptMode = 2 Then BEGIN
If #pocoScriptMode = 5 Then BEGIN
Goto DONE

:BEGIN
SuggestUsage 2
External $userdata1 "Your Default Font Family:" "Courier New"
External $userdata2 "Your Default Font Size:" "12"
ImportSettings

Set $fontFamily $userdata1
Set $fontFamilyString ""
AddStrings $fontFamilyString "font-family:'" $fontFamily "';"
CharCount #fontFamilyStringSize $fontFamilyString

Set $fontSize $userdata2
Set $fontSizeString ""
AddStrings $fontSizeString "font-size:" $fontSize "pt;"
CharCount #fontSizeStringSize $fontSizeString

ReadRawBody $rawBody %message
IntToChar $shiftedSpace 160
Set $shiftedSpaceReplacement " "
Set $wasChanged "false"
Set $isStyled "false"

{* Change default bottom margin of list elements.
{* Also, determine if message is Styled or Plain
LocateLine #lineNum "LI{display:list-item;margin" $rawBody True
If #lineNum = -1 Then FIX_NBSP_1
Set $wasChanged "true"
Set $isStyled "true"
Set $shiftedSpaceReplacement "&nbsp;"
DeleteLine $rawBody #lineNum 1
InsertLine $rawBody #lineNum "LI{display:list-item;margin-bottom:10px;}"

{* Change all occurrences of 0xA0 to &nbsp; (if Styled message)
{* or to a normal space (if plaintext message).  This second one is to fix a bug
{* (one instance where this happens is with the second space after a period
{* in text quoted from the QuoteBar when using a plaintext message that's
{* in reply to a Styled message (as of <25-Dec-2004>)).
:FIX_NBSP_1
StringPos #index $shiftedSpace $rawBody
If #index = 0 Then BRANCH_ON_MESSAGE_TYPE
Set $wasChanged "true"
ChopString $rawBody #index 1
InsertString $rawBody #index $shiftedSpaceReplacement
Goto FIX_NBSP_1

:BRANCH_ON_MESSAGE_TYPE
If $isStyled = "false" Then UPDATE_MESSAGE

{*** At this point, the message is Styled ***}

{* Remove all occurrences of the default font size
:REMOVE_DEFAULT_FONT_SIZE
StringPos #index $fontSizeString $rawBody
If #index = 0 Then BODY_SECTION
Set $wasChanged "true"
ChopString $rawBody #index #fontSizeStringSize
Goto REMOVE_DEFAULT_FONT_SIZE

{*** Done with entire message, now fix things only in the <body> section ***}

:BODY_SECTION
Set $headSection $rawBody
Set $bodySection $rawBody
StringPos #index "<BODY " $rawBody
ChopString $headSection #index 999999
Dec #index
ChopString $bodySection 1 #index

{* Change all occurrences of   to &nbsp;
:FIX_NBSP_2
StringPos #index " " $bodySection
If #index = 0 Then CARRIAGE_RETURN_AFTER_BODY_TAG
Set $wasChanged "true"
ChopString $bodySection #index 6
InsertString $bodySection #index $shiftedSpaceReplacement
Goto FIX_NBSP_2

{* Add carriage return after BODY tag
:CARRIAGE_RETURN_AFTER_BODY_TAG
StringPos #index ">" $bodySection
Inc #index
Char $ch #index $bodySection
If $ch = "\n" Then REMOVE_DEFAULT_FONT_FAMILY
Set $wasChanged "true"
InsertString $bodySection #index "\n"

{* Remove all occurrences of the default font family
:REMOVE_DEFAULT_FONT_FAMILY
StringPos #index $fontFamilyString $bodySection
If #index = 0 Then REMOVE_EMPTY_SPAN_TAGS
Set $wasChanged "true"
ChopString $bodySection #index #fontFamilyStringSize
Goto REMOVE_DEFAULT_FONT_FAMILY

{* Remove all occurrences of empty <SPAN> tags
:REMOVE_EMPTY_SPAN_TAGS
StringPos #index "<SPAN style=\"\">" $bodySection
If #index = 0 Then CARRIAGE_RETURN_BEFORE_LISTS
Set $wasChanged "true"
ChopString $bodySection #index 15
Set $tmpBodySection $bodySection
ChopString $tmpBodySection 1 #index
StringPos #tmpIndex "</SPAN>" $tmpBodySection
AddIntegers #index #tmpIndex
ChopString $bodySection #index 7
Goto REMOVE_EMPTY_SPAN_TAGS

{* Add carriage-return after <ol...> and <ul...> tags
:CARRIAGE_RETURN_BEFORE_LISTS
StringPos #index "><li" $bodySection
If #index = 0 Then CHANGE_DIV_CLASS_BODY
Set $wasChanged "true"
Inc #index
InsertString $bodySection #index "\n"
Goto CARRIAGE_RETURN_BEFORE_LISTS

{* Change all occurrences of <div class="body"...> to <div...>
:CHANGE_DIV_CLASS_BODY
StringPos #index "<div class=\"body\"" $bodySection
If #index = 0 Then CHANGE_DIV_NBSP_DIV_TO_BR
Set $wasChanged "true"
AddIntegers #index 4
ChopString $bodySection #index 13
Goto CHANGE_DIV_CLASS_BODY

{* Change all occurrences of <div>&nbsp;</div> to <br>
:CHANGE_DIV_NBSP_DIV_TO_BR
StringPos #index "<div>&nbsp;</div>" $bodySection
If #index = 0 Then CHANGE_DIV
Set $wasChanged "true"
ChopString $bodySection #index 17
InsertString $bodySection #index "<br>"
Goto CHANGE_DIV_NBSP_DIV_TO_BR

{* Change all occurrences of <div>...</div> to ...<br>
{* but ignore <div somethingHere>...</div>
:CHANGE_DIV
StringPos #index "<div>" $bodySection
If #index = 0 Then QUOTED_TEXT_IN_ITALICS
Set $wasChanged "true"
ChopString $bodySection #index 5
Set $tmpBodySection $bodySection
Dec #index
ChopString $tmpBodySection 1 #index
StringPos #tmpIndex "</div>" $tmpBodySection
AddIntegers #index #tmpIndex
ChopString $bodySection #index 6
InsertString $bodySection #index "<br>"
Goto CHANGE_DIV

{* Automatically use italics for quoted text
:QUOTED_TEXT_IN_ITALICS
StringPos #index "<SPAN style=\"color:#" $bodySection
If #index = 0 Then FIX_HORIZONTAL_RULES
AddIntegers #index 5
InsertString $bodySection #index " " {add a space so it only finds this tag once}
AddIntegers #index 21
Set $tmpBodySection $bodySection
ChopString $tmpBodySection 1 #index
StringPos #tmpIndex ";\">&gt;&nbsp;" $tmpBodySection
If #tmpIndex ! 1 Then FIX_HORIZONTAL_RULES
Set $wasChanged "true"
AddIntegers #index 8
ChopString $bodySection #index 6
InsertString $bodySection #index " <i>"
AddIntegers #index 3
ChopString $tmpBodySection 1 13
StringPos #tmpIndex "</SPAN>" $tmpBodySection
AddIntegers #index #tmpIndex
InsertString $bodySection #index "</i>"
Goto QUOTED_TEXT_IN_ITALICS

{* Fix Horizontal-Rule tags
:FIX_HORIZONTAL_RULES
StringPos #index "&lt;hr&gt;" $bodySection
If #index = 0 Then UPDATE_MESSAGE
Set $wasChanged "true"
ChopString $bodySection #index 10
Set $tmpBodySection $bodySection
Dec #index
ChopString $tmpBodySection 1 #index
Inc #index
ChopString $tmpBodySection 5 999999
StringPos #tmpIndex "<br>" $tmpBodySection
If #tmpIndex ! 1 Then FIX_HORIZONTAL_RULES_NO_ALIGN
ChopString $bodySection #index 4
InsertString $bodySection #index "<hr align=\"left\" width=\"25%\">"
Goto FIX_HORIZONTAL_RULES

:FIX_HORIZONTAL_RULES_NO_ALIGN
{ the user possibly specified the alignment during composition, so don't change it
InsertString $bodySection #index "<hr width=\"25%\">"
Goto FIX_HORIZONTAL_RULES

{* Update the message
:UPDATE_MESSAGE
If $wasChanged = "false" Then DONE
If $isStyled = "true" Then UPDATE_STYLED
AssignBody %message $rawBody
Goto UPDATE_CONTINUE

:UPDATE_STYLED
Set $rawBody ""
AddStrings $rawBody $headSection $bodySection
AssignStyledBody %message $rawBody

:UPDATE_CONTINUE
If #pocoScriptMode ! 5 Then DONE
SaveMessage %message $currentMailbox
DeleteMessage %message

:DONE
Exit

:POCO_ERROR
Exit
Last edited by Pete on Sun Mar 13, 2005 9:55 am, edited 1 time in total.
Pete
 

Postby J-Mac » Sun Dec 26, 2004 6:55 pm

Pete,

This script is very much appreciated!

Thanks for the work you put into this. I've been playing with some scripts and have not met with a great deal of success.

This is a truly useful script! Thank you again!
J-Mac
J-Mac
Poco Enthusiast
 
Posts: 356
Joined: Wed Jul 28, 2004 9:54 pm
Location: The Great State of Pennsylvania, in the Merry Old Land of Oz!

Postby Pete » Sun Mar 13, 2005 10:05 am

As of beta build 2112, PocoMail began using <div> tags in its styled messages instead of <p> tags. If this change is included in the next official release, then at that time, any people using this script will need to update it on their computer with the new version (that I just posted) after they have installed the new version of PocoMail.

You should not use this version of the script until either the next official release of PocoMail or if you are currently on the beta team and testing build 2112 or higher.

p.s. The script is a little smaller now. :)
Pete
 

Postby Pete » Sun Mar 13, 2005 1:18 pm

Thanks to J-Mac for asking me to clarify this.

If the only reason that you were using this script was to avoid the extra blank lines in outgoing styled messages, then you no longer need to use the script with beta build 2112 or later. That problem is fixed!

I'm going to continue to use this script, however, because it does some other things for me that I like. Please refer to the original discussion for the other things that it does (there's a link to it at the top of this topic).
Pete
 

Postby J-Mac » Sun Mar 13, 2005 5:19 pm

Thanks Pete!
J-Mac
J-Mac
Poco Enthusiast
 
Posts: 356
Joined: Wed Jul 28, 2004 9:54 pm
Location: The Great State of Pennsylvania, in the Merry Old Land of Oz!


Return to PocoScript Help and How-To

Who is online

Users browsing this forum: No registered users and 1 guest

cron