Class: Contacts::NetEase

Inherits:
Base
  • Object
show all
Defined in:
lib/contacts/net_ease.rb

Constant Summary collapse

URL =
"http://www.163.com"
LOGIN_URL =
"https://reg.163.com/logins.jsp"
LoginData =
{
  :url2 => {
    :wy163 => 'http://mail.163.com/errorpage/err_163.htm',
    :wy126 => 'http://mail.126.com/errorpage/err_126.htm',
    :yeah => 'http://mail.yeah.net/errorpage/err_yeah.htm'
  },
  :url => {
    :wy163 => 'http://entry.mail.163.com/coremail/fcg/ntesdoor2?lightweight=1&verifycookie=1&language=-1&style=-1&username=%s',
    :wy126 => 'http://entry.mail.126.com/cgi/ntesdoor?hid=10010102&lightweight=1&verifycookie=1&language=0&style=-1&username=%s',
    :yeah => 'http://entry.mail.yeah.net/cgi/ntesdoor?lightweight=1&verifycookie=1&style=-1&username=%s'
  },
  :product => {
    :wy163 => 'mail163',
    :wy126 => 'mail126',
    :yeah => 'mailyeah'
  }
}
ENTER_MAIL_URL =
{
  :wy163 => "http://entry.mail.163.com/coremail/fcg/ntesdoor2?lightweight=1&verifycookie=1&language=-1&style=-1&username=%s",
  :wy126 => "http://entry.mail.126.com/cgi/ntesdoor?hid=10010102&lightweight=1&verifycookie=1&language=0&style=-1&username=%s",
  :yeah => "http://entry.mail.yeah.net/cgi/ntesdoor?lightweight=1&verifycookie=1&style=-1&username=%s"
}
CONTACT_LIST_URL =
"%ss?sid=%s&func=global:sequential"
PROTOCOL_ERROR =
"netease has changed its protocols, please upgrade this library first. you can also contact [email protected]"

Instance Method Summary collapse

Methods inherited from Base

#connect, #connected?, #login, #login_with_domain, #login_without_domain, #password

Constructor Details

#initialize(login, password, options = {}) ⇒ NetEase

Returns a new instance of NetEase.



31
32
33
34
# File 'lib/contacts/net_ease.rb', line 31

def initialize(, password, options={})
  @mail_type = get_mail_type()
  super(,password,options)
end

Instance Method Details

#contactsObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/contacts/net_ease.rb', line 41

def contacts
  return @contacts if @contacts
  if connected?
    url = URI.parse(CONTACT_LIST_URL % [@mail_server,@sid])
    http = open_http(url)
    postdata = '<?xml version="1.0"?><object><array name="items"><object><string name="func">pab:searchContacts</string><object name="var"><array name="order"><object><string name="field">FN</string><boolean name="ignoreCase">true</boolean></object></array></object></object><object><string name="func">user:getSignatures</string></object><object><string name="func">pab:getAllGroups</string></object></array></object>'
    set_header = {"Cookie" => @cookies,'Accept' => 'text/javascript','Content-Type' => 'application/xml; charset=UTF-8'}
    resp, data = http.post("#{url.path}?#{url.query}",postdata,set_header)
    if resp.code_type != Net::HTTPOK
      raise ConnectionError, self.class.const_get(:PROTOCOL_ERROR)
    end
    parse(data)
  end
end

#real_connectObject



36
37
38
39
# File 'lib/contacts/net_ease.rb', line 36

def real_connect
  
  enter_mail_server
end