MCPcopy Index your code
hub / github.com/webpy/webpy / attach

Method attach

web/utils.py:1485–1514  ·  view source on GitHub ↗
(self, filename, content, content_type=None)

Source from the content-addressed store, hash-verified

1483 return Message()
1484
1485 def attach(self, filename, content, content_type=None):
1486 if not self.multipart:
1487 msg = self.new_message()
1488 msg.add_header("Content-Type", "multipart/mixed")
1489 msg.attach(self.message)
1490 self.message = msg
1491 self.multipart = True
1492
1493 import mimetypes
1494
1495 try:
1496 from email import encoders
1497 except:
1498 from email import Encoders as encoders
1499
1500 content_type = (
1501 content_type
1502 or mimetypes.guess_type(filename)[0]
1503 or "application/octet-stream"
1504 )
1505
1506 msg = self.new_message()
1507 msg.set_payload(content)
1508 msg.add_header("Content-Type", content_type)
1509 msg.add_header("Content-Disposition", "attachment", filename=filename)
1510
1511 if not content_type.startswith("text/"):
1512 encoders.encode_base64(msg)
1513
1514 self.message.attach(msg)
1515
1516 def prepare_message(self):
1517 for k, v in iteritems(self.headers):

Callers 1

sendmailFunction · 0.80

Calls 1

new_messageMethod · 0.95

Tested by

no test coverage detected