diff --git a/dev/Component/EmailAddresses.js b/dev/Component/EmailAddresses.js index b00c0336b..70db0536d 100644 --- a/dev/Component/EmailAddresses.js +++ b/dev/Component/EmailAddresses.js @@ -5,15 +5,15 @@ const contentType = 'snappymail/emailaddress', getAddressKey = li => li?.emailaddress?.key, parseEmailLine = line => addressparser(line).map(item => - (item.name || item.address) - ? new EmailModel(item.address, item.name) : null + (item.name || item.email) + ? new EmailModel(item.email, item.name) : null ).filter(v => v), splitEmailLine = line => { const result = []; let exists = false; addressparser(line).forEach(item => { - const address = (item.name || item.address) - ? new EmailModel(item.address, item.name) + const address = (item.name || item.email) + ? new EmailModel(item.email, item.name) : null; if (address?.email) { diff --git a/dev/Model/Email.js b/dev/Model/Email.js index 8b189407b..4a4a15c97 100644 --- a/dev/Model/Email.js +++ b/dev/Model/Email.js @@ -77,7 +77,7 @@ export function addressparser(str) { } else { endOperator = endOperator ? '' : OPERATORS[chr]; if ('<' === chr) { - node.type = 'address'; + node.type = 'email'; } else if ('(' === chr) { node.type = 'comment'; } else if (':' === chr) { @@ -94,7 +94,7 @@ export function addressparser(str) { pushAddress(); return addresses; -// return addresses.map(item => (item.name || item.address) ? new EmailModel(item.address, item.name) : null).filter(v => v); +// return addresses.map(item => (item.name || item.email) ? new EmailModel(item.email, item.name) : null).filter(v => v); } /** @@ -109,13 +109,12 @@ function _handleAddress(tokens) { address = {}, addresses = [], data = { - address: [], + email: [], comment: [], group: [], text: [] }; - // Filter out , (comments) and regular text tokens.forEach(token => { isGroup = isGroup || 'group' === token.type; data[token.type].push(token.value); @@ -129,68 +128,71 @@ function _handleAddress(tokens) { if (isGroup) { // http://tools.ietf.org/html/rfc2822#appendix-A.1.3 +/* addresses.push({ - address: '', + email: '', name: data.text.join(' ').trim(), group: addressparser(data.group.join(',')) // ,comment: data.comment.join(' ').trim() }); +*/ + addresses = addresses.concat(addressparser(data.group.join(','))); } else { // If no address was found, try to detect one from regular text - if (!data.address.length && data.text.length) { + if (!data.email.length && data.text.length) { var i = data.text.length; while (i--) { if (data.text[i].match(/^[^@\s]+@[^@\s]+$/)) { - data.address = data.text.splice(i, 1); + data.email = data.text.splice(i, 1); break; } } // still no address - if (!data.address.length) { + if (!data.email.length) { 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()]; + if (!data.email.length) { + data.email = [address.trim()]; return ''; } return address.trim(); }); - if (data.address.length) { + if (data.email.length) { break; } } } } - // If there's still is no text but a comment exists, replace the two + // If there's still no text but a comment exists, replace the two if (!data.text.length && data.comment.length) { data.text = data.comment; data.comment = []; } // Keep only the first address occurence, push others to regular text - if (data.address.length > 1) { - data.text = data.text.concat(data.address.splice(1)); + if (data.email.length > 1) { + data.text = data.text.concat(data.email.splice(1)); } address = { // Join values with spaces - address: data.address.join(' ').trim(), + email: data.email.join(' ').trim(), name: data.text.join(' ').trim() // ,comment: data.comment.join(' ').trim() }; - if (address.address === address.name) { - if (address.address.includes('@')) { + if (address.email === address.name) { + if (address.email.includes('@')) { address.name = ''; } else { - address.address = ''; + address.email = ''; } } -// address.address = address.address.replace(/^[<]+(.*)[>]+$/g, '$1'); +// address.email = address.email.replace(/^[<]+(.*)[>]+$/g, '$1'); addresses.push(address); } diff --git a/dev/Model/EmailCollection.js b/dev/Model/EmailCollection.js index a9dc69633..ab2d24aa8 100644 --- a/dev/Model/EmailCollection.js +++ b/dev/Model/EmailCollection.js @@ -40,7 +40,7 @@ export class EmailCollectionModel extends AbstractCollectionModel if (str) { let items = {}, key; addressparser(str).forEach(item => { - item = new EmailModel(item.address, item.name); + item = new EmailModel(item.email, item.name); // Make them unique key = item.email || item.name; if (key && (item.name || !items[key])) { diff --git a/dev/View/Popup/Compose.js b/dev/View/Popup/Compose.js index 2fe4eebf7..8eda55fc5 100644 --- a/dev/View/Popup/Compose.js +++ b/dev/View/Popup/Compose.js @@ -59,7 +59,7 @@ const base64_encode = text => btoa(unescape(encodeURIComponent(text))).match(/.{1,76}/g).join('\r\n'), - getEmail = value => addressparser(value)[0]?.address || false, + getEmail = value => addressparser(value)[0]?.email || false, /** * @param {Array} aList