Sign in to follow this  
Followers 0
wysocki

Bug?: _Inetmail can't have ampersand (&) in text

6 posts in this topic

I'm trying to create outgoing emails using the customer's mail client via _inetmail. It works great except when I try to insert an ampersand character (&) into the text.

#include <INet.au3>
$subj = 'Hello from Easyrest B&B resort'
$mesg = 'We hope you enjoy our B&B resort.'
_INetMail ( '', $subj,$mesg)

This produces a subject of: "Hello from Easyrest B"

and the message becomes: "We hope you enjoy our B"

I'm not sure what "version" of AutoIT I'm running. I just downloaded and installed the latest version today and the editor (Scite?) says it's Version 1.75 Nov 22 2007 but the autoit.exe is dated 12/23/06 (can't find version) and Aut2Exe is dated 2/9/2008 (version 3). Just to add to my confusion.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

I also got this problem. Any solution anyone?

Edited by Shy

Share this post


Link to post
Share on other sites

Put && instead of one &.

Share this post


Link to post
Share on other sites

Put && instead of one &.

Tried it,

didn't help :)

tried:

chr

chrW

/&

%26

don't know what else to do.

The problem seems to be in the function's use of "_INetExplorerCapable"

Share this post


Link to post
Share on other sites

Tried it,

didn't help :)

tried:

chr

chrW

/&

%26

don't know what else to do.

The problem seems to be in the function's use of "_INetExplorerCapable"

Does this work

$subj = 'Hello from Easyrest B&amp;B resort'


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

This problem can be fixed by modify "c:\Program Files\AutoIt3\Include\Inet.au3" .

Root cause :

'&' is a special character for mailto: command line. See http://www.ianr.unl.edu/internet/mailto.html .

Problem 1: _INetExplorerCapable() in inet.au3 didn't consider '&' (0x26).

Problem 2: _INetMail() in inet.au3 should not handle the entire command line by only one _INetExplorerCapable(), should handle sections separately so as to allow '&' to be translated to %26 correctly.

Solution :

Change the above two functions to as attached below. The new code also fixed garbled multibyte character (Chinese for example, also Japanese, Korean I think) problem.

;===============================================================================
;
; Function Name:    _INetMail()
; Description:      Open default mail client with given Address/Subject/Body
; Parameter(s):     $s_MailTo    - Address for E-Mail
;                   $s_Subject   - Subject <Weswolf at aol dot com>of E-Mail
;                   $s_MailBody  - Body of E-Mail
; Requirement(s):   _INetExplorerCapable
; Return Value(s):  On Success - Process ID of e-mail client
;                   On Failure - Returns 0 and sets @error to non-zero.
; Author(s):        Original : Wes Wolfe-Wolvereness <Weswolf at aol dot com>
;                   Bug fix : hcchen5600 2010/04/27 15:40:09 I fixed this bug "Bug?: _Inetmail can't have ampersand (&) in text" http://www.autoitscript.com/forum/index.php?showtopic=64890
;===============================================================================
;
Func _INetMail($s_MailTo, $s_MailSubject, $s_MailBody)
    Local $prev = opt("ExpandEnvStrings", 1)
    Local $var = RegRead('HKCR\mailto\shell\open\command', "")
    
    ; hcchen5600 2010/04/27 15:48:48 -- '&' is a special character in "mailto:" command line. So _INetExplorerCapable() needs to take care of 0x26 and here _INetExplorerCapable() need to take care each sections separately. -- hcchen5600 2010/04/27 15:48:58 
    ; Local $ret = Run(StringReplace($var, '%1', _INetExplorerCapable('mailto:' & $s_MailTo & '?subject=' & $s_MailSubject & '&body=' & $s_MailBody)))
    Local $ret = Run(StringReplace($var, '%1', 'mailto:' & _INetExplorerCapable($s_MailTo) & '?subject=' & _INetExplorerCapable($s_MailSubject) & '&body=' & _INetExplorerCapable($s_MailBody)))

    Local $nError = @error, $nExtended = @extended
    opt("ExpandEnvStrings", $prev)
    Return SetError($nError, $nExtended, $ret)
EndFunc   ;==>_INetMail


;===============================================================================
;
; Function Name:    _INetExplorerCapable()  
; Description:      Convert a string to IE capable line
; Parameter(s):     $s_IEString - String to convert to a capable IExplorer line -- hcchen5600 2010/04/27 15:53:40 with Chinese support (multibyte support)
; Requirement(s):   None
; Return Value(s):  On Success - Returns the converted string
;                   On Failure - Blank String and @error = 1
; Author(s):        Original : Wes  Wolfe-Wolvereness <Weswolf at aol dot com> 
;                   Bug fix : hcchen5600 2010/04/26 15:03:33 add multibyte character support (Chinese, simplified Chinese. Also Japanese, Korean I think)
;                   Bug fix : hcchen5600 2010/04/27 15:56:21 '&' is special character to mailto: that it must be changed to be %26 
;===============================================================================
;
Func _INetExplorerCapable($s_IEString)
    If StringLen($s_IEString) <= 0 Then
        Return ''
        SetError(1)
    Else
        Local $s_IEReturn
        Local $i_IECount, $i_MBCount
        Local $n_IEChar
        For $i_IECount = 1 To StringLen($s_IEString)
            
            ; Original version did not support multibyte characters. Also lost special character '&'=0x26.
            ; $n_IEChar = '0x' & Hex(Asc(StringMid($s_IEString, $i_IECount, 1)), 2)
            ; If $n_IEChar < 0x21 Or $n_IEChar = 0x25 Or $n_IEChar = 0x2f Or $n_IEChar > 0x7f Then
            ;   $s_IEReturn = $s_IEReturn & '%' & StringRight($n_IEChar, 2)
            ; Else
            ;   $s_IEReturn = $s_IEReturn & Chr($n_IEChar)
            ; EndIf

            ; consider multibyte characters hcchen5600 2010/04/26 15:54:45 
            $n_IEChar = StringToBinary(StringMid($s_IEString, $i_IECount, 1)&' ')
            $n_IEChar = StringRegExpReplace($n_IEChar,"(..)(20)?+\z","\1") ; remove tailing unexpected '20' hcchen5600  2010/04/26 08:39:28 
            If $n_IEChar < 0x21 Or $n_IEChar = 0x25 Or $n_IEChar = 0x26 Or $n_IEChar = 0x2f then  ; add 0x26 for '&' hcchen5600 2010/04/27 15:58:09 
                $s_IEReturn = $s_IEReturn & '%' & StringRight($n_IEChar, 2)
            ElseIf $n_IEChar > 0x7f Then
                For $i_MBCount = 3 To StringLen($n_IEChar) Step 2
                    $s_IEReturn &= '%' & BinaryToString(StringMid($n_IEChar, $i_MBCount, 2))
                Next
            Else
                $s_IEReturn = $s_IEReturn & Chr($n_IEChar)
            EndIf
        Next
        Return $s_IEReturn
    EndIf
EndFunc   ;==>_INetExplorerCapable

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0