Allow to delete attachments from a mail.

svn path=/branches/kdepim/enterprise/kdepim/; revision=665628
wilder-work
Volker Krause 19 years ago
parent 48f1058abc
commit 3a2d4a6310
  1. 91
      kmcommands.cpp
  2. 19
      kmcommands.h
  3. 5
      kmmessage.cpp
  4. 3
      kmmessage.h
  5. 25
      kmreaderwin.cpp

@ -3250,4 +3250,95 @@ void KMHandleAttachmentCommand::slotAtmDecryptWithChiasmusUploadResult( KIO::Job
d.setResult( OK );
}
KMDeleteAttachmentCommand::KMDeleteAttachmentCommand(partNode * node, KMMessage * msg, QWidget * parent) :
KMCommand( parent, msg ),
mPartIndex( node->nodeId() ),
mSernum( 0 )
{
kdDebug() << k_funcinfo << endl;
}
KMDeleteAttachmentCommand::~KMDeleteAttachmentCommand()
{
kdDebug() << k_funcinfo << endl;
}
KMCommand::Result KMDeleteAttachmentCommand::execute()
{
kdDebug() << k_funcinfo << endl;
KMMessage *msg = retrievedMessage();
if ( !msg )
return Failed;
mSernum = msg->getMsgSerNum();
KMMessagePart part;
// -2 because partNode counts root and body of the message as well
DwBodyPart *dwpart = msg->dwBodyPart( mPartIndex - 2 );
if ( !dwpart )
return Failed;
KMMessage::bodyPart( dwpart, &part, true );
if ( !part.isComplete() )
return Failed;
msg->removeBodyPart( dwpart );
// add dummy part to show that a attachment has been deleted
KMMessagePart dummyPart;
dummyPart.duplicate( part );
QString content = i18n("This attachment has been deleted.");
if ( !part.fileName().isEmpty() )
content = i18n( "The attachment '%1' has been deleted." ).arg( part.fileName() );
dummyPart.setBodyFromUnicode( content );
dummyPart.setTypeStr( "text" );
dummyPart.setSubtypeStr( "plain" );
QCString cd = dummyPart.contentDisposition();
if ( cd.find( "attachment", 0, false ) == 0 ) {
cd.replace( 0, 10, "inline" );
dummyPart.setContentDisposition( cd );
} else if ( cd.isEmpty() ) {
dummyPart.setContentDisposition( "inline" );
}
msg->addBodyPart( &dummyPart );
KMFolder *folder = msg->parent();
if ( !folder )
return Failed;
FolderStorage *storage = folder->storage();
if ( !storage )
return Failed;
KMMessage *newMsg = new KMMessage();
newMsg->fromDwString( msg->asDwString() );
newMsg->setStatus( msg->status() );
FolderJob *job = storage->createJob( newMsg, FolderJob::tPutMessage, folder );
connect( job, SIGNAL(result(KMail::FolderJob*)), SLOT(messageStoreResult(KMail::FolderJob*)) );
job->start();
setEmitsCompletedItself( true );
setDeletesItself( true );
return OK;
}
void KMDeleteAttachmentCommand::messageStoreResult(KMail::FolderJob * job)
{
kdDebug() << k_funcinfo << job << job->error() << endl;
if ( !job->error() && mSernum ) {
KMCommand *delCmd = new KMDeleteMsgCommand( mSernum );
connect( delCmd, SIGNAL(completed(KMCommand*)), SLOT(messageDeleteResult(KMCommand*)) );
delCmd->start();
return;
}
setResult( Failed );
emit completed( this );
deleteLater();
}
void KMDeleteAttachmentCommand::messageDeleteResult(KMCommand * cmd)
{
kdDebug() << k_funcinfo << cmd << cmd->result() << endl;
setResult( cmd->result() );
emit completed( this );
deleteLater();
}
#include "kmcommands.moc"

@ -1018,4 +1018,23 @@ private:
};
class KDE_EXPORT KMDeleteAttachmentCommand : public KMCommand
{
Q_OBJECT
public:
KMDeleteAttachmentCommand( partNode *node, KMMessage *msg, QWidget *parent );
~KMDeleteAttachmentCommand();
private slots:
void messageStoreResult( KMail::FolderJob *job );
void messageDeleteResult( KMCommand *cmd );
private:
Result execute();
int mPartIndex;
Q_UINT32 mSernum;
};
#endif /*KMCommands_h*/

@ -3091,6 +3091,11 @@ void KMMessage::deleteBodyParts()
mMsg->Body().DeleteBodyParts();
}
void KMMessage::removeBodyPart(DwBodyPart * dwPart)
{
mMsg->Body().RemoveBodyPart( dwPart );
mNeedsAssembly = true;
}
//-----------------------------------------------------------------------------
DwBodyPart* KMMessage::createDWBodyPart(const KMMessagePart* aPart)

@ -621,6 +621,9 @@ public:
/** Delete all body parts. */
void deleteBodyParts();
/** Removes the given body part. */
void removeBodyPart( DwBodyPart * dwPart );
/** Set "Status" and "X-Status" fields of the message from the
* internal message status. */
void setStatusFields();

@ -1903,6 +1903,7 @@ void KMReaderWin::showAttachmentPopup( int id, const QString & name, const QPoin
menu->insertItem(i18n("Open With..."), 2);
menu->insertItem(i18n("to view something", "View"), 3);
menu->insertItem(SmallIcon("filesaveas"),i18n("Save As..."), 4);
menu->insertItem(SmallIcon("editdelete"), i18n("Delete Attachment"), 7 );
if ( name.endsWith( ".xia", false ) &&
Kleo::CryptoBackendFactory::instance()->protocol( "Chiasmus" ) )
menu->insertItem( i18n( "Decrypt With Chiasmus..." ), 6 );
@ -1941,12 +1942,24 @@ void KMReaderWin::slotHandleAttachment( int choice )
{
mAtmUpdate = true;
partNode* node = mRootNode ? mRootNode->findId( mAtmCurrent ) : 0;
KMHandleAttachmentCommand* command = new KMHandleAttachmentCommand(
node, message(), mAtmCurrent, mAtmCurrentName,
KMHandleAttachmentCommand::AttachmentAction( choice ), 0, this );
connect( command, SIGNAL( showAttachment( int, const QString& ) ),
this, SLOT( slotAtmView( int, const QString& ) ) );
command->start();
if ( choice != 7 ) {
KMHandleAttachmentCommand* command = new KMHandleAttachmentCommand(
node, message(), mAtmCurrent, mAtmCurrentName,
KMHandleAttachmentCommand::AttachmentAction( choice ), 0, this );
connect( command, SIGNAL( showAttachment( int, const QString& ) ),
this, SLOT( slotAtmView( int, const QString& ) ) );
command->start();
} else {
if ( KMessageBox::warningContinueCancel( this,
i18n("Deleting an attachment might invalidate any digital signature on this message."),
i18n("Delete Attachment"), KStdGuiItem::del(), "DeleteAttachmentSignatureWarning" )
!= KMessageBox::Continue ) {
return;
}
kdDebug() << k_funcinfo << mAtmCurrent << mAtmCurrentName << endl;
KMDeleteAttachmentCommand* command = new KMDeleteAttachmentCommand( node, message(), this );
command->start();
}
}
//-----------------------------------------------------------------------------

Loading…
Cancel
Save