From 173c665e0cefde28ef37034a36031aab96c64ae7 Mon Sep 17 00:00:00 2001 From: Vincent Richard Date: Fri, 8 Feb 2013 14:23:48 +0100 Subject: [PATCH] Additional MDN fields (thanks to Mehmet Bozkurt). --- src/mdn/MDNHelper.cpp | 43 +++++++++++++++++++++++++++++++++++++---- vmime/mdn/MDNHelper.hpp | 9 +++++++-- 2 files changed, 46 insertions(+), 6 deletions(-) diff --git a/src/mdn/MDNHelper.cpp b/src/mdn/MDNHelper.cpp index ff5924b1..533813b1 100644 --- a/src/mdn/MDNHelper.cpp +++ b/src/mdn/MDNHelper.cpp @@ -66,7 +66,7 @@ const std::vector MDNHelper::getPossibleMDNs(const ref DispositionNotificationTo()->getValue() .dynamicCast (); - for (int i = 0 ; i < dnto.getMailboxCount() ; ++i) + for (size_t i = 0 ; i < dnto.getMailboxCount() ; ++i) result.push_back(sendableMDNInfos(msg, *dnto.getMailboxAt(i))); } @@ -151,7 +151,8 @@ ref MDNHelper::buildMDN(const sendableMDNInfos& mdnInfos, const mailbox& expeditor, const disposition& dispo, const string& reportingUA, - const std::vector & reportingUAProducts) + const std::vector & reportingUAProducts, + const std::map & fields) { // Create a new message ref msg = vmime::create (); @@ -178,7 +179,7 @@ ref MDNHelper::buildMDN(const sendableMDNInfos& mdnInfos, msg->getBody()->appendPart(createFirstMDNPart(mdnInfos, text, ch)); msg->getBody()->appendPart(createSecondMDNPart(mdnInfos, - dispo, reportingUA, reportingUAProducts)); + dispo, reportingUA, reportingUAProducts, fields)); msg->getBody()->appendPart(createThirdMDNPart(mdnInfos)); return (msg); @@ -208,7 +209,8 @@ ref MDNHelper::createFirstMDNPart(const sendableMDNInfos& /* mdnInfos ref MDNHelper::createSecondMDNPart(const sendableMDNInfos& mdnInfos, const disposition& dispo, const string& reportingUA, - const std::vector & reportingUAProducts) + const std::vector & reportingUAProducts, + const std::map & additionalFields) { ref part = vmime::create (); @@ -281,6 +283,39 @@ ref MDNHelper::createSecondMDNPart(const sendableMDNInfos& mdnInfos, // -- Disposition fields.Disposition()->setValue(dispo); + // -- Failure, Error and Warning fields + std::map ::const_iterator it; + + if (additionalFields.size() > 0) + { + it = additionalFields.find(vmime::fields::ERROR); + if (it != additionalFields.end()) + { + ref error = headerFieldFactory::getInstance()-> + create(vmime::fields::ERROR); + error->setValue(it->second); + fields.appendField(error); + } + + it = additionalFields.find(vmime::fields::WARNING); + if (it != additionalFields.end()) + { + ref warn = headerFieldFactory::getInstance()-> + create(vmime::fields::WARNING); + warn->setValue(it->second); + fields.appendField(warn); + } + + it = additionalFields.find(vmime::fields::FAILURE); + if (it != additionalFields.end()) + { + ref fail = headerFieldFactory::getInstance()-> + create(vmime::fields::FAILURE); + fail->setValue(it->second); + fields.appendField(fail); + } + } + std::ostringstream oss; utility::outputStreamAdapter vos(oss); diff --git a/vmime/mdn/MDNHelper.hpp b/vmime/mdn/MDNHelper.hpp index 4e2027ca..d06c47ce 100644 --- a/vmime/mdn/MDNHelper.hpp +++ b/vmime/mdn/MDNHelper.hpp @@ -102,6 +102,7 @@ public: * @param dispo disposition information * @param reportingUA name of reporting user-agent (optional) * @param reportingUAProducts list of products in the reporting user-agent (optional) + * @param fields additional MDN fields, like "Error", "Warning" or "Failure" (optional) * @return a new message object containing the MDN */ static ref buildMDN(const sendableMDNInfos& mdnInfos, @@ -111,7 +112,9 @@ public: const disposition& dispo, const string& reportingUA = NULL_STRING, const std::vector & reportingUAProducts - = std::vector ()); + = std::vector (), + const std::map & fields + = (std::map ())); private: @@ -121,7 +124,9 @@ private: static ref createSecondMDNPart(const sendableMDNInfos& mdnInfos, const disposition& dispo, const string& reportingUA, - const std::vector & reportingUAProducts); + const std::vector & reportingUAProducts, + const std::map & fields); + static ref createThirdMDNPart(const sendableMDNInfos& mdnInfos); };