--Boundary-00=_JBp/Bq0ZasVqaQN Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Content-Disposition: inline Hi, there was a little problem with the patch. Here the new corrected version. Danny -- Danny Kukawka (private mail: danny.kukawka@web.de) --Boundary-00=_JBp/Bq0ZasVqaQN Content-Type: text/x-diff; charset="utf-8"; name="fix-49939_kmail_and_kmailcvt_againstCVS_20050130.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="fix-49939_kmail_and_kmailcvt_againstCVS_20050130.diff" Index: kmailIface.h =================================================================== RCS file: /home/kde/kdepim/kmail/kmailIface.h,v retrieving revision 1.37 diff -U3 -r1.37 kmailIface.h --- kmail/kmailIface.h 17 Sep 2004 16:22:16 -0000 1.37 +++ kmail/kmailIface.h 29 Jan 2005 19:45:41 -0000 @@ -92,12 +92,21 @@ =-2, couldn't read messageFile. =-3, Can't allocate memory. =-4, Message already exists in folder. + =100 cleaned up static variable msgIds and lastFolder */ virtual int dcopAddMessage(const QString & foldername, const QString & messagefile) = 0; virtual int dcopAddMessage(const QString & foldername, const KURL & messagefile) = 0; - + + /** by danny.kukawka@web.de: to import without search duplicates */ + //---START --- + virtual int dcopAddMessage_fastImport(const QString & foldername, + const QString & messagefile) = 0; + virtual int dcopAddMessage_fastImport(const QString & foldername, + const KURL & messagefile) = 0; + //---END --- + virtual QStringList folderList() const =0; virtual DCOPRef getFolder( const QString& vpath ) =0; virtual void selectFolder( QString folder ) =0; Index: kmkernel.cpp =================================================================== RCS file: /home/kde/kdepim/kmail/kmkernel.cpp,v retrieving revision 1.319 diff -U3 -r1.319 kmkernel.cpp --- kmail/kmkernel.cpp 8 Jan 2005 02:27:02 -0000 1.319 +++ kmail/kmkernel.cpp 29 Jan 2005 19:45:41 -0000 @@ -597,10 +597,22 @@ static QString lastFolder = ""; bool readFolderMsgIds = false; + if(foldername.startsWith( "_CLEANUP_dcopAddmessage_NOW_" )) { + if ( msgIds != 0 ) { + msgIds->clear(); + delete msgIds; + msgIds = 0; + } + if(!lastFolder.isEmpty()) { + lastFolder = ""; + } + return 100; + } //kdDebug(5006) << "KMKernel::dcopAddMessage called" << endl; if ( foldername != lastFolder ) { if ( msgIds != 0 ) { + msgIds->clear(); delete msgIds; msgIds = 0; } @@ -630,30 +642,48 @@ if ( folder ) { if (readFolderMsgIds) { + // OLD COMMENT: // Try to determine if a message already exists in // the folder. The message id that is searched for, is // the subject line + the date. This should be quite // unique. The change that a given date with a given // subject is in the folder twice is very small. - // If the subject is empty, the fromStrip string // is taken. + + // NEW COMMENT from Danny Kukawka (danny.kukawka@web.de): + // subject line + the date is only unique if the following + // return a correct unique value: + // time_t DT = mb->date(); + // QString dt = ctime(&DT); + // But if the datestring in the Header isn't RFC conform + // subject line + the date isn't unique. + // + // The only uique headerfield is the Message-ID. In some + // cases this could be empty. I then I use the + // subject line + dateStr . + int i; folder->open(); for( i=0; icount(); i++) { KMMsgBase *mb = folder->getMsgBase(i); - time_t DT = mb->date(); - QString dt = ctime(&DT); - QString id = mb->subject(); - - if (id.isEmpty()) - id = mb->fromStrip(); - if (id.isEmpty()) - id = mb->toStrip(); - - id+=dt; - + QString msgIdMD5 = mb->msgIdMD5(); + QString id = msgIdMD5; + + if ( id.isEmpty()) { + QString dt = mb->dateStr(); + id = mb->subject(); + + if ( id.isEmpty() ) + id = mb->fromStrip(); + if ( id.isEmpty() ) + id = mb->toStrip(); + + id = mb->subject(); + id+=dt; + } + //fprintf(stderr,"%s\n",(const char *) id); if (!id.isEmpty()) { msgIds->append(id); @@ -662,16 +692,20 @@ folder->close(); } - time_t DT = msg->date(); - QString dt = ctime( &DT ); - QString msgId = msg->subject(); - - if ( msgId.isEmpty() ) - msgId = msg->fromStrip(); - if ( msgId.isEmpty() ) - msgId = msg->toStrip(); - - msgId += dt; + QString msgIdMD5 = msg->msgIdMD5(); + QString msgId = msgIdMD5; + + if ( msgId.isEmpty()) { + QString dt = msg->dateStr(); + msgId = msg->subject(); + + if ( msgId.isEmpty() ) + msgId = msg->fromStrip(); + if ( msgId.isEmpty() ) + msgId = msg->toStrip(); + + msgId+=dt; + } int k = msgIds->findIndex( msgId ); //fprintf(stderr,"find %s = %d\n",(const char *) msgId,k); @@ -688,7 +722,8 @@ msg = 0; } } else { - retval = -4; + //qDebug( "duplicate: " + msgId + "; subj: " + msg->subject() + ", from: " + msgId = msg->fromStrip()); + retval = -4; } } else { retval = -1; @@ -699,6 +734,55 @@ return retval; } +int KMKernel::dcopAddMessage_fastImport(const QString & foldername,const QString & msgUrlString) +{ + return dcopAddMessage_fastImport(foldername, KURL(msgUrlString)); +} + +int KMKernel::dcopAddMessage_fastImport(const QString & foldername,const KURL & msgUrl) +{ + // This is a proposed change by Danny Kukawka + // Use this function to import messages without + // search for already existing emails. + // If you would like to import your own messages, + // you don't want to loose messages in the most + // cases + + if ( foldername.isEmpty() ) + return -1; + + int retval; + QCString messageText; + + if (!msgUrl.isEmpty() && msgUrl.isLocalFile()) { + + messageText = KPIM::kFileToString( msgUrl.path(), true, false); + if ( messageText.isNull() ) + return -2; + + KMMessage *msg = new KMMessage(); + msg->fromString( messageText ); + + KMFolder *folder = the_folderMgr->findOrCreate(foldername, false); + + if ( folder ) { + if ( folder->addMsg( msg ) == 0 ) { + retval = 1; + } else { + retval =- 2; + delete msg; + msg = 0; + } + } else { + retval = -1; + } + + } else { + retval = -2; + } + return retval; +} + QStringList KMKernel::folderList() const { QStringList folders; Index: kmkernel.h =================================================================== RCS file: /home/kde/kdepim/kmail/kmkernel.h,v retrieving revision 1.128 diff -U3 -r1.128 kmkernel.h --- kmail/kmkernel.h 9 Jan 2005 21:10:07 -0000 1.128 +++ kmail/kmkernel.h 29 Jan 2005 19:45:41 -0000 @@ -134,6 +134,11 @@ void openReader() { openReader( false ); } int dcopAddMessage(const QString & foldername, const QString & messageFile); int dcopAddMessage(const QString & foldername, const KURL & messageFile); + /** by danny.kukawka@web.de: to import without search for duplicates */ + //---START --- + int dcopAddMessage_fastImport(const QString & foldername, const QString & messageFile); + int dcopAddMessage_fastImport(const QString & foldername, const KURL & messageFile); + //---END --- QStringList folderList() const; DCOPRef getFolder( const QString& vpath ); void selectFolder( QString folder ); Index: filter_evolution.cxx =================================================================== RCS file: /home/kde/kdepim/kmailcvt/filter_evolution.cxx,v retrieving revision 1.2 diff -U3 -r1.2 filter_evolution.cxx --- kmailcvt/filter_evolution.cxx 27 Jun 2004 14:57:52 -0000 1.2 +++ kmailcvt/filter_evolution.cxx 31 Jan 2005 18:55:44 -0000 @@ -28,8 +28,8 @@ /** Default constructor. */ FilterEvolution::FilterEvolution(void) : - Filter(i18n("Import Evolution Mails and Folder Structure"), - "Simon MARTIN", + Filter(i18n("Import Evolution 1.x Mails and Folder Structure"), + "Simon MARTIN

( Filter accelerated by Danny Kukawka )

", i18n("

Select the base directory of Evolution's mails (usually ~/evolution/local).

" "

As it is currently impossible to recreate the folder structure, it will be " "\"contained\" in the generated folder's names.

" @@ -38,7 +38,9 @@ {} /** Destructor. */ -FilterEvolution::~FilterEvolution(void) {} +FilterEvolution::~FilterEvolution(void) { + endImport(); +} /** Recursive import of Evolution's mboxes. */ void FilterEvolution::import(FilterInfo *info) @@ -118,7 +120,14 @@ QString destFolder = rootDir; if(!targetDir.isNull()) destFolder = destFolder + "-" + targetDir; - addMessage(info, destFolder, tmp.name()); + + /* comment by Danny Kukawka: + * addMessage() == old function, need more time and check for duplicates + * addMessage_fastImport == new function, faster and no check for duplicates + */ + if(info->removeDupMsg) addMessage( info, destFolder, tmp.name() ); + else addMessage_fastImport( info, destFolder, tmp.name() ); + tmp.unlink(); int currentPercentage = (int) (((float) mbox.at() / filenameInfo.size()) * 100); info->setCurrent(currentPercentage); @@ -126,6 +135,11 @@ } info->addLog(i18n("Finished importing emails from %1").arg(mboxName)); + if (count_duplicates > 0) + { + info->addLog( i18n("%1 Duplicate messages not imported").arg(count_duplicates)); + } + count_duplicates = 0; mbox.close(); } } Index: filter_mailapp.cxx =================================================================== RCS file: /home/kde/kdepim/kmailcvt/filter_mailapp.cxx,v retrieving revision 1.1 diff -U3 -r1.1 filter_mailapp.cxx --- kmailcvt/filter_mailapp.cxx 25 Aug 2004 20:26:28 -0000 1.1 +++ kmailcvt/filter_mailapp.cxx 29 Jan 2005 19:27:52 -0000 @@ -30,7 +30,7 @@ FilterMailApp::FilterMailApp() : Filter( i18n("Import From OS X Mail"), - "Chris Howells", + "Chris Howells

( Filter accelerated by Danny Kukawka )

", i18n("

OS X Mail Import Filter

" "

This filter imports e-mails from the Mail client in Apple Mac OS X.

" )) @@ -39,11 +39,14 @@ FilterMailApp::~FilterMailApp() { + endImport(); } void FilterMailApp::import(FilterInfo *info) { int currentFile = 1; + int overall_status = 0; + QString directory = KFileDialog::getExistingDirectory( QDir::homeDirPath(), info->parent() ); info->setOverall(0); @@ -55,34 +58,52 @@ if (! mbox.open( IO_ReadOnly ) ) { info->alert( i18n("Unable to open %1, skipping").arg( *filename ) ); } - - QFileInfo filenameInfo( *filename ); - kdDebug() << "importing filename " << *filename << endl; - QStringList name = QStringList::split("/", *filename); - QString folderName(name[name.count() - 2]); - QTextStream mboxFile( &mbox ); - QString mboxLine = mboxFile.readLine(); - - info->setCurrent(0); - info->addLog( i18n("Importing emails from %1...").arg( *filename ) ); - info->setFrom( *filename ); - info->setTo( folderName ); - - while ( ! mboxFile.atEnd() ) { + else { + QFileInfo filenameInfo( *filename ); + kdDebug() << "importing filename " << *filename << endl; + QStringList name = QStringList::split("/", *filename); + QString folderName(name[name.count() - 2]); + QTextStream mboxFile( &mbox ); + QString mboxLine = mboxFile.readLine(); + + info->setCurrent(0); + info->addLog( i18n("Importing emails from %1...").arg( *filename ) ); + info->setFrom( *filename ); + info->setTo( folderName ); + + while ( ! mboxFile.atEnd() ) { KTempFile tmp; *tmp.textStream() << mboxLine << endl; // Not really needed (the From line) while ( !( mboxLine = mboxFile.readLine() ).isNull() && mboxLine.left(5) != "From " ) - *tmp.textStream() << mboxLine << endl; + *tmp.textStream() << mboxLine << endl; tmp.close(); - addMessage( info, folderName, tmp.name() ); + + /* comment by Danny Kukawka: + * addMessage() == old function, need more time and check for duplicates + * addMessage_fastImport == new function, faster and no check for duplicates + */ + if(info->removeDupMsg) addMessage( info, folderName, tmp.name() ); + else addMessage_fastImport( info, folderName, tmp.name() ); + tmp.unlink(); + int currentPercentage = (int) ( ( (float) mbox.at() / filenameInfo.size() ) * 100 ); info->setCurrent( currentPercentage ); - info->setOverall( (int) ( currentPercentage * ( (float) currentFile / mMboxFiles.count() ) ) ); + if (currentFile == 1) + overall_status = (int)( currentPercentage*((float)currentFile/mMboxFiles.count())); + else + overall_status = (int)(((currentFile-1)*(100.0/(float)mMboxFiles.count()))+(currentPercentage*(1.0/(float)mMboxFiles.count()))); + info->setOverall( overall_status ); if ( info->shouldTerminate() ) return; + } + + info->addLog( i18n("Finished importing emails from %1").arg( *filename ) ); + if (count_duplicates > 0) { + info->addLog( i18n("%1 Duplicate messages not imported to folder %2 in KMail").arg(count_duplicates).arg(folderName)); + } + count_duplicates = 0; + mbox.close(); } - - info->addLog( i18n("Finished importing emails from %1").arg( *filename ) ); } } @@ -94,21 +115,16 @@ const QFileInfoList *fileinfolist = dir.entryInfoList(); QFileInfoListIterator it(*fileinfolist); QFileInfo *fi; - while ((fi = it.current())) - { - if (fi->fileName() == "." || fi->fileName() == "..") - { + while ((fi = it.current())) { + if (fi->fileName() == "." || fi->fileName() == "..") { ++it; continue; } - if (fi->isDir() && fi->isReadable()) - { + if (fi->isDir() && fi->isReadable()) { traverseDirectory(fi->filePath()); } - else - { - if (!fi->isDir() && fi->fileName() == "mbox") - { + else { + if (!fi->isDir() && fi->fileName() == "mbox") { kdDebug() << "adding the file " << fi->filePath() << endl; mMboxFiles.append(fi->filePath()); } Index: filter_mbox.cxx =================================================================== RCS file: /home/kde/kdepim/kmailcvt/filter_mbox.cxx,v retrieving revision 1.6 diff -U3 -r1.6 filter_mbox.cxx --- kmailcvt/filter_mbox.cxx 27 Jun 2004 14:57:52 -0000 1.6 +++ kmailcvt/filter_mbox.cxx 29 Jan 2005 19:27:52 -0000 @@ -26,7 +26,7 @@ FilterMBox::FilterMBox() : Filter( i18n("Import mbox Files (UNIX, Evolution)"), - "Laurence Anderson", + "Laurence Anderson

( Filter accelerated by Danny Kukawka )

", i18n("

mbox import filter

" "

This filter will import mbox files into KMail. Use this filter " "if you want to import mails from Ximian Evolution or other mailers that use this traditional UNIX format.

" @@ -36,46 +36,70 @@ } FilterMBox::~FilterMBox() -{ +{ + endImport(); } void FilterMBox::import(FilterInfo *info) { int currentFile = 1; + int overall_status = 0; + QStringList filenames = KFileDialog::getOpenFileNames( QDir::homeDirPath(), "*|" + i18n("mbox Files (*)"), info->parent() ); info->setOverall(0); - + for ( QStringList::Iterator filename = filenames.begin(); filename != filenames.end(); ++filename, ++currentFile) { QFile mbox( *filename ); if (! mbox.open( IO_ReadOnly ) ) { info->alert( i18n("Unable to open %1, skipping").arg( *filename ) ); } - - QFileInfo filenameInfo( *filename ); - QString folderName( "MBOX-" + filenameInfo.baseName(TRUE) ); - QTextStream mboxFile( &mbox ); - QString mboxLine = mboxFile.readLine(); - - info->setCurrent(0); - info->addLog( i18n("Importing emails from %1...").arg( *filename ) ); - info->setFrom( *filename ); - info->setTo( folderName ); - - while ( ! mboxFile.atEnd() ) { - KTempFile tmp; - *tmp.textStream() << mboxLine << endl; // Not really needed (the From line) - while ( !( mboxLine = mboxFile.readLine() ).isNull() && mboxLine.left(5) != "From " ) - *tmp.textStream() << mboxLine << endl; - tmp.close(); - addMessage( info, folderName, tmp.name() ); - tmp.unlink(); - int currentPercentage = (int) ( ( (float) mbox.at() / filenameInfo.size() ) * 100 ); - info->setCurrent( currentPercentage ); - info->setOverall( (int) ( currentPercentage * ( (float) currentFile / filenames.count() ) ) ); - if ( info->shouldTerminate() ) return; - } + else { + QFileInfo filenameInfo( *filename ); + QString folderName( "MBOX-" + filenameInfo.baseName(TRUE) ); + QTextStream mboxFile( &mbox ); + + QString mboxLine = mboxFile.readLine(); - info->addLog( i18n("Finished importing emails from %1").arg( *filename ) ); + info->setCurrent(0); + info->addLog( i18n("Importing emails from %1...").arg( *filename ) ); + + info->setFrom( *filename ); + info->setTo( folderName ); + + while ( ! mboxFile.atEnd() ) { + KTempFile tmp; + *tmp.textStream() << mboxLine << endl; // Not really needed (the From line) + while ( !( mboxLine = mboxFile.readLine() ).isNull() && mboxLine.left(5) != "From " ) + *tmp.textStream() << mboxLine << endl; + tmp.close(); + + /* comment by Danny Kukawka: + * addMessage() == old function, need more time and check for duplicates + * addMessage_fastImport == new function, faster and no check for duplicates + */ + if(info->removeDupMsg) addMessage( info, folderName, tmp.name() ); + else addMessage_fastImport( info, folderName, tmp.name() ); + + tmp.unlink(); + int currentPercentage = (int) ( ( (float) mbox.at() / filenameInfo.size() ) * 100 ); + info->setCurrent( currentPercentage ); + if (currentFile == 1) + overall_status = (int)( currentPercentage*((float)currentFile/filenames.count())); + else + overall_status = (int)(((currentFile-1)*(100.0/(float)filenames.count()))+(currentPercentage*(1.0/(float)filenames.count()))); + info->setOverall( overall_status ); + + if ( info->shouldTerminate() ) return; + } + + info->addLog( i18n("Finished importing emails from %1").arg( *filename )); + if (count_duplicates > 0) { + info->addLog( i18n("%1 Duplicate messages not imported to folder %2 in KMail").arg(count_duplicates).arg(folderName)); + } + count_duplicates = 0; + // don't forget to close the file !!! + mbox.close(); + } } } Index: filter_oe.cxx =================================================================== RCS file: /home/kde/kdepim/kmailcvt/filter_oe.cxx,v retrieving revision 1.15 diff -U3 -r1.15 filter_oe.cxx --- kmailcvt/filter_oe.cxx 12 Jun 2004 18:17:02 -0000 1.15 +++ kmailcvt/filter_oe.cxx 29 Jan 2005 19:27:52 -0000 @@ -36,7 +36,7 @@ FilterOE::FilterOE() : Filter( i18n("Import Outlook Express Emails"), - "Laurence Anderson", + "Laurence Anderson

( Filter accelerated by Danny Kukawka )

", i18n("

Outlook Express 4/5/6 import filter

" "

You will need to locate the folder where the mailbox has been stored by searching for .dbx or .mbx files under " "