Page Menu
Home
GnuPG
Search
Configure Global Search
Log In
Files
F23020592
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Size
10 KB
Subscribers
None
View Options
diff --git a/client/editor/attachment/attachmentpart.cpp b/client/editor/attachment/attachmentpart.cpp
index 372e6bf..3e3e808 100644
--- a/client/editor/attachment/attachmentpart.cpp
+++ b/client/editor/attachment/attachmentpart.cpp
@@ -1,235 +1,230 @@
/*
SPDX-FileCopyrightText: 2009 Constantin Berzan <exit3219@gmail.com>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#include "attachmentpart.h"
#include <KMime/Content>
#include <KMime/Util>
#include <QUrl>
using namespace MessageCore;
-uint MessageCore::qHash(const MessageCore::AttachmentPart::Ptr &ptr)
-{
- return ::qHash(ptr.data());
-}
-
// TODO move to kmime_util?
static qint64 sizeWithEncoding(const QByteArray &data, KMime::Headers::contentEncoding encoding) // local
{
auto content = new KMime::Content;
content->setBody(data);
content->contentTransferEncoding()->setEncoding(encoding);
const int size = content->size();
delete content;
return size;
}
static KMime::Headers::contentEncoding bestEncodingForTypeAndData(const QByteArray &mimeType, const QByteArray &data)
{
// Choose the best encoding for text/* and message/* attachments, but
// always use base64 for anything else to prevent CRLF/LF conversions
// etc. from corrupting the binary data
if (mimeType.isEmpty() || mimeType.startsWith("text/") || mimeType.startsWith("message/")) {
auto possibleEncodings = KMime::encodingsForData(data);
possibleEncodings.removeAll(KMime::Headers::CE8Bit);
if (!possibleEncodings.isEmpty()) {
return possibleEncodings.first();
} else {
return KMime::Headers::CEquPr; // TODO: maybe some other default?
}
} else {
return KMime::Headers::CEbase64;
}
}
class MessageCore::AttachmentPart::AttachmentPartPrivate
{
public:
AttachmentPartPrivate() = default;
QUrl mUrl;
QString mName;
QString mFileName;
QString mDescription;
QByteArray mCharset;
QByteArray mMimeType;
QByteArray mData;
KMime::Headers::contentEncoding mEncoding = KMime::Headers::CE7Bit;
qint64 mSize = -1;
bool mIsInline = false;
bool mAutoEncoding = true;
bool mCompressed = false;
bool mToEncrypt = false;
bool mToSign = false;
};
AttachmentPart::AttachmentPart()
: d(new AttachmentPartPrivate)
{
}
AttachmentPart::~AttachmentPart()
{
delete d;
}
QString AttachmentPart::name() const
{
return d->mName;
}
void AttachmentPart::setName(const QString &name)
{
d->mName = name;
}
QString AttachmentPart::fileName() const
{
return d->mFileName;
}
void AttachmentPart::setFileName(const QString &name)
{
d->mFileName = name;
}
QString AttachmentPart::description() const
{
return d->mDescription;
}
void AttachmentPart::setDescription(const QString &description)
{
d->mDescription = description;
}
bool AttachmentPart::isInline() const
{
return d->mIsInline;
}
void AttachmentPart::setInline(bool inl)
{
d->mIsInline = inl;
}
bool AttachmentPart::isAutoEncoding() const
{
return d->mAutoEncoding;
}
void AttachmentPart::setAutoEncoding(bool enabled)
{
d->mAutoEncoding = enabled;
if (enabled) {
d->mEncoding = bestEncodingForTypeAndData(d->mMimeType, d->mData);
}
d->mSize = sizeWithEncoding(d->mData, d->mEncoding);
}
KMime::Headers::contentEncoding AttachmentPart::encoding() const
{
return d->mEncoding;
}
void AttachmentPart::setEncoding(KMime::Headers::contentEncoding encoding)
{
d->mAutoEncoding = false;
d->mEncoding = encoding;
d->mSize = sizeWithEncoding(d->mData, d->mEncoding);
}
QByteArray AttachmentPart::charset() const
{
return d->mCharset;
}
void AttachmentPart::setCharset(const QByteArray &charset)
{
d->mCharset = charset;
}
QByteArray AttachmentPart::mimeType() const
{
return d->mMimeType;
}
void AttachmentPart::setMimeType(const QByteArray &mimeType)
{
d->mMimeType = mimeType;
}
bool AttachmentPart::isCompressed() const
{
return d->mCompressed;
}
void AttachmentPart::setCompressed(bool compressed)
{
d->mCompressed = compressed;
}
bool AttachmentPart::isEncrypted() const
{
return d->mToEncrypt;
}
void AttachmentPart::setEncrypted(bool encrypted)
{
d->mToEncrypt = encrypted;
}
bool AttachmentPart::isSigned() const
{
return d->mToSign;
}
void AttachmentPart::setSigned(bool sign)
{
d->mToSign = sign;
}
QByteArray AttachmentPart::data() const
{
return d->mData;
}
void AttachmentPart::setData(const QByteArray &data)
{
d->mData = data;
if (d->mAutoEncoding) {
d->mEncoding = bestEncodingForTypeAndData(d->mMimeType, d->mData);
}
d->mSize = sizeWithEncoding(d->mData, d->mEncoding);
}
qint64 AttachmentPart::size() const
{
return d->mSize;
}
bool AttachmentPart::isMessageOrMessageCollection() const
{
return (mimeType() == QByteArrayLiteral("message/rfc822")) || (mimeType() == QByteArrayLiteral("multipart/digest"));
}
void AttachmentPart::setUrl(const QUrl &url)
{
d->mUrl = url;
}
QUrl AttachmentPart::url() const
{
return d->mUrl;
}
diff --git a/client/editor/attachment/attachmentpart.h b/client/editor/attachment/attachmentpart.h
index 8c06d22..079026a 100644
--- a/client/editor/attachment/attachmentpart.h
+++ b/client/editor/attachment/attachmentpart.h
@@ -1,200 +1,197 @@
/*
SPDX-FileCopyrightText: 2009 Constantin Berzan <exit3219@gmail.com>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#pragma once
#include <KMime/Headers>
#include <QList>
#include <QMetaType>
#include <QSharedPointer>
class QUrl;
namespace MessageCore
{
/**
* @short A class that encapsulates an attachment.
*
* @author Constantin Berzan <exit3219@gmail.com>
*/
class AttachmentPart
{
public:
/**
* Defines a pointer to an attachment object.
*/
using Ptr = QSharedPointer<AttachmentPart>;
/**
* Defines a list of pointers to attachment objects.
*/
using List = QList<Ptr>;
/**
* Creates a new attachment part.
*/
AttachmentPart();
/**
* Destroys the attachment part.
*/
virtual ~AttachmentPart();
/**
* Sets the @p name of the attachment.
*
* The name will be used in the 'name=' part of
* the Content-Type header.
*/
void setName(const QString &name);
/**
* Returns the name of the attachment.
*/
[[nodiscard]] QString name() const;
/**
* Sets the file @p name of the attachment.
*
* The name will be used in the 'filename=' part of
* the Content-Disposition header.
*/
void setFileName(const QString &name);
/**
* Returns the file name of the attachment.
*/
[[nodiscard]] QString fileName() const;
/**
* Sets the @p description of the attachment.
*/
void setDescription(const QString &description);
/**
* Returns the description of the attachment.
*/
[[nodiscard]] QString description() const;
/**
* Sets whether the attachment will be displayed inline the message.
*/
void setInline(bool value);
/**
* Returns whether the attachment will be displayed inline the message.
*/
[[nodiscard]] bool isInline() const;
/**
* Sets whether encoding of the attachment will be determined automatically.
*/
void setAutoEncoding(bool enabled);
/**
* Returns whether encoding of the attachment will be determined automatically.
*/
[[nodiscard]] bool isAutoEncoding() const;
/**
* Sets the @p encoding that will be used for the attachment.
*
* @note only applies if isAutoEncoding is @c false
*/
void setEncoding(KMime::Headers::contentEncoding encoding);
/**
* Returns the encoding that will be used for the attachment.
*/
[[nodiscard]] KMime::Headers::contentEncoding encoding() const;
/**
* Sets the @p charset that will be used for the attachment.
*/
void setCharset(const QByteArray &charset);
/**
* Returns the charset that will be used for the attachment.
*/
[[nodiscard]] QByteArray charset() const;
/**
* Sets the @p mimeType of the attachment.
*/
void setMimeType(const QByteArray &mimeType);
/**
* Returns the mime type of the attachment.
*/
[[nodiscard]] QByteArray mimeType() const;
/**
* Sets whether the attachment is @p compressed.
*/
void setCompressed(bool compressed);
/**
* Returns whether the attachment is compressed.
*/
[[nodiscard]] bool isCompressed() const;
/**
* Sets whether the attachment is @p encrypted.
*/
void setEncrypted(bool encrypted);
/**
* Returns whether the attachment is encrypted.
*/
[[nodiscard]] bool isEncrypted() const;
/**
* Sets whether the attachment is @p signed.
*/
void setSigned(bool sign);
/**
* Returns whether the attachment is signed.
*/
[[nodiscard]] bool isSigned() const;
/**
* Sets the payload @p data of the attachment.
*/
void setData(const QByteArray &data);
/**
* Returns the payload data of the attachment.
*/
[[nodiscard]] QByteArray data() const;
/**
* Returns the size of the attachment.
*/
[[nodiscard]] qint64 size() const;
/**
* Returns whether the specified attachment part is an encapsulated message
* (message/rfc822) or a collection of encapsulated messages (multipart/digest)
*/
[[nodiscard]] bool isMessageOrMessageCollection() const;
void setUrl(const QUrl &url);
[[nodiscard]] QUrl url() const;
private:
//@cond PRIVATE
class AttachmentPartPrivate;
AttachmentPartPrivate *const d;
//@endcond
};
-
-// FIXME I don't understand why this doesn't work if I put it outside namespace KPIM.
-uint qHash(const QSharedPointer<MessageCore::AttachmentPart> &);
}
Q_DECLARE_METATYPE(MessageCore::AttachmentPart::Ptr)
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Mon, May 12, 6:26 PM (1 d, 16 h)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
0a/b5/935c550565b6d8980c0b198e8b56
Attached To
rOJ GpgOL.js
Event Timeline
Log In to Comment