Commit 3509cbad authored by Daniel Vrátil's avatar Daniel Vrátil 🤖

Always ask ItemSerializer which parts can be sent as foreign

At least PLD:RFC822 can always be stored as foreign payload, however some
serializers might want to also allow PLD:HEAD, if PLD:HEAD can be obtained
from the foreign payload directly.
parent 02c25d16
......@@ -175,11 +175,14 @@ QSet<QByteArray> ItemSerializer::availableParts(const Item &item)
return plugin->availableParts(item);
}
if (item.hasPayload()) {
QSet<QByteArray> ItemSerializer::allowedForeignParts(const Item &item)
{
if (!item.hasPayload()) {
return QSet<QByteArray>();
}
return QSet<QByteArray>() << Item::FullPayload;
ItemSerializerPlugin *plugin = TypePluginLoader::pluginForMimeTypeAndClass(item.mimeType(), item.availablePayloadMetaTypeIds());
return plugin->allowedForeignParts(item);
}
Item ItemSerializer::convert(const Item &item, int mtid)
......
......@@ -80,6 +80,14 @@ public:
*/
static QSet<QByteArray> availableParts(const Item &item);
/**
* Returns list of parts of the item payload that can be stored using
* foreign payload.
*
* @since 5.7
*/
static QSet<QByteArray> allowedForeignParts(const Item &item);
/**
* Tries to convert the payload in \a item into type with
* metatype-id \a metaTypeId.
......
......@@ -67,3 +67,12 @@ void ItemSerializerPlugin::apply(Item &item, const Item &other)
buffer.close();
}
QSet<QByteArray> ItemSerializerPlugin::allowedForeignParts(const Item &item) const
{
if (!item.hasPayload()) {
return {};
}
return { Item::FullPayload };
}
......@@ -208,6 +208,18 @@ public:
*/
virtual QSet<QByteArray> availableParts(const Item &item) const;
/**
* Returns the parts available in the item @p item that can be stored using
* foreign payload mechanism. Is only called for items whose payload has been
* set via Item::setPayloadPath().
*
* By default returns "RFC822", which can always be stored as foreign payload.
* Some implementations can also allow "HEAD" to be stored as foreign payload,
* if HEAD is only a subset of RFC822 part.
*
* @since 5.7
*/
virtual QSet<QByteArray> allowedForeignParts(const Item &item) const;
};
}
......
......@@ -54,6 +54,7 @@ public:
Collection mCollection;
Item mItem;
QSet<QByteArray> mParts;
QSet<QByteArray> mForeignParts;
QDateTime mDatetime;
QByteArray mPendingData;
ItemCreateJob::MergeOptions mMergeOptions;
......@@ -81,7 +82,7 @@ Protocol::PartMetaData ItemCreateJobPrivate::preparePart(const QByteArray &partN
}
int version = 0;
if (!mItem.d_ptr->mPayloadPath.isEmpty()) {
if (mForeignParts.contains(partLabel)) {
mPendingData = mItem.d_ptr->mPayloadPath.toUtf8();
const auto size = QFile(mItem.d_ptr->mPayloadPath).size();
return Protocol::PartMetaData(partName, size, version, Protocol::PartMetaData::Foreign);
......@@ -101,6 +102,10 @@ ItemCreateJob::ItemCreateJob(const Item &item, const Collection &collection, QOb
d->mItem = item;
d->mParts = d->mItem.loadedPayloadParts();
d->mCollection = collection;
if (!d->mItem.payloadPath().isEmpty()) {
d->mForeignParts = ItemSerializer::allowedForeignParts(d->mItem);
}
}
ItemCreateJob::~ItemCreateJob()
......
......@@ -63,7 +63,7 @@ Protocol::PartMetaData ItemModifyJobPrivate::preparePart(const QByteArray &partN
mPendingData.clear();
int version = 0;
const auto item = mItems.first();
if (!item.d_ptr->mPayloadPath.isEmpty()) {
if (mForeignParts.contains(partLabel)) {
mPendingData = item.d_ptr->mPayloadPath.toUtf8();
const auto size = QFile(item.d_ptr->mPayloadPath).size();
return Protocol::PartMetaData(partName, size, version, Protocol::PartMetaData::Foreign);
......@@ -125,6 +125,10 @@ ItemModifyJob::ItemModifyJob(const Item &item, QObject *parent)
d->mOperations.insert(ItemModifyJobPrivate::RemoteId);
d->mOperations.insert(ItemModifyJobPrivate::RemoteRevision);
if (!item.payloadPath().isEmpty()) {
d->mForeignParts = ItemSerializer::allowedForeignParts(item);
}
}
ItemModifyJob::ItemModifyJob(const Akonadi::Item::List &items, QObject *parent)
......
......@@ -67,6 +67,7 @@ public:
Item::List mItems;
bool mRevCheck;
QSet<QByteArray> mParts;
QSet<QByteArray> mForeignParts;
QByteArray mPendingData;
bool mIgnorePayload;
bool mAutomaticConflictHandlingEnabled;
......
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