void htmlTextPart::addEmbeddedObject(const bodyPart& part, const string& id, const embeddedObject::ReferenceType refType) { // The object may already exists. This can happen if an object is // identified by both a Content-Id and a Content-Location. In this // case, there will be two embedded objects with two different IDs // but referencing the same content. mediaType type; shared_ptr <const headerField> ctf = part.getHeader()->findField(fields::CONTENT_TYPE); if (ctf) { type = *ctf->getValue <mediaType>(); } else { // No "Content-type" field: assume "application/octet-stream". } m_objects.push_back(make_shared <embeddedObject> (vmime::clone(part.getBody()->getContents()), part.getBody()->getEncoding(), id, type, refType)); }
maildirMessagePart::maildirMessagePart(shared_ptr <maildirMessagePart> parent, const size_t number, const bodyPart& part) : m_parent(parent), m_header(null), m_number(number) { m_headerParsedOffset = part.getHeader()->getParsedOffset(); m_headerParsedLength = part.getHeader()->getParsedLength(); m_bodyParsedOffset = part.getBody()->getParsedOffset(); m_bodyParsedLength = part.getBody()->getParsedLength(); m_size = part.getBody()->getContents()->getLength(); m_mediaType = part.getBody()->getContentType(); }
void htmlTextPart::addEmbeddedObject(const bodyPart& part, const string& id) { // The object may already exists. This can happen if an object is // identified by both a Content-Id and a Content-Location. In this // case, there will be two embedded objects with two different IDs // but referencing the same content. mediaType type; try { const ref <const headerField> ctf = part.getHeader()->ContentType(); type = *ctf->getValue().dynamicCast <const mediaType>(); } catch (exceptions::no_such_field) { // No "Content-type" field: assume "application/octet-stream". } m_objects.push_back(vmime::create <embeddedObject> (part.getBody()->getContents()->clone().dynamicCast <contentHandler>(), part.getBody()->getEncoding(), id, type)); }
bool htmlTextPart::findPlainTextPart(const bodyPart& part, const bodyPart& parent, const bodyPart& textPart) { // We search for the nearest "multipart/alternative" part. const shared_ptr <const headerField> ctf = part.getHeader()->findField(fields::CONTENT_TYPE); if (ctf) { const mediaType type = *ctf->getValue <mediaType>(); if (type.getType() == mediaTypes::MULTIPART && type.getSubType() == mediaTypes::MULTIPART_ALTERNATIVE) { shared_ptr <const bodyPart> foundPart; for (size_t i = 0 ; i < part.getBody()->getPartCount() ; ++i) { const shared_ptr <const bodyPart> p = part.getBody()->getPartAt(i); if (p.get() == &parent || // if "text/html" is in "multipart/related" p.get() == &textPart) // if not... { foundPart = p; } } if (foundPart) { bool found = false; // Now, search for the alternative plain text part for (size_t i = 0 ; !found && i < part.getBody()->getPartCount() ; ++i) { const shared_ptr <const bodyPart> p = part.getBody()->getPartAt(i); const shared_ptr <const headerField> ctf = p->getHeader()->findField(fields::CONTENT_TYPE); if (ctf) { const mediaType type = *ctf->getValue <mediaType>(); if (type.getType() == mediaTypes::TEXT && type.getSubType() == mediaTypes::TEXT_PLAIN) { m_plainText = p->getBody()->getContents()->clone(); found = true; } } else { // No "Content-type" field. } } // If we don't have found the plain text part here, it means that // it does not exists (the MUA which built this message probably // did not include it...). return found; } } } else { // No "Content-type" field. } bool found = false; for (size_t i = 0 ; !found && i < part.getBody()->getPartCount() ; ++i) { found = findPlainTextPart(*part.getBody()->getPartAt(i), parent, textPart); } return found; }