Commit 9e9a316a authored by Igor Poboiko's avatar Igor Poboiko
Browse files

[NoteUtils] Add DataBase64Encoded and ContentID fields to Attachment

KPIMTextEdit returns already base64-encoded images, so if I want to attach them,
I have to decode it, just for KMime to encode them again. Instead, just
make it possible to explicitly tell KMime that attachment is already
base64-encoded.

It is also useful to be able to set some unique identifier to an
Attachment, just to be able to refer to it from the note (`contentID`).
Right now we only have `label` field, which is not unique and is
supposed to be user-facing.
parent 58e4d6ee
Pipeline #21981 passed with stage
in 4 minutes and 20 seconds
cmake_minimum_required(VERSION 3.5)
set(PIM_VERSION "5.14.40")
set(PIM_VERSION "5.14.41")
project(Akonadi-Notes VERSION ${PIM_VERSION})
......
......@@ -72,8 +72,10 @@ public:
QUrl mUrl;
QByteArray mData;
bool mDataBase64Encoded = false;
QString mMimetype;
QString mLabel;
QString mContentID;
};
Attachment::Attachment()
......@@ -107,11 +109,15 @@ bool Attachment::operator==(const Attachment &a) const
Q_D(const Attachment);
if (d->mUrl.isEmpty()) {
return d->mUrl == a.d_func()->mUrl &&
d->mDataBase64Encoded == a.d_func()->mDataBase64Encoded &&
d->mMimetype == a.d_func()->mMimetype &&
d->mContentID == a.d_func()->mContentID &&
d->mLabel == a.d_func()->mLabel;
}
return d->mData == a.d_func()->mData &&
d->mDataBase64Encoded == a.d_func()->mDataBase64Encoded &&
d->mMimetype == a.d_func()->mMimetype &&
d->mContentID == a.d_func()->mContentID &&
d->mLabel == a.d_func()->mLabel;
}
......@@ -132,6 +138,30 @@ QByteArray Attachment::data() const
return d->mData;
}
void Attachment::setDataBase64Encoded(bool encoded)
{
Q_D(Attachment);
d->mDataBase64Encoded = true;
}
bool Attachment::dataBase64Encoded() const
{
Q_D(const Attachment);
return d->mDataBase64Encoded;
}
void Attachment::setContentID(const QString &contentID)
{
Q_D(Attachment);
d->mContentID = contentID;
}
QString Attachment::contentID() const
{
Q_D(const Attachment);
return d->mContentID;
}
QString Attachment::mimetype() const
{
Q_D(const Attachment);
......@@ -320,8 +350,14 @@ KMime::Content *NoteMessageWrapper::NoteMessageWrapperPrivate::createAttachmentP
content->appendHeader(header);
}
content->contentTransferEncoding()->setEncoding(KMime::Headers::CEbase64);
if (a.dataBase64Encoded()) {
content->contentTransferEncoding()->setDecoded(false);
}
content->contentDisposition()->setDisposition(KMime::Headers::CDattachment);
content->contentDisposition()->setFilename(QStringLiteral("attachment"));
if (!a.contentID().isEmpty()) {
content->contentID()->setIdentifier(a.contentID().toLatin1());
}
return content;
}
......@@ -334,10 +370,12 @@ void NoteMessageWrapper::NoteMessageWrapperPrivate::parseAttachmentPart(KMime::C
if (KMime::Headers::Base *header = part->headerByType(X_NOTES_URL_HEADER)) {
Attachment attachment(QUrl(header->asUnicodeString()), QLatin1String(part->contentType()->mimeType()));
attachment.setLabel(label);
attachment.setContentID(QString::fromLatin1(part->contentID()->identifier()));
attachments.append(attachment);
} else {
Attachment attachment(part->decodedContent(), QLatin1String(part->contentType()->mimeType()));
attachment.setLabel(label);
attachment.setContentID(QString::fromLatin1(part->contentID()->identifier()));
attachments.append(attachment);
}
}
......
......@@ -84,6 +84,37 @@ public:
QByteArray data() const;
/**
* Sets the unique identifier of the attachment
*
* It can be used to refer to attachment from the note itself
*
* @since 5.15
*/
void setContentID(const QString &contentID);
/**
* Returns the unique identifier for inline attachment
*
* @since 5.15
*/
QString contentID() const;
/**
* Set this to true if inline data provided via ctor
* is alredy base64 encoded. Default value is false.
*
* @since 5.15
*/
void setDataBase64Encoded(bool encoded);
/**
* Returns true if data is already base64-encoded
*
* @since 5.15
*/
bool dataBase64Encoded() const;
/**
* Returns the mimetype
*/
QString mimetype() const;
......
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