0

我这里有个问题是调试输出

"?uƒn74tn5187r&key=6e6e0936c4e6c48be56a72eba8964df0"

应该

"?u=83n74tn5187r&key=6e6e0936c4e6c48be56a72eba8964df0"

我已经尝试过另一个类似问题的解决方案,但它让我失望了。

Dim uni As Byte() = Encoding.GetEncoding(437).GetBytes("?uƒn74tn5187r&key=6e6e0936c4e6c48be56a72eba8964df0")
Dim Ascii As String = Encoding.ASCII.GetString(uni)

ASCII = "?u?n74tn5187r&key=6e6e0936c4e6c48be56a72eba8964df0"

我猜我必须猜测 437 .. 可能是对所有数字的蛮力攻击,直到?u=83?uƒ

真的,我正在尝试从电子邮件(POP3)中读取 Unicode-32(巴西格式的文本)。现在我想在=83这里使用此功能可能会搞砸。

但是如果没有这个函数,POP3 电子邮件的正文将包含可能无用的 urlencode() 变体,但是.. 而不是%20使用=20.

我想知道如何解决这个问题。

 Public Shared Function DecodeQuotedPrintable(ByVal Message As String, Optional ByVal QuickClean As Boolean = False) As String
        'set up StringBuilder object with data stripped of any line continuation tags
        Dim Msg As New StringBuilder(Message.Replace("=" & vbCrLf, vbNullString))

        If QuickClean Then                                                  'perform a quick clean (clean up common basics)
            Return Msg.Replace("=" & vbCrLf, vbNullString).Replace("=0D", vbCr).Replace("=0A", _
                                   vbLf).Replace("=20", " ").Replace("=3D", "=").ToString
        Else                                                                'perform total cleaning
            'store 2-character hex values that require a leading "0"
            Dim HxData As String = "X0102030405060708090A0B0C0D0E0F"
            For Idx As Integer = 1 To &HF                                   'initially process codes 1-15, which require a leading zero
                Msg.Replace("=" & Mid(HxData, Idx << 1, 2), Chr(Idx))       'replace hex data with single character code (SHIFT is faster)
            Next
            For idx As Integer = &H10 To &HFF                               'process the whole 8-bit extended ASCII gambit
                Msg.Replace("=" & Hex(idx), Chr(idx))                       'replace hex data with single character code
            Next
            Return Msg.ToString                                             'return result string
        End If
    End Function

编辑: 我尝试修复该功能(如果它真的导致问题?我永远不会知道)

公共共享函数 DecodeQuotedPrintable(ByVal Message As String, Optional ByVal QuickClean As Boolean = False) As String '设置 StringBuilder 对象,其中删除任何行继续标记的数据 Dim Msg As New StringBuilder(Message.Replace("=" & vbCrLf, vbNullString ))

If QuickClean Then                                                  'perform a quick clean (clean up common basics)
    Return Msg.Replace("=" & vbCrLf, vbNullString).Replace("=0D", vbCr).Replace("=0A", _
                           vbLf).Replace("=20", " ").Replace("=3D", "=").ToString
Else                                                                'perform total cleaning
    'store 2-character hex values that require a leading "0"

    Msg.Replace("=" & vbCrLf, vbNullString).Replace("=0D", vbCr).Replace("=0A", _
                           vbLf).Replace("=20", " ").Replace("=3D", "%$#@[EQUALS]@#$%").ToString()

    Dim HxData As String = "X0102030405060708090A0B0C0D0E0F"
    For Idx As Integer = 1 To &HF                                   'initially process codes 1-15, which require a leading zero
        Msg.Replace("=" & Mid(HxData, Idx << 1, 2), Chr(Idx))       'replace hex data with single character code (SHIFT is faster)
    Next
    For idx As Integer = &H10 To &HFF                               'process the whole 8-bit extended ASCII gambit
        Msg.Replace("=" & Hex(idx), Chr(idx))                       'replace hex data with single character code
    Next

    Msg.Replace("%$#@[EQUALS]@#$%", "=")

    Return Msg.ToString                                             'return result string
End If

结束功能

4

1 回答 1

1

"ƒ" 在 Windows-1252 字符集中的 Quoted Printable 编码中由 =83 表示。

于 2012-01-08T00:16:56.373 回答