Commit a2bad59b authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Fix mem leak

parent a0b892d1
Pipeline #24833 failed with stage
in 60 minutes and 31 seconds
......@@ -43,6 +43,7 @@ using namespace MessageCore;
using namespace MessageViewer;
Q_DECLARE_METATYPE(const KMime::Headers::Generics::AddressList *)
Q_DECLARE_METATYPE(QSharedPointer<KMime::Headers::Generics::AddressList>)
Q_DECLARE_METATYPE(const KMime::Headers::Generics::MailboxList *)
Q_DECLARE_METATYPE(QSharedPointer<KMime::Headers::Generics::MailboxList>)
Q_DECLARE_METATYPE(QDateTime)
......@@ -73,6 +74,26 @@ inline QVariant TypeAccessor<const KMime::Headers::Generics::AddressList *>::loo
}
}
GRANTLEE_BEGIN_LOOKUP(QSharedPointer<KMime::Headers::Generics::MailboxList>)
if (property == QLatin1String("nameOnly")) {
return StringUtil::emailAddrAsAnchor(object.data(), StringUtil::DisplayNameOnly);
} else if (property == QLatin1String("isSet")) {
return !object->asUnicodeString().isEmpty();
} else if (property == QLatin1String("fullAddress")) {
return StringUtil::emailAddrAsAnchor(object.data(), StringUtil::DisplayFullAddress);
} else if (property == QLatin1String("str")) {
return object->asUnicodeString();
} else if (property.startsWith(QLatin1String("expandable"))) {
const auto &name = property.mid(10);
const QString val = MessageCore::StringUtil::emailAddrAsAnchor(
object.data(), MessageCore::StringUtil::DisplayFullAddress,
QString(), MessageCore::StringUtil::ShowLink,
MessageCore::StringUtil::ExpandableAddresses,
QStringLiteral("Full") + name + QStringLiteral("AddressList"));
return val;
}
GRANTLEE_END_LOOKUP
// Read-only introspection of KMime::Headers::Generics::MailboxList object.
namespace Grantlee {
template<>
......@@ -99,7 +120,7 @@ inline QVariant TypeAccessor<const KMime::Headers::Generics::MailboxList *>::loo
}
}
GRANTLEE_BEGIN_LOOKUP(QSharedPointer<KMime::Headers::Generics::MailboxList>)
GRANTLEE_BEGIN_LOOKUP(QSharedPointer<KMime::Headers::Generics::AddressList>)
if (property == QLatin1String("nameOnly")) {
return StringUtil::emailAddrAsAnchor(object.data(), StringUtil::DisplayNameOnly);
} else if (property == QLatin1String("isSet")) {
......@@ -119,6 +140,7 @@ if (property == QLatin1String("nameOnly")) {
}
GRANTLEE_END_LOOKUP
namespace Grantlee {
template<>
inline QVariant TypeAccessor<QDateTime &>::lookUp(const QDateTime &object, const QString &property)
......@@ -268,6 +290,7 @@ public:
Grantlee::registerMetaType<const KMime::Headers::Generics::AddressList *>();
Grantlee::registerMetaType<const KMime::Headers::Generics::MailboxList *>();
Grantlee::registerMetaType<QSharedPointer<KMime::Headers::Generics::MailboxList> >();
Grantlee::registerMetaType<QSharedPointer<KMime::Headers::Generics::AddressList> >();
Grantlee::registerMetaType<QDateTime>();
iconSize = KIconLoader::global()->currentSize(KIconLoader::Toolbar);
engine = new Grantlee::Engine;
......
......@@ -517,7 +517,7 @@ KMime::Headers::Base const *NodeHelper::mailHeaderAsBase(const char *header, con
return message->headerByType(header);
}
KMime::Headers::Generics::AddressList const *NodeHelper::mailHeaderAsAddressList(const char *header, const KMime::Content *message) const
QSharedPointer<KMime::Headers::Generics::AddressList> NodeHelper::mailHeaderAsAddressList(const char *header, const KMime::Content *message) const
{
/* works without this is maybe faster ?
if(strcmp(header, "to") == 0) {
......@@ -530,7 +530,7 @@ KMime::Headers::Generics::AddressList const *NodeHelper::mailHeaderAsAddressList
return message->cc();
} */
//FIXME: mem leak
auto addressList = new KMime::Headers::Generics::AddressList();
QSharedPointer<KMime::Headers::Generics::AddressList> addressList(new KMime::Headers::Generics::AddressList());
const auto hrd = mailHeaderAsBase(header, message);
const QByteArray &data = hrd->as7BitString(false);
addressList->from7BitString(data);
......
......@@ -86,7 +86,7 @@ public:
void registerOverrideHeader(KMime::Content *message, MessagePartPtr);
Q_REQUIRED_RESULT bool hasMailHeader(const char *header, const KMime::Content *message) const;
KMime::Headers::Base const *mailHeaderAsBase(const char *header, const KMime::Content *message) const;
KMime::Headers::Generics::AddressList const *mailHeaderAsAddressList(const char *header, const KMime::Content *message) const;
QSharedPointer<KMime::Headers::Generics::AddressList> mailHeaderAsAddressList(const char *header, const KMime::Content *message) const;
Q_REQUIRED_RESULT QDateTime dateHeader(KMime::Content *message) const;
/** Attach an extra node to an existing node */
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment