= and =3D screwing up HTML email

W

Wes Plate

I found two past posts complaining about how Entourage screws up HTML emails...
http://groups.google.com/group/micr...ourage/browse_thread/thread/8bca4cc7372e0811/
http://groups.google.com/group/micr...tourage/browse_thread/thread/d6382aaffe02617/
....This

is a problem for me as well in Entourage 11.2.1, is there any way around it?

I am sending a "complex HTML" message via Entourage, the message having
been constructed via AppleScript.

Is there anything I can do to work around this? Maybe I need to change
the encoding of the message? How?

Thank you


- Wes Plate
 
W

Wes Plate

I guess this is the way it is, huh? Ok, I gave up and I'm attaching
the HTML as a file to a text email.

Thanks.
 
P

Paul Berkowitz

I wrote you about this privately, Wes, in response to a private email (so
far, you have not responded, after some 10 hours or so).

OK, here goes again:

There's nothing at all improper about how Entourage does HTML email in this
context. In fact, it's absolutely according to protocol. It's because you're
parsing the HTML of an email - as apposed to a straight HTML file - that
you're hitting problems.

I'm assuming you are parsing the 'source', not the plain-text 'content', of
an HTML Entourage message, and getting everything between the <HTML> <BODY>
and </BODY> </HTML>.

You will notice that the HTML part has its own charset and encoding in the
source. The charset is usually "ISO-8859-1" (except in rare instances where
it might be utf-8), even where the plain text part's charset is "US-ASCII",
although it might also be "US-ASCII".

But in the HTML part you will always see:

Content-transfer-encoding: quoted-printable

quoted-printable ("QP") is a way of encoding all non-ascii characters as 2
or more ascii characters beginning with "=" as the signal. It's especially
important for Mac email programs (although PCs ought to use it too, if they
care about Mac recipients) since we use different encodings in MacRoman for
non-ASCII (so-called "upper ASCII") characters than they do on PCs. Any
characters with accents, like é, quite a bit of punctuation, and especially
curly quotes ³ ² are not ASCII and are encoded differently on Macs than
PCs. Using QP, these characters will be decoded properly on both Macs and
PCs. QP uses the "=" sign followed by the hexadecimal representation of the
ANSI number (i.e. ISO-8859-1 version, which is the same as the Windows
Latin-1 version except for a couple of characters), NOT the MacRoman number,
of these characters. E.g. "é" is represented by =E9 (hex for 233), ³ is
represented as =B3 (hex for 179), etc. =B6 (hex 182) at the end of the each
of the quoted script lines in your sample must be ANSI for the ¶ character
(does FMP uses this for 'end of a line within a cell' character?), and =A0
(hex 160) for a non-breaking space or tab character at the beginning of
indented script lines.

Even where NO such characters are used, i.e. the encoding is US-ASCII, not
ISO-8859-1, QP still needs to be used for the HTML part of the source.
That's because in HTML you get long (soft-wrapped) lines whereas email is
sent down the wire in short lines of maximum 80 characters, just like
plaintext. In QP, a simple "=" symbol at the end of the short lines is used
to indicate the the next line is a run-on line and when decoded the line-end
will be removed. (To encode a literal "=" character it uses =3D.)

Take a look at the source of your own sent message that you sent me. You'll
see, even in plain text, that because you used non-ASCII characters such as
¶ and whatever those pasted indentations were, the message was encode as
quoted-printable and those same =B6 and =A0 encodings appear.

There are ways to decode that QP-encoded source text. The best way I can
find is using 'TextCommands' that you can get (I think) at macscripter.net /
Scripting Additions, probably at www.osaxen.com . It's not actually a
scripting addition, but an app.

In order to test it. I first had to escape every \ and " backslash with an
exra \ backslash. And it works:


set theText to "\"set orderNum to \\\"\" & LineItems::ORDER_NUMBER &
\"\\\"=B6
set shippingEmail to \\\"\" & LineItems::SHIP_EMAIL & \"\\\"=B6
set ccEmail to \\\"\" & LineItems::c_EmailCC & \"\\\"=B6
set theSubject to \\\"Your order [\\\" & orderNum & \\\"]\\\"=B6
set theSource to \\\"\" & LineItems::g_HTMLemailBody & \"\\\"=B6
tell application \\\"Microsoft Entourage\\\"=B6
=A0 =A0activate=B6
=A0 =A0set htmlOrderMessage to make new outgoing message at outbox folder
with
properties {to recipients:shippingEmail, CC recipients:ccEmail,
subject:theSubject, content:theSource, has html:true}=B6
=A0 =A0send htmlOrderMessage=B6
end tell\""

tell application "TextCommands"
set theText to unpack theText using quoted printable encoding
set theText to convert to unicode theText from "iso-8859-1"
set theText to convert from unicode theText
end tell

--> "set orderNum to \"" & LineItems::ORDER_NUMBER & "\"¶
set shippingEmail to \"" & LineItems::SHIP_EMAIL & "\"¶
set ccEmail to \"" & LineItems::c_EmailCC & "\"¶
set theSubject to \"Your order [\" & orderNum & \"]\"¶
set theSource to \"" & LineItems::g_HTMLemailBody & "\"¶
tell application \"Microsoft Entourage\"¶
   activate¶
   set htmlOrderMessage to make new outgoing message at outbox folder with
properties {to recipients:shippingEmail, CC recipients:ccEmail,
subject:theSubject, content:theSource, has html:true}¶
   send htmlOrderMessage¶
end tell"


---------------------------------------------------

Obviously it's really arduous to do all that literal backslashing. However
you don't need to. If you already have that FMP quoted script as a variable
(e.g. theText) then this should do it:

tell app "FileMaker Pro" to set theText to ....

tell application "TextCommands"
set theText to unpack theText using quoted printable encoding
set theText to convert to unicode theText from "iso-8859-1"
set theText to convert from unicode theText
end tell


or if it's easier just to copy the text to the clipboard, then this works:


tell application "TextCommands"
set theText to (the clipboard)
set theText to unpack theText using quoted printable encoding
set theText to convert to unicode theText from "iso-8859-1"
set theText to convert from unicode theText
end tell



--
Paul Berkowitz
MVP MacOffice
Entourage FAQ Page: <http://www.entourage.mvps.org/faq/index.html>
AppleScripts for Entourage: <http://macscripter.net/scriptbuilders/>

Please "Reply To Newsgroup" to reply to this message. Emails will be
ignored.

PLEASE always state which version of Microsoft Office you are using -
**2004**, X or 2001. It's often impossible to answer your questions
otherwise.
 
Top