Results 1 to 12 of 12
  1. #1
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Salt Lake City, Utah, USA
    Posts
    9,508
    Thanks
    0
    Thanked 6 Times in 6 Posts

    Re: Remove reply indenting from HTML message (Outlook

    Hello, fellow obsessive-compulsive! I shall use this! <img src=/S/laugh.gif border=0 alt=laugh width=15 height=15>
    -John ... I float in liquid gardens
    UTC -7ąDS

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Remove reply indenting from HTML message (Outl

    Turns out that there is another way in which HTML is indented, if Word is involved as the mail editor: a LEFT-MARGIN property is set in a paragraph or other tag. This updated version addresses those as well. However, if the margin was there for some reason other than indenting a reply, it will be removed anyway, so that could be a problem for some types of stationery or heavily formatted newsletters.
    Code:
    Sub UnBlockQuote()
    ' Remove BLOCKQUOTE tags, which cause annoying indenting, from HTML message
    ' Not fault tolerant, do not run without HTML message open and active
    If MsgBox("Remove the BLOCKQUOTE tags and MARGIN-LEFT settings from this message?", _
            vbQuestion + vbYesNo) = vbNo Then Exit Sub
    Dim msg As MailItem
    Set msg = ActiveInspector.CurrentItem
    ' Remove end tag and then start tag
    msg.HTMLBody = Replace(msg.HTMLBody, "</BLOCKQUOTE>", vbNullString, , , vbTextCompare)
    msg.HTMLBody = WildReplace(msg.HTMLBody, "<BLOCKQUOTE.*>", vbNullString)
    ' Remove MARGIN-LEFT property and then clean up empty style tags, if any
    msg.HTMLBody = WildReplace(msg.HTMLBody, "MARGIN-LEFT: [0-9.]+in", vbNullString)
    msg.HTMLBody = Replace(msg.HTMLBody, " style=""""", vbNullString, , , vbTextCompare)
    Set msg = Nothing
    End Sub
     
    Private Function WildReplace(strExpression As String, strFind As String, _
        strReplace As String, Optional bolReplaceAll As Boolean = True, _
        Optional bolCaseSensitive As Boolean = False) As String
    'reference to Microsoft VBScript Regular Expressions NOT required... uses late binding
    'requires VBScript 5 = IE 5.x
    'perform minimal parameter checking
    If (strExpression = vbNullString) Or (strFind = vbNullString) Then
        WildReplace = strExpression
        Exit Function
    End If
    'Dim objRegExp As RegExp
    Dim objRegExp As Object
    'instantiate RegExp object
    'Set objRegExp = New RegExp
    Set objRegExp = CreateObject("vbscript.regexp")
    objRegExp.IgnoreCase = Not bolCaseSensitive
    objRegExp.Global = bolReplaceAll
    ' Pattern syntax: http://msdn.microsoft.com/library/de...propattern.asp
    objRegExp.Pattern = strFind
    WildReplace = objRegExp.Replace(strExpression, strReplace)
    Set objRegExp = Nothing
    End Function
    This is targeted to countries where margin indents are measured in inches. I'm sure there's a way to internationalize that, but let's see if there's any market demand first. [img]/forums/images/smilies/biggrin.gif[/img]

  3. #3
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Remove reply indenting from HTML message (Outl

    Unless I need HTML, I generally convert my reply or forward to plain text, which effectively removes the stationery. <img src=/S/grin.gif border=0 alt=grin width=15 height=15> To create a macro to remove it, I suspect that you'd have to rip out all the style definitions and background graphics. Could there be anything else? And I suspect you'd need code for both "normal" and Word-generated HTML. It would be interesting to write a macro that runs HTMLBody through HTML Tidy for clean-up. I wonder what would come back? <img src=/S/laugh.gif border=0 alt=laugh width=15 height=15>

  4. #4
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Salt Lake City, Utah, USA
    Posts
    9,508
    Thanks
    0
    Thanked 6 Times in 6 Posts

    Re: Remove reply indenting from HTML message (Outl

    I detest stationery. While you're at it, can you add code to remove stationery? It appears to be recognized as Type 1 Attachment, so I don't know how to distinguish it; perhaps this is it in the HTML script?

    Outlook Editor:
    <BODY id=ridBody background=cid:229542521@15042005-21D4>

    Word Editor:
    <BODY lang=EN-US style="MARGIN-TOP: 18.75pt; MARGIN-LEFT: 18.75pt" vLink=purple link=blue bgColor=white background=cid:image001.gif@01C541D2.2FB759D0>
    -John ... I float in liquid gardens
    UTC -7ąDS

  5. #5
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Salt Lake City, Utah, USA
    Posts
    9,508
    Thanks
    0
    Thanked 6 Times in 6 Posts

    Re: Remove reply indenting from HTML message (Outl

    By Notepad editing saved HTML message files created with the Outlook Editor and with Word, it looks like I need to remove
    " background=cid:"
    and all following junk through to the
    ">"

    I hate to even get messages with stationery. But I don't always change the format when I get HTML, because I get a lot of tables that get their format trashed by conversion to plain text.
    -John ... I float in liquid gardens
    UTC -7ąDS

  6. #6
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Remove reply indenting from HTML message (Outl

    Adding something like this might cleanse the BODY tag back to its essential purity:

    msg.HTMLBody = WildReplace(msg.HTMLBody, "<BODY.*>", "<BODY>")

    Want to test it out while I mosey on over to the Word forum for a while?

  7. #7
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Salt Lake City, Utah, USA
    Posts
    9,508
    Thanks
    0
    Thanked 6 Times in 6 Posts

    Re: Remove reply indenting from HTML message (Outl

    It's working on messages created by the built-in Outlook editor, but not on those created by Word. <img src=/S/scratch.gif border=0 alt=scratch width=25 height=29>
    -John ... I float in liquid gardens
    UTC -7ąDS

  8. #8
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Remove reply indenting from HTML message (Outl

    Hmmm, I found one of the little devils in my archives. There is a line break in the tag because it is so long, which causes the RegExp syntax not to work. Let me see... this is getting awfully repetitive, but it's fast and worthwhile, so we can cover both cases: one line and two:

    ' Kill background image and everything else in the BODY tag (normal, Word)
    msg.HTMLBody = WildReplace(msg.HTMLBody, "<BODY.*>", "<BODY>")
    msg.HTMLBody = WildReplace(msg.HTMLBody, "<BODY.*n.*>", "<BODY>")

    Should it be an optional extra? Naaaah! <img src=/S/laugh.gif border=0 alt=laugh width=15 height=15>

    Added: This was the Word BODY tag I found; there is some kind of "ivy" or other plant growing down the left side of the background image, hence the big margin setting.

    <body bgcolor=&quot;#FFFFFD&quot; background=&quot;cid:image001.gif@01C540D6.24E9AC8 0&quot;
    lang=EN-US link=blue vlink=purple style='margin-left:48.0pt'>

    I wonder whether the embedded graphic image data will get discarded if I click Forward first and clean the new message (rather than changing the original)? Would be a nice bonus, but I wouldn't count on it...

    Hmmm... I notice that the style tags use single quotation marks instead of double. Yet another thing to fix in my code. <img src=/S/smile.gif border=0 alt=smile width=15 height=15>

  9. #9
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Remove reply indenting from HTML message (Outlook

    <P ID="edit" class=small>(Edited by jscher2000 on 22-Apr-05 14:27. )</P>Indenting of replies really annoys me. This macro will remove indenting from HTML messages.
    <UL><big><span style="background-color: #FFFF00; color: #000000; font-weight: bold">April 22, 2005 - A new version of the UnBlockQuote procedure, now entitled UnIndentHTML, is in the attachment. You will still need the WildReplace function from the body of this message in order to run it.

    April 12, 2005 - Original limited version.</span hi>
    </big>[/list]<pre>Sub UnBlockQuote()
    ' Remove BLOCKQUOTE tags, which cause annoying indenting, from HTML message
    ' Not fault tolerant, do not run without HTML message open and active
    If MsgBox("Remove the BLOCKQUOTE tags from this message?", _
    vbQuestion + vbYesNo) = vbNo Then Exit Sub
    Dim msg As MailItem
    Set msg = ActiveInspector.CurrentItem
    msg.HTMLBody = Replace(msg.HTMLBody, "</BLOCKQUOTE>", vbNullString, , , vbTextCompare)
    msg.HTMLBody = WildReplace(msg.HTMLBody, "<BLOCKQUOTE.*>", vbNullString)
    Set msg = Nothing
    End Sub

    Private Function WildReplace(strExpression As String, strFind As String, _
    strReplace As String, Optional bolReplaceAll As Boolean = True, _
    Optional bolCaseSensitive As Boolean = False) As String
    'reference to Microsoft VBScript Regular Expressions NOT required... uses late binding
    'requires VBScript 5 = IE 5.x
    'perform minimal parameter checking
    If (strExpression = vbNullString) Or (strFind = vbNullString) Then
    WildReplace = strExpression
    Exit Function
    End If
    'Dim objRegExp As RegExp
    Dim objRegExp As Object
    'instantiate RegExp object
    'Set objRegExp = New RegExp
    Set objRegExp = CreateObject("vbscript.regexp")
    objRegExp.IgnoreCase = Not bolCaseSensitive
    objRegExp.Global = bolReplaceAll
    ' Pattern syntax: Visual Basic Scripting Edition-Pattern Property
    objRegExp.Pattern = strFind
    WildReplace = objRegExp.Replace(strExpression, strReplace)
    Set objRegExp = Nothing
    End Function
    </pre>

    What's strange is that closing the message doesn't seem to generate a "save/don't save" dialog. So if you're not sure you want to run it, don't run it.

  10. #10
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts

    Re: Remove reply indenting from HTML message (Outl

    Standing on the shoulders of giants, I have had a play with this and morphed it with VBA Macro to Remove Stationery from Email Message and to heavily strip the default html metadata content in emails when replying or forwarding. The particular problem I had was trying to standardise the fonts in an email when replying or forwarding. The default font where you type your message didn't appear to be controllable in the options in Outlook 2007 - well they don't respond to the obvious setting anyway.

    Having never played with regexp before this was a big learning experience for me and it took a long time for me to work out why it couldn't find anything when there were line breaks in the string. I would be interested in any suggestions to make the code more compact and work around the linebreaks problem in a more elegant way than my kludgy zxzx method.
    <pre>Sub EmailCleaner()
    On Error GoTo EmailCleaner_Error
    Dim myMessage As Outlook.MailItem
    Dim str As String

    ' First, check to see if we are in preview-pane mode or message-view mode
    ' If neither, quit out
    Select Case TypeName(Outlook.Application.ActiveWindow)
    Case "Explorer"
    Set myMessage = ActiveExplorer.Selection.Item(1)
    Case "Inspector"
    Set myMessage = ActiveInspector.CurrentItem
    Case Else
    MsgBox ("No message selected.")
    Exit Sub
    End Select
    ' Sanity check to make sure selected message is actually a mail item
    If TypeName(myMessage) <> "MailItem" Then
    MsgBox ("No message selected.")
    Exit Sub
    End If

    'Debug.Print myMessage.HTMLBody

    ' Remove attributes from <BODY> tag
    str = myMessage.HTMLBody
    str = WildReplace(str, "<body [^>]*>", "<body>" & vbCrLf & "

    </p>", True, False) 'simplify body
    str = WildReplace(str, "<p .+?>", "

    ", True, False) 'simplify para tags
    str = WildReplace(str, "<b .+?>", "[b]", True, False) 'simplify bold tags
    str = WildReplace(str, "<br .+?>", "
    ", True, False) 'simplify br tags
    str = WildReplace(str, "<img [^>]*>", "", True, False) 'remove img tags
    str = WildReplace(str, "<font [^>]*>", "", True, False) 'remove font tags
    str = Replace(str, "</font>", "", , , vbTextCompare) 'remove closing font tags
    str = WildReplace(str, "<span [^>]*>", "", True, False) 'remove span tags
    str = Replace(str, "</span>", "", , , vbTextCompare) 'remove closing span tags
    str = WildReplace(str, "<div.+?>", "", True, False) 'remove div tags
    str = Replace(str, "</div>", "", , , vbTextCompare) 'remove closing div tags

    'replace the complete head tag area with a simplified formatting override
    str = WildReplace(str, "<head.+?</head>", _
    "<head><style>p {font-family:'Lucida Sans','sans-serif';color:black;font-size:10pt}</head>", _
    True, False) 'simplify head

    str = Replace(str, "<o>", "", , , vbTextCompare)
    str = Replace(str, "</o>", "", , , vbTextCompare)
    str = Replace(str, vbCrLf & vbCrLf, vbCrLf, , , vbTextCompare)
    str = Replace(str, vbCrLf & vbCrLf, vbCrLf, , , vbTextCompare)
    str = Replace(str, "


    ", "

    ", , , vbTextCompare)
    str = Replace(str, "

    </p>", "", , , vbTextCompare)

    Debug.Print str
    myMessage.HTMLBody = str

    '' Finally, save the modified message
    '' If this line is disabled, you can't run the code from the preview mode
    'myMessage.Save
    Exit Sub

    EmailCleaner_Error:
    MsgBox Err.Number & vbCr & Err.Description
    Exit Sub

    End Sub

    '================================================= =
    Private Function WildReplace(strExpression As String, strFind As String, _
    strReplace As String, Optional bolReplaceAll As Boolean = True, _
    Optional bolCaseSensitive As Boolean = False) As String
    'reference to Microsoft VBScript Regular Expressions NOT required... uses late binding
    'requires VBScript 5 = IE 5.x
    'perform minimal parameter checking
    If (strExpression = vbNullString) Or (strFind = vbNullString) Then
    WildReplace = strExpression
    Exit Function
    End If
    'Dim objregexp As regexp
    Dim objregexp As Object
    'instantiate regexp object
    'Set objregexp = New regexp
    Set objregexp = CreateObject("vbscript.regexp")
    objregexp.IgnoreCase = Not bolCaseSensitive
    objregexp.Global = bolReplaceAll
    ' Pattern syntax: Visual Basic Scripting Edition-Pattern Property
    objregexp.Pattern = strFind

    'outer lines temporarily replace the line feeds to avoid the wildcard search tripping on them
    strExpression = Replace(strExpression, vbCrLf, "zxzx")
    strExpression = objregexp.Replace(strExpression, strReplace)
    WildReplace = Replace(strExpression, "zxzx", vbCrLf)

    Set objregexp = Nothing
    End Function
    </pre>

    Andrew Lockton, Chrysalis Design, Melbourne Australia

  11. #11
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Remove reply indenting from HTML message (Outl

    Note to readers: the Lounge software interprets a lower case as a line break and strips it. It will display the tag in uppercase. So in the post above, where there is an inexplicable line break, you probably need to reinsert the lower case . Or if you see an upper case , you should replace it with lower case, to avoid potential case sensitivity problems with matching.

  12. #12
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Remove reply indenting from HTML message (Outl

    Oops, the attachment was lost in the great server hard drive crash. I can't find that .txt file, but this is what I currently have in Outlook:

    <code>Sub UnIndentHTML()
    ' Remove BLOCKQUOTE and other tags which cause annoying indenting in HTML messages
    If Inspectors.Count = 0 Then
    MsgBox "Please open an HTML-format message before running this macro!", _
    vbExclamation + vbOKOnly
    Exit Sub
    End If
    If ActiveInspector.EditorType <> olEditorHTML Then
    MsgBox "This macro is for HTML-format messages only, sorry!", _
    vbExclamation + vbOKOnly
    Exit Sub
    End If
    If MsgBox("Remove the BLOCKQUOTE tags and MARGIN-LEFT settings from this message?", _
    vbQuestion + vbYesNo) = vbNo Then Exit Sub
    Dim msg As MailItem
    Set msg = ActiveInspector.CurrentItem
    ' Remove end tag and then start tag for BLOCKQUOTE
    msg.HTMLBody = Replace(msg.HTMLBody, "</BLOCKQUOTE>", vbNullString, , , vbTextCompare)
    msg.HTMLBody = WildReplace(msg.HTMLBody, "<BLOCKQUOTE.*>", vbNullString)
    ' Remove MARGIN-LEFT property and then clean up empty style tags, if any
    msg.HTMLBody = WildReplace(msg.HTMLBody, "MARGIN-LEFT: [0-9.]+in", vbNullString)
    msg.HTMLBody = Replace(msg.HTMLBody, " style=""""", vbNullString, , , vbTextCompare)
    ' Kill background image and everything else in the BODY tag (normal, Word)
    msg.HTMLBody = WildReplace(msg.HTMLBody, "<BODY.*>", "<BODY>")
    msg.HTMLBody = WildReplace(msg.HTMLBody, "<BODY.*n.*>", "<BODY>")
    If InStr(1, msg.HTMLBody, "<UL", vbTextCompare) > 0 Then
    If MsgBox("Remove the UL tags from this message? UL tags may be used for " & _
    "indenting, but also bulleted lists.", _
    vbQuestion + vbYesNo) = vbYes Then
    ' Remove end tag and then start tag for UL
    msg.HTMLBody = Replace(msg.HTMLBody, "[/list]", vbNullString, , , vbTextCompare)
    msg.HTMLBody = WildReplace(msg.HTMLBody, "<UL.*>", vbNullString)
    End If
    End If
    Set msg = Nothing
    End Sub</code>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •