BUG: urn:schemas:mailheader:from Field Is Corrupted When Binding to an ADO Stream (256517)



The information in this article applies to:

  • ActiveX Data Objects (ADO) 2.6
  • Collaboration Data Objects for Exchange 2000
  • Microsoft Collaboration Data Objects for Windows 2000

This article was previously published under Q256517

SYMPTOMS

When you bind to an ASCII file using an ActiveX Data Objects (ADO) Stream object, the field name urn:schemas:mailheader:from may be corrupted.

CAUSE

By default, the ADO Stream object uses the Unicode character set. Because the data in the newsgroup post (.nws) is ASCII, the field name becomes corrupted due to the mismatched character sets. ADO adds the Unicode byte-order marks to the beginning of any ASCII file, which creates a custom header as shown below.

Standard Header:
urn:schemas:mailheader:from

Modified Header:
urn:schemas:mailheader:from

WORKAROUND

To work around this problem, specify that the stream contains ASCII text before loading the file:
Sub main()
    Dim oMsg As New CDO.Message
    Dim oStream As New ADODB.Stream
    Dim oField As ADODB.Field

    Dim i As Integer
    Dim sFilepath As String
    
    sFilepath = "\\servername\directory\test.nws"
    'Note: The line below is the only change to the code in the "More Information" section.
    oStream.Charset = "us-ascii"
    oStream.Open
    oStream.LoadFromFile sFilepath
    oStream.Flush

    oMsg.BodyPart.DataSource.OpenObject oStream, cdoAdoStream
    'Print all of the fields.
    i = 0
    For Each oField In oMsg.Fields
        Debug.Print i & ") " & oField.Name & " = " & oField.Value
       i = i + 1
    Next
    'Query for the "From" Field.
    For Each oField In oMsg.Fields
     If (oField.Name = "urn:schemas:mailheader:from") Then
        Debug.Print oField.Name & " = " & oField.Value
     End If
    Next
End Sub
				

STATUS

Microsoft has confirmed that this is a problem in the Microsoft products that are listed at the beginning of this article.

MORE INFORMATION

Steps to Reproduce Behavior

  1. Use Microsoft Outlook Express to save a newsgroup post to your hard disk. This file should have an .nws extension .
  2. In Microsoft Visual Basic, create a new Standard EXE project.
  3. Reference the Microsoft ActiveX Data Objects 2.5 Library and the Microsoft CDO for Exchange 2000 Library.
  4. Copy the following code to a Visual Basic module:
    Sub main()
        Dim oMsg As New CDO.Message
        Dim oStream As New ADODB.Stream
        Dim oField As ADODB.Field
    
        Dim i As Integer
        Dim sFilepath As String
        
        sFilepath = "\\servername\directory\test.nws"
    
        oStream.Open
        oStream.LoadFromFile sFilepath
        oStream.Flush
    
        oMsg.BodyPart.DataSource.OpenObject oStream, cdoAdoStream
        'Print all of the fields.
        i = 0
        For Each oField In oMsg.Fields
            Debug.Print i & ") " & oField.Name & " = " & oField.Value
           i = i + 1
        Next
        'Query for the field "From".  
        For Each oField In oMsg.Fields
         If (oField.Name = "urn:schemas:mailheader:from") Then
            Debug.Print oField.Name & " = " & oField.Value
         End If
        Next
    End Sub
    					
  5. Run the code.

Modification Type:MinorLast Reviewed:8/25/2005
Keywords:kbbug kbnofix KB256517