mirror of
https://github.com/inverse-inc/sogo.git
synced 2026-03-31 02:52:43 +00:00
fix(web(js)): improve validation of email addresses
Overwrite the AngularJS validation and transformation of email inputs in order to support umlauts and eszett.
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
/* -*- Mode: javascript; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
|
||||
String.emailRE = /([\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+\.)*[\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+@((((([\u00C0-\u017Fa-z0-9]{1}[\u00C0-\u017Fa-z0-9\-]{0,62}[\u00C0-\u017Fa-z0-9]{1})|[\u00C0-\u017Fa-z])\.)+[a-z]{2,})|(\d{1,3}\.){3}\d{1,3}(\:\d{1,5})?)/;
|
||||
|
||||
String.prototype.endsWith = function(suffix) {
|
||||
return this.indexOf(suffix, this.length - suffix.length) !== -1;
|
||||
};
|
||||
@@ -135,10 +137,13 @@ String.prototype.formatted = function() {
|
||||
};
|
||||
|
||||
String.prototype.isValidEmail = function(strict) {
|
||||
var emailRE = strict ?
|
||||
/^([\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+\.)*[\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+@((((([a-z0-9]{1}[a-z0-9\-]{0,62}[a-z0-9]{1})|[a-z])\.)+[a-z]{2,})|(\d{1,3}\.){3}\d{1,3}(\:\d{1,5})?)$/i : /([\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+\.)*[\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+@((((([a-z0-9]{1}[a-z0-9\-]{0,62}[a-z0-9]{1})|[a-z])\.)+[a-z]{2,})|(\d{1,3}\.){3}\d{1,3}(\:\d{1,5})?)/i;
|
||||
var result = emailRE.test(this);
|
||||
|
||||
return emailRE.test(this);
|
||||
if (strict && result) {
|
||||
result = emailRE.exec(this)[0] == this;
|
||||
}
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
String.prototype.asCSSIdentifier = function() {
|
||||
|
||||
@@ -11,16 +11,17 @@
|
||||
function CardController($scope, $timeout, $window, $mdDialog, sgSettings, AddressBook, Card, Dialog, sgHotkeys, focus, $state, $stateParams, stateCard) {
|
||||
var vm = this, hotkeys = [];
|
||||
|
||||
vm.card = stateCard;
|
||||
this.card = stateCard;
|
||||
|
||||
vm.currentFolder = AddressBook.selectedFolder;
|
||||
vm.allEmailTypes = Card.$EMAIL_TYPES;
|
||||
vm.allTelTypes = Card.$TEL_TYPES;
|
||||
vm.allUrlTypes = Card.$URL_TYPES;
|
||||
vm.allAddressTypes = Card.$ADDRESS_TYPES;
|
||||
vm.categories = {};
|
||||
vm.userFilterResults = [];
|
||||
vm.showRawSource = false;
|
||||
this.currentFolder = AddressBook.selectedFolder;
|
||||
this.allEmailTypes = Card.$EMAIL_TYPES;
|
||||
this.allTelTypes = Card.$TEL_TYPES;
|
||||
this.allUrlTypes = Card.$URL_TYPES;
|
||||
this.allAddressTypes = Card.$ADDRESS_TYPES;
|
||||
this.categories = {};
|
||||
this.userFilterResults = [];
|
||||
this.showRawSource = false;
|
||||
this.emailRE = String.emailRE;
|
||||
|
||||
|
||||
_registerHotkeys(hotkeys);
|
||||
|
||||
@@ -279,7 +279,7 @@
|
||||
if (angular.isString(this[type])) {
|
||||
// The recipient is a string; try to extract the name
|
||||
var emailRE = /<?(([\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+\.)*[\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+@((((([a-z0-9]{1}[a-z0-9\-]{0,62}[a-z0-9]{1})|[a-z])\.)+[a-z]{2,})|(\d{1,3}\.){3}\d{1,3}(\:\d{1,5})?))/i;
|
||||
var match = this[type].match(emailRE);
|
||||
var match = this[type].match(String.emailRE);
|
||||
if (match) {
|
||||
address = this[type].substring(0, match.index);
|
||||
address = address.replace(/^\"? *(.+?)\"? *$/, "$1");
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
this.account = account;
|
||||
this.accountId = accountId;
|
||||
this.hostnameRE = usesSSO && accountId > 0 ? /^(?!(127\.0\.0\.1|localhost(?:\.localdomain)?)$)/ : /./;
|
||||
this.emailRE = String.emailRE;
|
||||
this.addressesSearchText = '';
|
||||
this.ckConfig = {
|
||||
'autoGrow_minHeight': 70,
|
||||
|
||||
@@ -294,12 +294,11 @@
|
||||
destinationCalendar = Calendar.$get(this.component.destinationCalendar),
|
||||
options = initOrganizer? { organizerCalendar: destinationCalendar } : {},
|
||||
promises = [];
|
||||
var emailRE = /([\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+\.)*[\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+@((((([a-z0-9]{1}[a-z0-9\-]{0,62}[a-z0-9]{1})|[a-z])\.)+[a-z]{2,})|(\d{1,3}\.){3}\d{1,3}(\:\d{1,5})?)/i,
|
||||
i, address;
|
||||
var i, address;
|
||||
if (partial) options.partial = partial;
|
||||
|
||||
function createCard(str) {
|
||||
var match = str.match(emailRE),
|
||||
var match = str.match(String.emailRE),
|
||||
email = match[0],
|
||||
name = str.replace(new RegExp(" *<?" + email + ">? *"), '');
|
||||
vm.showAttendeesEditor |= initOrganizer;
|
||||
@@ -333,7 +332,7 @@
|
||||
card.charCodeAt(i) == 32 || // space
|
||||
card.charCodeAt(i) == 44 || // ,
|
||||
card.charCodeAt(i) == 59) && // ;
|
||||
emailRE.test(address)) {
|
||||
String.emailRE.test(address)) {
|
||||
promises.push(createCard(address).then(addCard));
|
||||
address = '';
|
||||
}
|
||||
@@ -341,7 +340,7 @@
|
||||
address += card.charAt(i);
|
||||
}
|
||||
}
|
||||
if (address && emailRE.test(address)) {
|
||||
if (address && String.emailRE.test(address)) {
|
||||
promises.push(createCard(address).then(addCard));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -245,6 +245,7 @@
|
||||
function PropertiesDialogController($scope, $mdDialog, srcCalendar) {
|
||||
var vm = this;
|
||||
|
||||
vm.emailRE = String.emailRE;
|
||||
vm.calendar = new Calendar(srcCalendar.$omit());
|
||||
vm.saveProperties = saveProperties;
|
||||
vm.close = close;
|
||||
|
||||
Reference in New Issue
Block a user