LiveExtract.cs.svn-base
资源名称:GetFriend.rar [点击查看]
上传用户:asz878
上传日期:2020-04-01
资源大小:189k
文件大小:3k
源码类别:
WEB邮件程序
开发平台:
Visual C++
- //Code by Gnilly (http://gnillydev.blogspot.com)
- //Offical site: http://opencontacts.sourceforge.net
- //This program is free software: you can redistribute it and/or modify
- //it under the terms of the GNU Lesser General Public License as published by
- //the Free Software Foundation, either version 3 of the License, or
- //(at your option) any later version.
- //This program is distributed in the hope that it will be useful,
- //but WITHOUT ANY WARRANTY; without even the implied warranty of
- //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- //GNU Lesser General Public License for more details.
- //You should have received a copy of the GNU Lesser General Public License
- //along with this program. If not, see <http://www.gnu.org/licenses/>.
- using System;
- using System.Collections.Generic;
- using System.Net;
- using System.Text;
- using System.Xml;
- namespace OpenContactsNet
- {
- public class LiveExtract : IMailContactExtract
- {
- #region IMailContactExtract Members
- public bool Extract( NetworkCredential credential, out MailContactList list )
- {
- list = new MailContactList();
- bool result = false;
- try
- {
- TicketAcquirer ticketAcquirer = new TicketAcquirer();
- string ticket = ticketAcquirer.GetTicket( credential );
- if ( string.IsNullOrEmpty( ticket ) )
- {
- return false;
- }
- UriBuilder urib = new UriBuilder();
- urib.Scheme = "HTTPS";
- urib.Path = string.Format( "/{0}/LiveContacts", credential.UserName );
- urib.Host = "cumulus.services.live.com";
- urib.Port = 443;
- HttpWebRequest request = ( HttpWebRequest ) WebRequest.Create( urib.Uri );
- string authHeader = string.Format( "WLID1.0 t="{0}"", ticket );
- request.Headers.Add( "Authorization", authHeader );
- WebResponse response = request.GetResponse();
- if ( response.ContentLength != 0 )
- {
- XmlDocument xmlDocument = new XmlDocument();
- xmlDocument.Load( response.GetResponseStream() );
- XmlNodeList contacts = xmlDocument.SelectNodes( "/LiveContacts/Contacts/Contact" );
- foreach ( XmlNode node in contacts )
- {
- XmlNode firstName = node.SelectSingleNode("Profiles/Personal/DisplayName");
- //XmlNode lastName = node.SelectSingleNode("Profiles/Personal/DisplayName");
- XmlNode firstMail = node.SelectSingleNode("Emails/Email/Address");
- MailContact mailContact = new MailContact();
- mailContact.Name = string.Format( "{0}", firstName.InnerText);
- mailContact.Email = firstMail == null ? string.Empty : firstMail.InnerText;
- list.Add( mailContact );
- }
- }
- result = true;
- }
- catch(Exception ex)
- {
- string a = ex.Message;
- return false;
- }
- return result;
- }
- #endregion
- }
- }