Exemplo n.º 1
0
        public async Task <List <FocusedInboxOverride> > GetFocusedInboxOverridesAsync()
        {
            // Get the overrides that a user has set up to always classify messages from certain senders in specific ways.

            Uri URL = new Uri("https://outlook.office.com/api/v2.0/me/InferenceClassification/Overrides");

            string stringResponse = "";

            try
            {
                stringResponse = await SendGetRequestAsync(URL);
            }
            catch (Exception ex)
            {
                throw ex;
            }

            // Convert JSON response.

            var jsonResponse = (JObject)JsonConvert.DeserializeObject(stringResponse);
            var messages     = (JArray)jsonResponse.GetValue("value");

            List <FocusedInboxOverride> result = new List <FocusedInboxOverride>();

            foreach (var item in messages)
            {
                string id         = item.Value <string>("Id");
                string classifyAs = item.Value <string>("ClassifyAs");

                JObject jObjectSender             = item.Value <JObject>("SenderEmailAddress");
                FocusedInboxOverrideSender sender = new FocusedInboxOverrideSender();

                if (jObjectSender != null && jObjectSender.TryGetValue("Address", out JToken jTokenAddress))
                {
                    sender.Address = jTokenAddress.Value <string>();
                }

                if (jObjectSender != null && jObjectSender.TryGetValue("Name", out JToken jTokenName))
                {
                    sender.Name = jTokenName.Value <string>();
                }

                result.Add(new FocusedInboxOverride
                {
                    Id                 = id,
                    ClassifyAs         = (Classify)Enum.Parse(typeof(Classify), classifyAs, true),
                    SenderEmailAddress = sender
                });
            }

            return(result);
        }
Exemplo n.º 2
0
        public static bool TryCreate(string name, string address, out FocusedInboxOverrideSender result)
        {
            // Validate the email address.

            try
            {
                MailAddress mailAddress = new MailAddress(address);

                result = new FocusedInboxOverrideSender(name, address);
                return(true);
            }
            catch
            {
                result = null;
                return(false);
            }
        }
Exemplo n.º 3
0
        public async Task <List <FocusedInboxOverride> > GetFocusedInboxOverridesAsync()
        {
            // Get the overrides that a user has set up to always classify messages from certain senders in specific ways.

            Uri URL = Util.UseMicrosoftGraphInMailboxViewer ? new Uri("https://graph.microsoft.com/v1.0/me/inferenceClassification/overrides") : new Uri("https://outlook.office.com/api/v2.0/me/InferenceClassification/Overrides");

            string stringResponse = "";

            try
            {
                stringResponse = await SendGetRequestAsync(URL);
            }
            catch (Exception ex)
            {
                throw ex;
            }

            // Convert JSON response.

            var jsonResponse = (JObject)JsonConvert.DeserializeObject(stringResponse);
            var messages     = (JArray)jsonResponse.GetValue("value");

            List <FocusedInboxOverride> result = new List <FocusedInboxOverride>();

            string idAttributeName;
            string classifyAsAttributeName;
            string senderEmailAddressAttributeName;
            string addressAttributeName;
            string nameAttributeNmae;

            if (Util.UseMicrosoftGraphInMailboxViewer)
            {
                idAttributeName                 = "id";
                classifyAsAttributeName         = "classifyAs";
                senderEmailAddressAttributeName = "senderEmailAddress";
                addressAttributeName            = "address";
                nameAttributeNmae               = "name";
            }
            else
            {
                idAttributeName                 = "Id";
                classifyAsAttributeName         = "ClassifyAs";
                senderEmailAddressAttributeName = "SenderEmailAddress";
                addressAttributeName            = "Address";
                nameAttributeNmae               = "Name";
            }

            foreach (var item in messages)
            {
                string id         = item.Value <string>(idAttributeName);
                string classifyAs = item.Value <string>(classifyAsAttributeName);

                JObject jObjectSender             = item.Value <JObject>(senderEmailAddressAttributeName);
                FocusedInboxOverrideSender sender = new FocusedInboxOverrideSender();

                if (jObjectSender != null && jObjectSender.TryGetValue(addressAttributeName, out JToken jTokenAddress))
                {
                    sender.Address = jTokenAddress.Value <string>();
                }

                if (jObjectSender != null && jObjectSender.TryGetValue(nameAttributeNmae, out JToken jTokenName))
                {
                    sender.Name = jTokenName.Value <string>();
                }

                result.Add(new FocusedInboxOverride
                {
                    Id                 = id,
                    ClassifyAs         = (Classify)Enum.Parse(typeof(Classify), classifyAs, true),
                    SenderEmailAddress = sender
                });
            }

            return(result);
        }