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

use book title not file name as attachment name when sending email #2695

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
8 changes: 5 additions & 3 deletions cps/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,11 @@ def send_mail(book_id, book_format, convert, ereader_mail, calibrepath, user_id)
converted_file_name = entry.name + '.' + book_format.lower()
link = '<a href="{}">{}</a>'.format(url_for('web.show_book', book_id=book_id), escape(book.title))
email_text = N_("%(book)s send to eReader", book=link)
WorkerThread.add(user_id, TaskEmail(_("Send to eReader"), book.path, converted_file_name,
config.get_mail_settings(), ereader_mail,
email_text, _('This Email 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(), ereader_mail,
email_text, _(u'This e-mail has been sent via Calibre-Web.'),
False,
str(book.title.encode('utf-8'), 'utf-8') + '.' + book_format.lower()))
return
return _("The requested file could not be read. Maybe wrong permissions?")

Expand Down
8 changes: 6 additions & 2 deletions cps/tasks/mail.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ def __init__(self, *args, **kwargs):


class TaskEmail(CalibreTask):
def __init__(self, subject, filepath, attachment, settings, recipient, task_message, text, internal=False):
def __init__(self, subject, filepath, attachment, settings, recipient, task_message, text, internal=False
, display_name=""):
super(TaskEmail, self).__init__(task_message)
self.subject = subject
self.attachment = attachment
Expand All @@ -119,6 +120,9 @@ def __init__(self, subject, filepath, attachment, settings, recipient, task_mess
self.text = text
self.asyncSMTP = None
self.results = dict()
if display_name == "":
display_name = attachment
self.display_name = display_name

# from calibre code:
# https://github.com/kovidgoyal/calibre/blob/731ccd92a99868de3e2738f65949f19768d9104c/src/calibre/utils/smtp.py#L60
Expand Down Expand Up @@ -150,7 +154,7 @@ def prepare_message(self):
if content_type is None or encoding is not None:
content_type = 'application/octet-stream'
main_type, sub_type = content_type.split('/', 1)
message.add_attachment(data, maintype=main_type, subtype=sub_type, filename=self.attachment)
message.add_attachment(data, maintype=main_type, subtype=sub_type, filename=self.display_name)
else:
self._handleError("Attachment not found")
return
Expand Down