From 5fe1d9e6552bc58c7325c7d17c444d92e3f07a92 Mon Sep 17 00:00:00 2001 From: Ingo Klcker Date: Sun, 9 Nov 2003 22:23:15 +0000 Subject: [PATCH] Fix saving attachments. Attachments don't necessarily have a filename. It's okay if they just have a name, or in the case of a single body part if the user specified a filename. svn path=/trunk/kdepim/; revision=265942 --- kmcommands.cpp | 41 +++++++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/kmcommands.cpp b/kmcommands.cpp index 893789fc4..6533fbc52 100644 --- a/kmcommands.cpp +++ b/kmcommands.cpp @@ -1726,35 +1726,44 @@ void KMSaveAttachmentsCommand::slotSaveAll() fdlg.setMode( (unsigned int) KFile::Directory ); if ( !fdlg.exec() ) return; dir = fdlg.selectedURL().path(); - } else - { + } + else { // only one item, get the desired filename // replace all ':' with '_' because ':' isn't allowed on FAT volumes - const QString s = itr.current()->msgPart().fileName().replace( ':', '_' ); - file = KFileDialog::getSaveFileName( s, QString::null, mParent, QString::null ); + QString s = + (*itr)->msgPart().fileName().stripWhiteSpace().replace( ':', '_' ); + if ( s.isEmpty() ) + s = (*itr)->msgPart().name().stripWhiteSpace().replace( ':', '_' ); + if ( s.isEmpty() ) + s = "unnamed"; // ### this should probably be i18n'ed + file = KFileDialog::getSaveFileName( s, QString::null, mParent, + QString::null ); } while ( itr.current() ) { - QString s = itr.current()->msgPart().fileName(); - // Check if it has the Content-Disposition... filename: header - // to make sure it's an actual attachment - // we can't do the check earlier as we first need to load the mimeheader - // for imap attachments to do this check - if ( s.isEmpty() ) { - ++itr; - continue; - } - + QString s; QString filename; - if ( !dir.isEmpty() ) + if ( !dir.isEmpty() ) { + s = (*itr)->msgPart().fileName().stripWhiteSpace().replace( ':', '_' ); + if ( s.isEmpty() ) + s = (*itr)->msgPart().name().stripWhiteSpace().replace( ':', '_' ); + // Check if it has the Content-Disposition... filename: header + // to make sure it's an actual attachment + // we can't do the check earlier as we first need to load the mimeheader + // for imap attachments to do this check + if ( s.isEmpty() ) { + ++itr; + continue; + } filename = dir + "/" + s; + } else filename = file; if( !filename.isEmpty() ) { if( QFile::exists( filename ) ) { if( KMessageBox::warningYesNo( mParent, - i18n( "A file named %1 already exists. Do you want to overwrite it?" ).arg( s ), + i18n( "A file named %1 already exists. Do you want to overwrite it?" ).arg( s.isEmpty() ? filename : s ), i18n( "KMail Warning" ) ) == KMessageBox::No ) { ++itr;