mirror of
https://github.com/pretix/pretix.git
synced 2026-05-06 15:24:02 +00:00
Invoice: Improve handling of special characters in file names (#3347)
Co-authored-by: Richard Schreiber <schreiber@rami.io>
This commit is contained in:
@@ -466,9 +466,17 @@ def mail_send_task(self, *args, to: List[str], subject: str, body: str, html: st
|
||||
for inv in invoices:
|
||||
if inv.file:
|
||||
try:
|
||||
# We try to give the invoice a more human-readable name, e.g. "Invoice_ABC-123.pdf" instead of
|
||||
# just "ABC-123.pdf", but we only do so if our currently selected language allows to do this
|
||||
# as ASCII text. For example, we would not want a "فاتورة_" prefix for our filename since this
|
||||
# has shown to cause deliverability problems of the email and deliverability wins.
|
||||
filename = pgettext('invoice', 'Invoice {num}').format(num=inv.number).replace(' ', '_') + '.pdf'
|
||||
if not re.match("^[a-zA-Z0-9-_%./,&:# ]+$", filename):
|
||||
filename = inv.number.replace(' ', '_') + '.pdf'
|
||||
filename = re.sub("[^a-zA-Z0-9-_.]+", "_", filename)
|
||||
with language(inv.order.locale):
|
||||
email.attach(
|
||||
pgettext('invoice', 'Invoice {num}').format(num=inv.number).replace(' ', '_') + '.pdf',
|
||||
filename,
|
||||
inv.file.file.read(),
|
||||
'application/pdf'
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user