private void RibbonReadMailMessage_Load(object sender, RibbonUIEventArgs e) { try { bool shouldShowWorkshareTab = false; using (var inspector = new WsInspector((Inspector) Context)) { var mailItem = inspector.CurrentItem as WsMailItem; if (mailItem != null) { for (int i = 1; i <= mailItem.Attachments.Count; i++) { if (mailItem.Attachments[i].DisplayName == "Picture (Device Independent Bitmap)") continue; if (Utils.IsInterestingFileType(mailItem.Attachments[i].FileName)) { shouldShowWorkshareTab = true; break; } } } } tabWorkshare.Visible = shouldShowWorkshareTab; } catch (Exception ex) { Logger.LogError(ex); } }
private void OnNewInspector(Inspector Inspector) { var wsInspector = new WsInspector(Inspector); wsInspector.Activated += id => Activated(id); _wsInspectors.Add(wsInspector); if (NewInspector != null) NewInspector(wsInspector); }
public InspectorHook(WsInspector inspector) { _inspector = inspector; _inspector.InspectorClosing += OnInspectorClosing; _inspector.Activated += OnActivated; _inspector.Deactivate += OnDeactivate; _inspectorHandle = GetInspectorHandle(_inspector); _mailItem = inspector.CurrentItem as WsMailItem; if (_mailItem != null) _mailItem.BeforeCheckNames += OnBeforeCheckNames; }
public Inspector ActiveInspector() { // This is a bug you can have multiple inspector windows open if (_activeInspector == null) { var inspector = _application.ActiveInspector(); if (inspector != null) { _activeInspector = new WsInspector(inspector); _activeInspector.Closed += ActiveInspectorClosed; } } return _activeInspector; }
private void menuAttachments_ItemsLoading(object sender, RibbonControlEventArgs e) { try { if (!tabWorkshare.Visible) return; if (menuAttachments != null && menuAttachments.Items != null) menuAttachments.Items.Clear(); using (var inspector = new WsInspector((Inspector) Context)) { var mailItem = inspector.CurrentItem as WsMailItem; if (mailItem != null) { for (int i = 1; i <= mailItem.Attachments.Count; i++) { if (mailItem.Attachments[i].DisplayName == "Picture (Device Independent Bitmap)") continue; bool embeddedFile = Utils.IsEmbeddedFile(mailItem.Attachments[i]); string label = embeddedFile ? "Invalid Attachment Format" : mailItem.Attachments[i].DisplayName; if (Utils.IsInterestingFileType(label) || embeddedFile) { RibbonButton button = Factory.CreateRibbonButton(); button.Label = mailItem.Attachments[i].DisplayName; button.Enabled = true; button.Visible = true; button.ShowLabel = true; button.Image = ShellIcon.GetSmallIcon(mailItem.Attachments[i].FileName).ToBitmap(); button.Tag = i; button.Click += OnCompareButtonClicked; menuAttachments.Items.Add(button); } } } } } catch (Exception ex) { Logger.LogError(ex); } }
public RibbonButton GetProtectFilesButton(WsInspector inspector) { if (inspector == null) return null; RibbonButton ribbonButton = null; var ribbonCollection = Globals.Ribbons[inspector.UnSafeInspector]; if (ribbonCollection != null) { var ribbonNewMessage = ribbonCollection.RibbonNewMessage; if (ribbonNewMessage != null) { ribbonButton = ribbonNewMessage.btnProtectFiles; } } return ribbonButton; }
public void OnSendAndProtectClicked(object sender, RibbonControlEventArgs e) { var analyticsListener = new WsAnalyticsListener(); analyticsListener.SendEventStatistic("Send and protect clicked"); try { using (var inspector = new WsInspector((Inspector) e.Control.Context)) { var mailItem = inspector.CurrentItem as WsMailItem; if (mailItem != null) { _model.AddSendAndProtectMapiProperty(mailItem); // This is a port from the C++ code this will not work in all situations ie: Multilingual Keyboard // //SendKeys.Send("%(S)"); mailItem.Send(); } } } catch (Exception ex) { if (ex.Message.Contains("E_ABORT")) return; Logger.LogError(ex); var comEx = ex as COMException; if (comEx != null && comEx.ErrorCode == E_ABORT) { return; } WsMessage.ShowMessage(IntPtr.Zero, ex.Message, MessageButtons.WsOK, MessageBranding.WsProtect); } }
public void AddProtectTaskPanes(WsInspector inspector, bool hookSendButton = true, bool visible = false) { try { var hook = new InspectorHook(inspector); WaitForItemSend(hook); _customTaskPanes = Globals.ThisAddin.GetCustomTaskPaneCollection(); var alertBar = AddAlertTaskPane(_customTaskPanes, inspector); var ctp = new ProtectTaskPane(inspector, (AlertBarControl)alertBar.Control, OnStatusUpdate) { Dock = DockStyle .Fill }; ctp.InspectorHook = hook; CustomTaskPane taskPane = _customTaskPanes.Add(ctp, "Workshare Protect", inspector.UnSafeInspector); taskPane.Visible = visible; taskPane.Width = Utils.AdjustDimensionWithDpiHook(350); taskPane.VisibleChanged += TaskPaneVisibleChanged; taskPane.DockPositionChanged += OnDockPositionChanged; taskPane.DockPosition = (MsoCTPDockPosition)OptionApi.GetInt("InteractiveProtectDockPosition"); if (_protectTaskPanes.TryAdd(inspector.Id, taskPane) && hookSendButton) { hook.ActionQueueController = ctp.Presenter.ActionQueueController; ctp.InitializeMailItemWithAttachments(); } } catch (Exception e) { Logger.LogError(e); throw; } }
public void AddProtectTaskPanes(WsInspector inspector) { _wrapper.AddProtectTaskPanes(inspector); }
private bool IsMailItemSent(WsInspector inspector) { try { Thread.Sleep(1000); if (!_protectTaskPanes.ContainsKey(inspector.Id)) { return true; } const string PR_SENTMAIL_ENTRYID = "http://schemas.microsoft.com/mapi/proptag/0x0E0A0102"; inspector.CurrentItem.PropertyAccessor.GetProperty(PR_SENTMAIL_ENTRYID); return true; } catch (Exception) { return false; } }
private void ActiveInspectorClosed(Guid id) { if (_activeInspector != null) { _activeInspector.Dispose(); _activeInspector = null; } }
protected override void Dispose(bool disposing) { if (_item != null) { ((MailItem) (_item)).BeforeAttachmentRead -= OnBeforeAttachmentRead; ((MailItem) _item).AttachmentAdd -= OnAttachmentAdd; ((MailItem) _item).AttachmentRemove -= OnAttachmentRemove; ((MailItem) _item).BeforeCheckNames -= OnBeforeCheckNames; } if (_recipients != null) { _recipients.Dispose(); _recipients = null; } if (_wsAttachments != null) { _wsAttachments.Dispose(); _wsAttachments = null; } if (_wsInspector != null) { _wsInspector.Dispose(); _wsInspector = null; } if (_wsAccount != null) { _wsAccount.Dispose(); _wsAccount = null; } if (_wsApplication != null) { _wsApplication.Dispose(); _wsApplication = null; } if (_wsUserProperties != null) { _wsUserProperties.Dispose(); _wsUserProperties = null; } if (_wsPropertyAccessor != null) { _wsPropertyAccessor.Dispose(); _wsPropertyAccessor = null; } if (_wsSession != null) { _wsSession.Dispose(); _wsSession = null; } base.Dispose(disposing); }
void _wsInspectors_Activated(Guid id) { foreach (WsInspector inspector in _wsInspectors) { if (inspector.Id == id) { _activeInspector = inspector; break; } } }
private void OnCompareButtonClicked(object sender, RibbonControlEventArgs e) { try { var index = (int) (((RibbonButton) sender).Tag); using (var inspector = new WsInspector((Inspector) Context)) { var mailItem = inspector.CurrentItem as WsMailItem; if (mailItem != null) { Attachment attachment = mailItem.Attachments[index]; string temppath = Path.GetTempPath(); temppath = Path.Combine(temppath, "Workshare"); temppath = Path.Combine(temppath, "wmtemp" + Process.GetCurrentProcess().Id); if (!Directory.Exists(temppath)) { Directory.CreateDirectory(temppath); } string filepath = string.Empty; if (Utils.IsEmbeddedFile(attachment)) { filepath = Path.Combine(temppath, "Invalid Attachment Format"); } else { filepath = Path.Combine(temppath, attachment.DisplayName); } // VE2556: Attachments saved from Filesite are saved as read only. Set file to normal prior to overwriting them. if (File.Exists(filepath)) { File.SetAttributes(filepath, FileAttributes.Normal); } attachment.SaveAsFile(filepath); Utils.Launch(filepath); } } } catch (Exception ex) { Logger.LogError(ex); } }
private CustomTaskPane AddAlertTaskPane(CustomTaskPaneCollection customTaskPanes, WsInspector inspector) { if (_alertTaskPanes.ContainsKey(inspector.Id)) return _alertTaskPanes[inspector.Id]; var alertUserControl = new AlertBarControl(inspector) { Visible = true }; alertUserControl.ShowAlertBar += OnShowAlertBar; alertUserControl.AlertBarClicked += OnAlertBarClicked; var alertTaskPane = customTaskPanes.Add(alertUserControl, " ", inspector.UnSafeInspector); alertUserControl.TaskPane = alertTaskPane; alertTaskPane.DockPosition = MsoCTPDockPosition.msoCTPDockPositionTop; alertTaskPane.Height = Utils.AdjustDimensionWithDpiHook(55); alertTaskPane.Visible = false; _alertTaskPanes.TryAdd(inspector.Id, alertTaskPane); return alertTaskPane; }
public void OnAddLargeAttachmentClicked(object sender, RibbonControlEventArgs e) { var analyticsListener = new WsAnalyticsListener(); analyticsListener.SendEventStatistic("Add Large Attachment clicked"); try { using (var inspector = new WsInspector((Inspector) e.Control.Context)) { WsMailItem mailItem = inspector.CurrentItem; var ofd = new OpenFileDialog(); ofd.CheckFileExists = true; ofd.CheckPathExists = true; ofd.Multiselect = false; ofd.Title = "Select Attachment"; DialogResult dr = ofd.ShowDialog(new WindowWrapper(Process.GetCurrentProcess().MainWindowHandle)); if (dr == DialogResult.OK) { _model.AddAttachment(mailItem, ofd.FileName); analyticsListener.SendEventStatistic("Add Large Attachment Dialog-OK"); } else { analyticsListener.SendEventStatistic("Add Large Attachment Dialog-Cancel"); } } } catch (Exception ex) { Logger.LogError(ex); WsMessage.ShowMessage(IntPtr.Zero, ex.Message, MessageButtons.WsOK, MessageBranding.WsProtect); } }
void RefreshView(WsInspector inspector) { var ctp = GetProtectTaskPane(inspector.Id); if (ctp != null) { var protectTaskPane = ctp.Control as ProtectTaskPane; if (protectTaskPane != null) { protectTaskPane.UpdateLastDiscovery(); } } }
private IntPtr GetInspectorHandle(WsInspector inspector) { Guid oleInterface = new Guid("00000114-0000-0000-C000-000000000046"); IntPtr handle = IntPtr.Zero; IntPtr punk = Marshal.GetIUnknownForObject(inspector.UnSafeInspector); IntPtr inspectorInterface; Marshal.QueryInterface(punk, ref oleInterface, out inspectorInterface); try { var window = (IOleWindow)Marshal.GetTypedObjectForIUnknown(inspectorInterface, typeof(IOleWindow)); if (window != null) { window.GetWindow(out handle); } } catch (COMException ex) { Logger.LogError(ex); } finally { Marshal.Release(inspectorInterface); } return handle; }