From 73dee0e8d156fca6eee4b06edeab43a366144f46 Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Thu, 4 Jul 2019 18:17:34 +0000 Subject: [PATCH] --- Controllers/MailController.cs | 49 ++++++++++++++++++++- util/RfMail.cs | 45 +++++++++++++++++++ wwwroot/js/app.mailEdit.js | 81 +++++++++++++++++++++++++++++++++++ 3 files changed, 173 insertions(+), 2 deletions(-) diff --git a/Controllers/MailController.cs b/Controllers/MailController.cs index e5ca2c8..64abedb 100644 --- a/Controllers/MailController.cs +++ b/Controllers/MailController.cs @@ -69,10 +69,10 @@ namespace rockfishCore.Controllers } - [HttpPost("isspam/{account}/{id}")] + [HttpPost("isspam/{account}/{id}")] public JsonResult IsSpam([FromRoute] string account, [FromRoute] uint id) { - + RfMail.rfMailAccount acct = RfMail.rfMailAccount.support; if (account.Contains("sales")) { @@ -89,6 +89,51 @@ namespace rockfishCore.Controllers return Json(new { msg = ex.Message, error = 1 }); } } + + + [HttpPost("movetosub/{account}/{id}")] + public JsonResult MoveToSub([FromRoute] string account, [FromRoute] uint id) + { + + RfMail.rfMailAccount acct = RfMail.rfMailAccount.support; + if (account.Contains("sales")) + { + acct = RfMail.rfMailAccount.sales; + } + + try + { + RfMail.MoveAndMarkRead(id, acct, true); + return Json(new { msg = "message processed as spam", ok = 1 }); + } + catch (Exception ex) + { + return Json(new { msg = ex.Message, error = 1 }); + } + } + + [HttpPost("movetonotsub/{account}/{id}")] + public JsonResult MoveToNotSub([FromRoute] string account, [FromRoute] uint id) + { + + RfMail.rfMailAccount acct = RfMail.rfMailAccount.support; + if (account.Contains("sales")) + { + acct = RfMail.rfMailAccount.sales; + } + + try + { + RfMail.MoveAndMarkRead(id, acct, false); + return Json(new { msg = "message processed as spam", ok = 1 }); + } + catch (Exception ex) + { + return Json(new { msg = ex.Message, error = 1 }); + } + } + + // //------------------------------------------------------ public class dtoReplyMessageItem diff --git a/util/RfMail.cs b/util/RfMail.cs index 1d20504..384dc12 100644 --- a/util/RfMail.cs +++ b/util/RfMail.cs @@ -200,6 +200,51 @@ namespace rockfishCore.Util #endregion + #region handle read and move message + + + + /// + /// Move to sub or unsub mail folder and mark as read + /// + /// + /// + public static void MoveAndMarkRead(uint moveMessageId, rfMailAccount replyFromAccount, bool toSubscribed) + { + using (var client = new ImapClient()) + { + // Accept all SSL certificates + client.ServerCertificateValidationCallback = (s, c, h, e) => true; + client.Connect(MAIL_IMAP_ADDRESS, MAIL_IMAP_PORT); + // Note: since we don't have an OAuth2 token, disable + // the XOAUTH2 authentication mechanism. + client.AuthenticationMechanisms.Remove("XOAUTH2"); + if (replyFromAccount == rfMailAccount.support) + { + client.Authenticate(MAIL_ACCOUNT_SUPPORT, MAIL_ACCOUNT_PASSWORD_SUPPORT); + } + else + { + client.Authenticate(MAIL_ACCOUNT_SALES, MAIL_ACCOUNT_PASSWORD_SALES); + } + +//AyaNovaReceivedNOTSUB +//AyaNovaReceivedSubscribed + + var newFolder = client.GetFolder(toSubscribed?"AyaNovaReceivedSubscribed":"AyaNovaReceivedNOTSUB"); + + if (newFolder != null) + { + client.Inbox.Open(FolderAccess.ReadWrite); + client.Inbox.MoveTo(new UniqueId(moveMessageId), newFolder); + } + + + client.Disconnect(true); + } + }//spaminator + + #endregion diff --git a/wwwroot/js/app.mailEdit.js b/wwwroot/js/app.mailEdit.js index 5796dc4..e340d6b 100644 --- a/wwwroot/js/app.mailEdit.js +++ b/wwwroot/js/app.mailEdit.js @@ -101,6 +101,80 @@ app.mailEdit = (function() { return false; }; + + + /////////////////////////////////// + // MOVE TO SUB HANDLER + // + onMoveToSub = function(event) { + event.preventDefault(); + + $.gevent.publish("app-clear-error"); + + //is this a new record? + if (stateMap.id == "new") { + alert("New message MOVE handling makes no sense - figure it out!"); + return false; + } + + app.api.create( + "mail/movetosub/" + + stateMap.context.params.mail_account + + "/" + + stateMap.context.params.mail_id, + null, + function(res) { + if (res.error) { + $.gevent.publish("app-show-error", res.msg); + } else { + page("#!/inbox"); + } + } + ); + + return false; + }; + + + /////////////////////////////////// + // MOVE TO SUB HANDLER + // + onMoveToNotSub = function(event) { + event.preventDefault(); + + $.gevent.publish("app-clear-error"); + + //is this a new record? + if (stateMap.id == "new") { + alert("New message MOVE handling makes no sense - figure it out!"); + return false; + } + + + app.api.create( + "mail/movetonotsub/" + + stateMap.context.params.mail_account + + "/" + + stateMap.context.params.mail_id, + null, + function(res) { + if (res.error) { + $.gevent.publish("app-show-error", res.msg); + } else { + page("#!/inbox"); + } + } + ); + + return false; + }; + + + //new move routes: + //movetosub + //movetonotsub + + //-------------------- END EVENT HANDLERS -------------------- //------------------- BEGIN PUBLIC METHODS ------------------- @@ -167,6 +241,13 @@ app.mailEdit = (function() { //Context menu app.nav.contextAddButton("btn-generate", "IsSpam", "axe", onSpam); + app.nav.contextAddButton("btn-generate", "IsSpam", "axe", onSpam); + + //Move to subscribed or not subscribed + + //id, title, icon, clickhandler + + } else { //NEW email options var $group = $("#sendToGroup");