This project is read-only.

Help with implementing 'mark as unread' method into existing app

Oct 24, 2012 at 4:29 AM
Edited Oct 24, 2012 at 2:51 PM

Hi, I have an app which periodically checks a gmail account for new mail. If the subject title contains a specific phrase then an action is taken. However I need to modify the app a little to mark certain messages as unread.

Here is the existing code. A button click calls the logInLogOut() sub and starts a timer which takes care of the app periodically checking for new mail by calling the checkNewMail() sub in another thread. The app works as intended though the below may not be the best way of doing it. See comment:

//*****.......and mark the mail as unread
				

 

private void logInLogOut()
	{
		try
		{
			Client.ConnectSsl(txtIMAPServer.Text, int.Parse(txtIMAPPort.Text));
			Client.Login(@txtUserName.Text, txtPassword.Text); 
			globalClientConnected = true;

		}
		catch (Exception ex)
		{
			globalClientConnected = false;
			
		}
	}    
	
	
private void checkNewMail()
	{
		if (globalClientConnected)
		{
			foreach (ActiveUp.Net.Mail.Message email in GetUnreadMails("Inbox"))
			{
				string from = parseEmailAddress(email.From.ToString());
				string subject = email.Subject;
				string receivedDateTime = email.ReceivedDate.Date.ToString()

				string updateString = receivedDateTime + ", " + from + ", " + subject + "\r\n";
			   
				if (subject.Contains("ABC"))
				{
					string to = from;
					
					try
					{              
						//do something
					}
					catch (Exception ex)
					{
						/bla bla
					}
				}
				else
				{
					//If mail subject not like "XYZ"
					//Do something else
					
					//*****.......and mark the mail as unread
				}
			}

			
		}

		
	}

Thanks