Exemple #1
0
		private void ProcessSender(IEmailProxy proxy)
		{
			if ((null == m_uro) || (0 == m_uro.Source.Items.Count))
				return;

			IRoutingItem senderRoutingItem = m_uro.Source.Items[0];
			if (null == senderRoutingItem)
				return;

			EmailRecipient sender = new EmailRecipient();
			sender.EmailAddress = senderRoutingItem.Content;

			string displayName;
			if (senderRoutingItem.Properties.TryGetValue(SMTPPropertyKeys.DisplayName, out displayName))
			{
				sender.Name = displayName;
			}

			proxy.Sender = sender;
		}
		private EmailRecipient GetFromRecipient()
		{
			string senderEmailAddress = m_outlookMail.SenderEmailAddress;
			if (string.IsNullOrEmpty(senderEmailAddress))
				return null;

			EmailRecipient recipient = new EmailRecipient();
			recipient.Name = m_outlookMail.SenderName;
			recipient.EmailAddress = senderEmailAddress;
			recipient.Internal = true;

			return recipient;
		}
		private static void GetEmailDetailsFromSession(EmailRecipient currentUser, MSOutlook.Application app)
		{
			if (OutlookVersion.Convert(app.Version) < OutlookVersion.Version.Outlook2007)
				return; // no access to the accounts here, sorry

			if (app != null)
			{
				var sess = app.Session;
				if (sess != null)
				{
					var accts = sess.Accounts;
					if (accts != null)
					{
						for (int i = 1; i <= app.Session.Accounts.Count; i++)
						{
							var act = app.Session.Accounts[i];
							if (act.AccountType == MSOutlook.OlAccountType.olExchange)
							{
								currentUser.Name = act.DisplayName;
								currentUser.EmailAddress = act.SmtpAddress;
							}
						}

					}
				}
			}
		}
 private void GetSenderAsEmailRecipient()
 {
     using (var mailItem = m_oif.CreateWSMail(m_outlookMail))
     {
         var sender = mailItem.Sender;
         var currentUser = new EmailRecipient();
         if (sender != null)
         {
             currentUser.Name = sender.Name;
             currentUser.EmailAddress = sender.Address;
             OutlookRecipientsProxy.SetSmtpAddress(currentUser, sender.GetFields(MapiDefines.PR_EMS_AB_PROXY_ADDRESSES));
         }
         else
         {
             currentUser.Name = "Unknown sender";
             currentUser.EmailAddress = "Unknown email address";
             if (mailItem.MailItem != null)
             {
                 var app = mailItem.MailItem.Application;
                 GetEmailDetailsFromSession(currentUser, app);
             }
         }
         currentUser.Internal = true;
         m_currentUser = currentUser;
     }
 }
		private void GetSenderAsEmailRecipient()
		{
			IWSAddressEntry sender = m_mailItem.Sender;
			m_currentUser = new EmailRecipient();
			m_currentUser.Name = sender.Name;
			m_currentUser.EmailAddress = sender.Address;
			SetSmtpAddress(m_currentUser, sender.GetFields(MapiDefines.PR_EMS_AB_PROXY_ADDRESSES));
			m_currentUser.Internal = true;
		}
		internal static void SetSmtpAddress(EmailRecipient recipient, object list)
		{
			if (Workshare.DirectorySearcher.AddressUtils.GetAddressType(recipient.EmailAddress) == Workshare.DirectorySearcher.AddressType.Smtp)
				return;

			string smtpAddress = ExtractSmtpAddress(list);
			if (!string.IsNullOrEmpty(smtpAddress))
			{
				recipient.EmailAddress = smtpAddress;
			}
		}
		private static EmailRecipient GetSessionUser()
		{
			if (m_currentUser != null)
				return m_currentUser;

			OutlookIImplFactory oif = new OutlookIImplFactory();
            using (IWSUtilities utils = oif.CreateUtilities())
            {
				using (IWSCurrentUser currentUser = utils.CurrentUser)
				{
					m_currentUser = new EmailRecipient();
					m_currentUser.Name = currentUser.Name;
					m_currentUser.EmailAddress = currentUser.Address;
					SetSmtpAddress(m_currentUser, currentUser.GetFields(MapiDefines.PR_EMS_AB_PROXY_ADDRESSES));
					m_currentUser.Internal = true;
				}
            }
			return m_currentUser;
		}
Exemple #8
0
		private void ProcessRecipients(IEmailProxy proxy)
		{
			if ((null == m_uro) || (0 == m_uro.Destination.Items.Count))
				return;

			proxy.ToRecipients.Clear();
			proxy.CcRecipients.Clear();
			proxy.BccRecipients.Clear();

			foreach (IRoutingItem routingItem in m_uro.Destination.Items)
			{
				string readOnlyValue;
				if (routingItem.Properties.TryGetValue(EmailProperties.ReadOnlyKey, out readOnlyValue))
				{
					if (System.Convert.ToBoolean(readOnlyValue, System.Globalization.CultureInfo.InvariantCulture))
						continue;
				}

				EmailRecipient recipient = new EmailRecipient();
				recipient.EmailAddress = routingItem.Content;

				string displayName;
				if (routingItem.Properties.TryGetValue(SMTPPropertyKeys.DisplayName, out displayName))
				{
					recipient.Name = displayName;
				}

				string addressType;
				if (!routingItem.Properties.TryGetValue(SMTPItemPropertyKeys.AddressType, out addressType))
					continue;

				switch (addressType)
				{
				case AddressType.To:
					proxy.ToRecipients.Add(recipient);
					break;
				case AddressType.CC:
					proxy.CcRecipients.Add(recipient);
					break;
				case AddressType.BCC:
					proxy.BccRecipients.Add(recipient);
					break;
				default:
					break;
				}
			}
		}
Exemple #9
0
		private EmailRecipient GetRecipientFromEntryId(object entryId, bool isInternal)
		{
			if (null == entryId)
				return null;

			string recipientEntryIdString = EntryIdToString(entryId);
			if (string.IsNullOrEmpty(recipientEntryIdString))
				return null;

            using (IWSUtilities utils = m_oif.CreateUtilities())
            {
                using (IWSAddressEntry recipientAddressEntry = utils.GetAddressEntryFromID(recipientEntryIdString))
                {
                    if ((null == recipientAddressEntry) || (string.IsNullOrEmpty(recipientAddressEntry.Name)) ||
                        (string.IsNullOrEmpty(recipientAddressEntry.Address)))
                        return null;

                    EmailRecipient recipient = new EmailRecipient();
                    recipient.Name = recipientAddressEntry.Name;
                    recipient.EmailAddress = recipientAddressEntry.Address;
                    SetSmtpAddress(recipient, recipientAddressEntry.GetFields(MapiDefines.PR_EMS_AB_PROXY_ADDRESSES));
                    recipient.Internal = isInternal;
                    return recipient;
                }
            }
		}
Exemple #10
0
		private EmailRecipient GetSessionUser()
		{
			EmailRecipient sessionUser = null;
            using (IWSUtilities utils = m_oif.CreateUtilities())
            {
                using (IWSCurrentUser currentUser = utils.CurrentUser)
                {
                    sessionUser = new EmailRecipient();
                    try
                    {
                        sessionUser.Name = currentUser.Name;
                        sessionUser.EmailAddress = currentUser.Address;
                        SetSmtpAddress(sessionUser, currentUser.GetFields(MapiDefines.PR_EMS_AB_PROXY_ADDRESSES));
                    }
                    catch (Exception)
                    {
                        //If we cannot get user name and address we will set these params to default values. See OutlookMailProxy.GetSenderAsEmailRecipient()
                    }
                    sessionUser.Internal = true;
                }
            }
		    return sessionUser;
		}
Exemple #11
0
		private EmailRecipient GetFromRecipient()
		{
            if (string.IsNullOrEmpty(SenderEmailAddress))
                return null;
			
            IWSAddressEntry addressEntry = null;
            using (IWSUtilities utils = m_oif.CreateUtilities())
            {
                addressEntry = utils.GetRecipientAsAddressEntry(SenderEmailAddress);                
            }

            if (addressEntry == null)
                return null;

            EmailRecipient recipient = new EmailRecipient();
            recipient.EmailAddress = SenderEmailAddress;
            recipient.Name = string.IsNullOrEmpty(SenderName) ? SenderEmailAddress : SenderName;                
            recipient.Internal = RecipientType.IsInternal(addressEntry);
            return recipient;                      
		}
Exemple #12
0
		private EmailRecipient GetFirstReplyRecipient()
		{
			if (0 == ReplyRecipients.Count)
				return null;

			IWSRecipient firstReplyRecipient = ReplyRecipients.Item(0);
			if (null == firstReplyRecipient)
				return null;

			IWSAddressEntry addressEntry = firstReplyRecipient.AddressEntry;
			if (null == addressEntry)
				return null;

			EmailRecipient recipient = new EmailRecipient();
			recipient.EmailAddress = addressEntry.Address;
			recipient.Name = string.IsNullOrEmpty(addressEntry.Name) ? addressEntry.Address : addressEntry.Name;
            recipient.Internal = RecipientType.IsInternal(addressEntry);

			addressEntry.Dispose();
			firstReplyRecipient.Dispose();

			return recipient;
		}
        public void TestProxy()
        {
            using (WsActivationContext wsac = new WsActivationContext())
            {
                CreateNotesProxy();
                Assert.IsNotNull(m_notesProxy);

                string subject = "Plain text e-mail: This is a test mail";
                m_notesProxy.SetSubject(subject);
                m_notesProxy.SetSender("DevBuild<*****@*****.**>");
                m_notesProxy.SetResolvedRecipientsTypeToken("INTERNAL_TOKEN_F19CA8B3B44d13BCE9A38EC838E2C3224F74F2554c9586EA5DEBBCAD7F");
                m_notesProxy.SetPriority(NotesProxy.NotesMailPriority.Normal);
                string body = "We have a body that looks like something";
                m_notesProxy.SetBody(body);

                NotesProxy.Attachment proxyAttachment = new NotesProxy.AttachmentClass();
                proxyAttachment.SetDisplayName("test.doc");
                proxyAttachment.SetFileName(m_testPath + "test.doc");
                proxyAttachment.SetContentItemIndex(1);
                proxyAttachment.SetContentId("B61002A0-1A85-48a5-9A95-7F254EECECF1");
                m_notesProxy.AddAttachment(proxyAttachment);

                NotesMailProxy proxy = new NotesMailProxy(m_notesProxy);

                Assert.AreEqual(Workshare.Mime.Conversions.Priority.Normal, proxy.Priority);
                proxy.Priority = Workshare.Mime.Conversions.Priority.High;
                Assert.AreEqual(Workshare.Mime.Conversions.Priority.High, proxy.Priority);
                proxy.Priority = Workshare.Mime.Conversions.Priority.Normal;

                Assert.AreEqual("Plain text e-mail: This is a test mail", proxy.Subject);

                subject = "Let change the subject";
                proxy.Subject = subject;
                Assert.AreEqual(subject, m_notesProxy.GetSubject());

                Assert.AreEqual(body, proxy.FormattedBodyText);
                body = "The body has been changed";
                proxy.FormattedBodyText = body;
                Assert.AreEqual(body, proxy.FormattedBodyText);

                Assert.AreEqual("DevBuild", proxy.Sender.Name);
                Assert.AreEqual("*****@*****.**", proxy.Sender.EmailAddress);

                EmailRecipient newSender = new EmailRecipient();
                newSender.Name = "phantom";
                newSender.EmailAddress = "*****@*****.**";

                proxy.Sender = newSender;

                Assert.AreEqual("phantom", proxy.Sender.Name);
                Assert.AreEqual("*****@*****.**", proxy.Sender.EmailAddress);

                Assert.AreEqual(1, proxy.ToRecipients.Count);
                Assert.AreEqual(1, proxy.CcRecipients.Count);
                Assert.AreEqual(1, proxy.BccRecipients.Count);

                Assert.AreEqual("INTERNAL_TOKEN_F19CA8B3B44d13BCE9A38EC838E2C3224F74F2554c9586EA5DEBBCAD7F", proxy.ToRecipients[0].Name);
                Assert.AreEqual("INTERNAL_TOKEN_F19CA8B3B44d13BCE9A38EC838E2C3224F74F2554c9586EA5DEBBCAD7F", proxy.ToRecipients[0].EmailAddress);

                Assert.AreEqual("INTERNAL_TOKEN_F19CA8B3B44d13BCE9A38EC838E2C3224F74F2554c9586EA5DEBBCAD7F", proxy.CcRecipients[0].Name);
                Assert.AreEqual("INTERNAL_TOKEN_F19CA8B3B44d13BCE9A38EC838E2C3224F74F2554c9586EA5DEBBCAD7F", proxy.CcRecipients[0].EmailAddress);

                Assert.AreEqual("INTERNAL_TOKEN_F19CA8B3B44d13BCE9A38EC838E2C3224F74F2554c9586EA5DEBBCAD7F", proxy.BccRecipients[0].Name);
                Assert.AreEqual("INTERNAL_TOKEN_F19CA8B3B44d13BCE9A38EC838E2C3224F74F2554c9586EA5DEBBCAD7F", proxy.BccRecipients[0].EmailAddress);
                
                // Lets test the recipient iterator as well
                foreach (IEmailRecipient recipient in proxy.ToRecipients)
                {
                    Assert.IsTrue(recipient.Name.Contains("INTERNAL_TOKEN_F19CA8B3B44d13BCE9A38EC838E2C3224F74F2554c9586EA5DEBBCAD7F"));
                }

                Assert.AreEqual(1, proxy.Attachments.Count);
                Assert.AreEqual("test.doc", proxy.Attachments[0].DisplayName);
                Assert.AreEqual("application/msword; name=test.doc", proxy.Attachments[0].ContentType);
                Assert.IsTrue(proxy.Attachments[0].FileName.Contains("test.doc"), "Expected to find a non-empty stream");

                // Lets test the attachment iterator as well
                foreach (IEmailAttachment attachment in proxy.Attachments)
                {
                    Assert.IsTrue(attachment.DisplayName.Contains("test.doc"));
                }
            }
        }
Exemple #14
0
        public void TestSetRecipients()
        {
            using (Stream mimeStream = new MemoryStream())
            using (MimeProxy proxy = new MimeProxy(mimeStream))
            {
                Assert.AreEqual(0, proxy.ToRecipients.Count);
                Assert.AreEqual(0, proxy.CcRecipients.Count);
                Assert.AreEqual(0, proxy.BccRecipients.Count);

                EmailRecipient recipient = new EmailRecipient();

                recipient.Name = "blackhole";
                recipient.EmailAddress = "*****@*****.**";

                proxy.ToRecipients.Add(recipient);

                Assert.AreEqual(1, proxy.ToRecipients.Count);
                Assert.AreEqual(0, proxy.CcRecipients.Count);
                Assert.AreEqual(0, proxy.BccRecipients.Count);

                // Copy the To Recipients to Cc Recipients
                proxy.CcRecipients = proxy.ToRecipients;

                Assert.AreEqual(1, proxy.ToRecipients.Count);
                Assert.AreEqual(1, proxy.CcRecipients.Count);
                Assert.AreEqual(0, proxy.BccRecipients.Count);

                recipient.Name = "blackhole2";
                recipient.EmailAddress = "*****@*****.**";
                
                proxy.CcRecipients.Add(recipient);

                Assert.AreEqual(1, proxy.ToRecipients.Count);
                Assert.AreEqual(2, proxy.CcRecipients.Count);
                Assert.AreEqual(0, proxy.BccRecipients.Count);

                // Copy the To Recipients to Cc Recipients
                proxy.CcRecipients = proxy.ToRecipients;

                Assert.AreEqual(1, proxy.ToRecipients.Count);
                Assert.AreEqual(1, proxy.CcRecipients.Count);
                Assert.AreEqual(0, proxy.BccRecipients.Count);

                recipient.Name = "blackhole2";
                recipient.EmailAddress = "*****@*****.**";

                proxy.CcRecipients.Add(recipient);

                Assert.AreEqual(1, proxy.ToRecipients.Count);
                Assert.AreEqual(2, proxy.CcRecipients.Count);
                Assert.AreEqual(0, proxy.BccRecipients.Count);

                // Copy the Cc Recipients to To Recipients
                proxy.ToRecipients = proxy.CcRecipients;

                Assert.AreEqual(2, proxy.ToRecipients.Count);
                Assert.AreEqual(2, proxy.CcRecipients.Count);
                Assert.AreEqual(0, proxy.BccRecipients.Count);

                // Copy the Cc Recipients to Bcc Recipients
                proxy.BccRecipients = proxy.CcRecipients;

                Assert.AreEqual(2, proxy.ToRecipients.Count);
                Assert.AreEqual(2, proxy.CcRecipients.Count);
                Assert.AreEqual(2, proxy.BccRecipients.Count);

                recipient.Name = "blackhole3";
                recipient.EmailAddress = "*****@*****.**";

                proxy.CcRecipients.Add(recipient);

                Assert.AreEqual(2, proxy.ToRecipients.Count);
                Assert.AreEqual(3, proxy.CcRecipients.Count);
                Assert.AreEqual(2, proxy.BccRecipients.Count);

                // Copy the Cc Recipients to Bcc Recipients
                proxy.BccRecipients = proxy.CcRecipients;

                Assert.AreEqual(2, proxy.ToRecipients.Count);
                Assert.AreEqual(3, proxy.CcRecipients.Count);
                Assert.AreEqual(3, proxy.BccRecipients.Count);

                recipient.Name = "blackhole4";
                recipient.EmailAddress = "*****@*****.**";

                proxy.BccRecipients.Add(recipient);

                Assert.AreEqual(2, proxy.ToRecipients.Count);
                Assert.AreEqual(3, proxy.CcRecipients.Count);
                Assert.AreEqual(4, proxy.BccRecipients.Count);
            }
        }
Exemple #15
0
        public void TestModifyMimeUsingProxy()
        {
            using (Stream mimeStream = new MemoryStream())
            using (MimeProxy proxy = new MimeProxy(mimeStream))
            {
                proxy.Sender.Name = "lnpair";
                proxy.Sender.EmailAddress = "*****@*****.**";

                Assert.AreEqual("lnpair", proxy.Sender.Name);
                Assert.AreEqual("*****@*****.**", proxy.Sender.EmailAddress);

                EmailRecipient recipient = new EmailRecipient();

                recipient.Name = "blackhole";
                recipient.EmailAddress = "blackhole1";

                proxy.ToRecipients.Add(recipient);

                recipient.Name = "blackhole";
                recipient.EmailAddress = "blackhole2";

                proxy.ToRecipients.Add(recipient);

                proxy.ToRecipients[0].Name += "1";
                proxy.ToRecipients[0].EmailAddress += "@workshare.com";

                proxy.ToRecipients[1].Name += "2";
                proxy.ToRecipients[1].EmailAddress += "@workshare.com";

                recipient.Name = "blackhole3";
                recipient.EmailAddress = "*****@*****.**";

                proxy.CcRecipients.Add(recipient);

                recipient.Name = "blackhole4";
                recipient.EmailAddress = "*****@*****.**";

                proxy.BccRecipients.Add(recipient);

                proxy.FormattedBodyText = "This body is plain text.";
                proxy.FormattedBodyText += " And don't forget it!";

                Assert.AreEqual("This body is plain text. And don't forget it!", proxy.FormattedBodyText);

                proxy.Subject = "TestPlainTextMessageBody";
                proxy.Subject += " processed.";

                Assert.AreEqual("TestPlainTextMessageBody processed.", proxy.Subject);
                
                Assert.AreEqual(2, proxy.ToRecipients.Count);
                Assert.AreEqual(1, proxy.CcRecipients.Count);
                Assert.AreEqual(1, proxy.BccRecipients.Count);

                Assert.AreEqual("blackhole1", proxy.ToRecipients[0].Name);
                Assert.AreEqual("*****@*****.**", proxy.ToRecipients[0].EmailAddress);
                Assert.AreEqual("blackhole2", proxy.ToRecipients[1].Name);
                Assert.AreEqual("*****@*****.**", proxy.ToRecipients[1].EmailAddress);

                Assert.AreEqual("blackhole3", proxy.CcRecipients[0].Name);
                Assert.AreEqual("*****@*****.**", proxy.CcRecipients[0].EmailAddress);

                Assert.AreEqual("blackhole4", proxy.BccRecipients[0].Name);
                Assert.AreEqual("*****@*****.**", proxy.BccRecipients[0].EmailAddress);

                EmailAttachment attachment = new EmailAttachment();
                attachment.DisplayName = "test.ppt";
                attachment.FileName = Path.Combine(m_testPath, "test.ppt");
                proxy.Attachments.Add(attachment);

                Assert.AreEqual(1, proxy.Attachments.Count);

                Assert.AreEqual("test.ppt", proxy.Attachments[0].DisplayName);
                Assert.AreEqual("application/vnd.ms-powerpoint; name=test.ppt", proxy.Attachments[0].ContentType);
                Assert.IsTrue(proxy.Attachments[0].FileName.Contains("test.ppt"), "Expected to find a non-empty stream");

                // Now, lets modify the recipients via the enumerator
                foreach (IEmailRecipient recip in proxy.ToRecipients)
                {
                    recip.Name += " Changed";
                    recip.EmailAddress += "ified";
                }

                Assert.AreEqual(2, proxy.ToRecipients.Count);
                Assert.AreEqual("blackhole1 Changed", proxy.ToRecipients[0].Name);
                Assert.AreEqual("*****@*****.**", proxy.ToRecipients[0].EmailAddress);
                Assert.AreEqual("blackhole2 Changed", proxy.ToRecipients[1].Name);
                Assert.AreEqual("*****@*****.**", proxy.ToRecipients[1].EmailAddress);
            }
        }