VS.NET 2010 (and above) Users Click Here   

HOMECONTACT PRODUCTS DOWNLOADS PURCHASE TESTIMONIALS FORUMS COMPANY CONTACT
Home
Products
Downloads
Purchase
Licensing
Licensing FAQ
Software Updates
Support Forums
Testimonials
Feature Requests
Guarantee
About Us
Contact Us
Hosting Companies
Privacy Policy
   
Shopping Cart


Feature Requests forum



[ Reply to Post ] [ Back To Forum ]
From: "dave wanta" <dave@...>
Date: 4/10/2013 12:04:04 PM
Subject: RE: Way to periodically query for new messages
Hi Mike,
Sure:

ManualResetEvent idleWatcher = new ManualResetEvent(false);
void IMAPIdleTest()
{
	IMAP4 imap = new IMAP4( true, false);

	//create and load the ssl socket
	AdvancedIntellect.Ssl.SslSocket ssl = new AdvancedIntellect.Ssl.SslSocket();
	imap.LoadSslSocket( ssl );


	//rest of the IMAP properties
	imap.Port = 993;
	imap.Connect();
	imap.Login();


	MailFolderCollection mfc = imap.FolderList();

	//get the message count
	MailFolder inbox = imap.SelectInbox();

	//wire up the idle event
	inbox.IdleResponse += new IdleResponseEventHandler( OnIdleResponse );

	Console.WriteLine("starting to idle...");

	inbox.Idle();
	
	while( idleWatcher.WaitOne() )
	{
		//our idleWatcher notified us of new messages.
		break;
	}
	


	inbox.IdleStop();

	//get the latest messges that just came in
	string recentSet = inbox.SearchClient.RecentSet();

	if( ( recentSet != null ) && ( recentSet.Trim().Length > 0 ) )
	{
		//download the latest
		MimePartCollection messages = inbox.FetchClient.Messages( recentSet,IndexType.UniqueId, true );

		//loop through the messages, and write out the subject
		foreach( MimeMessage message in messages)
		{
			if( message != null )
			{
				if( message.Subject != null )
				{
					Console.WriteLine( message.Subject.Value );
				}
				else
				{
					Console.WriteLine( "No subject");
				}
			}
		}

	}

	imap.Disconnect();

}
void OnIdleResponse( object sender, IdleResponseEventArgs e )
{
	//write out the response sent from the server
	string response = System.Text.Encoding.ASCII.GetString( e.Data, 0, e.DataCount );
	Console.WriteLine( response );

	//in here, we could open a new IMAP connection to download the latets messages
	//IMAP4 imap = new IMAP4();
	//iimap....

	//or we could notify the waiting thread, that we received and update, and the waiting thread, could continue processing.
	//One way of doing this, is by using a ManualResetEvent
	idleWatcher.Set();
}




Does that help?
--Dave

 

 

 



Thread View

Subject By Date
Way to periodically query for new messages Mike Schelstrate 4/9/2013
   RE: Way to periodically query for new messages dave wanta 4/10/2013
     RE: Way to periodically query for new messages Mike Schelstrate 4/10/2013
       RE: Way to periodically query for new messages [ you are here ] dave wanta 4/10/2013
         RE: Way to periodically query for new messages Mike Schelstrate 4/11/2013
           RE: Way to periodically query for new messages dave wanta 4/11/2013

 

 

Testimonial

Great tool, Dave. I cannot tell you how much work this has saved me. "

Paul | Assisted Solutions

Read more testimonials
ListNanny aspNetDNS aspNetEmail aspNetPOP3 aspNetMX IPMuncher aspNetMIME aspNetPING aspNetTraceRoute aspNetIMAP aspNetMHT