电子邮件附带的XML文件包含错误的字符

时间:2019-01-18 09:50:19

标签: xml vb.net mimekit

我正在下载附件为“ file.xml”的电子邮件。

当我保存文件时,文件被错误地保存,用“ =”替换为“ 3D =“。

下面是示例:

<?xml version=3D"1.0" encoding=3D"UTF-8"?><ns3:RicevutaConsegna xmlns:ns3=
    =3D"http://ivaservizi.agenziaentrate.gov.it/docs/xsd/fattura/messaggi/v1.0"=
         xmlns:ns2=3D"http://www.w3.org/2000/09/xmldsig#" versione=3D"1.0">

代替

    <?xml version="1.0" encoding="UTF-8"?><ns3:RicevutaConsegna xmlns:ns3=
"http://ivaservizi.agenziaentrate.gov.it/docs/xsd/fattura/messaggi/v1.0"
xmlns:ns2="http://www.w3.org/2000/09/xmldsig#" versione="1.0">

如果我使用Thunderbird保存文件,则效果很好。

    client.CheckCertificateRevocation = False
    client.Connect("imap.pec.it", 993, True)

    client.Authenticate("xxxxxx@pec.it", "xxxx")
    client.Inbox.Open(FolderAccess.ReadOnly)
    Dim query = Search.SearchQuery.SubjectContains("Ricevuta di consegna")

    For Each uid In client.Inbox.Search(query)
        Dim messaggio = client.Inbox.GetMessage(uid)
        ListBox1.Items.Add(messaggio.Subject)

        For Each BodyPart In messaggio.BodyParts

            If BodyPart.ContentDisposition.FileName = "postacert.eml" Then
                Dim postacert As MimeKit.MessagePart = BodyPart

                TextBox1.Text = postacert.Message.Attachments(0).ToString
                Dim attach As MimeKit.MimePart = postacert.Message.Attachments(0)
                Dim file As FileStream = New FileStream(attach.FileName, FileMode.Create)
                attach.Content.WriteTo(b.FileName)
                file.Close()

有错误吗?

(我正在VB.NET中工作。)

1 个答案:

答案 0 :(得分:1)

找到错误的地方。 我用:

attach.Content.WriteTo(file)

代替

attach.Content.DecodeTo(file)