detect_email_settings 0.0.1

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.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in detect_email_settings.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Jonathan Jeffus
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,50 @@
1
+ # DetectEmailSettings
2
+
3
+ This gem is intended to detect email settings for use with Mikel Lindsaar's mail gem. The idea is that a user can give your site their email address and password and the correct connection settings will be auto-detected.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'detect_email_settings'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install detect_email_settings
18
+
19
+ ## Usage
20
+
21
+ To guess detect email settings for all possible mail servers. This
22
+ process can take up to 10 minutes for some server configurations and is
23
+ not guaranteed to work. If you need faster service you may consider
24
+ using C<detect_known_only()>.
25
+
26
+ settings = DetectEmailSettings.detect_settings('someemail@somedomain.com', 'password')
27
+ if settings.nil?
28
+ puts "Couldn't detect email settings."
29
+ else
30
+ Mail.defaults do
31
+ retriever_method settings[:method],
32
+ :address => settings[:address],
33
+ :port => settings[:port],
34
+ :user_name => settings[:user_name],
35
+ :password => settings[:password],
36
+ :enable_ssl => settings[:enable_ssl]
37
+ end
38
+ end
39
+
40
+ You will get almost immediate results using C<detect_known_only()>. This
41
+ checks for major free or premium mail services with known connection
42
+ settings.
43
+
44
+ ## Contributing
45
+
46
+ 1. Fork it
47
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
48
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
49
+ 4. Push to the branch (`git push origin my-new-feature`)
50
+ 5. Create new Pull Request
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $: << File.join(File.dirname(__FILE__), "../lib")
4
+
5
+ require 'detect_email_settings'
6
+
7
+ STDERR.puts "Final: #{DetectEmailSettings.detect_settings(ARGV[0], ARGV[1])}"
@@ -0,0 +1,18 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/detect_email_settings/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Jonathan Jeffus"]
6
+ gem.email = ["jjeffus@gmail.com"]
7
+ gem.homepage = "http://github.com/jjeffus/detect_email_settings"
8
+ gem.summary = "Detect incoming mail settings."
9
+ gem.description = "The library detects incoming mail settings (imap,pop3) given an email address and password."
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "detect_email_settings"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = DetectEmailSettings::VERSION
17
+ gem.add_runtime_dependency 'mail'
18
+ end
@@ -0,0 +1,82 @@
1
+ require 'mail'
2
+ require 'resolv'
3
+ require "detect_email_settings/version"
4
+ require "detect_email_settings/detect_known"
5
+
6
+ module DetectEmailSettings
7
+ def self.check_settings(settings)
8
+ if settings[:method] == :imap
9
+ mail = Mail::IMAP.new(settings)
10
+ elsif settings[:method] == :pop3
11
+ mail = Mail::POP3.new(settings)
12
+ end
13
+ begin
14
+ mail.connection do |con|
15
+ ''
16
+ end
17
+ return settings
18
+ rescue Exception => e
19
+ # STDERR.puts "Fail: #{e.message}"
20
+ return nil
21
+ end
22
+ end
23
+
24
+ def self.detect_known_only(email, password)
25
+ settings = self.get_known_settings(email)
26
+ if settings
27
+ settings[:user_name] = email
28
+ settings[:password] = password
29
+ return self.check_settings(settings)
30
+ end
31
+ nil
32
+ end
33
+
34
+ def self.detect_settings(email, password)
35
+ settings = self.detect_known_only(email, password)
36
+ if settings
37
+ return settings
38
+ else
39
+ methods = {
40
+ :imap => [[993,true],[585,true],[143,false]],
41
+ :pop3 => [[110,false],[995,true]]
42
+ }
43
+ settings = {}
44
+ settings[:password] = password
45
+ resolver = Resolv::DNS.new
46
+ address = Mail::Address.new(email)
47
+
48
+ # Look at these addresses for the server.
49
+ servers = ["mail.#{address.domain}", "pop.#{address.domain}", "pop3.#{address.domain}", "imap.#{address.domain}"]
50
+ begin
51
+ # And check for an MX record.
52
+ mx = resolver.getresource(address.domain, Resolv::DNS::Resource::IN::MX)
53
+ servers.push mx.exchange.to_s
54
+ rescue
55
+ end
56
+
57
+ # Check each server
58
+ servers.each do |server|
59
+ settings[:address] = server
60
+ # And each method
61
+ methods.each_key do |method|
62
+ settings[:method] = method
63
+ methods[method].each do |combo|
64
+ # And each port and ssl option
65
+ settings[:port] = combo[0]
66
+ settings[:enable_ssl] = combo[1]
67
+ # Check with email as username and just the account name
68
+ [email, address.local].each do |username|
69
+ settings[:user_name] = username
70
+ ret = self.check_settings(settings)
71
+ unless ret.nil?
72
+ return ret
73
+ end
74
+ end
75
+ end
76
+ end
77
+ end
78
+ nil
79
+ end
80
+
81
+ end
82
+ end
@@ -0,0 +1,54 @@
1
+ module DetectEmailSettings
2
+ def self.get_known_settings(email)
3
+ aol = {
4
+ :method => :imap,
5
+ :port => 143,
6
+ :address => 'imap.aol.com',
7
+ :enable_ssl => false,
8
+ :domains => ['aol.com']
9
+ }
10
+ gmail = {
11
+ :method => :imap,
12
+ :port => 993,
13
+ :address => 'imap.gmail.com',
14
+ :enable_ssl => true,
15
+ :domains => ['gmail.com'],
16
+ :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."
17
+ }
18
+ hotmail = {
19
+ :method => :pop3,
20
+ :port => 995,
21
+ :address => 'pop3.live.com',
22
+ :enable_ssl => true,
23
+ :domains => ['hotmail.com', 'live.com', 'msn.com'],
24
+ :notice => "MSN.com email addresses are known to have issues."
25
+ }
26
+ mailcom = {
27
+ :method => :pop3,
28
+ :port => 110,
29
+ :address => 'pop.mail.com',
30
+ :enable_ssl => false,
31
+ :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"],
32
+ :notice => "Your email provider requires a Plus account or higher in order to use this address for our service."
33
+ }
34
+ yahoo = {
35
+ :method => :pop3,
36
+ :port => 995,
37
+ :address => 'pop.mail.yahoo.com',
38
+ :enable_ssl => true,
39
+ :domains => ['yahoo.com', 'ymail.com', 'rocketmail.com']
40
+ }
41
+ domains = {}
42
+ [aol, gmail, hotmail, mailcom, yahoo].each do |site|
43
+ site[:domains].each do |domain|
44
+ domains[domain] = site
45
+ end
46
+ end
47
+ address = Mail::Address.new(email)
48
+
49
+ if domains.has_key? address.domain.downcase
50
+ return domains[address.domain]
51
+ end
52
+ nil
53
+ end
54
+ end
@@ -0,0 +1,3 @@
1
+ module DetectEmailSettings
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: detect_email_settings
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jonathan Jeffus
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-08-17 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: mail
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ description: The library detects incoming mail settings (imap,pop3) given an email
31
+ address and password.
32
+ email:
33
+ - jjeffus@gmail.com
34
+ executables:
35
+ - test.rb
36
+ extensions: []
37
+ extra_rdoc_files: []
38
+ files:
39
+ - .gitignore
40
+ - Gemfile
41
+ - LICENSE
42
+ - README.md
43
+ - Rakefile
44
+ - bin/test.rb
45
+ - detect_email_settings.gemspec
46
+ - lib/detect_email_settings.rb
47
+ - lib/detect_email_settings/detect_known.rb
48
+ - lib/detect_email_settings/version.rb
49
+ homepage: http://github.com/jjeffus/detect_email_settings
50
+ licenses: []
51
+ post_install_message:
52
+ rdoc_options: []
53
+ require_paths:
54
+ - lib
55
+ required_ruby_version: !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ! '>='
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ! '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ requirements: []
68
+ rubyforge_project:
69
+ rubygems_version: 1.8.24
70
+ signing_key:
71
+ specification_version: 3
72
+ summary: Detect incoming mail settings.
73
+ test_files: []