Sort-POP3-messages-by-date - WeOnlyDo Software example code



All

wodCrypt (12)
wodSSH (10)
wodSFTP (23)
wodSSHServer (1)
wodSSHTunnel (11)
wodSSHpackage
wodSFTPdll

wodSSH.NET (10)
wodSFTP.NET (24)
wodFtpDLX.NET (22)
wodWebServer.NET (10)

wodAppUpdate (13)
wodHttpDLX (8)
wodFtpDLX (22)
wodTelnetDLX
wodFTPServer (3)
wodWebServer (10)
wodVPN
wodXMPP (13)
All ** [Visual Basic] ** [C#] ** [VB.NET] **

Sort POP3 messages by date
VB code
Dim wodPop3 As wodPop3Com
Set wodPop3 = New wodPop3Com

'First we set up the hostname, login and password for POP3 server.
wodPop3.HostName = "your_pop3_hostname"
wodPop3.Login = "your_pop3_login"
wodPop3.Password = "your_pop3_password"
wodPop3.Blocking = True 'Use synchronous connections
'Then we connect to POP3 server.
wodPop3.Connect
'Using GetAll all messages will be downloaded from server.
wodPop3.Messages.GetAll
'We can disconnect from server now because messages are downloaded.
wodPop3.Disconnect

Dim sortDate As Date
Dim i, j, k, minIndex As Integer
Dim collDate As Collection
Dim collDatePosition As Collection
Dim collOutput As New Collection
Set collDate = New Collection
Set collDatePosition = New Collection
Set collOutput = New Collection

'Put messages from Pop3Msgs collection in new collection.
For i = 0 To wodPop3.Messages.Count - 1
    collDate.Add wodPop3.Messages(i).Date
    collDatePosition.Add i
Next i

'Now we will sort messages by date.
Do
    sortDate = collDate.Item(1)
    minIndex = 1
    For j = 1 To collDate.Count
        If collDate(j) <= sortDate Then
            sortDate = collDate(j)
            minIndex = j
        End If
    Next j
    collOutput.Add collDatePosition(minIndex)
    collDate.Remove (minIndex)
    collDatePosition.Remove (minIndex)
Loop Until collDate.Count = 0

'Finally we will print messages sorted by date from oldest to newest message.
For k = 1 To collOutput.Count
    Debug.Print "Date:    " & wodPop3.Messages(collOutput(k)).Date  'Message date
    Debug.Print "From:    " & wodPop3.Messages(collOutput(k)).From  'Sender of message
    Debug.Print "Subject: " & wodPop3.Messages(collOutput(k)).Subject 'Message subject
Next k
VB.NET code
Dim wodPop3 As New WODPOP3COMLib.wodPop3Com

'First we set up the hostname, login and password for POP3 server.
wodPop3.Hostname = "your_pop3_hostname"
wodPop3.Login = "your_pop3_login"
wodPop3.Password = "your_pop3_password"
wodPop3.Blocking = True 'Use synchronous connections
'Then we connect to POP3 server.
wodPop3.Connect()
'Using GetAll all messages will be downloaded from server.
wodPop3.Messages.GetAll()
'We can disconnect from server now because messages are downloaded.
wodPop3.Disconnect()

Dim sortDate As Date
Dim i, j, k, minIndex As Integer
Dim collDate As Collection
Dim collDatePosition As Collection
Dim collOutput As New Collection
collDate = New Collection
collDatePosition = New Collection
collOutput = New Collection

'Put messages from Pop3Msgs collection in new collection.
For i = 0 To wodPop3.Messages.Count - 1
    collDate.Add(wodPop3.Messages(i).Date)
    collDatePosition.Add(i)
Next i

'Now we will sort messages by date.
Do
    sortDate = collDate.Item(1)
    minIndex = 1
    For j = 1 To collDate.Count
        If collDate(j) <= sortDate Then
            sortDate = collDate(j)
            minIndex = j
        End If
    Next j
    collOutput.Add(collDatePosition(minIndex))
    collDate.Remove(minIndex)
    collDatePosition.Remove(minIndex)
Loop Until collDate.Count = 0

'Finally we will print messages sorted by date from oldest to newest message.
For k = 1 To collOutput.Count
    Console.WriteLine("Date:   " + wodPop3.Messages(collOutput(k)).Date) 'Message date
    Console.WriteLine("From:   " & wodPop3.Messages(collOutput(k)).From) 'Sender of message
    Console.WriteLine("Subject: " & wodPop3.Messages(collOutput(k)).Subject) 'Message subject
Next k
C# code
WODPOP3COMLib.wodPop3Com wodPop3 = new WODPOP3COMLib.wodPop3Com();

//First we set up the hostname, login and password for POP3 server.
wodPop3.Hostname = "your_pop3_hostname";
wodPop3.Login = "your_pop3_login";
wodPop3.Password = "your_pop3_password";
wodPop3.Blocking = true; //Use synchronous connections
//Then we connect to POP3 server.
wodPop3.Connect();
//Using GetAll all messages will be downloaded from server.
wodPop3.Messages.GetAll();
//We can disconnect from server now becaouse messages are downloaded.
wodPop3.Disconnect();

DateTime sortDate;
short i;
short j;
short k;
short minIndex;
List<DateTime> collDate = new List<DateTime>();
List<short> collDatePosition = new List<short>();
List<short> collOutput = new List<short>();

//Put messages from Pop3Msgs collection in new collection.
for (i = 0; i <= wodPop3.Messages.Count - 1; i++)
{
    collDate.Add(wodPop3.Messages[i].Date);
    collDatePosition.Add(i);
}

//Now we will sort messages by date.
do
{
    sortDate = (System.DateTime)collDate[0];
    minIndex = 1;
    for (j = 0; j <= collDate.Count - 1; j++)
    {
        if (collDate[j] <= sortDate)
        {
            sortDate = (System.DateTime)collDate[j];
            minIndex = j;
        }
    }
    collOutput.Add(collDatePosition[minIndex]);
    collDate.Remove(sortDate);
    collDatePosition.Remove(minIndex);
} while (!(collDate.Count == 0));

//Finally we will print messages sorted by date from oldest to newest message.
for (k = 0; k <= collOutput.Count - 1; k++)
{	
    Console.WriteLine("Date:    " + wodPop3.Messages[(short)collOutput[k]].Date); //Message date
    Console.WriteLine("From:    " + wodPop3.Messages[(short)collOutput[k]].From); //Sender of message
    Console.WriteLine("Subject: " + wodPop3.Messages[(short)collOutput[k]].Subject); //Message subject
}