Copy or Move mails using IMAP and C#

Sep 13, 2010 at 7:08 AM

Hi,

         Iam using Koolwired.Imap opensource to read mail and from mail server.

Iam able to read,but after reading i want  to move mails from inbox to subfolders.

When iam trying to move mail , my application is getting hang(not responding).

Any help on this appreciated.

Below is the code iam using to move mails.

 

ImapConnect connection;

Imap.

ImapCommand command;

Imap.

ImapAuthenticate authenticate;

Imap.

ImapMailbox mailBox;

connection = GetImapConneection();

 

if (connection.State != Imap.ConnectionState.Connected)

 

return ;

command =

new Imap.ImapCommand(connection);

authenticate =

new Imap.ImapAuthenticate(connection, Properties.Settings.Default.MailUserName, Properties.Settings.Default.MailUserPwd);

authenticate.Login();

mailBox = command.Select(mailBoxFolder);

mailBox = command.Fetch(mailBox);

 

foreach (Imap.ImapMailboxMessage mailMessage in mailBox.Messages)

{

 

if (mailMessage.Subject == sourceMailSubject)

{

command.Copy(destFolder, mailMessage.ID, mailMessage.ID);

command.SetSeen(mailMessage.ID,

true);

 

 

 

 

 

 

Thanks & Regards

Ravi

 

}

}

authenticate.Logout();

connection.Close();

Imap.

Sep 1, 2011 at 1:07 PM
Edited Sep 1, 2011 at 1:14 PM

Copy command returns an OK response in case it's been successful: '<clientID> OK COPY completed' (as you can see in the debugger). Just add a regex or response.Contains("OK COPY completed") to IsResponseEnd method.