Exemplo n.º 1
0
        public static List <Attachment> convertAttachments(JArray attachments)
        {
            try
            {
                List <Attachment> result_files = new List <Attachment>();

                foreach (JToken attachment in attachments)
                {
                    //get the content
                    Stream content = new MemoryStream(attachment["content"]["data"].ToObject <byte[]>());

                    //create attachment
                    Attachment mail_attachment = new Attachment(content, attachment["filename"].ToString(), attachment["contentType"].ToString());

                    result_files.Add(mail_attachment);
                }

                return(result_files);
            }
            catch (Exception ex)
            {
                COMMON_FUNCTIONS.storeError("FORWARD_COMMON", MethodBase.GetCurrentMethod().ReflectedType.Name, ex.ToString());
                return(null);
            }
        }
Exemplo n.º 2
0
        public IActionResult RetrieveMail([FromBody] JsonElement mail)
        {
            try
            {
                if (mail.ToString() == null)
                {
                    return(NotFound());
                }

                var mail_obj = JsonConvert.DeserializeObject <JObject>(mail.ToString());

                //Send mail to group
                List <string> sent_to   = FORWARD_COMMON.sentToToList(JArray.Parse(mail_obj["to"]["value"].ToString()));
                string        sent_from = mail_obj["from"]["value"][0]["address"].ToString();
                DateTime      sent_on   = Convert.ToDateTime(mail_obj["date"]);

                string subject   = mail_obj["subject"].ToString();
                string mail_body = mail_obj["from"]["value"][0]["address"].ToString();

                //has attachements
                List <Attachment> attachments = new List <Attachment>();

                if (JArray.Parse(mail_obj["attachments"].ToString()).Count > 0)
                {
                    attachments = FORWARD_COMMON.convertAttachments(JArray.Parse(mail_obj["attachments"].ToString()));
                }

                return(Ok());
            }
            catch (Exception ex)
            {
                COMMON_FUNCTIONS.storeError(this.GetType().Name, MethodBase.GetCurrentMethod().ReflectedType.Name, ex.ToString());
                return(NotFound());
            }
        }
Exemplo n.º 3
0
        public static bool createAlias(string name, string recipients, string description = "", string labels = "", bool is_enabled = true)
        {
            try
            {
                var restClient = FORWARD_COMMON.getRestClient();

                //the request
                var request = new RestRequest(Method.POST);
                request.Resource = FORWARD_COMMON.Aliases;

                request.AddParameter("name", name);
                request.AddParameter("recipients", recipients);
                request.AddParameter("description", description);
                request.AddParameter("labels", labels);
                request.AddParameter("is_enabled", is_enabled);

                IRestResponse response = restClient.Execute(request);

                if (response.StatusCode == System.Net.HttpStatusCode.OK)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception ex)
            {
                COMMON_FUNCTIONS.storeError("FORWARD_ALIAS", MethodBase.GetCurrentMethod().ReflectedType.Name, ex.ToString());

                return(false);
            }
        }
Exemplo n.º 4
0
        public static JArray getAliasDetails(string name = "", string recipients = "")
        {
            try
            {
                var restClient = FORWARD_COMMON.getRestClient();

                //the request
                var request = new RestRequest(Method.GET);
                request.Resource = FORWARD_COMMON.Aliases;

                request.AddParameter("name", name);
                request.AddParameter("recipients", recipients);

                IRestResponse response = restClient.Execute(request);

                if (response.StatusCode == System.Net.HttpStatusCode.OK)
                {
                    return(JsonConvert.DeserializeObject <JArray>(response.Content));
                }
                else
                {
                    return(null);
                }
            }
            catch (Exception ex)
            {
                COMMON_FUNCTIONS.storeError("FORWARD_ALIAS", MethodBase.GetCurrentMethod().ReflectedType.Name, ex.ToString());

                return(null);
            }
        }
Exemplo n.º 5
0
        public static bool updateAlias(string old_name, string new_name, string recipients, string description = "", string labels = "", bool is_enabled = true)
        {
            try
            {
                //get the detailks
                JArray temp_alias = getAliasDetails(old_name);
                //failed to retrieve
                if (temp_alias == null)
                {
                    return(false);
                }

                string id_to_del = temp_alias[0]["id"].ToString();

                var restClient = FORWARD_COMMON.getRestClient();

                //the request
                var request = new RestRequest(Method.PUT);
                request.Resource = FORWARD_COMMON.Aliases + "/" + id_to_del;

                request.AddParameter("name", new_name);
                request.AddParameter("recipients", recipients);
                request.AddParameter("description", description);
                request.AddParameter("labels", labels);
                request.AddParameter("is_enabled", is_enabled);

                IRestResponse response = restClient.Execute(request);

                if (response.StatusCode == System.Net.HttpStatusCode.OK)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception ex)
            {
                COMMON_FUNCTIONS.storeError("FORWARD_ALIAS", MethodBase.GetCurrentMethod().ReflectedType.Name, ex.ToString());

                return(false);
            }
        }
Exemplo n.º 6
0
        public static List <string> sentToToList(JArray distribution_list)
        {
            try
            {
                List <string> distribution_result = new List <string>();

                foreach (JToken distribution in distribution_list)
                {
                    distribution_result.Add(distribution["address"].ToString());
                }

                return(distribution_result);
            }
            catch (Exception ex)
            {
                COMMON_FUNCTIONS.storeError("FORWARD_COMMON", MethodBase.GetCurrentMethod().ReflectedType.Name, ex.ToString());
                return(null);
            }
        }
Exemplo n.º 7
0
        public static bool deleteAlias(string name)
        {
            try
            {
                //get the detailks
                JArray alias_to_delete = getAliasDetails(name);
                //failed to retrieve
                if (alias_to_delete == null)
                {
                    return(false);
                }

                string id_to_del = alias_to_delete[0]["id"].ToString();

                var restClient = FORWARD_COMMON.getRestClient();

                //the request
                var request = new RestRequest(Method.DELETE);
                request.Resource = FORWARD_COMMON.Aliases + "/" + id_to_del;

                IRestResponse response = restClient.Execute(request);

                if (response.StatusCode == System.Net.HttpStatusCode.OK)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception ex)
            {
                COMMON_FUNCTIONS.storeError("FORWARD_ALIAS", MethodBase.GetCurrentMethod().ReflectedType.Name, ex.ToString());

                return(false);
            }
        }