Commit 0b53b367 authored by Ingo Klöcker's avatar Ingo Klöcker
Browse files

Allow deletion of attachments from message structure view

Deletion of attachments (and other message parts) is only allowed
one at a time. Message parts inside encrypted message parts cannot
be deleted.

This (re-)adds the "Delete Attachment" action to the context menu
of the message structure view. It was removed 3 years ago because
it always crashed (because it tried to work with a copy of the node
tree of the original message).

Sponsored by: Intevation GmbH

CCBUG: 287177
BUG: 436089
FIXED-IN: 5.18.0
parent cc6dd431
Pipeline #59414 canceled with stage
in 8 minutes and 57 seconds
......@@ -1680,6 +1680,7 @@ void ViewerPrivate::showContextMenu(KMime::Content *content, const QPoint &pos)
}
}
const bool isAttachment = !content->contentType()->isMultipart() && !content->isTopLevel();
const bool isExtraContent = !mMessage->content(content->index());
const bool isRoot = (content == mMessage.data());
const auto hasAttachments = KMime::hasAttachment(mMessage.data());
......@@ -1704,13 +1705,17 @@ void ViewerPrivate::showContextMenu(KMime::Content *content, const QPoint &pos)
popup.addAction(i18n("Save All Attachments..."), this, &ViewerPrivate::slotAttachmentSaveAll);
}
// edit + delete only for attachments
if (!isRoot) {
if (isAttachment) {
popup.addAction(QIcon::fromTheme(QStringLiteral("edit-copy")), i18n("Copy"), this, &ViewerPrivate::slotAttachmentCopy);
}
if (!content->isTopLevel()) {
auto deleteAction =
popup.addAction(QIcon::fromTheme(QStringLiteral("edit-delete")), i18n("Delete Attachment"), this, &ViewerPrivate::slotAttachmentDelete);
// body parts can only be deleted one at a time, and extra content cannot be delete
deleteAction->setEnabled(selectedContents().size() == 1 && !isExtraContent);
popup.addSeparator();
popup.addAction(i18n("Properties"), this, &ViewerPrivate::slotAttachmentProperties);
}
......@@ -2485,6 +2490,22 @@ void ViewerPrivate::attachmentCopy(const KMime::Content::List &contents)
#endif
}
void ViewerPrivate::slotAttachmentDelete()
{
const auto contents = selectedContents();
if (contents.size() != 1) {
return;
}
// look up the selected content node of the mime part tree in the node tree of the original message;
// since deleting extra content (e.g. attachments inside encrypted message parts) is not supported,
// we do not need to consider the extra content in the lookup
const auto contentIndex = contents[0]->index();
const auto contentInOriginalMessage = mMessage->content(contentIndex);
if (contentInOriginalMessage) {
(void)deleteAttachment(contentInOriginalMessage);
}
}
void ViewerPrivate::slotLevelQuote(int l)
{
if (mLevelQuote != l) {
......
......@@ -532,6 +532,7 @@ public Q_SLOTS:
void slotAttachmentView();
void slotAttachmentProperties();
void slotAttachmentCopy();
void slotAttachmentDelete();
void slotLevelQuote(int l);
/** Toggle display mode between HTML and plain text. */
......
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