Пример #1
0
        public static T GetEmail <T>(IAuthenticationManager authMgr, string id)
        {
            StringBuilder sb = new StringBuilder();

            string url = GetInBoxUrl(authMgr.Account);//string.Format("https://{0}/exchange/{1}/InBox/",AuthenticationManager.Current.Host,AuthenticationManager.Current.EmailAddress);

            sb.AppendLine("<?xml version=\"1.0\"?>");
            sb.AppendLine("<searchrequest xmlns=\"DAV:\">");
            sb.AppendLine("	<sql>SELECT \"urn:schemas:mailheader:message-id\" as id, \"urn:schemas:httpmail:from\" as from, \"urn:schemas:httpmail:datereceived\" as datereceived, \"urn:schemas:httpmail:cc\" as cc, \"urn:schemas:mailheader:subject\" as subject, \"urn:schemas:httpmail:to\" as to,\"urn:schemas:httpmail:htmldescription\" as htmldescription,\"urn:schemas:httpmail:textdescription\" as textdescription, \"urn:schemas:httpmail:hasattachment\" as hasattachment,\"urn:schemas:httpmail:read\" as read, \"urn:schemas:httpmail:thread-topic\" as topic, \"urn:schemas:httpmail:submitted\" as submitted, \"urn:schemas:httpmail:priority\" as priority");
            sb.AppendLine(string.Format("FROM Scope('SHALLOW TRAVERSAL OF \"{0}\"')", url));
            sb.AppendLine("WHERE \"urn:schemas:mailheader:message-id\" = '" + System.Security.SecurityElement.Escape(id) + "' AND \"DAV:isfolder\" = false");
            sb.AppendLine("	</sql>");
            sb.AppendLine("</searchrequest>");

            string query = sb.ToString();

            byte[] content = Encoding.UTF8.GetBytes(query);

            OwaRequest request = OwaRequest.Search(url, content, authMgr.CookieCache,
                                                   new Dictionary <string, string>()
            {
                { "depth", "1" }, { "Translate", "f" }
            });

            request.Accept      = "*/*";
            request.ContentType = "text/xml";

            object result = null;
            Type   t      = typeof(T);

            if (t == typeof(string))
            {
                using (OwaResponse response = request.Send())
                {
                    using (StreamReader sr = new StreamReader(response.GetResponseStream(), Encoding.UTF8))
                    {
                        result = sr.ReadToEnd();
                    }
                }
            }
            else if (t == typeof(IEmail))
            {
                IList <IEmail> emails;
                using (OwaResponse response = request.Send())
                {
                    emails = Deserialize(response.GetResponseStream());
                }
                result = emails.SingleOrDefault();
            }

            return(result == null ? default(T) : (T)Convert.ChangeType(result, t));
        }
Пример #2
0
        public static T GetEmailSimpleList <T>(IAuthenticationManager authMgr, int startIndex, int endIndex)
        {
            string        url = GetInBoxUrl(authMgr.Account);//string.Format("https://{0}/exchange/{1}/InBox/",AuthenticationManager.Current.Host,AuthenticationManager.Current.EmailAddress);
            StringBuilder sb  = new StringBuilder();

            sb.AppendLine("<?xml version=\"1.0\"?>");
            sb.AppendLine("<searchrequest xmlns=\"DAV:\">");
            sb.AppendLine("	<sql>SELECT \"urn:schemas:mailheader:message-id\" as id, \"urn:schemas:httpmail:from\" as from, \"urn:schemas:httpmail:datereceived\" as datereceived, \"urn:schemas:httpmail:cc\" as cc, \"urn:schemas:mailheader:subject\" as subject, \"urn:schemas:httpmail:to\" as to, \"urn:schemas:httpmail:read\" as read, \"urn:schemas:httpmail:thread-topic\" as topic, \"urn:schemas:httpmail:submitted\" as submitted, \"urn:schemas:httpmail:priority\" as priority");
            sb.AppendLine(string.Format("FROM Scope('SHALLOW TRAVERSAL OF \"{0}\"')", url));
            sb.AppendLine("WHERE \"DAV:isfolder\" = false");
            sb.AppendLine("ORDER BY \"urn:schemas:httpmail:datereceived\" DESC");
            sb.AppendLine("	</sql>");
            sb.AppendFormat("	<range type=\"row\">{0}-{1}</range>{2}", startIndex, endIndex, Environment.NewLine);
            sb.AppendLine("</searchrequest>");

            byte[] content = Encoding.UTF8.GetBytes(sb.ToString());


            OwaRequest request = OwaRequest.Search(url, content, authMgr.CookieCache,
                                                   new Dictionary <string, string>()
            {
                { "depth", "1" }, { "Translate", "f" }
            });

            request.Accept      = "*/*";
            request.ContentType = "text/xml";

            object result = null;

            Type t = typeof(T);

            if (t == typeof(string))
            {
                using (OwaResponse response = request.Send())
                {
                    using (StreamReader sr = new StreamReader(response.GetResponseStream(), Encoding.UTF8))
                    {
                        result = sr.ReadToEnd();
                    }
                }
            }
            else if (t == typeof(IList <IEmail>))
            {
                using (OwaResponse response = request.Send())
                {
                    result = Deserialize(response.GetResponseStream());
                }
            }

            return(result == null ? default(T) : (T)Convert.ChangeType(result, t));
        }
Пример #3
0
        public static string GetEmailFullList(IAuthenticationManager authMgr, int startIndex, int endIndex)
        {
            string        url = GetInBoxUrl(authMgr.Account);//string.Format("https://{0}/exchange/{1}/InBox/",AuthenticationManager.Current.Host,AuthenticationManager.Current.EmailAddress);
            StringBuilder sb  = new StringBuilder();

            sb.AppendLine("<?xml version=\"1.0\"?>");
            sb.AppendLine("<searchrequest xmlns=\"DAV:\">");
            //sb.AppendLine("	<sql>SELECT \"http://schemas.microsoft.com/exchange/smallicon\" as smicon, \"http://schemas.microsoft.com/mapi/sent_representing_name\" as from, \"urn:schemas:httpmail:datereceived\" as recvd, \"http://schemas.microsoft.com/mapi/proptag/x10900003\" as flag, \"http://schemas.microsoft.com/mapi/subject\" as subj, \"http://schemas.microsoft.com/exchange/x-priority-long\" as prio, \"urn:schemas:httpmail:hasattachment\" as fattach,\"urn:schemas:httpmail:read\" as r, \"http://schemas.microsoft.com/exchange/outlookmessageclass\" as m, \"http://schemas.microsoft.com/mapi/proptag/x10950003\" as flagcolor");
            sb.AppendLine("    <sql>SELECT *");
            sb.AppendLine("FROM Scope('SHALLOW TRAVERSAL OF \"\"')");
            sb.AppendLine("WHERE \"http://schemas.microsoft.com/mapi/proptag/0x67aa000b\" = false AND \"DAV:isfolder\" = false AND \"urn:schemas:mailheader:message-id\" = '" + System.Security.SecurityElement.Escape("<*****@*****.**>") + "'");
            sb.AppendLine("ORDER BY \"urn:schemas:httpmail:datereceived\" DESC");
            sb.AppendLine("	</sql>");
            sb.AppendFormat("	<range type=\"row\">{0}-{1}</range>{2}", startIndex, endIndex, Environment.NewLine);
            sb.AppendLine("</searchrequest>");

            byte[] content = Encoding.UTF8.GetBytes(sb.ToString());


            OwaRequest request = OwaRequest.Search(url, content, authMgr.CookieCache,
                                                   new Dictionary <string, string>()
            {
                { "depth", "1" }, { "Translate", "f" }
            });

            request.Accept      = "*/*";
            request.ContentType = "text/xml";

            string result;

            using (OwaResponse response = request.Send())
            {
                using (StreamReader sr = new StreamReader(response.GetResponseStream(), Encoding.UTF8))
                {
                    result = sr.ReadToEnd();
                }
            }

            return(result);
        }
Пример #4
0
        public static IList <Cookie> Authenticate(IAccount account)
        {
            string owaUrl = string.Format("https://{0}/exchweb/bin/auth/owaauth.dll", account.Host);
            string desUrl = string.Format("https://{0}/exchange", account.Host);
            string query  = string.Format("destination={0}&flags=0&forcedownlevel=0&trusted=0&username={1}&password={2}&SubmitCreds=Log On;", desUrl, account.UserName, account.Password);

            byte[] content = Encoding.UTF8.GetBytes(query);

            // Create the web OwaRequest:
            OwaRequest owaRequest = OwaRequest.Post(owaUrl, content);

            OwaResponse response = owaRequest.Send();

            if (response.StatusCode != HttpStatusCode.OK)
            {
                throw new Exception(string.Format("Message: Connection failed to url ({0}). Response status code: '{1}'.", desUrl, response.StatusCode));
            }

            response.Close();

            return(response.Cookies);
        }