Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] #9298 : Add several e-mail addresses into address fields at once #9347

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 58 additions & 1 deletion src/components/Composer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -1216,15 +1216,72 @@
onNewBccAddr(option) {
this.onNewAddr(option, this.selectBcc)
},
onNewAddr(option, list) {
getLabelAndAddress(string) {
const regex = /(<)?(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9]))\.){3}(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9])|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])(>?|,?|;?|>?,?|>;?)/g

Check failure on line 1220 in src/components/Composer.vue

View workflow job for this annotation

GitHub Actions / NPM lint

Unexpected control character(s) in regular expression: \x01, \x08, \x0b, \x0c, \x0e, \x1f, \x01, \x09, \x0b, \x0c, \x0e, \x01, \x08, \x0b, \x0c, \x0e, \x1f, \x01, \x09, \x0b, \x0c, \x0e
const match = string.match(regex)

if (!match) return false

const email = match[0].replace(/<|>|\n/g, '').trim()
const label = string.split(match[0])[0].trim() || email

return { label, email }
},
parseEmailList(string) {
let start = 0
let inEmail = false
let list = []

Check failure on line 1233 in src/components/Composer.vue

View workflow job for this annotation

GitHub Actions / NPM lint

'list' is never reassigned. Use 'const' instead

for (let i = 0; i < string.length; i++) {
const char = string[i]

if (char === '@' || inEmail) {
inEmail = true

if ([';', ',', ' '].includes(char)) {
let stringAddress = string.substring(start, i).trim()

Check failure on line 1242 in src/components/Composer.vue

View workflow job for this annotation

GitHub Actions / NPM lint

'stringAddress' is never reassigned. Use 'const' instead
let labelAndAddress = this.getLabelAndAddress(stringAddress)

Check failure on line 1243 in src/components/Composer.vue

View workflow job for this annotation

GitHub Actions / NPM lint

'labelAndAddress' is never reassigned. Use 'const' instead

if (labelAndAddress) {
list.push(labelAndAddress)
}

inEmail = false
start = i + 1
}

Check failure on line 1251 in src/components/Composer.vue

View workflow job for this annotation

GitHub Actions / NPM lint

Unexpected tab character

Check failure on line 1251 in src/components/Composer.vue

View workflow job for this annotation

GitHub Actions / NPM lint

Trailing spaces not allowed
}
}

if (inEmail) {
let stringAddress = string.substring(start).trim()

Check failure on line 1256 in src/components/Composer.vue

View workflow job for this annotation

GitHub Actions / NPM lint

'stringAddress' is never reassigned. Use 'const' instead
let labelAndAddress = this.getLabelAndAddress(stringAddress)

Check failure on line 1257 in src/components/Composer.vue

View workflow job for this annotation

GitHub Actions / NPM lint

'labelAndAddress' is never reassigned. Use 'const' instead

if (labelAndAddress) {
list.push(labelAndAddress)
}
}

return list
},
pushNewAddr(option, list){

Check failure on line 1266 in src/components/Composer.vue

View workflow job for this annotation

GitHub Actions / NPM lint

Missing space before opening brace
if (list.some((recipient) => recipient.email === option.email)) {
return
}

const recipient = { ...option }
this.newRecipients.push(recipient)
list.push(recipient)
this.saveDraftDebounced()
},
onNewAddr(option, list) {
if (option.id) {
this.pushNewAddr(option, list)
} else {
const emailList = this.parseEmailList(option.email)

emailList.forEach(email => this.pushNewAddr(email, list));

Check failure on line 1282 in src/components/Composer.vue

View workflow job for this annotation

GitHub Actions / NPM lint

Extra semicolon
}
},
async onSend(_, force = false) {
if (this.encrypt) {
logger.debug('get encrypted message from mailvelope')
Expand Down
Loading