MCPcopy Create free account
hub / github.com/MailCore/mailcore2 / testMessageBuilder

Function testMessageBuilder

tests/test-all.cpp:78–127  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

76}
77
78static mailcore::Data * testMessageBuilder()
79{
80 mailcore::Address * address = new mailcore::Address();
81 address->setDisplayName(displayName);
82 address->setMailbox(email);
83
84 address->release();
85
86 mailcore::MessageBuilder * msg = new mailcore::MessageBuilder();
87
88 msg->header()->setFrom(mailcore::Address::addressWithDisplayName(displayName, email));
89 mailcore::Array * to = new mailcore::Array();
90 mailcore::Array * bcc = new mailcore::Array();
91 to->addObject(mailcore::Address::addressWithDisplayName(MCSTR("Foo Bar"), MCSTR("foobar@to-recipient.org")));
92 to->addObject(mailcore::Address::addressWithDisplayName(MCSTR("Other Recipient"), MCSTR("another-foobar@to-recipient.org")));
93 bcc->addObject(mailcore::Address::addressWithDisplayName(MCSTR("Hidden Recipient"), MCSTR("foobar@bcc-recipient.org")));
94 msg->header()->setTo(to);
95 msg->header()->setBcc(bcc);
96 to->release();
97 bcc->release();
98 MCAssert(msg->header()->allExtraHeadersNames()->count() == 0);
99 msg->header()->setExtraHeader(MCSTR("X-Custom-Header"), MCSTR("Custom Header Value"));
100 msg->header()->setSubject(MCSTR("Mon projet d'été"));
101 msg->setHTMLBody(MCSTR("<div>Hello <img src=\"cid:1234\"></div>"));
102 msg->addAttachment(mailcore::Attachment::attachmentWithContentsOfFile(MCSTR("first-filename")));
103 msg->addAttachment(mailcore::Attachment::attachmentWithContentsOfFile(MCSTR("second-filename")));
104 mailcore::Attachment * attachment = mailcore::Attachment::attachmentWithContentsOfFile(MCSTR("third-image-attachment"));
105 attachment->setContentID(MCSTR("1234"));
106 msg->addRelatedAttachment(attachment);
107
108 mailcore::Data * data = msg->data();
109
110 MCLog("%s", data->bytes());
111
112 mailcore::String *filename = temporaryFilenameForTest();
113 msg->writeToFile(filename);
114 mailcore::Data *fileData = mailcore::Data::dataWithContentsOfFile(filename);
115 MCAssert(data->isEqual(fileData));
116
117 mailcore::MessageBuilder * msg2 = new mailcore::MessageBuilder(msg);
118 mailcore::String *htmlBody = msg->htmlBody();
119 mailcore::String *htmlBody2 = msg2->htmlBody();
120 MCAssert(htmlBody->isEqual(htmlBody2));
121
122 msg->release();
123 msg2->release();
124 unlink(filename->fileSystemRepresentation());
125
126 return data;
127}
128
129static void testMessageParser(mailcore::Data * data)
130{

Callers

nothing calls this directly

Calls 15

temporaryFilenameForTestFunction · 0.85
releaseMethod · 0.80
bytesMethod · 0.80
setDisplayNameMethod · 0.45
setMailboxMethod · 0.45
setFromMethod · 0.45
headerMethod · 0.45
addObjectMethod · 0.45
setToMethod · 0.45
setBccMethod · 0.45
countMethod · 0.45

Tested by

no test coverage detected