Sha256: 40aa645bc6cca4ea5524737f63da6db2f9f360031dcdc8e1d5ffd36c0b10adf1

Contents?: true

Size: 1.55 KB

Versions: 14

Compression:

Stored size: 1.55 KB

Contents

require 'blackbook/importer/page_scraper'

class Blackbook::Importer::Freenet < Blackbook::Importer::PageScraper
  LOGIN_URL = "https://office.freenet.de"
  MESSAGES_URL = "/main_overview.html"

  def =~( options )
    options && options[:username] =~ /@freenet\.de$/i
  end

  def login
    username, password = options[:username], options[:password]

    begin
      page = agent.get LOGIN_URL

      form = page.forms.with.name("loginform").first
      form.username = username.split("@").first
      form.password = password
      page = form.submit

      if page.body.match(/Fehlgeschlagene Login-Versuche/)
        page = page.forms.with.name("sicherform").submit
        page = agent.get MESSAGES_URL
      end

      if page.body.match(/Login (erneut )?fehlgeschlagen/) || page.body.match(/Ich bin bereits Mitglied/)
        raise Blackbook::BadCredentialsError.new
      end
    rescue => e
      raise e || Blackbook::BlackbookError.new
    end
  end

  def prepare
    login
  end

  def scrape_contacts
    contacts = ["INBOX", "INBOX.sent"].map do |folder|
      page = agent.get "/messages/mail_mailbox.html?mail_folder=#{folder}"
      find_contacts(page)
    end

    contacts.inject([]) do |memo, contact|
      memo << contact unless memo.include? contact
      memo
    end.flatten
  end


  protected
    def find_contacts(page)
      page.search("tr[@id]/td[9]").map do |cell|
        recp, fullname, email = *cell.attributes["title"].match(/"(.*)"<(.*)>/)

        { :name => fullname, :email => email }
      end
    end

    Blackbook.register :freenet, self
end

Version data entries

14 entries across 14 versions & 3 rubygems

Version Path
bcardarella-blackbook-1.0.10 lib/blackbook/importer/freenet.rb
bcardarella-blackbook-1.0.11 lib/blackbook/importer/freenet.rb
bcardarella-blackbook-1.0.7 lib/blackbook/importer/freenet.rb
bcardarella-blackbook-1.0.8 lib/blackbook/importer/freenet.rb
bcardarella-blackbook-1.0.9 lib/blackbook/importer/freenet.rb
briancollins-blackbook-1.0.15 lib/blackbook/importer/freenet.rb
rakutenusa-blackbook-1.0.12 lib/blackbook/importer/freenet.rb
rakutenusa-blackbook-1.0.13 lib/blackbook/importer/freenet.rb
rakutenusa-blackbook-1.0.14 lib/blackbook/importer/freenet.rb
rakutenusa-blackbook-1.0.15 lib/blackbook/importer/freenet.rb
rakutenusa-blackbook-1.0.16 lib/blackbook/importer/freenet.rb
rakutenusa-blackbook-1.0.17 lib/blackbook/importer/freenet.rb
rakutenusa-blackbook-1.0.18 lib/blackbook/importer/freenet.rb
rakutenusa-blackbook-1.0.19 lib/blackbook/importer/freenet.rb