From cb0d9ec95cbde06c20692ea133820413947c65e8 Mon Sep 17 00:00:00 2001 From: gjutras Date: Mon, 28 Mar 2022 19:59:59 -0400 Subject: [PATCH 1/3] Allow kindle_email to be CSV to allow sending to multiple kindles --- cps/helper.py | 33 +++++++++++++++++++-------------- cps/tasks/convert.py | 18 ++++++++++-------- cps/templates/user_edit.html | 2 +- 3 files changed, 30 insertions(+), 23 deletions(-) diff --git a/cps/helper.py b/cps/helper.py index 4928d388..ddaf507f 100644 --- a/cps/helper.py +++ b/cps/helper.py @@ -109,9 +109,11 @@ def convert_book_format(book_id, calibrepath, old_book_format, new_book_format, def send_test_mail(kindle_mail, user_name): - WorkerThread.add(user_name, TaskEmail(_(u'Calibre-Web test e-mail'), None, None, - config.get_mail_settings(), kindle_mail, _(u"Test e-mail"), - _(u'This e-mail has been sent via Calibre-Web.'))) + for email in kindle_mail.split(','): + email = email.strip() + WorkerThread.add(user_name, TaskEmail(_(u'Calibre-Web test e-mail'), None, None, + config.get_mail_settings(), email, _(u"Test e-mail"), + _(u'This e-mail has been sent via Calibre-Web.'))) return @@ -217,9 +219,11 @@ def send_mail(book_id, book_format, convert, kindle_mail, calibrepath, user_id): converted_file_name = entry.name + '.' + book_format.lower() link = '{}'.format(url_for('web.show_book', book_id=book_id), escape(book.title)) email_text = _(u"%(book)s send to Kindle", book=link) - WorkerThread.add(user_id, TaskEmail(_(u"Send to Kindle"), book.path, converted_file_name, - config.get_mail_settings(), kindle_mail, - email_text, _(u'This e-mail has been sent via Calibre-Web.'))) + for email in kindle_mail.split(','): + email = email.strip() + WorkerThread.add(user_id, TaskEmail(_(u"Send to Kindle"), book.path, converted_file_name, + config.get_mail_settings(), email, + email_text, _(u'This e-mail has been sent via Calibre-Web.'))) return return _(u"The requested file could not be read. Maybe wrong permissions?") @@ -644,14 +648,15 @@ def check_username(username): return username -def valid_email(email): - email = email.strip() - # Regex according to https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/email#validation - if not re.search(r"^[\w.!#$%&'*+\\/=?^_`{|}~-]+@[\w](?:[\w-]{0,61}[\w])?(?:\.[\w](?:[\w-]{0,61}[\w])?)*$", - email): - log.error(u"Invalid e-mail address format") - raise Exception(_(u"Invalid e-mail address format")) - return email +def valid_email(emails): + for email in emails.split(','): + email = email.strip() + # Regex according to https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/email#validation + if not re.search(r"^[\w.!#$%&'*+\\/=?^_`{|}~-]+@[\w](?:[\w-]{0,61}[\w])?(?:\.[\w](?:[\w-]{0,61}[\w])?)*$", + email): + log.error(u"Invalid e-mail address format") + raise Exception(_(u"Invalid e-mail address format")) + return emails # ################################# External interface ################################# diff --git a/cps/tasks/convert.py b/cps/tasks/convert.py index 98cd7b48..a67edaf8 100644 --- a/cps/tasks/convert.py +++ b/cps/tasks/convert.py @@ -90,14 +90,16 @@ class TaskConvert(CalibreTask): # todo: figure out how to incorporate this into the progress try: EmailText = _(u"%(book)s send to Kindle", book=escape(self.title)) - worker_thread.add(self.user, TaskEmail(self.settings['subject'], - self.results["path"], - filename, - self.settings, - self.kindle_mail, - EmailText, - self.settings['body'], - internal=True) + for email in self.kindle_mail.split(','): + email = email.strip() + worker_thread.add(self.user, TaskEmail(self.settings['subject'], + self.results["path"], + filename, + self.settings, + email, + EmailText, + self.settings['body'], + internal=True) ) except Exception as ex: return self._handleError(str(ex)) diff --git a/cps/templates/user_edit.html b/cps/templates/user_edit.html index b489cbaf..b5f7f333 100644 --- a/cps/templates/user_edit.html +++ b/cps/templates/user_edit.html @@ -25,7 +25,7 @@ {% endif %}
- +
{% if not content.role_anonymous() %} From ff46af9c495b4cb14f8b253c707bae7f07dcfd6b Mon Sep 17 00:00:00 2001 From: gjutras Date: Sun, 10 Jul 2022 17:23:20 -0400 Subject: [PATCH 2/3] fix indentation and spaces --- cps/helper.py | 12 ++++++------ cps/tasks/convert.py | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/cps/helper.py b/cps/helper.py index e7d8fcf0..6ae78a0e 100755 --- a/cps/helper.py +++ b/cps/helper.py @@ -112,9 +112,9 @@ def convert_book_format(book_id, calibre_path, old_book_format, new_book_format, def send_test_mail(ereader_mail, user_name): for email in ereader_mail.split(','): email = email.strip() - WorkerThread.add(user_name, TaskEmail(_(u'Calibre-Web test e-mail'), None, None, - config.get_mail_settings(), email, N_(u"Test e-mail"), - _(u'This e-mail has been sent via Calibre-Web.'))) + WorkerThread.add(user_name, TaskEmail(_(u'Calibre-Web test e-mail'), None, None, + config.get_mail_settings(), email, N_(u"Test e-mail"), + _(u'This e-mail has been sent via Calibre-Web.'))) return @@ -226,9 +226,9 @@ def send_mail(book_id, book_format, convert, ereader_mail, calibrepath, user_id) email_text = N_(u"%(book)s send to E-Reader", book=link) for email in ereader_mail.split(','): email = email.strip() - WorkerThread.add(user_id, TaskEmail(_(u"Send to E-Reader"), book.path, converted_file_name, - config.get_mail_settings(), email, - email_text, _(u'This e-mail has been sent via Calibre-Web.'))) + WorkerThread.add(user_id, TaskEmail(_(u"Send to E-Reader"), book.path, converted_file_name, + config.get_mail_settings(), email, email_text, + _(u'This e-mail has been sent via Calibre-Web.'))) return return _(u"The requested file could not be read. Maybe wrong permissions?") diff --git a/cps/tasks/convert.py b/cps/tasks/convert.py index 7ce852e4..540394ee 100755 --- a/cps/tasks/convert.py +++ b/cps/tasks/convert.py @@ -96,11 +96,11 @@ class TaskConvert(CalibreTask): self.results["path"], filename, self.settings, - email, + email, EmailText, self.settings['body'], internal=True) - ) + ) except Exception as ex: return self._handleError(str(ex)) From c974cd048ee3c97d14978bc96a0d7931c9bc664c Mon Sep 17 00:00:00 2001 From: gjutras Date: Tue, 2 Aug 2022 19:51:31 -0400 Subject: [PATCH 3/3] minor formatting --- cps/helper.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cps/helper.py b/cps/helper.py index d2026db0..e238132f 100755 --- a/cps/helper.py +++ b/cps/helper.py @@ -113,7 +113,7 @@ def send_test_mail(ereader_mail, user_name): for email in ereader_mail.split(','): email = email.strip() WorkerThread.add(user_name, TaskEmail(_(u'Calibre-Web test e-mail'), None, None, - config.get_mail_settings(), email, N_(u"Test e-mail"), + config.get_mail_settings(), email, N_(u"Test e-mail"), _(u'This e-mail has been sent via Calibre-Web.'))) return @@ -227,8 +227,8 @@ def send_mail(book_id, book_format, convert, ereader_mail, calibrepath, user_id) for email in ereader_mail.split(','): email = email.strip() WorkerThread.add(user_id, TaskEmail(_(u"Send to E-Reader"), book.path, converted_file_name, - config.get_mail_settings(), email, email_text, - _(u'This e-mail has been sent via Calibre-Web.'))) + config.get_mail_settings(), email, + email_text, _(u'This e-mail has been sent via Calibre-Web.'))) return return _(u"The requested file could not be read. Maybe wrong permissions?")