WorkshareProfileCollection IWorkshareProfileProvider.GetProfiles()
		{
			WorkshareProfileCollection profiles = new WorkshareProfileCollection();

			int profileCount = _provider.GetProfilesCount();
			for (int i = 0; i < profileCount; i++)
			{
				Notes.IProfile profile = _provider.GetProfile(i);
				ServerProfile serverProfile = new ServerProfile(profile.GetName(), profile.GetDescription(), profile.GetDisplayName(), profile.GetEmailAddress());

                if (string.IsNullOrEmpty(serverProfile.Name) || string.IsNullOrEmpty(serverProfile.EmailAddress))
                {
                    Logger.LogError("Failed to add the Server Profile to the collection. Either the Name or EmailAddress is invalid.");
                    continue;
                }

				Logger.LogDebug(string.Format(
					"Adding server profile \"{0}\" with email address \"{1}\".",
					serverProfile.Name, serverProfile.EmailAddress));

				profiles.Add(i, serverProfile);
			}

			// Always insert a "Workshare Default Server Profile at the end"
			// The Workshare default is defined by an email address with an empty string.
			Logger.LogDebug("Adding default server profile with empty email address.");
			profiles.Add(profiles.Count + 1, new ServerProfile(
				DefaultServerProfileName, DefaultServerProfileDescription,
				string.Empty, 0, string.Empty));

			return profiles;
		}
		WorkshareProfileCollection IWorkshareProfileProvider.GetProfiles()
		{
            var profiles = new WorkshareProfileCollection();
			
            try
			{
                profiles = GetServerProfile();
			}
            catch (Exception ex)
            {
                Logger.LogError(ex);
            }
                        
            profiles.Add(profiles.Count, GetDefaultProfile());
	        return profiles;			
		}
        private WorkshareProfileCollection GetServerProfile()
        {   
            var profiles = new WorkshareProfileCollection();
            
            if (_provider == null)
            {
                Logger.LogError("Provider (Outlook.Application) is null or has not been set.");
                return profiles;
            }

            if (string.IsNullOrEmpty(_distributionListName))
            {
                Logger.LogError("DistributionListName is null or has not been set.");
                return profiles;
            }

            RecipientsProxy.OutlookSecurity.Instance.Disable();
            try
            {
                Redemption.RDOSession session = RedemptionLoader.new_RDOSession();
                session.MAPIOBJECT = _provider.Session.MAPIOBJECT;

				Redemption.RDOAddressEntry dl = FindAddressEntry(session.AddressBook.GAL.ResolveNameEx(_distributionListName), _distributionListName);
                if (dl == null)
                {
                    Redemption.IRDOAddressList con = FindAddressList(session.AddressBook.AddressLists(), "Contacts");
                    if (con != null)
                    {
                        dl = FindAddressEntry(con.AddressEntries, _distributionListName);    
                    }
                    
                    if (dl == null)
                    {
                        Logger.LogError("DistributionList not found in either GAL or Contacts");
                        return profiles;
                    }
                }               

                int profileIndex = 1;
                foreach (Redemption.RDOAddressEntry entry in dl.Members)
                {
                    string profileDescription = entry.Name;
                    try
                    {
                        // Profile description will be specified in 'Notes' property for a contact in Exchange Server
                        // 'Notes' property is available through 'Comments' property of ExhchangeUser.
                        profileDescription = entry.Comments;
                    }
                    catch (Exception ex)
                    {
                        Logger.LogError("Unable to find Profile Description. Setting to Profile Name.");
                        Logger.LogError(ex);
                    }

                    ServerProfile sp = new ServerProfile(entry.Name, profileDescription, String.IsNullOrWhiteSpace(entry.SMTPAddress) ? entry.Address : entry.SMTPAddress);
                    profiles.Add(profileIndex - 1, sp);
                    profileIndex++;

                    Logger.LogDebug(string.Format("Server profile \"{0}\" and email address \"{1}\" added", sp.Name, sp.EmailAddress));
                }
                                
                return profiles;
            }
            finally
            {
                if (_provider == null)
                {
                    RecipientsProxy.OutlookSecurity.Instance.Enable();
                }
            }
        }
Example #4
0
		private void OnItemSend(MailItem mailItem, bool hasLargeAttachments, ref bool cancelEmailSend)
		{
			MailClientHookBase.PreCacheEventWaitForCompletion();

			MailAttachmentTransform msgHandler = null;
		    Request request = null;
			try
			{
				InitClientProgress();

				request = CreateRequest(mailItem);
			    request.HasLargeAttachments = hasLargeAttachments;

				//WriteOutRequest(request);

                msgHandler = new MailAttachmentTransform(GetMsgNestingLevelOption(), m_application, DisableAccessToDOMAttachments);
				List<Attachment> allAttachments = msgHandler.Flatten(request);
				if (msgHandler.AtLeastOneEmail)
				{
					request.Attachments = allAttachments.ToArray();
				}

				m_uiManager.ParentHwnd = m_parentWnd;
				RequestManager requestManager = new RequestManager(request, m_uiManager, msgHandler.ExpandMSG, msgHandler.PackMSG);
				requestManager.TotalAttachmentSize = GetTotalAttachmentSize(mailItem);
				requestManager.IsSimpleMapi = IsSimpleMapi;
				requestManager.MailItem = mailItem;

				using (new WsActivationContext())
				{
					bool bDisplayProgress = DisplayProgressOnMailSend(request);

					requestManager.SendAndProtect = SendAndProtect;
				    requestManager.HasLargeAttachments = request.HasLargeAttachments;
					ProcessResult result;
					if (ProtectSimple)
					{
						bool isCorporateAccount = GetAccountType(mailItem) == MsOutlook.OlAccountType.olExchange;
                        requestManager.ProtectSimpleProfiles = GetWorkshareProfiles(mailItem.Application, request, isCorporateAccount, msgHandler.AtLeastOneEmail);
                        
                        // If any of the attachment is a large attachment, then just show send-link profiles, remove everything else
                        if (request.HasLargeAttachments)
                        {
                            int i = 0;
                            var profiles = new WorkshareProfileCollection();
                            foreach (WorkshareProfile profile in requestManager.ProtectSimpleProfiles.Values)
                            {
								if (profile.Name.Contains("Secure File Transfer"))
                                {
                                    profiles.Add(i++, profile);
                                }
                            }

                            requestManager.ProtectSimpleProfiles = profiles;
                        }
						result = requestManager.ProcessRequestForProtectSimple(bDisplayProgress, isCorporateAccount);
					}
					else
					{
						result = requestManager.ProcessRequest(m_clientProgress, bDisplayProgress, IsDynamicDiscoveryEnabled(request));
					}

					switch (result)
					{
					case ProcessResult.CANCELLED:
						cancelEmailSend = true;
						break;

					case ProcessResult.PROCESSED:
						cancelEmailSend = false;
						//////////////////////////////////////////////////////////////////////////////////////////
						// JE - 21.01.2010
						// This code block ensures that for simple attachments (i.e not containers - zip,msg)
						// we will only replace the attachment on the email if we have processed it.
						// Container atachments will currently always be replaced with rebuilt versions
						// that contain copies of the original files that may or may not have been processed.
						//////////////////////////////////////////////////////////////////////////////////////////

						Attachment[] builtup = requestManager.EnforceResponse.ModifiedRequest.Attachments;
						if (requestManager.ReplaceAllAttachments())
						{
							// This is used for the Cryptzone Secure Email Action
							// We can only support one Action that has this property and still function
							// in a reasonable fashion since we are allowing the Action to remove all 
							// attachments and replace then with completely new ones. JE 19.10.2011
							msgHandler.ReplaceAttachments(mailItem, builtup);
						}
						else
						{
							List<Attachment> processedbuiltup = requestManager.GetTopLevelProcessedAttachments();

							// VE263 Consolidate all the attachments (processed and unprocessed), so that we can recreate the email and have all the attachments in their original order.
							// Otherwise modified attachments would be added to the end of the attachment list, ie no longer in the original order.
							builtup = BuildMsgAndProcessedAttachments(msgHandler, builtup, processedbuiltup);
							if (SendLinkBase.ShouldExecuteSendLinkAction(requestManager.Response))
							{
								IsSendLink = ExecuteSendLinkAction(mailItem, builtup, requestManager);
								cancelEmailSend = !IsSendLink;
							}
							else
							{
								msgHandler.ReplaceProcessedAttachments(mailItem, builtup, requestManager.GetGroupedZipOptions());
							}
						}

						if (!cancelEmailSend)
						{
							if (IsSendLink)
							{
								SendLinkUpdateEmailContent(mailItem, requestManager.EnforceResponse.ModifiedRequest);
							}
							else
							{
								UpdateEmailContent(mailItem, requestManager.EnforceResponse.ModifiedRequest);
							}
							SetHeaderProcessingInfo(mailItem, requestManager.EnforceResponse.ModifiedRequest);
						    SetProcessedByWorkshareProtect(mailItem);

							RemoveCustomProperties(mailItem);
						}
						break;

					//VE 4955 - Don't tag the message (XHeader). Protect Server should 
					//process the message if Protect Client failed to process the message
					//and the user selected to send anyway.
					case ProcessResult.ERROR_OVERRIDE_USER_SELECTED_SEND:
						cancelEmailSend = false;
						break;

					// I presume that an Exception result is actually
					// handled by a catch block, but case added here
					// to make sure that we show an error if it isn't.
					case ProcessResult.ERRORS:
					case ProcessResult.EXCEPTION:
						cancelEmailSend = !HandleErrors(requestManager.Errors);
						break;

					default: //no violations or actions for this email - continue to send it.

                        if (request.HasLargeAttachments)
                        {
                            // and no policy triggered (probably because they are all not-supported types)
                            // then we need to replace the place-holder-files (for large attachments) with actual attachments 
                            msgHandler.ReplaceAttachments(mailItem, request.Attachments);
                        }

                        IsProtectDisabledForCurrentRouting = true;
						cancelEmailSend = false;
						SetHeaderProcessingInfo(mailItem, requestManager.Request);
					    SetProcessedByWorkshareProtect(mailItem);
						RemoveCustomProperties(mailItem);
						break;
					}
				}
			}
			catch (Exception ex)
			{
				cancelEmailSend = !ShouldContinueAfterException(ex);
			}
			finally
			{
                if (!cancelEmailSend && request != null)
                {
                    foreach (var att in request.Attachments)
                    {
                        ContentEncryptionManager.ClearPasswordCacheFor(att);
                    }
                }

				if (m_clientProgress != null)
				{
					m_clientProgress.Complete();
					m_clientProgress.Close();
				}

                if (request != null)
                {
                    request.Dispose();
                    request = null;
                }

			    // Explicitly clear up Redemption in case any extended MAPI objects are left lying around
				IWSUtilities utils = Oif.CreateUtilities();
				utils.Cleanup();

				if (msgHandler != null)
				{
					msgHandler.Dispose();
				}

				Interop.Logging.Logger.LogInfo("Shutting down application cache instance.");
				OfficeApplicationCache.Instance.ShutDown();
			}
		}