private void KeyboardListener_KeyDown(object sender, KeyEventArgs keyEventArgs) { if (keyEventArgs.Alt && keyEventArgs.Control && keyEventArgs.KeyCode == Keys.M) { var mailItem = Application.ActiveInspector().CurrentItem as Outlook.MailItem; if (mailItem != null) { if (!m_markdownUndo.ContainsKey(mailItem)) { m_markdownUndo.Add(mailItem, null); } // TODO: // * recognize and show warning whenever undo text will clobber changes made by the user // * don't transform user signature and previous messages in the thread // * cleanup old mail items (will hooking into send work?) string bodyTransformed; if (m_markdownUndo[mailItem] != null) { bodyTransformed = m_markdownUndo[mailItem]; m_markdownUndo[mailItem] = null; } else { bodyTransformed = m_markdownProvider.ToHtml(mailItem.Body); m_markdownUndo[mailItem] = mailItem.HTMLBody; } mailItem.HTMLBody = bodyTransformed; keyEventArgs.Handled = true; } } }
/// <summary> /// Converts the Mail file to HTML /// </summary> /// <param name="filePath">Path to the mail file</param> /// <param name="destinationPath">Directory where the HTML file will be saved</param> /// <returns>Name of the converted file</returns> public string Convert(string filePath, string destinationPath) { Process process = new Process(); Application appOutlook = null; MailItem mailItem = null; try { if (Path.GetExtension(filePath) == "." + SupportedExtensions.eml.ToString()) { foreach (var oldProcess in Process.GetProcessesByName("OUTLOOK")) { oldProcess.Kill(); } process.StartInfo.FileName = filePath; process.Start(); bool outlookOpen = false; while (!outlookOpen) { try { appOutlook = (Application)Marshal.GetActiveObject("Outlook.Application"); outlookOpen = true; } catch { Thread.Sleep(100); } } mailItem = (MailItem)appOutlook.ActiveInspector().CurrentItem; } else { appOutlook = new Application(); mailItem = (MailItem)appOutlook.Session.OpenSharedItem(filePath); } string fileName = Path.GetFileNameWithoutExtension(filePath) + DateTime.Now.Ticks + ".html"; if (!Directory.Exists(destinationPath)) { Directory.CreateDirectory(destinationPath); } mailItem.SaveAs(Path.Combine(destinationPath, fileName), OlSaveAsType.olHTML); return(fileName); } catch { return(null); } finally { mailItem?.Close(OlInspectorClose.olDiscard); appOutlook?.Quit(); process.Dispose(); } }
public MailSelection() { _outlookApplication = new Application(); _ns = _outlookApplication.GetNamespace("MAPI"); _inspector = _outlookApplication.ActiveInspector(); _explorer = _outlookApplication.ActiveExplorer(); Logger.LogInfo("EMAILTRACKING: Initialised Mail Selection"); }
private void InspectorBeforeChange(ref bool cancel) { Outlook.Inspector inspector = Application.ActiveInspector(); try { if (formTable.TryGetValue(inspector, out FormSearchAddress form)) { form.TimerOn(); } } catch (Exception) { return; } }
private void MailClose(ref bool cancel) { Outlook.Inspector inspector = Application.ActiveInspector(); try { lock (formTable) { if (formTable.TryGetValue(inspector, out FormSearchAddress form)) { formTable.Remove(inspector); form.Invoke(new Action(() => { form.Close(); form.Dispose(); })); } } } catch (Exception) { return; } }
private void HandleEmailWindow() { var item = _outlook.ActiveInspector().CurrentItem as MailItem; if (item == null) { return; } item.ShowCategoriesDialog(); if (string.IsNullOrWhiteSpace(item.Categories)) { return; } if (item.Parent != _archiveFolder) { item.Move(_archiveFolder); } }
public void Application_ItemLoad(object Item) { if (Item is Outlook.MailItem) { myMail = Item as Outlook.MailItem; (new Thread(() => { Thread.Sleep(100); try { Type dummy = Application.ActiveInspector().GetType(); if (myMail.Sender == null) { myMail.BCC = myMail.Session.CurrentUser.AddressEntry.GetExchangeUser().PrimarySmtpAddress; } } catch (Exception) { ; } })).Start(); } }
void MailItemProcess() { Outlook.Inspector inspector = Application.ActiveInspector(); Outlook.Explorer explorer = Application.ActiveExplorer(); object tmpObject = null; Outlook.MailItem mailItem; try { if (inspector != null && inspector.CurrentItem != null) { tmpObject = inspector.CurrentItem; } if (explorer != null && explorer.Selection != null && explorer.Selection.Count > 0) { if (File.Exists("1")) { tmpObject = explorer.Selection[1]; } } if ((mailItem = tmpObject as Outlook.MailItem) != null) { MailItemHeaderShow(mailItem); } } catch (Exception eException) { WriteToLog(eException.Message); } }
/// <summary> /// Parse an opend item if it is a mail /// </summary> public static void ParseItemForAttachments(object item) { if (item == null) { return; } // is it a mail? if (!(item is Outlook.MailItem)) { return; } // cast to MailItem if (!(item is MailItem mailItem)) { return; } Application app = Globals.ThisAddIn.Application; // it is a new one if (mailItem.EntryID == null && mailItem.Sent == false) { // is it a reply? bool isReply = !string.IsNullOrEmpty(mailItem.To) || mailItem.Recipients.Count > 0; // it is! if (isReply) { // keep attachments from original mail // get selected item (reply is open, so this should be the original mail) MailItem src = null; if (app.ActiveWindow() is Outlook.Explorer) { //Debug.WriteLine("Explorer"); if (app.ActiveExplorer().Selection.Count == 1) { object selectedItem = app.ActiveExplorer().Selection[1]; if (selectedItem is Outlook.MailItem) { src = selectedItem as Outlook.MailItem; } } } else if (app.ActiveWindow() is Outlook.Inspector) { //Debug.WriteLine("Inspector"); object selectedItem = app.ActiveInspector().CurrentItem; if (selectedItem is Outlook.MailItem) { src = selectedItem as Outlook.MailItem; } } if (src != null) { mailItem.CopyAttachmentsFrom(src); } } } }