email-spy 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +1 -1
- data/Gemfile.lock +1 -1
- data/README.md +22 -2
- data/email-spy.gemspec +1 -1
- data/lib/email-spy.rb +2 -1
- data/lib/email-spy/163.rb +60 -0
- data/lib/email-spy/version.rb +1 -1
- data/spec/163_spec.rb +6 -0
- data/spec/fixture/email_type.yml.sample +13 -0
- metadata +17 -12
    
        data/.gitignore
    CHANGED
    
    
    
        data/Gemfile.lock
    CHANGED
    
    
    
        data/README.md
    CHANGED
    
    | @@ -1,7 +1,6 @@ | |
| 1 1 | 
             
            email-spy
         | 
| 2 2 | 
             
            =========
         | 
| 3 3 |  | 
| 4 | 
            -
             | 
| 5 4 | 
             
            Usage
         | 
| 6 5 | 
             
            -----
         | 
| 7 6 |  | 
| @@ -18,4 +17,25 @@ Current Supported Email Type | |
| 18 17 | 
             
            + gmail
         | 
| 19 18 | 
             
            + hotmail
         | 
| 20 19 | 
             
            + 126
         | 
| 21 | 
            -
            +  | 
| 20 | 
            +
            + 163
         | 
| 21 | 
            +
            + yahoo
         | 
| 22 | 
            +
             | 
| 23 | 
            +
             | 
| 24 | 
            +
            Encoding
         | 
| 25 | 
            +
            --------
         | 
| 26 | 
            +
             | 
| 27 | 
            +
            我们尚未对联系人姓名编码进行什么处理,应为我们觉得这会使Email Spy不够纯粹:它只返回web server响应的内容。也许之后会支持?:alien:
         | 
| 28 | 
            +
             | 
| 29 | 
            +
            我们推荐 rCharDet19(https://github.com/oleander/rchardet) 来帮助你解决编码的问题:
         | 
| 30 | 
            +
             | 
| 31 | 
            +
            ```ruby
         | 
| 32 | 
            +
            EmailSpy.fetch(account,password,emailtype).map do |c| 
         | 
| 33 | 
            +
             c.name.encode('utf-8',CharDet.detect(c.name).encoding)
         | 
| 34 | 
            +
            end
         | 
| 35 | 
            +
            ```
         | 
| 36 | 
            +
             | 
| 37 | 
            +
            Change Log
         | 
| 38 | 
            +
            ----------
         | 
| 39 | 
            +
             | 
| 40 | 
            +
            + 0.0.3 first release
         | 
| 41 | 
            +
            + 0.0.4 支持163
         | 
    
        data/email-spy.gemspec
    CHANGED
    
    | @@ -4,7 +4,7 @@ require File.expand_path('../lib/email-spy/version', __FILE__) | |
| 4 4 | 
             
            Gem::Specification.new do |s|
         | 
| 5 5 | 
             
              s.name        = 'email-spy'
         | 
| 6 6 | 
             
              s.version     = EmailSpy::VERSION
         | 
| 7 | 
            -
              s.date        = '2012- | 
| 7 | 
            +
              s.date        = '2012-08-17'
         | 
| 8 8 | 
             
              s.summary     = ""
         | 
| 9 9 | 
             
              s.description = "Retrieves contact list of email"
         | 
| 10 10 | 
             
              s.authors     = ["Wade Xing"]
         | 
    
        data/lib/email-spy.rb
    CHANGED
    
    | @@ -17,6 +17,7 @@ require 'email-spy/errors' | |
| 17 17 | 
             
            require 'email-spy/gmail'
         | 
| 18 18 | 
             
            require "email-spy/hotmail"
         | 
| 19 19 | 
             
            require "email-spy/126"
         | 
| 20 | 
            +
            require "email-spy/163"
         | 
| 20 21 | 
             
            require "email-spy/yahoo"
         | 
| 21 22 |  | 
| 22 23 | 
             
            module EmailSpy
         | 
| @@ -24,7 +25,7 @@ module EmailSpy | |
| 24 25 | 
             
              # @param [String] 邀请人电邮地址
         | 
| 25 26 | 
             
              # @param [String] 邀请人电邮密码
         | 
| 26 27 | 
             
              # @param [String] 邮件类型
         | 
| 27 | 
            -
              # @ | 
| 28 | 
            +
              # @return [Array<EmailSay::Contact>] 联系人集合
         | 
| 28 29 | 
             
              def self.fetch invitor_email_address,invitor_email_password,email_type
         | 
| 29 30 | 
             
                self.const_get(operating_klass_name email_type).fetch invitor_email_address,invitor_email_password
         | 
| 30 31 | 
             
              end
         | 
| @@ -0,0 +1,60 @@ | |
| 1 | 
            +
            # -*- coding: utf-8 -*-
         | 
| 2 | 
            +
            module EmailSpy
         | 
| 3 | 
            +
              class OneSixThree
         | 
| 4 | 
            +
             | 
| 5 | 
            +
                # 登录页
         | 
| 6 | 
            +
                LANDING_PAGE_URL = 'http://mail.163.com'
         | 
| 7 | 
            +
             | 
| 8 | 
            +
                # 联系人 URL 模板
         | 
| 9 | 
            +
                Contacts_URL =  "http://g4a30.mail.163.com/jy3/address/addrlist.jsp?sid=%s&gid=all"
         | 
| 10 | 
            +
             | 
| 11 | 
            +
                def self.fetch invitor_email_address,invitor_email_password
         | 
| 12 | 
            +
                  self.new(invitor_email_address,invitor_email_password).contacts
         | 
| 13 | 
            +
                end
         | 
| 14 | 
            +
             | 
| 15 | 
            +
                
         | 
| 16 | 
            +
                def initialize invitor_email_address,invitor_email_password
         | 
| 17 | 
            +
                  @invitor_email_address = invitor_email_address
         | 
| 18 | 
            +
                  @invitor_email_password = invitor_email_password
         | 
| 19 | 
            +
                  @agent = Mechanize.new
         | 
| 20 | 
            +
                end
         | 
| 21 | 
            +
             | 
| 22 | 
            +
                # 通讯录联系人
         | 
| 23 | 
            +
                # @return [Array<EmailSpy::Contract>] 
         | 
| 24 | 
            +
                def contacts
         | 
| 25 | 
            +
                  body = @agent.get(Contacts_URL % sid).body 
         | 
| 26 | 
            +
                  contacts = []
         | 
| 27 | 
            +
             | 
| 28 | 
            +
                  Nokogiri::HTML(body).xpath(".//*[@id='addrstable']/tbody[1]/tr").each do |tr|
         | 
| 29 | 
            +
                    contacts << Contact.new(tr.css(".Ibx_Td_addrName a").text,
         | 
| 30 | 
            +
                                       tr.css(".Ibx_Td_addrEmail a").text)
         | 
| 31 | 
            +
                  end
         | 
| 32 | 
            +
             | 
| 33 | 
            +
                  contacts
         | 
| 34 | 
            +
                end
         | 
| 35 | 
            +
             | 
| 36 | 
            +
                private 
         | 
| 37 | 
            +
             | 
| 38 | 
            +
                # 登录
         | 
| 39 | 
            +
                # @return [String] SID
         | 
| 40 | 
            +
                def sid
         | 
| 41 | 
            +
                  page = @agent.get(LANDING_PAGE_URL)
         | 
| 42 | 
            +
                  login_form = page.forms[0]
         | 
| 43 | 
            +
                  login_form.action= 'http://reg.163.com/login.jsp'
         | 
| 44 | 
            +
                  login_form.add_field!('type',1)
         | 
| 45 | 
            +
                  login_form.add_field!('product','mail163')
         | 
| 46 | 
            +
                  login_form.add_field!('url' ,URI.encode("http://entry.mail.163.com/cgi/ntesdoor?hid=10010102&lightweight=1&language=0&style=3"))
         | 
| 47 | 
            +
                  login_form.username ,login_form.password = @invitor_email_address,@invitor_email_password
         | 
| 48 | 
            +
                  page = login_form.submit(login_form.buttons.first)
         | 
| 49 | 
            +
                  page1 = login_form.click_button
         | 
| 50 | 
            +
                  page2 = page1.links[0].click
         | 
| 51 | 
            +
             | 
| 52 | 
            +
                  page3 = @agent.get('http://entry.mail.163.com/cgi/ntesdoor?verifycookie=1&lightweight=1&style=-1')
         | 
| 53 | 
            +
                  page3.uri.to_s.scan(/sid=(\S+)/).first[0]
         | 
| 54 | 
            +
                end
         | 
| 55 | 
            +
              end
         | 
| 56 | 
            +
             | 
| 57 | 
            +
              private
         | 
| 58 | 
            +
              
         | 
| 59 | 
            +
              EMAIL_TYPE['163'] = "OneSixThree"
         | 
| 60 | 
            +
            end
         | 
    
        data/lib/email-spy/version.rb
    CHANGED
    
    
    
        data/spec/163_spec.rb
    ADDED
    
    
    
        metadata
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: email-spy
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.0. | 
| 4 | 
            +
              version: 0.0.4
         | 
| 5 5 | 
             
              prerelease: 
         | 
| 6 6 | 
             
            platform: ruby
         | 
| 7 7 | 
             
            authors:
         | 
| @@ -9,11 +9,11 @@ authors: | |
| 9 9 | 
             
            autorequire: 
         | 
| 10 10 | 
             
            bindir: bin
         | 
| 11 11 | 
             
            cert_chain: []
         | 
| 12 | 
            -
            date: 2012- | 
| 12 | 
            +
            date: 2012-08-17 00:00:00.000000000Z
         | 
| 13 13 | 
             
            dependencies:
         | 
| 14 14 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 15 15 | 
             
              name: httpclient
         | 
| 16 | 
            -
              requirement: & | 
| 16 | 
            +
              requirement: &70365808763600 !ruby/object:Gem::Requirement
         | 
| 17 17 | 
             
                none: false
         | 
| 18 18 | 
             
                requirements:
         | 
| 19 19 | 
             
                - - ~>
         | 
| @@ -21,10 +21,10 @@ dependencies: | |
| 21 21 | 
             
                    version: 2.2.5
         | 
| 22 22 | 
             
              type: :runtime
         | 
| 23 23 | 
             
              prerelease: false
         | 
| 24 | 
            -
              version_requirements: * | 
| 24 | 
            +
              version_requirements: *70365808763600
         | 
| 25 25 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 26 26 | 
             
              name: nokogiri
         | 
| 27 | 
            -
              requirement: & | 
| 27 | 
            +
              requirement: &70365808763080 !ruby/object:Gem::Requirement
         | 
| 28 28 | 
             
                none: false
         | 
| 29 29 | 
             
                requirements:
         | 
| 30 30 | 
             
                - - ~>
         | 
| @@ -32,10 +32,10 @@ dependencies: | |
| 32 32 | 
             
                    version: 1.5.0
         | 
| 33 33 | 
             
              type: :runtime
         | 
| 34 34 | 
             
              prerelease: false
         | 
| 35 | 
            -
              version_requirements: * | 
| 35 | 
            +
              version_requirements: *70365808763080
         | 
| 36 36 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 37 37 | 
             
              name: gdata_19
         | 
| 38 | 
            -
              requirement: & | 
| 38 | 
            +
              requirement: &70365808762560 !ruby/object:Gem::Requirement
         | 
| 39 39 | 
             
                none: false
         | 
| 40 40 | 
             
                requirements:
         | 
| 41 41 | 
             
                - - ~>
         | 
| @@ -43,10 +43,10 @@ dependencies: | |
| 43 43 | 
             
                    version: 1.1.5
         | 
| 44 44 | 
             
              type: :runtime
         | 
| 45 45 | 
             
              prerelease: false
         | 
| 46 | 
            -
              version_requirements: * | 
| 46 | 
            +
              version_requirements: *70365808762560
         | 
| 47 47 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 48 48 | 
             
              name: mechanize
         | 
| 49 | 
            -
              requirement: & | 
| 49 | 
            +
              requirement: &70365808762000 !ruby/object:Gem::Requirement
         | 
| 50 50 | 
             
                none: false
         | 
| 51 51 | 
             
                requirements:
         | 
| 52 52 | 
             
                - - ~>
         | 
| @@ -54,10 +54,10 @@ dependencies: | |
| 54 54 | 
             
                    version: 2.5.1
         | 
| 55 55 | 
             
              type: :runtime
         | 
| 56 56 | 
             
              prerelease: false
         | 
| 57 | 
            -
              version_requirements: * | 
| 57 | 
            +
              version_requirements: *70365808762000
         | 
| 58 58 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 59 59 | 
             
              name: rspec
         | 
| 60 | 
            -
              requirement: & | 
| 60 | 
            +
              requirement: &70365808761480 !ruby/object:Gem::Requirement
         | 
| 61 61 | 
             
                none: false
         | 
| 62 62 | 
             
                requirements:
         | 
| 63 63 | 
             
                - - ~>
         | 
| @@ -65,7 +65,7 @@ dependencies: | |
| 65 65 | 
             
                    version: 2.11.0
         | 
| 66 66 | 
             
              type: :development
         | 
| 67 67 | 
             
              prerelease: false
         | 
| 68 | 
            -
              version_requirements: * | 
| 68 | 
            +
              version_requirements: *70365808761480
         | 
| 69 69 | 
             
            description: Retrieves contact list of email
         | 
| 70 70 | 
             
            email:
         | 
| 71 71 | 
             
            - iamxingxing@gmail.com
         | 
| @@ -83,6 +83,7 @@ files: | |
| 83 83 | 
             
            - email-spy.gemspec
         | 
| 84 84 | 
             
            - lib/email-spy.rb
         | 
| 85 85 | 
             
            - lib/email-spy/126.rb
         | 
| 86 | 
            +
            - lib/email-spy/163.rb
         | 
| 86 87 | 
             
            - lib/email-spy/contact.rb
         | 
| 87 88 | 
             
            - lib/email-spy/email_types.rb
         | 
| 88 89 | 
             
            - lib/email-spy/errors.rb
         | 
| @@ -91,7 +92,9 @@ files: | |
| 91 92 | 
             
            - lib/email-spy/version.rb
         | 
| 92 93 | 
             
            - lib/email-spy/yahoo.rb
         | 
| 93 94 | 
             
            - spec/126_spec.rb
         | 
| 95 | 
            +
            - spec/163_spec.rb
         | 
| 94 96 | 
             
            - spec/email-spy_spec.rb
         | 
| 97 | 
            +
            - spec/fixture/email_type.yml.sample
         | 
| 95 98 | 
             
            - spec/gmail_spec.rb
         | 
| 96 99 | 
             
            - spec/hotmail_spec.rb
         | 
| 97 100 | 
             
            - spec/spec_helper.rb
         | 
| @@ -122,7 +125,9 @@ specification_version: 3 | |
| 122 125 | 
             
            summary: ''
         | 
| 123 126 | 
             
            test_files:
         | 
| 124 127 | 
             
            - spec/126_spec.rb
         | 
| 128 | 
            +
            - spec/163_spec.rb
         | 
| 125 129 | 
             
            - spec/email-spy_spec.rb
         | 
| 130 | 
            +
            - spec/fixture/email_type.yml.sample
         | 
| 126 131 | 
             
            - spec/gmail_spec.rb
         | 
| 127 132 | 
             
            - spec/hotmail_spec.rb
         | 
| 128 133 | 
             
            - spec/spec_helper.rb
         |