public object InsertNew(object item) { try { MWMailItem mailItem = item as MWMailItem; Utils.Debug($"Inserting new record {mailItem.Subject}"); using (SQLiteConnection connection = new SQLiteConnection(Module.ConnectionString)) { connection.Open(); using (SQLiteCommand command = new SQLiteCommand(connection)) { command.CommandText = $@"INSERT INTO {TableName} ({Schema.GetColumnsFormated()}) VALUES ({Schema.GetParametersFormated()})"; command.Parameters.AddRange(Schema.GetParameters(mailItem).ToArray()); using (SQLiteTransaction transaction = connection.BeginTransaction()) { command.ExecuteNonQuery(); transaction.Commit(); return(mailItem); } } } } catch (Exception e) { Utils.Debug($"Error Inserting new item into {TableName} [InsertNew].\n{e.Message}"); throw new Exception($"Error Inserting new item into {TableName} [InsertNew].\n{e.Message}"); } }
public object Update(object item) { try { MWMailItem entry = item as MWMailItem; Utils.Debug($"Updating item - {entry.Subject}"); using (SQLiteConnection connection = new SQLiteConnection(Module.ConnectionString)) { connection.Open(); using (SQLiteCommand command = new SQLiteCommand(connection)) { command.CommandText = $@"INSERT OR REPLACE into {TableName} ({Schema.GetColumnsFormated()}) VALUES ({Schema.GetParametersFormated()})"; command.Parameters.AddRange(Schema.GetParameters(entry).ToArray()); using (SQLiteTransaction transaction = connection.BeginTransaction()) { command.ExecuteNonQuery(); transaction.Commit(); return(entry); } } } } catch (System.Exception e) { Utils.Debug($"Error updating entry in DB"); return(null); } }
public void RemoveFromWatchList(MWMailItem item) { if (WatchList.ContainsKey(item.EntryID)) { WatchList.Remove(item.EntryID); App?.PaneWPF?.RemoveItemFromView(item); } }
/// <summary> /// Adds an item to both current WatchList of the controller and also to WPF to make it visible to the user. /// </summary> /// <param name="item"></param> public void AddToWatchList(MWMailItem item) { if (!WatchList.ContainsKey(item.EntryID)) { WatchList.Add(item.EntryID, item); App?.PaneWPF?.AddItemToView(item); } }
private void User_BeforeItemMove(object Item, MAPIFolder MoveTo, ref bool Cancel) { MailItem mail = Item as MailItem; if (App.MWContoller != null && mail != null) { MWMailItem MWItem = new MWMailItem(mail); App.MWContoller.HandleOutgoingMail(MWItem); Debug.WriteLine($"Item moved {MWItem.Subject}"); } }
public override List <SQLiteParameter> GetParameters(object el) { MWMailItem item = el as MWMailItem; List <SQLiteParameter> result = new List <SQLiteParameter>(); for (int i = 0; i < Columns.Count; i++) { switch (Columns[i]) { case "mail_id": result.Add(new SQLiteParameter("mail_id", item.EntryID)); break; case "folder_id": result.Add(new SQLiteParameter("folder_id", item.FolderEntryID)); break; case "subject": result.Add(new SQLiteParameter("subject", item.Subject)); break; case "mail_from": result.Add(new SQLiteParameter("mail_from", item.From)); break; case "mail_to": result.Add(new SQLiteParameter("mail_to", item.To)); break; case "mail_cc": result.Add(new SQLiteParameter("mail_cc", item.CC)); break; case "received_date": result.Add(new SQLiteParameter("received_date", item.ReceivedDate.ToString(dateTimeFormat))); break; case "status": result.Add(new SQLiteParameter("status", item.status.ToString())); break; case "mail_user": result.Add(new SQLiteParameter("mail_user", item.mail_user)); break; case "body": result.Add(new SQLiteParameter("body", item.Body)); break; } } return(result); }
/// <summary> /// Handle outgoind mail. /// When a mail is sent, it shuld check the following on the mail that is being replied: /// = if item should be handled /// - check if item is our watchlist /// - if yes /// * update to processed /// * remove from watchlist and WPF /// - check if item is in db /// - yes: /// * update to processed /// - no: /// * Insert as processed /// </summary> /// <param name="oldMail">The mail that is being replied</param> public void HandleOutgoingMail(MWMailItem oldMail) { Utils.Debug("HandleOutgoing"); if (App.Rules.IsMailToBeHandled(oldMail) != MWIterfaces.MWAction.Exclude) { RemoveFromWatchList(oldMail); MWMailItem dbItem = App.DBModule?.MailTable?.SelectOne(oldMail.EntryID) as MWMailItem; if (dbItem != null) { dbItem.status = DBModule.ItemStatus.Processed; App.DBModule?.MailTable.Update(dbItem); } } }
private void Items_ItemAdd(object Item) { MailItem mail = Item as MailItem; if (mail != null && mail.ReceivedTime > DateTime.Now.AddHours(-100)) { Debug.WriteLine($"Received"); if (App.MWContoller != null) { MWMailItem MWItem = new MWMailItem(mail); App.MWContoller.HandleExistingMail(MWItem); } } }
/// <summary> /// The order of rules is IMPORTANT. /// First rule that is compliant is taken into account. The rest rules are then ignored. /// </summary> /// <param name="item">Mail to be checked.</param> /// <returns>The action to be executed on the mail</returns> public MWAction IsMailToBeHandled(MWMailItem item) { if (item.ReceivedDate < DateTime.Now.AddHours(-100)) { return(MWAction.Exclude); } foreach (IRule rule in this.Rules) { if (rule.IsMailCompliant(item)) { return(rule.action); } } // if nothing was found, exclude the mail return(MWAction.Exclude); }
/// <summary> /// When a new mail arrives, it will be passed to this funcion. /// It should do the following: /// = First check against the rules if the item should be handled /// - Check if item is already in the db /// - if yes /// * check it's status /// * if status = new /// # check if it is visible to the current user /// # if not visible show it (add to the observable collection) /// * if not new, ignore /// - if not in db, add it /// </summary> /// <param name="item"></param> public void HandleExistingMail(MWMailItem item) { Utils.Debug("HandleExistingMail"); if (App.Rules.IsMailToBeHandled(item) != MWIterfaces.MWAction.Exclude) { MWMailItem dbItem = App.DBModule?.MailTable?.SelectOne(item.EntryID) as MWMailItem; if (dbItem != null) { if (dbItem.status == DBModule.ItemStatus.New) { this.AddToWatchList(item); } } else { // add item to db App.DBModule.MailTable.InsertNew(item); this.AddToWatchList(item); } } }
public MWAction IsMailToBeHandled(MWMailItem item) { return(RealRulesTable.IsMailToBeHandled(item)); }
public void RemoveFromWatchList(MWMailItem item) { RealController.RemoveFromWatchList(item); }
public void HandleOutgoingMail(MWMailItem oldMail) { RealController.HandleOutgoingMail(oldMail); }
public void HandleExistingMail(MWMailItem item) { RealController.HandleExistingMail(item); }
public void AddToWatchList(MWMailItem item) { RealController.AddToWatchList(item); }
public bool IsMailCompliant(MWMailItem mail) { return(true); }