PocketBook is so bad I have no words

This commit is contained in:
Kovid Goyal 2022-09-08 17:17:22 +05:30
parent 2554ab467b
commit a911ffc16c
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -153,18 +153,16 @@ def send_mails(jobnames, callback, attachments, to_s, subjects,
for name, attachment, to, subject, text, aname in zip(jobnames, for name, attachment, to, subject, text, aname in zip(jobnames,
attachments, to_s, subjects, texts, attachment_names): attachments, to_s, subjects, texts, attachment_names):
description = _('Email %(name)s to %(to)s') % dict(name=name, to=to) description = _('Email %(name)s to %(to)s') % dict(name=name, to=to)
if isinstance(to, str) and ('@pbsync.com' in to or '@kindle.com' in to): if isinstance(to, str):
# The pbsync service chokes on non-ascii filenames and commas if '@kindle.com' in to:
# Dont know if amazon's service chokes or not, but since filenames aname = ascii_filename(aname)
# arent visible on Kindles anyway, might as well be safe elif '@pbsync.com' in to:
aname = ascii_filename(aname).replace(',', ' ') # The PocketBook service is a total joke. It cant handle
if '@pbsync.com' in to: # non-ascii, filenames that are long enough to be split up, commas, and
# pbsync chokes on filenames that need to be encoded on # the good lord alone knows what else. So use a random filename
# multiple lines in the SMTP header # containing only 22 English letters and numbers
limit = 58 from calibre.utils.short_uuid import uuid4
if len(aname) > limit: aname = f'{uuid4()}.' + aname.rpartition('.')[-1]
b, ext = os.path.splitext(aname)
aname = b[:limit - len(aname) - 1] + ext
job = ThreadedJob('email', description, gui_sendmail, (attachment, aname, to, job = ThreadedJob('email', description, gui_sendmail, (attachment, aname, to,
subject, text), {}, callback) subject, text), {}, callback)
job_manager.run_threaded_job(job) job_manager.run_threaded_job(job)