title: MailSystem.NET IMAP4, marking mail as unread
body: <p>Anyone familiar with MailSystem.NET?</p>
  
  <p>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.</p>
  
  <p>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. </p>
  
  <pre><code>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 "ABC"
                  //Do something else
  
                  //Mark the mail as unread
              }
          }
  
  
      }
  
  
  }
  </code></pre>