Bugfix: Email addressparser

Cleanup vendor scripts
This commit is contained in:
djmaze 2020-08-12 11:49:40 +02:00
parent aaf4933b0a
commit a8ef5ec75b
11 changed files with 651 additions and 968 deletions

View file

@ -7,19 +7,15 @@ import { Mime } from 'Common/Mime';
const
$ = jQuery,
$div = $('<div></div>'),
isArray = Array.isArray;
var htmlspecialchars = ((de,se,gt,lt,sq,dq,bt) => {
return (str, quote_style = 3, double_encode = true) => {
str = (''+str)
.replace(double_encode?de:se,'&amp;')
.replace(gt,'&lt;')
.replace(lt,'&gt;')
.replace(bt,'&#x60;');
if (quote_style & 1) { str = str.replace(sq,'&#x27;'); }
return (quote_style & 2) ? str.replace(dq,'&quot;') : str;
};
})(/&/g,/&(?![\w#]+;)/gi,/</g,/>/g,/'/g,/"/g,/`/g);
isArray = Array.isArray,
htmlmap = {
'&': '&amp;',
'<': '&lt;',
'>': '&gt;',
'"': '&quot;',
"'": '&#x27;'
},
htmlspecialchars = str => (''+str).replace(/[&<>"']/g, m => htmlmap[m]);
/**
* @param {*} value
@ -89,15 +85,13 @@ export function simpleQueryParser(queryString) {
* @returns {string}
*/
export function fakeMd5(len = 32) {
const line = '0123456789abcdefghijklmnopqrstuvwxyz',
lineLen = line.length;
const line = '0123456789abcdefghijklmnopqrstuvwxyz';
len = pInt(len);
let result = '';
while (result.length < len) {
result += line.substr(Math.round(Math.random() * lineLen), 1);
}
while (len--)
result += line.substr(Math.round(Math.random() * 36), 1);
return result;
}

22
dev/External/ko.js vendored
View file

@ -747,35 +747,33 @@ ko.bindingHandlers.emailsTags = {
$el = $(element),
fValue = fValueAccessor(),
fAllBindings = fAllBindingsAccessor(),
fAutoCompleteSource = fAllBindings.autoCompleteSource || null,
inputDelimiters = [',', ';', '\n'],
fFocusCallback = (value) => {
if (fValue && fValue.focused) {
fValue.focused(!!value);
}
};
inputDelimiters = [',', ';', '\n'];
$el.inputosaurus({
parseOnBlur: true,
allowDragAndDrop: true,
focusCallback: fFocusCallback,
focusCallback: value => {
if (fValue && fValue.focused) {
fValue.focused(!!value);
}
},
inputDelimiters: inputDelimiters,
autoCompleteSource: fAutoCompleteSource,
splitHook: (value) => {
autoCompleteSource: fAllBindings.autoCompleteSource || null,
splitHook: value => {
const v = value.trim();
if (v && inputDelimiters.includes(v.substr(-1))) {
return EmailModel.splitEmailLine(value);
}
return null;
},
parseHook: (input) =>
parseHook: input =>
input.map(inputValue => {
const values = EmailModel.parseEmailLine(inputValue);
return values.length ? values : inputValue;
}).flat(Infinity).map(
item => (item.toLine ? [item.toLine(false), item] : [item, null])
),
change: (event) => {
change: event => {
$el.data('EmailsTagsValue', event.target.value);
fValue(event.target.value);
}

View file

@ -1,4 +1,4 @@
import { encodeHtml, isNonEmptyArray } from 'Common/Utils';
import { encodeHtml } from 'Common/Utils';
'use strict';
@ -64,12 +64,10 @@ function _handleAddress(tokens) {
comment: [],
group: [],
text: []
// Filter out <addresses>, (comments) and regular text
};
for (var i = 0, len = tokens.length; i < len; i++) {
var token = tokens[i];
// Filter out <addresses>, (comments) and regular text
tokens.forEach(token => {
if (token.type === 'operator') {
switch (token.value) {
case '<':
@ -85,12 +83,10 @@ function _handleAddress(tokens) {
default:
state = 'text';
}
} else {
if (token.value) {
data[state].push(token.value);
}
} else if (token.value) {
data[state].push(token.value);
}
}
});
// If there is no text but a comment, replace the two
if (!data.text.length && data.comment.length) {
@ -108,25 +104,25 @@ function _handleAddress(tokens) {
} else {
// If no address was found, try to detect one from regular text
if (!data.address.length && data.text.length) {
for (var _i = data.text.length - 1; _i >= 0; _i--) {
if (data.text[_i].match(/^[^@\s]+@[^@\s]+$/)) {
data.address = data.text.splice(_i, 1);
var i = data.text.length;
while (i--) {
if (data.text[i].match(/^[^@\s]+@[^@\s]+$/)) {
data.address = data.text.splice(i, 1);
break;
}
}
var _regexHandler = function _regexHandler(address) {
if (!data.address.length) {
data.address = [address.trim()];
return ' ';
}
return address;
};
// still no address
if (!data.address.length) {
for (var _i2 = data.text.length - 1; _i2 >= 0; _i2--) {
data.text[_i2] = data.text[_i2].replace(/\s*\b[^@\s]+@[^@\s]+\b\s*/, _regexHandler).trim();
i = data.text.length;
while (i--) {
data.text[i] = data.text[i].replace(/\s*\b[^@\s]+@[^@\s]+\b\s*/, address => {
if (!data.address.length) {
data.address = [address.trim()];
return '';
}
return address.trim();
});
if (data.address.length) {
break;
}
@ -202,8 +198,8 @@ class Tokenizer
}
tokenize() {
var list = [], i = this.str.length;
while (i--) this.checkChar(this.str[i]);
var list = [];
[...this.str].forEach(c => this.checkChar(c));
this.list.forEach(node => {
node.value = (node.value || '').toString().trim();
@ -420,7 +416,7 @@ class EmailModel {
static splitEmailLine(line) {
const parsedResult = addressparser(line);
if (isNonEmptyArray(parsedResult)) {
if (parsedResult.length) {
const result = [];
let exists = false;
parsedResult.forEach((item) => {
@ -443,7 +439,7 @@ class EmailModel {
static parseEmailLine(line) {
const parsedResult = addressparser(line);
if (isNonEmptyArray(parsedResult)) {
if (parsedResult.length) {
return parsedResult.map(item =>
item.address ? new EmailModel(item.address.replace(/^[<]+(.*)[>]+$/g, '$1'), item.name || '') : null
).filter(value => !!value);
@ -463,7 +459,7 @@ class EmailModel {
}
const result = addressparser(emailAddress);
if (isNonEmptyArray(result) && result[0]) {
if (result.length) {
this.name = result[0].name || '';
this.email = result[0].address || '';
this.clearDuplicateName();

View file

@ -1401,7 +1401,7 @@ class ComposePopupView extends AbstractViewNext {
}
});
this.addAttachmentEnabled(true).dragAndDropEnabled(oJua.isDragAndDropSupported());
this.addAttachmentEnabled(true).dragAndDropEnabled(true);
} else {
this.addAttachmentEnabled(false).dragAndDropEnabled(false);
}