0
1

Hi,

I want to sort the my messages by date. SO the newest email must show at the top. How can I do this? I am using the following code.

Pop3 client = new Pop3(); client.Connect("pop.gmail.com",995,null, Pop3Security.Implicit);

        client.Login("xxx", "xxx");

        Pop3MessageCollection messages = 
          client.GetMessageList(Pop3ListFields.FullHeaders);

        // display info about each message   
        Console.WriteLine("UID | From | To | Subject");
        foreach (Pop3MessageInfo message in messages)
        {
            Console.WriteLine(
               message.UniqueId.ToString() + "|" + 
               message.From.ToString() + "|" + 
               message.To.ToString() + "|" + 
               message.Subject.ToString());
        }

        client.Disconnect();

asked 30 Jul '10, 12:37

Oguz's gravatar image

Oguz
16
accept rate: 0%

edited 07 Dec '10, 21:10

Rebex%20KB's gravatar image

Rebex KB ♦♦
256312


Hi,

if you are using .NET 3.5 or later you can do it by using LINQ extension method OrderBy() or OrderByDescending(), so your code will now like this:

Pop3MessageCollection messages = 
  client.GetMessageList(Pop3ListFields.FullHeaders);    

IEnumerable<Pop3MessageInfo> orderedAsc = 
   messages.OrderBy(m => m.Date.UniversalTime);

// display info about each message   
Console.WriteLine("UID | From | To | Subject");

foreach (Pop3MessageInfo message in orderedAsc)
{
     Console.WriteLine(
        message.UniqueId.ToString() + "|" + 
        message.From.ToString() + "|" +      
        message.To.ToString() + "|" + 
        message.Subject.ToString());
}
link

answered 30 Jul '10, 14:43

Ivan%20Prochazka's gravatar image

Ivan Prochazka ♦♦
261
accept rate: 0%

edited 07 Dec '10, 21:11

Rebex%20KB's gravatar image

Rebex KB ♦♦
256312

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×33
×1

Asked: 30 Jul '10, 12:37

Seen: 483 times

Last updated: 07 Dec '10, 21:11