Пример #1
0
        public void OnCategoriesAction(Office.IRibbonControl control)
        {
            Outlook.Inspector inspector = null;
            if (ControlIsInInspector(control, ref inspector) == true)
            {
                Outlook.MailItem mailItem = inspector.CurrentItem as Outlook.MailItem;
                if (mailItem != null)
                {
                    mailItem.Categories = "";
                    mailItem.Categories = control.Tag;
                    mailItem.Save();
                }
                return;
            }

            Outlook.Explorer explorer = null;
            if (ControlIsInExplorer(control, ref explorer) == true)
            {
                Outlook.Selection selection = explorer.Selection;
                foreach (var selected in selection)
                {
                    Outlook.MailItem mailItem = selected as Outlook.MailItem;
                    if (mailItem != null)
                    {
                        mailItem.Categories = "";
                        mailItem.Categories = control.Tag;
                        mailItem.Save();
                    }
                }
                return;
            }
        }
Пример #2
0
        /// <summary>Handles the onAction event of the OpenMessage button.
        /// </summary>
        /// <param name="control">The source control of the event.</param>
        public void OpenMessage(Office.IRibbonControl control)
        {
            if (!string.IsNullOrWhiteSpace(currentSearchText))
            {
                // Obtain a reference to selection.
                Outlook.Selection selection = ActiveExplorer.Selection;
                if (selection.Count == 0)
                {
                    return;
                }

                // Open the first item that is a supported Outlook item.
                // The selection may contain various item types.
                IEnumerator e = ActiveExplorer.Selection.GetEnumerator();
                while (e.MoveNext())
                {
                    if (e.Current is Outlook.MailItem)
                    {
                        Outlook.MailItem item = e.Current as Outlook.MailItem;
                        item.Display();
                        FindInInspector(item.GetInspector, currentSearchText);
                        break;
                    }
                    else if (e.Current is Outlook.MeetingItem)
                    {
                        Outlook.MeetingItem item =
                            e.Current as Outlook.MeetingItem;
                        item.Display();
                        FindInInspector(item.GetInspector, currentSearchText);
                        break;
                    }
                }
            }
        }
Пример #3
0
    private void DecryptButton_Click(Office.CommandBarButton Ctrl, ref bool CancelDefault)
    {
      // Get the selected item in Outlook and determine its type.
      Outlook.Selection outlookSelection = Application.ActiveExplorer().Selection;
      if (outlookSelection.Count <= 0)
        return;

      object selectedItem = outlookSelection[1];
      Outlook.MailItem mailItem = selectedItem as Outlook.MailItem;

      if (mailItem == null)
      {
        MessageBox.Show(
            "OutlookGnuPG can only decrypt mails.",
            "Invalid Item Type",
            MessageBoxButtons.OK,
            MessageBoxIcon.Error);

        return;
      }

      // Force open of mailItem with auto decrypt.
      _autoDecrypt = true;
      mailItem.Display(true);
//      DecryptEmail(mailItem);
    }
Пример #4
0
        private void ExplorerSelectionChange()
        {
            _activeExplorer = Application.ActiveExplorer();
            if (_activeExplorer == null)
            {
                return;
            }
            Outlook.Selection selection = _activeExplorer.Selection;

            if (_ribbon != null)
            {
                if (selection != null && selection.Count == 1 && selection[1] is Outlook.MailItem)
                {
                    // one Mail object is selected
                    Outlook.MailItem selectedMail = selection[1] as Outlook.MailItem; // (collection is 1-indexed)
                                                                                      // tell the ribbon what our currently selected email is by setting this custom property, and run code against it
                    _ribbon.CurrentEmail = selectedMail;
                }
                else
                {
                    _ribbon.CurrentEmail = null;
                }

                _ribbon.SetRibbonButtonStatus(_ribbon.CurrentEmail != null);
            }
        }
Пример #5
0
        private void Initialize(object sender, EventArgs e)
        {
            //Debug.WriteLine("Initialize {0:T}", DateTime.Now);
            SetUIWorking();
            if (DataAPI.Ready())
            {
                //Debug.WriteLine("Ready {0:T}", DateTime.Now);
                _timerForm.timerCalRibbon.Stop();
                //initial mail or appt item
                Outlook.Selection explSelection = Globals.ThisAddIn.Application.ActiveExplorer().Selection;
                if (explSelection != null && explSelection.Count > 0)
                {
                    if (explSelection[1] is Outlook.MailItem)
                    {
                        SetMailItem(explSelection[1] as Outlook.MailItem);
                    }
                    else if (explSelection[1] is Outlook.AppointmentItem)
                    {
                        SetApptItem(explSelection[1] as Outlook.AppointmentItem);
                    }
                }
                explSelection = null;

                if (DataAPI.Online)
                {
                    lblStatus.Label = Globals.ThisAddIn.SyncStatus;
                }
                else
                {
                    lblStatus.Label = "";
                }
            }
            SetUI();
        }
Пример #6
0
        public void FillMailList()
        {
            if (olApplication.ActiveExplorer().Selection.Count > 0)
            {
                Outlook.Selection mySelection = olApplication.ActiveExplorer().Selection;
                Outlook.MailItem  mailitem    = null;

                foreach (Object obj in mySelection)
                {
                    if (obj is Outlook.MailItem)
                    {
                        mailitem = (Outlook.MailItem)obj;
                        selection.Add(mailitem);
                        var item = new ListViewItem(new string[] {
                            String.Format("{0:yyyy-MM-dd HH:mm:ss}", mailitem.ReceivedTime),
                            mailitem.Subject,
                            "-"
                        })
                        {
                            Name = mailitem.EntryID
                        };
                        listView1.Items.Add(item);
                        this.l_mailsInSelection.Text = selection.Count.ToString();
                    }
                }
            }
        }
Пример #7
0
 // Only show MyTab when Explorer Selection is
 // a received mail or when Inspector is a read note
 public bool MyTab_GetVisible(Office.IRibbonControl control)
 {
     if (control.Context is Outlook.Explorer)
     {
         Outlook.Explorer explorer =
             control.Context as Outlook.Explorer;
         Outlook.Selection selection = explorer.Selection;
         if (selection.Count == 1)
         {
             if (selection[1] is Outlook.MailItem)
             {
                 Outlook.MailItem oMail =
                     selection[1] as Outlook.MailItem;
                 if (oMail.Sent == true)
                 {
                     return(true);
                 }
                 else
                 {
                     return(false);
                 }
             }
             else
             {
                 return(false);
             }
         }
         else
         {
             return(false);
         }
     }
     else if (control.Context is Outlook.Inspector)
     {
         Outlook.Inspector oInsp =
             control.Context as Outlook.Inspector;
         if (oInsp.CurrentItem is Outlook.MailItem)
         {
             Outlook.MailItem oMail =
                 oInsp.CurrentItem as Outlook.MailItem;
             if (oMail.Sent == true)
             {
                 return(true);
             }
             else
             {
                 return(false);
             }
         }
         else
         {
             return(false);
         }
     }
     else
     {
         return(true);
     }
 }
Пример #8
0
        public void BtnBackupEmail_Click(Office.IRibbonControl control)
        {
            Outlook.MailItem  mailItem  = null;
            Outlook.Explorer  explorer  = null;
            Outlook.Inspector inspector = null;

            if (ControlIsInInspector(control, ref inspector) == true)
            {
                mailItem = inspector.CurrentItem as Outlook.MailItem;
                if (mailItem != null)
                {
                    if (BackupEmailUtil.IsEmailAlreadyInBackupFolder(mailItem))
                    {
                        mailItem.Close(Outlook.OlInspectorClose.olSave);
                    }
                    else
                    {
                        BackupEmailUtil.MarkEmailReadAndClearAllCategories(mailItem);
                        EmailFlagUtil.FlagEmail(mailItem);
                        BackupEmailUtil.BackupEmail(mailItem);
                    }
                }
            }
            else if (ControlIsInExplorer(control, ref explorer) == true)
            {
                try {
                    // I have to wrap 'explorer.selction' into a try block,
                    // becasue outlook will raise an exception on this line when the first page is 'Outlook Today'
                    Outlook.Selection selection = explorer.Selection;
                    foreach (var selected in selection)
                    {
                        mailItem = selected as Outlook.MailItem;
                        if (mailItem != null)
                        {
                            if (BackupEmailUtil.IsEmailAlreadyInBackupFolder(mailItem) == false)
                            {
                                EmailFlagUtil.FlagEmail(mailItem);
                            }
                        }
                    }
                    foreach (var selected in selection)
                    {
                        mailItem = selected as Outlook.MailItem;
                        if (mailItem != null)
                        {
                            if (BackupEmailUtil.IsEmailAlreadyInBackupFolder(mailItem) == false)
                            {
                                BackupEmailUtil.MarkEmailReadAndClearAllCategories(mailItem);
                                BackupEmailUtil.BackupEmail(mailItem);
                            }
                        }
                    }
                } catch (COMException ex) {
                    Debug.WriteLine(ex.ToString());
                }
            }
        }
Пример #9
0
 private void Application_ItemContextMenuDisplay(Office.CommandBar CommandBar, Outlook.Selection Selection)
 {
     Outlook.Selection       selection   = Selection;
     Outlook.MailItem        item1       = (Outlook.MailItem)selection[1];
     Office.CommandBarButton objMainMenu = (Office.CommandBarButton)CommandBar.Controls.Add(Microsoft.Office.Core.MsoControlType.msoControlButton, this.missing, this.missing, this.missing, this.missing);
     objMainMenu.Caption = "SuiteCRM Archive";
     objMainMenu.Visible = true;
     objMainMenu.Picture = RibbonImageHelper.Convert(Resources.SuiteCRM1);
     objMainMenu.Click  += new Office._CommandBarButtonEvents_ClickEventHandler(this.contextMenuArchiveButton_Click);
 }
Пример #10
0
        private void CurrentExplorer_Event()
        {
            Outlook.MAPIFolder selectedFolder =
                olApp.ActiveExplorer().CurrentFolder;


            Outlook.Selection oSel = olExplorer.Selection;

            /* if (oSel.Count != 1)
             * {
             *   MessageBox.Show("Please select only one message for PKCS#7 structure inspection!");
             *   return;
             * }
             * */
            System.Collections.IEnumerator i = oSel.GetEnumerator();
            i.MoveNext();

            Object selObject = (Outlook.MailItem)i.Current;

            if (selObject is Outlook.MailItem)
            {
                Outlook.MailItem mailItem =
                    (selObject as Outlook.MailItem);
                try
                {
                    bool doIt = false;



                    SafeMailItem smi = new SafeMailItemClass();
                    smi.Item = mailItem;

                    mailID = mailItem.EntryID;

                    /*Outlook.NameSpace ns = olApp.GetNamespace("MAPI");
                     *
                     * Outlook.MAPIFolder f = ns.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);
                     * Outlook.Folders folders = f.Folders;
                     * foreach (Outlook.Folder fol in folders) {
                     *  if (fol.Name == "TEST") {
                     *      //
                     *      break;
                     *  }
                     *
                     * }
                     *
                     */
                    // @"\\Mailbox - Dauberschmidt, Markus\Inbox\TEST"
                }
                catch (Exception ie)
                {
                    MessageBox.Show("Exception: " + ie.Message);
                }
            }
        }
Пример #11
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="selection"></param>
        internal static void MoveMail(Outlook.Selection selection)
        {
            if (selection == null || selection.Count < 1)
            {
                return;
            }

            using var form = new ProjectSelectFormHost();
            var result = form.ShowDialog();

            if (result != DialogResult.OK)
            {
                return;
            }

            var folder = GetSharedFolder(form.SelectedFolders[0]);

            if (folder == null)
            {
                throw new ArgumentNullException(nameof(folder), @"No shared folder.");
            }

            var duplicates = new List <string>();

            foreach (var item in selection)
            {
                if (item is Outlook.MailItem mail)
                {
                    if (IsDuplicateInFolder(folder, mail))
                    {
                        duplicates.Add(mail.Subject);
                        continue;
                    }

                    mail.Move(folder);
                    //TODO: Log analytics
                }
            }

            if (!duplicates.Any())
            {
                return;
            }

            var stringBuilder = new StringBuilder();

            stringBuilder.Append("The following items where already present in the folder: \n");
            foreach (var item in duplicates)
            {
                stringBuilder.AppendLine($"\n{item}");
            }

            MessageBox.Show(stringBuilder.ToString(), @"Mail Assistant", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
Пример #12
0
        public static void RightClickCallback(IRibbonControl control, TestOutlookAddIn.ToOTRS_2020 app)
        {
            Outlook.Selection sel  = control.Context as Outlook.Selection;
            Outlook.MailItem  mail = sel[1];
            // MessageBox.Show(mail.Body);
            //   copyMailItem();


            app.processing.copyMailItem();

            //processing.copyMailItem();
        }
        public void ArchiveItem()
        {
            Outlook.Selection conversations = Globals.ThisAddIn.Application.ActiveExplorer().Selection;

            foreach (Outlook.ConversationHeader convHeader in conversations.GetSelection(Outlook.OlSelectionContents.olConversationHeaders))
            {
                foreach (Outlook.MailItem item in convHeader.GetItems())
                {
                    ArchiveMailItem(item);
                }
            }
        }
Пример #14
0
 //This
 void Application_ContextMenuClose(Outlook.OlContextMenu ContextMenu)
 {
     selection = null;
     item      = null;
     if (btnCheckForRule != null)
     {
         btnCheckForRule.Click -= new Office
                                  ._CommandBarButtonEvents_ClickEventHandler(
             btnRules_Click);
     }
     btnCheckForRule = null;
 }
Пример #15
0
        ///
        /// Gets the mail item selected in the explorer view if one is selected or instance if that is the view active.
        ///
        /// The instance containing the event data.
        /// A Outlook.MailItem for the mail being viewed.
        private IEnumerable <Outlook.MailItem> GetSelectedEmails()
        {
            Outlook.Application outlookApp    = this.Application;
            Outlook.Selection   selectedItems = outlookApp.ActiveExplorer().Selection;

            foreach (Outlook.MailItem email in selectedItems)
            {
                if (email is Outlook.MailItem)
                {
                    yield return(email as Outlook.MailItem);
                }
            }
        }
Пример #16
0
        /// <summary>
        /// 選択中のOutlookメールアイテムを取得
        /// 参考:<https://stackoverflow.com/questions/10935611/retrieve-current-email-body-in-outlook>
        /// </summary>
        /// <typeparam name="ItemType"></typeparam>
        /// <returns></returns>
        public ItemType GetSelectedItem <ItemType>() where ItemType : class
        {
            Outlook.Explorer  explorer  = Globals.ThisAddIn.Application.ActiveExplorer();
            Outlook.Selection selection = explorer.Selection;

            if (selection.Count <= 0)
            {
                return(null);
            }

            object selectedItem = selection[1];

            return(selectedItem as ItemType);// Outlook.MailItem;
        }
Пример #17
0
        public static List <Outlook.MailItem> GetMailItem(RibbonControlEventArgs e)
        {
            List <Outlook.MailItem> returnList = new List <Outlook.MailItem>();

            // Check to see if an item is selected in explorer or we are in inspector.
            if (e.Control.Context is Outlook.Inspector)
            {
                Outlook.Inspector inspector = (Outlook.Inspector)e.Control.Context;

                if (inspector.CurrentItem is Outlook.MailItem)
                {
                    returnList.Add(inspector.CurrentItem as Outlook.MailItem);
                    //return inspector.CurrentItem as Outlook.MailItem;
                    return(returnList);
                }
            }

            if (e.Control.Context is Outlook.Explorer)
            {
                Outlook.Explorer explorer = (Outlook.Explorer)e.Control.Context;

                Outlook.Selection selectedItems = explorer.Selection;
                if (selectedItems.Count == 0)
                {
                    return(returnList);
                }
                else if (selectedItems.Count == 1)
                {
                    if (selectedItems[1] is Outlook.MailItem)
                    {
                        returnList.Add(selectedItems[1] as Outlook.MailItem);
                    }
                    return(returnList);
                }
                else
                {
                    foreach (var item in selectedItems)
                    {
                        if (item is Outlook.MailItem)
                        {
                            returnList.Add(item as Outlook.MailItem);
                        }
                    }
                    return(returnList);
                }
            }

            return(returnList);
        }
Пример #18
0
        // Méthode jouée si contextmenu affiché sur une entrée
        private void addEntrytoContextMenu(CommandBar menu, Outlook.Selection Selection)
        {
            if (Selection.Count == 1 && Selection[1] is Outlook.MailItem)
            {
                CommandBarControls controls = menu.Controls;
                this.addActionButton         = (CommandBarButton)controls.Add(MsoControlType.msoControlButton, 1, "", 1, true);
                this.addActionButton.FaceId  = 341;
                this.addActionButton.Style   = MsoButtonStyle.msoButtonIconAndCaption;
                this.addActionButton.Caption = "TaskLeader: ajouter à une action";
                this.addActionButton.Click  += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(getSelectedItem);

                this.addActionButton.Visible = true;

                Marshal.FinalReleaseComObject(controls);
            }
        }
        //This method gets the currently active window in Outlook, gets the selected items, iterates through
        //them and attaches them to be submitted as phishing.  This is where all the magic happens.
        public void SubmitSelectedEmails()
        {
            Outlook.Explorer  activeExplorere  = this.Application.ActiveExplorer();
            Outlook.Selection currentSelection = activeExplorere.Selection;

            DialogResult dialogResult = MessageBox.Show(
                "The selected emails will be submitted to your security team. Proceed?",
                "Report Phishing?",
                MessageBoxButtons.YesNo);

            if (currentSelection.Count == 0)
            {
                MessageBox.Show("Please select messages to report and try again");
                return;
            }


            if (dialogResult == DialogResult.Yes)
            {
                foreach (object selected in currentSelection)
                {
                    Outlook.MailItem mailItem;
                    //It may be possible that the selected item is not an email. I'm not sure under what
                    //conditions this could occure, but better to handle it just in case.
                    try
                    {
                        mailItem = (Outlook.MailItem)selected;
                    }
                    catch (InvalidCastException) { continue; }


                    //An email is created that will be send to security and will have the phishing email attached.
                    Outlook.MailItem submission = Application.CreateItem(Outlook.OlItemType.olMailItem);

                    foreach (string recipient in mailRecipients)
                    {
                        submission.Recipients.Add(recipient);
                    }

                    submission.Subject = this.mailSubjectPrefix + mailItem.Subject;
                    submission.Attachments.Add(mailItem, Outlook.OlAttachmentType.olEmbeddeditem);
                    submission.Body = this.mailBody;
                    submission.Send();
                    mailItem.Delete();
                }
            }
        }
Пример #20
0
        //This
        void Application_ItemContextMenuDisplay(Office.CommandBar CommandBar, Outlook.Selection Selection)
        {
            selection = Selection;
            if (GetMessageClass(selection[1]) == "IPM.Note" && selection.Count == 1)
            {
                item                    = (Outlook.MailItem)selection[1];
                btnCheckForRule         = (Office.CommandBarButton)CommandBar.Controls.Add(Office.MsoControlType.msoControlButton, missing, missing, missing);
                btnCheckForRule.Caption = "CheckRules";
                btnCheckForRule.Click  += new Office._CommandBarButtonEvents_ClickEventHandler(btnCheckForRule_Click);

                foreach (Outlook.Rule R in Application.Session.DefaultStore.GetRules())
                {
                    Office.CommandBarButton test = (Office.CommandBarButton)CommandBar.Controls.Add(Office.MsoControlType.msoControlButton, missing, missing, missing);
                    test.Caption = @"ADD2RULE: " + R.Name;
                    test.Click  += new Office._CommandBarButtonEvents_ClickEventHandler(btnRules_Click);
                }
            }
        }
Пример #21
0
        private void ButtonClick(Office.CommandBarButton ButtonContrl, ref bool CancelOption)
        {
            // Message box displayed on button click


            P7MViewer.frmMain  m = new P7MViewer.frmMain();
            Outlook.MAPIFolder selectedFolder =
                olApp.ActiveExplorer().CurrentFolder;


            Outlook.Selection oSel = olExplorer.Selection;
            if (oSel.Count != 1)
            {
                MessageBox.Show("Please select only one message for PKCS#7 structure inspection!");
                return;
            }

            System.Collections.IEnumerator i = oSel.GetEnumerator();
            i.MoveNext();

            Object selObject = (Outlook.MailItem)i.Current;

            if (selObject is Outlook.MailItem)
            {
                Outlook.MailItem mailItem =
                    (selObject as Outlook.MailItem);
                try
                {
                    SafeMailItem smi = new SafeMailItemClass();
                    smi.Item = mailItem;



                    m.setOutlookMessage(mailItem);
                    m.Show();
                    m.readMail();
                }
                catch (Exception e)
                {
                    MessageBox.Show(e.Message);
                }
            }
        }
Пример #22
0
        void Application_ItemContextMenuDisplay(Office.CommandBar CommandBar, Outlook.Selection Selection)
        {
            // only show if one item is selected and it is a mail item.
            if (Selection.Count == 1 && GetMessageClass(Selection[1]) == "IPM.Note")
            {
                var button = (Office.CommandBarButton)CommandBar.Controls.Add(
                    Office.MsoControlType.msoControlButton, missing, missing, missing, missing);
                button.Caption = CREATE_MENU_TEXT;
                button.Visible = true;
                button.Click  += new Office
                                 ._CommandBarButtonEvents_ClickEventHandler(CreateTask_Click);

                button = (Office.CommandBarButton)CommandBar.Controls.Add(
                    Office.MsoControlType.msoControlButton, missing, missing, missing, missing);
                button.Caption = APPEND_MENU_TEXT;
                button.Visible = true;
                button.Click  += new Office
                                 ._CommandBarButtonEvents_ClickEventHandler(AppendTask_Click);
            }
        }
Пример #23
0
    /// <summary>
    /// WrapEvent fired for SelectionChange event.
    /// </summary>
    /// <param name="explorer">the explorer for which a selectionchange event fired.</param>
    void wrappedExplorer_SelectionChange(Outlook.Explorer explorer)
    {
      Outlook.Selection Selection = explorer.Selection;
      if (Selection.Count != 1)
        return;
      Outlook.MailItem mailItem = Selection[1] as Outlook.MailItem;
      if (mailItem == null)
        return;
      if (mailItem.BodyFormat == Outlook.OlBodyFormat.olFormatPlain)
      {
        Match match = Regex.Match(mailItem.Body, _pgpHeaderPattern);

        _gpgCommandBar.GetButton("Verify").Enabled = (match.Value == _pgpSignedHeader);
        _gpgCommandBar.GetButton("Decrypt").Enabled = (match.Value == _pgpEncryptedHeader);
      }
      else
      {
        _gpgCommandBar.GetButton("Verify").Enabled = false;
        _gpgCommandBar.GetButton("Decrypt").Enabled = false;
      }
    }
Пример #24
0
        private Outlook.MailItem GetSelectedMail(Office.IRibbonControl control)
        {
            Outlook.MailItem mail = null;

            if (control.Context is Outlook.Inspector) // opened message window
            {
                Outlook.Inspector item = control.Context as Outlook.Inspector;
                mail = item.CurrentItem as Outlook.MailItem;
            }
            else if (control.Context is Outlook.Selection) // right click on e-mail context menu
            {
                Outlook.Selection sel = control.Context as Outlook.Selection;
                mail = (Outlook.MailItem)sel[1];
            }
            else // selection from explorer via button in ribbon
            {
                Outlook.Selection selection = Globals.RedmineAddIn.Application.ActiveExplorer().Selection;
                mail = (Outlook.MailItem)selection[1];
            }

            return(mail);
        }
Пример #25
0
        private void Application_ItemContextMenuDisplay(Office.CommandBar cb, Outlook.Selection selection)
        {
            try
            {
                // add the context menu 'Test Forward'
                // this will appear as the first item in context menu list when you rignt click on any message
                ctxMenuTest         = (Office.CommandBarButton)cb.Controls.Add(Office.MsoControlType.msoControlButton, Type.Missing, "Test Forward", 1, Type.Missing);
                ctxMenuTest.Caption = "An Steinbach CRM übergeben";
                ctxMenuTest.Style   = Microsoft.Office.Core.MsoButtonStyle.msoButtonIconAndCaption;
                ctxMenuTest.Visible = true;

                // assign image for the context menu
                // ctxMenuTest.Picture = GetImage("Options");

                // add click event handler
                ctxMenuTest.Click += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(ctxMenuTest_Click);
            }
            catch (Exception ex)
            {
                MessageBox.Show("ItemContextMenuDisplay - " + ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Пример #26
0
    private void VerifyButton_Click(Office.CommandBarButton Ctrl, ref bool CancelDefault)
    {
      // Get the selected item in Outlook and determine its type.
      Outlook.Selection outlookSelection = Application.ActiveExplorer().Selection;
      if (outlookSelection.Count <= 0)
        return;

      object selectedItem = outlookSelection[1];
      Outlook.MailItem mailItem = selectedItem as Outlook.MailItem;

      if (mailItem == null)
      {
        MessageBox.Show(
            "OutlookGnuPG can only verify mails.",
            "Invalid Item Type",
            MessageBoxButtons.OK,
            MessageBoxIcon.Error);

        return;
      }

      VerifyEmail(mailItem);
    }
Пример #27
0
        public void OnFixedRepliesAction(Office.IRibbonControl control)
        {
            Outlook.Inspector inspector = null;
            if (ControlIsInInspector(control, ref inspector) == true)
            {
                Outlook.MailItem mailItem = inspector.CurrentItem as Outlook.MailItem;
                if ((mailItem != null) && (mailItem.Sent == false) /* compose mode */)
                {
                    FixedReplyUtil.AddText(mailItem, control.Tag);
                    mailItem.Save();
                }
                return;
            }

            Outlook.Explorer explorer = null;
            if (ControlIsInExplorer(control, ref explorer) == true)
            {
                Outlook.Selection selection = explorer.Selection;
                foreach (var selected in selection)
                {
                    Outlook.MailItem mailItem = selected as Outlook.MailItem;
                    if (mailItem != null)
                    {
                        if (mailItem.Application.ActiveExplorer().ActiveInlineResponse != null)
                        {
                            Outlook.MailItem inlineMailItem = mailItem.Application.ActiveExplorer().ActiveInlineResponse as Outlook.MailItem;
                            if (inlineMailItem != null)
                            {
                                FixedReplyUtil.AddText(inlineMailItem, control.Tag);
                                inlineMailItem.Save();
                            }
                        }
                    }
                }
                return;
            }
        }
Пример #28
0
        private static MailItem getMailItem()
        {
            dynamic wind = ThisAddIn.AppObj.ActiveWindow();



            if (wind is Microsoft.Office.Interop.Outlook.Inspector)
            {
                Microsoft.Office.Interop.Outlook.Inspector inspector = (Microsoft.Office.Interop.Outlook.Inspector)wind;

                if (inspector.CurrentItem is Microsoft.Office.Interop.Outlook.MailItem)
                {
                    Microsoft.Office.Interop.Outlook.MailItem mailitem = (Microsoft.Office.Interop.Outlook.MailItem)inspector.CurrentItem;
                    return(mailitem);
                }
            }

            if (wind is Microsoft.Office.Interop.Outlook.Explorer)
            {
                Microsoft.Office.Interop.Outlook.Explorer explorer = (Microsoft.Office.Interop.Outlook.Explorer)wind;

                Microsoft.Office.Interop.Outlook.Selection selectedItems = explorer.Selection;
                if (selectedItems.Count != 1)
                {
                    return(null);
                }

                if (selectedItems[1] is Microsoft.Office.Interop.Outlook.MailItem)
                {
                    Microsoft.Office.Interop.Outlook.MailItem mailitem = selectedItems[1];
                    return(mailitem);
                }
            }

            return(null);
        }
Пример #29
0
        // OnMyButtonClick routine handles all button click events
        // and displays IRibbonControl.Context in message box
        public void OnMyButtonClick(Office.IRibbonControl control)
        {
            string msg = string.Empty;

            if (control.Context is Outlook.AttachmentSelection)
            {
                msg = "Context=AttachmentSelection" + "\n";
                Outlook.AttachmentSelection attachSel =
                    control.Context as Outlook.AttachmentSelection;
                foreach (Outlook.Attachment attach in attachSel)
                {
                    msg = msg + attach.DisplayName + "\n";
                }
            }
            else if (control.Context is Outlook.Folder)
            {
                msg = "Context=Folder" + "\n";
                Outlook.Folder folder =
                    control.Context as Outlook.Folder;
                msg = msg + folder.Name;
            }
            else if (control.Context is Outlook.Selection)
            {
                msg = "Context=Selection" + "\n";
                Outlook.Selection selection =
                    control.Context as Outlook.Selection;
                if (selection.Count == 1)
                {
                    OutlookItem olItem =
                        new OutlookItem(selection[1]);
                    msg = msg + olItem.Subject
                          + "\n" + olItem.LastModificationTime;
                }
                else
                {
                    msg = msg + "Multiple Selection Count="
                          + selection.Count;
                }
            }
            else if (control.Context is Outlook.OutlookBarShortcut)
            {
                msg = "Context=OutlookBarShortcut" + "\n";
                Outlook.OutlookBarShortcut shortcut =
                    control.Context as Outlook.OutlookBarShortcut;
                msg = msg + shortcut.Name;
            }
            else if (control.Context is Outlook.Store)
            {
                msg = "Context=Store" + "\n";
                Outlook.Store store =
                    control.Context as Outlook.Store;
                msg = msg + store.DisplayName;
            }
            else if (control.Context is Outlook.View)
            {
                msg = "Context=View" + "\n";
                Outlook.View view =
                    control.Context as Outlook.View;
                msg = msg + view.Name;
            }
            else if (control.Context is Outlook.Inspector)
            {
                msg = "Context=Inspector" + "\n";
                Outlook.Inspector insp =
                    control.Context as Outlook.Inspector;
                if (insp.AttachmentSelection.Count >= 1)
                {
                    Outlook.AttachmentSelection attachSel =
                        insp.AttachmentSelection;
                    foreach (Outlook.Attachment attach in attachSel)
                    {
                        msg = msg + attach.DisplayName + "\n";
                    }
                }
                else
                {
                    OutlookItem olItem =
                        new OutlookItem(insp.CurrentItem);
                    msg = msg + olItem.Subject;
                }
            }
            else if (control.Context is Outlook.Explorer)
            {
                msg = "Context=Explorer" + "\n";
                Outlook.Explorer explorer =
                    control.Context as Outlook.Explorer;
                if (explorer.AttachmentSelection.Count >= 1)
                {
                    Outlook.AttachmentSelection attachSel =
                        explorer.AttachmentSelection;
                    foreach (Outlook.Attachment attach in attachSel)
                    {
                        msg = msg + attach.DisplayName + "\n";
                    }
                }
                else
                {
                    Outlook.Selection selection =
                        explorer.Selection;
                    if (selection.Count == 1)
                    {
                        OutlookItem olItem =
                            new OutlookItem(selection[1]);
                        msg = msg + olItem.Subject
                              + "\n" + olItem.LastModificationTime;
                    }
                    else
                    {
                        msg = msg + "Multiple Selection Count="
                              + selection.Count;
                    }
                }
            }
            else if (control.Context is Outlook.NavigationGroup)
            {
                msg = "Context=NavigationGroup" + "\n";
                Outlook.NavigationGroup navGroup =
                    control.Context as Outlook.NavigationGroup;
                msg = msg + navGroup.Name;
            }
            else if (control.Context is
                     Microsoft.Office.Core.IMsoContactCard)
            {
                msg = "Context=IMsoContactCard" + "\n";
                Office.IMsoContactCard card =
                    control.Context as Office.IMsoContactCard;
                if (card.AddressType ==
                    Office.MsoContactCardAddressType.
                    msoContactCardAddressTypeOutlook)
                {
                    // IMSOContactCard.Address is AddressEntry.ID
                    Outlook.AddressEntry addr =
                        Globals.ThisAddIn.Application.Session.GetAddressEntryFromID(
                            card.Address);
                    if (addr != null)
                    {
                        msg = msg + addr.Name;
                    }
                }
            }
            else if (control.Context is Outlook.NavigationModule)
            {
                msg = "Context=NavigationModule";
            }
            else if (control.Context == null)
            {
                msg = "Context=Null";
            }
            else
            {
                msg = "Context=Unknown";
            }
            MessageBox.Show(msg,
                            "RibbonXOutlook14AddinCS",
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Information);
        }
Пример #30
0
        private void ImagePanel_Drop(object sender, DragEventArgs e)
        {
            string[] FileList = (string[])e.Data.GetData(DataFormats.FileDrop, false);

            if (FileList == null)
            {
                Outlook.Application outlook    = new Outlook.Application();
                Outlook.Explorer    oExplorer  = outlook.ActiveExplorer();
                Outlook.Selection   oSelection = oExplorer.Selection;
                string baseProjDir             = System.IO.Path.Combine("C:\\Project_Notes\\Stored_Content",
                                                                        this.ProjectID.ToString());
                if (!Directory.Exists(baseProjDir))
                {
                    Directory.CreateDirectory(baseProjDir);
                }

                foreach (object item in oSelection)
                {
                    Outlook.MailItem mi       = (Outlook.MailItem)item;
                    string           filePath = System.IO.Path.Combine(baseProjDir, mi.Subject);

                    using (
                        SqlConnection conn =
                            new SqlConnection(
                                "Server=(LocalDB)\\MSSQLLocalDB;Database=Project_Notes;Integrated Security = true"))
                    {
                        conn.Open(); //insert log, the creation_date is added by default
                        string sql = @"
                INSERT INTO FILES(filepath,Project_ID) VALUES(@filepath,@projectId);
                ";
                        using (SqlCommand cmd = new SqlCommand(sql, conn))
                        {
                            string cd     = mi.CreationTime.ToString("MM-dd-yy HH:mm");
                            string inside = mi.Subject + " (" + cd + ").msg";
                            inside = inside.Replace("/", "").Replace(":", "-");
                            string saveString = System.IO.Path.Combine(baseProjDir, inside);
                            cmd.Parameters.Add("@filepath", saveString);
                            cmd.Parameters.Add("@projectId", this.ProjectID);
                            mi.SaveAs(saveString, Outlook.OlSaveAsType.olMSG);
                            mi.Save();
                            if (File.Exists(saveString))
                            {
                                cmd.ExecuteNonQuery();
                            }
                            else
                            {
                                MessageBox.Show("Failed to save email");
                            }
                        }
                    }
                }
            }
            else if (FileList[0] != null)
            {
                string baseProjDir = System.IO.Path.Combine("C:\\Project_Notes\\Stored_Content",
                                                            this.ProjectID.ToString());
                if (!Directory.Exists(baseProjDir))
                {
                    Directory.CreateDirectory(baseProjDir);
                }


                foreach (var file in FileList)
                {
                    string filePath = System.IO.Path.Combine(baseProjDir,
                                                             System.IO.Path.GetFileName(file.ToString()).Replace("/", "").Replace(":", ""));

                    using (
                        SqlConnection conn =
                            new SqlConnection(
                                "Server=(LocalDB)\\MSSQLLocalDB;Database=Project_Notes;Integrated Security = true"))
                    {
                        conn.Open(); //insert log, the creation_date is added by default
                        string sql = @"
                INSERT INTO FILES(filepath,Project_ID) VALUES(@filepath,@projectId);
                ";
                        using (SqlCommand cmd = new SqlCommand(sql, conn))
                        {
                            cmd.Parameters.Add("@filepath", filePath);
                            cmd.Parameters.Add("@projectId", this.ProjectID);
                            File.Copy(file, filePath, overwrite: true);
                            cmd.ExecuteNonQuery();
                        }
                    }
                }
            }
            Files fileWindow = new Files(this.ProjectID, this.ArchivedMode);

            App.Current.MainWindow = fileWindow;
            this.Close();
            fileWindow.Show();
        }
Пример #31
0
        public void init(Outlook.Selection mailSelection)
        {
            IDictionary<string, string> parameters = new Dictionary<string, string>();
            parameters[SessionParameter.BindingType] = BindingType.AtomPub;

            XmlNode rootNode = Config1.xmlRootNode();

            parameters[SessionParameter.AtomPubUrl] = rootNode.ChildNodes.Item(0).InnerText + "atom/cmis";
            parameters[SessionParameter.User] = rootNode.ChildNodes.Item(1).InnerText;
            parameters[SessionParameter.Password] = rootNode.ChildNodes.Item(2).InnerText;

            SessionFactory factory = SessionFactory.NewInstance();
            ISession session = factory.GetRepositories(parameters)[0].CreateSession();

            // construction de l'arborescence
            string id = null;
            IItemEnumerable<IQueryResult> qr = session.Query("SELECT * from cmis:folder where cmis:name = 'Default domain'", false);

            foreach (IQueryResult hit in qr) { id = hit["cmis:objectId"].FirstValue.ToString(); }
            IFolder doc = session.GetObject(id) as IFolder;

            TreeNode root = treeView.Nodes.Add(doc.Id, doc.Name);
            AddVirtualNode(root);

            int i;
            Outlook.MailItem mailItem;
            string subject;

            selection = mailSelection;

            int nbMail = selection.Count;

            // Affichage tableau des courriers
            for (i = 1; i <= nbMail; i++)
            {
                mailItem = (Outlook.MailItem)selection[i];
                subject = mailItem.Subject;

                object[] dr = new object[4];
                dr[0] = i.ToString();
                dr[1] = subject;
                dr[2] = mailItem.Attachments.Count;
                dr[3] = true;
                mailGrid.Rows.Add(dr);
            }
        }
Пример #32
0
        //This
        void Application_ItemContextMenuDisplay(Office.CommandBar CommandBar, Outlook.Selection Selection)
        {
            selection = Selection;
            if (GetMessageClass(selection[1])=="IPM.Note" &&selection.Count==1)
            {
                item = (Outlook.MailItem)selection[1];
                btnCheckForRule = (Office.CommandBarButton)CommandBar.Controls.Add(Office.MsoControlType.msoControlButton, missing, missing, missing);
                btnCheckForRule.Caption = "CheckRules";
                btnCheckForRule.Click += new Office._CommandBarButtonEvents_ClickEventHandler(btnCheckForRule_Click);

                foreach (Outlook.Rule R in Application.Session.DefaultStore.GetRules())
                {
                    Office.CommandBarButton test=     (Office.CommandBarButton)CommandBar.Controls.Add(Office.MsoControlType.msoControlButton, missing, missing, missing);
                    test.Caption = @"ADD2RULE: "+R.Name;
                    test.Click += new Office._CommandBarButtonEvents_ClickEventHandler(btnRules_Click);
                }
            }
        }
Пример #33
0
        /// <summary>
        /// <c>addinExplorer_BeforeItemPaste</c> Event Handler
        /// Fires when any item is dragged and dropped to an outlook Folder
        /// </summary>
        /// <param name="ClipboardContent"></param>
        /// <param name="Target"></param>
        /// <param name="Cancel"></param>
        void addinExplorer_BeforeItemPaste(ref object ClipboardContent, Microsoft.Office.Interop.Outlook.MAPIFolder Target, ref bool Cancel)
        {
            ///code written by Joy///
              ///checks if any upload is running
            if (isuploadRunning == true||isTimerUploadRunning==true||isMoveRunning==true||isCopyRunninng==true)
            {
                frmMessageWindow objMessage = new frmMessageWindow();
                objMessage.DisplayMessage = "Your uploads are still running.Please wait for sometime.";
                objMessage.TopLevel = true;
                objMessage.TopMost = true;
                objMessage.ShowDialog();
                objMessage.Dispose();
                //EncodingAndDecoding.ShowMessageBox("", "Please check the uploading form. Form is still open.", MessageBoxIcon.Warning);
                Cancel = true;
                return;

            }
            else
            {
                try
                {
                    ///all code in this section written by joy
                    ///retrieves the mail items from the Selection and set the progressbar value to default

                    Outlook.MailItem mailitem;
                    no_of_items_copied = 0;

                    Outlook.Application myApplication = Globals.ThisAddIn.Application;
                    Outlook.Explorer myActiveExplorer = (Outlook.Explorer)myApplication.ActiveExplorer();

                    ///retrieves the mail items from the Selection
                    oselection = myActiveExplorer.Selection;

                    no_of_items_to_be_uploaded = oselection.Count;

                    AddfFolderinSessionMapi();

                    IsUrlIsTyped = false;
                    currentFolderSelected = Target.Name;
                    currentFolderSelectedGuid = Target.EntryID;

                    myTargetFolder = Target;

                    if (IsUploadingFormIsOpen == true)
                    {
                        if (Globals.ThisAddIn.frmlistObject != null)
                        {
                            ///set the progressbar value to default
                            frmlistObject.progressBar1.Value = frmlistObject.progressBar1.Minimum;
                            frmlistObject.lblPRStatus.Text = "";
                        }
                        //frmUploadItemsList frmUplList = new frmUploadItemsList();
                        //frmUplList.progressBar1.Value = frmUplList.progressBar1.Minimum;
                        //frmUplList.lblPRStatus.Text = "";
                        //frmUplList.Refresh();
                        //frmUplList.Visible = false;
                        //frmUplList.Dispose();

                    }

                    //Check  dropping item is from browser or not

                    if (ClipboardContent.GetType().Name == "String")
                    {
                        //Set active folder as TargetFolder
                        this.Application.ActiveExplorer().SelectFolder(Target);

                        //'Cerate instance
                        frmSPSiteConfigurationObject = new frmSPSiteConfiguration();
                        //Get the drop url

                        frmSPSiteConfigurationObject.URL = Convert.ToString(ClipboardContent);

                        frmSPSiteConfigurationObject.ShowDialog();
                        if (frmSPSiteConfigurationObject.IsConfigureCompleted)
                        {
                            //Save the details in log proeprties object
                            XMLLogProperties xLogProperties = frmSPSiteConfigurationObject.FolderConfigProperties;

                            Outlook.MAPIFolder newFolder = null;
                            bool result = CreateFolderInOutLookSideMenu(xLogProperties.DisplayFolderName, xLogProperties.SiteURL, out newFolder, Target);

                            Cancel = true;
                            if (result == true && newFolder != null)
                            {

                                //Set new folder location
                                xLogProperties.OutlookFolderLocation = newFolder.FolderPath;
                                //Create node in xml file
                                UserLogManagerUtility.CreateXMLFileForStoringUserCredentials(xLogProperties);

                                MAPIFolderWrapper omapi = null;
                                if (string.IsNullOrEmpty(xLogProperties.DocumentLibraryName) == true)
                                {
                                    //Doc name is empty means Folder is not mapped with Doc Lib
                                    omapi = new MAPIFolderWrapper(ref  newFolder, addinExplorer, false);
                                }
                                else
                                {
                                    omapi = new MAPIFolderWrapper(ref newFolder, addinExplorer, true);
                                }
                                omapi.AttachedFolder.WebViewURL = ListWebClass.WebViewUrl(omapi.AttachedFolder.WebViewURL);
                                myFolders.Add(omapi);

                            }

                        }
                        else
                        {
                            frmSPSiteConfigurationObject.Close();
                            Cancel = true;
                        }
                    }
                    else
                    {

                    }
                }
                catch (Exception ex)
                {
                    EncodingAndDecoding.ShowMessageBox("BeforeItemPaste", ex.Message, MessageBoxIcon.Error);
                }
                finally
                {

                }
            }
        }
Пример #34
0
 //This
 void Application_ContextMenuClose(Outlook.OlContextMenu ContextMenu)
 {
     selection = null;
     item = null;
     if (btnCheckForRule != null)
     {
         btnCheckForRule.Click -= new Office
             ._CommandBarButtonEvents_ClickEventHandler(
             btnRules_Click);
     }
     btnCheckForRule = null;
 }