Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Mail Master mail app for iOS & Android detection #474

Closed
wants to merge 9 commits into from
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
- Add Google Search App detection.
- Add Huawei Browser detection.
- Fix Duck Duck Go browser that was being recognized as a bot.
- Add Miui Browser detection
- Add Mail Master mail app for iOS & Android detection
- Add Miui Browser detection.
- Add `Browser::Base#qq?`.
- Fix QQ detection.
Expand Down
6 changes: 6 additions & 0 deletions lib/browser/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,12 @@ def sougou_browser?(expected_version = nil)
detect_version?(full_version, expected_version)
end

# Detect if browser is NetEase Mail Master.
def mail_master?(expected_version = nil)
MailMaster.new(ua).match? &&
detect_version?(full_version, expected_version)
end

# Detect if browser is Google Search App
def google_search_app?(expected_version = nil)
ua.include?("GSA") && detect_version?(full_version, expected_version)
Expand Down
1 change: 1 addition & 0 deletions lib/browser/browser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ def self.matchers
HuaweiBrowser, # must be placed before Chrome and Safari
MiuiBrowser, # must be placed before Chrome and Safari
Maxthon, # must be placed before Chrome and Safari
MailMaster, # must be placed before Chrome and Safari
SougouBrowser, # must be placed before Chrome and Safari
GoogleSearchApp, # must be placed before Chrome and Safari
Chrome,
Expand Down
1 change: 1 addition & 0 deletions lib/browser/chrome.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def match?
!huawei_browser? &&
!miui_browser? &&
!maxthon? &&
!mail_master? &&
!qq? &&
!sougou_browser? &&
!google_search_app?
Expand Down
21 changes: 21 additions & 0 deletions lib/browser/mail_master.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# frozen_string_literal: true

module Browser
class MailMaster < Base
def id
:mail_master
end

def name
"Mail Master"
end

def full_version
ua[%r{(?:MailMaster|MailMaster_Android_Mobile)/([\d.]+)}i, 1] || "0.0"
end

def match?
ua =~ /MailMaster/i
end
end
end
1 change: 1 addition & 0 deletions lib/browser/safari.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def match?
!yandex? &&
!sputnik? &&
!maxthon? &&
!mail_master? &&
!qq? &&
!alipay? &&
!sougou_browser? &&
Expand Down
2 changes: 2 additions & 0 deletions test/ua.yml
Original file line number Diff line number Diff line change
Expand Up @@ -172,3 +172,5 @@ XBOXONE: "Mozilla/5.0 (Compatible; MSIE 10.0; Windows NT 6.2; Trident /6.0; Xbox
XOOM: "Mozilla/5.0 (Linux; U; Android 3.0; en-us; Xoom Build/HRI39) AppleWebKit/534.13 (KHTML, like Gecko) Version/4.0 Safari/534.13"
YANDEX_BROWSER_DESKTOP: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 YaBrowser/19.6.0.1583 Yowser/2.5 Safari/537.36"
YANDEX_BROWSER_IOS: "Mozilla/5.0 (iPhone; CPU iPhone OS 12_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.0 YaBrowser/19.6.1.157.10 Mobile/15E148 Safari/605.1"
MAIL_MASTER_IOS: "Mozilla/5.0 (iPhone; CPU iPhone OS 13_4_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 MailMaster/6.22.4.1582"
MAIL_MASTER_ANDROID: "Mozilla/5.0 (Linux; Android 10; LIO-AL00 Build/HUAWEILIO-AL00; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/78.0.3904.108 Mobile Safari/537.36 MailMaster_Android_Mobile/6.22.1"
47 changes: 47 additions & 0 deletions test/unit/mail_master_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# frozen_string_literal: true

require "test_helper"

class MailMasterTest < Minitest::Test
test "detects MailMaster on iOS" do
browser = Browser.new(Browser["MAIL_MASTER_IOS"])
assert browser.platform.ios?("13.4.1")
assert browser.mail_master?
refute browser.safari?
refute browser.chrome?
assert_equal "Mail Master", browser.name
assert_equal :mail_master, browser.id
end

test "detects correct version on iOS" do
browser = Browser.new(Browser["MAIL_MASTER_IOS"])
assert_equal "6.22.4.1582", browser.full_version
assert_equal "6", browser.version
end

test "detects version by range on iOS" do
browser = Browser.new(Browser["MAIL_MASTER_IOS"])
assert browser.mail_master?(%w[>=6 <7])
end

test "detects MailMaster on Android" do
browser = Browser.new(Browser["MAIL_MASTER_ANDROID"])
assert browser.platform.android?(10)
assert browser.mail_master?
refute browser.safari?
refute browser.chrome?
assert_equal "Mail Master", browser.name
assert_equal :mail_master, browser.id
end

test "detects correct version on Android" do
browser = Browser.new(Browser["MAIL_MASTER_ANDROID"])
assert_equal "6.22.1", browser.full_version
assert_equal "6", browser.version
end

test "detects version by range on Android" do
browser = Browser.new(Browser["MAIL_MASTER_ANDROID"])
assert browser.mail_master?(%w[>=6 <7])
end
end
Loading