Skip to content

Commit

Permalink
added email client detection
Browse files Browse the repository at this point in the history
  • Loading branch information
SidOfc committed Apr 26, 2017
1 parent b8c7f50 commit d30d713
Show file tree
Hide file tree
Showing 5 changed files with 134 additions and 7 deletions.
4 changes: 4 additions & 0 deletions lib/browserino/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ def like(tmp, opts = {}, &block)
preset opts.merge(like: tmp.to_sym), &block
end

def emails(opts = {}, &block)
preset opts.merge(type: :email), &block
end

def validators(opts = {}, &block)
preset opts.merge(type: :validator), &block
end
Expand Down
4 changes: 3 additions & 1 deletion lib/browserino/definitions/labels.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,7 @@
label :windows_vista, for: :windows, range: '6.0'..'6.0.9'
label :windows_7, for: :windows, range: '6.1'..'6.1.9'
label :windows_8, for: :windows, range: '6.2'..'6.3'
label :windows_10, for: :windows, range: '10.0'..'10.0.9'
label :windows_10, for: :windows, range: '10.0'..'10.9.9'

label :outlook_2016, for: :outlook, range: '16.0'..'16.9.9'
end
30 changes: 27 additions & 3 deletions lib/browserino/definitions/matchers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# a simple set of global matchers that will be merged and scanned
# with a specific matcher when the final client object is created
match do
locale %r{(?<!nintendo)[;\s(]([a-z]{2}(?:\-[a-z]{2})?)[;)]}i
locale %r{(?<!nintendo)[;\s(]([a-z]{2}(?:[-_][a-z]{2})?)[;)]}i
architecture %r{((?:(?:x|x86_|amd|wow|win)64)|i[36]86|arm)}i

mobile %r{(bolt|nokia|samsung(?!b)|mobi(?:le)?|i?p(?:[ao]d|hone)
Expand All @@ -26,15 +26,36 @@

platform %r{.*(xbox|wii|nintendo\sds|playstation|windows(?:\sphone)?
|macintosh|mac\sos\sx|android|tizen|ip(?:[ao]d|hone)
|blackberry|cros|linux|ubuntu|x11|bsd|s(?:unos|olaris)
|amigaos|w(?:eb)?os|risc)}xi
|blackberry|risc|linux|ubuntu|x11|bsd|s(?:unos|olaris)
|amigaos|w(?:eb)?os|(?<!mi)cros)}xi

platform_version %r{(?:windows(?:\sphone(?:\sos)?)?|nt|android|linux/?
|mac\sos\sx(?:\s\w+\s)?|(?:cpu\s|ip(?:[ao]d|hone)\s)os
|blackberry|bb|s(?:unos|olaris)/?|w(?:eb)?os/|tizen
|amigaos/?|cros\s[\w-]+)\s?([\d\._]+)}xi
end

# automatically set type to :email for each defined matcher
emails do
match %r{outlook}i, name: :outlook
match %r{airmail}i, name: :airmail, engine: :webkit
match %r{barca}i, name: :barca, version: %r{barca(?:pro)?/([\d\.]+)}i

match %r{ggpht}i do
name :gmail
engine %r{(trident|gecko|webkit|presto|blink|servo|edge)}i
engine_version %r{(?:rv:|trident|webkit|presto|blink
|servo|edge)[\s/]?([\d\.]+)}i
end
end

# these are the same as above except with engine set to gecko and
# to look for engine_version using gecko version pattern
emails engine: :gecko, engine_version: %r{rv:\s?([\d\.]+)}i do
match %r{thunderbird}i, name: :thunderbird
match %r{postbox}i, name: :postbox
end

# automatically set type to :browser for each defined matcher
browsers do
# a single matcher that will create a matcher for a specific match
Expand Down Expand Up @@ -135,6 +156,7 @@
end

# automatically set type to :bot for each defined matcher
# additionally, set text to true to each of the matchers automatically
bots text: true do
match %r{googlebot}i, name: :googlebot
match %r{yahoo\!\sslurp}i, name: :yahoo_slurp
Expand Down Expand Up @@ -229,6 +251,7 @@
end

# automatically set type to :validator for each defined matcher
# additionally, set text to true to each of the matchers automatically
validators text: true do
match %r{cse\shtml\svalidator}i, name: :cse_html_validator
match %r{csscheck}i, name: :csscheck
Expand All @@ -245,6 +268,7 @@
end

# automatically set type to :library for each defined matcher
# additionally, set text to true to each of the matchers automatically
libraries text: true do
match %r{Go-http-client}i, name: :golang, version: %r{-client/([\d\.]+)}i
match %r{python}i, name: :python, version: %r{-urllib/([\d\.]+)}i
Expand Down
93 changes: 93 additions & 0 deletions spec/files/emails.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
---
:emails:
- :user_agent: Mozilla/5.0 (Windows NT 6.2; WOW64; rv:7.0.1) Gecko/20151105 Postbox/4.0.8
:name: :postbox
:version: '4.0.8'
:engine: :gecko
:engine_version: '7.0.1'
:platform: :windows
:platform_version: '6.2'
:platform_label: :windows_8
:architecture: :x64
:locale:
:to_s: 'postbox postbox4 gecko gecko7 windows windows6'

- :user_agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.1.8) Gecko/20100317 Postbox/1.1.3
:name: :postbox
:version: '1.1.3'
:engine: :gecko
:engine_version: '1.9.1.8'
:platform: :macintosh
:platform_version: '10.6'
:platform_label: :snow_leopard
:architecture:
:locale: :en_us
:to_s: 'postbox postbox1 gecko gecko1 macintosh macintosh10'

- :user_agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.14) Gecko/20080505 Thunderbird/2.0.0.14
:name: :thunderbird
:version: '2.0.0.14'
:engine: :gecko
:engine_version: '1.8.1.14'
:platform: :linux
:platform_version:
:platform_label:
:architecture: :x64
:locale: :en_us
:to_s: 'thunderbird thunderbird2 gecko gecko1 linux'

- :user_agent: Microsoft Office/16.0 (Windows NT 10.0; Microsoft Outlook 16.0.6326; Pro)
:name: :outlook
:version: '16.0.6326'
:label: :outlook_2016
:engine:
:engine_version:
:platform: :windows
:platform_version: '10'
:platform_label: :windows_10
:locale:
:to_s: 'outlook outlook16 windows windows10'

- :user_agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.0.7) Gecko/2009021910 Firefox/3.0.7 (via ggpht.com)
:name: :gmail
:version:
:engine: :gecko
:engine_version: '1.9.0.7'
:platform: :windows
:platform_version: '5.1'
:platform_label: :windows_xp
:locale: :de
:to_s: 'gmail gecko gecko1 windows windows5'

- :user_agent: BarcaPro/2.8.4400
:name: :barca
:version: '2.8.4400'
:engine:
:engine_version:
:platform:
:platform_version:
:platform_label:
:locale:
:to_s: 'barca barca2'

- :user_agent: Barca/2.0.3350
:name: :barca
:version: '2.0.3350'
:engine:
:engine_version:
:platform:
:platform_version:
:platform_label:
:locale:
:to_s: 'barca barca2'

- :user_agent: Airmail 1.0 rv:148 (Macintosh; Mac OS X 10.8.3; en_BE)
:name: :airmail
:version: '1.0'
:engine: :webkit
:engine_version:
:platform: :macintosh
:platform_version: '10.8.3'
:platform_label: :mountain_lion
:locale: :en_be
:to_s: 'airmail airmail1 webkit macintosh macintosh10'
10 changes: 7 additions & 3 deletions spec/non_browser_spec.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
# frozen_string_literal: true

require 'spec_helper'

TYPE_MAP = { validators: :validator, bots: :bot, libraries: :library }
(Library.data.keys - [:browsers]).each do |type|
TYPE_MAP = { validators: :validator, bots: :bot, libraries: :library,
emails: :email }.freeze

TYPE_MAP.each do |type, singular_type|
describe "Browserino #{type}" do
Library.data.fetch(type, []).shuffle.each do |spec|
ua = spec.delete :user_agent
client = Browserino.parse ua
spec[:type] ||= TYPE_MAP[type]
spec[:type] ||= singular_type

describe [client.name, ua].join(' :: ') do
if spec[:to_s]
Expand Down

0 comments on commit d30d713

Please sign in to comment.