artemis/artemis.py
changeset 69 88c088722a30
parent 67 30bd40ef9165
child 70 5796e44b0e17
equal deleted inserted replaced
68:50ecb341130d 69:88c088722a30
   253             if counter in attachment_numbers:
   253             if counter in attachment_numbers:
   254                 filename = part.get_filename()
   254                 filename = part.get_filename()
   255                 if not filename:
   255                 if not filename:
   256                     ext = mimetypes.guess_extension(part.get_content_type()) or ''
   256                     ext = mimetypes.guess_extension(part.get_content_type()) or ''
   257                     filename = 'attachment-%03d%s' % (counter, ext)
   257                     filename = 'attachment-%03d%s' % (counter, ext)
       
   258                 else:
       
   259                     filename = os.path.basename(filename)
   258                 fp = open(filename, 'wb')
   260                 fp = open(filename, 'wb')
   259                 fp.write(part.get_payload(decode = True))
   261                 fp.write(part.get_payload(decode = True))
   260                 fp.close()
   262                 fp.close()
   261             counter += 1
   263             counter += 1
   262 
   264 
   417             attachment.set_payload(fp.read())
   419             attachment.set_payload(fp.read())
   418             fp.close()
   420             fp.close()
   419             # Encode the payload using Base64
   421             # Encode the payload using Base64
   420             encoders.encode_base64(attachment)
   422             encoders.encode_base64(attachment)
   421         # Set the filename parameter
   423         # Set the filename parameter
   422         attachment.add_header('Content-Disposition', 'attachment', filename=filename)
   424         attachment.add_header('Content-Disposition', 'attachment', filename=os.path.basename(filename))
   423         outer.attach(attachment)
   425         outer.attach(attachment)
   424     return outer
   426     return outer
   425 
   427 
   426 def _read_formats(ui):
   428 def _read_formats(ui):
   427     formats = []
   429     formats = []