Ejemplo n.º 1
0
        public static string GetCustomMailTip(RecipientData recipientData, int traceId, int lcid)
        {
            MailTipsUtility.GetMailTipsTracer.TraceFunction((long)traceId, "Entering GetBestCustomMailTip");
            CultureInfo cultureInfo = null;

            try
            {
                cultureInfo = new CultureInfo(lcid);
            }
            catch (ArgumentException)
            {
                MailTipsUtility.GetMailTipsTracer.TraceDebug((long)traceId, "Exiting GetBestCustomMailTip - invalid culture, returning default");
                return(ADRecipient.DefaultMailTipGetter(recipientData.MailTipTranslations) as string);
            }
            object mailTipTranslations = recipientData.MailTipTranslations;

            if (mailTipTranslations == null)
            {
                return(null);
            }
            IList <string> list = (IList <string>)mailTipTranslations;

            if (list.Count == 0)
            {
                MailTipsUtility.GetMailTipsTracer.TraceDebug((long)traceId, "Exiting GetBestCustomMailTip - no values, returning null");
                return(null);
            }
            string result;

            if (list.Count != 1)
            {
                for (int i = 0; i < 10; i++)
                {
                    string name = cultureInfo.Name;
                    MailTipsUtility.GetMailTipsTracer.TraceDebug <string>((long)traceId, "Checking for custom MailTip for {0}", name);
                    if (MailTipsUtility.TryGetTranslation(list, name, out result))
                    {
                        MailTipsUtility.GetMailTipsTracer.TraceDebug((long)traceId, "Exiting GetBestCustomMailTip with match");
                        return(result);
                    }
                    if (cultureInfo == CultureInfo.InvariantCulture)
                    {
                        MailTipsUtility.GetMailTipsTracer.TraceDebug((long)traceId, "Exiting GetBestCustomMailTip with default");
                        return(ADRecipient.DefaultMailTipGetter(recipientData.MailTipTranslations) as string);
                    }
                    cultureInfo = cultureInfo.Parent;
                }
                return(ADRecipient.DefaultMailTipGetter(recipientData.MailTipTranslations) as string);
            }
            string text;

            if (ADRecipient.TryGetMailTipParts(list[0], out text, out result))
            {
                MailTipsUtility.GetMailTipsTracer.TraceDebug((long)traceId, "Exiting GetBestCustomMailTip - returning the sole value");
                return(result);
            }
            MailTipsUtility.GetMailTipsTracer.TraceDebug((long)traceId, "Exiting GetBestCustomMailTip - sole value corrupt, returning null");
            return(null);
        }
Ejemplo n.º 2
0
        internal void ParseUserOofSettings(UserOofSettings oofSettings, MailTips mailTips, int traceId)
        {
            if (oofSettings.OofState == OofState.Disabled)
            {
                MailTipsLocalQuery.GetMailTipsTracer.TraceDebug <object, EmailAddress>((long)traceId, "{0} / {1}: OutOfOffice is disabled", TraceContext.Get(), mailTips.EmailAddress);
                mailTips.OutOfOfficeMessage = string.Empty;
                return;
            }
            DateTime utcNow = DateTime.UtcNow;

            if (oofSettings.OofState == OofState.Scheduled && (utcNow > oofSettings.EndTime || utcNow < oofSettings.StartTime))
            {
                MailTipsLocalQuery.GetMailTipsTracer.TraceDebug <object, EmailAddress>((long)traceId, "{0} / {1}: OutOfOffice is Scheduled, but we're outside the scheduled interval", TraceContext.Get(), mailTips.EmailAddress);
                mailTips.OutOfOfficeMessage = string.Empty;
                return;
            }
            ReplyBody replyBody;

            if (MailTipsAccessLevel.All != mailTips.Permission.AccessLevel)
            {
                MailTipsLocalQuery.GetMailTipsTracer.TraceDebug <object, EmailAddress>((long)traceId, "{0} / {1}: MailTipsAccessLevel is not All, retrieving external auto reply.", TraceContext.Get(), mailTips.EmailAddress);
                replyBody = oofSettings.ExternalReply;
            }
            else if (this.clientContext is InternalClientContext)
            {
                MailTipsLocalQuery.GetMailTipsTracer.TraceDebug <object, EmailAddress>((long)traceId, "{0} / {1}: InternalClientContext detected, retrieving internal auto reply.", TraceContext.Get(), mailTips.EmailAddress);
                replyBody = oofSettings.InternalReply;
            }
            else
            {
                ExternalClientContext externalClientContext = (ExternalClientContext)this.clientContext;
                if (mailTips.Configuration.Domains.IsInternal(externalClientContext.EmailAddress.Domain))
                {
                    MailTipsLocalQuery.GetMailTipsTracer.TraceDebug((long)traceId, "{0} / {1}: ExternalClientContext detected and caller domain {2} is internal to recipient organization {3}, retrieving internal auto reply.", new object[]
                    {
                        TraceContext.Get(),
                        mailTips.EmailAddress,
                        externalClientContext.EmailAddress.Domain,
                        mailTips.Configuration.OrganizationConfiguration.Configuration.OrganizationId
                    });
                    replyBody = oofSettings.InternalReply;
                }
                else
                {
                    MailTipsLocalQuery.GetMailTipsTracer.TraceDebug((long)traceId, "{0} / {1}: ExternalClientContext detected and caller domain {2} is not internal to recipient organization {3}, retrieving external auto reply.", new object[]
                    {
                        TraceContext.Get(),
                        mailTips.EmailAddress,
                        externalClientContext.EmailAddress.Domain,
                        mailTips.Configuration.OrganizationConfiguration.Configuration.OrganizationId
                    });
                    replyBody = oofSettings.ExternalReply;
                }
            }
            if (replyBody == null || replyBody.RawMessage == null || RuleGenerator.IsEmptyString(replyBody.RawMessage))
            {
                MailTipsLocalQuery.GetMailTipsTracer.TraceDebug <object, EmailAddress>((long)traceId, "{0} / {1}: OutOfOfficeMessage is null or empty", TraceContext.Get(), mailTips.EmailAddress);
                mailTips.OutOfOfficeMessage = string.Empty;
                return;
            }
            MailTipsLocalQuery.GetMailTipsTracer.TraceDebug <object, EmailAddress, string>((long)traceId, "{0} / {1}: OutOfOffice message has been retrieved: {2}", TraceContext.Get(), mailTips.EmailAddress, replyBody.Message);
            string outOfOfficeMessage = MailTipsUtility.MakeSafeHtml(traceId, replyBody.Message);

            mailTips.OutOfOfficeMessage         = outOfOfficeMessage;
            mailTips.OutOfOfficeMessageLanguage = replyBody.LanguageTag;
            if (oofSettings.OofState == OofState.Scheduled)
            {
                mailTips.OutOfOfficeDuration = oofSettings.Duration;
            }
        }