[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kmail-devel
Subject:    Re: KMailCVT - new filter for Evolution 2.x, Opera and Thunderbird
From:       Danny Kukawka <dkukawka () suse ! de>
Date:       2005-01-31 21:13:37
Message-ID: 200501312213.39344.dkukawka () suse ! de
[Download RAW message or body]

Hi, 

also a little problem with the patch. Here the new version.

Danny

-- 
Danny Kukawka
(private mail: danny.kukawka@web.de)

On Monday 31 January 2005 19:46, Danny Kukawka wrote:
> Hi,
>
> I wrote 3 new filter. The patch (against CVS) depends on my KMail/KMailCVT
> patch.
>
> The new filter:
> - for Evolution 2.x (tested with 2.0.x and 2.1.x)
> - for Opera (tested with 8.0Beta1)
> - for Thunderbird (tested with 1.0)
>
> Happy testing! Comments welcome.
>
> Danny

["kmailcvt_addon_3newFilter_full.diff" (text/x-diff)]

Index: Makefile.am
===================================================================
RCS file: /home/kde/kdepim/kmailcvt/Makefile.am,v
retrieving revision 1.27
diff -U3 -r1.27 Makefile.am
--- kmailcvt/Makefile.am	25 Aug 2004 20:26:28 -0000	1.27
+++ kmailcvt/Makefile.am	31 Jan 2005 14:50:58 -0000
@@ -3,7 +3,9 @@
 kmailcvt_SOURCES = kimportpagedlg.ui kimportpage.cpp kselfilterpagedlg.ui \
                    kselfilterpage.cpp filters.cxx filter_oe.cxx kmailcvt.cpp \
                    main.cpp filter_pmail.cxx filter_plain.cxx \
-                   filter_mbox.cxx filter_evolution.cxx filter_mailapp.cxx
+                   filter_mbox.cxx filter_evolution.cxx filter_mailapp.cxx \
+                   filter_evolution_v2.cxx filter_opera.cxx filter_thunderbird.cxx
+                
 kmailcvt_LDADD   = $(LIB_KFILE)
 
 EXTRA_DIST = main.cpp kmailcvt.cpp kimportpage.cpp kimportpage.h \
@@ -15,7 +17,10 @@
              filter_plain.cxx filter_plain.hxx \
              filter_mbox.cxx filter_mbox.hxx \
              filter_evolution.cxx filter_evolution.hxx \
-	     filter_mailapp.hxx
+             filter_mailapp.hxx filter_mailapp.cxx \
+             filter_opera.hxx filter_opera.cxx \
+             filter_evolution_v2.hxx filter_evolution_v2.cxx \
+             filter_thunderbird.hxx filter_thunderbird.cxx
 
 install-data-local: uninstall.desktop

Index: kselfilterpage.cpp
===================================================================
RCS file: /home/kde/kdepim/kmailcvt/kselfilterpage.cpp,v
retrieving revision 1.10
diff -U3 -r1.10 kselfilterpage.cpp
--- kmailcvt/kselfilterpage.cpp	25 Aug 2004 20:26:28 -0000	1.10
+++ kmailcvt/kselfilterpage.cpp	31 Jan 2005 20:35:34 -0000
@@ -26,6 +27,9 @@
 #include "filter_plain.hxx"
 #include "filter_evolution.hxx"
 #include "filter_mailapp.hxx"
+#include "filter_evolution_v2.hxx"
+#include "filter_opera.hxx"
+#include "filter_thunderbird.hxx"
 
 #include "kselfilterpage.h"
 
@@ -45,7 +49,10 @@
         addFilter(new FilterPlain);
         addFilter(new FilterPMail);
         addFilter(new FilterEvolution);
+        addFilter(new FilterEvolution_v2);
         addFilter(new FilterMailApp);
+        addFilter(new FilterOpera);
+        addFilter(new FilterThunderbird);
 }
 
 KSelFilterPage::~KSelFilterPage() {
--- kmailcvt/filter_evolution_v2.hxx	2005-01-30 22:05:23.000000000 +0100
+++ kmailcvt/filter_evolution_v2.hxx	2005-01-30 22:12:19.000000000 +0100
@@ -0,0 +1,41 @@
+/***************************************************************************
+            filter_evolution_v2.hxx  -  Evolution 2.0.x mail import
+                             -------------------
+    begin                : Januar 26 2005
+    copyright            : (C) 2005 by Danny Kukawka
+                           (inspired and partly copied from filter_evolution)
+    email                : danny.kukawka@web.de
+ ***************************************************************************/
+
+/***************************************************************************
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ ***************************************************************************/
+ 
+#ifndef FILTER_EVOLUTION_V2_HXX
+#define FILTER_EVOLUTION_V2_HXX
+
+#include "filters.hxx"
+
+/**
+ * Imports Evolution v2.x mail folder recursively, keeping the folder structure.
+ * @author Danny Kukawka
+ */
+class FilterEvolution_v2 : public Filter
+{
+public:
+  FilterEvolution_v2(void);
+  ~FilterEvolution_v2(void);
+
+  void import(FilterInfo *info);
+
+private:
+  void importDirContents(FilterInfo*, const QString&, const QString&, const \
QString&); +  void importMBox(FilterInfo*, const QString&, const QString&, const \
QString&); +};
+
+#endif
--- kmailcvt/filter_evolution_v2.cxx	2005-01-30 22:05:20.000000000 +0100
+++ kmailcvt/filter_evolution_v2.cxx	2005-01-31 15:15:57.000000000 +0100
@@ -0,0 +1,169 @@
+/***************************************************************************
+            filter_evolution_v2.cxx  -  Evolution 2.0.x mail import
+                             -------------------
+    begin                : Januar 26 2005
+    copyright            : (C) 2005 by Danny Kukawka
+                           (inspired and partly copied from filter_evolution)
+    email                : danny.kukawka@web.de
+ ***************************************************************************/
+
+/***************************************************************************
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ ***************************************************************************/
+
+#include "filter_evolution_v2.hxx"
+
+#include <config.h>
+#include <klocale.h>
+#include <kfiledialog.h>
+#include <ktempfile.h>
+
+
+/** Default constructor. */
+FilterEvolution_v2::FilterEvolution_v2(void) : 
+  Filter(i18n("Import Evolution 2.x local Mails and Folder Structure"),
+	 "Danny Kukawka",
+	 i18n("<p><b>Evolution 2.x import filter</b></p>"
+              "<p>Select the base directory of your local Evolution mailfolder \
(usually ~/.evolution/mail/local/).</p>" +              "<p><b>Note:</b> Never choose \
a Folder, which <u>doesn't</u> contain mbox-files (for example" +              "a \
maildir)! If you do it anyway, you will get many new folder!</p>" +              \
"<p>As it is currently impossible to recreate the folder structure, it will be " +	   \
"\"contained\" in the generated folder's names.</p>")) +{}
+
+/** Destructor. */
+FilterEvolution_v2::~FilterEvolution_v2(void) {
+   endImport();
+}
+
+/** Recursive import of Evolution's mboxes. */
+void FilterEvolution_v2::import(FilterInfo *info)
+{
+  /** 
+   * We ask the user to choose Evolution's root directory. 
+   * This should be usually ~/.evolution/mail/local/
+   */
+  QString mailDir = KFileDialog::getExistingDirectory(QDir::homeDirPath(), \
info->parent()); +  info->setOverall(0);
+
+  /** Recursive import of the MailArchives */
+  QDir dir(mailDir);
+  QStringList rootSubDirs = dir.entryList("[^\\.]*", QDir::Dirs, QDir::Name); // \
Removal of . and .. +  int currentDir = 1, numSubDirs = rootSubDirs.size();
+  for(QStringList::Iterator filename = rootSubDirs.begin() ; filename != \
rootSubDirs.end() ; ++filename, ++currentDir) { +    importDirContents(info, \
dir.filePath(*filename), *filename, QString::null); +    info->setOverall((int) \
((float) currentDir / numSubDirs * 100)); +  }
+  
+  /** import last but not least all archives from the root-dir */
+  QDir importDir (mailDir);
+  QStringList files = importDir.entryList("[^\\.]*", QDir::Files, QDir::Name);
+  for ( QStringList::Iterator mailFile = files.begin(); mailFile != files.end(); \
++mailFile) { +    QString temp_mailfile = *mailFile;
+    if (temp_mailfile.endsWith(".cmeta") || temp_mailfile.endsWith(".ev-summary") || \
 +        temp_mailfile.endsWith(".ibex.index") || \
temp_mailfile.endsWith(".ibex.index.data") ) {} +    else {  
+        info->addLog( i18n("Start import file %1...").arg( temp_mailfile ) );
+        importMBox(info, mailDir + "/" + temp_mailfile , temp_mailfile, \
QString::null); +    }    
+  }
+  
+  info->addLog( i18n("Finished importing emails from %1").arg( mailDir ));
+  info->setCurrent(100);
+  if(count_duplicates > 0) {
+     info->addLog( i18n("%1 Duplicate messages not \
imported").arg(count_duplicates)); +  }
+}
+
+/**
+ * Import of a directory contents.
+ * @param info Information storage for the operation.
+ * @param dirName The name of the directory to import.
+ * @param KMailRootDir The directory's root directory in KMail's folder structure.
+ * @param KMailSubDir The directory's direct ancestor in KMail's folder structure.
+ */
+void FilterEvolution_v2::importDirContents(FilterInfo *info, const QString& dirName, \
const QString& KMailRootDir, const QString& KMailSubDir) +{
+    /** Here Import all archives in the current dir */
+    QDir dir(dirName);
+  
+    QDir importDir (dirName);
+    QStringList files = importDir.entryList("[^\\.]*", QDir::Files, QDir::Name);
+    for ( QStringList::Iterator mailFile = files.begin(); mailFile != files.end(); \
++mailFile) { +      QString temp_mailfile = *mailFile;
+      if (temp_mailfile.endsWith(".cmeta") || temp_mailfile.endsWith(".ev-summary") \
||  +          temp_mailfile.endsWith(".ibex.index") || \
temp_mailfile.endsWith(".ibex.index.data") ) {} +      else {  
+          info->addLog( i18n("Start import file %1...").arg( temp_mailfile ) );
+          importMBox(info, (dirName + "/" + temp_mailfile) , KMailRootDir, \
KMailSubDir); +      }    
+    }
+
+    /** If there are subfolders, we import them one by one */
+    QDir subfolders(dirName);
+    QStringList subDirs = subfolders.entryList("[^\\.]*", QDir::Dirs, QDir::Name);
+    for(QStringList::Iterator filename = subDirs.begin() ; filename != subDirs.end() \
; ++filename) { +      QString kSubDir;
+      if(!KMailSubDir.isNull()) {
+        kSubDir = KMailSubDir + "-" + *filename;
+      } else {
+        kSubDir = *filename;
+      }
+      importDirContents(info, subfolders.filePath(*filename), KMailRootDir, \
kSubDir); +    }
+}
+
+/**
+ * Import of a MBox file.
+ * @param info Information storage for the operation.
+ * @param dirName The MBox's name.
+ * @param KMailRootDir The directory's root directory in KMail's folder structure.
+ * @param KMailSubDir The directory's equivalent in KMail's folder structure. *
+ */
+void FilterEvolution_v2::importMBox(FilterInfo *info, const QString& mboxName, const \
QString& rootDir, const QString& targetDir) +{
+  QFile mbox(mboxName);
+  if (!mbox.open(IO_ReadOnly)) {
+    info->alert(i18n("Unable to open %1, skipping").arg(mboxName));
+  } else {
+    QFileInfo filenameInfo(mboxName);
+    QTextStream mboxFile(&mbox);
+    QString mboxLine = mboxFile.readLine();
+    
+    info->setCurrent(0);
+    info->setFrom(mboxName);
+    info->setTo(targetDir);
+    
+    while (!mboxFile.atEnd()) {
+      KTempFile tmp;
+      /** @todo check if the file is really a mbox, maybe search for 'from' string \
at start */ +      *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();
+      QString destFolder = rootDir;
+      QString _targetDir = targetDir;
+      if(destFolder.contains(".sbd")) destFolder.remove(".sbd");
+      if(!targetDir.isNull()){
+         if(_targetDir.contains(".sbd")) _targetDir.remove(".sbd");
+         destFolder += ("-" + _targetDir);
+         destFolder += "-" + filenameInfo.baseName(TRUE);// mboxName;
+      }
+      
+      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);
+      if (info->shouldTerminate()) return;
+    }
+    mbox.close();
+  }
+  
+}
--- kmailcvt/filter_opera.hxx	2005-01-29 20:52:48.000000000 +0100
+++ kmailcvt/filter_opera.hxx	2005-01-29 17:27:40.000000000 +0100
@@ -0,0 +1,37 @@
+/***************************************************************************
+                  filter_opera.hxx  -  Opera mail import
+                             -------------------
+    begin                : Januar 26 2005
+    copyright            : (C) 2005 by Danny Kukawka
+    email                : danny.kukawka@web.de
+ ***************************************************************************/
+
+/***************************************************************************
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ ***************************************************************************/
+
+#ifndef FILTER_OPERA_HXX
+#define FILTER_OPERA_HXX
+
+#include "filters.hxx"
+
+/**imports opera account-archives into KMail
+ *@author Danny Kukawka
+ */
+
+class FilterOpera : public Filter {
+  public:
+    FilterOpera();
+    ~FilterOpera();
+
+    void import(FilterInfo *info);
+};
+
+#endif
+
+// vim: ts=2 sw=2 et
--- kmailcvt/filter_opera.cxx	2005-01-29 20:52:52.000000000 +0100
+++ kmailcvt/filter_opera.cxx	2005-01-30 02:15:35.000000000 +0100
@@ -0,0 +1,133 @@
+/***************************************************************************
+                  filter_opera.cxx  -  Opera mail import
+                             -------------------
+    begin                : Januar 26 2005
+    copyright            : (C) 2005 by Danny Kukawka
+    email                : danny.kukawka@web.de
+ ***************************************************************************/
+
+/***************************************************************************
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ ***************************************************************************/
+
+
+#include <config.h>
+#include <klocale.h>
+#include <kfiledialog.h>
+#include <ktempfile.h>
+#include <kdebug.h>
+#include <qdatetime.h>
+
+#include "filter_opera.hxx"
+
+FilterOpera::FilterOpera() :
+Filter(	i18n("Import Opera Emails"),
+    "Danny Kukawka",
+    i18n("<p><b>Opera email import filter</b></p>"
+      "<p>This filter will import mails from Opera mail folder. Use this filter "
+      "if you want to import all mails within a account in the Opera maildir.</p>"
+      "<p>Select the directory of the account (usually \
~/.opera/mail/store/account*).</p>" +      "<p><b>Note:</b> Emails will be imported \
into a folder named after the account they came from, prefixed with OPERA-</p>" +     \
)) +{
+}
+
+FilterOpera::~FilterOpera()
+{ 
+   endImport();
+}
+
+void FilterOpera::import(FilterInfo *info)
+{
+  /** try to go to opera mailfolder in the home of the user */
+  QString operaDir = "";
+  QString startdir = QDir::homeDirPath() + "/.opera/mail/store/" ;
+  QDir d_check( startdir );
+  if(d_check.exists()){
+  	operaDir = KFileDialog::getExistingDirectory(startdir, info->parent());
+  }
+  else {
+  	/** fallback to userhome if no opera mailfolder found in userhome */
+	operaDir = KFileDialog::getExistingDirectory(QDir::homeDirPath(), info->parent());
+  }
+  
+  if (operaDir.isEmpty()) { 
+   	info->alert(i18n("No directory selected."));
+   	return;
+  }
+  
+  info->setOverall(0);
+  
+  QDir importDir (operaDir);
+  QStringList files = importDir.entryList("*.[mM][bB][sS]", QDir::Files, \
QDir::Name); +  
+  // Count total number of files to be processed
+  info->addLog(i18n("Counting files..."));
+  int totalFiles = files.count();
+  int currentFile = 1;
+  
+  if(totalFiles > 0) {
+     int overall_status = 0;
+     
+     info->addLog(i18n("Importing new mail files..."));
+     for ( QStringList::Iterator mailFile = files.begin(); mailFile != files.end(); \
++mailFile) { +        info->setCurrent(0);
+        QFile operaArchiv( importDir.filePath(*mailFile) );
+        if (! operaArchiv.open( IO_ReadOnly ) ) {
+            info->alert( i18n("Unable to open %1, skipping").arg( *mailFile ) );
+        }
+        else {
+            info->addLog( i18n("Importing emails from %1...").arg( *mailFile ) );
+            QFileInfo filenameInfo( importDir.filePath(*mailFile) );
+            QString folderName( "OPERA-" + importDir.dirName() );
+            QTextStream operaFile( &operaArchiv );
+            QString operaLine = operaFile.readLine();
+            
+            info->setFrom( *mailFile );
+            info->setTo( folderName );
+            
+            while ( !operaFile.atEnd() ) {
+		KTempFile tmp;
+		*tmp.textStream() << operaLine << endl; 
+		while ( !( operaLine = operaFile.readLine() ).isNull() && operaLine.left(5) != \
"From " ) { +			/** remove in KMail unneeded Flags from Opera (for example: \
X-Opera-Status)*/ +			if(!operaLine.startsWith("X-Opera-")) *tmp.textStream() << \
operaLine << endl; +		}
+		
+		tmp.close();
+		if(info->removeDupMsg) addMessage( info, folderName, tmp.name() );
+		else addMessage_fastImport( info, folderName, tmp.name() );
+		tmp.unlink();
+		int currentPercentage = (int) ( ( (float) operaArchiv.at() / filenameInfo.size() ) \
* 100 ); +		info->setCurrent( currentPercentage );
+		
+		if (currentFile == 1)
+                   overall_status = (int) ( currentPercentage * ( (float) \
currentFile / totalFiles ) ); +            	else
+                   overall_status = \
(int)(((currentFile-1)*(100.0/(float)totalFiles))+(currentPercentage*(1.0/(float)totalFiles)));
 +		
+		info->setOverall( overall_status );
+		if ( info->shouldTerminate() ) return;
+            }
+	    
+            info->addLog( i18n("Finished importing emails from %1").arg( *mailFile \
)); +            if (count_duplicates > 0) {
+                info->addLog( i18n("%1 Duplicate messages not \
imported").arg(count_duplicates)); +            }
+            
+	    currentFile++;
+            count_duplicates = 0;
+            operaArchiv.close();
+       }
+    }
+  }
+  else {
+    info->addLog(i18n("No files found for import."));
+    return;
+  }
+}
--- kmailcvt/filter_thunderbird.hxx	2005-01-31 15:35:52.000000000 +0100
+++ kmailcvt/filter_thunderbird.hxx	2005-01-31 14:23:53.000000000 +0100
@@ -0,0 +1,40 @@
+/***************************************************************************
+            filter_thunderbird.hxx  -  Thunderbird mail import
+                             -------------------
+    begin                : Januar 26 2005
+    copyright            : (C) 2005 by Danny Kukawka
+    email                : danny.kukawka@web.de
+ ***************************************************************************/
+
+/***************************************************************************
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ ***************************************************************************/
+ 
+#ifndef FILTER_THUNDERBIRD_HXX
+#define FILTER_THUNDERBIRD_HXX
+
+#include "filters.hxx"
+
+/**
+ * Imports Thinderbird mail folder recursively, keeping the folder structure.
+ * @author Danny Kukawka
+ */
+class FilterThunderbird : public Filter
+{
+public:
+  FilterThunderbird(void);
+  ~FilterThunderbird(void);
+
+  void import(FilterInfo *info);
+
+private:
+  void importDirContents(FilterInfo*, const QString&, const QString&, const \
QString&); +  void importMBox(FilterInfo*, const QString&, const QString&, const \
QString&); +};
+
+#endif
--- kmailcvt/filter_thunderbird.cxx	2005-01-31 15:35:44.000000000 +0100
+++ kmailcvt/filter_thunderbird.cxx	2005-01-31 15:15:38.000000000 +0100
@@ -0,0 +1,167 @@
+/***************************************************************************
+            filter_thunderbird.cxx  -  Thunderbird mail import
+                             -------------------
+    begin                : Januar 26 2005
+    copyright            : (C) 2005 by Danny Kukawka
+    email                : danny.kukawka@web.de
+ ***************************************************************************/
+
+/***************************************************************************
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ ***************************************************************************/
+
+#include "filter_thunderbird.hxx"
+
+#include <config.h>
+#include <klocale.h>
+#include <kfiledialog.h>
+#include <ktempfile.h>
+
+
+/** Default constructor. */
+FilterThunderbird::FilterThunderbird(void) : 
+  Filter(i18n("Import Thunderbird local Mails and Folder Structure"),
+	 "Danny Kukawka",
+	 i18n("<p><b>Thunderbird import filter</b></p>"
+              "<p>Select your base Thunderbird mailfolder"
+              " (usually ~/.thunderbird/*.default/Mail/Local Folders/).</p>"
+              "<p><b>Note:</b> Never choose a Folder, which <u>doesn't</u> contain \
mbox-files (for example" +              " a maildir)! If you do it anyway, you will \
get many new folder!</p>" +              "<p>As it is currently impossible to \
recreate the folder structure, it will be " +	      "\"contained\" in the generated \
folder's names.</p>")) +{}
+
+/** Destructor. */
+FilterThunderbird::~FilterThunderbird(void) {
+   endImport();
+}
+
+/** Recursive import of Evolution's mboxes. */
+void FilterThunderbird::import(FilterInfo *info)
+{
+  /** 
+   * We ask the user to choose Evolution's root directory. 
+   * This should be usually ~/.thunderbird/*.default/Mail/Local Folders/
+   */
+  QString mailDir = KFileDialog::getExistingDirectory(QDir::homeDirPath(), \
info->parent()); +  info->setOverall(0);
+
+  /** Recursive import of the MailArchives */
+  QDir dir(mailDir);
+  QStringList rootSubDirs = dir.entryList("[^\\.]*", QDir::Dirs, QDir::Name); // \
Removal of . and .. +  int currentDir = 1, numSubDirs = rootSubDirs.size();
+  for(QStringList::Iterator filename = rootSubDirs.begin() ; filename != \
rootSubDirs.end() ; ++filename, ++currentDir) { +    importDirContents(info, \
dir.filePath(*filename), *filename, QString::null); +    info->setOverall((int) \
((float) currentDir / numSubDirs * 100)); +  }
+  
+  /** import last but not least all archives from the root-dir */
+  QDir importDir (mailDir);
+  QStringList files = importDir.entryList("[^\\.]*", QDir::Files, QDir::Name);
+  for ( QStringList::Iterator mailFile = files.begin(); mailFile != files.end(); \
++mailFile) { +    QString temp_mailfile = *mailFile;
+    if (temp_mailfile.endsWith(".msf")) {}
+    else {  
+        info->addLog( i18n("Start import file %1...").arg( temp_mailfile ) );
+        importMBox(info, mailDir + "/" + temp_mailfile , temp_mailfile, \
QString::null); +    }    
+  }
+  
+  info->addLog( i18n("Finished importing emails from %1").arg( mailDir ));
+  info->setCurrent(100);
+  if(count_duplicates > 0) {
+     info->addLog( i18n("%1 Duplicate messages not \
imported").arg(count_duplicates)); +  }
+}
+
+/**
+ * Import of a directory contents.
+ * @param info Information storage for the operation.
+ * @param dirName The name of the directory to import.
+ * @param KMailRootDir The directory's root directory in KMail's folder structure.
+ * @param KMailSubDir The directory's direct ancestor in KMail's folder structure.
+ */
+void FilterThunderbird::importDirContents(FilterInfo *info, const QString& dirName, \
const QString& KMailRootDir, const QString& KMailSubDir) +{
+    /** Here Import all archives in the current dir */
+    QDir dir(dirName);
+  
+    QDir importDir (dirName);
+    QStringList files = importDir.entryList("[^\\.]*", QDir::Files, QDir::Name);
+    for ( QStringList::Iterator mailFile = files.begin(); mailFile != files.end(); \
++mailFile) { +      QString temp_mailfile = *mailFile;
+      if (temp_mailfile.endsWith(".msf")) {}
+      else {  
+          info->addLog( i18n("Start import file %1...").arg( temp_mailfile ) );
+          importMBox(info, (dirName + "/" + temp_mailfile) , KMailRootDir, \
KMailSubDir); +      }    
+    }
+
+    /** If there are subfolders, we import them one by one */
+    QDir subfolders(dirName);
+    QStringList subDirs = subfolders.entryList("[^\\.]*", QDir::Dirs, QDir::Name);
+    for(QStringList::Iterator filename = subDirs.begin() ; filename != subDirs.end() \
; ++filename) { +      QString kSubDir;
+      if(!KMailSubDir.isNull()) {
+        kSubDir = KMailSubDir + "-" + *filename;
+      } else {
+        kSubDir = *filename;
+      }
+      importDirContents(info, subfolders.filePath(*filename), KMailRootDir, \
kSubDir); +    }
+}
+
+/**
+ * Import of a MBox file.
+ * @param info Information storage for the operation.
+ * @param dirName The MBox's name.
+ * @param KMailRootDir The directory's root directory in KMail's folder structure.
+ * @param KMailSubDir The directory's equivalent in KMail's folder structure. *
+ */
+void FilterThunderbird::importMBox(FilterInfo *info, const QString& mboxName, const \
QString& rootDir, const QString& targetDir) +{
+  QFile mbox(mboxName);
+  if (!mbox.open(IO_ReadOnly)) {
+    info->alert(i18n("Unable to open %1, skipping").arg(mboxName));
+  } else {
+    QFileInfo filenameInfo(mboxName);
+    QTextStream mboxFile(&mbox);
+    QString mboxLine = mboxFile.readLine();
+    
+    info->setCurrent(0);
+    info->setFrom(mboxName);
+    info->setTo(targetDir);
+    
+    while (!mboxFile.atEnd()) {
+      KTempFile tmp;
+      /** @todo check if the file is really a mbox, maybe search for 'from' string \
at start */ +      *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();
+      QString destFolder = rootDir;
+      QString _targetDir = targetDir;
+      if(destFolder.contains(".sbd")) destFolder.remove(".sbd");
+      if(!targetDir.isNull()){
+         if(_targetDir.contains(".sbd")) _targetDir.remove(".sbd");
+         destFolder += ("-" + _targetDir);
+         destFolder += "-" + filenameInfo.baseName(TRUE);// mboxName;
+      }
+      
+      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);
+      if (info->shouldTerminate()) return;
+    }
+    mbox.close();
+  }
+  
+}



_______________________________________________
KMail developers mailing list
KMail-devel@kde.org
https://mail.kde.org/mailman/listinfo/kmail-devel


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic