[Catégorie modifiée VB6 -> .Net] pour q'un textbox lire les codes html

Signaler
Messages postés
17
Date d'inscription
mercredi 1 avril 2009
Statut
Membre
Dernière intervention
22 mai 2011
-
Messages postés
14008
Date d'inscription
samedi 29 décembre 2001
Statut
Modérateur
Dernière intervention
28 août 2015
-
J'ai fais un module pour lire mes mails par POP3 de ma boite Yahoo qui marche sans probleme, mais pour les messages que recoit en HTML je vois tout le code.

Quelqu'un connaitrait-il un moyen simple (genre API) d'extraire le texte brut, sans les tags HTML ?

mercii

3 réponses

Messages postés
14008
Date d'inscription
samedi 29 décembre 2001
Statut
Modérateur
Dernière intervention
28 août 2015
74
Pas bonjour non plus.

Ça s'appelle un WebBrowser = "Microsoft Internet Controls".

Vala
Jack, MVP VB
NB : Je ne répondrai pas aux messages privés

Le savoir est la seule matière qui s'accroit quand on la partage (Socrate)
Messages postés
17
Date d'inscription
mercredi 1 avril 2009
Statut
Membre
Dernière intervention
22 mai 2011

bsr jack
est ce que tu peu expliqué svp
voici mon code vb2008
Imports System
Imports System.Net.Sockets
Imports System.Net.Security
Imports System.Security.Cryptography.X509Certificates
Imports System.Text
Imports System.IO
Imports System.Net
Imports System.Threading
Imports System.Windows.Forms



Public Class Form1 : Inherits System.Windows.Forms.Form
    Dim Server As TcpClient
    Dim NetStrm As System.Net.Security.SslStream
    Dim RdStrm As StreamReader


    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub




    Private Shared Function CertificateValidationCallback(ByVal sender As Object, ByVal certificate As X509Certificate, ByVal chain As X509Chain, ByVal sslPolicyErrors__1 As SslPolicyErrors) As Boolean
        If sslPolicyErrors__1 <> SslPolicyErrors.None Then
            MessageBox.Show("SSL Certificate Validation Error!")
            Debug.Print(sslPolicyErrors__1.ToString())
            Return False
        Else
            Return True
        End If
    End Function

    Public Function connect() As Integer
        Dim POP3Account As String
        POP3Account = "pop3.live.com"
        If POP3Account.Trim = "" Then Exit Function
        Try
            Dim certName As String = "pop3.live.com"
            Server = New TcpClient()
            Server.Connect(POP3Account.Trim, 995)
            NetStrm = New SslStream(Server.GetStream(), False, New RemoteCertificateValidationCallback(AddressOf CertificateValidationCallback))
            NetStrm.AuthenticateAsClient(certName)
            RdStrm = New StreamReader(NetStrm)
        Catch exc As Exception
            MsgBox(exc.Message)
            Exit Function
        End Try

        Dim user As String
        user = "sts2012@hotmail.fr"
        Dim data As String = "USER " + user.Trim + vbCrLf
        Dim szData() As Byte = System.Text.Encoding.ASCII.GetBytes(data.ToCharArray())
        NetStrm.Write(szData, 0, szData.Length)
        Dim POPResponse As String
        POPResponse = RdStrm.ReadLine
        If POPResponse.Contains("-ERR") Then
            MsgBox("Invalid user Name")
            Return -1
        End If
        Dim password As String
        password = "sts123"
        data = "PASS " & password & vbCrLf
        szData = System.Text.Encoding.ASCII.GetBytes(data.ToCharArray())
        NetStrm.Write(szData, 0, szData.Length)
        POPResponse = RdStrm.ReadLine
        If POPResponse.Contains("-ERR") Then
            MsgBox("Invalid Password")
            Return (-1)
        End If
        data = "STAT" + vbCrLf
        szData = System.Text.Encoding.ASCII.GetBytes(data.ToCharArray())
        NetStrm.Write(szData, 0, szData.Length)
        POPResponse = RdStrm.ReadLine
        If POPResponse.Substring(0, 4) = "-ERR" Then
            MsgBox("could not log your in")
            Return -1
        End If
        data = "Stat" + vbCrLf
        szData = System.Text.Encoding.ASCII.GetBytes(data.ToCharArray())
        NetStrm.Write(szData, 0, szData.Length)
        POPResponse = RdStrm.ReadLine
        If POPResponse.Contains("-ERR") Then
            MsgBox("could not log your in")
            Return -1
        End If
        Dim parts() As String
        parts = POPResponse.Split(" ")
        Dim messages As Integer

        'messages = parts(3)
        messages = CInt(parts(1))
        Return messages

    End Function
    Public Function DeleteMessage(ByVal msgIndex As Integer)
        Dim data As String = "DELE " & msgIndex.ToString & vbCrLf
        Dim SzData() As Byte = System.Text.Encoding.ASCII.GetBytes(data.ToCharArray())
        NetStrm.Write(SzData, 0, SzData.Length)
        Dim tmpString As String = RdStrm.ReadLine()
        If tmpString.Substring(0, 4) = "-ERR" Then
            MsgBox("Could Not Delete Message")
            Return (-1)
        Else
            Return 11
        End If
    End Function



    Public Structure Message
        Dim _From As String
        Dim _To As String
        Dim _Date As String
        Dim _Subject As String
        Dim _CC As String
        Dim _BCC As String
        Dim _Body As String
        Dim _Received As String
    End Structure

    Public Function CreateFromText(ByVal strMessage As String) As Message
        Dim Mssg As New Message
        Dim brkPos As Integer
        Dim Header As String
        Dim Headers() As String
        Dim Body As String
        Dim HeaderName As String
        Dim HeaderValue As String
        brkPos = InStr(1, strMessage, vbCrLf & vbCrLf)
        If brkPos Then
            Header = strMessage.Substring(0, brkPos - 1)
            Body = strMessage.Substring(brkPos + 1, _
            strMessage.Length - Header.Length - 3)
            Mssg._Body = Body
        Else
            Throw New Exception("Invalid Message Format")
            Exit Function
        End If
        Headers = Split(Header, vbCrLf)
        Dim _header As String
        For Each _header In Headers
            brkPos = _header.IndexOf(":")
            If brkPos >= 0 Then
                HeaderName = _header.Substring(0, brkPos)
            Else
                HeaderName = ""
            End If
            HeaderValue = _header.Substring(brkPos + 1)
            Select Case HeaderName.ToLower
                Case "received"
                    Mssg._Received = HeaderValue
                Case "from"
                    Mssg._From = HeaderValue
                Case "to"
                    Mssg._To = HeaderValue
                Case "cc"
                    Mssg._CC = HeaderValue
                Case "bcc"
                    Mssg._BCC = HeaderValue
                Case "subject"
                    Mssg._Subject = HeaderValue
                Case "date"
                    Mssg._Date = HeaderValue
            End Select
        Next
        Return Mssg
    End Function
    Function GetMessage(ByVal msgindex As Integer) As String
        Dim tmpString As String
        Dim Data As String
        Dim SzData() As Byte
        Dim msg As String

        Try
            Data = "RETR " & msgindex.ToString & vbCrLf
            SzData = System.Text.Encoding.ASCII.GetBytes(Data.ToCharArray())
            NetStrm.Write(SzData, 0, SzData.Length)
            tmpString = RdStrm.ReadLine()
            If tmpString.Substring(0, 4) <> "-ERR" Then
                While (tmpString <> ".")
                    msg = msg & tmpString & vbCrLf
                    tmpString = RdStrm.ReadLine
                End While
            End If
        Catch exc As InvalidOperationException
            MsgBox("Message Retrival Failed: " & vbCrLf & Err.ToString())
        End Try
        Return msg
    End Function

    Private Sub btnMailReceive_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMailReceive.Click
        Dim i As Integer
        Dim msg As Form1.Message
        Dim msgstring As String
        Dim messages1 As Integer
        Me.Cursor = Cursors.WaitCursor
        messages1 = connect()
        If messages1 = -1 Then
            Me.Cursor = Cursors.Default
            Exit Sub
        End If
        Dim originalCaption As String = Me.Text
        For i = 1 To messages1
            Me.Text = "Downloading Message " & i.ToString & "/" & _
            messages1.ToString
            Dim msgitem As New ListViewItem
            msgstring = GetMessage(i)
            msg = CreateFromText(msgstring)
            msgitem.Text = msg._From
            msgitem.SubItems.Add(msg._Subject)
            msgitem.SubItems.Add(msg._Date)
            lstMailList.Items.Add(msgitem)
            txtMailContent.AppendText(msg._Body & vbCrLf)
        Next
        Me.Text = originalCaption
        Me.Cursor = Cursors.Default
    End Sub

    Private Sub lstMailList_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

        'Dim objPOP3 As POP3Message
        txtMailContent.Text = GetMessage(lstMailList.SelectedIndices(0) + 1)
    End Sub

    Private Sub lstMailList_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles lstMailList.KeyUp
        If e.KeyCode = Keys.Delete Then
            If DeleteMessage(lstMailList.SelectedIndices(0) + 1) >= 0 Then
                lstMailList.Items(lstMailList.SelectedIndices(0)).Text = "DELETED"
                lstMailList.Items(lstMailList.SelectedIndices(0)).SubItems.Clear()
                MsgBox("Your Email Message is Deleted", MsgBoxStyle.Information, "Delete Message")
            End If
        End If
    End Sub
Messages postés
14008
Date d'inscription
samedi 29 décembre 2001
Statut
Modérateur
Dernière intervention
28 août 2015
74
Si c'est du .Net, pourquoi avoir posté dans la catégorie VB6 ?

Au lieu d'envoyer ton texte dans une TextBox, tu confectionnes un fichier que tu relis au travers du composant WebBrowser (ça doit toujours exister en .Net)