mirror of
https://github.com/hcengineering/platform.git
synced 2025-06-11 21:11:57 +00:00
UBERF-11175: Fix person names
Signed-off-by: Artem Savchenko <armisav@gmail.com>
This commit is contained in:
parent
8dd1e19685
commit
c73753048b
@ -47,8 +47,8 @@ describe('parseEmailHeader', () => {
|
|||||||
expect(result).toEqual([
|
expect(result).toEqual([
|
||||||
{
|
{
|
||||||
email: 'john.doe@example.com',
|
email: 'john.doe@example.com',
|
||||||
firstName: '<john.doe@example.com>',
|
firstName: 'John',
|
||||||
lastName: 'John Doe'
|
lastName: 'Doe'
|
||||||
}
|
}
|
||||||
])
|
])
|
||||||
})
|
})
|
||||||
@ -58,8 +58,8 @@ describe('parseEmailHeader', () => {
|
|||||||
expect(result).toEqual([
|
expect(result).toEqual([
|
||||||
{
|
{
|
||||||
email: 'john.doe@example.com',
|
email: 'john.doe@example.com',
|
||||||
firstName: '<john.doe@example.com>',
|
firstName: 'John',
|
||||||
lastName: 'John Doe'
|
lastName: 'Doe'
|
||||||
}
|
}
|
||||||
])
|
])
|
||||||
})
|
})
|
||||||
@ -69,8 +69,8 @@ describe('parseEmailHeader', () => {
|
|||||||
expect(result).toEqual([
|
expect(result).toEqual([
|
||||||
{
|
{
|
||||||
email: 'john.doe@example.com',
|
email: 'john.doe@example.com',
|
||||||
firstName: '<john.doe@example.com>',
|
firstName: 'John Doe Smith',
|
||||||
lastName: 'John Doe Smith'
|
lastName: ''
|
||||||
}
|
}
|
||||||
])
|
])
|
||||||
})
|
})
|
||||||
@ -96,13 +96,13 @@ describe('parseEmailHeader', () => {
|
|||||||
expect(result).toEqual([
|
expect(result).toEqual([
|
||||||
{
|
{
|
||||||
email: 'john@example.com',
|
email: 'john@example.com',
|
||||||
firstName: '<john@example.com>',
|
firstName: 'John',
|
||||||
lastName: 'John'
|
lastName: ''
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
email: 'jane@example.com',
|
email: 'jane@example.com',
|
||||||
firstName: '<jane@example.com>',
|
firstName: 'Jane',
|
||||||
lastName: 'Jane Doe'
|
lastName: 'Doe'
|
||||||
}
|
}
|
||||||
])
|
])
|
||||||
})
|
})
|
||||||
@ -112,13 +112,13 @@ describe('parseEmailHeader', () => {
|
|||||||
expect(result).toEqual([
|
expect(result).toEqual([
|
||||||
{
|
{
|
||||||
email: 'john@example.com',
|
email: 'john@example.com',
|
||||||
firstName: '<john@example.com>',
|
firstName: 'Doe',
|
||||||
lastName: 'Doe, John'
|
lastName: 'John'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
email: 'jane@example.com',
|
email: 'jane@example.com',
|
||||||
firstName: '<jane@example.com>',
|
firstName: 'Jane',
|
||||||
lastName: 'Jane Doe'
|
lastName: 'Doe'
|
||||||
}
|
}
|
||||||
])
|
])
|
||||||
})
|
})
|
||||||
@ -133,8 +133,8 @@ describe('parseEmailHeader', () => {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
email: 'jane@example.com',
|
email: 'jane@example.com',
|
||||||
firstName: '<jane@example.com>',
|
firstName: 'Jane',
|
||||||
lastName: 'Jane Doe'
|
lastName: 'Doe'
|
||||||
}
|
}
|
||||||
])
|
])
|
||||||
})
|
})
|
||||||
@ -165,8 +165,8 @@ describe('parseEmailHeader', () => {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
email: 'jane@example.com',
|
email: 'jane@example.com',
|
||||||
firstName: '<jane@example.com>',
|
firstName: 'Jane',
|
||||||
lastName: 'Jane Doe'
|
lastName: 'Doe'
|
||||||
}
|
}
|
||||||
])
|
])
|
||||||
})
|
})
|
||||||
@ -176,13 +176,13 @@ describe('parseEmailHeader', () => {
|
|||||||
expect(result).toEqual([
|
expect(result).toEqual([
|
||||||
{
|
{
|
||||||
email: 'example-staff@example.com',
|
email: 'example-staff@example.com',
|
||||||
firstName: '<example-staff@example.com>',
|
firstName: 'example',
|
||||||
lastName: 'example staff'
|
lastName: 'staff'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
email: 'personnel@example.com',
|
email: 'personnel@example.com',
|
||||||
firstName: '<personnel@example.com>',
|
firstName: 'personnel',
|
||||||
lastName: 'personnel'
|
lastName: ''
|
||||||
}
|
}
|
||||||
])
|
])
|
||||||
})
|
})
|
||||||
@ -208,13 +208,13 @@ describe('parseEmailHeader', () => {
|
|||||||
expect(result).toEqual([
|
expect(result).toEqual([
|
||||||
{
|
{
|
||||||
email: 'john@example.com',
|
email: 'john@example.com',
|
||||||
firstName: '<john@example.com>',
|
firstName: 'John',
|
||||||
lastName: 'John'
|
lastName: ''
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
email: 'jane@example.com',
|
email: 'jane@example.com',
|
||||||
firstName: '<jane@example.com>',
|
firstName: 'Jane',
|
||||||
lastName: 'Jane'
|
lastName: ''
|
||||||
}
|
}
|
||||||
])
|
])
|
||||||
})
|
})
|
||||||
@ -224,13 +224,13 @@ describe('parseEmailHeader', () => {
|
|||||||
expect(result).toEqual([
|
expect(result).toEqual([
|
||||||
{
|
{
|
||||||
email: 'john@example.com',
|
email: 'john@example.com',
|
||||||
firstName: '<john@example.com>',
|
firstName: 'John',
|
||||||
lastName: 'John'
|
lastName: ''
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
email: 'jane@example.com',
|
email: 'jane@example.com',
|
||||||
firstName: '<jane@example.com>',
|
firstName: 'Jane',
|
||||||
lastName: 'Jane'
|
lastName: ''
|
||||||
}
|
}
|
||||||
])
|
])
|
||||||
})
|
})
|
||||||
|
@ -21,8 +21,8 @@ describe('parseNameFromEmailHeader', () => {
|
|||||||
const input = '"John Doe" <john.doe@example.com>'
|
const input = '"John Doe" <john.doe@example.com>'
|
||||||
const expected: EmailContact = {
|
const expected: EmailContact = {
|
||||||
email: 'john.doe@example.com',
|
email: 'john.doe@example.com',
|
||||||
firstName: '<john.doe@example.com>',
|
firstName: 'John',
|
||||||
lastName: 'John Doe'
|
lastName: 'Doe'
|
||||||
}
|
}
|
||||||
|
|
||||||
expect(parseNameFromEmailHeader(input)).toEqual(expected)
|
expect(parseNameFromEmailHeader(input)).toEqual(expected)
|
||||||
@ -32,8 +32,8 @@ describe('parseNameFromEmailHeader', () => {
|
|||||||
const input = 'Jane Smith <jane.smith@example.com>'
|
const input = 'Jane Smith <jane.smith@example.com>'
|
||||||
const expected: EmailContact = {
|
const expected: EmailContact = {
|
||||||
email: 'jane.smith@example.com',
|
email: 'jane.smith@example.com',
|
||||||
firstName: '<jane.smith@example.com>',
|
firstName: 'Jane',
|
||||||
lastName: 'Jane Smith'
|
lastName: 'Smith'
|
||||||
}
|
}
|
||||||
|
|
||||||
expect(parseNameFromEmailHeader(input)).toEqual(expected)
|
expect(parseNameFromEmailHeader(input)).toEqual(expected)
|
||||||
@ -65,8 +65,8 @@ describe('parseNameFromEmailHeader', () => {
|
|||||||
const input = 'Maria Van Der Berg <maria@example.com>'
|
const input = 'Maria Van Der Berg <maria@example.com>'
|
||||||
const expected: EmailContact = {
|
const expected: EmailContact = {
|
||||||
email: 'maria@example.com',
|
email: 'maria@example.com',
|
||||||
firstName: '<maria@example.com>',
|
firstName: 'Maria Van Der Berg',
|
||||||
lastName: 'Maria Van Der Berg'
|
lastName: ''
|
||||||
}
|
}
|
||||||
|
|
||||||
expect(parseNameFromEmailHeader(input)).toEqual(expected)
|
expect(parseNameFromEmailHeader(input)).toEqual(expected)
|
||||||
@ -108,8 +108,8 @@ describe('parseNameFromEmailHeader', () => {
|
|||||||
const input = 'Support <help@example.com>'
|
const input = 'Support <help@example.com>'
|
||||||
const expected: EmailContact = {
|
const expected: EmailContact = {
|
||||||
email: 'help@example.com',
|
email: 'help@example.com',
|
||||||
firstName: '<help@example.com>',
|
firstName: 'Support',
|
||||||
lastName: 'Support'
|
lastName: ''
|
||||||
}
|
}
|
||||||
|
|
||||||
expect(parseNameFromEmailHeader(input)).toEqual(expected)
|
expect(parseNameFromEmailHeader(input)).toEqual(expected)
|
||||||
@ -119,8 +119,8 @@ describe('parseNameFromEmailHeader', () => {
|
|||||||
const input = '"O\'Neill, James" <james.oneill@example.com>'
|
const input = '"O\'Neill, James" <james.oneill@example.com>'
|
||||||
const expected: EmailContact = {
|
const expected: EmailContact = {
|
||||||
email: 'james.oneill@example.com',
|
email: 'james.oneill@example.com',
|
||||||
firstName: '<james.oneill@example.com>',
|
firstName: 'O\'Neill',
|
||||||
lastName: "O'Neill, James"
|
lastName: 'James'
|
||||||
}
|
}
|
||||||
|
|
||||||
expect(parseNameFromEmailHeader(input)).toEqual(expected)
|
expect(parseNameFromEmailHeader(input)).toEqual(expected)
|
||||||
|
@ -104,10 +104,26 @@ export function parseNameFromEmailHeader (headerValue: string | undefined): Emai
|
|||||||
const displayName = match[1]?.trim()
|
const displayName = match[1]?.trim()
|
||||||
const email = match[2].trim()
|
const email = match[2].trim()
|
||||||
|
|
||||||
const wrappedEmail = displayName != null && displayName.length > 0 ? `<${email}>` : email
|
if (displayName == null || displayName === '') {
|
||||||
|
return {
|
||||||
|
email,
|
||||||
|
firstName: email,
|
||||||
|
lastName: ''
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const nameParts = displayName
|
||||||
|
.split(/[\s,;]+/)
|
||||||
|
.filter((part) => part !== '')
|
||||||
|
if (nameParts.length === 2) {
|
||||||
|
return {
|
||||||
|
email,
|
||||||
|
firstName: nameParts[0],
|
||||||
|
lastName: nameParts[1]
|
||||||
|
}
|
||||||
|
}
|
||||||
return {
|
return {
|
||||||
email,
|
email,
|
||||||
firstName: wrappedEmail,
|
firstName: displayName,
|
||||||
lastName: displayName ?? ''
|
lastName: ''
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user