Skip to content

Commit 756330d

Browse files
authored
Merge pull request #1179 from JulianAdams4/email-regex
Accept external email addresses format
2 parents 8d7ca2c + 7f6fc24 commit 756330d

File tree

6 files changed

+64
-11
lines changed

6 files changed

+64
-11
lines changed

electron_app/src/utils/RegexUtils.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
const emailRegex = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/;
1+
/* eslint no-useless-escape: 0 */
2+
const emailRegex = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
23
const HTMLTagsRegex = /<[^>]*>?/g;
34
const mailtoProtocolRegex = /^mailto:/;
45
const mailformedEventRegex = /(\[|,)null(\]|,)/g;

electron_app/src/utils/__tests__/RegexUtils.js

Lines changed: 54 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/* eslint-env node, jest */
2-
const { mailformedEventRegex } = require('./../RegexUtils');
2+
const { mailformedEventRegex, emailRegex } = require('./../RegexUtils');
33

4-
describe('Regex Utils: ', () => {
5-
it(' Should match malformed events ', () => {
4+
describe('Regex Utils: Pending events: ', () => {
5+
it('Should match malformed events ', () => {
66
const invalidStartComma =
77
'{"cmd":304,"params":{"labelsAdded":["Spam"],"labelsRemoved":[],"threadIds":[,null]}}';
88
const invalidBetweenComma =
@@ -18,7 +18,7 @@ describe('Regex Utils: ', () => {
1818
expect(invalidWithoutComma.match(mailformedEventRegex)).not.toBe(null);
1919
});
2020

21-
it(' Should not match wellformed events ', () => {
21+
it('Should not match wellformed events ', () => {
2222
const validAdded =
2323
'{"cmd":304,"params":{"labelsAdded":["null"],"labelsRemoved":[],"threadIds":["<1>"]}}';
2424
const validRemoved =
@@ -31,3 +31,53 @@ describe('Regex Utils: ', () => {
3131
expect(validAddedAndRemoved.match(mailformedEventRegex)).toBeNull();
3232
});
3333
});
34+
35+
describe('Regex Utils: Email address: ', () => {
36+
it('Should match valid email addresses', () => {
37+
const validEmailAddresses = [
38+
39+
40+
41+
42+
43+
44+
'email@[123.123.123.123]',
45+
'"email"@domain.com',
46+
47+
48+
49+
50+
51+
52+
53+
54+
'あいうえお@domain.com',
55+
56+
'reply+adelvyfdwyausnlpgjrihp53sytbxevbnhhb3iv4oy@reply.github.com'
57+
];
58+
for (const emailAddress of validEmailAddresses) {
59+
expect(emailAddress.match(emailRegex)).not.toBe(null);
60+
}
61+
});
62+
63+
it('Should not match invalid email addresses', () => {
64+
const invalidEmailAddresses = [
65+
'plainaddress',
66+
'#@%^%#$@#$@#.com',
67+
'@domain.com',
68+
'Joe Smith <[email protected]>',
69+
'email.domain.com',
70+
71+
72+
73+
74+
'[email protected] (Joe Smith)',
75+
'email@domain',
76+
77+
78+
];
79+
for (const emailAddress of invalidEmailAddresses) {
80+
expect(emailAddress.match(emailRegex)).toBe(null);
81+
}
82+
});
83+
});
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
export const emailRegex = /^(([a-z]*\+)?[\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/;
1+
/* eslint no-useless-escape: 0 */
2+
export const emailRegex = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
23
export const HTMLTagsRegex = /<[^>]*>?/g;
34
export const contactsRegex = string =>
45
new RegExp(`(^${string}| ${string})`, 'i');
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
export const emailRegex = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,8}(?:\.[a-z]{2})?)$/;
1+
/* eslint no-useless-escape: 0 */
2+
export const emailRegex = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
23
export const HTMLTagsRegex = /<[^>]*>?/g;
34
export const mimeTypeImageRegex = /image\/([a-z][-+])*/;

email_mailbox/src/utils/__tests__/EmailUtils.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ describe('Form recipients', () => {
190190
const data = {
191191
to: ['<[email protected]>'],
192192
cc: [
193-
'Name<>1 <[email protected]>',
193+
'Name<>1 <[email protected]>',
194194
195195
196196
],
@@ -217,7 +217,7 @@ describe('Check email is: to me or from me', () => {
217217
const data = {
218218
to: ['<[email protected]>'],
219219
cc: [
220-
'Name<>1 <[email protected]>',
220+
'Name<>1 <[email protected]>',
221221
222222
223223
],
@@ -233,7 +233,7 @@ describe('Check email is: to me or from me', () => {
233233
const data = {
234234
to: ['<[email protected]>'],
235235
cc: [
236-
'Name<>1 <[email protected]>',
236+
'Name<>1 <[email protected]>',
237237
238238
239239
],

email_mailbox/src/utils/__tests__/__snapshots__/EmailUtils.js.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Object {
1212
1313
],
1414
"cc": Array [
15-
"Name<>1 <[email protected]>",
15+
"Name<>1 <[email protected]>",
1616
1717
1818
],

0 commit comments

Comments
 (0)