vb.net 接收邮政问题.高手请进
Private Function ShowSubject(ByVal i As String) As String
Dim M_Subject As String()
SW.WriteLine("RETR " & i) '获取邮件文本
SW.Flush()
While SR.Peek <> 46
M_Response = SR.ReadLine
If M_Response <> "" Then
M_Subject = M_Response.Split(":".ToCharArray())
Try
If M_Subject(0).ToString = "Subject" Then
Return (Decode(M_Subject(1).ToString))
End If
Catch ex As Exception
MsgBox("err")
Return ""
End Try
End If
End While
Return ""
End Function
Private Function Decode(ByVal Subject As String) As String
Dim tmp As String
If Subject.Substring(1, 8) = "=?gbk?B?" Then '首部去除标志字符
tmp = Mid(Subject, 10, Subject.Length - 11) '尾部去除<?=>标志)
ElseIf Subject.Substring(1, 11) = "=?gb2312?B?" Then
tmp = Mid(Subject, 13, Subject.Length - 14)
End If
Try
Dim Ret As Byte() = Convert.FromBase64String(tmp)
Subject = Encoding.GetEncoding(936).GetString(Ret) '解码BASE64码
Return Subject
Catch ex As Exception
MsgBox("邮件标题编码错误!", MsgBoxStyle.Critical, "错误信息")
Return ""
End Try
End Function
"=?gbk?B?" 出错了.
"=?gb2312?B?" 出错了.