Last active
December 14, 2015 15:49
-
-
Save facebookegypt/5110353 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'Starts | |
Imports System.IO | |
Imports System.Net.Sockets | |
Imports System.Text | |
Imports System.Net.Security | |
Imports System.Net | |
Class Form1 | |
Dim PopHost As String | |
Dim UserName As String | |
Dim Password As String | |
Dim PortNm As Integer | |
Dim POP3 As New TcpClient | |
Dim Read_Stream As StreamReader | |
Dim NetworkS_tream As NetworkStream | |
Dim m_sslStream As SslStream | |
Dim server_Command As String | |
Dim ret_Val As Integer | |
Dim Response As String | |
Dim Parts() As String | |
Dim m_buffer() As Byte | |
Dim StatResp As String | |
Dim server_Stat(2) As String | |
Private Sub CmdDownload_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CmdDownload.Click | |
'If statement is to control the login and logout method : Exception (Already Connected TcpClient) | |
If POP3.Connected = True Then | |
CloseServer() | |
POP3 = New TcpClient(PopHost, Integer.Parse(TxtPort.Text)) | |
ret_Val = 0 | |
Exit Sub | |
Else | |
PopHost = TxtHost.Text | |
UserName = TxtUsrNm.Text | |
Password = TxtPass.Text | |
PortNm = TxtPort.Text | |
Cursor = Cursors.WaitCursor | |
POP3 = New TcpClient(PopHost, Integer.Parse(TxtPort.Text)) | |
NetworkS_tream = POP3.GetStream 'Read the stream | |
m_sslStream = New SslStream(NetworkS_tream) 'Read SSL Stream | |
m_sslStream.AuthenticateAsClient(PopHost) 'Auth. | |
Read_Stream = New StreamReader(m_sslStream) 'Read the stream | |
StatResp = Read_Stream.ReadLine() | |
ListBox1.Items.Clear() | |
StatResp = Login(m_sslStream, "USER " & UserName) & vbCrLf | |
ListBox1.Items.Add(StatResp) | |
StatResp = Login(m_sslStream, "PASS " & Password) & vbCrLf | |
ListBox1.Items.Add(StatResp) | |
StatResp = Login(m_sslStream, "STAT ") & vbCrLf | |
ListBox1.Items.Add(StatResp) | |
'Get Messages count | |
server_Stat = StatResp.Split(" ") | |
MsgCount.Text = server_Stat(1) | |
ret_Val = 1 | |
End If | |
Cursor = Cursors.Default | |
CmdClose.Enabled = True | |
CmdDownload.Enabled = False | |
End Sub | |
Sub CloseServer() | |
StatResp = Login(m_sslStream, "QUIT ") & vbCrLf | |
ListBox1.Items.Add(StatResp) | |
ListBox2.Items.Clear() | |
TextBox1.Text = String.Empty | |
POP3.Close() | |
ret_Val = 0 | |
End Sub | |
Function Login(ByVal SslStrem As SslStream, ByVal Server_Command As String) As String | |
Dim Read_Stream2 = New StreamReader(SslStrem) | |
Server_Command = Server_Command + vbCrLf | |
m_buffer = System.Text.Encoding.ASCII.GetBytes(Server_Command.ToCharArray()) | |
m_sslStream.Write(m_buffer, 0, m_buffer.Length) | |
Dim Server_Reponse As String | |
Server_Reponse = Read_Stream2.ReadLine() | |
Return Server_Reponse | |
End Function | |
Private Sub CmdClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CmdClose.Click | |
CloseServer() | |
CmdClose.Enabled = False | |
CmdDownload.Enabled = True | |
ret_Val = 0 | |
End Sub | |
Sub getMesgs(ByVal Num_Emails As Integer) | |
Cursor = Cursors.WaitCursor | |
Dim List_Resp As String | |
Dim I As Integer | |
For I = 1 To Num_Emails | |
List_Resp = Login(m_sslStream, "LIST " & I.ToString) | |
ListBox2.Items.Add(List_Resp) | |
Next I | |
Cursor = Cursors.Default | |
End Sub | |
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click | |
If ret_Val = 0 Then | |
ListBox2.Items.Add("You are not connected, please connect") | |
Exit Sub | |
End If | |
ListBox2.Items.Clear() | |
getMesgs(Integer.Parse(server_Stat(1))) | |
End Sub | |
Sub GetEmails(ByVal Server_Command As String) | |
Dim m_buffer() As Byte = System.Text.Encoding.ASCII.GetBytes(Server_Command.ToCharArray()) | |
Dim stream_Reader As StreamReader | |
Dim TxtLine As String = "" | |
Try | |
m_sslStream.Write(m_buffer, 0, m_buffer.Length) | |
stream_Reader = New StreamReader(m_sslStream) | |
Do While stream_Reader.Peek() <> -1 | |
TxtLine += stream_Reader.ReadLine() & vbNewLine | |
Loop | |
TextBox1.Text = TxtLine | |
Catch ex As Exception | |
MsgBox(ex.Message) | |
End Try | |
End Sub | |
Private Sub ListBox2_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListBox2.DoubleClick | |
Dim Index_Num As String | |
Dim StrRetr As String | |
TextBox1.Text = "" | |
Try | |
Index_Num = (ListBox2.SelectedIndex + 1).ToString | |
StrRetr = ("RETR " + Index_Num + vbCrLf) | |
GetEmails(StrRetr) Catch ex As Exception | |
MsgBox(ex.Message) | |
End Try | |
End Sub | |
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click | |
Application.Exit() | |
End Sub | |
End Class | |
'End here |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment