def test_craft_response_attachment(): sample = MailResponse(To=list_name + "@librelist.com", From=user_full_address, Subject="Test message with attachments.", Body="The body as one attachment.") sample.attach(filename="tests/model/mailinglist_tests.py", content_type="text/plain", disposition="attachment") sample['message-id'] = '123545666' im = sample.to_message() assert_equal(len([x for x in im.walk()]), 3) inmsg = MailRequest("fakepeer", None, None, str(sample)) assert_equal(len(inmsg.all_parts()), 2) outmsg = craft_response(inmsg, list_name, list_name + "@librelist.com") om = outmsg.to_message() assert_equal(len([x for x in om.walk()]), len([x for x in im.walk()])) assert 'message-id' in outmsg
def get_response(self): """ Creates a Lamson MailResponse instance """ response = MailResponse(Subject=self.subject, To=self.recipients, From=self.sender, Body=self.body, Html=self.html) if self.bcc: response.base['Bcc'] = self.bcc if self.cc: response.base['Cc'] = self.cc for attachment in self.attachments: response.attach(attachment.filename, attachment.content_type, attachment.data, attachment.disposition) return response