Index: messageviewer/src/viewer/bodypartformatter.cpp =================================================================== --- messageviewer/src/viewer/bodypartformatter.cpp +++ messageviewer/src/viewer/bodypartformatter.cpp @@ -143,84 +143,6 @@ } } -class MultiPartSignedBodyPartFormatter - : public MessageViewer::Interface::BodyPartFormatter -{ -public: - MessagePart::Ptr process(const Interface::BodyPart &part) const; - MessageViewer::Interface::BodyPartFormatter::Result format(Interface::BodyPart *, HtmlWriter *) const Q_DECL_OVERRIDE; - using MessageViewer::Interface::BodyPartFormatter::format; - static const MessageViewer::Interface::BodyPartFormatter *create(); -private: - static const MultiPartSignedBodyPartFormatter *self; -}; - -const MultiPartSignedBodyPartFormatter *MultiPartSignedBodyPartFormatter::self; - -const MessageViewer::Interface::BodyPartFormatter *MultiPartSignedBodyPartFormatter::create() -{ - if (!self) { - self = new MultiPartSignedBodyPartFormatter(); - } - return self; -} - -MessagePart::Ptr MultiPartSignedBodyPartFormatter::process(const Interface::BodyPart &part) const -{ - return part.objectTreeParser()->processMultiPartSignedSubtype(part.content(), *part.processResult()); -} - -MessageViewer::Interface::BodyPartFormatter::Result MultiPartSignedBodyPartFormatter::format(Interface::BodyPart *part, HtmlWriter *writer) const -{ - Q_UNUSED(writer) - MessagePart::Ptr mp = process(*part); - if (!mp.isNull()) { - mp->html(false); - return Ok; - } - - return Failed; -} - -class MultiPartEncryptedBodyPartFormatter - : public MessageViewer::Interface::BodyPartFormatter -{ -public: - MessagePart::Ptr process(const Interface::BodyPart &part) const; - MessageViewer::Interface::BodyPartFormatter::Result format(Interface::BodyPart *, HtmlWriter *) const Q_DECL_OVERRIDE; - using MessageViewer::Interface::BodyPartFormatter::format; - static const MessageViewer::Interface::BodyPartFormatter *create(); -private: - static const MultiPartEncryptedBodyPartFormatter *self; -}; - -const MultiPartEncryptedBodyPartFormatter *MultiPartEncryptedBodyPartFormatter::self; - -const MessageViewer::Interface::BodyPartFormatter *MultiPartEncryptedBodyPartFormatter::create() -{ - if (!self) { - self = new MultiPartEncryptedBodyPartFormatter(); - } - return self; -} - -MessagePart::Ptr MultiPartEncryptedBodyPartFormatter::process(const Interface::BodyPart &part) const -{ - return part.objectTreeParser()->processMultiPartEncryptedSubtype(part.content(), *part.processResult()); -} - -MessageViewer::Interface::BodyPartFormatter::Result MultiPartEncryptedBodyPartFormatter::format(Interface::BodyPart *part, HtmlWriter *writer) const -{ - Q_UNUSED(writer) - MessagePart::Ptr mp = process(*part); - if (!mp.isNull()) { - mp->html(false); - return Ok; - } - - return Failed; -} - #define CREATE_BODY_PART_FORMATTER(subtype) \ class subtype##BodyPartFormatter \ : public MessageViewer::Interface::BodyPartFormatter \ @@ -256,12 +178,15 @@ } CREATE_BODY_PART_FORMATTER(TextPlain) +CREATE_BODY_PART_FORMATTER(Mailman) CREATE_BODY_PART_FORMATTER(TextHtml) CREATE_BODY_PART_FORMATTER(ApplicationPkcs7Mime) CREATE_BODY_PART_FORMATTER(MultiPartMixed) CREATE_BODY_PART_FORMATTER(MultiPartAlternative) +CREATE_BODY_PART_FORMATTER(MultiPartSigned) +CREATE_BODY_PART_FORMATTER(MultiPartEncrypted) typedef TextPlainBodyPartFormatter ApplicationPgpBodyPartFormatter; @@ -274,27 +199,29 @@ if (!reg) { return; } - (*reg)["application"]["octet-stream"] = AnyTypeBodyPartFormatter::create(); - (*reg)["application"]["pgp"] = ApplicationPgpBodyPartFormatter::create(); - (*reg)["application"]["pkcs7-mime"] = ApplicationPkcs7MimeBodyPartFormatter::create(); - (*reg)["application"]["x-pkcs7-mime"] = ApplicationPkcs7MimeBodyPartFormatter::create(); - (*reg)["application"]["*"] = AnyTypeBodyPartFormatter::create(); - - (*reg)["text"]["plain"] = TextPlainBodyPartFormatter::create(); - (*reg)["text"]["html"] = TextHtmlBodyPartFormatter::create(); - (*reg)["text"]["rtf"] = AnyTypeBodyPartFormatter::create(); - (*reg)["text"]["vcard"] = AnyTypeBodyPartFormatter::create(); - (*reg)["text"]["x-vcard"] = AnyTypeBodyPartFormatter::create(); - (*reg)["text"]["*"] = TextPlainBodyPartFormatter::create(); - - (*reg)["image"]["*"] = ImageTypeBodyPartFormatter::create(); - - (*reg)["message"]["rfc822"] = MessageRfc822BodyPartFormatter::create(); - (*reg)["message"]["*"] = AnyTypeBodyPartFormatter::create(); - - (*reg)["multipart"]["alternative"] = MultiPartAlternativeBodyPartFormatter::create(); - (*reg)["multipart"]["encrypted"] = MultiPartEncryptedBodyPartFormatter::create(); - (*reg)["multipart"]["signed"] = MultiPartSignedBodyPartFormatter::create(); - (*reg)["multipart"]["*"] = MultiPartMixedBodyPartFormatter::create(); - (*reg)["*"]["*"] = AnyTypeBodyPartFormatter::create(); + (*reg)["application"].insert(std::make_pair("octet-stream", AnyTypeBodyPartFormatter::create())); + (*reg)["application"].insert(std::make_pair("pgp", ApplicationPgpBodyPartFormatter::create())); + (*reg)["application"].insert(std::make_pair("pkcs7-mime", ApplicationPkcs7MimeBodyPartFormatter::create())); + (*reg)["application"].insert(std::make_pair("x-pkcs7-mime", ApplicationPkcs7MimeBodyPartFormatter::create())); + (*reg)["application"].insert(std::make_pair("*", AnyTypeBodyPartFormatter::create())); + + (*reg)["text"].insert(std::make_pair("html", TextHtmlBodyPartFormatter::create())); + (*reg)["text"].insert(std::make_pair("rtf", AnyTypeBodyPartFormatter::create())); + (*reg)["text"].insert(std::make_pair("vcard", AnyTypeBodyPartFormatter::create())); + (*reg)["text"].insert(std::make_pair("x-vcard", AnyTypeBodyPartFormatter::create())); + (*reg)["text"].insert(std::make_pair("plain", MailmanBodyPartFormatter::create())); + (*reg)["text"].insert(std::make_pair("plain", TextPlainBodyPartFormatter::create())); + (*reg)["text"].insert(std::make_pair("*", MailmanBodyPartFormatter::create())); + (*reg)["text"].insert(std::make_pair("*", TextPlainBodyPartFormatter::create())); + + (*reg)["image"].insert(std::make_pair("*", ImageTypeBodyPartFormatter::create())); + + (*reg)["message"].insert(std::make_pair("rfc822", MessageRfc822BodyPartFormatter::create())); + (*reg)["message"].insert(std::make_pair("*", AnyTypeBodyPartFormatter::create())); + + (*reg)["multipart"].insert(std::make_pair("alternative", MultiPartAlternativeBodyPartFormatter::create())); + (*reg)["multipart"].insert(std::make_pair("encrypted", MultiPartEncryptedBodyPartFormatter::create())); + (*reg)["multipart"].insert(std::make_pair("signed", MultiPartSignedBodyPartFormatter::create())); + (*reg)["multipart"].insert(std::make_pair("*", MultiPartMixedBodyPartFormatter::create())); + (*reg)["*"].insert(std::make_pair("*", AnyTypeBodyPartFormatter::create())); } Index: messageviewer/src/viewer/bodypartformatterfactory.h =================================================================== --- messageviewer/src/viewer/bodypartformatterfactory.h +++ messageviewer/src/viewer/bodypartformatterfactory.h @@ -34,6 +34,7 @@ #ifndef __MESSAGEVIEWER_BODYPARTFORMATTERFACTORY_H__ #define __MESSAGEVIEWER_BODYPARTFORMATTERFACTORY_H__ +#include #include class QString; @@ -46,6 +47,15 @@ class BodyPartFormatter; } +struct ltstr { + bool operator()(const char *s1, const char *s2) const + { + return qstricmp(s1, s2) < 0; + } +}; + +typedef std::multimap SubtypeRegistry; + class BodyPartFormatterFactory { class gcc_shut_up; @@ -55,6 +65,9 @@ static const BodyPartFormatterFactory *instance(); + SubtypeRegistry::const_iterator createForIterator(const char *type, const char *subtype) const; + const SubtypeRegistry &subtypeRegistry(const char *type) const; + const Interface::BodyPartFormatter *createFor(const char *type, const char *subtype) const; const Interface::BodyPartFormatter *createFor(const QString &type, const QString &subtype) const; const Interface::BodyPartFormatter *createFor(const QByteArray &type, const QByteArray &subtype) const; Index: messageviewer/src/viewer/bodypartformatterfactory.cpp =================================================================== --- messageviewer/src/viewer/bodypartformatterfactory.cpp +++ messageviewer/src/viewer/bodypartformatterfactory.cpp @@ -102,7 +102,9 @@ if (subtype_it != subtype_reg.end()) { qCDebug(MESSAGEVIEWER_LOG) << "BodyPartFormatterFactory: overwriting previously registered formatter for \"" << type << "/" << subtype << "\""; - subtype_reg.erase(subtype_it); subtype_it = subtype_reg.end(); + qDebug() << "BodyPartFormatterFactory: overwriting previously registered formatter for \"" + << type << "/" << subtype << "\""; + //subtype_reg.erase(subtype_it); subtype_it = subtype_reg.end(); } subtype_reg.insert(std::make_pair(subtype, formatter)); @@ -116,6 +118,7 @@ return; } const QStringList types = pl->types(); + qDebug() << "BodyPartFormatterFactory: found" << types.size() << "plugins."; qCDebug(MESSAGEVIEWER_LOG) << "BodyPartFormatterFactory: found" << types.size() << "plugins."; for (QStringList::const_iterator it = types.begin(); it != types.end(); ++it) { const Interface::BodyPartFormatterPlugin *plugin = pl->createForName(*it); @@ -139,6 +142,7 @@ << i; break; } + qDebug() << "plugin for " << type << subtype; insertBodyPartFormatter(type, subtype, bfp); } const Interface::BodyPartURLHandler *handler; @@ -157,7 +161,36 @@ } } -const Interface::BodyPartFormatter *BodyPartFormatterFactory::createFor(const char *type, const char *subtype) const +const SubtypeRegistry &BodyPartFormatterFactory::subtypeRegistry(const char* type) const +{ + if (!type || !*type) { + type = "*"; //krazy:exclude=doublequote_chars + } + + setup(); + assert(all); + + if (all->empty()) { + return SubtypeRegistry(); + } + + TypeRegistry::const_iterator type_it = all->find(type); + if (type_it == all->end()) { + type_it = all->find("*"); + } + if (type_it == all->end()) { + return SubtypeRegistry(); + } + + const SubtypeRegistry &subtype_reg = type_it->second; + if (subtype_reg.empty()) { + return SubtypeRegistry(); + } + return subtype_reg; +} + + +SubtypeRegistry::const_iterator BodyPartFormatterFactory::createForIterator(const char* type, const char* subtype) const { if (!type || !*type) { type = "*"; //krazy:exclude=doublequote_chars @@ -170,36 +203,46 @@ assert(all); if (all->empty()) { - return 0; + return SubtypeRegistry::const_iterator(); } TypeRegistry::const_iterator type_it = all->find(type); if (type_it == all->end()) { type_it = all->find("*"); } if (type_it == all->end()) { - return 0; + return SubtypeRegistry::const_iterator(); } const SubtypeRegistry &subtype_reg = type_it->second; if (subtype_reg.empty()) { - return 0; + return SubtypeRegistry::const_iterator(); } SubtypeRegistry::const_iterator subtype_it = subtype_reg.find(subtype); + qDebug() << type << subtype << subtype_reg.size(); if (subtype_it == subtype_reg.end()) { subtype_it = subtype_reg.find("*"); } if (subtype_it == subtype_reg.end()) { - return 0; + return SubtypeRegistry::const_iterator(); } if (!(*subtype_it).second) { qCWarning(MESSAGEVIEWER_LOG) << "BodyPartFormatterFactory: a null bodypart formatter sneaked in for \"" << type << "/" << subtype << "\"!"; } - return (*subtype_it).second; + return subtype_it; +} + +const Interface::BodyPartFormatter *BodyPartFormatterFactory::createFor(const char *type, const char *subtype) const +{ + const auto it = createForIterator(type, subtype); + if ((*it).second) { + return (*it).second; + } + return 0; } const Interface::BodyPartFormatter *BodyPartFormatterFactory::createFor(const QString &type, const QString &subtype) const Index: messageviewer/src/viewer/bodypartformatterfactory_p.h =================================================================== --- messageviewer/src/viewer/bodypartformatterfactory_p.h +++ messageviewer/src/viewer/bodypartformatterfactory_p.h @@ -34,31 +34,19 @@ #ifndef __MESSAGEVIEWER_BODYPARTFORMATTERFACTORY_P_H__ #define __MESSAGEVIEWER_BODYPARTFORMATTERFACTORY_P_H__ +#include "bodypartformatterfactory.h" + #include -#include -namespace MessageViewer -{ -namespace Interface -{ -class BodyPartFormatter; -} -} +#include namespace MessageViewer { namespace BodyPartFormatterFactoryPrivate { -struct ltstr { - bool operator()(const char *s1, const char *s2) const - { - return qstricmp(s1, s2) < 0; - } -}; -typedef std::map SubtypeRegistry; -typedef std::map TypeRegistry; +typedef std::map TypeRegistry; // defined in bodypartformatters.cpp extern void messageviewer_create_builtin_bodypart_formatters(TypeRegistry *);