mirror of
https://github.com/faisalman/ua-parser-js.git
synced 2026-01-16 08:27:12 +03:00
feat(email): expand email client detection & add Outlook edition helper (#819)
* feat(email): significantly expanded email client detection to support 40+ new user agents, including Alpine, Canary Mail, FairEmail, ProtonMail Bridge, Tutanota, and The Bat! feat(helpers): added getOutlookEdition() utility to interpret raw version strings into specific Outlook editions (e.g., distinguishing Outlook 2016 MSI vs. Click-to-Run/365). chore(enums): added comprehensive BrowserName.Email enums for all newly supported clients. chore(types): added TypeScript definitions for the new getOutlookEdition helper. test(email): added comprehensive test suite covering 60+ email client user agent strings. test(helpers): added unit tests for getOutlookEdition covering Windows (MSI/C2R) and Mac variants. * chore: Some small updates for business logic around K-9, Yahoo Mail, Outlook * test: Edgecase alignment and fixes chore(deps): npm vulnerability fix in package-lock.json chore: Updated dist builds * Revert accidentally-removed additional code and comments * Correct comment syntax in ua-parser-extensions.js Fix comment formatting and clean up code. * chore: build fix
This commit is contained in:
@@ -38,18 +38,34 @@ describe('Extensions', () => {
|
||||
});
|
||||
});
|
||||
|
||||
// Existing test cases
|
||||
const outlook = 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 10.0; WOW64; Trident/7.0; .NET4.0C; .NET4.0E; .NET CLR 2.0.50727; .NET CLR 3.0.30729; .NET CLR 3.5.30729; Microsoft Outlook 16.0.9126; Microsoft Outlook 16.0.9126; ms-office; MSOffice 16)';
|
||||
const thunderbird = 'Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.13.0';
|
||||
const axios = 'axios/1.3.5';
|
||||
const jsdom = 'Mozilla/5.0 (darwin) AppleWebKit/537.36 (KHTML, like Gecko) jsdom/20.0.3';
|
||||
const scrapy = 'Scrapy/1.5.0 (+https://scrapy.org)';
|
||||
|
||||
// New test cases for updated Regex logic
|
||||
const macOutlook = 'MacOutlook/16.61.22041701 (Intel Mac OS X 10.15.7)';
|
||||
const yahooMobile = 'YahooMobile/1.0 (mail; 3.0.5.1311380)';
|
||||
|
||||
assert.equal(UAParser(scrapy, Bots).browser.name, Library.SCRAPY);
|
||||
|
||||
const emailParser = new UAParser(Emails);
|
||||
|
||||
// Verify Standard Outlook
|
||||
assert.deepEqual(emailParser.setUA(outlook).getBrowser(), {name: Email.MICROSOFT_OUTLOOK, version: "16.0.9126", major: "16", type: BrowserType.EMAIL});
|
||||
|
||||
// Verify Thunderbird
|
||||
assert.deepEqual(emailParser.setUA(thunderbird).getBrowser(), {name: Email.THUNDERBIRD, version: "78.13.0", major: "78", type: BrowserType.EMAIL});
|
||||
|
||||
// Verify New MacOutlook Logic (Distinguishing it from Windows Outlook)
|
||||
assert.deepEqual(emailParser.setUA(macOutlook).getBrowser(), {name: Email.MICROSOFT_OUTLOOK_MAC, version: "16.61.22041701", major: "16", type: BrowserType.EMAIL});
|
||||
|
||||
// Verify Yahoo Mobile Logic (Tightened Regex)
|
||||
// Note: We expect 'Yahoo Mail' (Email.YAHOO_MAIL) because of the normalization helper.
|
||||
assert.deepEqual(emailParser.setUA(yahooMobile).getBrowser(), {name: Email.YAHOO_MAIL, version: "1.0", major: "1", type: BrowserType.EMAIL});
|
||||
|
||||
const libraryParser = new UAParser(Libraries);
|
||||
assert.deepEqual(libraryParser.setUA(axios).getBrowser(), {name: Library.AXIOS, version: "1.3.5", major: "1", type: BrowserType.LIBRARY});
|
||||
assert.deepEqual(libraryParser.setUA(jsdom).getBrowser(), {name: Library.JSDOM, version: "20.0.3", major: "20", type: BrowserType.LIBRARY});
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
const assert = require('assert');
|
||||
const { isFrozenUA } = require('../../../src/helpers/ua-parser-helpers');
|
||||
const { isFrozenUA, getOutlookEdition } = require('../../../src/helpers/ua-parser-helpers');
|
||||
|
||||
describe('isFrozenUA()', () => {
|
||||
it('matches supplied user-agent string with known frozen user-agent pattern', () => {
|
||||
@@ -10,4 +10,30 @@ describe('isFrozenUA()', () => {
|
||||
assert.equal(isFrozenUA(regularMobileUA), false);
|
||||
assert.equal(isFrozenUA(frozenMobileUA), true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getOutlookEdition()', () => {
|
||||
it('identifies Windows versions correctly', () => {
|
||||
// MSI Version (Older engine)
|
||||
assert.equal(getOutlookEdition('Microsoft Outlook', '16.0.4266.1001'), 'Outlook 2016 (MSI / Volume License)');
|
||||
// Click-to-Run (Modern engine)
|
||||
assert.equal(getOutlookEdition('Microsoft Outlook', '16.0.14326.20000'), 'Outlook 365 / 2019+ (Modern)');
|
||||
// Legacy Major Version
|
||||
assert.equal(getOutlookEdition('Microsoft Outlook', '15.0.4569.1506'), 'Outlook 2013');
|
||||
});
|
||||
|
||||
it('identifies Mac versions correctly', () => {
|
||||
assert.equal(getOutlookEdition('MacOutlook', '16.61'), 'Outlook for Mac (Modern)');
|
||||
assert.equal(getOutlookEdition('MacOutlook', '15.4'), 'Outlook for Mac (Legacy)');
|
||||
});
|
||||
|
||||
it('returns original name for unknown inputs', () => {
|
||||
assert.equal(getOutlookEdition('Thunderbird', '91.0'), 'Thunderbird');
|
||||
});
|
||||
|
||||
it('handles New Outlook (OneOutlook) correctly', () => {
|
||||
// New Outlook usually sends a browser UA, but if it sends "Outlook" without version info matches,
|
||||
// it shouldn't trigger the Legacy/MSI logic.
|
||||
assert.equal(getOutlookEdition('Microsoft Outlook', 'SomeRandomString'), 'Microsoft Outlook');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user