public JsonResult ArchiveMail(string[] messageIds, string folderName) { var successful = false; if (Request.IsAuthenticated) { using (var uow = new UnitOfWork(GlobalConfig.ConnectionString)) { var user = uow.UserRepository.GetUserByUsername(User.Identity.Name); if (DateTime.Compare(DateTime.Now, user.OAuthAccessTokenExpiration) < 0) { using ( var imap = new ImapClient("imap.gmail.com", user.EmailAddress, user.CurrentOAuthAccessToken, AuthMethods.SaslOAuth, 993, true, true)) { imap.SelectMailbox(folderName); foreach (var messageId in messageIds) { imap.MoveMessage(messageId, "[Gmail]/All Mail"); } imap.Expunge(); successful = true; } } } } return Json(new {Result = successful}); }
public JsonResult DeleteMail(string[] messageIds, string folderName) { var successful = false; if (Request.IsAuthenticated) { using (var uow = new UnitOfWork(GlobalConfig.ConnectionString)) { var user = uow.UserRepository.GetUserByUsername(User.Identity.Name); if (DateTime.Compare(DateTime.Now, user.OAuthAccessTokenExpiration) < 0) { using ( var imap = new ImapClient("imap.gmail.com", user.EmailAddress, user.CurrentOAuthAccessToken, AuthMethods.SaslOAuth, 993, true, true)) { imap.SelectMailbox(folderName); foreach (var messageId in messageIds) { try { imap.MoveMessage(messageId, "[Gmail]/Trash"); } // ReSharper disable once EmptyGeneralCatchClause catch (Exception) //Deleting always throws excptions { } finally { imap.Expunge(); } } successful = true; } } } } return Json(new {Result = successful}); }