1 // 2 // VMime library (http://www.vmime.org) 3 // Copyright (C) 2002-2013 Vincent Richard <vincent@vmime.org> 4 // 5 // This program is free software; you can redistribute it and/or 6 // modify it under the terms of the GNU General Public License as 7 // published by the Free Software Foundation; either version 3 of 8 // the License, or (at your option) any later version. 9 // 10 // This program is distributed in the hope that it will be useful, 11 // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 // General Public License for more details. 14 // 15 // You should have received a copy of the GNU General Public License along 16 // with this program; if not, write to the Free Software Foundation, Inc., 17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 // 19 // Linking this library statically or dynamically with other modules is making 20 // a combined work based on this library. Thus, the terms and conditions of 21 // the GNU General Public License cover the whole combination. 22 // 23 24 #include "vmime/mdn/receivedMDNInfos.hpp" 25 26 #include "vmime/utility/outputStreamAdapter.hpp" 27 28 29 namespace vmime { 30 namespace mdn { 31 32 receivedMDNInfos(const shared_ptr<const message> msg)33receivedMDNInfos::receivedMDNInfos(const shared_ptr <const message> msg) 34 : m_msg(msg) 35 { 36 extract(); 37 } 38 39 receivedMDNInfos(const receivedMDNInfos & other)40receivedMDNInfos::receivedMDNInfos(const receivedMDNInfos& other) 41 : MDNInfos() 42 { 43 copyFrom(other); 44 } 45 46 operator =(const receivedMDNInfos & other)47receivedMDNInfos& receivedMDNInfos::operator=(const receivedMDNInfos& other) 48 { 49 copyFrom(other); 50 return (*this); 51 } 52 53 getMessage() const54const shared_ptr <const message> receivedMDNInfos::getMessage() const 55 { 56 return (m_msg); 57 } 58 59 getOriginalMessageId() const60const messageId receivedMDNInfos::getOriginalMessageId() const 61 { 62 return (m_omid); 63 } 64 65 getDisposition() const66const disposition receivedMDNInfos::getDisposition() const 67 { 68 return (m_disp); 69 } 70 71 getContentMIC() const72const string receivedMDNInfos::getContentMIC() const 73 { 74 return m_contentMIC; 75 } 76 77 copyFrom(const receivedMDNInfos & other)78void receivedMDNInfos::copyFrom(const receivedMDNInfos& other) 79 { 80 m_msg = other.m_msg; 81 m_omid = other.m_omid; 82 m_disp = other.m_disp; 83 m_contentMIC = other.m_contentMIC; 84 } 85 86 extract()87void receivedMDNInfos::extract() 88 { 89 const shared_ptr <const body> bdy = m_msg->getBody(); 90 91 for (size_t i = 0 ; i < bdy->getPartCount() ; ++i) 92 { 93 const shared_ptr <const bodyPart> part = bdy->getPartAt(i); 94 95 if (!part->getHeader()->hasField(fields::CONTENT_TYPE)) 96 continue; 97 98 const mediaType& type = *part->getHeader()->ContentType()->getValue <mediaType>(); 99 100 // Extract from second part (message/disposition-notification) 101 if (type.getType() == vmime::mediaTypes::MESSAGE && 102 type.getSubType() == vmime::mediaTypes::MESSAGE_DISPOSITION_NOTIFICATION) 103 { 104 std::ostringstream oss; 105 utility::outputStreamAdapter vos(oss); 106 107 part->getBody()->getContents()->extract(vos); 108 109 // Body actually contains fields 110 header fields; 111 fields.parse(oss.str()); 112 113 shared_ptr <messageId> omid = 114 fields.findFieldValue <messageId>(fields::ORIGINAL_MESSAGE_ID); 115 116 if (omid) 117 m_omid = *omid; 118 119 shared_ptr <disposition> disp = 120 fields.findFieldValue <disposition>(fields::DISPOSITION); 121 122 if (disp) 123 m_disp = *disp; 124 125 shared_ptr <text> contentMIC = 126 fields.findFieldValue <text>("Received-content-MIC"); 127 128 if (contentMIC) 129 m_contentMIC = contentMIC->generate(); 130 } 131 } 132 } 133 134 135 } // mdn 136 } // vmime 137