Module: DetectEmailSettings

Defined in:
lib/detect_email_settings.rb,
lib/detect_email_settings/version.rb,
lib/detect_email_settings/detect_known.rb

Constant Summary collapse

VERSION =
"0.0.1"

Class Method Summary collapse

Class Method Details

.check_settings(settings) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/detect_email_settings.rb', line 7

def self.check_settings(settings)
  if    settings[:method] == :imap
    mail = Mail::IMAP.new(settings)
  elsif settings[:method] == :pop3
    mail = Mail::POP3.new(settings)
  end
  begin
    mail.connection do |con|
      ''
    end
    return settings
  rescue Exception => e
    # STDERR.puts "Fail: #{e.message}"
    return nil
  end
end

.detect_known_only(email, password) ⇒ Object



24
25
26
27
28
29
30
31
32
# File 'lib/detect_email_settings.rb', line 24

def self.detect_known_only(email, password)
  settings = self.get_known_settings(email)
  if settings
    settings[:user_name] = email
    settings[:password]  = password
    return self.check_settings(settings)
  end
  nil
end

.detect_settings(email, password) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/detect_email_settings.rb', line 34

def self.detect_settings(email, password)
  settings = self.detect_known_only(email, password)
  if settings
    return settings
  else
    methods = {
      :imap => [[993,true],[585,true],[143,false]],
      :pop3 => [[110,false],[995,true]]
    }
    settings            = {}
    settings[:password] = password
    resolver            = Resolv::DNS.new
    address             = Mail::Address.new(email)

    # Look at these addresses for the server.
    servers  = ["mail.#{address.domain}", "pop.#{address.domain}", "pop3.#{address.domain}", "imap.#{address.domain}"]
    begin
      # And check for an MX record.
      mx = resolver.getresource(address.domain, Resolv::DNS::Resource::IN::MX)
      servers.push mx.exchange.to_s
    rescue
    end

    # Check each server
    servers.each do |server|
      settings[:address] = server
      # And each method
      methods.each_key do |method|
        settings[:method] = method
        methods[method].each do |combo|
          # And each port and ssl option
          settings[:port]       = combo[0]
          settings[:enable_ssl] = combo[1]
          # Check with email as username and just the account name
          [email, address.local].each do |username|
            settings[:user_name] = username
            ret                  = self.check_settings(settings)
            unless ret.nil?
              return ret
            end
          end
        end
      end
    end
    nil
  end

end

.get_known_settings(email) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/detect_email_settings/detect_known.rb', line 2

def self.get_known_settings(email)
  aol = {
    :method     => :imap,
    :port       => 143,
    :address    => 'imap.aol.com',
    :enable_ssl => false,
    :domains    => ['aol.com']
  }
  gmail = {
    :method     => :imap,
    :port       => 993,
    :address    => 'imap.gmail.com',
    :enable_ssl => true,
    :domains    => ['gmail.com'],
    :notice     => "You need to <a href=\"http://support.google.com/mail/bin/answer.py?hl=en&answer=77695\">Enable IMAP Access</a> on your GMail account if you want to use this account with our service."
  }
  hotmail = {
    :method     => :pop3,
    :port       => 995,
    :address    => 'pop3.live.com',
    :enable_ssl => true,
    :domains    => ['hotmail.com', 'live.com', 'msn.com'],
    :notice     => "MSN.com email addresses are known to have issues."
  }
  mailcom = {
    :method     => :pop3,
    :port       => 110,
    :address    => 'pop.mail.com',
    :enable_ssl => false,
    :domains    => ["mail.com", "email.com", "usa.com", "myself.com", "consultant.com", "post.com", "europe.com", "london.com", "asia.com", "iname.com", "writeme.com", "dr.com", "engineer.com", "cheerful.com", "accountant.com", "techie.com", "linuxmail.org", "lawyer.com", "uymail.com", "contractor.net", "accountant.com", "activist.com", "adexec.com", "allergist.com", "alumni.com", "alumnidirector.com", "angelic.com", "appraiser.net", "archaeologist.com", "arcticmail.com", "artlover.com", "asia.com", "auctioneer.net", "bartender.net", "bikerider.com", "birdlover.com", "brew-meister.com", "cash4u.com", "chef.net", "chemist.com", "clerk.com", "clubmember.org", "collector.org", "columnist.com", "comic.com", "computer4u.com", "consultant.com", "contractor.net", "coolsite.net", "counsellor.com", "cyberservices.com", "deliveryman.com", "diplomats.com", "disposable.com", "doctor.com", "dr.com", "engineer.com", "execs.com", "fastservice.com", "financier.com", "fireman.net", "gardener.com", "geologist.com", "graduate.org", "graphic-designer.com", "groupmail.com", "hairdresser.net", "homemail.com", "hot-shot.com", "instruction.com", "instructor.net", "insurer.com", "job4u.com", "journalist.com", "lawyer.com", "legislator.com", "lobbyist.com", "minister.com", "musician.org", "myself.com", "net-shopping.com", "optician.com", "orthodontist.net", "pediatrician.com", "photographer.net", "physicist.net", "planetmail.com", "planetmail.net", "politician.com", "post.com", "presidency.com", "priest.com", "programmer.net", "publicist.com", "qualityservice.com", "radiologist.net", "realtyagent.com", "registerednurses.com", "repairman.com", "representative.com", "rescueteam.com", "revenue.com", "salesperson.net", "scientist.com", "secretary.net", "socialworker.net", "sociologist.com", "solution4u.com", "songwriter.net", "surgical.net", "teachers.org", "tech-center.com", "techie.com", "technologist.com", "theplate.com", "therapist.net", "toothfairy.com", "tvstar.com", "umpire.com", "webname.com", "worker.com", "workmail.com", "writeme.com", "activist.com", "aircraftmail.com", "artlover.com", "atheist.com", "bikerider.com", "birdlover.com", "blader.com", "boardermail.com", "brew-master.com", "brew-meister.com", "bsdmail.com", "catlover.com", "chef.net", "clubmember.org", "collector.org", "cutey.com", "dbzmail.com", "doglover.com", "doramail.com", "gardener.com", "greenmail.net", "hackermail.com", "hilarious.com", "keromail.com", "kittymail.com", "linuxmail.org", "lovecat.com", "marchmail.com", "musician.org", "nonpartisan.com", "petlover.com", "photographer.net", "snakebite.com", "songwriter.net", "techie.com", "theplate.com", "toke.com", "uymail.com", "computer4u.com", "consultant.com", "contractor.net", "coolsite.net", "cyberdude.com", "cybergal.com", "cyberservices.com", "cyber-wizard.com", "engineer.com", "fastservice.com", "graphic-designer.com", "groupmail.com", "homemail.com", "hot-shot.com", "housemail.com", "humanoid.net", "iname.com", "inorbit.com", "mail-me.com", "myself.com", "net-shopping.com", "null.net", "physicist.net", "planetmail.com", "planetmail.net", "post.com", "programmer.net", "qualityservice.com", "rocketship.com", "scientist.com", "solution4u.com", "tech-center.com", "techie.com", "technologist.com", "webname.com", "workmail.com", "writeme.com", "acdcfan.com", "angelic.com", "artlover.com", "atheist.com", "chemist.com", "diplomats.com", "discofan.com", "elvisfan.com", "execs.com", "hiphopfan.com", "housemail.com", "kissfans.com", "madonnafan.com", "metalfan.com", "minister.com", "musician.org", "ninfan.com", "oath.com", "ravemail.com", "reborn.com", "reggaefan.com", "snakebite.com", "songwriter.net", "bellair.net", "californiamail.com", "dallasmail.com", "nycmail.com", "pacific-ocean.com", "pacificwest.com", "sanfranmail.com", "usa.com", "africamail.com", "arcticmail.com", "asia.com", "asia-mail.com", "australiamail.com", "berlin.com", "brazilmail.com", "chinamail.com", "dublin.com", "dutchmail.com", "englandmail.com", "europe.com", "europemail.com", "germanymail.com", "irelandmail.com", "israelmail.com", "italymail.com", "japan.com", "koreamail.com", "london.com", "madrid.com", "mexicomail.com", "moscowmail.com", "munich.com", "polandmail.com", "rome.com", "safrica.com", "samerica.com", "scotlandmail.com", "singapore.com", "spainmail.com", "swedenmail.com", "swissmail.com", "tokyo.com", "torontomail.com", "angelic.com", "atheist.com", "disciples.com", "innocent.com", "minister.com", "muslim.com", "oath.com", "priest.com", "protestant.com", "reborn.com", "reincarnate.com", "religious.com", "saintly.com"],
    :notice     => "Your email provider requires a Plus account or higher in order to use this address for our service."
  }
  yahoo = {
    :method     => :pop3,
    :port       => 995,
    :address    => 'pop.mail.yahoo.com',
    :enable_ssl => true,
    :domains    => ['yahoo.com', 'ymail.com', 'rocketmail.com']
  }
  domains = {}
  [aol, gmail, hotmail, mailcom, yahoo].each do |site|
    site[:domains].each do |domain|
      domains[domain] = site
    end
  end
  address  = Mail::Address.new(email)

  if domains.has_key? address.domain.downcase
    return domains[address.domain]
  end
  nil
end