Beispiel #1
0
        void Application_ItemSend(object item, ref bool Cancel)
        {
            mailItem = (Microsoft.Office.Interop.Outlook.MailItem)item;

            if (string.IsNullOrEmpty(mailItem.Subject) || !mailItem.Subject.StartsWith(SUBJECT_TRANSMITTED)) {
                // new mail needed to be processed
                this.filesToTransmit = new List<string>();

                CopyAttachedFiles(FindAttachedFiles());

                bool saved = false;
                try {
                    this.mailItem.Save();
                    saved = true;
                }
                catch (COMException x) {
                    System.Windows.Forms.MessageBox.Show(x.Message);
                    //this.RestoreFilesToSend(this.mailItem);
                    //this.RestoreFoldersToSend(this.mailItem);
                }

                if (saved && filesToTransmit.Count > 0) {
                    Transfer();

                    // cancel normal send (place in Draft) so it's possible to lookup later
                    Cancel = true;
                }
            }
            else {
                mailItem.Subject = mailItem.Subject.Substring(SUBJECT_TRANSMITTED.Length);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Gets all the headers of a mailitem
        /// </summary>
        /// <param name="mailItem"></param>
        /// <returns></returns>
        private string GetAllHeaders(Microsoft.Office.Interop.Outlook.MailItem mailItem)
        {
            if (null != mailItem)
            {
                return((string)mailItem.PropertyAccessor.GetProperty(TransportMessageHeadersSchema));
            }

            return(string.Empty);
        }
Beispiel #3
0
 /// <summary>
 /// Process new email
 /// </summary>
 /// <param name="EntryIDCollection">ID of the email</param>
 private void Application_NewMailEx(string EntryIDCollection)
 {
     if (Properties.Settings.Default.MailAlertsEnabled)
     {
         Microsoft.Office.Interop.Outlook.MailItem newMail = Globals.ThisAddIn.Application.Session.GetItemFromID(EntryIDCollection) as Microsoft.Office.Interop.Outlook.MailItem;
         if (newMail != null)
         {
             NewMailAlert nm = new NewMailAlert(newMail, Properties.Settings.Default.DisplayTimeOut);
             // Show the popup without stealing focus
             SoundHelper.sndPlaySoundW(SoundHelper.MailBeep, SoundHelper.SND_NODEFAULT);
             nm.Show();
         }
     }
 }
Beispiel #4
0
        /// <summary>
        /// Finds a single mime-header among all the headers
        /// </summary>
        /// <param name="mailItem"></param>
        /// <param name="header"></param>
        /// <returns></returns>
        private string GetHeader(Microsoft.Office.Interop.Outlook.MailItem mailItem, string header)
        {
            string headerValue = string.Empty;

            string allHeaders = GetAllHeaders(mailItem);

            if (!string.IsNullOrWhiteSpace(allHeaders))
            {
                var match = System.Text.RegularExpressions.Regex.Match(allHeaders, string.Format(CultureInfo.CurrentCulture, "{0}:[\\s]*(.*)[\\s]*\r\n", header));
                if (null != match && match.Groups.Count > 1)
                {
                    headerValue = match.Groups[1].Value.Trim(new char[] { ' ', '<', '>' });
                }
            }

            return(headerValue);
        }
Beispiel #5
0
        // Event Handler for Send Button
        public void OnSendButton(Office.IRibbonControl control)
        {
            Explorer explorer = Globals.ThisAddIn.Application.ActiveExplorer();

            Microsoft.Office.Interop.Outlook.AddressEntry addrEntry = Globals.ThisAddIn.Application.Session.CurrentUser.AddressEntry;
            string currentUserEmail = "";
            string userFullName     = "";

            if (addrEntry.Type == "EX")
            {
                Microsoft.Office.Interop.Outlook.ExchangeUser currentUser = Globals.ThisAddIn.Application.Session.CurrentUser.
                                                                            AddressEntry.GetExchangeUser();
                currentUserEmail = currentUser.PrimarySmtpAddress;
                userFullName     = currentUser.FirstName + " " + currentUser.LastName + " (" + currentUser.PrimarySmtpAddress + ")";
            }
            else
            {
                currentUserEmail = addrEntry.Address;
                userFullName     = addrEntry.Name + " (" + addrEntry.Address + ")";
            }

            MailItem mailItem = null;

            if (explorer != null && explorer.Selection != null && explorer.Selection.Count > 0)
            {
                object item = explorer.Selection[1];
                if (item is MailItem)
                {
                    mailItem = item as MailItem;
                }
            }

            if (mailItem != null)
            {
                string PR_TRANSPORT_MESSAGE_HEADERS = "http://schemas.microsoft.com/mapi/proptag/0x007D001E";

                Microsoft.Office.Interop.Outlook.PropertyAccessor olPA = mailItem.PropertyAccessor;
                string headers = olPA.GetProperty(PR_TRANSPORT_MESSAGE_HEADERS);

                string senderEmail = "";

                if (mailItem.SenderEmailType == "EX")
                {
                    // Exchange email address

                    string[] directoryParts = mailItem.SenderEmailAddress.Split('=');
                    if (directoryParts.Length > 1)
                    {
                        senderEmail = directoryParts[directoryParts.Length - 1].ToLower();
                    }
                }
                else
                {
                    senderEmail = mailItem.SenderEmailAddress;


                    int successCode = AddPhishingEmail(senderEmail);

                    if (successCode > 0)
                    {
                        MessageBox.Show("'" + senderEmail + "' was successfully added to the list of phishing email addresses and forwarded to central IS (phishing.uoregon.edu).");

                        string subject = "Phishing Email added to Phishing Email List";

                        string messageBody = "Phishing Email added to Phishing Email List '" + senderEmail + "'.<br />";
                        messageBody += "Added By: " + userFullName + " at " + DateTime.Now.ToString() + "<br /><br />";
                        messageBody += "Headers: <br />" + headers;


                        Microsoft.Office.Interop.Outlook.MailItem eMail = (Microsoft.Office.Interop.Outlook.MailItem)
                                                                          Globals.ThisAddIn.Application.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);
                        eMail.Subject  = subject;
                        eMail.To       = PHISHING_EMAIL;
                        eMail.Body     = messageBody;
                        eMail.HTMLBody = messageBody;
                        eMail.Attachments.Add(mailItem);

                        eMail.Importance = Microsoft.Office.Interop.Outlook.OlImportance.olImportanceHigh;
                        ((Microsoft.Office.Interop.Outlook._MailItem)eMail).Send();
                    }
                }
            }
        }
Beispiel #6
0
        /// <summary>
        /// Files have been successfully transferred and we have a transmit token.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="transmitToken"></param>
        void TransmitDone(object sender, TransmitCompletedResult result)
        {
            // we might need to have this as a local variable
            Microsoft.Office.Interop.Outlook.Application applicationObject = this.Application;

            Microsoft.Office.Interop.Outlook.MailItem mailItem = null;
            try {
                object storeID = applicationObject.Session.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderDrafts).StoreID;
                mailItem = (Microsoft.Office.Interop.Outlook.MailItem)applicationObject.Session.GetItemFromID(this.entryID, storeID);
                if (!string.IsNullOrEmpty(result.Response)) {
                    mailItem.Subject = SUBJECT_TRANSMITTED + mailItem.Subject;
                    if (mailItem.HTMLBody != null) {
                        string linkHtml = result.Response;

                        string str2 = "<img border=\"0\" width=\"120\" height=\"35\" src=\"cid:reply.gif\"/>";
                        int index = linkHtml.IndexOf(str2);
                        if (index > -1) {
                            linkHtml = linkHtml.Substring(0, index - 1) + linkHtml.Substring(index + str2.Length);
                        }
                        int length = -1;
                        length = mailItem.HTMLBody.ToUpper().LastIndexOf("</BODY>");
                        if (length != -1) {
                            mailItem.HTMLBody = mailItem.HTMLBody.Substring(0, length) + linkHtml + mailItem.HTMLBody.Substring(length, mailItem.HTMLBody.Length - length);
                        }
                        else {
                            mailItem.HTMLBody += "\n" + linkHtml;
                        }
                    }
                    else {
                        mailItem.Body = mailItem.Body + result.Response;
                    }

                    // do actual sending of email (move from Draft to Outbox)
                    (mailItem as Microsoft.Office.Interop.Outlook._MailItem).Send();
                }
                else {
                    mailItem.Display(false);
                    //this.RestoreFilesToSend(mailItem);
                    //this.RestoreFoldersToSend(mailItem);
                }
                try {
                    foreach (string str3 in this.filesToTransmit) {
                        File.Delete(str3);
                    }
                    if (this.filesToTransmit.Count > 0) {
                        new DirectoryInfo(Path.GetDirectoryName(this.filesToTransmit[0])).Delete();
                    }
                }
                catch (Exception exception) {
                    System.Windows.Forms.MessageBox.Show(exception.Message);
                    //MessageBox.Show(ForegroundWindow.Instance, Messages.Instance.Get("ErrorCleanup"), Messages.Instance.Get("MessageTitle"), MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    //ErrorLogger.Log("ErrorCleanup", exception);
                }
            }
            catch (Exception exception2) {
                System.Windows.Forms.MessageBox.Show(exception2.Message);
                //MessageBox.Show(ForegroundWindow.Instance, Messages.Instance.Get("ErrorSending"), Messages.Instance.Get("MessageTitle"), MessageBoxButtons.OK, MessageBoxIcon.Hand);
                //ErrorLogger.Log("ErrorSending", exception2);
            }
            finally {
                if (mailItem != null) {
                    Marshal.ReleaseComObject(mailItem);
                }
                mailItem = null;
                if (applicationObject != null) {
                    Marshal.ReleaseComObject(applicationObject);
                }
                applicationObject = null;
                transferForm.Close();
                transferForm = null;
            }
        }