예제 #1
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);
                }
            }
        }
        private MSOutlook._MailItem CreateTestMailItem()
        {
            MSOutlook.MAPIFolder drafts = GetOutlookSession().GetDefaultFolder(MSOutlook.OlDefaultFolders.olFolderDrafts);

            MSOutlook._MailItem oItem = (MSOutlook._MailItem)drafts.Items.Add(0);

            SafeMailItemClass sItem = new SafeMailItemClass();

            sItem.Item = oItem;

            oItem.Save();

            return oItem;
        }
        private MSOutlook._MailItem GetMailItemFromFile(string filePath)
        {
            MSOutlook.MAPIFolder drafts = GetOutlookSession().GetDefaultFolder(MSOutlook.OlDefaultFolders.olFolderDrafts);

            MSOutlook._MailItem oItem = (MSOutlook._MailItem)drafts.Items.Add(0);

            SafeMailItemClass sItem = new SafeMailItemClass();

            sItem.Item = oItem;

            sItem.Import(filePath, 3); //3 == Outlook MSG file format

            oItem.Save();

            return oItem;
        }
예제 #4
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);
                }
            }
        }
예제 #5
0
		private static void HandleSubjectAndBody(SafeMailItemClass mailItem, UniversalRequestObject uro)
		{
			string subject = (string)mailItem.get_Fields(0x0037001E);
			if (null == subject)
				subject = String.Empty;

			uro.Properties.Add(MailMessagePropertyKeys.Subject, subject);

			Logging.Trace.WriteLine(uro.Properties[MailMessagePropertyKeys.Subject], "RedemptionMailConverter.Convert");

			string msgBody = null;
			msgBody = mailItem.Body;
			if (mailItem.Body == null)
				msgBody = String.Empty;
			else
				msgBody = mailItem.Body;

			uro.Properties.Add(MailMessagePropertyKeys.Body, msgBody);
		}
예제 #6
0
        private void loadMessage(TreeNode messageNode)
        {
            String str;

            str = "Outlook Envelope data";
            messageNode.Text = str;
            txtBox.AppendText(str + "\n");



            //Redemption.SafeMailItemClass emailR = new Redemption.SafeMailItemClass();



            /*str = email.Subject;
             * messageNode.Nodes.Add(str);
             * txtBox.AppendText(str + "\n");
             *
             * str = "Subject: " + email.Subject;
             * messageNode.Nodes.Add(str);
             * txtBox.AppendText(str + "\n");
             */

            /*TreeNode bodyNode = messageNode.Nodes.Add("Body: (double click to view)");
             * bodyNode.Tag = new string[] { message.BodyText, message.BodyRTF };
             */

            /* WE'RE NOT GETTING ANY FURTHER HERE, BECAUSE OUTLOOK WILL THROW AN "Your digital ID cannot be found"
             * error as soon as we *try* to access the various mail properties....
             * Stupid Outlook...
             *
             * Try another programming model?
             * Outlook seems to behave as when a user tries to access
             */
            try
            {
                str = "Recipients: " + email.Recipients.Count;
                TreeNode recipientNode = messageNode.Nodes.Add(str);
                txtBox.AppendText(str + "\n");
                foreach (Outlook.Recipient recipient in email.Recipients)
                {
                    Redemption.MAPIUtilsClass muc = new Redemption.MAPIUtilsClass();
                    String recp = (String)muc.HrGetOneProp(recipient.AddressEntry.MAPIOBJECT, 0x39FE001E);

                    str = recipient.Type + ": " + recipient.Address;
                    recipientNode.Nodes.Add(str);
                    txtBox.AppendText(str + "\n");
                }

                str = "Attachments: " + email.Attachments.Count;
                TreeNode attachmentNode = messageNode.Nodes.Add(str);
                txtBox.AppendText(str + "\n");
                SafeMailItem smi = new SafeMailItemClass();
                smi.Item = email;
                System.Collections.IEnumerator i = smi.Attachments.GetEnumerator();
                while (i.MoveNext() == true)
                {
                    Redemption.Attachment attachment = (Redemption.Attachment)i.Current;


                    str = attachment.FileName + ": " + attachment.Size + " bytes";
                    attachmentNode.Nodes.Add(str);
                    txtBox.AppendText(str + "\n");
                    // Check for SMIME attachment
                    if (attachment.FileName.Equals("smime.p7m"))
                    {
                        smimefound = true;
                        txtBox.AppendText("==== PKCS#7 Enveloped data ====\n");



                        parsePKCS7((byte [])attachment.AsArray, attachmentNode);
                    }
                }

                /*
                 * str = "Sub Messages: " + email.Messages.Count;
                 * TreeNode subMessageNode = messageNode.Nodes.Add(str);
                 * txtBox.AppendText(str + "\n");
                 * foreach (OutlookStorage.Message subMessage in message.Messages)
                 * {
                 *  this.loadMessage(subMessage, subMessageNode.Nodes.Add("MSG"));
                 * }
                 */
                if (smimefound)
                {
                    statusBar.Text = "S/MIME attachment(s) found!";
                }
                else
                {
                    statusBar.Text = "No S/MIME attachment(s) found!";
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
        }
예제 #7
0
        private static DateTime GetDate(SafeMailItemClass mailItem)
        {
            object oDate = mailItem.get_Fields(0x0E060040);
            if (oDate != null)
            {
                try
                {
                    DateTime dt = (DateTime)oDate;
                    return dt;
                }
                catch (InvalidCastException)
                {
                    Logging.Trace.WriteLine("An invalid date was returned from MAPI field.  On screen the date for this item will default to Now", "RedemptionMailConverter.HandleSendDate");
                }
            }

            return DateTime.Now;
        }
예제 #8
0
        private void HandleRecipients(SafeMailItemClass redemptionItem,
                                        UniversalRequestObject uro)
        {
			SafeRecipients recips = redemptionItem.Recipients;

			using (new ComObjectGovernor(recips))
			{
				for (int i = 1; i <= recips.Count; i++)
				{
					SafeRecipient recip = recips.Item(i);
					using (new ComObjectGovernor(recip))
					{
                        IRoutingItem routingItem = MakeSMTPRoutingItem(recip);

                        switch (recip.Type)
						{
							case 1:
								routingItem.Properties[SMTPItemPropertyKeys.AddressType] = AddressType.To;
								break;
							case 2:
                                routingItem.Properties[SMTPItemPropertyKeys.AddressType] = AddressType.CC;
                                break;
							case 3:
                                routingItem.Properties[SMTPItemPropertyKeys.AddressType] = AddressType.BCC;
                                break;
							default:
								break;
						}
                        uro.Destination.Items.Add(routingItem);
					}
				}
			}
        }
예제 #9
0
        /// <summary>
        /// Handle the originator field of a mail item.
        /// </summary>
        /// <param name="redemptionItem"></param>
        /// <param name="outMailItem"></param>
        /// <exception cref="FormatException"></exception>
        private void HandleOriginator(SafeMailItemClass redemptionItem,
                                        UniversalRequestObject uro)
        {
			if (redemptionItem != null)
			{
				AddressEntry sender = redemptionItem.Sender;
				Outlook.MailItem item = redemptionItem.Item as Outlook.MailItem;

				using (new ComObjectGovernor(sender))
				using (new ComObjectGovernor(item))
				{
					string smtpAddress = (string)sender.get_Fields(0x39FE001E);

					if (null == smtpAddress)
					{
						smtpAddress = GetUtils().HrGetOneProp(item.MAPIOBJECT, 0x0C1F001E) as string;

						if (null == smtpAddress)
						{
							Logging.Trace.WriteLine("Failed to get a valid smtp address for the originator of this message", "RedemptionMailConverter.HandleOriginator");
							throw new FormatException();
						}
					}

                    IRoutingItem sourceRoutingItem = new RoutingItem(smtpAddress);
                    sourceRoutingItem.Properties[SMTPItemPropertyKeys.AddressType] = AddressType.From;
                    sourceRoutingItem.Properties[SMTPItemPropertyKeys.DisplayName] = redemptionItem.SenderName;
                    sourceRoutingItem.Properties[SMTPItemPropertyKeys.Internal] = bool.FalseString;
                    uro.Source.Items.Add(sourceRoutingItem);
				}
			}
        }
예제 #10
0
		private static void HandleAttachments(SafeMailItemClass mailItem, UniversalRequestObject uro)
		{
			System.Text.StringBuilder sb = new System.Text.StringBuilder();

			Attachments mailAttachments = mailItem.Attachments;
			using (new ComObjectGovernor(mailAttachments))
			{
				string filenames = "";
				for (int i = 1; i <= mailAttachments.Count; i++)
				{
					Attachment attachmentToCopy = mailAttachments.Item(i);
					using (new ComObjectGovernor(attachmentToCopy))
					{
						sb.AppendFormat("{0} ", attachmentToCopy.DisplayName);

						object objAttach = attachmentToCopy.AsArray;
						byte[] bytes = objAttach as byte[];

						if (bytes != null)
						{
							System.IO.MemoryStream memStream = new System.IO.MemoryStream(bytes);
							bytes = null;

							using (System.Net.Mail.Attachment tempAttach = new System.Net.Mail.Attachment(memStream, attachmentToCopy.FileName))
							{
								filenames += tempAttach.Name;
								RequestAttachment ra = new RequestAttachment
									{
										Name = tempAttach.Name,
										ContentType = tempAttach.ContentType.ToString(),
										Data = new OptimizedBinaryData(tempAttach.ContentStream)
									};
								uro.Attachments.Add(ra);
							}
						}
					}
				}
			}

			uro.Properties.Add(MailMessagePropertyKeys.Attachments, sb.ToString());
		}
예제 #11
0
		private static void HandleUroProperties(SafeMailItemClass mailItem, UniversalRequestObject uro)
		{
            uro.PolicyType = PolicyType.ClientEmail;
            uro.DataTimeStamp = GetDate(mailItem);
			uro.Properties.Add(MailMessagePropertyKeys.FileHeader, String.Empty);
			uro.Properties.Add("RequestChannel", RequestChannel.Outlook.ToString());
		}