Example #1
0
bool MDNHelper::isMDN(const std::shared_ptr<const message> msg)
{
	const std::shared_ptr<const header> hdr = msg->getHeader();

	// A MDN message implies the following:
	//   - a Content-Type field is present and its value is "multipart/report"
	//   - a "report-type" parameter is present in the Content-Type field,
	//     and its value is "disposition-notification"
	if (hdr->hasField(fields::CONTENT_TYPE))
	{
		//const contentTypeField& ctf = *(hdr->ContentType() TODO shared
		//	.dynamicCast <const contentTypeField>());
		const contentTypeField& ctf = *std::dynamic_pointer_cast<const contentTypeField>(hdr->ContentType());

		//const mediaType type = *ctf.getValue().dynamicCast <const mediaType>(); TODO shared
		const mediaType type = *std::dynamic_pointer_cast<const mediaType>(ctf.getValue());

		if (type.getType() == vmime::mediaTypes::MULTIPART &&
		    type.getSubType() == vmime::mediaTypes::MULTIPART_REPORT)
		{
			if (ctf.hasParameter("report-type") &&
			    ctf.getReportType() == "disposition-notification")
			{
				return (true);
			}
		}
	}

	return (false);
}