From 4bd4ac21f11fdb5b76ffda985397398102a81e9b Mon Sep 17 00:00:00 2001 From: Michele Calgaro Date: Tue, 15 Dec 2020 11:30:44 +0900 Subject: Renaming of files in preparation for code style tools. Signed-off-by: Michele Calgaro (cherry picked from commit 3a75bdfe83b71ef1dbc2fbf52f2d18b8174e22e5) --- kmailcvt/CMakeLists.txt | 12 +- kmailcvt/Makefile.am | 42 ++-- kmailcvt/README | 6 +- kmailcvt/filter_evolution.cpp | 200 ++++++++++++++++++ kmailcvt/filter_evolution.cxx | 200 ------------------ kmailcvt/filter_evolution.h | 45 ++++ kmailcvt/filter_evolution.hxx | 45 ---- kmailcvt/filter_evolution_v2.cpp | 231 ++++++++++++++++++++ kmailcvt/filter_evolution_v2.cxx | 231 -------------------- kmailcvt/filter_evolution_v2.h | 43 ++++ kmailcvt/filter_evolution_v2.hxx | 43 ---- kmailcvt/filter_kmail_archive.cpp | 35 ++++ kmailcvt/filter_kmail_archive.cxx | 35 ---- kmailcvt/filter_kmail_archive.h | 32 +++ kmailcvt/filter_kmail_archive.hxx | 32 --- kmailcvt/filter_kmail_maildir.cpp | 218 +++++++++++++++++++ kmailcvt/filter_kmail_maildir.cxx | 218 ------------------- kmailcvt/filter_kmail_maildir.h | 43 ++++ kmailcvt/filter_kmail_maildir.hxx | 43 ---- kmailcvt/filter_lnotes.cpp | 157 ++++++++++++++ kmailcvt/filter_lnotes.cxx | 157 -------------- kmailcvt/filter_lnotes.h | 53 +++++ kmailcvt/filter_lnotes.hxx | 53 ----- kmailcvt/filter_mailapp.cpp | 168 +++++++++++++++ kmailcvt/filter_mailapp.cxx | 168 --------------- kmailcvt/filter_mailapp.h | 36 ++++ kmailcvt/filter_mailapp.hxx | 36 ---- kmailcvt/filter_mbox.cpp | 144 +++++++++++++ kmailcvt/filter_mbox.cxx | 144 ------------- kmailcvt/filter_mbox.h | 37 ++++ kmailcvt/filter_mbox.hxx | 37 ---- kmailcvt/filter_oe.cpp | 429 ++++++++++++++++++++++++++++++++++++++ kmailcvt/filter_oe.cxx | 429 -------------------------------------- kmailcvt/filter_oe.h | 84 ++++++++ kmailcvt/filter_oe.hxx | 84 -------- kmailcvt/filter_opera.cpp | 158 ++++++++++++++ kmailcvt/filter_opera.cxx | 158 -------------- kmailcvt/filter_opera.h | 37 ++++ kmailcvt/filter_opera.hxx | 37 ---- kmailcvt/filter_outlook.cpp | 61 ++++++ kmailcvt/filter_outlook.cxx | 61 ------ kmailcvt/filter_outlook.h | 38 ++++ kmailcvt/filter_outlook.hxx | 38 ---- kmailcvt/filter_plain.cpp | 87 ++++++++ kmailcvt/filter_plain.cxx | 87 -------- kmailcvt/filter_plain.h | 37 ++++ kmailcvt/filter_plain.hxx | 37 ---- kmailcvt/filter_pmail.cpp | 346 ++++++++++++++++++++++++++++++ kmailcvt/filter_pmail.cxx | 346 ------------------------------ kmailcvt/filter_pmail.h | 76 +++++++ kmailcvt/filter_pmail.hxx | 76 ------- kmailcvt/filter_sylpheed.cpp | 228 ++++++++++++++++++++ kmailcvt/filter_sylpheed.cxx | 228 -------------------- kmailcvt/filter_sylpheed.h | 47 +++++ kmailcvt/filter_sylpheed.hxx | 47 ----- kmailcvt/filter_thebat.cpp | 231 ++++++++++++++++++++ kmailcvt/filter_thebat.cxx | 231 -------------------- kmailcvt/filter_thebat.h | 42 ++++ kmailcvt/filter_thebat.hxx | 42 ---- kmailcvt/filter_thunderbird.cpp | 234 +++++++++++++++++++++ kmailcvt/filter_thunderbird.cxx | 234 --------------------- kmailcvt/filter_thunderbird.h | 42 ++++ kmailcvt/filter_thunderbird.hxx | 42 ---- kmailcvt/filters.cpp | 216 +++++++++++++++++++ kmailcvt/filters.cxx | 216 ------------------- kmailcvt/filters.h | 145 +++++++++++++ kmailcvt/filters.hxx | 145 ------------- kmailcvt/kmailcvt.cpp | 2 +- kmailcvt/kselfilterpage.cpp | 32 +-- 69 files changed, 4027 insertions(+), 4027 deletions(-) create mode 100644 kmailcvt/filter_evolution.cpp delete mode 100644 kmailcvt/filter_evolution.cxx create mode 100644 kmailcvt/filter_evolution.h delete mode 100644 kmailcvt/filter_evolution.hxx create mode 100644 kmailcvt/filter_evolution_v2.cpp delete mode 100644 kmailcvt/filter_evolution_v2.cxx create mode 100644 kmailcvt/filter_evolution_v2.h delete mode 100644 kmailcvt/filter_evolution_v2.hxx create mode 100644 kmailcvt/filter_kmail_archive.cpp delete mode 100644 kmailcvt/filter_kmail_archive.cxx create mode 100644 kmailcvt/filter_kmail_archive.h delete mode 100644 kmailcvt/filter_kmail_archive.hxx create mode 100644 kmailcvt/filter_kmail_maildir.cpp delete mode 100644 kmailcvt/filter_kmail_maildir.cxx create mode 100644 kmailcvt/filter_kmail_maildir.h delete mode 100644 kmailcvt/filter_kmail_maildir.hxx create mode 100644 kmailcvt/filter_lnotes.cpp delete mode 100644 kmailcvt/filter_lnotes.cxx create mode 100644 kmailcvt/filter_lnotes.h delete mode 100644 kmailcvt/filter_lnotes.hxx create mode 100644 kmailcvt/filter_mailapp.cpp delete mode 100644 kmailcvt/filter_mailapp.cxx create mode 100644 kmailcvt/filter_mailapp.h delete mode 100644 kmailcvt/filter_mailapp.hxx create mode 100644 kmailcvt/filter_mbox.cpp delete mode 100644 kmailcvt/filter_mbox.cxx create mode 100644 kmailcvt/filter_mbox.h delete mode 100644 kmailcvt/filter_mbox.hxx create mode 100644 kmailcvt/filter_oe.cpp delete mode 100644 kmailcvt/filter_oe.cxx create mode 100644 kmailcvt/filter_oe.h delete mode 100644 kmailcvt/filter_oe.hxx create mode 100644 kmailcvt/filter_opera.cpp delete mode 100644 kmailcvt/filter_opera.cxx create mode 100644 kmailcvt/filter_opera.h delete mode 100644 kmailcvt/filter_opera.hxx create mode 100644 kmailcvt/filter_outlook.cpp delete mode 100644 kmailcvt/filter_outlook.cxx create mode 100644 kmailcvt/filter_outlook.h delete mode 100644 kmailcvt/filter_outlook.hxx create mode 100644 kmailcvt/filter_plain.cpp delete mode 100644 kmailcvt/filter_plain.cxx create mode 100644 kmailcvt/filter_plain.h delete mode 100644 kmailcvt/filter_plain.hxx create mode 100644 kmailcvt/filter_pmail.cpp delete mode 100644 kmailcvt/filter_pmail.cxx create mode 100644 kmailcvt/filter_pmail.h delete mode 100644 kmailcvt/filter_pmail.hxx create mode 100644 kmailcvt/filter_sylpheed.cpp delete mode 100644 kmailcvt/filter_sylpheed.cxx create mode 100644 kmailcvt/filter_sylpheed.h delete mode 100644 kmailcvt/filter_sylpheed.hxx create mode 100644 kmailcvt/filter_thebat.cpp delete mode 100644 kmailcvt/filter_thebat.cxx create mode 100644 kmailcvt/filter_thebat.h delete mode 100644 kmailcvt/filter_thebat.hxx create mode 100644 kmailcvt/filter_thunderbird.cpp delete mode 100644 kmailcvt/filter_thunderbird.cxx create mode 100644 kmailcvt/filter_thunderbird.h delete mode 100644 kmailcvt/filter_thunderbird.hxx create mode 100644 kmailcvt/filters.cpp delete mode 100644 kmailcvt/filters.cxx create mode 100644 kmailcvt/filters.h delete mode 100644 kmailcvt/filters.hxx (limited to 'kmailcvt') diff --git a/kmailcvt/CMakeLists.txt b/kmailcvt/CMakeLists.txt index 9a566690..ac96928a 100644 --- a/kmailcvt/CMakeLists.txt +++ b/kmailcvt/CMakeLists.txt @@ -38,12 +38,12 @@ install( tde_add_executable( kmailcvt AUTOMOC 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_outlook.cxx filter_mbox.cxx - filter_evolution.cxx filter_mailapp.cxx filter_evolution_v2.cxx - filter_opera.cxx filter_thunderbird.cxx filter_kmail_maildir.cxx - filter_sylpheed.cxx filter_thebat.cxx filter_lnotes.cxx - filter_kmail_archive.cxx + kselfilterpage.cpp filters.cpp filter_oe.cpp kmailcvt.cpp main.cpp + filter_pmail.cpp filter_plain.cpp filter_outlook.cpp filter_mbox.cpp + filter_evolution.cpp filter_mailapp.cpp filter_evolution_v2.cpp + filter_opera.cpp filter_thunderbird.cpp filter_kmail_maildir.cpp + filter_sylpheed.cpp filter_thebat.cpp filter_lnotes.cpp + filter_kmail_archive.cpp LINK tdeio-shared DESTINATION ${BIN_INSTALL_DIR} ) diff --git a/kmailcvt/Makefile.am b/kmailcvt/Makefile.am index 7c49b36a..46a25870 100644 --- a/kmailcvt/Makefile.am +++ b/kmailcvt/Makefile.am @@ -1,32 +1,32 @@ bin_PROGRAMS = kmailcvt 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_outlook.cxx \ - filter_mbox.cxx filter_evolution.cxx filter_mailapp.cxx \ - filter_evolution_v2.cxx filter_opera.cxx filter_thunderbird.cxx \ - filter_kmail_maildir.cxx filter_sylpheed.cxx filter_thebat.cxx \ - filter_lnotes.cxx filter_kmail_archive.cxx + kselfilterpage.cpp filters.cpp filter_oe.cpp kmailcvt.cpp \ + main.cpp filter_pmail.cpp filter_plain.cpp filter_outlook.cpp \ + filter_mbox.cpp filter_evolution.cpp filter_mailapp.cpp \ + filter_evolution_v2.cpp filter_opera.cpp filter_thunderbird.cpp \ + filter_kmail_maildir.cpp filter_sylpheed.cpp filter_thebat.cpp \ + filter_lnotes.cpp filter_kmail_archive.cpp kmailcvt_LDADD = $(LIB_TDEFILE) EXTRA_DIST = main.cpp kmailcvt.cpp kimportpage.cpp kimportpage.h \ kselfilterpage.cpp kselfilterpage.h kmailcvt.h \ - kmailcvt.desktop filter_oe.cxx filter_oe.hxx \ - filters.cxx filters.hxx \ + kmailcvt.desktop filter_oe.cpp filter_oe.h \ + filters.cpp filters.h \ PAB_format.html sv9429424.gif \ - filter_pmail.cxx filter_pmail.hxx \ - filter_plain.cxx filter_plain.hxx \ - filter_mbox.cxx filter_mbox.hxx \ - filter_evolution.cxx filter_evolution.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 \ - filter_kmail_maildir.hxx filter_kmail_maildir.cxx \ - filter_sylpheed.hxx filter_sylpheed.cxx \ - filter_thebat.hxx filter_thebat.cxx filter_lnotes.hxx filter_lnotes.cxx \ - filter_kmail_archive.cxx fitler_kmail_archive.hxx + filter_pmail.cpp filter_pmail.h \ + filter_plain.cpp filter_plain.h \ + filter_mbox.cpp filter_mbox.h \ + filter_evolution.cpp filter_evolution.h \ + filter_mailapp.h filter_mailapp.cpp \ + filter_opera.h filter_opera.cpp \ + filter_evolution_v2.h filter_evolution_v2.cpp \ + filter_thunderbird.h filter_thunderbird.cpp \ + filter_kmail_maildir.h filter_kmail_maildir.cpp \ + filter_sylpheed.h filter_sylpheed.cpp \ + filter_thebat.h filter_thebat.cpp filter_lnotes.h filter_lnotes.cpp \ + filter_kmail_archive.cpp fitler_kmail_archive.h install-data-local: uninstall.desktop $(mkinstalldirs) $(DESTDIR)$(kde_appsdir)/Utilities @@ -45,7 +45,7 @@ kmailcvt_LDFLAGS = $(all_libraries) $(KDE_RPATH) $(LIB_QT) -lDCOP $(LIB_TDECORE) KDE_ICON=AUTO messages: rc.cpp - LIST=`find . -name \*.h -o -name \*.hh -o -name \*.H -o -name \*.hxx -o -name \*.hpp -o -name \*.cpp -o -name \*.cc -o -name \*.cxx -o -name \*.ecpp -o -name \*.C`; \ + LIST=`find . -name \*.h -o -name \*.cpp`; \ if test -n "$$LIST"; then \ $(XGETTEXT) $$LIST -o $(podir)/kmailcvt.pot; \ fi diff --git a/kmailcvt/README b/kmailcvt/README index d8322ed4..d1105fe4 100644 --- a/kmailcvt/README +++ b/kmailcvt/README @@ -7,9 +7,9 @@ with KMail via its DCOP interface to add messages. Writing a filter ---------------- -...is very easy. Create two files filter_myformat.cxx and filter_myformat.hxx -and add "filter_myformat.cxx" to the end of the kmailcvt_SOURCES line in -Makefile.am and "filter_myformat.cxx filter_myformat.hxx" to the end of the +...is very easy. Create two files filter_myformat.cpp and filter_myformat.h +and add "filter_myformat.cpp" to the end of the kmailcvt_SOURCES line in +Makefile.am and "filter_myformat.cpp filter_myformat.h" to the end of the EXTRA_DIST line in Makefile.am. Now run "make -f Makefile.cvs; ./configure" in your tdepim source directory. diff --git a/kmailcvt/filter_evolution.cpp b/kmailcvt/filter_evolution.cpp new file mode 100644 index 00000000..a372058e --- /dev/null +++ b/kmailcvt/filter_evolution.cpp @@ -0,0 +1,200 @@ +/* + * filter_evolution.cpp + * Author : Simon MARTIN + * Copyright (c) 2004 Simon MARTIN + * + * 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. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Library General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include "filter_evolution.h" + +#include +#include +#include +#include + + +/** Default constructor. */ +FilterEvolution::FilterEvolution(void) : + Filter(i18n("Import Evolution 1.x Local Mails and Folder Structure"), + "Simon MARTIN

( Filter accelerated by Danny Kukawka )", + i18n("

Evolution 1.x import filter

" + "

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

" + "

Since it is possible to recreate the folder structure, the folders " + "will be stored under: \"Evolution-Import\".

")) +{} + +/** Destructor. */ +FilterEvolution::~FilterEvolution(void) +{ +} + +/** Recursive import of Evolution's mboxes. */ +void FilterEvolution::import(FilterInfo *info) +{ + // We ask the user to choose Evolution's root directory. + TQString evolDir = TQDir::homeDirPath() + "/evolution/local"; + TQDir d( evolDir ); + if ( !d.exists() ) { + evolDir = TQDir::homeDirPath(); + } + + mailDir = KFileDialog::getExistingDirectory(evolDir, info->parent()); + + if (mailDir.isEmpty()) { + info->alert(i18n("No directory selected.")); + } + /** + * If the user only select homedir no import needed because + * there should be no files and we surely import wrong files. + */ + else if ( mailDir == TQDir::homeDirPath() || mailDir == (TQDir::homeDirPath() + "/")) { + info->addLog(i18n("No files found for import.")); + } else { + info->setOverall(0); + // Recursive import of the MBoxes. + TQDir dir(mailDir); + TQStringList rootSubDirs = dir.entryList("[^\\.]*", TQDir::Dirs, TQDir::Name); // Removal of . and .. + int currentDir = 1, numSubDirs = rootSubDirs.size(); + for(TQStringList::Iterator filename = rootSubDirs.begin() ; filename != rootSubDirs.end() ; ++filename, ++currentDir) { + importDirContents(info, dir.filePath(*filename), *filename, TQString()); + info->setOverall((int) ((float) currentDir / numSubDirs * 100)); + } + } + info->addLog( i18n("Finished importing emails from %1").arg( mailDir )); + info->setCurrent(100); + info->setOverall(100); +} + +/** + * 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::importDirContents(FilterInfo *info, const TQString& dirName, const TQString& KMailRootDir, const TQString& KMailSubDir) +{ + // If there is a mbox, we import it + TQDir dir(dirName); + if(dir.exists("mbox")) { + importMBox(info, dirName + "/mbox", KMailRootDir, KMailSubDir); + } + // If there are subfolders, we import them one by one + if(dir.exists("subfolders")) { + TQDir subfolders(dirName + "/subfolders"); + TQStringList subDirs = subfolders.entryList("[^\\.]*", TQDir::Dirs, TQDir::Name); + for(TQStringList::Iterator filename = subDirs.begin() ; filename != subDirs.end() ; ++filename) { + TQString 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::importMBox(FilterInfo *info, const TQString& mboxName, const TQString& rootDir, const TQString& targetDir) +{ + TQFile mbox(mboxName); + bool first_msg = true; + TQString tmp_from = mboxName; + if (!mbox.open(IO_ReadOnly)) { + info->alert(i18n("Unable to open %1, skipping").arg(mboxName)); + } else { + TQFileInfo filenameInfo(mboxName); + + info->setCurrent(0); + if( mboxName.length() > 20 ) { + TQString tmp_info = mboxName; + tmp_info = tmp_info.replace( mailDir, ".." ); + if (tmp_info.contains("subfolders/")) + tmp_info.remove("subfolders/"); + info->setFrom( tmp_info ); + tmp_from = tmp_info; + } else + info->setFrom(mboxName); + if(targetDir.contains("subfolders/")) { + TQString tmp_info = targetDir; + tmp_info.remove("subfolders/"); + info->setTo(tmp_info); + } else + info->setTo(targetDir); + + info->addLog(i18n("Importing emails from %1...").arg(tmp_from)); + + TQByteArray input(MAX_LINE); + long l = 0; + + while (!mbox.atEnd()) { + KTempFile tmp; + /* comment by Danny: + * Don't use TQTextStream to read from mbox, etter use TQDataStream. TQTextStream only + * support Unicode/Latin1/Locale. So you lost information from emails with + * charset!=Unicode/Latin1/Locale (e.g. KOI8-R) and Content-Transfer-Encoding != base64 + * (e.g. 8Bit). It also not help to convert the TQTextStream to Unicode. By this you + * get Unicode/UTF-email but KMail can't detect the correct charset. + */ + TQCString seperate; + + if(!first_msg) + tmp.file()->writeBlock( input, l ); + l = mbox.readLine( input.data(),MAX_LINE); // read the first line, prevent "From " + tmp.file()->writeBlock( input, l ); + + while ( ! mbox.atEnd() && (l = mbox.readLine(input.data(),MAX_LINE)) && ((seperate = input.data()).left(5) != "From ")) { + tmp.file()->writeBlock( input, l ); + } + tmp.close(); + first_msg = false; + + TQString destFolder = rootDir; + if(!targetDir.isNull()) { + destFolder = "Evolution-Import/" + destFolder + "/" + targetDir; + } else { + destFolder = "Evolution-Import/" + destFolder; + } + + /* 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); + if (info->shouldTerminate()) return; + } + + if (count_duplicates > 0) { + info->addLog( i18n("1 duplicate message not imported", "%n duplicate messages not imported", count_duplicates)); + } + count_duplicates = 0; + mbox.close(); + } +} diff --git a/kmailcvt/filter_evolution.cxx b/kmailcvt/filter_evolution.cxx deleted file mode 100644 index b4443d14..00000000 --- a/kmailcvt/filter_evolution.cxx +++ /dev/null @@ -1,200 +0,0 @@ -/* - * filter_evolution.cxx - * Author : Simon MARTIN - * Copyright (c) 2004 Simon MARTIN - * - * 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. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Library General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#include "filter_evolution.hxx" - -#include -#include -#include -#include - - -/** Default constructor. */ -FilterEvolution::FilterEvolution(void) : - Filter(i18n("Import Evolution 1.x Local Mails and Folder Structure"), - "Simon MARTIN

( Filter accelerated by Danny Kukawka )", - i18n("

Evolution 1.x import filter

" - "

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

" - "

Since it is possible to recreate the folder structure, the folders " - "will be stored under: \"Evolution-Import\".

")) -{} - -/** Destructor. */ -FilterEvolution::~FilterEvolution(void) -{ -} - -/** Recursive import of Evolution's mboxes. */ -void FilterEvolution::import(FilterInfo *info) -{ - // We ask the user to choose Evolution's root directory. - TQString evolDir = TQDir::homeDirPath() + "/evolution/local"; - TQDir d( evolDir ); - if ( !d.exists() ) { - evolDir = TQDir::homeDirPath(); - } - - mailDir = KFileDialog::getExistingDirectory(evolDir, info->parent()); - - if (mailDir.isEmpty()) { - info->alert(i18n("No directory selected.")); - } - /** - * If the user only select homedir no import needed because - * there should be no files and we surely import wrong files. - */ - else if ( mailDir == TQDir::homeDirPath() || mailDir == (TQDir::homeDirPath() + "/")) { - info->addLog(i18n("No files found for import.")); - } else { - info->setOverall(0); - // Recursive import of the MBoxes. - TQDir dir(mailDir); - TQStringList rootSubDirs = dir.entryList("[^\\.]*", TQDir::Dirs, TQDir::Name); // Removal of . and .. - int currentDir = 1, numSubDirs = rootSubDirs.size(); - for(TQStringList::Iterator filename = rootSubDirs.begin() ; filename != rootSubDirs.end() ; ++filename, ++currentDir) { - importDirContents(info, dir.filePath(*filename), *filename, TQString()); - info->setOverall((int) ((float) currentDir / numSubDirs * 100)); - } - } - info->addLog( i18n("Finished importing emails from %1").arg( mailDir )); - info->setCurrent(100); - info->setOverall(100); -} - -/** - * 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::importDirContents(FilterInfo *info, const TQString& dirName, const TQString& KMailRootDir, const TQString& KMailSubDir) -{ - // If there is a mbox, we import it - TQDir dir(dirName); - if(dir.exists("mbox")) { - importMBox(info, dirName + "/mbox", KMailRootDir, KMailSubDir); - } - // If there are subfolders, we import them one by one - if(dir.exists("subfolders")) { - TQDir subfolders(dirName + "/subfolders"); - TQStringList subDirs = subfolders.entryList("[^\\.]*", TQDir::Dirs, TQDir::Name); - for(TQStringList::Iterator filename = subDirs.begin() ; filename != subDirs.end() ; ++filename) { - TQString 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::importMBox(FilterInfo *info, const TQString& mboxName, const TQString& rootDir, const TQString& targetDir) -{ - TQFile mbox(mboxName); - bool first_msg = true; - TQString tmp_from = mboxName; - if (!mbox.open(IO_ReadOnly)) { - info->alert(i18n("Unable to open %1, skipping").arg(mboxName)); - } else { - TQFileInfo filenameInfo(mboxName); - - info->setCurrent(0); - if( mboxName.length() > 20 ) { - TQString tmp_info = mboxName; - tmp_info = tmp_info.replace( mailDir, ".." ); - if (tmp_info.contains("subfolders/")) - tmp_info.remove("subfolders/"); - info->setFrom( tmp_info ); - tmp_from = tmp_info; - } else - info->setFrom(mboxName); - if(targetDir.contains("subfolders/")) { - TQString tmp_info = targetDir; - tmp_info.remove("subfolders/"); - info->setTo(tmp_info); - } else - info->setTo(targetDir); - - info->addLog(i18n("Importing emails from %1...").arg(tmp_from)); - - TQByteArray input(MAX_LINE); - long l = 0; - - while (!mbox.atEnd()) { - KTempFile tmp; - /* comment by Danny: - * Don't use TQTextStream to read from mbox, etter use TQDataStream. TQTextStream only - * support Unicode/Latin1/Locale. So you lost information from emails with - * charset!=Unicode/Latin1/Locale (e.g. KOI8-R) and Content-Transfer-Encoding != base64 - * (e.g. 8Bit). It also not help to convert the TQTextStream to Unicode. By this you - * get Unicode/UTF-email but KMail can't detect the correct charset. - */ - TQCString seperate; - - if(!first_msg) - tmp.file()->writeBlock( input, l ); - l = mbox.readLine( input.data(),MAX_LINE); // read the first line, prevent "From " - tmp.file()->writeBlock( input, l ); - - while ( ! mbox.atEnd() && (l = mbox.readLine(input.data(),MAX_LINE)) && ((seperate = input.data()).left(5) != "From ")) { - tmp.file()->writeBlock( input, l ); - } - tmp.close(); - first_msg = false; - - TQString destFolder = rootDir; - if(!targetDir.isNull()) { - destFolder = "Evolution-Import/" + destFolder + "/" + targetDir; - } else { - destFolder = "Evolution-Import/" + destFolder; - } - - /* 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); - if (info->shouldTerminate()) return; - } - - if (count_duplicates > 0) { - info->addLog( i18n("1 duplicate message not imported", "%n duplicate messages not imported", count_duplicates)); - } - count_duplicates = 0; - mbox.close(); - } -} diff --git a/kmailcvt/filter_evolution.h b/kmailcvt/filter_evolution.h new file mode 100644 index 00000000..83fb4155 --- /dev/null +++ b/kmailcvt/filter_evolution.h @@ -0,0 +1,45 @@ +/* + * filter_evolution.h + * Author : Simon MARTIN + * Copyright (c) 2004 Simon MARTIN + * + * 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. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Library General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifndef FILTER_EVOLUTION_H +#define FILTER_EVOLUTION_H + +#include "filters.h" + +/** + * Imports Evolution mboxes recursively, keeping the folder structure. + * @author Simon MARTIN + */ +class FilterEvolution : public Filter +{ +public: + FilterEvolution(void); + ~FilterEvolution(void); + + void import(FilterInfo *info); + +private: + TQString mailDir; + + void importDirContents(FilterInfo*, const TQString&, const TQString&, const TQString&); + void importMBox(FilterInfo*, const TQString&, const TQString&, const TQString&); +}; + +#endif diff --git a/kmailcvt/filter_evolution.hxx b/kmailcvt/filter_evolution.hxx deleted file mode 100644 index 1aa5184f..00000000 --- a/kmailcvt/filter_evolution.hxx +++ /dev/null @@ -1,45 +0,0 @@ -/* - * filter_evolution.hxx - * Author : Simon MARTIN - * Copyright (c) 2004 Simon MARTIN - * - * 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. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Library General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#ifndef FILTER_EVOLUTION_HXX -#define FILTER_EVOLUTION_HXX - -#include "filters.hxx" - -/** - * Imports Evolution mboxes recursively, keeping the folder structure. - * @author Simon MARTIN - */ -class FilterEvolution : public Filter -{ -public: - FilterEvolution(void); - ~FilterEvolution(void); - - void import(FilterInfo *info); - -private: - TQString mailDir; - - void importDirContents(FilterInfo*, const TQString&, const TQString&, const TQString&); - void importMBox(FilterInfo*, const TQString&, const TQString&, const TQString&); -}; - -#endif diff --git a/kmailcvt/filter_evolution_v2.cpp b/kmailcvt/filter_evolution_v2.cpp new file mode 100644 index 00000000..a4c6203c --- /dev/null +++ b/kmailcvt/filter_evolution_v2.cpp @@ -0,0 +1,231 @@ +/*************************************************************************** + filter_evolution_v2.cpp - 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.h" + +#include +#include +#include +#include + + +/** Default constructor. */ +FilterEvolution_v2::FilterEvolution_v2(void) : + Filter(i18n("Import Evolution 2.x Local Mails and Folder Structure"), + "Danny Kukawka", + i18n("

Evolution 2.x import filter

" + "

Select the base directory of your local Evolution mailfolder (usually ~/.evolution/mail/local/).

" + "

Note: Never choose a Folder which does not contain mbox-files (for example " + "a maildir): if you do, you will get many new folders.

" + "

Since it is possible to recreate the folder structure, the folders " + "will be stored under: \"Evolution-Import\".

")) +{} + +/** Destructor. */ +FilterEvolution_v2::~FilterEvolution_v2(void) +{ +} + +/** 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/ + */ + TQString evolDir = TQDir::homeDirPath() + "/.evolution/mail/local"; + TQDir d( evolDir ); + if ( !d.exists() ) { + evolDir = TQDir::homeDirPath(); + } + + //TQString mailDir = KFileDialog::getExistingDirectory(TQDir::homeDirPath(), info->parent()); + KFileDialog *kfd; + kfd = new KFileDialog( evolDir, "", 0, "tdefiledialog", true ); + kfd->setMode(KFile::Directory | KFile::LocalOnly); + kfd->exec(); + mailDir = kfd->selectedFile(); + delete kfd; + + if (mailDir.isEmpty()) { + info->alert(i18n("No directory selected.")); + } + /** + * If the user only select homedir no import needed because + * there should be no files and we surely import wrong files. + */ + else if ( mailDir == TQDir::homeDirPath() || mailDir == (TQDir::homeDirPath() + "/")) { + info->addLog(i18n("No files found for import.")); + } else { + info->setOverall(0); + + /** Recursive import of the MailArchives */ + TQDir dir(mailDir); + TQStringList rootSubDirs = dir.entryList("[^\\.]*", TQDir::Dirs, TQDir::Name); // Removal of . and .. + int currentDir = 1, numSubDirs = rootSubDirs.size(); + for(TQStringList::Iterator dirname = rootSubDirs.begin() ; dirname != rootSubDirs.end() ; ++dirname, ++currentDir) { + if (info->shouldTerminate()) break; + importDirContents(info, false, dir.filePath(*dirname), *dirname, *dirname); + info->setOverall((int) ((float) currentDir / numSubDirs * 100)); + } + + /** import last but not least all archives from the root-dir */ + importDirContents(info, true, mailDir, TQString(), TQString()); + + info->addLog( i18n("Finished importing emails from %1").arg( mailDir )); + if(count_duplicates > 0) { + info->addLog( i18n("1 duplicate message not imported", "%n duplicate messages not imported", count_duplicates)); + } + if (info->shouldTerminate()) info->addLog( i18n("Finished import, canceled by user.")); + } + info->setCurrent(100); + info->setOverall(100); +} + +/** + * Import of a directory contents. + * @param info Information storage for the operation. + * @param root if this is the rootdir or not + * @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, bool root, + const TQString& dirName, const TQString& KMailRootDir, const TQString& KMailSubDir) +{ + if (info->shouldTerminate()) return; + + /** Here Import all archives in the current dir */ + TQDir dir(dirName); + + TQDir importDir (dirName); + TQStringList files = importDir.entryList("[^\\.]*", TQDir::Files, TQDir::Name); + for ( TQStringList::Iterator mailFile = files.begin(); mailFile != files.end(); ++mailFile) { + if (info->shouldTerminate()) break; + TQString temp_mailfile = *mailFile; + if (temp_mailfile.endsWith(".cmeta") || temp_mailfile.endsWith(".ev-summary") || temp_mailfile.endsWith(".ev-summary-meta") || + temp_mailfile.endsWith(".ibex.index") || temp_mailfile.endsWith(".ibex.index.data") ) {} + else { + info->addLog( i18n("Start import file %1...").arg( temp_mailfile ) ); + if (!root) + importMBox(info, (dirName + "/" + temp_mailfile) , KMailRootDir, KMailSubDir); + else + importMBox(info, dirName + temp_mailfile , temp_mailfile, TQString()); + } + } + + if (!root) { + /** If there are subfolders, we import them one by one */ + TQDir subfolders(dirName); + TQStringList subDirs = subfolders.entryList("[^\\.]*", TQDir::Dirs, TQDir::Name); + for(TQStringList::Iterator filename = subDirs.begin() ; filename != subDirs.end() ; ++filename) { + TQString kSubDir; + if(!KMailSubDir.isNull()) { + kSubDir = KMailSubDir + "/" + *filename; + } else { + kSubDir = *filename; + } + importDirContents(info, false, 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 TQString& mboxName, const TQString& rootDir, const TQString& targetDir) +{ + TQFile mbox(mboxName); + bool first_msg = true; + if (!mbox.open(IO_ReadOnly)) { + info->alert(i18n("Unable to open %1, skipping").arg(mboxName)); + } else { + TQFileInfo filenameInfo(mboxName); + + info->setCurrent(0); + if( mboxName.length() > 20 ) { + TQString tmp_info = mboxName; + tmp_info = tmp_info.replace( mailDir, "../" ); + if (tmp_info.contains(".sbd")) + tmp_info.remove(".sbd"); + info->setFrom( tmp_info ); + } else + info->setFrom(mboxName); + if(targetDir.contains(".sbd")) { + TQString tmp_info = targetDir; + tmp_info.remove(".sbd"); + info->setTo(tmp_info); + } else + info->setTo(targetDir); + + TQByteArray input(MAX_LINE); + long l = 0; + + while (!mbox.atEnd()) { + KTempFile tmp; + /** @todo check if the file is really a mbox, maybe search for 'from' string at start */ + /* comment by Danny: + * Don't use TQTextStream to read from mbox, etter use TQDataStream. TQTextStream only + * support Unicode/Latin1/Locale. So you lost information from emails with + * charset!=Unicode/Latin1/Locale (e.g. KOI8-R) and Content-Transfer-Encoding != base64 + * (e.g. 8Bit). It also not help to convert the TQTextStream to Unicode. By this you + * get Unicode/UTF-email but KMail can't detect the correct charset. + */ + TQCString seperate; + + if(!first_msg) + tmp.file()->writeBlock( input, l ); + l = mbox.readLine( input.data(),MAX_LINE); // read the first line, prevent "From " + tmp.file()->writeBlock( input, l ); + + while ( ! mbox.atEnd() && (l = mbox.readLine(input.data(),MAX_LINE)) && ((seperate = input.data()).left(5) != "From ")) { + tmp.file()->writeBlock( input, l ); + } + tmp.close(); + first_msg = false; + + TQString destFolder; + TQString _targetDir = targetDir; + if(!targetDir.isNull()) { + if(_targetDir.contains(".sbd")) + _targetDir.remove(".sbd"); + destFolder += "Evolution-Import/" + _targetDir + "/" + filenameInfo.baseName(TRUE); // mboxName; + } else { + destFolder = "Evolution-Import/" + rootDir; + if(destFolder.contains(".sbd")) + destFolder.remove(".sbd"); + } + + + 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()) break; + } + mbox.close(); + } +} diff --git a/kmailcvt/filter_evolution_v2.cxx b/kmailcvt/filter_evolution_v2.cxx deleted file mode 100644 index b6ee8a57..00000000 --- a/kmailcvt/filter_evolution_v2.cxx +++ /dev/null @@ -1,231 +0,0 @@ -/*************************************************************************** - 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 -#include -#include -#include - - -/** Default constructor. */ -FilterEvolution_v2::FilterEvolution_v2(void) : - Filter(i18n("Import Evolution 2.x Local Mails and Folder Structure"), - "Danny Kukawka", - i18n("

Evolution 2.x import filter

" - "

Select the base directory of your local Evolution mailfolder (usually ~/.evolution/mail/local/).

" - "

Note: Never choose a Folder which does not contain mbox-files (for example " - "a maildir): if you do, you will get many new folders.

" - "

Since it is possible to recreate the folder structure, the folders " - "will be stored under: \"Evolution-Import\".

")) -{} - -/** Destructor. */ -FilterEvolution_v2::~FilterEvolution_v2(void) -{ -} - -/** 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/ - */ - TQString evolDir = TQDir::homeDirPath() + "/.evolution/mail/local"; - TQDir d( evolDir ); - if ( !d.exists() ) { - evolDir = TQDir::homeDirPath(); - } - - //TQString mailDir = KFileDialog::getExistingDirectory(TQDir::homeDirPath(), info->parent()); - KFileDialog *kfd; - kfd = new KFileDialog( evolDir, "", 0, "tdefiledialog", true ); - kfd->setMode(KFile::Directory | KFile::LocalOnly); - kfd->exec(); - mailDir = kfd->selectedFile(); - delete kfd; - - if (mailDir.isEmpty()) { - info->alert(i18n("No directory selected.")); - } - /** - * If the user only select homedir no import needed because - * there should be no files and we surely import wrong files. - */ - else if ( mailDir == TQDir::homeDirPath() || mailDir == (TQDir::homeDirPath() + "/")) { - info->addLog(i18n("No files found for import.")); - } else { - info->setOverall(0); - - /** Recursive import of the MailArchives */ - TQDir dir(mailDir); - TQStringList rootSubDirs = dir.entryList("[^\\.]*", TQDir::Dirs, TQDir::Name); // Removal of . and .. - int currentDir = 1, numSubDirs = rootSubDirs.size(); - for(TQStringList::Iterator dirname = rootSubDirs.begin() ; dirname != rootSubDirs.end() ; ++dirname, ++currentDir) { - if (info->shouldTerminate()) break; - importDirContents(info, false, dir.filePath(*dirname), *dirname, *dirname); - info->setOverall((int) ((float) currentDir / numSubDirs * 100)); - } - - /** import last but not least all archives from the root-dir */ - importDirContents(info, true, mailDir, TQString(), TQString()); - - info->addLog( i18n("Finished importing emails from %1").arg( mailDir )); - if(count_duplicates > 0) { - info->addLog( i18n("1 duplicate message not imported", "%n duplicate messages not imported", count_duplicates)); - } - if (info->shouldTerminate()) info->addLog( i18n("Finished import, canceled by user.")); - } - info->setCurrent(100); - info->setOverall(100); -} - -/** - * Import of a directory contents. - * @param info Information storage for the operation. - * @param root if this is the rootdir or not - * @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, bool root, - const TQString& dirName, const TQString& KMailRootDir, const TQString& KMailSubDir) -{ - if (info->shouldTerminate()) return; - - /** Here Import all archives in the current dir */ - TQDir dir(dirName); - - TQDir importDir (dirName); - TQStringList files = importDir.entryList("[^\\.]*", TQDir::Files, TQDir::Name); - for ( TQStringList::Iterator mailFile = files.begin(); mailFile != files.end(); ++mailFile) { - if (info->shouldTerminate()) break; - TQString temp_mailfile = *mailFile; - if (temp_mailfile.endsWith(".cmeta") || temp_mailfile.endsWith(".ev-summary") || temp_mailfile.endsWith(".ev-summary-meta") || - temp_mailfile.endsWith(".ibex.index") || temp_mailfile.endsWith(".ibex.index.data") ) {} - else { - info->addLog( i18n("Start import file %1...").arg( temp_mailfile ) ); - if (!root) - importMBox(info, (dirName + "/" + temp_mailfile) , KMailRootDir, KMailSubDir); - else - importMBox(info, dirName + temp_mailfile , temp_mailfile, TQString()); - } - } - - if (!root) { - /** If there are subfolders, we import them one by one */ - TQDir subfolders(dirName); - TQStringList subDirs = subfolders.entryList("[^\\.]*", TQDir::Dirs, TQDir::Name); - for(TQStringList::Iterator filename = subDirs.begin() ; filename != subDirs.end() ; ++filename) { - TQString kSubDir; - if(!KMailSubDir.isNull()) { - kSubDir = KMailSubDir + "/" + *filename; - } else { - kSubDir = *filename; - } - importDirContents(info, false, 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 TQString& mboxName, const TQString& rootDir, const TQString& targetDir) -{ - TQFile mbox(mboxName); - bool first_msg = true; - if (!mbox.open(IO_ReadOnly)) { - info->alert(i18n("Unable to open %1, skipping").arg(mboxName)); - } else { - TQFileInfo filenameInfo(mboxName); - - info->setCurrent(0); - if( mboxName.length() > 20 ) { - TQString tmp_info = mboxName; - tmp_info = tmp_info.replace( mailDir, "../" ); - if (tmp_info.contains(".sbd")) - tmp_info.remove(".sbd"); - info->setFrom( tmp_info ); - } else - info->setFrom(mboxName); - if(targetDir.contains(".sbd")) { - TQString tmp_info = targetDir; - tmp_info.remove(".sbd"); - info->setTo(tmp_info); - } else - info->setTo(targetDir); - - TQByteArray input(MAX_LINE); - long l = 0; - - while (!mbox.atEnd()) { - KTempFile tmp; - /** @todo check if the file is really a mbox, maybe search for 'from' string at start */ - /* comment by Danny: - * Don't use TQTextStream to read from mbox, etter use TQDataStream. TQTextStream only - * support Unicode/Latin1/Locale. So you lost information from emails with - * charset!=Unicode/Latin1/Locale (e.g. KOI8-R) and Content-Transfer-Encoding != base64 - * (e.g. 8Bit). It also not help to convert the TQTextStream to Unicode. By this you - * get Unicode/UTF-email but KMail can't detect the correct charset. - */ - TQCString seperate; - - if(!first_msg) - tmp.file()->writeBlock( input, l ); - l = mbox.readLine( input.data(),MAX_LINE); // read the first line, prevent "From " - tmp.file()->writeBlock( input, l ); - - while ( ! mbox.atEnd() && (l = mbox.readLine(input.data(),MAX_LINE)) && ((seperate = input.data()).left(5) != "From ")) { - tmp.file()->writeBlock( input, l ); - } - tmp.close(); - first_msg = false; - - TQString destFolder; - TQString _targetDir = targetDir; - if(!targetDir.isNull()) { - if(_targetDir.contains(".sbd")) - _targetDir.remove(".sbd"); - destFolder += "Evolution-Import/" + _targetDir + "/" + filenameInfo.baseName(TRUE); // mboxName; - } else { - destFolder = "Evolution-Import/" + rootDir; - if(destFolder.contains(".sbd")) - destFolder.remove(".sbd"); - } - - - 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()) break; - } - mbox.close(); - } -} diff --git a/kmailcvt/filter_evolution_v2.h b/kmailcvt/filter_evolution_v2.h new file mode 100644 index 00000000..2c93bba8 --- /dev/null +++ b/kmailcvt/filter_evolution_v2.h @@ -0,0 +1,43 @@ +/*************************************************************************** + filter_evolution_v2.h - 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_H +#define FILTER_EVOLUTION_V2_H + +#include "filters.h" + +/** + * 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: + TQString mailDir; + + void importDirContents(FilterInfo*, bool, const TQString&, const TQString&, const TQString&); + void importMBox(FilterInfo*, const TQString&, const TQString&, const TQString&); +}; + +#endif diff --git a/kmailcvt/filter_evolution_v2.hxx b/kmailcvt/filter_evolution_v2.hxx deleted file mode 100644 index da58b4fe..00000000 --- a/kmailcvt/filter_evolution_v2.hxx +++ /dev/null @@ -1,43 +0,0 @@ -/*************************************************************************** - 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: - TQString mailDir; - - void importDirContents(FilterInfo*, bool, const TQString&, const TQString&, const TQString&); - void importMBox(FilterInfo*, const TQString&, const TQString&, const TQString&); -}; - -#endif diff --git a/kmailcvt/filter_kmail_archive.cpp b/kmailcvt/filter_kmail_archive.cpp new file mode 100644 index 00000000..49325d2a --- /dev/null +++ b/kmailcvt/filter_kmail_archive.cpp @@ -0,0 +1,35 @@ +/* Copyright 2009 Klarälvdalens Datakonsult AB + + 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) version 3 or any later version + accepted by the membership of KDE e.V. (or its successor approved + by the membership of KDE e.V.), which shall act as a proxy + defined in Section 14 of version 3 of the license. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ +#include "filter_kmail_archive.h" + +#include + +FilterKMailArchive::FilterKMailArchive() + : Filter( i18n( "Import KMail Archive File" ), + "Klar\xE4lvdalens Datakonsult AB", + i18n( "

KMail Archive File Import Filter

" + "

This filter will import archives files previously exported by KMail.

" + "

Archive files contain a complete folder subtree compressed into a single file.

" ) ) +{ +} + +void FilterKMailArchive::import( FilterInfo *info ) +{ + showKMailImportArchiveDialog( info ); +} diff --git a/kmailcvt/filter_kmail_archive.cxx b/kmailcvt/filter_kmail_archive.cxx deleted file mode 100644 index 3c7c20d0..00000000 --- a/kmailcvt/filter_kmail_archive.cxx +++ /dev/null @@ -1,35 +0,0 @@ -/* Copyright 2009 Klarälvdalens Datakonsult AB - - 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) version 3 or any later version - accepted by the membership of KDE e.V. (or its successor approved - by the membership of KDE e.V.), which shall act as a proxy - defined in Section 14 of version 3 of the license. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ -#include "filter_kmail_archive.hxx" - -#include - -FilterKMailArchive::FilterKMailArchive() - : Filter( i18n( "Import KMail Archive File" ), - "Klar\xE4lvdalens Datakonsult AB", - i18n( "

KMail Archive File Import Filter

" - "

This filter will import archives files previously exported by KMail.

" - "

Archive files contain a complete folder subtree compressed into a single file.

" ) ) -{ -} - -void FilterKMailArchive::import( FilterInfo *info ) -{ - showKMailImportArchiveDialog( info ); -} diff --git a/kmailcvt/filter_kmail_archive.h b/kmailcvt/filter_kmail_archive.h new file mode 100644 index 00000000..a1f74925 --- /dev/null +++ b/kmailcvt/filter_kmail_archive.h @@ -0,0 +1,32 @@ +/* Copyright 2009 Klarälvdalens Datakonsult AB + + 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) version 3 or any later version + accepted by the membership of KDE e.V. (or its successor approved + by the membership of KDE e.V.), which shall act as a proxy + defined in Section 14 of version 3 of the license. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ +#ifndef FILTER_KMAIL_ARCHIVE_H +#define FILTER_KMAIL_ARCHIVE_H + +#include "filters.h" + +class FilterKMailArchive : public Filter +{ +public: + FilterKMailArchive(); + void import( FilterInfo *info ); + virtual bool needsSecondPage() { return false; } +}; + +#endif diff --git a/kmailcvt/filter_kmail_archive.hxx b/kmailcvt/filter_kmail_archive.hxx deleted file mode 100644 index 755d3cc2..00000000 --- a/kmailcvt/filter_kmail_archive.hxx +++ /dev/null @@ -1,32 +0,0 @@ -/* Copyright 2009 Klarälvdalens Datakonsult AB - - 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) version 3 or any later version - accepted by the membership of KDE e.V. (or its successor approved - by the membership of KDE e.V.), which shall act as a proxy - defined in Section 14 of version 3 of the license. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ -#ifndef FILTER_KMAIL_ARCHIVE_HXX -#define FILTER_KMAIL_ARCHIVE_HXX - -#include "filters.hxx" - -class FilterKMailArchive : public Filter -{ -public: - FilterKMailArchive(); - void import( FilterInfo *info ); - virtual bool needsSecondPage() { return false; } -}; - -#endif diff --git a/kmailcvt/filter_kmail_maildir.cpp b/kmailcvt/filter_kmail_maildir.cpp new file mode 100644 index 00000000..f24ef7af --- /dev/null +++ b/kmailcvt/filter_kmail_maildir.cpp @@ -0,0 +1,218 @@ +/*************************************************************************** + filter_kmail_maildir.cpp - Kmail maildir mail import + ------------------- + begin : April 06 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_kmail_maildir.h" + +#include +#include +#include + +/** Default constructor. */ +FilterKMail_maildir::FilterKMail_maildir( void ) : + Filter( i18n( "Import KMail Maildirs and Folder Structure" ), + "Danny Kukawka", + i18n( "

KMail import filter

" + "

Select the base directory of the KMail mailfolder you want to import.

" + "

Note: Never select your current local KMail maildir (usually " + "~/Mail or ~/.trinity/share/apps/kmail/mail ): in this case, KMailCVT may become stuck " + "in a continuous loop.

" + "

This filter does not import KMail mailfolders with mbox files.

" + "

Since it is possible to recreate the folder structure, the folders " + "will be stored under: \"KMail-Import\" in your local folder.

" ) ) +{} + +/** Destructor. */ +FilterKMail_maildir::~FilterKMail_maildir( void ) +{ +} + +/** Recursive import of KMail maildir. */ +void FilterKMail_maildir::import( FilterInfo *info ) +{ + + TQString _homeDir = TQDir::homeDirPath(); + + KFileDialog *kfd; + kfd = new KFileDialog( _homeDir, "", 0, "tdefiledialog", true ); + kfd->setMode( KFile::Directory | KFile::LocalOnly ); + kfd->exec(); + mailDir = kfd->selectedFile(); + delete kfd; + + if ( mailDir.isEmpty() ) { + info->alert( i18n( "No directory selected." ) ); + } + /** + * If the user only select homedir no import needed because + * there should be no files and we surely import wrong files. + */ + else if ( mailDir == TQDir::homeDirPath() || mailDir == ( TQDir::homeDirPath() + "/" ) ) { + info->addLog( i18n( "No files found for import." ) ); + } else { + info->setOverall(0); + + /** Recursive import of the MailArchives */ + TQDir dir(mailDir); + TQStringList rootSubDirs = dir.entryList("*", TQDir::Dirs | TQDir::Hidden, TQDir::Name); + int currentDir = 1, numSubDirs = rootSubDirs.size(); + for(TQStringList::Iterator filename = rootSubDirs.begin() ; filename != rootSubDirs.end() ; ++filename, ++currentDir) { + if(info->shouldTerminate()) break; + if(!(*filename == "." || *filename == "..")) { + info->setCurrent(0); + importDirContents(info, dir.filePath(*filename)); + info->setOverall((int) ((float) currentDir / numSubDirs * 100)); + info->setCurrent(100); + } + } + } + + info->addLog( i18n("Finished importing emails from %1").arg( mailDir )); + if (count_duplicates > 0) { + info->addLog( i18n("1 duplicate message not imported", "%n duplicate messages not imported", count_duplicates)); + } + if (info->shouldTerminate()) info->addLog( i18n("Finished import, canceled by user.")); + count_duplicates = 0; + info->setCurrent(100); + info->setOverall(100); +} + +/** + * Import of a directory contents. + * @param info Information storage for the operation. + * @param dirName The name of the directory to import. + */ +void FilterKMail_maildir::importDirContents( FilterInfo *info, const TQString& dirName) +{ + + /** Here Import all archives in the current dir */ + importFiles(info, dirName); + + /** If there are subfolders, we import them one by one */ + + TQDir subfolders(dirName); + TQStringList subDirs = subfolders.entryList("*", TQDir::Dirs | TQDir::Hidden, TQDir::Name); + for(TQStringList::Iterator filename = subDirs.begin() ; filename != subDirs.end() ; ++filename) { + if(info->shouldTerminate()) return; + if(!(*filename == "." || *filename == "..")) { + importDirContents(info, subfolders.filePath(*filename)); + } + } +} + + +/** + * Extract the X-Status flag from a mailfile + * @param info Information storage for the operation. + * @param fileName The full path to the file to import + */ +TQString FilterKMail_maildir::getMessageFlags( FilterInfo *info, const TQString& fileName ) { + + TQString status_flag = ""; + + TQFile mailfile( fileName ); + if (! mailfile.open( IO_ReadOnly ) ) { + info->alert( i18n("Unable to open %1, skipping").arg( fileName ) ); + return status_flag; + } else { + + TQByteArray input(MAX_LINE); + + while ( !mailfile.atEnd() && status_flag.isEmpty()) { + TQCString seperate; + + while ( ! mailfile.atEnd() && mailfile.readLine(input.data(),MAX_LINE) ) { + + if ((seperate = input.data()).left(10) == "X-Status: ") { + status_flag = seperate; + status_flag.remove("X-Status: "); + status_flag = status_flag.stripWhiteSpace(); + // tqDebug("status_flag: %s", status_flag.latin1() ); + break; + } + } + } + mailfile.close(); + } + return status_flag; +} + + +/** + * Import the files within a Folder. + * @param info Information storage for the operation. + * @param dirName The name of the directory to import. + */ +void FilterKMail_maildir::importFiles( FilterInfo *info, const TQString& dirName) +{ + + TQDir dir(dirName); + TQString _path; + bool generatedPath = false; + + TQDir importDir (dirName); + TQStringList files = importDir.entryList("[^\\.]*", TQDir::Files, TQDir::Name); + int currentFile = 1, numFiles = files.size(); + for ( TQStringList::Iterator mailFile = files.begin(); mailFile != files.end(); ++mailFile, ++currentFile) { + if(info->shouldTerminate()) return; + + TQString temp_mailfile = *mailFile; + + if (!(temp_mailfile.endsWith(".index") || temp_mailfile.endsWith(".index.ids") || + temp_mailfile.endsWith(".index.sorted") || temp_mailfile.endsWith(".uidcache") )) { + if(!generatedPath) { + _path = "KMail-Import"; + TQString _tmp = dir.filePath(*mailFile); + _tmp = _tmp.remove( mailDir ,TRUE); + TQStringList subFList = TQStringList::split("/",_tmp,FALSE); + for ( TQStringList::Iterator it = subFList.begin(); it != subFList.end(); ++it ) { + TQString _cat = *it; + if(!(_cat == *mailFile)) { + if(_cat.startsWith(".") && _cat.endsWith(".directory")) { + _cat.remove(0,1); + _cat.remove((_cat.length() - 10), 10); + } else if (_cat.startsWith(".")) { + _cat = _cat.remove(0 , 1); + } + _path += "/" + _cat; + } + } + if(_path.endsWith("cur")) + _path.remove(_path.length() - 4 , 4); + TQString _info = _path; + info->addLog(i18n("Import folder %1...").arg(_info.remove(0,12))); + info->setFrom(_info); + info->setTo(_path); + generatedPath = true; + } + + TQString msg_flag = getMessageFlags(info, dir.filePath(*mailFile)); + + if(info->removeDupMsg) { + if(! addMessage( info, _path, dir.filePath(*mailFile), msg_flag )) { + info->addLog( i18n("Could not import %1").arg( *mailFile ) ); + } + info->setCurrent((int) ((float) currentFile / numFiles * 100)); + } else { + if(! addMessage_fastImport( info, _path, dir.filePath(*mailFile), msg_flag )) { + info->addLog( i18n("Could not import %1").arg( *mailFile ) ); + } + info->setCurrent((int) ((float) currentFile / numFiles * 100)); + } + } + } +} + diff --git a/kmailcvt/filter_kmail_maildir.cxx b/kmailcvt/filter_kmail_maildir.cxx deleted file mode 100644 index 9d642814..00000000 --- a/kmailcvt/filter_kmail_maildir.cxx +++ /dev/null @@ -1,218 +0,0 @@ -/*************************************************************************** - filter_kmail_maildir.cxx - Kmail maildir mail import - ------------------- - begin : April 06 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_kmail_maildir.hxx" - -#include -#include -#include - -/** Default constructor. */ -FilterKMail_maildir::FilterKMail_maildir( void ) : - Filter( i18n( "Import KMail Maildirs and Folder Structure" ), - "Danny Kukawka", - i18n( "

KMail import filter

" - "

Select the base directory of the KMail mailfolder you want to import.

" - "

Note: Never select your current local KMail maildir (usually " - "~/Mail or ~/.trinity/share/apps/kmail/mail ): in this case, KMailCVT may become stuck " - "in a continuous loop.

" - "

This filter does not import KMail mailfolders with mbox files.

" - "

Since it is possible to recreate the folder structure, the folders " - "will be stored under: \"KMail-Import\" in your local folder.

" ) ) -{} - -/** Destructor. */ -FilterKMail_maildir::~FilterKMail_maildir( void ) -{ -} - -/** Recursive import of KMail maildir. */ -void FilterKMail_maildir::import( FilterInfo *info ) -{ - - TQString _homeDir = TQDir::homeDirPath(); - - KFileDialog *kfd; - kfd = new KFileDialog( _homeDir, "", 0, "tdefiledialog", true ); - kfd->setMode( KFile::Directory | KFile::LocalOnly ); - kfd->exec(); - mailDir = kfd->selectedFile(); - delete kfd; - - if ( mailDir.isEmpty() ) { - info->alert( i18n( "No directory selected." ) ); - } - /** - * If the user only select homedir no import needed because - * there should be no files and we surely import wrong files. - */ - else if ( mailDir == TQDir::homeDirPath() || mailDir == ( TQDir::homeDirPath() + "/" ) ) { - info->addLog( i18n( "No files found for import." ) ); - } else { - info->setOverall(0); - - /** Recursive import of the MailArchives */ - TQDir dir(mailDir); - TQStringList rootSubDirs = dir.entryList("*", TQDir::Dirs | TQDir::Hidden, TQDir::Name); - int currentDir = 1, numSubDirs = rootSubDirs.size(); - for(TQStringList::Iterator filename = rootSubDirs.begin() ; filename != rootSubDirs.end() ; ++filename, ++currentDir) { - if(info->shouldTerminate()) break; - if(!(*filename == "." || *filename == "..")) { - info->setCurrent(0); - importDirContents(info, dir.filePath(*filename)); - info->setOverall((int) ((float) currentDir / numSubDirs * 100)); - info->setCurrent(100); - } - } - } - - info->addLog( i18n("Finished importing emails from %1").arg( mailDir )); - if (count_duplicates > 0) { - info->addLog( i18n("1 duplicate message not imported", "%n duplicate messages not imported", count_duplicates)); - } - if (info->shouldTerminate()) info->addLog( i18n("Finished import, canceled by user.")); - count_duplicates = 0; - info->setCurrent(100); - info->setOverall(100); -} - -/** - * Import of a directory contents. - * @param info Information storage for the operation. - * @param dirName The name of the directory to import. - */ -void FilterKMail_maildir::importDirContents( FilterInfo *info, const TQString& dirName) -{ - - /** Here Import all archives in the current dir */ - importFiles(info, dirName); - - /** If there are subfolders, we import them one by one */ - - TQDir subfolders(dirName); - TQStringList subDirs = subfolders.entryList("*", TQDir::Dirs | TQDir::Hidden, TQDir::Name); - for(TQStringList::Iterator filename = subDirs.begin() ; filename != subDirs.end() ; ++filename) { - if(info->shouldTerminate()) return; - if(!(*filename == "." || *filename == "..")) { - importDirContents(info, subfolders.filePath(*filename)); - } - } -} - - -/** - * Extract the X-Status flag from a mailfile - * @param info Information storage for the operation. - * @param fileName The full path to the file to import - */ -TQString FilterKMail_maildir::getMessageFlags( FilterInfo *info, const TQString& fileName ) { - - TQString status_flag = ""; - - TQFile mailfile( fileName ); - if (! mailfile.open( IO_ReadOnly ) ) { - info->alert( i18n("Unable to open %1, skipping").arg( fileName ) ); - return status_flag; - } else { - - TQByteArray input(MAX_LINE); - - while ( !mailfile.atEnd() && status_flag.isEmpty()) { - TQCString seperate; - - while ( ! mailfile.atEnd() && mailfile.readLine(input.data(),MAX_LINE) ) { - - if ((seperate = input.data()).left(10) == "X-Status: ") { - status_flag = seperate; - status_flag.remove("X-Status: "); - status_flag = status_flag.stripWhiteSpace(); - // tqDebug("status_flag: %s", status_flag.latin1() ); - break; - } - } - } - mailfile.close(); - } - return status_flag; -} - - -/** - * Import the files within a Folder. - * @param info Information storage for the operation. - * @param dirName The name of the directory to import. - */ -void FilterKMail_maildir::importFiles( FilterInfo *info, const TQString& dirName) -{ - - TQDir dir(dirName); - TQString _path; - bool generatedPath = false; - - TQDir importDir (dirName); - TQStringList files = importDir.entryList("[^\\.]*", TQDir::Files, TQDir::Name); - int currentFile = 1, numFiles = files.size(); - for ( TQStringList::Iterator mailFile = files.begin(); mailFile != files.end(); ++mailFile, ++currentFile) { - if(info->shouldTerminate()) return; - - TQString temp_mailfile = *mailFile; - - if (!(temp_mailfile.endsWith(".index") || temp_mailfile.endsWith(".index.ids") || - temp_mailfile.endsWith(".index.sorted") || temp_mailfile.endsWith(".uidcache") )) { - if(!generatedPath) { - _path = "KMail-Import"; - TQString _tmp = dir.filePath(*mailFile); - _tmp = _tmp.remove( mailDir ,TRUE); - TQStringList subFList = TQStringList::split("/",_tmp,FALSE); - for ( TQStringList::Iterator it = subFList.begin(); it != subFList.end(); ++it ) { - TQString _cat = *it; - if(!(_cat == *mailFile)) { - if(_cat.startsWith(".") && _cat.endsWith(".directory")) { - _cat.remove(0,1); - _cat.remove((_cat.length() - 10), 10); - } else if (_cat.startsWith(".")) { - _cat = _cat.remove(0 , 1); - } - _path += "/" + _cat; - } - } - if(_path.endsWith("cur")) - _path.remove(_path.length() - 4 , 4); - TQString _info = _path; - info->addLog(i18n("Import folder %1...").arg(_info.remove(0,12))); - info->setFrom(_info); - info->setTo(_path); - generatedPath = true; - } - - TQString msg_flag = getMessageFlags(info, dir.filePath(*mailFile)); - - if(info->removeDupMsg) { - if(! addMessage( info, _path, dir.filePath(*mailFile), msg_flag )) { - info->addLog( i18n("Could not import %1").arg( *mailFile ) ); - } - info->setCurrent((int) ((float) currentFile / numFiles * 100)); - } else { - if(! addMessage_fastImport( info, _path, dir.filePath(*mailFile), msg_flag )) { - info->addLog( i18n("Could not import %1").arg( *mailFile ) ); - } - info->setCurrent((int) ((float) currentFile / numFiles * 100)); - } - } - } -} - diff --git a/kmailcvt/filter_kmail_maildir.h b/kmailcvt/filter_kmail_maildir.h new file mode 100644 index 00000000..f0d8c6ac --- /dev/null +++ b/kmailcvt/filter_kmail_maildir.h @@ -0,0 +1,43 @@ +/*************************************************************************** + filter_kmail_maildir.h - Kmail maildir mail import + ------------------- + begin : April 06 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_KMAIL_MAILDIR_H +#define FILTER_KMAIL_MAILDIR_H + +#include "filters.h" + +/** + * Imports KMail mail folder with maildir format recursively, recreating the folder structure. + * @author Danny Kukawka + */ +class FilterKMail_maildir : public Filter +{ +public: + FilterKMail_maildir(void); + ~FilterKMail_maildir(void); + + void import(FilterInfo *info); + +private: + TQString mailDir; + + TQString getMessageFlags(FilterInfo*, const TQString&); + + void importDirContents(FilterInfo*, const TQString&); + void importFiles(FilterInfo*, const TQString&); +}; + +#endif diff --git a/kmailcvt/filter_kmail_maildir.hxx b/kmailcvt/filter_kmail_maildir.hxx deleted file mode 100644 index 66f44490..00000000 --- a/kmailcvt/filter_kmail_maildir.hxx +++ /dev/null @@ -1,43 +0,0 @@ -/*************************************************************************** - filter_kmail_maildir.hxx - Kmail maildir mail import - ------------------- - begin : April 06 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_KMAIL_MAILDIR_HXX -#define FILTER_KMAIL_MAILDIR_HXX - -#include "filters.hxx" - -/** - * Imports KMail mail folder with maildir format recursively, recreating the folder structure. - * @author Danny Kukawka - */ -class FilterKMail_maildir : public Filter -{ -public: - FilterKMail_maildir(void); - ~FilterKMail_maildir(void); - - void import(FilterInfo *info); - -private: - TQString mailDir; - - TQString getMessageFlags(FilterInfo*, const TQString&); - - void importDirContents(FilterInfo*, const TQString&); - void importFiles(FilterInfo*, const TQString&); -}; - -#endif diff --git a/kmailcvt/filter_lnotes.cpp b/kmailcvt/filter_lnotes.cpp new file mode 100644 index 00000000..7733c1c1 --- /dev/null +++ b/kmailcvt/filter_lnotes.cpp @@ -0,0 +1,157 @@ +/*************************************************************************** + filter_lnotes.cpp - Lotus Notes Structured Text mail import + ------------------- + begin : Wed Feb 16, 2005 + copyright : (C) 2005 by Robert Rockers + email : tdeconfigure@rockerssoft.com + ***************************************************************************/ + +/*************************************************************************** + * * + * 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 + +#include +#include +#include +#include +#include + +#include "filter_lnotes.h" + +/** Default constructor. */ +FilterLNotes::FilterLNotes() : + Filter( i18n("Import Lotus Notes Emails"), + "Robert Rockers", + i18n("

Lotus Notes Structured Text mail import filter

" + "

This filter will import Structured Text files from an exported Lotus Notes email " + "client into KMail. Use this filter if you want to import mails from Lotus or other " + "mailers that use the Lotus Notes Structured Text format.

" + "

Note: Since it is possible to recreate the folder structure, the imported " + "messages will be stored in subfolders under: \"LNotes-Import\", in your local folder, " + "named using the names of the files the messages came from.

")) +{} + +/** Destructor. */ +FilterLNotes::~FilterLNotes() { +} + +/** + * Recursive import of The Bat! maildir. + * @param info Information storage for the operation. + */ +void FilterLNotes::import(FilterInfo *info) { + + inf = info; + currentFile = 1; + totalFiles = 0; + + TQStringList filenames = KFileDialog::getOpenFileNames( TQDir::homeDirPath(), "*|" + i18n("All Files (*)"), + inf->parent() ); + totalFiles = filenames.count(); + inf->setOverall(0); + + // See filter_mbox.cpp for better reference. + for ( TQStringList::Iterator filename = filenames.begin(); filename != filenames.end(); ++filename ) { + + ++currentFile; + info->addLog( i18n("Importing emails from %1").arg(*filename) ); + ImportLNotes( *filename ); + inf->setOverall( 100 * currentFile / totalFiles ); + if ( info->shouldTerminate() ) + break; + } +} + +/** + * Import the files within a Folder. + * @param file The name of the file to import. + */ +void FilterLNotes::ImportLNotes(const TQString& file) { + + // See Filter_pmail.cpp for better reference + + // Format of a Lotus Notes 5 Structured Text Document w form feed + // Each email begins with a custom Header Principal: + // The Message ends with a 0c character + + // open the message + TQFile f(file); + + if (! f.open( IO_ReadOnly ) ) { + inf->alert( i18n("Unable to open %1, skipping").arg( file ) ); + } else { + + int ch = 0; + int state = 0; + int n = 0; + KTempFile *tempfile = 0; + + // Get folder name + TQFileInfo filenameInfo( file ); + TQString folder("LNotes-Import/" + filenameInfo.baseName(TRUE)); + inf->setTo(folder); + + // State machine to read the data in. The fgetc usage is probably terribly slow ... + while ((ch = f.getch()) >= 0) { + switch (state) { + // new message state + case 0: + // open temp output file + tempfile = new KTempFile; + state = 1; + inf->setCurrent(i18n("Message %1").arg(n++)); + if ( inf->shouldTerminate() ) + return; + // fall through + + // inside a message state + case 1: + if (ch == 0x0c) { + // close file, send it + tempfile->close(); + + if(inf->removeDupMsg) + addMessage( inf, folder, tempfile->name() ); + else + addMessage_fastImport( inf, folder, tempfile->name() ); + + tempfile->unlink(); + state = 0; + + int currentPercentage = (int) ( ( (float) f.at() / filenameInfo.size() ) * 100 ); + inf->setCurrent( currentPercentage ); + if ( inf->shouldTerminate() ) + return; + + break; + } + if (ch == 0x0d) { + break; + } + tempfile->file()->putch(ch); + break; + } + } + + // did Folder end without 0x1a at the end? + if (state != 0) { + tempfile->close(); + + if(inf->removeDupMsg) + addMessage( inf, folder, tempfile->name() ); + else + addMessage_fastImport( inf, folder, tempfile->name() ); + + tempfile->unlink(); + delete tempfile; + } + f.close(); + } +} diff --git a/kmailcvt/filter_lnotes.cxx b/kmailcvt/filter_lnotes.cxx deleted file mode 100644 index af92e1b4..00000000 --- a/kmailcvt/filter_lnotes.cxx +++ /dev/null @@ -1,157 +0,0 @@ -/*************************************************************************** - filter_lnotes.cxx - Lotus Notes Structured Text mail import - ------------------- - begin : Wed Feb 16, 2005 - copyright : (C) 2005 by Robert Rockers - email : tdeconfigure@rockerssoft.com - ***************************************************************************/ - -/*************************************************************************** - * * - * 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 - -#include -#include -#include -#include -#include - -#include "filter_lnotes.hxx" - -/** Default constructor. */ -FilterLNotes::FilterLNotes() : - Filter( i18n("Import Lotus Notes Emails"), - "Robert Rockers", - i18n("

Lotus Notes Structured Text mail import filter

" - "

This filter will import Structured Text files from an exported Lotus Notes email " - "client into KMail. Use this filter if you want to import mails from Lotus or other " - "mailers that use the Lotus Notes Structured Text format.

" - "

Note: Since it is possible to recreate the folder structure, the imported " - "messages will be stored in subfolders under: \"LNotes-Import\", in your local folder, " - "named using the names of the files the messages came from.

")) -{} - -/** Destructor. */ -FilterLNotes::~FilterLNotes() { -} - -/** - * Recursive import of The Bat! maildir. - * @param info Information storage for the operation. - */ -void FilterLNotes::import(FilterInfo *info) { - - inf = info; - currentFile = 1; - totalFiles = 0; - - TQStringList filenames = KFileDialog::getOpenFileNames( TQDir::homeDirPath(), "*|" + i18n("All Files (*)"), - inf->parent() ); - totalFiles = filenames.count(); - inf->setOverall(0); - - // See filter_mbox.cxx for better reference. - for ( TQStringList::Iterator filename = filenames.begin(); filename != filenames.end(); ++filename ) { - - ++currentFile; - info->addLog( i18n("Importing emails from %1").arg(*filename) ); - ImportLNotes( *filename ); - inf->setOverall( 100 * currentFile / totalFiles ); - if ( info->shouldTerminate() ) - break; - } -} - -/** - * Import the files within a Folder. - * @param file The name of the file to import. - */ -void FilterLNotes::ImportLNotes(const TQString& file) { - - // See Filter_pmail.cxx for better reference - - // Format of a Lotus Notes 5 Structured Text Document w form feed - // Each email begins with a custom Header Principal: - // The Message ends with a 0c character - - // open the message - TQFile f(file); - - if (! f.open( IO_ReadOnly ) ) { - inf->alert( i18n("Unable to open %1, skipping").arg( file ) ); - } else { - - int ch = 0; - int state = 0; - int n = 0; - KTempFile *tempfile = 0; - - // Get folder name - TQFileInfo filenameInfo( file ); - TQString folder("LNotes-Import/" + filenameInfo.baseName(TRUE)); - inf->setTo(folder); - - // State machine to read the data in. The fgetc usage is probably terribly slow ... - while ((ch = f.getch()) >= 0) { - switch (state) { - // new message state - case 0: - // open temp output file - tempfile = new KTempFile; - state = 1; - inf->setCurrent(i18n("Message %1").arg(n++)); - if ( inf->shouldTerminate() ) - return; - // fall through - - // inside a message state - case 1: - if (ch == 0x0c) { - // close file, send it - tempfile->close(); - - if(inf->removeDupMsg) - addMessage( inf, folder, tempfile->name() ); - else - addMessage_fastImport( inf, folder, tempfile->name() ); - - tempfile->unlink(); - state = 0; - - int currentPercentage = (int) ( ( (float) f.at() / filenameInfo.size() ) * 100 ); - inf->setCurrent( currentPercentage ); - if ( inf->shouldTerminate() ) - return; - - break; - } - if (ch == 0x0d) { - break; - } - tempfile->file()->putch(ch); - break; - } - } - - // did Folder end without 0x1a at the end? - if (state != 0) { - tempfile->close(); - - if(inf->removeDupMsg) - addMessage( inf, folder, tempfile->name() ); - else - addMessage_fastImport( inf, folder, tempfile->name() ); - - tempfile->unlink(); - delete tempfile; - } - f.close(); - } -} diff --git a/kmailcvt/filter_lnotes.h b/kmailcvt/filter_lnotes.h new file mode 100644 index 00000000..bf5cd91c --- /dev/null +++ b/kmailcvt/filter_lnotes.h @@ -0,0 +1,53 @@ +/*************************************************************************** + filter_lnotes.h - Lotus Notes Structured Text mail import + ------------------- + begin : Wed Feb 16, 2005 + copyright : (C) 2005 by Robert Rockers + email : tdeconfigure@rockerssoft.com + ***************************************************************************/ + +/*************************************************************************** + * * + * 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_LNOTES_H +#define FILTER_LNOTES_H + +#include "filters.h" + +/**imports Lotus Notes Structured Text Archives and archvies messages into KMail + *@author Robert Rockers + */ + +class FilterLNotes : public Filter { + +public: + FilterLNotes(); + ~FilterLNotes(); + /** Standard import filter... starting line for our import */ + void import(FilterInfo *info); + +private: + /** the working directory */ + TQDir dir; + /** Our Filterinfo stuff... important methods for getting the email imported */ + FilterInfo * inf; + /** which file (of totalFiles) is now in the work? */ + int currentFile; + /** total number of files that get imported */ + int totalFiles; + + /** + * This is were all the real action is gonna be handled. + * Gets called once for EACH file imported + */ + void ImportLNotes(const TQString& file); + +}; + +#endif diff --git a/kmailcvt/filter_lnotes.hxx b/kmailcvt/filter_lnotes.hxx deleted file mode 100644 index 430ae83e..00000000 --- a/kmailcvt/filter_lnotes.hxx +++ /dev/null @@ -1,53 +0,0 @@ -/*************************************************************************** - filter_lnotes.hxx - Lotus Notes Structured Text mail import - ------------------- - begin : Wed Feb 16, 2005 - copyright : (C) 2005 by Robert Rockers - email : tdeconfigure@rockerssoft.com - ***************************************************************************/ - -/*************************************************************************** - * * - * 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_LNOTES_HXX -#define FILTER_LNOTES_HXX - -#include "filters.hxx" - -/**imports Lotus Notes Structured Text Archives and archvies messages into KMail - *@author Robert Rockers - */ - -class FilterLNotes : public Filter { - -public: - FilterLNotes(); - ~FilterLNotes(); - /** Standard import filter... starting line for our import */ - void import(FilterInfo *info); - -private: - /** the working directory */ - TQDir dir; - /** Our Filterinfo stuff... important methods for getting the email imported */ - FilterInfo * inf; - /** which file (of totalFiles) is now in the work? */ - int currentFile; - /** total number of files that get imported */ - int totalFiles; - - /** - * This is were all the real action is gonna be handled. - * Gets called once for EACH file imported - */ - void ImportLNotes(const TQString& file); - -}; - -#endif diff --git a/kmailcvt/filter_mailapp.cpp b/kmailcvt/filter_mailapp.cpp new file mode 100644 index 00000000..1da632ec --- /dev/null +++ b/kmailcvt/filter_mailapp.cpp @@ -0,0 +1,168 @@ +/*************************************************************************** + filter_mailapp.cpp - OS X Mail App import + ------------------- + copyright : (C) 2004 by Chris Howells + email : howells@kde.org + + Derived from code by: + copyright : (C) 2003 by Laurence Anderson + email : l.d.anderson@warwick.ac.uk + + ***************************************************************************/ + +/*************************************************************************** + * * + * 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 +#include +#include +#include +#include + +#include "filter_mailapp.h" + +FilterMailApp::FilterMailApp() : + Filter( i18n("Import From OS X Mail"), + "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.

")) +{} + +FilterMailApp::~FilterMailApp() +{ +} + +void FilterMailApp::import(FilterInfo *info) +{ + int currentFile = 1; + int overall_status = 0; + bool first_msg = true; + + TQString directory = KFileDialog::getExistingDirectory( TQDir::homeDirPath(), info->parent() ); + + //tqDebug("starting by looking in directory: %s", directory.latin1()); + if ( directory.isEmpty() ) { + info->addLog( i18n("No directory selected.")); + info->addLog( i18n("No files found for import.")); + } else { + info->setOverall(0); + traverseDirectory(info, directory); + + for ( TQStringList::Iterator filename = mMboxFiles.begin(); filename != mMboxFiles.end(); ++filename, ++currentFile) { + if ( info->shouldTerminate() ) break; + TQFile mbox( *filename ); + if (! mbox.open( IO_ReadOnly ) ) { + info->alert( i18n("Unable to open %1, skipping").arg( *filename ) ); + } else { + TQFileInfo filenameInfo( *filename ); + kdDebug() << "importing filename " << *filename << endl; + TQStringList name = TQStringList::split("/", *filename); + TQString folderName(name[name.count() - 2]); + + info->setCurrent(0); + info->addLog( i18n("Importing emails from %1...").arg( *filename ) ); + info->setFrom( *filename ); + info->setTo( folderName ); + + TQByteArray input(MAX_LINE); + long l = 0; + + while ( ! mbox.atEnd() ) { + KTempFile tmp; + /* comment by Danny: + * Don't use TQTextStream to read from mbox, etter use TQDataStream. TQTextStream only + * support Unicode/Latin1/Locale. So you lost information from emails with + * charset!=Unicode/Latin1/Locale (e.g. KOI8-R) and Content-Transfer-Encoding != base64 + * (e.g. 8Bit). It also not help to convert the TQTextStream to Unicode. By this you + * get Unicode/UTF-email but KMail can't detect the correct charset. + */ + TQCString seperate; + + if(!first_msg) + tmp.file()->writeBlock( input, l ); + l = mbox.readLine( input.data(),MAX_LINE); // read the first line, prevent "From " + tmp.file()->writeBlock( input, l ); + + while ( ! mbox.atEnd() && (l = mbox.readLine(input.data(),MAX_LINE)) && ((seperate = input.data()).left(5) != "From ")) { + tmp.file()->writeBlock( input, l ); + } + tmp.close(); + first_msg = false; + + // force stop if user chancel the import + if ( info->shouldTerminate() ) { + tmp.unlink(); + break; + } + + /* 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/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() ) break; + } + + info->addLog( i18n("Finished importing emails from %1").arg( *filename ) ); + if (count_duplicates > 0) { + info->addLog( i18n("1 duplicate message not imported to folder %1 in KMail", + "%n duplicate messages not imported to folder %1 in KMail", count_duplicates).arg(folderName)); + } + count_duplicates = 0; + mbox.close(); + } + } + } + + if (info->shouldTerminate()) info->addLog( i18n("Finished import, canceled by user.")); + info->setCurrent(100); + info->setOverall(100); +} + +void FilterMailApp::traverseDirectory(FilterInfo *info, const TQString &dirName) +{ + TQDir dir(dirName); + dir.setFilter(TQDir::Dirs | TQDir::Files); + + const TQFileInfoList *fileinfolist = dir.entryInfoList(); + TQFileInfoListIterator it(*fileinfolist); + TQFileInfo *fi; + + if ( info->shouldTerminate() ) return; + + while ((fi = it.current())) { + if (fi->fileName() == "." || fi->fileName() == "..") { + ++it; + continue; + } + if (fi->isDir() && fi->isReadable()) { + traverseDirectory(info, fi->filePath()); + } else { + if (!fi->isDir() && fi->fileName() == "mbox") { + kdDebug() << "adding the file " << fi->filePath() << endl; + mMboxFiles.append(fi->filePath()); + } + } + ++it; + } +} diff --git a/kmailcvt/filter_mailapp.cxx b/kmailcvt/filter_mailapp.cxx deleted file mode 100644 index fded411d..00000000 --- a/kmailcvt/filter_mailapp.cxx +++ /dev/null @@ -1,168 +0,0 @@ -/*************************************************************************** - filter_mailapp.cxx - OS X Mail App import - ------------------- - copyright : (C) 2004 by Chris Howells - email : howells@kde.org - - Derived from code by: - copyright : (C) 2003 by Laurence Anderson - email : l.d.anderson@warwick.ac.uk - - ***************************************************************************/ - -/*************************************************************************** - * * - * 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 -#include -#include -#include -#include - -#include "filter_mailapp.hxx" - -FilterMailApp::FilterMailApp() : - Filter( i18n("Import From OS X Mail"), - "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.

")) -{} - -FilterMailApp::~FilterMailApp() -{ -} - -void FilterMailApp::import(FilterInfo *info) -{ - int currentFile = 1; - int overall_status = 0; - bool first_msg = true; - - TQString directory = KFileDialog::getExistingDirectory( TQDir::homeDirPath(), info->parent() ); - - //tqDebug("starting by looking in directory: %s", directory.latin1()); - if ( directory.isEmpty() ) { - info->addLog( i18n("No directory selected.")); - info->addLog( i18n("No files found for import.")); - } else { - info->setOverall(0); - traverseDirectory(info, directory); - - for ( TQStringList::Iterator filename = mMboxFiles.begin(); filename != mMboxFiles.end(); ++filename, ++currentFile) { - if ( info->shouldTerminate() ) break; - TQFile mbox( *filename ); - if (! mbox.open( IO_ReadOnly ) ) { - info->alert( i18n("Unable to open %1, skipping").arg( *filename ) ); - } else { - TQFileInfo filenameInfo( *filename ); - kdDebug() << "importing filename " << *filename << endl; - TQStringList name = TQStringList::split("/", *filename); - TQString folderName(name[name.count() - 2]); - - info->setCurrent(0); - info->addLog( i18n("Importing emails from %1...").arg( *filename ) ); - info->setFrom( *filename ); - info->setTo( folderName ); - - TQByteArray input(MAX_LINE); - long l = 0; - - while ( ! mbox.atEnd() ) { - KTempFile tmp; - /* comment by Danny: - * Don't use TQTextStream to read from mbox, etter use TQDataStream. TQTextStream only - * support Unicode/Latin1/Locale. So you lost information from emails with - * charset!=Unicode/Latin1/Locale (e.g. KOI8-R) and Content-Transfer-Encoding != base64 - * (e.g. 8Bit). It also not help to convert the TQTextStream to Unicode. By this you - * get Unicode/UTF-email but KMail can't detect the correct charset. - */ - TQCString seperate; - - if(!first_msg) - tmp.file()->writeBlock( input, l ); - l = mbox.readLine( input.data(),MAX_LINE); // read the first line, prevent "From " - tmp.file()->writeBlock( input, l ); - - while ( ! mbox.atEnd() && (l = mbox.readLine(input.data(),MAX_LINE)) && ((seperate = input.data()).left(5) != "From ")) { - tmp.file()->writeBlock( input, l ); - } - tmp.close(); - first_msg = false; - - // force stop if user chancel the import - if ( info->shouldTerminate() ) { - tmp.unlink(); - break; - } - - /* 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/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() ) break; - } - - info->addLog( i18n("Finished importing emails from %1").arg( *filename ) ); - if (count_duplicates > 0) { - info->addLog( i18n("1 duplicate message not imported to folder %1 in KMail", - "%n duplicate messages not imported to folder %1 in KMail", count_duplicates).arg(folderName)); - } - count_duplicates = 0; - mbox.close(); - } - } - } - - if (info->shouldTerminate()) info->addLog( i18n("Finished import, canceled by user.")); - info->setCurrent(100); - info->setOverall(100); -} - -void FilterMailApp::traverseDirectory(FilterInfo *info, const TQString &dirName) -{ - TQDir dir(dirName); - dir.setFilter(TQDir::Dirs | TQDir::Files); - - const TQFileInfoList *fileinfolist = dir.entryInfoList(); - TQFileInfoListIterator it(*fileinfolist); - TQFileInfo *fi; - - if ( info->shouldTerminate() ) return; - - while ((fi = it.current())) { - if (fi->fileName() == "." || fi->fileName() == "..") { - ++it; - continue; - } - if (fi->isDir() && fi->isReadable()) { - traverseDirectory(info, fi->filePath()); - } else { - if (!fi->isDir() && fi->fileName() == "mbox") { - kdDebug() << "adding the file " << fi->filePath() << endl; - mMboxFiles.append(fi->filePath()); - } - } - ++it; - } -} diff --git a/kmailcvt/filter_mailapp.h b/kmailcvt/filter_mailapp.h new file mode 100644 index 00000000..e562dbf7 --- /dev/null +++ b/kmailcvt/filter_mailapp.h @@ -0,0 +1,36 @@ +/*************************************************************************** + filter_mailapp.h - OS X Mail App import + ------------------- + copyright : (C) 2004 by Chris Howells + email : howells@kde.org + + Derived from code by: + copyright : (C) 2003 by Laurence Anderson + email : l.d.anderson@warwick.ac.uk + + ***************************************************************************/ + +#ifndef FILTER_MAILAPP_H +#define FILTER_MAILAPP_H + +#include "filters.h" + +/** + *imports mbox archives messages into KMail + *@author Chris Howells + */ + +class FilterMailApp : public Filter +{ +public: + FilterMailApp(); + ~FilterMailApp(); + + void import(FilterInfo *info); + +private: + TQStringList mMboxFiles; + void traverseDirectory(FilterInfo *info, const TQString &); +}; + +#endif diff --git a/kmailcvt/filter_mailapp.hxx b/kmailcvt/filter_mailapp.hxx deleted file mode 100644 index 571f77ff..00000000 --- a/kmailcvt/filter_mailapp.hxx +++ /dev/null @@ -1,36 +0,0 @@ -/*************************************************************************** - filter_mailapp.hxx - OS X Mail App import - ------------------- - copyright : (C) 2004 by Chris Howells - email : howells@kde.org - - Derived from code by: - copyright : (C) 2003 by Laurence Anderson - email : l.d.anderson@warwick.ac.uk - - ***************************************************************************/ - -#ifndef FILTER_MAILAPP_HXX -#define FILTER_MAILAPP_HXX - -#include "filters.hxx" - -/** - *imports mbox archives messages into KMail - *@author Chris Howells - */ - -class FilterMailApp : public Filter -{ -public: - FilterMailApp(); - ~FilterMailApp(); - - void import(FilterInfo *info); - -private: - TQStringList mMboxFiles; - void traverseDirectory(FilterInfo *info, const TQString &); -}; - -#endif diff --git a/kmailcvt/filter_mbox.cpp b/kmailcvt/filter_mbox.cpp new file mode 100644 index 00000000..c5f87e51 --- /dev/null +++ b/kmailcvt/filter_mbox.cpp @@ -0,0 +1,144 @@ +/*************************************************************************** + filter_mbox.cpp - mbox mail import + ------------------- + begin : Sat Apr 5 2003 + copyright : (C) 2003 by Laurence Anderson + email : l.d.anderson@warwick.ac.uk + ***************************************************************************/ + +/*************************************************************************** + * * + * 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 +#include +#include +#include +#include + +#include "filter_mbox.h" + + +FilterMBox::FilterMBox() : + Filter( i18n("Import mbox Files (UNIX, Evolution)"), + "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.

" + "

Note: Emails will be imported into folders named after the " + "file they came from, prefixed with MBOX-

" )) +{} + +FilterMBox::~FilterMBox() +{ +} + +void FilterMBox::import(FilterInfo *info) +{ + int currentFile = 1; + int overall_status = 0; + bool first_msg = true; + + TQStringList filenames = KFileDialog::getOpenFileNames( TQDir::homeDirPath(), "*|" + i18n("mbox Files (*)"), info->parent() ); + info->setOverall(0); + + for ( TQStringList::Iterator filename = filenames.begin(); filename != filenames.end(); ++filename, ++currentFile) { + TQFile mbox( *filename ); + if (! mbox.open( IO_ReadOnly ) ) { + info->alert( i18n("Unable to open %1, skipping").arg( *filename ) ); + } else { + TQFileInfo filenameInfo( *filename ); + TQString folderName( "MBOX-" + filenameInfo.baseName(TRUE) ); + + info->setCurrent(0); + info->addLog( i18n("Importing emails from %1...").arg( *filename ) ); + + info->setFrom( *filename ); + info->setTo( folderName ); + + TQByteArray input(MAX_LINE); + long l = 0; + + while ( ! mbox.atEnd() ) { + KTempFile tmp; + TQIODevice::Offset filepos = 0; + /* comment by Danny: + * Don't use TQTextStream to read from mbox, better use TQDataStream. TQTextStream only + * support Unicode/Latin1/Locale. So you lost information from emails with + * charset!=Unicode/Latin1/Locale (e.g. KOI8-R) and Content-Transfer-Encoding != base64 + * (e.g. 8Bit). It also not help to convert the TQTextStream to Unicode. By this you + * get Unicode/UTF-email but KMail can't detect the correct charset. + */ + TQCString seperate; + TQString x_status_flag = ""; + + /* check if the first line start with "From " (and not "From: ") and discard the line + * in this case because some IMAP servers (e.g. Cyrus) don't accept this header line */ + if(!first_msg && ((seperate = input.data()).left(5) != "From ")) + tmp.file()->writeBlock( input, l ); + + l = mbox.readLine( input.data(),MAX_LINE); // read the first line, prevent "From " + + if ((seperate = input.data()).left(5) != "From ") + tmp.file()->writeBlock( input, l ); + + while ( ! mbox.atEnd() && (l = mbox.readLine(input.data(),MAX_LINE)) && ((seperate = input.data()).left(5) != "From ")) { + tmp.file()->writeBlock( input, l ); + + if ((seperate = input.data()).left(10) == "X-Status: ") { + x_status_flag = seperate; + x_status_flag.remove("X-Status: "); + x_status_flag = x_status_flag.stripWhiteSpace(); + // tqDebug("x_status_flag: %s", x_status_flag.latin1() ); + } + + // workaround to fix hang if a corrupted mbox contains some + // binary data, for more see bug #106796 + if (mbox.at() == filepos) + mbox.at(mbox.size()); + else + filepos = mbox.at(); + } + tmp.close(); + first_msg = false; + + /* 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(), x_status_flag ); + else + addMessage_fastImport( info, folderName, tmp.name(), x_status_flag ); + + 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() ) break; + } + + info->addLog( i18n("Finished importing emails from %1").arg( *filename )); + if (count_duplicates > 0) { + info->addLog( i18n("1 duplicate message not imported to folder %1 in KMail", + "%n duplicate messages not imported to folder %1 in KMail", + count_duplicates).arg(folderName)); + } + if (info->shouldTerminate()) info->addLog( i18n("Finished import, canceled by user.")); + count_duplicates = 0; + // don't forget to close the file !!! + mbox.close(); + } + } +} diff --git a/kmailcvt/filter_mbox.cxx b/kmailcvt/filter_mbox.cxx deleted file mode 100644 index 19afccf2..00000000 --- a/kmailcvt/filter_mbox.cxx +++ /dev/null @@ -1,144 +0,0 @@ -/*************************************************************************** - filter_mbox.cxx - mbox mail import - ------------------- - begin : Sat Apr 5 2003 - copyright : (C) 2003 by Laurence Anderson - email : l.d.anderson@warwick.ac.uk - ***************************************************************************/ - -/*************************************************************************** - * * - * 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 -#include -#include -#include -#include - -#include "filter_mbox.hxx" - - -FilterMBox::FilterMBox() : - Filter( i18n("Import mbox Files (UNIX, Evolution)"), - "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.

" - "

Note: Emails will be imported into folders named after the " - "file they came from, prefixed with MBOX-

" )) -{} - -FilterMBox::~FilterMBox() -{ -} - -void FilterMBox::import(FilterInfo *info) -{ - int currentFile = 1; - int overall_status = 0; - bool first_msg = true; - - TQStringList filenames = KFileDialog::getOpenFileNames( TQDir::homeDirPath(), "*|" + i18n("mbox Files (*)"), info->parent() ); - info->setOverall(0); - - for ( TQStringList::Iterator filename = filenames.begin(); filename != filenames.end(); ++filename, ++currentFile) { - TQFile mbox( *filename ); - if (! mbox.open( IO_ReadOnly ) ) { - info->alert( i18n("Unable to open %1, skipping").arg( *filename ) ); - } else { - TQFileInfo filenameInfo( *filename ); - TQString folderName( "MBOX-" + filenameInfo.baseName(TRUE) ); - - info->setCurrent(0); - info->addLog( i18n("Importing emails from %1...").arg( *filename ) ); - - info->setFrom( *filename ); - info->setTo( folderName ); - - TQByteArray input(MAX_LINE); - long l = 0; - - while ( ! mbox.atEnd() ) { - KTempFile tmp; - TQIODevice::Offset filepos = 0; - /* comment by Danny: - * Don't use TQTextStream to read from mbox, better use TQDataStream. TQTextStream only - * support Unicode/Latin1/Locale. So you lost information from emails with - * charset!=Unicode/Latin1/Locale (e.g. KOI8-R) and Content-Transfer-Encoding != base64 - * (e.g. 8Bit). It also not help to convert the TQTextStream to Unicode. By this you - * get Unicode/UTF-email but KMail can't detect the correct charset. - */ - TQCString seperate; - TQString x_status_flag = ""; - - /* check if the first line start with "From " (and not "From: ") and discard the line - * in this case because some IMAP servers (e.g. Cyrus) don't accept this header line */ - if(!first_msg && ((seperate = input.data()).left(5) != "From ")) - tmp.file()->writeBlock( input, l ); - - l = mbox.readLine( input.data(),MAX_LINE); // read the first line, prevent "From " - - if ((seperate = input.data()).left(5) != "From ") - tmp.file()->writeBlock( input, l ); - - while ( ! mbox.atEnd() && (l = mbox.readLine(input.data(),MAX_LINE)) && ((seperate = input.data()).left(5) != "From ")) { - tmp.file()->writeBlock( input, l ); - - if ((seperate = input.data()).left(10) == "X-Status: ") { - x_status_flag = seperate; - x_status_flag.remove("X-Status: "); - x_status_flag = x_status_flag.stripWhiteSpace(); - // tqDebug("x_status_flag: %s", x_status_flag.latin1() ); - } - - // workaround to fix hang if a corrupted mbox contains some - // binary data, for more see bug #106796 - if (mbox.at() == filepos) - mbox.at(mbox.size()); - else - filepos = mbox.at(); - } - tmp.close(); - first_msg = false; - - /* 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(), x_status_flag ); - else - addMessage_fastImport( info, folderName, tmp.name(), x_status_flag ); - - 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() ) break; - } - - info->addLog( i18n("Finished importing emails from %1").arg( *filename )); - if (count_duplicates > 0) { - info->addLog( i18n("1 duplicate message not imported to folder %1 in KMail", - "%n duplicate messages not imported to folder %1 in KMail", - count_duplicates).arg(folderName)); - } - if (info->shouldTerminate()) info->addLog( i18n("Finished import, canceled by user.")); - count_duplicates = 0; - // don't forget to close the file !!! - mbox.close(); - } - } -} diff --git a/kmailcvt/filter_mbox.h b/kmailcvt/filter_mbox.h new file mode 100644 index 00000000..f1f376de --- /dev/null +++ b/kmailcvt/filter_mbox.h @@ -0,0 +1,37 @@ +/*************************************************************************** + filter_mbox.h - mbox mail import + ------------------- + begin : Sat Apr 5 2003 + copyright : (C) 2003 by Laurence Anderson + email : l.d.anderson@warwick.ac.uk + ***************************************************************************/ + +/*************************************************************************** + * * + * 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_MBOX_H +#define FILTER_MBOX_H + +#include "filters.h" + +/** + * imports mbox archives messages into KMail + * @author Laurence Anderson + */ + +class FilterMBox : public Filter +{ +public: + FilterMBox(); + ~FilterMBox(); + + void import(FilterInfo *info); +}; + +#endif diff --git a/kmailcvt/filter_mbox.hxx b/kmailcvt/filter_mbox.hxx deleted file mode 100644 index e1c5e967..00000000 --- a/kmailcvt/filter_mbox.hxx +++ /dev/null @@ -1,37 +0,0 @@ -/*************************************************************************** - filter_mbox.hxx - mbox mail import - ------------------- - begin : Sat Apr 5 2003 - copyright : (C) 2003 by Laurence Anderson - email : l.d.anderson@warwick.ac.uk - ***************************************************************************/ - -/*************************************************************************** - * * - * 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_MBOX_HXX -#define FILTER_MBOX_HXX - -#include "filters.hxx" - -/** - * imports mbox archives messages into KMail - * @author Laurence Anderson - */ - -class FilterMBox : public Filter -{ -public: - FilterMBox(); - ~FilterMBox(); - - void import(FilterInfo *info); -}; - -#endif diff --git a/kmailcvt/filter_oe.cpp b/kmailcvt/filter_oe.cpp new file mode 100644 index 00000000..47002d96 --- /dev/null +++ b/kmailcvt/filter_oe.cpp @@ -0,0 +1,429 @@ +/*************************************************************************** + filter_oe.cpp - Outlook Express mail import + ------------------- + begin : Sat Feb 1 2003 + copyright : (C) 2003 by Laurence Anderson + (C) 2005 by Danny Kukawka + email : l.d.anderson@warwick.ac.uk + 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. * + * * + ***************************************************************************/ + +// This filter was created by looking at libdbx & liboe + +#include +#include +#include +#include +#include + +#include "filter_oe.h" + +#define OE4_SIG_1 0x36464d4a +#define OE4_SIG_2 0x00010003 +#define OE5_SIG_1 0xfe12adcf +#define OE5_EMAIL_SIG_2 0x6f74fdc5 +#define OE5_FOLDER_SIG_2 0x6f74fdc6 +#define OE5_SIG_3 0x11d1e366 +#define OE5_SIG_4 0xc0004e9a +#define MBX_MAILMAGIC 0x7F007F00 + +FilterOE::FilterOE() : + Filter( i18n("Import Outlook Express Emails"), + "Laurence Anderson
( Filter enhanced 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 " + "

  • C:\\Windows\\Application Data in Windows 9x" + "
  • Documents and Settings in Windows 2000 or later

" + "

Note: Since it is possible to recreate the folder structure, the folders from " + "Outlook Express 5 and 6 will be stored under: \"OE-Import\" in your local folder.

" )) +{} + +FilterOE::~FilterOE() +{ +} + +void FilterOE::import(FilterInfo *info) +{ + // Select directory containing plain text emails + mailDir = KFileDialog::getExistingDirectory(TQDir::homeDirPath(),info->parent()); + if (mailDir.isEmpty()) { // No directory selected + info->alert(i18n("No directory selected.")); + return; + } + + TQDir dir (mailDir); + TQStringList files = dir.entryList("*.[dDmM][bB][xX]", TQDir::Files, TQDir::Name); + if (files.isEmpty()) { + info->alert(i18n("No Outlook Express mailboxes found in directory %1.").arg(mailDir)); + return; + } + + totalFiles = files.count(); + currentFile = 0; + count0x04 = 0; + count0x84 = 0; + parsedFolder = false; + + info->setOverall(0); + + /** search the folderfile to recreate folder struct */ + for ( TQStringList::Iterator mailFile = files.begin(); mailFile != files.end(); ++mailFile ) { + if(*mailFile == "Folders.dbx") { + info->addLog(i18n("Import folder structure...")); + importMailBox(info, dir.filePath(*mailFile)); + if(!folderStructure.isEmpty()) parsedFolder = true; + // remove file from TQStringList::files, no longer needed + files.remove(mailFile); + currentIsFolderFile = false; + break; + } + } + + int n=0; + for ( TQStringList::Iterator mailFile = files.begin(); mailFile != files.end(); ++mailFile ) { + if ( info->shouldTerminate() ) break; + importMailBox(info, dir.filePath(*mailFile)); + info->setOverall(100 * ++n / files.count()); + } + + info->setOverall(100); + info->setCurrent(100); + info->addLog(i18n("Finished importing Outlook Express emails")); + if (info->shouldTerminate()) info->addLog( i18n("Finished import, canceled by user.")); + + kdDebug() << "\n" << "total emails in current file: " << totalEmails << endl; + kdDebug() << "0x84 Mails: " << count0x84 << endl; + kdDebug() << "0x04 Mails: " << count0x04 << endl; +} + +void FilterOE::importMailBox( FilterInfo *info, const TQString& fileName) +{ + TQFile mailfile(fileName); + TQFileInfo mailfileinfo(fileName); + TQString _nameOfFile = fileName; + _nameOfFile.remove( mailDir ); + _nameOfFile.remove( "/" ); + info->setFrom(mailfileinfo.fileName()); + + if (!mailfile.open(IO_ReadOnly)) { + info->addLog(i18n("Unable to open mailbox %1").arg(fileName)); + return; + } + TQDataStream mailbox(&mailfile); + mailbox.setByteOrder(TQDataStream::LittleEndian); + + // Parse magic + TQ_UINT32 sig_block1, sig_block2; + mailbox >> sig_block1 >> sig_block2; + if (sig_block1 == OE4_SIG_1 && sig_block2 == OE4_SIG_2) { + folderName = "OE-Import/" + mailfileinfo.baseName(TRUE); + info->addLog(i18n("Importing OE4 Mailbox %1").arg( "../" + _nameOfFile)); + info->setTo(folderName); + mbxImport(info, mailbox); + return; + } else { + TQ_UINT32 sig_block3, sig_block4; + mailbox >> sig_block3 >> sig_block4; + if (sig_block1 == OE5_SIG_1 && sig_block3 == OE5_SIG_3 && sig_block4 == OE5_SIG_4) { + if (sig_block2 == OE5_EMAIL_SIG_2) { + folderName = "OE-Import/" + mailfileinfo.baseName(TRUE); + if(parsedFolder) { + TQString _tmpFolder = getFolderName(_nameOfFile); + if(!_tmpFolder.isEmpty()) folderName = "OE-Import/" + _tmpFolder; + } + info->addLog(i18n("Importing OE5+ Mailbox %1").arg( "../" + _nameOfFile)); + info->setTo(folderName); + dbxImport(info, mailbox); + return; + } else if (sig_block2 == OE5_FOLDER_SIG_2) { + if(!parsedFolder) { + info->addLog(i18n("Importing OE5+ Folder file %1").arg( "../" + _nameOfFile)); + currentIsFolderFile = true; + dbxImport(info, mailbox); + currentIsFolderFile = false; + } + return; + } + } + } + // info->addLog(i18n("File %1 does not seem to be an Outlook Express mailbox").arg("../" + _nameOfFile)); +} + +/* ------------------- MBX support ------------------- */ + +void FilterOE::mbxImport( FilterInfo *info, TQDataStream& ds) +{ + TQ_UINT32 msgCount, lastMsgNum, fileSize; + + // Read the header + ds >> msgCount >> lastMsgNum >> fileSize; + ds.device()->at( ds.device()->at() + 64 ); // Skip 0's + kdDebug() << "This mailbox has " << msgCount << " messages" << endl; + if (msgCount == 0) + return; // Don't import empty mailbox + + TQ_UINT32 msgMagic; + ds >> msgMagic; // Read first magic + + while (!ds.atEnd()) { + TQ_UINT32 msgNumber, msgSize, msgTextSize; + KTempFile tmp; + tmp.dataStream()->setByteOrder(TQDataStream::LittleEndian); + + // Read the messages + ds >> msgNumber >> msgSize >> msgTextSize; // All seem to be lies...? + + do { + ds >> msgMagic; + if (msgMagic != MBX_MAILMAGIC) + *tmp.dataStream() << msgMagic; + else + break; + } while ( !ds.atEnd() ); + + 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(); + if(info->shouldTerminate()) return; + } +} + +/* ------------------- DBX support ------------------- */ + +void FilterOE::dbxImport( FilterInfo *info, TQDataStream& ds) +{ + // Get item count & offset of index + TQ_UINT32 itemCount, indexPtr; + ds.device()->at(0xc4); + ds >> itemCount; + ds.device()->at(0xe4); + ds >> indexPtr; + kdDebug() << "Item count is " << itemCount << ", Index at " << indexPtr << endl; + + if (itemCount == 0) + return; // Empty file + totalEmails = itemCount; + currentEmail = 0; + // Parse the indexes + ds.device()->at(indexPtr); + dbxReadIndex(info, ds, indexPtr); +} + +void FilterOE::dbxReadIndex( FilterInfo *info, TQDataStream& ds, int filePos) +{ + + if(info->shouldTerminate()) return; + TQ_UINT32 self, unknown, nextIndexPtr, parent, indexCount; + TQ_UINT8 unknown2, ptrCount; + TQ_UINT16 unknown3; + int wasAt = ds.device()->at(); + ds.device()->at(filePos); + + + kdDebug() << "Reading index of file " << folderName << endl; + ds >> self >> unknown >> nextIndexPtr >> parent >> unknown2 >> ptrCount >> unknown3 >> indexCount; // _dbx_tableindexstruct + + kdDebug() << "This index has " << (int) ptrCount << " data pointers" << endl; + for (int count = 0; count < ptrCount; count++) { + if(info->shouldTerminate()) return; + TQ_UINT32 dataIndexPtr, anotherIndexPtr, anotherIndexCount; // _dbx_indexstruct + ds >> dataIndexPtr >> anotherIndexPtr >> anotherIndexCount; + + if (anotherIndexCount > 0) { + kdDebug() << "Recursing to another table @ " << anotherIndexPtr << endl; + dbxReadIndex(info, ds, anotherIndexPtr); + } + kdDebug() << "Data index @ " << dataIndexPtr << endl; + dbxReadDataBlock(info, ds, dataIndexPtr); + } + + if (indexCount > 0) { // deal with nextTablePtr + kdDebug() << "Recuring to next table @ " << nextIndexPtr << endl; + dbxReadIndex(info, ds, nextIndexPtr); + } + + ds.device()->at(wasAt); // Restore file position to same as when function called +} + +void FilterOE::dbxReadDataBlock( FilterInfo *info, TQDataStream& ds, int filePos) +{ + TQ_UINT32 curOffset, blockSize; + TQ_UINT16 unknown; + TQ_UINT8 count, unknown2; + int wasAt = ds.device()->at(); + + TQString folderEntry[4]; + + ds.device()->at(filePos); + + ds >> curOffset >> blockSize >> unknown >> count >> unknown2; // _dbx_email_headerstruct + kdDebug() << "Data block has " << (int) count << " elements" << endl; + + for (int c = 0; c < count; c++) { + if(info->shouldTerminate()) return; + TQ_UINT8 type; // _dbx_email_pointerstruct + TQ_UINT32 value; // Actually 24 bit + + ds >> type >> value; + value &= 0xffffff; + ds.device()->at(ds.device()->at() - 1); // We only wanted 3 bytes + + if(!currentIsFolderFile) { + if (type == 0x84) { // It's an email! + kdDebug() << "**** Offset of emaildata (0x84) " << value << " ****" << endl; + dbxReadEmail(info, ds, value); + ++count0x84; + } else if( type == 0x04) { + int currentFilePos = ds.device()->at(); + ds.device()->at(filePos + 12 + value + (count*4) ); + TQ_UINT32 newOFF; + ds >> newOFF; + kdDebug() << "**** Offset of emaildata (0x04) " << newOFF << endl; + ds.device()->at(currentFilePos); + dbxReadEmail(info, ds, newOFF); + ++count0x04; + } + } + else { + // this is a folderfile + if(type == 0x02) { + // kdDebug() << "**** FOLDER: descriptive name ****" << endl; + folderEntry[0] = parseFolderString(ds, filePos + 12 + value + (count*4) ); + } else if (type == 0x03) { + // kdDebug() << "**** FOLDER: filename ****" << endl; + folderEntry[1] = parseFolderString(ds, filePos + 12 + value + (count*4) ); + + } else if (type == 0x80) { + // kdDebug() << "**** FOLDER: current ID ****" << endl; + folderEntry[2] = TQString::number(value); + + } else if (type == 0x81) { + // kdDebug() << "**** FOLDER: parent ID ****" << endl; + folderEntry[3] = TQString::number(value); + } + } + } + if(currentIsFolderFile) { + folderStructure.append(folderEntry); + } + ds.device()->at(wasAt); // Restore file position to same as when function called +} + +void FilterOE::dbxReadEmail( FilterInfo *info, TQDataStream& ds, int filePos) +{ + if(info->shouldTerminate()) return; + TQ_UINT32 self, nextAddressOffset, nextAddress=0; + TQ_UINT16 blockSize; + TQ_UINT8 intCount, unknown; + KTempFile tmp; + bool _break = false; + int wasAt = ds.device()->at(); + ds.device()->at(filePos); + + do { + ds >> self >> nextAddressOffset >> blockSize >> intCount >> unknown >> nextAddress; // _dbx_block_hdrstruct + TQByteArray blockBuffer(blockSize); + ds.readRawBytes(blockBuffer.data(), blockSize); + tmp.dataStream()->writeRawBytes(blockBuffer.data(), blockSize); + // to detect incomplete mails or corrupted archives. See Bug #86119 + if(ds.atEnd()) { + _break = true; + break; + } + ds.device()->at(nextAddress); + } while (nextAddress != 0); + tmp.close(); + + if(!_break) { + if(info->removeDupMsg) + addMessage( info, folderName, tmp.name() ); + else + addMessage_fastImport( info, folderName, tmp.name() ); + + currentEmail++; + int currentPercentage = (int) ( ( (float) currentEmail / totalEmails ) * 100 ); + info->setCurrent(currentPercentage); + ds.device()->at(wasAt); + } + tmp.unlink(); +} + +/* ------------------- FolderFile support ------------------- */ +TQString FilterOE::parseFolderString( TQDataStream& ds, int filePos ) +{ + char tmp; + TQString returnString; + int wasAt = ds.device()->at(); + ds.device()->at(filePos); + + // read while != 0x00 + while( !ds.device()->atEnd() ) { + tmp = ds.device()->getch(); + if( tmp != 0x00) { + returnString += tmp; + } + else break; + } + ds.device()->at(wasAt); + return returnString; +} + +/** get the foldername for a given file ID from folderMatrix */ +TQString FilterOE::getFolderName(TQString filename) +{ + bool found = false; + bool foundFilename = false; + TQString folder; + // we must do this because folder with more than one upper letter + // at start have maybe not a file named like the folder !!! + TQString search = filename.lower(); + + while (!found) + { + for ( FolderStructureIterator it = folderStructure.begin(); it != folderStructure.end(); it++) { + FolderStructure tmp = *it; + if(foundFilename == false) { + TQString _tmpFileName = tmp[1]; + _tmpFileName = _tmpFileName.lower(); + if(_tmpFileName == search) { + folder.prepend( tmp[0] + TQString::fromLatin1("/") ); + search = tmp[3]; + foundFilename = true; + } + } else { + TQString _currentID = tmp[2]; + TQString _parentID = tmp[3]; + if(_currentID == search) { + if(_parentID.isEmpty()) { // this is the root of the folder + found = true; + break; + } else { + folder.prepend( tmp[0] + TQString::fromLatin1("/") ); + search = tmp[3]; + } + } + } + } + // need to break the while loop maybe in some cases + if((foundFilename == false) && (folder.isEmpty())) return folder; + } + return folder; +} diff --git a/kmailcvt/filter_oe.cxx b/kmailcvt/filter_oe.cxx deleted file mode 100644 index afd96527..00000000 --- a/kmailcvt/filter_oe.cxx +++ /dev/null @@ -1,429 +0,0 @@ -/*************************************************************************** - filter_oe.cxx - Outlook Express mail import - ------------------- - begin : Sat Feb 1 2003 - copyright : (C) 2003 by Laurence Anderson - (C) 2005 by Danny Kukawka - email : l.d.anderson@warwick.ac.uk - 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. * - * * - ***************************************************************************/ - -// This filter was created by looking at libdbx & liboe - -#include -#include -#include -#include -#include - -#include "filter_oe.hxx" - -#define OE4_SIG_1 0x36464d4a -#define OE4_SIG_2 0x00010003 -#define OE5_SIG_1 0xfe12adcf -#define OE5_EMAIL_SIG_2 0x6f74fdc5 -#define OE5_FOLDER_SIG_2 0x6f74fdc6 -#define OE5_SIG_3 0x11d1e366 -#define OE5_SIG_4 0xc0004e9a -#define MBX_MAILMAGIC 0x7F007F00 - -FilterOE::FilterOE() : - Filter( i18n("Import Outlook Express Emails"), - "Laurence Anderson
( Filter enhanced 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 " - "

  • C:\\Windows\\Application Data in Windows 9x" - "
  • Documents and Settings in Windows 2000 or later

" - "

Note: Since it is possible to recreate the folder structure, the folders from " - "Outlook Express 5 and 6 will be stored under: \"OE-Import\" in your local folder.

" )) -{} - -FilterOE::~FilterOE() -{ -} - -void FilterOE::import(FilterInfo *info) -{ - // Select directory containing plain text emails - mailDir = KFileDialog::getExistingDirectory(TQDir::homeDirPath(),info->parent()); - if (mailDir.isEmpty()) { // No directory selected - info->alert(i18n("No directory selected.")); - return; - } - - TQDir dir (mailDir); - TQStringList files = dir.entryList("*.[dDmM][bB][xX]", TQDir::Files, TQDir::Name); - if (files.isEmpty()) { - info->alert(i18n("No Outlook Express mailboxes found in directory %1.").arg(mailDir)); - return; - } - - totalFiles = files.count(); - currentFile = 0; - count0x04 = 0; - count0x84 = 0; - parsedFolder = false; - - info->setOverall(0); - - /** search the folderfile to recreate folder struct */ - for ( TQStringList::Iterator mailFile = files.begin(); mailFile != files.end(); ++mailFile ) { - if(*mailFile == "Folders.dbx") { - info->addLog(i18n("Import folder structure...")); - importMailBox(info, dir.filePath(*mailFile)); - if(!folderStructure.isEmpty()) parsedFolder = true; - // remove file from TQStringList::files, no longer needed - files.remove(mailFile); - currentIsFolderFile = false; - break; - } - } - - int n=0; - for ( TQStringList::Iterator mailFile = files.begin(); mailFile != files.end(); ++mailFile ) { - if ( info->shouldTerminate() ) break; - importMailBox(info, dir.filePath(*mailFile)); - info->setOverall(100 * ++n / files.count()); - } - - info->setOverall(100); - info->setCurrent(100); - info->addLog(i18n("Finished importing Outlook Express emails")); - if (info->shouldTerminate()) info->addLog( i18n("Finished import, canceled by user.")); - - kdDebug() << "\n" << "total emails in current file: " << totalEmails << endl; - kdDebug() << "0x84 Mails: " << count0x84 << endl; - kdDebug() << "0x04 Mails: " << count0x04 << endl; -} - -void FilterOE::importMailBox( FilterInfo *info, const TQString& fileName) -{ - TQFile mailfile(fileName); - TQFileInfo mailfileinfo(fileName); - TQString _nameOfFile = fileName; - _nameOfFile.remove( mailDir ); - _nameOfFile.remove( "/" ); - info->setFrom(mailfileinfo.fileName()); - - if (!mailfile.open(IO_ReadOnly)) { - info->addLog(i18n("Unable to open mailbox %1").arg(fileName)); - return; - } - TQDataStream mailbox(&mailfile); - mailbox.setByteOrder(TQDataStream::LittleEndian); - - // Parse magic - TQ_UINT32 sig_block1, sig_block2; - mailbox >> sig_block1 >> sig_block2; - if (sig_block1 == OE4_SIG_1 && sig_block2 == OE4_SIG_2) { - folderName = "OE-Import/" + mailfileinfo.baseName(TRUE); - info->addLog(i18n("Importing OE4 Mailbox %1").arg( "../" + _nameOfFile)); - info->setTo(folderName); - mbxImport(info, mailbox); - return; - } else { - TQ_UINT32 sig_block3, sig_block4; - mailbox >> sig_block3 >> sig_block4; - if (sig_block1 == OE5_SIG_1 && sig_block3 == OE5_SIG_3 && sig_block4 == OE5_SIG_4) { - if (sig_block2 == OE5_EMAIL_SIG_2) { - folderName = "OE-Import/" + mailfileinfo.baseName(TRUE); - if(parsedFolder) { - TQString _tmpFolder = getFolderName(_nameOfFile); - if(!_tmpFolder.isEmpty()) folderName = "OE-Import/" + _tmpFolder; - } - info->addLog(i18n("Importing OE5+ Mailbox %1").arg( "../" + _nameOfFile)); - info->setTo(folderName); - dbxImport(info, mailbox); - return; - } else if (sig_block2 == OE5_FOLDER_SIG_2) { - if(!parsedFolder) { - info->addLog(i18n("Importing OE5+ Folder file %1").arg( "../" + _nameOfFile)); - currentIsFolderFile = true; - dbxImport(info, mailbox); - currentIsFolderFile = false; - } - return; - } - } - } - // info->addLog(i18n("File %1 does not seem to be an Outlook Express mailbox").arg("../" + _nameOfFile)); -} - -/* ------------------- MBX support ------------------- */ - -void FilterOE::mbxImport( FilterInfo *info, TQDataStream& ds) -{ - TQ_UINT32 msgCount, lastMsgNum, fileSize; - - // Read the header - ds >> msgCount >> lastMsgNum >> fileSize; - ds.device()->at( ds.device()->at() + 64 ); // Skip 0's - kdDebug() << "This mailbox has " << msgCount << " messages" << endl; - if (msgCount == 0) - return; // Don't import empty mailbox - - TQ_UINT32 msgMagic; - ds >> msgMagic; // Read first magic - - while (!ds.atEnd()) { - TQ_UINT32 msgNumber, msgSize, msgTextSize; - KTempFile tmp; - tmp.dataStream()->setByteOrder(TQDataStream::LittleEndian); - - // Read the messages - ds >> msgNumber >> msgSize >> msgTextSize; // All seem to be lies...? - - do { - ds >> msgMagic; - if (msgMagic != MBX_MAILMAGIC) - *tmp.dataStream() << msgMagic; - else - break; - } while ( !ds.atEnd() ); - - 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(); - if(info->shouldTerminate()) return; - } -} - -/* ------------------- DBX support ------------------- */ - -void FilterOE::dbxImport( FilterInfo *info, TQDataStream& ds) -{ - // Get item count & offset of index - TQ_UINT32 itemCount, indexPtr; - ds.device()->at(0xc4); - ds >> itemCount; - ds.device()->at(0xe4); - ds >> indexPtr; - kdDebug() << "Item count is " << itemCount << ", Index at " << indexPtr << endl; - - if (itemCount == 0) - return; // Empty file - totalEmails = itemCount; - currentEmail = 0; - // Parse the indexes - ds.device()->at(indexPtr); - dbxReadIndex(info, ds, indexPtr); -} - -void FilterOE::dbxReadIndex( FilterInfo *info, TQDataStream& ds, int filePos) -{ - - if(info->shouldTerminate()) return; - TQ_UINT32 self, unknown, nextIndexPtr, parent, indexCount; - TQ_UINT8 unknown2, ptrCount; - TQ_UINT16 unknown3; - int wasAt = ds.device()->at(); - ds.device()->at(filePos); - - - kdDebug() << "Reading index of file " << folderName << endl; - ds >> self >> unknown >> nextIndexPtr >> parent >> unknown2 >> ptrCount >> unknown3 >> indexCount; // _dbx_tableindexstruct - - kdDebug() << "This index has " << (int) ptrCount << " data pointers" << endl; - for (int count = 0; count < ptrCount; count++) { - if(info->shouldTerminate()) return; - TQ_UINT32 dataIndexPtr, anotherIndexPtr, anotherIndexCount; // _dbx_indexstruct - ds >> dataIndexPtr >> anotherIndexPtr >> anotherIndexCount; - - if (anotherIndexCount > 0) { - kdDebug() << "Recursing to another table @ " << anotherIndexPtr << endl; - dbxReadIndex(info, ds, anotherIndexPtr); - } - kdDebug() << "Data index @ " << dataIndexPtr << endl; - dbxReadDataBlock(info, ds, dataIndexPtr); - } - - if (indexCount > 0) { // deal with nextTablePtr - kdDebug() << "Recuring to next table @ " << nextIndexPtr << endl; - dbxReadIndex(info, ds, nextIndexPtr); - } - - ds.device()->at(wasAt); // Restore file position to same as when function called -} - -void FilterOE::dbxReadDataBlock( FilterInfo *info, TQDataStream& ds, int filePos) -{ - TQ_UINT32 curOffset, blockSize; - TQ_UINT16 unknown; - TQ_UINT8 count, unknown2; - int wasAt = ds.device()->at(); - - TQString folderEntry[4]; - - ds.device()->at(filePos); - - ds >> curOffset >> blockSize >> unknown >> count >> unknown2; // _dbx_email_headerstruct - kdDebug() << "Data block has " << (int) count << " elements" << endl; - - for (int c = 0; c < count; c++) { - if(info->shouldTerminate()) return; - TQ_UINT8 type; // _dbx_email_pointerstruct - TQ_UINT32 value; // Actually 24 bit - - ds >> type >> value; - value &= 0xffffff; - ds.device()->at(ds.device()->at() - 1); // We only wanted 3 bytes - - if(!currentIsFolderFile) { - if (type == 0x84) { // It's an email! - kdDebug() << "**** Offset of emaildata (0x84) " << value << " ****" << endl; - dbxReadEmail(info, ds, value); - ++count0x84; - } else if( type == 0x04) { - int currentFilePos = ds.device()->at(); - ds.device()->at(filePos + 12 + value + (count*4) ); - TQ_UINT32 newOFF; - ds >> newOFF; - kdDebug() << "**** Offset of emaildata (0x04) " << newOFF << endl; - ds.device()->at(currentFilePos); - dbxReadEmail(info, ds, newOFF); - ++count0x04; - } - } - else { - // this is a folderfile - if(type == 0x02) { - // kdDebug() << "**** FOLDER: descriptive name ****" << endl; - folderEntry[0] = parseFolderString(ds, filePos + 12 + value + (count*4) ); - } else if (type == 0x03) { - // kdDebug() << "**** FOLDER: filename ****" << endl; - folderEntry[1] = parseFolderString(ds, filePos + 12 + value + (count*4) ); - - } else if (type == 0x80) { - // kdDebug() << "**** FOLDER: current ID ****" << endl; - folderEntry[2] = TQString::number(value); - - } else if (type == 0x81) { - // kdDebug() << "**** FOLDER: parent ID ****" << endl; - folderEntry[3] = TQString::number(value); - } - } - } - if(currentIsFolderFile) { - folderStructure.append(folderEntry); - } - ds.device()->at(wasAt); // Restore file position to same as when function called -} - -void FilterOE::dbxReadEmail( FilterInfo *info, TQDataStream& ds, int filePos) -{ - if(info->shouldTerminate()) return; - TQ_UINT32 self, nextAddressOffset, nextAddress=0; - TQ_UINT16 blockSize; - TQ_UINT8 intCount, unknown; - KTempFile tmp; - bool _break = false; - int wasAt = ds.device()->at(); - ds.device()->at(filePos); - - do { - ds >> self >> nextAddressOffset >> blockSize >> intCount >> unknown >> nextAddress; // _dbx_block_hdrstruct - TQByteArray blockBuffer(blockSize); - ds.readRawBytes(blockBuffer.data(), blockSize); - tmp.dataStream()->writeRawBytes(blockBuffer.data(), blockSize); - // to detect incomplete mails or corrupted archives. See Bug #86119 - if(ds.atEnd()) { - _break = true; - break; - } - ds.device()->at(nextAddress); - } while (nextAddress != 0); - tmp.close(); - - if(!_break) { - if(info->removeDupMsg) - addMessage( info, folderName, tmp.name() ); - else - addMessage_fastImport( info, folderName, tmp.name() ); - - currentEmail++; - int currentPercentage = (int) ( ( (float) currentEmail / totalEmails ) * 100 ); - info->setCurrent(currentPercentage); - ds.device()->at(wasAt); - } - tmp.unlink(); -} - -/* ------------------- FolderFile support ------------------- */ -TQString FilterOE::parseFolderString( TQDataStream& ds, int filePos ) -{ - char tmp; - TQString returnString; - int wasAt = ds.device()->at(); - ds.device()->at(filePos); - - // read while != 0x00 - while( !ds.device()->atEnd() ) { - tmp = ds.device()->getch(); - if( tmp != 0x00) { - returnString += tmp; - } - else break; - } - ds.device()->at(wasAt); - return returnString; -} - -/** get the foldername for a given file ID from folderMatrix */ -TQString FilterOE::getFolderName(TQString filename) -{ - bool found = false; - bool foundFilename = false; - TQString folder; - // we must do this because folder with more than one upper letter - // at start have maybe not a file named like the folder !!! - TQString search = filename.lower(); - - while (!found) - { - for ( FolderStructureIterator it = folderStructure.begin(); it != folderStructure.end(); it++) { - FolderStructure tmp = *it; - if(foundFilename == false) { - TQString _tmpFileName = tmp[1]; - _tmpFileName = _tmpFileName.lower(); - if(_tmpFileName == search) { - folder.prepend( tmp[0] + TQString::fromLatin1("/") ); - search = tmp[3]; - foundFilename = true; - } - } else { - TQString _currentID = tmp[2]; - TQString _parentID = tmp[3]; - if(_currentID == search) { - if(_parentID.isEmpty()) { // this is the root of the folder - found = true; - break; - } else { - folder.prepend( tmp[0] + TQString::fromLatin1("/") ); - search = tmp[3]; - } - } - } - } - // need to break the while loop maybe in some cases - if((foundFilename == false) && (folder.isEmpty())) return folder; - } - return folder; -} diff --git a/kmailcvt/filter_oe.h b/kmailcvt/filter_oe.h new file mode 100644 index 00000000..2a46854f --- /dev/null +++ b/kmailcvt/filter_oe.h @@ -0,0 +1,84 @@ +/*************************************************************************** + filter_oe.h - Outlook Express mail import + ------------------- + begin : Sat Feb 1 2003 + copyright : (C) 2003 by Laurence Anderson + email : l.d.anderson@warwick.ac.uk + ***************************************************************************/ + +/*************************************************************************** + * * + * 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_OE_H +#define FILTER_OE_H + +#include "filters.h" + +/** + *imports outlook text messages into KMail + *@author Laurence Anderson + */ + +class FilterOE : public Filter +{ +public: + FilterOE(); + ~FilterOE(); + + void import(FilterInfo *info); + +protected: + void importMailBox( FilterInfo *info, const TQString& fileName); + void mbxImport( FilterInfo *info, TQDataStream& ds); + void dbxImport( FilterInfo *info, TQDataStream& ds); + void dbxReadIndex( FilterInfo *info, TQDataStream& ds, int filePos); + void dbxReadDataBlock( FilterInfo *info, TQDataStream& ds, int filePos); + void dbxReadEmail( FilterInfo *info, TQDataStream& ds, int filePos); + + /** helperfunctions for folder structure support */ + TQString parseFolderString( TQDataStream& ds, int filePos); + TQString getFolderName(TQString filename); + +private: // Private methods + /** which file (of totalFiles) is now in the work? */ + int currentFile; + /** total number of files that get imported */ + int totalFiles; + /** total emails in current file */ + int totalEmails; + /** which email (of totalFiles) is now in the work? */ + int currentEmail; + /** number of imported mails with flag 0x04 */ + int count0x04; + /** number of imported mails with flag 0x84 */ + int count0x84; + + /** true if the folderstructure is parsed */ + bool parsedFolder; + /** true if the current parsing file is the folder file */ + bool currentIsFolderFile; + + /** Folder structure with following 4 entries: + 1. descriptive folder name + 2. filename + 3. ID of current folder + 4. ID of parent folder + */ + typedef FolderStructureBase<4> FolderStructure; + /** matrix with information about the folder structure*/ + TQValueList folderStructure; + typedef TQValueList::Iterator FolderStructureIterator; + + /** name of the current folder */ + TQString folderName; + /** name of the chosen folder */ + TQString mailDir; +}; + +#endif diff --git a/kmailcvt/filter_oe.hxx b/kmailcvt/filter_oe.hxx deleted file mode 100644 index 821aa5df..00000000 --- a/kmailcvt/filter_oe.hxx +++ /dev/null @@ -1,84 +0,0 @@ -/*************************************************************************** - filter_oe.hxx - Outlook Express mail import - ------------------- - begin : Sat Feb 1 2003 - copyright : (C) 2003 by Laurence Anderson - email : l.d.anderson@warwick.ac.uk - ***************************************************************************/ - -/*************************************************************************** - * * - * 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_OE_HXX -#define FILTER_OE_HXX - -#include "filters.hxx" - -/** - *imports outlook text messages into KMail - *@author Laurence Anderson - */ - -class FilterOE : public Filter -{ -public: - FilterOE(); - ~FilterOE(); - - void import(FilterInfo *info); - -protected: - void importMailBox( FilterInfo *info, const TQString& fileName); - void mbxImport( FilterInfo *info, TQDataStream& ds); - void dbxImport( FilterInfo *info, TQDataStream& ds); - void dbxReadIndex( FilterInfo *info, TQDataStream& ds, int filePos); - void dbxReadDataBlock( FilterInfo *info, TQDataStream& ds, int filePos); - void dbxReadEmail( FilterInfo *info, TQDataStream& ds, int filePos); - - /** helperfunctions for folder structure support */ - TQString parseFolderString( TQDataStream& ds, int filePos); - TQString getFolderName(TQString filename); - -private: // Private methods - /** which file (of totalFiles) is now in the work? */ - int currentFile; - /** total number of files that get imported */ - int totalFiles; - /** total emails in current file */ - int totalEmails; - /** which email (of totalFiles) is now in the work? */ - int currentEmail; - /** number of imported mails with flag 0x04 */ - int count0x04; - /** number of imported mails with flag 0x84 */ - int count0x84; - - /** true if the folderstructure is parsed */ - bool parsedFolder; - /** true if the current parsing file is the folder file */ - bool currentIsFolderFile; - - /** Folder structure with following 4 entries: - 1. descriptive folder name - 2. filename - 3. ID of current folder - 4. ID of parent folder - */ - typedef FolderStructureBase<4> FolderStructure; - /** matrix with information about the folder structure*/ - TQValueList folderStructure; - typedef TQValueList::Iterator FolderStructureIterator; - - /** name of the current folder */ - TQString folderName; - /** name of the chosen folder */ - TQString mailDir; -}; - -#endif diff --git a/kmailcvt/filter_opera.cpp b/kmailcvt/filter_opera.cpp new file mode 100644 index 00000000..ff537695 --- /dev/null +++ b/kmailcvt/filter_opera.cpp @@ -0,0 +1,158 @@ +/*************************************************************************** + filter_opera.cpp - 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 +#include +#include +#include +#include + +#include "filter_opera.h" + + +FilterOpera::FilterOpera() : + Filter( i18n("Import Opera Emails"), + "Danny Kukawka", + i18n("

Opera email import filter

" + "

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.

" + "

Select the directory of the account (usually ~/.opera/mail/store/account*).

" + "

Note: Emails will be imported into a folder named after the account " + "they came from, prefixed with OPERA-

" )) +{} + +FilterOpera::~FilterOpera() +{ +} + +void FilterOpera::import(FilterInfo *info) +{ + /** try to go to opera mailfolder in the home of the user */ + TQString startdir = TQDir::homeDirPath() + "/.opera/mail/store/"; + TQDir d( startdir ); + if ( !d.exists() ) { + startdir = TQDir::homeDirPath(); + } + + //TQString mailDir = KFileDialog::getExistingDirectory(TQDir::homeDirPath(), info->parent()); + KFileDialog *kfd; + kfd = new KFileDialog( startdir, "", 0, "tdefiledialog", true ); + kfd->setMode(KFile::Directory | KFile::LocalOnly); + kfd->exec(); + TQString operaDir = kfd->selectedFile(); + delete kfd; + + if (operaDir.isEmpty()) { + info->alert(i18n("No directory selected.")); + } + /** + * If the user only select homedir no import needed because + * there should be no files and we surely import wrong files. + */ + else if ( operaDir == TQDir::homeDirPath() || operaDir == (TQDir::homeDirPath() + "/")) { + info->addLog(i18n("No files found for import.")); + } else { + info->setOverall(0); + + TQDir importDir (operaDir); + TQStringList files = importDir.entryList("*.[mM][bB][sS]", TQDir::Files, TQDir::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 ( TQStringList::Iterator mailFile = files.begin(); mailFile != files.end(); ++mailFile) { + info->setCurrent(0); + TQFile 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 ) ); + TQFileInfo filenameInfo( importDir.filePath(*mailFile) ); + TQString folderName( "OPERA-" + importDir.dirName() ); + + info->setFrom( *mailFile ); + info->setTo( folderName ); + + TQByteArray input(MAX_LINE); + long l = 0; + bool first_msg = true; + + while ( !operaArchiv.atEnd() ) { + KTempFile tmp; + /* comment by Danny: + * Don't use TQTextStream to read from mbox, etter use TQDataStream. TQTextStream only + * support Unicode/Latin1/Locale. So you lost information from emails with + * charset!=Unicode/Latin1/Locale (e.g. KOI8-R) and Content-Transfer-Encoding != base64 + * (e.g. 8Bit). It also not help to convert the TQTextStream to Unicode. By this you + * get Unicode/UTF-email but KMail can't detect the correct charset. + */ + TQCString seperate; + + if(!first_msg) + tmp.file()->writeBlock( input, l ); + l = operaArchiv.readLine( input.data(),MAX_LINE); // read the first line, prevent "From " + tmp.file()->writeBlock( input, l ); + + while ( ! operaArchiv.atEnd() && (l = operaArchiv.readLine(input.data(),MAX_LINE)) && ((seperate = input.data()).left(5) != "From ")) { + /** remove in KMail unneeded Flags from Opera (for example: X-Opera-Status)*/ + if(seperate.left(8) != "X-Opera-") + tmp.file()->writeBlock( input, l ); + } + tmp.close(); + first_msg = false; + + 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() ) break; + } + + info->addLog( i18n("Finished importing emails from %1").arg( *mailFile )); + if (count_duplicates > 0) { + info->addLog( i18n("1 duplicate message not imported", "%n duplicate messages not imported", count_duplicates)); + } + currentFile++; + count_duplicates = 0; + operaArchiv.close(); + } + if ( info->shouldTerminate() ) break; + } + } else { + info->addLog(i18n("No files found for import.")); + } + } + if (info->shouldTerminate()) info->addLog( i18n("Finished import, canceled by user.")); + info->setCurrent(100); + info->setOverall(100); +} diff --git a/kmailcvt/filter_opera.cxx b/kmailcvt/filter_opera.cxx deleted file mode 100644 index 90aef382..00000000 --- a/kmailcvt/filter_opera.cxx +++ /dev/null @@ -1,158 +0,0 @@ -/*************************************************************************** - 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 -#include -#include -#include -#include - -#include "filter_opera.hxx" - - -FilterOpera::FilterOpera() : - Filter( i18n("Import Opera Emails"), - "Danny Kukawka", - i18n("

Opera email import filter

" - "

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.

" - "

Select the directory of the account (usually ~/.opera/mail/store/account*).

" - "

Note: Emails will be imported into a folder named after the account " - "they came from, prefixed with OPERA-

" )) -{} - -FilterOpera::~FilterOpera() -{ -} - -void FilterOpera::import(FilterInfo *info) -{ - /** try to go to opera mailfolder in the home of the user */ - TQString startdir = TQDir::homeDirPath() + "/.opera/mail/store/"; - TQDir d( startdir ); - if ( !d.exists() ) { - startdir = TQDir::homeDirPath(); - } - - //TQString mailDir = KFileDialog::getExistingDirectory(TQDir::homeDirPath(), info->parent()); - KFileDialog *kfd; - kfd = new KFileDialog( startdir, "", 0, "tdefiledialog", true ); - kfd->setMode(KFile::Directory | KFile::LocalOnly); - kfd->exec(); - TQString operaDir = kfd->selectedFile(); - delete kfd; - - if (operaDir.isEmpty()) { - info->alert(i18n("No directory selected.")); - } - /** - * If the user only select homedir no import needed because - * there should be no files and we surely import wrong files. - */ - else if ( operaDir == TQDir::homeDirPath() || operaDir == (TQDir::homeDirPath() + "/")) { - info->addLog(i18n("No files found for import.")); - } else { - info->setOverall(0); - - TQDir importDir (operaDir); - TQStringList files = importDir.entryList("*.[mM][bB][sS]", TQDir::Files, TQDir::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 ( TQStringList::Iterator mailFile = files.begin(); mailFile != files.end(); ++mailFile) { - info->setCurrent(0); - TQFile 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 ) ); - TQFileInfo filenameInfo( importDir.filePath(*mailFile) ); - TQString folderName( "OPERA-" + importDir.dirName() ); - - info->setFrom( *mailFile ); - info->setTo( folderName ); - - TQByteArray input(MAX_LINE); - long l = 0; - bool first_msg = true; - - while ( !operaArchiv.atEnd() ) { - KTempFile tmp; - /* comment by Danny: - * Don't use TQTextStream to read from mbox, etter use TQDataStream. TQTextStream only - * support Unicode/Latin1/Locale. So you lost information from emails with - * charset!=Unicode/Latin1/Locale (e.g. KOI8-R) and Content-Transfer-Encoding != base64 - * (e.g. 8Bit). It also not help to convert the TQTextStream to Unicode. By this you - * get Unicode/UTF-email but KMail can't detect the correct charset. - */ - TQCString seperate; - - if(!first_msg) - tmp.file()->writeBlock( input, l ); - l = operaArchiv.readLine( input.data(),MAX_LINE); // read the first line, prevent "From " - tmp.file()->writeBlock( input, l ); - - while ( ! operaArchiv.atEnd() && (l = operaArchiv.readLine(input.data(),MAX_LINE)) && ((seperate = input.data()).left(5) != "From ")) { - /** remove in KMail unneeded Flags from Opera (for example: X-Opera-Status)*/ - if(seperate.left(8) != "X-Opera-") - tmp.file()->writeBlock( input, l ); - } - tmp.close(); - first_msg = false; - - 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() ) break; - } - - info->addLog( i18n("Finished importing emails from %1").arg( *mailFile )); - if (count_duplicates > 0) { - info->addLog( i18n("1 duplicate message not imported", "%n duplicate messages not imported", count_duplicates)); - } - currentFile++; - count_duplicates = 0; - operaArchiv.close(); - } - if ( info->shouldTerminate() ) break; - } - } else { - info->addLog(i18n("No files found for import.")); - } - } - if (info->shouldTerminate()) info->addLog( i18n("Finished import, canceled by user.")); - info->setCurrent(100); - info->setOverall(100); -} diff --git a/kmailcvt/filter_opera.h b/kmailcvt/filter_opera.h new file mode 100644 index 00000000..7da80afa --- /dev/null +++ b/kmailcvt/filter_opera.h @@ -0,0 +1,37 @@ +/*************************************************************************** + filter_opera.h - 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_H +#define FILTER_OPERA_H + +#include "filters.h" + +/** + *imports opera account-archives into KMail + *@author Danny Kukawka + */ + +class FilterOpera : public Filter +{ +public: + FilterOpera(); + ~FilterOpera(); + + void import(FilterInfo *info); +}; + +#endif diff --git a/kmailcvt/filter_opera.hxx b/kmailcvt/filter_opera.hxx deleted file mode 100644 index 27ded4cc..00000000 --- a/kmailcvt/filter_opera.hxx +++ /dev/null @@ -1,37 +0,0 @@ -/*************************************************************************** - 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 diff --git a/kmailcvt/filter_outlook.cpp b/kmailcvt/filter_outlook.cpp new file mode 100644 index 00000000..bb395918 --- /dev/null +++ b/kmailcvt/filter_outlook.cpp @@ -0,0 +1,61 @@ +/*************************************************************************** + filter_opera.cpp - Outlook mail import + ------------------- + begin : February 01 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 +#include +#include +#include +#include + +#include "filter_outlook.h" + +FilterOutlook::FilterOutlook() : + Filter( i18n("Import Outlook Emails"), + "Danny Kukawka", + i18n("

Outlook email import filter

" + "

This filter will import mails from a Outlook pst-file. You will need to locate " + "the folder where the pst-file has been stored by searching for .pst files under: " + "C:\\Documents and Settings in Windows 2000 or later

" + "

Note: Emails will be imported into a folder named after the " + "account they came from, prefixed with OUTLOOK-

" )) +{} + +FilterOutlook::~FilterOutlook() +{ +} + +void FilterOutlook::import(FilterInfo *info) +{ + info->alert(i18n("No directory selected.")); + info->addLog(i18n("Counting files...")); + info->addLog(i18n("Counting mail...")); + info->addLog(i18n("Counting directories...")); + info->addLog(i18n("Counting folders...")); + info->addLog(i18n("Importing new mail files...")); + info->addLog(i18n("No files found for import.")); + + TQString outlookDir; + outlookDir = KFileDialog::getExistingDirectory(TQDir::homeDirPath(), info->parent()); + TQDir importDir (outlookDir); + TQStringList files = importDir.entryList("*.[pP][sS][tT]", TQDir::Files, TQDir::Name); + for ( TQStringList::Iterator pstFile = files.begin(); pstFile != files.end(); ++pstFile) { + info->addLog( i18n("Importing emails from %1...").arg( *pstFile ) ); + info->addLog( i18n("1 duplicate message not imported", "%n duplicate messages not imported", count_duplicates)); + info->alert( i18n("Unable to open %1, skipping").arg( *pstFile ) ); + } +} diff --git a/kmailcvt/filter_outlook.cxx b/kmailcvt/filter_outlook.cxx deleted file mode 100644 index 10483d09..00000000 --- a/kmailcvt/filter_outlook.cxx +++ /dev/null @@ -1,61 +0,0 @@ -/*************************************************************************** - filter_opera.cxx - Outlook mail import - ------------------- - begin : February 01 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 -#include -#include -#include -#include - -#include "filter_outlook.hxx" - -FilterOutlook::FilterOutlook() : - Filter( i18n("Import Outlook Emails"), - "Danny Kukawka", - i18n("

Outlook email import filter

" - "

This filter will import mails from a Outlook pst-file. You will need to locate " - "the folder where the pst-file has been stored by searching for .pst files under: " - "C:\\Documents and Settings in Windows 2000 or later

" - "

Note: Emails will be imported into a folder named after the " - "account they came from, prefixed with OUTLOOK-

" )) -{} - -FilterOutlook::~FilterOutlook() -{ -} - -void FilterOutlook::import(FilterInfo *info) -{ - info->alert(i18n("No directory selected.")); - info->addLog(i18n("Counting files...")); - info->addLog(i18n("Counting mail...")); - info->addLog(i18n("Counting directories...")); - info->addLog(i18n("Counting folders...")); - info->addLog(i18n("Importing new mail files...")); - info->addLog(i18n("No files found for import.")); - - TQString outlookDir; - outlookDir = KFileDialog::getExistingDirectory(TQDir::homeDirPath(), info->parent()); - TQDir importDir (outlookDir); - TQStringList files = importDir.entryList("*.[pP][sS][tT]", TQDir::Files, TQDir::Name); - for ( TQStringList::Iterator pstFile = files.begin(); pstFile != files.end(); ++pstFile) { - info->addLog( i18n("Importing emails from %1...").arg( *pstFile ) ); - info->addLog( i18n("1 duplicate message not imported", "%n duplicate messages not imported", count_duplicates)); - info->alert( i18n("Unable to open %1, skipping").arg( *pstFile ) ); - } -} diff --git a/kmailcvt/filter_outlook.h b/kmailcvt/filter_outlook.h new file mode 100644 index 00000000..ec762066 --- /dev/null +++ b/kmailcvt/filter_outlook.h @@ -0,0 +1,38 @@ +/*************************************************************************** + filter_opera.h - Outlook 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_OUTLOOK_H +#define FILTER_OUTLOOK_H + +#include "filters.h" + +/** + * imports mails from Outlook pst-files into KMail + * NOTE: This is a dummy at the moment + * @author Danny Kukawka + */ + +class FilterOutlook : public Filter +{ +public: + FilterOutlook(); + ~FilterOutlook(); + + void import(FilterInfo *info); +}; + +#endif diff --git a/kmailcvt/filter_outlook.hxx b/kmailcvt/filter_outlook.hxx deleted file mode 100644 index bad7d5ee..00000000 --- a/kmailcvt/filter_outlook.hxx +++ /dev/null @@ -1,38 +0,0 @@ -/*************************************************************************** - filter_opera.hxx - Outlook 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_OUTLOOK_HXX -#define FILTER_OUTLOOK_HXX - -#include "filters.hxx" - -/** - * imports mails from Outlook pst-files into KMail - * NOTE: This is a dummy at the moment - * @author Danny Kukawka - */ - -class FilterOutlook : public Filter -{ -public: - FilterOutlook(); - ~FilterOutlook(); - - void import(FilterInfo *info); -}; - -#endif diff --git a/kmailcvt/filter_plain.cpp b/kmailcvt/filter_plain.cpp new file mode 100644 index 00000000..01554c87 --- /dev/null +++ b/kmailcvt/filter_plain.cpp @@ -0,0 +1,87 @@ +/*************************************************************************** + FilterPlain.cpp - Plain mail import + ------------------- + begin : Fri Jun 14 2002 + copyright : (C) 2002 by Laurence Anderson + email : l.d.anderson@warwick.ac.uk + ***************************************************************************/ + +/*************************************************************************** + * * + * 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 +#include +#include +#include + +#include "filter_plain.h" + + +FilterPlain::FilterPlain() : + Filter(i18n("Import Plain Text Emails"), + "Laurence Anderson

( Filter accelerated by Danny Kukawka )

", + i18n("

Select the directory containing the emails on your system. " + "The emails are placed in a folder with the same name as the " + "directory they were in, prefixed by PLAIN-

" + "

This filter will import all .msg, .eml and .txt emails.

")) +{} + +FilterPlain::~FilterPlain() +{ +} + +void FilterPlain::import(FilterInfo *info) +{ + // Select directory containing plain text emails + TQString mailDir = KFileDialog::getExistingDirectory(TQDir::homeDirPath(),info->parent()); + if (mailDir.isEmpty()) { // No directory selected + info->alert(i18n("No directory selected.")); + return; + } + TQDir dir (mailDir); + TQStringList files = dir.entryList("*.[eE][mM][lL]; *.[tT][xX][tT]; *.[mM][sS][gG]", TQDir::Files, TQDir::Name); + + // Count total number of files to be processed + info->addLog(i18n("Counting files...")); + int totalFiles = files.count(); + int currentFile = 0; + + info->addLog(i18n("Importing new mail files...")); + for ( TQStringList::Iterator mailFile = files.begin(); mailFile != files.end(); ++mailFile ) { + info->setFrom(*mailFile); + info->setTo(dir.dirName()); + info->setCurrent(0); + + /* 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) { + if(! addMessage( info, "PLAIN-" + dir.dirName(), dir.filePath(*mailFile) )) { + info->addLog( i18n("Could not import %1").arg( *mailFile ) ); + } + } else { + if( ! addMessage_fastImport( info, "PLAIN-" + dir.dirName(), dir.filePath(*mailFile) )) { + info->addLog( i18n("Could not import %1").arg( *mailFile ) ); + } + } + + info->setCurrent(100); + info->setOverall(100 * ++currentFile/ totalFiles); + if ( info->shouldTerminate() ) break; + } + + info->addLog( i18n("Finished importing emails from %1").arg( mailDir )); + if (count_duplicates > 0) { + info->addLog( i18n("1 duplicate message not imported", "%n duplicate messages not imported", count_duplicates)); + } + if (info->shouldTerminate()) info->addLog( i18n("Finished import, canceled by user.")); + + count_duplicates = 0; +} diff --git a/kmailcvt/filter_plain.cxx b/kmailcvt/filter_plain.cxx deleted file mode 100644 index 9f78b939..00000000 --- a/kmailcvt/filter_plain.cxx +++ /dev/null @@ -1,87 +0,0 @@ -/*************************************************************************** - FilterPlain.cxx - Plain mail import - ------------------- - begin : Fri Jun 14 2002 - copyright : (C) 2002 by Laurence Anderson - email : l.d.anderson@warwick.ac.uk - ***************************************************************************/ - -/*************************************************************************** - * * - * 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 -#include -#include -#include - -#include "filter_plain.hxx" - - -FilterPlain::FilterPlain() : - Filter(i18n("Import Plain Text Emails"), - "Laurence Anderson

( Filter accelerated by Danny Kukawka )

", - i18n("

Select the directory containing the emails on your system. " - "The emails are placed in a folder with the same name as the " - "directory they were in, prefixed by PLAIN-

" - "

This filter will import all .msg, .eml and .txt emails.

")) -{} - -FilterPlain::~FilterPlain() -{ -} - -void FilterPlain::import(FilterInfo *info) -{ - // Select directory containing plain text emails - TQString mailDir = KFileDialog::getExistingDirectory(TQDir::homeDirPath(),info->parent()); - if (mailDir.isEmpty()) { // No directory selected - info->alert(i18n("No directory selected.")); - return; - } - TQDir dir (mailDir); - TQStringList files = dir.entryList("*.[eE][mM][lL]; *.[tT][xX][tT]; *.[mM][sS][gG]", TQDir::Files, TQDir::Name); - - // Count total number of files to be processed - info->addLog(i18n("Counting files...")); - int totalFiles = files.count(); - int currentFile = 0; - - info->addLog(i18n("Importing new mail files...")); - for ( TQStringList::Iterator mailFile = files.begin(); mailFile != files.end(); ++mailFile ) { - info->setFrom(*mailFile); - info->setTo(dir.dirName()); - info->setCurrent(0); - - /* 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) { - if(! addMessage( info, "PLAIN-" + dir.dirName(), dir.filePath(*mailFile) )) { - info->addLog( i18n("Could not import %1").arg( *mailFile ) ); - } - } else { - if( ! addMessage_fastImport( info, "PLAIN-" + dir.dirName(), dir.filePath(*mailFile) )) { - info->addLog( i18n("Could not import %1").arg( *mailFile ) ); - } - } - - info->setCurrent(100); - info->setOverall(100 * ++currentFile/ totalFiles); - if ( info->shouldTerminate() ) break; - } - - info->addLog( i18n("Finished importing emails from %1").arg( mailDir )); - if (count_duplicates > 0) { - info->addLog( i18n("1 duplicate message not imported", "%n duplicate messages not imported", count_duplicates)); - } - if (info->shouldTerminate()) info->addLog( i18n("Finished import, canceled by user.")); - - count_duplicates = 0; -} diff --git a/kmailcvt/filter_plain.h b/kmailcvt/filter_plain.h new file mode 100644 index 00000000..2319e888 --- /dev/null +++ b/kmailcvt/filter_plain.h @@ -0,0 +1,37 @@ +/*************************************************************************** + FilterPlain.h - Plain mail import + ------------------- + begin : Fri Jun 24 2002 + copyright : (C) 2002 by Laurence Anderson + email : l.d.anderson@warwick.ac.uk + ***************************************************************************/ + +/*************************************************************************** + * * + * 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_PLAIN_H +#define FILTER_PLAIN_H + +#include "filters.h" + +/** + *imports Plain text messages into KMail + *@author laurence + */ + +class FilterPlain : public Filter +{ +public: + FilterPlain(); + ~FilterPlain(); + + void import(FilterInfo *info); +}; + +#endif diff --git a/kmailcvt/filter_plain.hxx b/kmailcvt/filter_plain.hxx deleted file mode 100644 index ddd9d494..00000000 --- a/kmailcvt/filter_plain.hxx +++ /dev/null @@ -1,37 +0,0 @@ -/*************************************************************************** - FilterPlain.hxx - Plain mail import - ------------------- - begin : Fri Jun 24 2002 - copyright : (C) 2002 by Laurence Anderson - email : l.d.anderson@warwick.ac.uk - ***************************************************************************/ - -/*************************************************************************** - * * - * 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_PLAIN_HXX -#define FILTER_PLAIN_HXX - -#include "filters.hxx" - -/** - *imports Plain text messages into KMail - *@author laurence - */ - -class FilterPlain : public Filter -{ -public: - FilterPlain(); - ~FilterPlain(); - - void import(FilterInfo *info); -}; - -#endif diff --git a/kmailcvt/filter_pmail.cpp b/kmailcvt/filter_pmail.cpp new file mode 100644 index 00000000..b45a0be4 --- /dev/null +++ b/kmailcvt/filter_pmail.cpp @@ -0,0 +1,346 @@ +/*************************************************************************** + FilterPMail.cpp - Pegasus-Mail import + ------------------- + begin : Sat Jan 6 2001 + copyright : (C) 2001 by Holger Schurig + (C) 2005 by Danny Kukawka + email : holgerschurig@gmx.de + 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 +#include +#include +#include +#include +#include + +#include "filter_pmail.h" + + +FilterPMail::FilterPMail() : + Filter(i18n("Import Folders From Pegasus-Mail"), + "Holger Schurig
( rewritten by Danny Kukawka )", + i18n("

Select the Pegasus-Mail directory on your system (containing *.CNM, *.PMM and *.MBX files). " + "On many systems this is stored in C:\\pmail\\mail or C:\\pmail\\mail\\admin

" + "

Note: Since it is possible to recreate the folder structure, the folders " + "will be stored under: \"PegasusMail-Import\".

")) +{} + +FilterPMail::~FilterPMail() +{ +} + +void FilterPMail::import(FilterInfo *info) +{ + inf = info; + + // Select directory from where I have to import files + KFileDialog *kfd; + kfd = new KFileDialog( TQDir::homeDirPath(), "", 0, "tdefiledialog", true ); + kfd->setMode(KFile::Directory | KFile::LocalOnly); + kfd->exec(); + chosenDir = kfd->selectedFile(); + delete kfd; + + if (chosenDir.isEmpty()) { + info->alert(i18n("No directory selected.")); + return; + } + + // Count total number of files to be processed + info->addLog(i18n("Counting files...")); + dir.setPath (chosenDir); + TQStringList files = dir.entryList("*.[cC][nN][mM]; *.[pP][mM][mM]; *.[mM][bB][xX]", TQDir::Files, TQDir::Name); + totalFiles = files.count(); + currentFile = 0; + kdDebug() << "Count is " << totalFiles << endl; + + if(!(folderParsed = parseFolderMatrix())) { + info->addLog(i18n("Cannot parse the folder structure; continuing import without subfolder support.")); + } + + info->addLog(i18n("Importing new mail files ('.cnm')...")); + processFiles("*.[cC][nN][mM]", &FilterPMail::importNewMessage); + info->addLog(i18n("Importing mail folders ('.pmm')...")); + processFiles("*.[pP][mM][mM]", &FilterPMail::importMailFolder); + info->addLog(i18n("Importing 'UNIX' mail folders ('.mbx')...")); + processFiles("*.[mM][bB][xX]", &FilterPMail::importUnixMailFolder); + + info->addLog( i18n("Finished importing emails from %1").arg( chosenDir )); + info->setCurrent(100); + info->setOverall(100); +} + +/** this looks for all files with the filemask 'mask' and calls the 'workFunc' on each of them */ +void FilterPMail::processFiles(const TQString& mask, void(FilterPMail::* workFunc)(const TQString&) ) +{ + if (inf->shouldTerminate()) return; + + TQStringList files = dir.entryList(mask, TQDir::Files, TQDir::Name); + //kdDebug() << "Mask is " << mask << " count is " << files.count() << endl; + for ( TQStringList::Iterator mailFile = files.begin(); mailFile != files.end(); ++mailFile ) { + // Notify current file + TQFileInfo mailfileinfo(*mailFile); + inf->setFrom(mailfileinfo.fileName()); + + // Clear the other fields + inf->setTo(TQString()); + inf->setCurrent(TQString()); + inf->setCurrent(-1); + + // call worker function, increase progressbar + (this->*workFunc)(dir.filePath(*mailFile)); + ++currentFile; + inf->setOverall( (int) ((float) currentFile / totalFiles * 100)); + inf->setCurrent( 100 ); + if (inf->shouldTerminate()) return; + } +} + + +/** this function imports one *.CNM message */ +void FilterPMail::importNewMessage(const TQString& file) +{ + TQString destFolder("PegasusMail-Import/New Messages"); + inf->setTo(destFolder); + + /* 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(inf->removeDupMsg) + addMessage( inf, destFolder, file ); + else + addMessage_fastImport( inf, destFolder, file ); +} + + +/** this function imports one mail folder file (*.PMM) */ +void FilterPMail::importMailFolder(const TQString& file) +{ + // Format of a PMM file: + // First comes a header with 128 bytes. At the beginning is the name of + // the folder. Then there are some unknown bytes (strings). At offset 128 + // the first message starts. + // + // Each message is terminated by a 0x1A byte. The next message follows + // immediately. + // + // The last message is followed by a 0x1A, too. + // + // 000000 6d 61 69 6c 73 65 72 76 65 72 2d 70 72 6f 6a 65 mailserver-proje + // 000010 63 74 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ct.............. + // 000020 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ + // 000030 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ + // 000040 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ + // 000050 00 00 00 00 00 00 36 30 34 37 35 37 32 45 3a 36 ......6047572E:6 + // 000060 46 34 39 3a 46 4f 4c 30 31 33 35 35 00 00 00 00 F49:FOL01355.... + // 000070 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ + // 000080 52 65 74 75 72 6e 2d 50 61 74 68 3a 20 3c 75 72 Return-Path: alert(i18n("Unable to open %1, skipping").arg(file)); + } else { + // Get folder name + l = f.readBlock((char *) &pmm_head, sizeof(pmm_head)); + TQString folder("PegasusMail-Import/"); + if(folderParsed) + folder.append(getFolderName((TQString)pmm_head.id)); + else + folder.append(pmm_head.folder); + inf->setTo(folder); + inf->addLog(i18n("Importing %1").arg("../" + TQString(pmm_head.folder))); + + TQByteArray input(MAX_LINE); + bool first_msg = true; + + while (!f.atEnd()) { + KTempFile tempfile; + inf->setCurrent( (int) ( ( (float) f.at() / f.size() ) * 100 ) ); + + if(!first_msg) { + // set the filepos back to last line minus the seperate char (0x1a) + f.at(f.at() - l + 1); + } + + // no problem to loose the last line in file. This only contains a seperate char + while ( ! f.atEnd() && (l = f.readLine(input.data(),MAX_LINE))) { + if (inf->shouldTerminate()){ + tempfile.close(); + tempfile.unlink(); + return; + } + if(input[0] == 0x1a ) { + break; + } else { + tempfile.file()->writeBlock( input, l ); + } + } + tempfile.close(); + + if(inf->removeDupMsg) + addMessage( inf, folder, tempfile.name() ); + else + addMessage_fastImport( inf, folder, tempfile.name() ); + + first_msg = false; + tempfile.unlink(); + } + } + f.close(); +} + + +/** imports a 'unix' format mail folder (*.MBX) */ +void FilterPMail::importUnixMailFolder(const TQString& file) +{ + struct { + char folder[58]; + char id[31]; + } pmg_head; + + TQFile f; + TQString folder("PegasusMail-Import/"), s(file), seperate; + TQByteArray line(MAX_LINE); + int n = 0, l = 0; + + /** Get the folder name */ + s.replace( TQRegExp("mbx$"), "pmg"); + s.replace( TQRegExp("MBX$"), "PMG"); + f.setName(s); + if (! f.open( IO_ReadOnly ) ) { + inf->alert( i18n("Unable to open %1, skipping").arg( s ) ); + return; + } else { + f.readBlock((char *) &pmg_head, sizeof(pmg_head)); + f.close(); + + if(folderParsed) + folder.append(getFolderName((TQString)pmg_head.id)); + else + folder.append(pmg_head.folder); + + inf->setTo(folder); + inf->setTo(folder); + } + + /** Read in the mbox */ + f.setName(file); + if (! f.open( IO_ReadOnly ) ) { + inf->alert( i18n("Unable to open %1, skipping").arg( s ) ); + } else { + inf->addLog(i18n("Importing %1").arg("../" + TQString(pmg_head.folder))); + l = f.readLine( line.data(),MAX_LINE); // read the first line which is unneeded + while ( ! f.atEnd() ) { + KTempFile tempfile; + + // we lost the last line, which is the first line of the new message in + // this lopp, but this is ok, because this is the seperate line with + // "From ???@???" and we can forget them + while ( ! f.atEnd() && (l = f.readLine(line.data(),MAX_LINE)) && ((seperate = line.data()).left(5) != "From ")) { + tempfile.file()->writeBlock(line.data(), l); + if (inf->shouldTerminate()){ + tempfile.close(); + tempfile.unlink(); + return; + } + } + tempfile.close(); + if(inf->removeDupMsg) + addMessage( inf, folder, tempfile.name() ); + else + addMessage_fastImport( inf, folder, tempfile.name() ); + tempfile.unlink(); + + n++; + inf->setCurrent(i18n("Message %1").arg(n)); + inf->setCurrent( (int) ( ( (float) f.at() / f.size() ) * 100 ) ); + } + } + f.close(); +} + +/** Parse the information about folderstructure to folderMatrix */ +bool FilterPMail::parseFolderMatrix() +{ + kdDebug() << "Start parsing the foldermatrix." << endl; + inf->addLog(i18n("Parsing the folder structure...")); + + TQFile hierarch(chosenDir + "/hierarch.pm"); + if (! hierarch.open( IO_ReadOnly ) ) { + inf->alert( i18n("Unable to open %1, skipping").arg( chosenDir + "hierarch.pm" ) ); + return false; + } else { + TQStringList tmpList; + TQString tmpRead; + while ( !hierarch.atEnd() && hierarch.readLine(tmpRead,100)) { + TQString tmpArray[5]; + tmpRead.remove(tmpRead.length() -2,2); + TQStringList tmpList = TQStringList::split(",", tmpRead, false); + int i = 0; + for ( TQStringList::Iterator it = tmpList.begin(); it != tmpList.end(); ++it, i++) { + TQString _tmp = *it; + if(i < 5) tmpArray[i] = _tmp.remove("\""); + else { + hierarch.close(); + return false; + } + } + folderMatrix.append(tmpArray); + } + } + hierarch.close(); + return true; +} + +/** get the foldername for a given file ID from folderMatrix */ +TQString FilterPMail::getFolderName(TQString ID) +{ + bool found = false; + TQString folder; + TQString search = ID; + + while (!found) + { + for ( FolderStructureIterator it = folderMatrix.begin(); it != folderMatrix.end(); it++) { + FolderStructure tmp = *it; + + TQString _ID = tmp[2]; + if(_ID == search) { + TQString _type = tmp[0] + tmp[1]; + if(( _type == "21")) { + found = true; + break; + } + else { + folder.prepend((tmp[4] + "/")); + search = tmp[3]; + } + } + } + } + return folder; +} diff --git a/kmailcvt/filter_pmail.cxx b/kmailcvt/filter_pmail.cxx deleted file mode 100644 index e48e062d..00000000 --- a/kmailcvt/filter_pmail.cxx +++ /dev/null @@ -1,346 +0,0 @@ -/*************************************************************************** - FilterPMail.cxx - Pegasus-Mail import - ------------------- - begin : Sat Jan 6 2001 - copyright : (C) 2001 by Holger Schurig - (C) 2005 by Danny Kukawka - email : holgerschurig@gmx.de - 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 -#include -#include -#include -#include -#include - -#include "filter_pmail.hxx" - - -FilterPMail::FilterPMail() : - Filter(i18n("Import Folders From Pegasus-Mail"), - "Holger Schurig
( rewritten by Danny Kukawka )", - i18n("

Select the Pegasus-Mail directory on your system (containing *.CNM, *.PMM and *.MBX files). " - "On many systems this is stored in C:\\pmail\\mail or C:\\pmail\\mail\\admin

" - "

Note: Since it is possible to recreate the folder structure, the folders " - "will be stored under: \"PegasusMail-Import\".

")) -{} - -FilterPMail::~FilterPMail() -{ -} - -void FilterPMail::import(FilterInfo *info) -{ - inf = info; - - // Select directory from where I have to import files - KFileDialog *kfd; - kfd = new KFileDialog( TQDir::homeDirPath(), "", 0, "tdefiledialog", true ); - kfd->setMode(KFile::Directory | KFile::LocalOnly); - kfd->exec(); - chosenDir = kfd->selectedFile(); - delete kfd; - - if (chosenDir.isEmpty()) { - info->alert(i18n("No directory selected.")); - return; - } - - // Count total number of files to be processed - info->addLog(i18n("Counting files...")); - dir.setPath (chosenDir); - TQStringList files = dir.entryList("*.[cC][nN][mM]; *.[pP][mM][mM]; *.[mM][bB][xX]", TQDir::Files, TQDir::Name); - totalFiles = files.count(); - currentFile = 0; - kdDebug() << "Count is " << totalFiles << endl; - - if(!(folderParsed = parseFolderMatrix())) { - info->addLog(i18n("Cannot parse the folder structure; continuing import without subfolder support.")); - } - - info->addLog(i18n("Importing new mail files ('.cnm')...")); - processFiles("*.[cC][nN][mM]", &FilterPMail::importNewMessage); - info->addLog(i18n("Importing mail folders ('.pmm')...")); - processFiles("*.[pP][mM][mM]", &FilterPMail::importMailFolder); - info->addLog(i18n("Importing 'UNIX' mail folders ('.mbx')...")); - processFiles("*.[mM][bB][xX]", &FilterPMail::importUnixMailFolder); - - info->addLog( i18n("Finished importing emails from %1").arg( chosenDir )); - info->setCurrent(100); - info->setOverall(100); -} - -/** this looks for all files with the filemask 'mask' and calls the 'workFunc' on each of them */ -void FilterPMail::processFiles(const TQString& mask, void(FilterPMail::* workFunc)(const TQString&) ) -{ - if (inf->shouldTerminate()) return; - - TQStringList files = dir.entryList(mask, TQDir::Files, TQDir::Name); - //kdDebug() << "Mask is " << mask << " count is " << files.count() << endl; - for ( TQStringList::Iterator mailFile = files.begin(); mailFile != files.end(); ++mailFile ) { - // Notify current file - TQFileInfo mailfileinfo(*mailFile); - inf->setFrom(mailfileinfo.fileName()); - - // Clear the other fields - inf->setTo(TQString()); - inf->setCurrent(TQString()); - inf->setCurrent(-1); - - // call worker function, increase progressbar - (this->*workFunc)(dir.filePath(*mailFile)); - ++currentFile; - inf->setOverall( (int) ((float) currentFile / totalFiles * 100)); - inf->setCurrent( 100 ); - if (inf->shouldTerminate()) return; - } -} - - -/** this function imports one *.CNM message */ -void FilterPMail::importNewMessage(const TQString& file) -{ - TQString destFolder("PegasusMail-Import/New Messages"); - inf->setTo(destFolder); - - /* 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(inf->removeDupMsg) - addMessage( inf, destFolder, file ); - else - addMessage_fastImport( inf, destFolder, file ); -} - - -/** this function imports one mail folder file (*.PMM) */ -void FilterPMail::importMailFolder(const TQString& file) -{ - // Format of a PMM file: - // First comes a header with 128 bytes. At the beginning is the name of - // the folder. Then there are some unknown bytes (strings). At offset 128 - // the first message starts. - // - // Each message is terminated by a 0x1A byte. The next message follows - // immediately. - // - // The last message is followed by a 0x1A, too. - // - // 000000 6d 61 69 6c 73 65 72 76 65 72 2d 70 72 6f 6a 65 mailserver-proje - // 000010 63 74 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ct.............. - // 000020 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ - // 000030 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ - // 000040 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ - // 000050 00 00 00 00 00 00 36 30 34 37 35 37 32 45 3a 36 ......6047572E:6 - // 000060 46 34 39 3a 46 4f 4c 30 31 33 35 35 00 00 00 00 F49:FOL01355.... - // 000070 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ - // 000080 52 65 74 75 72 6e 2d 50 61 74 68 3a 20 3c 75 72 Return-Path: alert(i18n("Unable to open %1, skipping").arg(file)); - } else { - // Get folder name - l = f.readBlock((char *) &pmm_head, sizeof(pmm_head)); - TQString folder("PegasusMail-Import/"); - if(folderParsed) - folder.append(getFolderName((TQString)pmm_head.id)); - else - folder.append(pmm_head.folder); - inf->setTo(folder); - inf->addLog(i18n("Importing %1").arg("../" + TQString(pmm_head.folder))); - - TQByteArray input(MAX_LINE); - bool first_msg = true; - - while (!f.atEnd()) { - KTempFile tempfile; - inf->setCurrent( (int) ( ( (float) f.at() / f.size() ) * 100 ) ); - - if(!first_msg) { - // set the filepos back to last line minus the seperate char (0x1a) - f.at(f.at() - l + 1); - } - - // no problem to loose the last line in file. This only contains a seperate char - while ( ! f.atEnd() && (l = f.readLine(input.data(),MAX_LINE))) { - if (inf->shouldTerminate()){ - tempfile.close(); - tempfile.unlink(); - return; - } - if(input[0] == 0x1a ) { - break; - } else { - tempfile.file()->writeBlock( input, l ); - } - } - tempfile.close(); - - if(inf->removeDupMsg) - addMessage( inf, folder, tempfile.name() ); - else - addMessage_fastImport( inf, folder, tempfile.name() ); - - first_msg = false; - tempfile.unlink(); - } - } - f.close(); -} - - -/** imports a 'unix' format mail folder (*.MBX) */ -void FilterPMail::importUnixMailFolder(const TQString& file) -{ - struct { - char folder[58]; - char id[31]; - } pmg_head; - - TQFile f; - TQString folder("PegasusMail-Import/"), s(file), seperate; - TQByteArray line(MAX_LINE); - int n = 0, l = 0; - - /** Get the folder name */ - s.replace( TQRegExp("mbx$"), "pmg"); - s.replace( TQRegExp("MBX$"), "PMG"); - f.setName(s); - if (! f.open( IO_ReadOnly ) ) { - inf->alert( i18n("Unable to open %1, skipping").arg( s ) ); - return; - } else { - f.readBlock((char *) &pmg_head, sizeof(pmg_head)); - f.close(); - - if(folderParsed) - folder.append(getFolderName((TQString)pmg_head.id)); - else - folder.append(pmg_head.folder); - - inf->setTo(folder); - inf->setTo(folder); - } - - /** Read in the mbox */ - f.setName(file); - if (! f.open( IO_ReadOnly ) ) { - inf->alert( i18n("Unable to open %1, skipping").arg( s ) ); - } else { - inf->addLog(i18n("Importing %1").arg("../" + TQString(pmg_head.folder))); - l = f.readLine( line.data(),MAX_LINE); // read the first line which is unneeded - while ( ! f.atEnd() ) { - KTempFile tempfile; - - // we lost the last line, which is the first line of the new message in - // this lopp, but this is ok, because this is the seperate line with - // "From ???@???" and we can forget them - while ( ! f.atEnd() && (l = f.readLine(line.data(),MAX_LINE)) && ((seperate = line.data()).left(5) != "From ")) { - tempfile.file()->writeBlock(line.data(), l); - if (inf->shouldTerminate()){ - tempfile.close(); - tempfile.unlink(); - return; - } - } - tempfile.close(); - if(inf->removeDupMsg) - addMessage( inf, folder, tempfile.name() ); - else - addMessage_fastImport( inf, folder, tempfile.name() ); - tempfile.unlink(); - - n++; - inf->setCurrent(i18n("Message %1").arg(n)); - inf->setCurrent( (int) ( ( (float) f.at() / f.size() ) * 100 ) ); - } - } - f.close(); -} - -/** Parse the information about folderstructure to folderMatrix */ -bool FilterPMail::parseFolderMatrix() -{ - kdDebug() << "Start parsing the foldermatrix." << endl; - inf->addLog(i18n("Parsing the folder structure...")); - - TQFile hierarch(chosenDir + "/hierarch.pm"); - if (! hierarch.open( IO_ReadOnly ) ) { - inf->alert( i18n("Unable to open %1, skipping").arg( chosenDir + "hierarch.pm" ) ); - return false; - } else { - TQStringList tmpList; - TQString tmpRead; - while ( !hierarch.atEnd() && hierarch.readLine(tmpRead,100)) { - TQString tmpArray[5]; - tmpRead.remove(tmpRead.length() -2,2); - TQStringList tmpList = TQStringList::split(",", tmpRead, false); - int i = 0; - for ( TQStringList::Iterator it = tmpList.begin(); it != tmpList.end(); ++it, i++) { - TQString _tmp = *it; - if(i < 5) tmpArray[i] = _tmp.remove("\""); - else { - hierarch.close(); - return false; - } - } - folderMatrix.append(tmpArray); - } - } - hierarch.close(); - return true; -} - -/** get the foldername for a given file ID from folderMatrix */ -TQString FilterPMail::getFolderName(TQString ID) -{ - bool found = false; - TQString folder; - TQString search = ID; - - while (!found) - { - for ( FolderStructureIterator it = folderMatrix.begin(); it != folderMatrix.end(); it++) { - FolderStructure tmp = *it; - - TQString _ID = tmp[2]; - if(_ID == search) { - TQString _type = tmp[0] + tmp[1]; - if(( _type == "21")) { - found = true; - break; - } - else { - folder.prepend((tmp[4] + "/")); - search = tmp[3]; - } - } - } - } - return folder; -} diff --git a/kmailcvt/filter_pmail.h b/kmailcvt/filter_pmail.h new file mode 100644 index 00000000..07f62a36 --- /dev/null +++ b/kmailcvt/filter_pmail.h @@ -0,0 +1,76 @@ +/*************************************************************************** + FilterPMail.h - Pegasus-Mail import + ------------------- + begin : Sat Jan 6 2001 + copyright : (C) 2001 by Holger Schurig + email : holgerschurig@gmx.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_PMAIL_H +#define FILTER_PMAIL_H + +#include +#include + +#include "filters.h" + +class FilterPMail : public Filter +{ +public: + FilterPMail(); + ~FilterPMail(); + + void import(FilterInfo *info); + +protected: + /** this looks for all files with the filemask 'mask' and calls the 'workFunc' on each of them */ + void processFiles(const TQString& mask, void(FilterPMail::* workFunc)(const TQString&) ); + /** this function imports one *.CNM message */ + void importNewMessage(const TQString& file); + /** this function imports one mail folder file (*.PMM) */ + void importMailFolder(const TQString& file); + /** imports a 'unix' format mail folder (*.MBX) */ + void importUnixMailFolder(const TQString& file); + /** this function recreate the folder structure */ + bool parseFolderMatrix(); + /** this function parse the folder structure */ + TQString getFolderName(TQString ID); + +private: + /** the working directory */ + TQDir dir; + /** pointer to the info */ + FilterInfo * inf; + + /** Folder structure here has 5 entries. */ + typedef FolderStructureBase<5> FolderStructure; + /** List with the folder matrix, which contains following strings: + 1. type (2 for root-folder, 1 for folder, 0 for mailarchiv) + 2. type (1 for root-folder, 3 for folder, 0 for mailarchiv) + 3. "ID:flag:filename" of folder/archiv + 4. "ID:name" of parent folder + 5. name of folder/archiv + */ + TQValueList folderMatrix; + typedef TQValueList::Iterator FolderStructureIterator; + + bool folderParsed; + + TQString chosenDir; + + /** which file (of totalFiles) is now in the work? */ + int currentFile; + /** total number of files that get imported */ + int totalFiles; + +}; +#endif diff --git a/kmailcvt/filter_pmail.hxx b/kmailcvt/filter_pmail.hxx deleted file mode 100644 index 664fdcc1..00000000 --- a/kmailcvt/filter_pmail.hxx +++ /dev/null @@ -1,76 +0,0 @@ -/*************************************************************************** - FilterPMail.hxx - Pegasus-Mail import - ------------------- - begin : Sat Jan 6 2001 - copyright : (C) 2001 by Holger Schurig - email : holgerschurig@gmx.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_PMAIL_HXX -#define FILTER_PMAIL_HXX - -#include -#include - -#include "filters.hxx" - -class FilterPMail : public Filter -{ -public: - FilterPMail(); - ~FilterPMail(); - - void import(FilterInfo *info); - -protected: - /** this looks for all files with the filemask 'mask' and calls the 'workFunc' on each of them */ - void processFiles(const TQString& mask, void(FilterPMail::* workFunc)(const TQString&) ); - /** this function imports one *.CNM message */ - void importNewMessage(const TQString& file); - /** this function imports one mail folder file (*.PMM) */ - void importMailFolder(const TQString& file); - /** imports a 'unix' format mail folder (*.MBX) */ - void importUnixMailFolder(const TQString& file); - /** this function recreate the folder structure */ - bool parseFolderMatrix(); - /** this function parse the folder structure */ - TQString getFolderName(TQString ID); - -private: - /** the working directory */ - TQDir dir; - /** pointer to the info */ - FilterInfo * inf; - - /** Folder structure here has 5 entries. */ - typedef FolderStructureBase<5> FolderStructure; - /** List with the folder matrix, which contains following strings: - 1. type (2 for root-folder, 1 for folder, 0 for mailarchiv) - 2. type (1 for root-folder, 3 for folder, 0 for mailarchiv) - 3. "ID:flag:filename" of folder/archiv - 4. "ID:name" of parent folder - 5. name of folder/archiv - */ - TQValueList folderMatrix; - typedef TQValueList::Iterator FolderStructureIterator; - - bool folderParsed; - - TQString chosenDir; - - /** which file (of totalFiles) is now in the work? */ - int currentFile; - /** total number of files that get imported */ - int totalFiles; - -}; -#endif diff --git a/kmailcvt/filter_sylpheed.cpp b/kmailcvt/filter_sylpheed.cpp new file mode 100644 index 00000000..e8f4a66a --- /dev/null +++ b/kmailcvt/filter_sylpheed.cpp @@ -0,0 +1,228 @@ +/*************************************************************************** + filter_sylpheed.h - Sylpheed maildir mail import + ------------------- + begin : April 07 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_sylpheed.h" + +#include +#include +#include +#include + +/** Default constructor. */ +FilterSylpheed::FilterSylpheed( void ) : + Filter( i18n( "Import Sylpheed Maildirs and Folder Structure" ), + "Danny Kukawka", + i18n( "

Sylpheed import filter

" + "

Select the base directory of the Sylpheed mailfolder you want to import " + "(usually: ~/Mail ).

" + "

Since it is possible to recreate the folder structure, the folders " + "will be stored under: \"Sylpheed-Import\" in your local folder.

" + "

This filter also recreates the status of message, e.g. new or forwarded.") ) +{} + +/** Destructor. */ +FilterSylpheed::~FilterSylpheed( void ) +{ +} + +/** Recursive import of Sylpheed maildir. */ +void FilterSylpheed::import( FilterInfo *info ) +{ + + TQString _homeDir = TQDir::homeDirPath(); + + KFileDialog *kfd; + kfd = new KFileDialog( _homeDir, "", 0, "tdefiledialog", true ); + kfd->setMode( KFile::Directory | KFile::LocalOnly ); + kfd->exec(); + mailDir = kfd->selectedFile(); + delete kfd; + + if ( mailDir.isEmpty() ) { + info->alert( i18n( "No directory selected." ) ); + } + /** + * If the user only select homedir no import needed because + * there should be no files and we surely import wrong files. + */ + else if ( mailDir == TQDir::homeDirPath() || mailDir == ( TQDir::homeDirPath() + "/" ) ) { + info->addLog( i18n( "No files found for import." ) ); + } else { + info->setOverall(0); + + /** Recursive import of the MailFolders */ + TQDir dir(mailDir); + TQStringList rootSubDirs = dir.entryList("[^\\.]*", TQDir::Dirs , TQDir::Name); + int currentDir = 1, numSubDirs = rootSubDirs.size(); + for(TQStringList::Iterator filename = rootSubDirs.begin() ; filename != rootSubDirs.end() ; ++filename, ++currentDir) { + if(info->shouldTerminate()) break; + importDirContents(info, dir.filePath(*filename)); + info->setOverall((int) ((float) currentDir / numSubDirs * 100)); + } + } + + info->addLog( i18n("Finished importing emails from %1").arg( mailDir )); + if (count_duplicates > 0) { + info->addLog( i18n("1 duplicate message not imported", "%n duplicate messages not imported", count_duplicates)); + } + if (info->shouldTerminate()) info->addLog( i18n("Finished import, canceled by user.")); + count_duplicates = 0; + info->setCurrent(100); + info->setOverall(100); +} + +/** + * Import of a directory contents. + * @param info Information storage for the operation. + * @param dirName The name of the directory to import. + */ +void FilterSylpheed::importDirContents( FilterInfo *info, const TQString& dirName) +{ + if(info->shouldTerminate()) return; + + /** Here Import all archives in the current dir */ + importFiles(info, dirName); + + /** If there are subfolders, we import them one by one */ + TQDir subfolders(dirName); + TQStringList subDirs = subfolders.entryList("[^\\.]*", TQDir::Dirs , TQDir::Name); + for(TQStringList::Iterator filename = subDirs.begin() ; filename != subDirs.end() ; ++filename) { + if(info->shouldTerminate()) return; + importDirContents(info, subfolders.filePath(*filename)); + } +} + + +/** + * Import the files within a Folder. + * @param info Information storage for the operation. + * @param dirName The name of the directory to import. + */ +void FilterSylpheed::importFiles( FilterInfo *info, const TQString& dirName) +{ + TQDir dir(dirName); + TQString _path; + bool generatedPath = false; + + TQDict msgflags; + msgflags.setAutoDelete(true); + + TQDir importDir (dirName); + TQStringList files = importDir.entryList("[^\\.]*", TQDir::Files, TQDir::Name); + int currentFile = 1, numFiles = files.size(); + + readMarkFile(info, dir.filePath(".sylpheed_mark"), msgflags); + + for ( TQStringList::Iterator mailFile = files.begin(); mailFile != files.end(); ++mailFile, ++currentFile) { + if(info->shouldTerminate()) return; + TQString _mfile = *mailFile; + if (!(_mfile.endsWith(".sylpheed_cache") || _mfile.endsWith(".sylpheed_mark") || _mfile.endsWith(".mh_sequences") )) { + if(!generatedPath) { + _path = "Sylpheed-Import/"; + TQString _tmp = dir.filePath(*mailFile); + _tmp = _tmp.remove(_tmp.length() - _mfile.length() -1, _mfile.length()+1); + _path += _tmp.remove( mailDir ,TRUE); + TQString _info = _path; + info->addLog(i18n("Import folder %1...").arg(_info.remove(0,15))); + + info->setFrom(_info); + info->setTo(_path); + generatedPath = true; + } + + TQString flags; + if (msgflags[_mfile]) + flags = msgFlagsToString(*(msgflags[_mfile])); + + if(info->removeDupMsg) { + if(! addMessage( info, _path, dir.filePath(*mailFile), flags )) { + info->addLog( i18n("Could not import %1").arg( *mailFile ) ); + } + info->setCurrent((int) ((float) currentFile / numFiles * 100)); + } else { + if(! addMessage_fastImport( info, _path, dir.filePath(*mailFile), flags )) { + info->addLog( i18n("Could not import %1").arg( *mailFile ) ); + } + info->setCurrent((int) ((float) currentFile / numFiles * 100)); + } + } + } +} + + +void FilterSylpheed::readMarkFile( FilterInfo *info, const TQString &path, TQDict &dict ) +{ + /* Each sylpheed mail directory contains a .sylpheed_mark file which + * contains all the flags for each messages. The layout of this file + * is documented in the source code of sylpheed: in procmsg.h for + * the flag bits, and procmsg.c. + * + * Note that the mark file stores 32 bit unsigned integers in the + * platform's native "endianness". + * + * The mark file starts with a 32 bit unsigned integer with a version + * number. It is then followed by pairs of 32 bit unsigned integers, + * the first one with the message file name (which is a number), + * and the second one with the actual message flags */ + + TQ_UINT32 in, flags; + TQFile file(path); + + if (!file.open(IO_ReadOnly)) + return; + + TQDataStream stream(&file); + + if (Q_BYTE_ORDER == Q_LITTLE_ENDIAN) + stream.setByteOrder(TQDataStream::LittleEndian); + + + + /* Read version; if the value is reasonably too big, we're looking + * at a file created on another platform. I don't have any test + * marks/folders, so just ignoring this case */ + stream >> in; + if (in > (TQ_UINT32) 0xffff) + return; + + while (!stream.atEnd()) { + if(info->shouldTerminate()){ + file.close(); + return; + } + stream >> in; + stream >> flags; + TQString s; + s.setNum((uint) in); + dict.insert(s, new unsigned long(flags)); + } +} + +TQString FilterSylpheed::msgFlagsToString(unsigned long flags) +{ + TQString status; + + /* see sylpheed's procmsg.h */ + if (flags & 1UL) status += 'N'; + if (flags & 2UL) status += 'U'; + if ((flags & 3UL) == 0UL) status += 'R'; + if (flags & 8UL) status += 'D'; + if (flags & 16UL) status += 'A'; + if (flags & 32UL) status += 'F'; + + return status; +} diff --git a/kmailcvt/filter_sylpheed.cxx b/kmailcvt/filter_sylpheed.cxx deleted file mode 100644 index 1fc008d4..00000000 --- a/kmailcvt/filter_sylpheed.cxx +++ /dev/null @@ -1,228 +0,0 @@ -/*************************************************************************** - filter_sylpheed.hxx - Sylpheed maildir mail import - ------------------- - begin : April 07 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_sylpheed.hxx" - -#include -#include -#include -#include - -/** Default constructor. */ -FilterSylpheed::FilterSylpheed( void ) : - Filter( i18n( "Import Sylpheed Maildirs and Folder Structure" ), - "Danny Kukawka", - i18n( "

Sylpheed import filter

" - "

Select the base directory of the Sylpheed mailfolder you want to import " - "(usually: ~/Mail ).

" - "

Since it is possible to recreate the folder structure, the folders " - "will be stored under: \"Sylpheed-Import\" in your local folder.

" - "

This filter also recreates the status of message, e.g. new or forwarded.") ) -{} - -/** Destructor. */ -FilterSylpheed::~FilterSylpheed( void ) -{ -} - -/** Recursive import of Sylpheed maildir. */ -void FilterSylpheed::import( FilterInfo *info ) -{ - - TQString _homeDir = TQDir::homeDirPath(); - - KFileDialog *kfd; - kfd = new KFileDialog( _homeDir, "", 0, "tdefiledialog", true ); - kfd->setMode( KFile::Directory | KFile::LocalOnly ); - kfd->exec(); - mailDir = kfd->selectedFile(); - delete kfd; - - if ( mailDir.isEmpty() ) { - info->alert( i18n( "No directory selected." ) ); - } - /** - * If the user only select homedir no import needed because - * there should be no files and we surely import wrong files. - */ - else if ( mailDir == TQDir::homeDirPath() || mailDir == ( TQDir::homeDirPath() + "/" ) ) { - info->addLog( i18n( "No files found for import." ) ); - } else { - info->setOverall(0); - - /** Recursive import of the MailFolders */ - TQDir dir(mailDir); - TQStringList rootSubDirs = dir.entryList("[^\\.]*", TQDir::Dirs , TQDir::Name); - int currentDir = 1, numSubDirs = rootSubDirs.size(); - for(TQStringList::Iterator filename = rootSubDirs.begin() ; filename != rootSubDirs.end() ; ++filename, ++currentDir) { - if(info->shouldTerminate()) break; - importDirContents(info, dir.filePath(*filename)); - info->setOverall((int) ((float) currentDir / numSubDirs * 100)); - } - } - - info->addLog( i18n("Finished importing emails from %1").arg( mailDir )); - if (count_duplicates > 0) { - info->addLog( i18n("1 duplicate message not imported", "%n duplicate messages not imported", count_duplicates)); - } - if (info->shouldTerminate()) info->addLog( i18n("Finished import, canceled by user.")); - count_duplicates = 0; - info->setCurrent(100); - info->setOverall(100); -} - -/** - * Import of a directory contents. - * @param info Information storage for the operation. - * @param dirName The name of the directory to import. - */ -void FilterSylpheed::importDirContents( FilterInfo *info, const TQString& dirName) -{ - if(info->shouldTerminate()) return; - - /** Here Import all archives in the current dir */ - importFiles(info, dirName); - - /** If there are subfolders, we import them one by one */ - TQDir subfolders(dirName); - TQStringList subDirs = subfolders.entryList("[^\\.]*", TQDir::Dirs , TQDir::Name); - for(TQStringList::Iterator filename = subDirs.begin() ; filename != subDirs.end() ; ++filename) { - if(info->shouldTerminate()) return; - importDirContents(info, subfolders.filePath(*filename)); - } -} - - -/** - * Import the files within a Folder. - * @param info Information storage for the operation. - * @param dirName The name of the directory to import. - */ -void FilterSylpheed::importFiles( FilterInfo *info, const TQString& dirName) -{ - TQDir dir(dirName); - TQString _path; - bool generatedPath = false; - - TQDict msgflags; - msgflags.setAutoDelete(true); - - TQDir importDir (dirName); - TQStringList files = importDir.entryList("[^\\.]*", TQDir::Files, TQDir::Name); - int currentFile = 1, numFiles = files.size(); - - readMarkFile(info, dir.filePath(".sylpheed_mark"), msgflags); - - for ( TQStringList::Iterator mailFile = files.begin(); mailFile != files.end(); ++mailFile, ++currentFile) { - if(info->shouldTerminate()) return; - TQString _mfile = *mailFile; - if (!(_mfile.endsWith(".sylpheed_cache") || _mfile.endsWith(".sylpheed_mark") || _mfile.endsWith(".mh_sequences") )) { - if(!generatedPath) { - _path = "Sylpheed-Import/"; - TQString _tmp = dir.filePath(*mailFile); - _tmp = _tmp.remove(_tmp.length() - _mfile.length() -1, _mfile.length()+1); - _path += _tmp.remove( mailDir ,TRUE); - TQString _info = _path; - info->addLog(i18n("Import folder %1...").arg(_info.remove(0,15))); - - info->setFrom(_info); - info->setTo(_path); - generatedPath = true; - } - - TQString flags; - if (msgflags[_mfile]) - flags = msgFlagsToString(*(msgflags[_mfile])); - - if(info->removeDupMsg) { - if(! addMessage( info, _path, dir.filePath(*mailFile), flags )) { - info->addLog( i18n("Could not import %1").arg( *mailFile ) ); - } - info->setCurrent((int) ((float) currentFile / numFiles * 100)); - } else { - if(! addMessage_fastImport( info, _path, dir.filePath(*mailFile), flags )) { - info->addLog( i18n("Could not import %1").arg( *mailFile ) ); - } - info->setCurrent((int) ((float) currentFile / numFiles * 100)); - } - } - } -} - - -void FilterSylpheed::readMarkFile( FilterInfo *info, const TQString &path, TQDict &dict ) -{ - /* Each sylpheed mail directory contains a .sylpheed_mark file which - * contains all the flags for each messages. The layout of this file - * is documented in the source code of sylpheed: in procmsg.h for - * the flag bits, and procmsg.c. - * - * Note that the mark file stores 32 bit unsigned integers in the - * platform's native "endianness". - * - * The mark file starts with a 32 bit unsigned integer with a version - * number. It is then followed by pairs of 32 bit unsigned integers, - * the first one with the message file name (which is a number), - * and the second one with the actual message flags */ - - TQ_UINT32 in, flags; - TQFile file(path); - - if (!file.open(IO_ReadOnly)) - return; - - TQDataStream stream(&file); - - if (Q_BYTE_ORDER == Q_LITTLE_ENDIAN) - stream.setByteOrder(TQDataStream::LittleEndian); - - - - /* Read version; if the value is reasonably too big, we're looking - * at a file created on another platform. I don't have any test - * marks/folders, so just ignoring this case */ - stream >> in; - if (in > (TQ_UINT32) 0xffff) - return; - - while (!stream.atEnd()) { - if(info->shouldTerminate()){ - file.close(); - return; - } - stream >> in; - stream >> flags; - TQString s; - s.setNum((uint) in); - dict.insert(s, new unsigned long(flags)); - } -} - -TQString FilterSylpheed::msgFlagsToString(unsigned long flags) -{ - TQString status; - - /* see sylpheed's procmsg.h */ - if (flags & 1UL) status += 'N'; - if (flags & 2UL) status += 'U'; - if ((flags & 3UL) == 0UL) status += 'R'; - if (flags & 8UL) status += 'D'; - if (flags & 16UL) status += 'A'; - if (flags & 32UL) status += 'F'; - - return status; -} diff --git a/kmailcvt/filter_sylpheed.h b/kmailcvt/filter_sylpheed.h new file mode 100644 index 00000000..1d92adf0 --- /dev/null +++ b/kmailcvt/filter_sylpheed.h @@ -0,0 +1,47 @@ +/*************************************************************************** + filter_sylpheed.h - Sylpheed maildir mail import + ------------------- + begin : April 07 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_SYLPHEED_H +#define FILTER_SYLPHEED_H + +#include + +#include "filters.h" + +/** + * Imports Sylpheed mail folder with maildir format recursively, recreating the folder structure. + * @author Danny Kukawka + */ +class FilterSylpheed : public Filter +{ + +public: + FilterSylpheed(void); + ~FilterSylpheed(void); + + void import(FilterInfo *info); + +private: + TQString mailDir; + + void importDirContents(FilterInfo*, const TQString&); + void importFiles(FilterInfo*, const TQString&); + + void readMarkFile( FilterInfo*, const TQString&, TQDict&); + TQString msgFlagsToString(unsigned long); +}; + +#endif diff --git a/kmailcvt/filter_sylpheed.hxx b/kmailcvt/filter_sylpheed.hxx deleted file mode 100644 index fcc3af85..00000000 --- a/kmailcvt/filter_sylpheed.hxx +++ /dev/null @@ -1,47 +0,0 @@ -/*************************************************************************** - filter_sylpheed.hxx - Sylpheed maildir mail import - ------------------- - begin : April 07 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_SYLPHEED_HXX -#define FILTER_SYLPHEED_HXX - -#include - -#include "filters.hxx" - -/** - * Imports Sylpheed mail folder with maildir format recursively, recreating the folder structure. - * @author Danny Kukawka - */ -class FilterSylpheed : public Filter -{ - -public: - FilterSylpheed(void); - ~FilterSylpheed(void); - - void import(FilterInfo *info); - -private: - TQString mailDir; - - void importDirContents(FilterInfo*, const TQString&); - void importFiles(FilterInfo*, const TQString&); - - void readMarkFile( FilterInfo*, const TQString&, TQDict&); - TQString msgFlagsToString(unsigned long); -}; - -#endif diff --git a/kmailcvt/filter_thebat.cpp b/kmailcvt/filter_thebat.cpp new file mode 100644 index 00000000..a255f352 --- /dev/null +++ b/kmailcvt/filter_thebat.cpp @@ -0,0 +1,231 @@ +/*************************************************************************** + filter_thebat.h - TheBat! mail import + ------------------- + begin : April 07 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_thebat.h" + +#include + +#include +#include + +#include +#include +#include + +#include + +/** Default constructor. */ +FilterTheBat::FilterTheBat( void ) : + Filter( i18n( "Import The Bat! Mails and Folder Structure" ), + "Danny Kukawka", + i18n( "

The Bat! import filter

" + "

Select the base directory of the \'The Bat!\' local mailfolder you " + "want to import.

" + "

Note: This filter imports the *.tbb-files from \'The Bat!\' " + "local folder, e.g. from POP accounts, and not from IMAP/DIMAP accounts.

" + "

Since it is possible to recreate the folder structure, the folders " + "will be stored under: \"TheBat-Import\" in your local account.

" ) ) +{} + +/** Destructor. */ +FilterTheBat::~FilterTheBat( void ) +{ +} + +/** Recursive import of The Bat! maildir. */ +void FilterTheBat::import( FilterInfo *info ) +{ + TQString _homeDir = TQDir::homeDirPath(); + + KFileDialog *kfd; + kfd = new KFileDialog( _homeDir, "", 0, "tdefiledialog", true ); + kfd->setMode( KFile::Directory | KFile::LocalOnly ); + kfd->exec(); + mailDir = kfd->selectedFile(); + delete kfd; + + if ( mailDir.isEmpty() ) { + info->alert( i18n( "No directory selected." ) ); + } + /** + * If the user only select homedir no import needed because + * there should be no files and we surely import wrong files. + */ + else if ( mailDir == TQDir::homeDirPath() || mailDir == ( TQDir::homeDirPath() + "/" ) ) { + info->addLog( i18n( "No files found for import." ) ); + } else { + info->setOverall(0); + + /** Recursive import of the MailFolders */ + TQDir dir(mailDir); + TQStringList rootSubDirs = dir.entryList("[^\\.]*", TQDir::Dirs , TQDir::Name); + int currentDir = 1, numSubDirs = rootSubDirs.size(); + for(TQStringList::Iterator filename = rootSubDirs.begin() ; filename != rootSubDirs.end() ; ++filename, ++currentDir) { + importDirContents(info, dir.filePath(*filename)); + info->setOverall((int) ((float) currentDir / numSubDirs * 100)); + if(info->shouldTerminate()) break; + } + } + + info->addLog( i18n("Finished importing emails from %1").arg( mailDir )); + if (count_duplicates > 0) { + info->addLog( i18n("1 duplicate message not imported", "%n duplicate messages not imported", count_duplicates)); + } + if (info->shouldTerminate()) info->addLog( i18n("Finished import, canceled by user.")); + + count_duplicates = 0; + info->setCurrent(100); + info->setOverall(100); +} + +/** + * Import of a directory contents. + * @param info Information storage for the operation. + * @param dirName The name of the directory to import. + */ +void FilterTheBat::importDirContents( FilterInfo *info, const TQString& dirName) +{ + if(info->shouldTerminate()) return; + + /** Here Import all archives in the current dir */ + TQDir dir(dirName); + TQDir importDir (dirName); + TQStringList files = importDir.entryList("*.[tT][bB][bB]", TQDir::Files, TQDir::Name); + for ( TQStringList::Iterator mailFile = files.begin(); mailFile != files.end(); ++mailFile) { + TQString temp_mailfile = *mailFile; + importFiles(info, (dirName + "/" + temp_mailfile)); + if(info->shouldTerminate()) return; + } + + /** If there are subfolders, we import them one by one */ + TQDir subfolders(dirName); + TQStringList subDirs = subfolders.entryList("[^\\.]*", TQDir::Dirs , TQDir::Name); + for(TQStringList::Iterator filename = subDirs.begin() ; filename != subDirs.end() ; ++filename) { + importDirContents(info, subfolders.filePath(*filename)); + if(info->shouldTerminate()) return; + } +} + +/** + * Import the files within a Folder. + * @param info Information storage for the operation. + * @param dirName The name of the directory to import. + */ +void FilterTheBat::importFiles( FilterInfo *info, const TQString& FileName) +{ + + // Format of a tbb-file from The Bat! 3.x + // ---------------------------------------- + // First comes a header of 3K (3128 byte/ 0x00000c38), which we can forget. + // The byte 3129 is the first character of the first message. + // + // The end of a message is marked trough "! p 0" and 43 following characters. + // (within: "_UB", blanks and some other chars.) Together are 48 characters as + // separator. + // ---------------------------------------- + + long l = 0; + TQByteArray input(50); + TQRegExp regexp("!.p.0"); + TQFile tbb(FileName); + int iFound = 0; + int count = 0; + long endOfEmail = 0; + TQValueList offsets; + + if (!tbb.open(IO_ReadOnly)) { + info->alert(i18n("Unable to open %1, skipping").arg(FileName)); + } else { + // BUILD the index of messages : + // We need this really ugly way, because read with tbb.readLine() + // does not work correct. Maybe in come in a continuous loop !!! + // Reason: + // if you use readLine() to read from a file with binary data + // TQFile::at() and TQFile::atEnd() return wrong value. So we + // never get TQFile::atEnd() == true in some cases. This looks + // like a bug in TQt3 maybe fixed in TQt4. + // + while((l = tbb.readBlock(input.data(),50)) ) { + if(info->shouldTerminate()) { + tbb.close(); + return; + } + TQString _tmp = input.data(); + + if (tbb.atEnd()) + break; + + iFound = _tmp.contains(regexp); + if(!iFound) { + iFound = _tmp.findRev("!"); + if (iFound >= 0 && ((l-iFound) < 5) ) { + int _i = tbb.at(); + tbb.at((_i - iFound)); + } + } else { + ++count; + endOfEmail = (tbb.at() - l + _tmp.find(regexp)); + offsets.append(endOfEmail); + } + } + // info->addLog(i18n("--COUNTED: %1").arg(count)); + + // IMPORT the messages: + if(!offsets.empty() || (offsets.empty() && (tbb.size() > 3128))) { + offsets.append(tbb.size()); + tbb.at(3128); + long lastPos = 3128; + long endPos = 0; + + TQString _path = "TheBat-Import/"; + TQString _tmp = FileName; + _tmp = _tmp.remove(_tmp.length() - 13, 13); + _path += _tmp.remove( mailDir ,TRUE); + TQString _info = _path; + info->addLog(i18n("Import folder %1...").arg(_info.remove(0,14))); + info->setTo(_path); + info->setFrom("../" + _info + "/messages.tbb"); + + for(TQValueList::Iterator it = offsets.begin() ; it != offsets.end() ; ++it) { + if(info->shouldTerminate()) { + tbb.close(); + return; + } + endPos = *it; + TQByteArray input(endPos-lastPos); + tbb.readBlock(input.data(), endPos-lastPos); + + KTempFile tmp; + tmp.file()->writeBlock( input, endPos-lastPos ); + tmp.close(); + + //KMessageBox::warningContinueCancel(info->parent(), ""); + if(info->removeDupMsg) + addMessage( info, _path, tmp.name() ); + else + addMessage_fastImport( info, _path, tmp.name() ); + + tmp.unlink(); + lastPos = endPos + 48; + tbb.at(lastPos); + info->setCurrent( (int) ( ( (float) tbb.at() / tbb.size() ) * 100 )); + } + + } + } + tbb.close(); +} diff --git a/kmailcvt/filter_thebat.cxx b/kmailcvt/filter_thebat.cxx deleted file mode 100644 index eaf16461..00000000 --- a/kmailcvt/filter_thebat.cxx +++ /dev/null @@ -1,231 +0,0 @@ -/*************************************************************************** - filter_thebat.hxx - TheBat! mail import - ------------------- - begin : April 07 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_thebat.hxx" - -#include - -#include -#include - -#include -#include -#include - -#include - -/** Default constructor. */ -FilterTheBat::FilterTheBat( void ) : - Filter( i18n( "Import The Bat! Mails and Folder Structure" ), - "Danny Kukawka", - i18n( "

The Bat! import filter

" - "

Select the base directory of the \'The Bat!\' local mailfolder you " - "want to import.

" - "

Note: This filter imports the *.tbb-files from \'The Bat!\' " - "local folder, e.g. from POP accounts, and not from IMAP/DIMAP accounts.

" - "

Since it is possible to recreate the folder structure, the folders " - "will be stored under: \"TheBat-Import\" in your local account.

" ) ) -{} - -/** Destructor. */ -FilterTheBat::~FilterTheBat( void ) -{ -} - -/** Recursive import of The Bat! maildir. */ -void FilterTheBat::import( FilterInfo *info ) -{ - TQString _homeDir = TQDir::homeDirPath(); - - KFileDialog *kfd; - kfd = new KFileDialog( _homeDir, "", 0, "tdefiledialog", true ); - kfd->setMode( KFile::Directory | KFile::LocalOnly ); - kfd->exec(); - mailDir = kfd->selectedFile(); - delete kfd; - - if ( mailDir.isEmpty() ) { - info->alert( i18n( "No directory selected." ) ); - } - /** - * If the user only select homedir no import needed because - * there should be no files and we surely import wrong files. - */ - else if ( mailDir == TQDir::homeDirPath() || mailDir == ( TQDir::homeDirPath() + "/" ) ) { - info->addLog( i18n( "No files found for import." ) ); - } else { - info->setOverall(0); - - /** Recursive import of the MailFolders */ - TQDir dir(mailDir); - TQStringList rootSubDirs = dir.entryList("[^\\.]*", TQDir::Dirs , TQDir::Name); - int currentDir = 1, numSubDirs = rootSubDirs.size(); - for(TQStringList::Iterator filename = rootSubDirs.begin() ; filename != rootSubDirs.end() ; ++filename, ++currentDir) { - importDirContents(info, dir.filePath(*filename)); - info->setOverall((int) ((float) currentDir / numSubDirs * 100)); - if(info->shouldTerminate()) break; - } - } - - info->addLog( i18n("Finished importing emails from %1").arg( mailDir )); - if (count_duplicates > 0) { - info->addLog( i18n("1 duplicate message not imported", "%n duplicate messages not imported", count_duplicates)); - } - if (info->shouldTerminate()) info->addLog( i18n("Finished import, canceled by user.")); - - count_duplicates = 0; - info->setCurrent(100); - info->setOverall(100); -} - -/** - * Import of a directory contents. - * @param info Information storage for the operation. - * @param dirName The name of the directory to import. - */ -void FilterTheBat::importDirContents( FilterInfo *info, const TQString& dirName) -{ - if(info->shouldTerminate()) return; - - /** Here Import all archives in the current dir */ - TQDir dir(dirName); - TQDir importDir (dirName); - TQStringList files = importDir.entryList("*.[tT][bB][bB]", TQDir::Files, TQDir::Name); - for ( TQStringList::Iterator mailFile = files.begin(); mailFile != files.end(); ++mailFile) { - TQString temp_mailfile = *mailFile; - importFiles(info, (dirName + "/" + temp_mailfile)); - if(info->shouldTerminate()) return; - } - - /** If there are subfolders, we import them one by one */ - TQDir subfolders(dirName); - TQStringList subDirs = subfolders.entryList("[^\\.]*", TQDir::Dirs , TQDir::Name); - for(TQStringList::Iterator filename = subDirs.begin() ; filename != subDirs.end() ; ++filename) { - importDirContents(info, subfolders.filePath(*filename)); - if(info->shouldTerminate()) return; - } -} - -/** - * Import the files within a Folder. - * @param info Information storage for the operation. - * @param dirName The name of the directory to import. - */ -void FilterTheBat::importFiles( FilterInfo *info, const TQString& FileName) -{ - - // Format of a tbb-file from The Bat! 3.x - // ---------------------------------------- - // First comes a header of 3K (3128 byte/ 0x00000c38), which we can forget. - // The byte 3129 is the first character of the first message. - // - // The end of a message is marked trough "! p 0" and 43 following characters. - // (within: "_UB", blanks and some other chars.) Together are 48 characters as - // separator. - // ---------------------------------------- - - long l = 0; - TQByteArray input(50); - TQRegExp regexp("!.p.0"); - TQFile tbb(FileName); - int iFound = 0; - int count = 0; - long endOfEmail = 0; - TQValueList offsets; - - if (!tbb.open(IO_ReadOnly)) { - info->alert(i18n("Unable to open %1, skipping").arg(FileName)); - } else { - // BUILD the index of messages : - // We need this really ugly way, because read with tbb.readLine() - // does not work correct. Maybe in come in a continuous loop !!! - // Reason: - // if you use readLine() to read from a file with binary data - // TQFile::at() and TQFile::atEnd() return wrong value. So we - // never get TQFile::atEnd() == true in some cases. This looks - // like a bug in TQt3 maybe fixed in TQt4. - // - while((l = tbb.readBlock(input.data(),50)) ) { - if(info->shouldTerminate()) { - tbb.close(); - return; - } - TQString _tmp = input.data(); - - if (tbb.atEnd()) - break; - - iFound = _tmp.contains(regexp); - if(!iFound) { - iFound = _tmp.findRev("!"); - if (iFound >= 0 && ((l-iFound) < 5) ) { - int _i = tbb.at(); - tbb.at((_i - iFound)); - } - } else { - ++count; - endOfEmail = (tbb.at() - l + _tmp.find(regexp)); - offsets.append(endOfEmail); - } - } - // info->addLog(i18n("--COUNTED: %1").arg(count)); - - // IMPORT the messages: - if(!offsets.empty() || (offsets.empty() && (tbb.size() > 3128))) { - offsets.append(tbb.size()); - tbb.at(3128); - long lastPos = 3128; - long endPos = 0; - - TQString _path = "TheBat-Import/"; - TQString _tmp = FileName; - _tmp = _tmp.remove(_tmp.length() - 13, 13); - _path += _tmp.remove( mailDir ,TRUE); - TQString _info = _path; - info->addLog(i18n("Import folder %1...").arg(_info.remove(0,14))); - info->setTo(_path); - info->setFrom("../" + _info + "/messages.tbb"); - - for(TQValueList::Iterator it = offsets.begin() ; it != offsets.end() ; ++it) { - if(info->shouldTerminate()) { - tbb.close(); - return; - } - endPos = *it; - TQByteArray input(endPos-lastPos); - tbb.readBlock(input.data(), endPos-lastPos); - - KTempFile tmp; - tmp.file()->writeBlock( input, endPos-lastPos ); - tmp.close(); - - //KMessageBox::warningContinueCancel(info->parent(), ""); - if(info->removeDupMsg) - addMessage( info, _path, tmp.name() ); - else - addMessage_fastImport( info, _path, tmp.name() ); - - tmp.unlink(); - lastPos = endPos + 48; - tbb.at(lastPos); - info->setCurrent( (int) ( ( (float) tbb.at() / tbb.size() ) * 100 )); - } - - } - } - tbb.close(); -} diff --git a/kmailcvt/filter_thebat.h b/kmailcvt/filter_thebat.h new file mode 100644 index 00000000..ef69c231 --- /dev/null +++ b/kmailcvt/filter_thebat.h @@ -0,0 +1,42 @@ +/*************************************************************************** + filter_thebat.h - TheBat! mail import + ------------------- + begin : April 07 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_THEBAT_H +#define FILTER_THEBAT_H + +#include "filters.h" + +/** + * Imports The Bat! mail folder recursively, recreating the folder structure. + * @author Danny Kukawka + */ +class FilterTheBat : public Filter +{ + +public: + FilterTheBat(void); + ~FilterTheBat(void); + + void import(FilterInfo *info); + +private: + TQString mailDir; + + void importDirContents(FilterInfo*, const TQString&); + void importFiles(FilterInfo*, const TQString&); +}; + +#endif diff --git a/kmailcvt/filter_thebat.hxx b/kmailcvt/filter_thebat.hxx deleted file mode 100644 index 7d62018d..00000000 --- a/kmailcvt/filter_thebat.hxx +++ /dev/null @@ -1,42 +0,0 @@ -/*************************************************************************** - filter_thebat.hxx - TheBat! mail import - ------------------- - begin : April 07 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_THEBAT_HXX -#define FILTER_THEBAT_HXX - -#include "filters.hxx" - -/** - * Imports The Bat! mail folder recursively, recreating the folder structure. - * @author Danny Kukawka - */ -class FilterTheBat : public Filter -{ - -public: - FilterTheBat(void); - ~FilterTheBat(void); - - void import(FilterInfo *info); - -private: - TQString mailDir; - - void importDirContents(FilterInfo*, const TQString&); - void importFiles(FilterInfo*, const TQString&); -}; - -#endif diff --git a/kmailcvt/filter_thunderbird.cpp b/kmailcvt/filter_thunderbird.cpp new file mode 100644 index 00000000..e5f21d14 --- /dev/null +++ b/kmailcvt/filter_thunderbird.cpp @@ -0,0 +1,234 @@ +/*************************************************************************** + filter_thunderbird.cpp - 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.h" + +#include +#include +#include +#include + + +/** Default constructor. */ +FilterThunderbird::FilterThunderbird(void) : + Filter(i18n("Import Thunderbird/Mozilla Local Mails and Folder Structure"), + "Danny Kukawka", + i18n("

Thunderbird/Mozilla import filter

" + "

Select your base Thunderbird/Mozilla mailfolder" + " (usually ~/.thunderbird/*.default/Mail/Local Folders/).

" + "

Note: Never choose a Folder which does not contain mbox-files (for example," + " a maildir): if you do, you will get many new folders.

" + "

Since it is possible to recreate the folder structure, the folders " + "will be stored under: \"Thunderbird-Import\".

")) +{} + +/** Destructor. */ +FilterThunderbird::~FilterThunderbird(void) +{ +} + +/** 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/xxxx.default/Mail/Local Folders/ + */ + TQString thunderDir = TQDir::homeDirPath() + "/.thunderbird/"; + TQDir d( thunderDir ); + if ( !d.exists() ) { + thunderDir = TQDir::homeDirPath(); + } + + KFileDialog *kfd; + kfd = new KFileDialog( thunderDir, "", 0, "tdefiledialog", true ); + kfd->setMode(KFile::Directory | KFile::LocalOnly); + kfd->exec(); + mailDir = kfd->selectedFile(); + delete kfd; + + if (mailDir.isEmpty()) { + info->alert(i18n("No directory selected.")); + } + /** + * If the user only select homedir no import needed because + * there should be no files and we surely import wrong files. + */ + else if ( mailDir == TQDir::homeDirPath() || mailDir == (TQDir::homeDirPath() + "/")) { + info->addLog(i18n("No files found for import.")); + } else { + info->setOverall(0); + + /** Recursive import of the MailArchives */ + TQDir dir(mailDir); + TQStringList rootSubDirs = dir.entryList("[^\\.]*", TQDir::Dirs, TQDir::Name); // Removal of . and .. + int currentDir = 1, numSubDirs = rootSubDirs.size(); + for(TQStringList::Iterator filename = rootSubDirs.begin() ; filename != rootSubDirs.end() ; ++filename, ++currentDir) { + if(info->shouldTerminate()) break; + importDirContents(info, dir.filePath(*filename), *filename, *filename); + info->setOverall((int) ((float) currentDir / numSubDirs * 100)); + } + + /** import last but not least all archives from the root-dir */ + TQDir importDir (mailDir); + TQStringList files = importDir.entryList("[^\\.]*", TQDir::Files, TQDir::Name); + for ( TQStringList::Iterator mailFile = files.begin(); mailFile != files.end(); ++mailFile) { + if(info->shouldTerminate()) break; + TQString temp_mailfile = *mailFile; + if (temp_mailfile.endsWith(".msf") || temp_mailfile.endsWith("msgFilterRules.dat")) {} + else { + info->addLog( i18n("Start import file %1...").arg( temp_mailfile ) ); + importMBox(info, mailDir + temp_mailfile , temp_mailfile, TQString()); + } + } + + info->addLog( i18n("Finished importing emails from %1").arg( mailDir )); + if(count_duplicates > 0) { + info->addLog( i18n("1 duplicate message not imported", "%n duplicate messages not imported", count_duplicates)); + } + } + if (info->shouldTerminate()) info->addLog( i18n("Finished import, canceled by user.")); + info->setCurrent(100); + info->setOverall(100); +} + +/** + * 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 TQString& dirName, const TQString& KMailRootDir, const TQString& KMailSubDir) +{ + if(info->shouldTerminate()) return; + /** Here Import all archives in the current dir */ + TQDir dir(dirName); + + TQDir importDir (dirName); + TQStringList files = importDir.entryList("[^\\.]*", TQDir::Files, TQDir::Name); + for ( TQStringList::Iterator mailFile = files.begin(); mailFile != files.end(); ++mailFile) { + if(info->shouldTerminate()) break; + TQString temp_mailfile = *mailFile; + if (temp_mailfile.endsWith(".msf") || temp_mailfile.endsWith("msgFilterRules.dat")) {} + 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 */ + TQDir subfolders(dirName); + TQStringList subDirs = subfolders.entryList("[^\\.]*", TQDir::Dirs, TQDir::Name); + for(TQStringList::Iterator filename = subDirs.begin() ; filename != subDirs.end() ; ++filename) { + if(info->shouldTerminate()) break; + TQString 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 TQString& mboxName, const TQString& rootDir, const TQString& targetDir) +{ + TQFile mbox(mboxName); + bool first_msg = true; + if (!mbox.open(IO_ReadOnly)) { + info->alert(i18n("Unable to open %1, skipping").arg(mboxName)); + } else { + TQFileInfo filenameInfo(mboxName); + + info->setCurrent(0); + if( mboxName.length() > 20 ) { + TQString tmp_info = mboxName; + tmp_info = tmp_info.replace( mailDir, "../" ); + if (tmp_info.contains(".sbd")) + tmp_info.remove(".sbd"); + info->setFrom( tmp_info ); + } else + info->setFrom(mboxName); + if(targetDir.contains(".sbd")) { + TQString tmp_info = targetDir; + tmp_info.remove(".sbd"); + info->setTo(tmp_info); + } else + info->setTo(targetDir); + + TQByteArray input(MAX_LINE); + long l = 0; + + while (!mbox.atEnd()) { + KTempFile tmp; + /** @todo check if the file is really a mbox, maybe search for 'from' string at start */ + /* comment by Danny: + * Don't use TQTextStream to read from mbox, etter use TQDataStream. TQTextStream only + * support Unicode/Latin1/Locale. So you lost information from emails with + * charset!=Unicode/Latin1/Locale (e.g. KOI8-R) and Content-Transfer-Encoding != base64 + * (e.g. 8Bit). It also not help to convert the TQTextStream to Unicode. By this you + * get Unicode/UTF-email but KMail can't detect the correct charset. + */ + TQCString seperate; + + if(!first_msg) + tmp.file()->writeBlock( input, l ); + l = mbox.readLine( input.data(),MAX_LINE); // read the first line, prevent "From " + tmp.file()->writeBlock( input, l ); + + while ( ! mbox.atEnd() && (l = mbox.readLine(input.data(),MAX_LINE)) && ((seperate = input.data()).left(5) != "From ")) { + tmp.file()->writeBlock( input, l ); + } + tmp.close(); + first_msg = false; + + TQString destFolder; + TQString _targetDir = targetDir; + if(!targetDir.isNull()) { + if(_targetDir.contains(".sbd")) + _targetDir.remove(".sbd"); + destFolder += "Thunderbird-Import/" + _targetDir + "/" + filenameInfo.baseName(TRUE);// mboxName; + } else { + destFolder = "Thunderbird-Import/" + rootDir; + if(destFolder.contains(".sbd")) + destFolder.remove(".sbd"); + } + + 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()) { + mbox.close(); + return; + } + } + mbox.close(); + } +} diff --git a/kmailcvt/filter_thunderbird.cxx b/kmailcvt/filter_thunderbird.cxx deleted file mode 100644 index 50f6355f..00000000 --- a/kmailcvt/filter_thunderbird.cxx +++ /dev/null @@ -1,234 +0,0 @@ -/*************************************************************************** - 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 -#include -#include -#include - - -/** Default constructor. */ -FilterThunderbird::FilterThunderbird(void) : - Filter(i18n("Import Thunderbird/Mozilla Local Mails and Folder Structure"), - "Danny Kukawka", - i18n("

Thunderbird/Mozilla import filter

" - "

Select your base Thunderbird/Mozilla mailfolder" - " (usually ~/.thunderbird/*.default/Mail/Local Folders/).

" - "

Note: Never choose a Folder which does not contain mbox-files (for example," - " a maildir): if you do, you will get many new folders.

" - "

Since it is possible to recreate the folder structure, the folders " - "will be stored under: \"Thunderbird-Import\".

")) -{} - -/** Destructor. */ -FilterThunderbird::~FilterThunderbird(void) -{ -} - -/** 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/xxxx.default/Mail/Local Folders/ - */ - TQString thunderDir = TQDir::homeDirPath() + "/.thunderbird/"; - TQDir d( thunderDir ); - if ( !d.exists() ) { - thunderDir = TQDir::homeDirPath(); - } - - KFileDialog *kfd; - kfd = new KFileDialog( thunderDir, "", 0, "tdefiledialog", true ); - kfd->setMode(KFile::Directory | KFile::LocalOnly); - kfd->exec(); - mailDir = kfd->selectedFile(); - delete kfd; - - if (mailDir.isEmpty()) { - info->alert(i18n("No directory selected.")); - } - /** - * If the user only select homedir no import needed because - * there should be no files and we surely import wrong files. - */ - else if ( mailDir == TQDir::homeDirPath() || mailDir == (TQDir::homeDirPath() + "/")) { - info->addLog(i18n("No files found for import.")); - } else { - info->setOverall(0); - - /** Recursive import of the MailArchives */ - TQDir dir(mailDir); - TQStringList rootSubDirs = dir.entryList("[^\\.]*", TQDir::Dirs, TQDir::Name); // Removal of . and .. - int currentDir = 1, numSubDirs = rootSubDirs.size(); - for(TQStringList::Iterator filename = rootSubDirs.begin() ; filename != rootSubDirs.end() ; ++filename, ++currentDir) { - if(info->shouldTerminate()) break; - importDirContents(info, dir.filePath(*filename), *filename, *filename); - info->setOverall((int) ((float) currentDir / numSubDirs * 100)); - } - - /** import last but not least all archives from the root-dir */ - TQDir importDir (mailDir); - TQStringList files = importDir.entryList("[^\\.]*", TQDir::Files, TQDir::Name); - for ( TQStringList::Iterator mailFile = files.begin(); mailFile != files.end(); ++mailFile) { - if(info->shouldTerminate()) break; - TQString temp_mailfile = *mailFile; - if (temp_mailfile.endsWith(".msf") || temp_mailfile.endsWith("msgFilterRules.dat")) {} - else { - info->addLog( i18n("Start import file %1...").arg( temp_mailfile ) ); - importMBox(info, mailDir + temp_mailfile , temp_mailfile, TQString()); - } - } - - info->addLog( i18n("Finished importing emails from %1").arg( mailDir )); - if(count_duplicates > 0) { - info->addLog( i18n("1 duplicate message not imported", "%n duplicate messages not imported", count_duplicates)); - } - } - if (info->shouldTerminate()) info->addLog( i18n("Finished import, canceled by user.")); - info->setCurrent(100); - info->setOverall(100); -} - -/** - * 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 TQString& dirName, const TQString& KMailRootDir, const TQString& KMailSubDir) -{ - if(info->shouldTerminate()) return; - /** Here Import all archives in the current dir */ - TQDir dir(dirName); - - TQDir importDir (dirName); - TQStringList files = importDir.entryList("[^\\.]*", TQDir::Files, TQDir::Name); - for ( TQStringList::Iterator mailFile = files.begin(); mailFile != files.end(); ++mailFile) { - if(info->shouldTerminate()) break; - TQString temp_mailfile = *mailFile; - if (temp_mailfile.endsWith(".msf") || temp_mailfile.endsWith("msgFilterRules.dat")) {} - 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 */ - TQDir subfolders(dirName); - TQStringList subDirs = subfolders.entryList("[^\\.]*", TQDir::Dirs, TQDir::Name); - for(TQStringList::Iterator filename = subDirs.begin() ; filename != subDirs.end() ; ++filename) { - if(info->shouldTerminate()) break; - TQString 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 TQString& mboxName, const TQString& rootDir, const TQString& targetDir) -{ - TQFile mbox(mboxName); - bool first_msg = true; - if (!mbox.open(IO_ReadOnly)) { - info->alert(i18n("Unable to open %1, skipping").arg(mboxName)); - } else { - TQFileInfo filenameInfo(mboxName); - - info->setCurrent(0); - if( mboxName.length() > 20 ) { - TQString tmp_info = mboxName; - tmp_info = tmp_info.replace( mailDir, "../" ); - if (tmp_info.contains(".sbd")) - tmp_info.remove(".sbd"); - info->setFrom( tmp_info ); - } else - info->setFrom(mboxName); - if(targetDir.contains(".sbd")) { - TQString tmp_info = targetDir; - tmp_info.remove(".sbd"); - info->setTo(tmp_info); - } else - info->setTo(targetDir); - - TQByteArray input(MAX_LINE); - long l = 0; - - while (!mbox.atEnd()) { - KTempFile tmp; - /** @todo check if the file is really a mbox, maybe search for 'from' string at start */ - /* comment by Danny: - * Don't use TQTextStream to read from mbox, etter use TQDataStream. TQTextStream only - * support Unicode/Latin1/Locale. So you lost information from emails with - * charset!=Unicode/Latin1/Locale (e.g. KOI8-R) and Content-Transfer-Encoding != base64 - * (e.g. 8Bit). It also not help to convert the TQTextStream to Unicode. By this you - * get Unicode/UTF-email but KMail can't detect the correct charset. - */ - TQCString seperate; - - if(!first_msg) - tmp.file()->writeBlock( input, l ); - l = mbox.readLine( input.data(),MAX_LINE); // read the first line, prevent "From " - tmp.file()->writeBlock( input, l ); - - while ( ! mbox.atEnd() && (l = mbox.readLine(input.data(),MAX_LINE)) && ((seperate = input.data()).left(5) != "From ")) { - tmp.file()->writeBlock( input, l ); - } - tmp.close(); - first_msg = false; - - TQString destFolder; - TQString _targetDir = targetDir; - if(!targetDir.isNull()) { - if(_targetDir.contains(".sbd")) - _targetDir.remove(".sbd"); - destFolder += "Thunderbird-Import/" + _targetDir + "/" + filenameInfo.baseName(TRUE);// mboxName; - } else { - destFolder = "Thunderbird-Import/" + rootDir; - if(destFolder.contains(".sbd")) - destFolder.remove(".sbd"); - } - - 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()) { - mbox.close(); - return; - } - } - mbox.close(); - } -} diff --git a/kmailcvt/filter_thunderbird.h b/kmailcvt/filter_thunderbird.h new file mode 100644 index 00000000..333e2380 --- /dev/null +++ b/kmailcvt/filter_thunderbird.h @@ -0,0 +1,42 @@ +/*************************************************************************** + filter_thunderbird.h - 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_H +#define FILTER_THUNDERBIRD_H + +#include "filters.h" + +/** + * 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: + TQString mailDir; + + void importDirContents(FilterInfo*, const TQString&, const TQString&, const TQString&); + void importMBox(FilterInfo*, const TQString&, const TQString&, const TQString&); +}; + +#endif diff --git a/kmailcvt/filter_thunderbird.hxx b/kmailcvt/filter_thunderbird.hxx deleted file mode 100644 index d3bcd7f9..00000000 --- a/kmailcvt/filter_thunderbird.hxx +++ /dev/null @@ -1,42 +0,0 @@ -/*************************************************************************** - 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: - TQString mailDir; - - void importDirContents(FilterInfo*, const TQString&, const TQString&, const TQString&); - void importMBox(FilterInfo*, const TQString&, const TQString&, const TQString&); -}; - -#endif diff --git a/kmailcvt/filters.cpp b/kmailcvt/filters.cpp new file mode 100644 index 00000000..2c43ff43 --- /dev/null +++ b/kmailcvt/filters.cpp @@ -0,0 +1,216 @@ +/*************************************************************************** + filters.cpp - description + ------------------- + begin : Fri Jun 30 2000 + copyright : (C) 2000 by Hans Dijkema + email : kmailcvt@hum.org + ***************************************************************************/ + +/*************************************************************************** + * * + * 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 +#include +#include +#include +#include +#include + +#include "filters.h" +#include "kmailcvt.h" + + +////////////////////////////////////////////////////////////////////////////////// +// +// The API to the kmailcvt dialog --> Gives the import filter access to +// put information on the dialog. +// +////////////////////////////////////////////////////////////////////////////////// + +bool FilterInfo::s_terminateASAP = false; + +FilterInfo::FilterInfo( KImportPageDlg* dlg, TQWidget* parent , bool _removeDupMsg) + : m_dlg( dlg ), + m_parent( parent ) +{ + removeDupMsg = _removeDupMsg; + s_terminateASAP = false; +} + +FilterInfo::~FilterInfo() +{ +} + +void FilterInfo::setStatusMsg( const TQString& status ) +{ + m_dlg->_texStatus->setText( status ); +} + +void FilterInfo::setFrom( const TQString& from ) +{ + m_dlg->_from->setText( from ); +} + +void FilterInfo::setTo( const TQString& to ) +{ + m_dlg->_to->setText( to ); +} + +void FilterInfo::setCurrent( const TQString& current ) +{ + m_dlg->_current->setText( current ); + kapp->processEvents(); +} + +void FilterInfo::setCurrent( int percent ) +{ + m_dlg->_done_current->setProgress( percent ); + kapp->processEvents(); // Be careful - back & finish buttons disabled, so only user event that can happen is cancel/close button +} + +void FilterInfo::setOverall( int percent ) +{ + m_dlg->_done_overall->setProgress( percent ); +} + +void FilterInfo::addLog( const TQString& log ) +{ + m_dlg->_log->insertItem( log ); + m_dlg->_log->setCurrentItem( m_dlg->_log->count() - 1 ); + m_dlg->_log->centerCurrentItem(); + kapp->processEvents(); +} + +void FilterInfo::clear() +{ + m_dlg->_log->clear(); + setCurrent(); + setOverall(); + setCurrent( TQString() ); + setFrom( TQString() ); + setTo( TQString() ); +} + +void FilterInfo::alert( const TQString& message ) +{ + KMessageBox::information( m_parent, message ); +} + +void FilterInfo::terminateASAP() +{ + s_terminateASAP = true; +} + +bool FilterInfo::shouldTerminate() +{ + return s_terminateASAP; +} + +////////////////////////////////////////////////////////////////////////////////// +// +// The generic filter class +// +////////////////////////////////////////////////////////////////////////////////// + + +Filter::Filter( const TQString& name, const TQString& author, + const TQString& info ) + : m_name( name ), + m_author( author ), + m_info( info ) +{ + //public + count_duplicates = 0; +} + +bool Filter::addMessage( FilterInfo* info, const TQString& folderName, + const TQString& msgPath, const TQString & msgStatusFlags) +{ + KURL msgURL; + msgURL.setPath( msgPath ); + + if ( !kapp->dcopClient()->isApplicationRegistered( "kmail" ) ) + TDEApplication::startServiceByDesktopName( "kmail", TQString() ); // Will wait until kmail is started + + DCOPReply reply = DCOPRef( "kmail", "KMailIface" ).call( "dcopAddMessage", folderName, msgURL, msgStatusFlags ); + + if ( !reply.isValid() ) + { + info->alert( i18n( "Fatal: Unable to start KMail for DCOP communication. " + "Make sure kmail is installed." ) ); + return false; + } + + switch ( int( reply ) ) + { + case -1: + info->alert( i18n( "Cannot make folder %1 in KMail" ).arg( folderName ) ); + return false; + case -2: + info->alert( i18n( "Cannot add message to folder %1 in KMail" ).arg( folderName ) ); + return false; + case -4: + count_duplicates++; + return false; + case 0: + info->alert( i18n( "Error while adding message to folder %1 in KMail" ).arg( folderName ) ); + return false; + } + return true; +} + +bool Filter::addMessage_fastImport( FilterInfo* info, const TQString& folderName, + const TQString& msgPath, const TQString& msgStatusFlags ) +{ + KURL msgURL; + msgURL.setPath( msgPath ); + + if ( !kapp->dcopClient()->isApplicationRegistered( "kmail" ) ) + TDEApplication::startServiceByDesktopName( "kmail", TQString() ); // Will wait until kmail is started + + DCOPReply reply = DCOPRef( "kmail", "KMailIface" ).call( "dcopAddMessage_fastImport", folderName, msgURL, msgStatusFlags ); + if ( !reply.isValid() ) + { + info->alert( i18n( "Fatal: Unable to start KMail for DCOP communication. " + "Make sure kmail is installed." ) ); + return false; + } + + switch ( int( reply ) ) + { + case -1: + info->alert( i18n( "Cannot make folder %1 in KMail" ).arg( folderName ) ); + return false; + case -2: + info->alert( i18n( "Cannot add message to folder %1 in KMail" ).arg( folderName ) ); + return false; + case 0: + info->alert( i18n( "Error while adding message to folder %1 in KMail" ).arg( folderName ) ); + return false; + } + return true; +} + +void Filter::showKMailImportArchiveDialog( FilterInfo* info ) +{ + if ( !kapp->dcopClient()->isApplicationRegistered( "kmail" ) ) + TDEApplication::startServiceByDesktopName( "kmail", TQString() ); // Will wait until kmail is started + + DCOPReply reply = DCOPRef( "kmail", "KMailIface" ).call( "showImportArchiveDialog" ); + if ( !reply.isValid() ) + { + info->alert( i18n( "Fatal: Unable to start KMail for DCOP communication. " + "Make sure kmail is installed." ) ); + } +} + +bool Filter::needsSecondPage() +{ + return true; +} diff --git a/kmailcvt/filters.cxx b/kmailcvt/filters.cxx deleted file mode 100644 index 6aeb4fde..00000000 --- a/kmailcvt/filters.cxx +++ /dev/null @@ -1,216 +0,0 @@ -/*************************************************************************** - filters.cxx - description - ------------------- - begin : Fri Jun 30 2000 - copyright : (C) 2000 by Hans Dijkema - email : kmailcvt@hum.org - ***************************************************************************/ - -/*************************************************************************** - * * - * 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 -#include -#include -#include -#include -#include - -#include "filters.hxx" -#include "kmailcvt.h" - - -////////////////////////////////////////////////////////////////////////////////// -// -// The API to the kmailcvt dialog --> Gives the import filter access to -// put information on the dialog. -// -////////////////////////////////////////////////////////////////////////////////// - -bool FilterInfo::s_terminateASAP = false; - -FilterInfo::FilterInfo( KImportPageDlg* dlg, TQWidget* parent , bool _removeDupMsg) - : m_dlg( dlg ), - m_parent( parent ) -{ - removeDupMsg = _removeDupMsg; - s_terminateASAP = false; -} - -FilterInfo::~FilterInfo() -{ -} - -void FilterInfo::setStatusMsg( const TQString& status ) -{ - m_dlg->_texStatus->setText( status ); -} - -void FilterInfo::setFrom( const TQString& from ) -{ - m_dlg->_from->setText( from ); -} - -void FilterInfo::setTo( const TQString& to ) -{ - m_dlg->_to->setText( to ); -} - -void FilterInfo::setCurrent( const TQString& current ) -{ - m_dlg->_current->setText( current ); - kapp->processEvents(); -} - -void FilterInfo::setCurrent( int percent ) -{ - m_dlg->_done_current->setProgress( percent ); - kapp->processEvents(); // Be careful - back & finish buttons disabled, so only user event that can happen is cancel/close button -} - -void FilterInfo::setOverall( int percent ) -{ - m_dlg->_done_overall->setProgress( percent ); -} - -void FilterInfo::addLog( const TQString& log ) -{ - m_dlg->_log->insertItem( log ); - m_dlg->_log->setCurrentItem( m_dlg->_log->count() - 1 ); - m_dlg->_log->centerCurrentItem(); - kapp->processEvents(); -} - -void FilterInfo::clear() -{ - m_dlg->_log->clear(); - setCurrent(); - setOverall(); - setCurrent( TQString() ); - setFrom( TQString() ); - setTo( TQString() ); -} - -void FilterInfo::alert( const TQString& message ) -{ - KMessageBox::information( m_parent, message ); -} - -void FilterInfo::terminateASAP() -{ - s_terminateASAP = true; -} - -bool FilterInfo::shouldTerminate() -{ - return s_terminateASAP; -} - -////////////////////////////////////////////////////////////////////////////////// -// -// The generic filter class -// -////////////////////////////////////////////////////////////////////////////////// - - -Filter::Filter( const TQString& name, const TQString& author, - const TQString& info ) - : m_name( name ), - m_author( author ), - m_info( info ) -{ - //public - count_duplicates = 0; -} - -bool Filter::addMessage( FilterInfo* info, const TQString& folderName, - const TQString& msgPath, const TQString & msgStatusFlags) -{ - KURL msgURL; - msgURL.setPath( msgPath ); - - if ( !kapp->dcopClient()->isApplicationRegistered( "kmail" ) ) - TDEApplication::startServiceByDesktopName( "kmail", TQString() ); // Will wait until kmail is started - - DCOPReply reply = DCOPRef( "kmail", "KMailIface" ).call( "dcopAddMessage", folderName, msgURL, msgStatusFlags ); - - if ( !reply.isValid() ) - { - info->alert( i18n( "Fatal: Unable to start KMail for DCOP communication. " - "Make sure kmail is installed." ) ); - return false; - } - - switch ( int( reply ) ) - { - case -1: - info->alert( i18n( "Cannot make folder %1 in KMail" ).arg( folderName ) ); - return false; - case -2: - info->alert( i18n( "Cannot add message to folder %1 in KMail" ).arg( folderName ) ); - return false; - case -4: - count_duplicates++; - return false; - case 0: - info->alert( i18n( "Error while adding message to folder %1 in KMail" ).arg( folderName ) ); - return false; - } - return true; -} - -bool Filter::addMessage_fastImport( FilterInfo* info, const TQString& folderName, - const TQString& msgPath, const TQString& msgStatusFlags ) -{ - KURL msgURL; - msgURL.setPath( msgPath ); - - if ( !kapp->dcopClient()->isApplicationRegistered( "kmail" ) ) - TDEApplication::startServiceByDesktopName( "kmail", TQString() ); // Will wait until kmail is started - - DCOPReply reply = DCOPRef( "kmail", "KMailIface" ).call( "dcopAddMessage_fastImport", folderName, msgURL, msgStatusFlags ); - if ( !reply.isValid() ) - { - info->alert( i18n( "Fatal: Unable to start KMail for DCOP communication. " - "Make sure kmail is installed." ) ); - return false; - } - - switch ( int( reply ) ) - { - case -1: - info->alert( i18n( "Cannot make folder %1 in KMail" ).arg( folderName ) ); - return false; - case -2: - info->alert( i18n( "Cannot add message to folder %1 in KMail" ).arg( folderName ) ); - return false; - case 0: - info->alert( i18n( "Error while adding message to folder %1 in KMail" ).arg( folderName ) ); - return false; - } - return true; -} - -void Filter::showKMailImportArchiveDialog( FilterInfo* info ) -{ - if ( !kapp->dcopClient()->isApplicationRegistered( "kmail" ) ) - TDEApplication::startServiceByDesktopName( "kmail", TQString() ); // Will wait until kmail is started - - DCOPReply reply = DCOPRef( "kmail", "KMailIface" ).call( "showImportArchiveDialog" ); - if ( !reply.isValid() ) - { - info->alert( i18n( "Fatal: Unable to start KMail for DCOP communication. " - "Make sure kmail is installed." ) ); - } -} - -bool Filter::needsSecondPage() -{ - return true; -} diff --git a/kmailcvt/filters.h b/kmailcvt/filters.h new file mode 100644 index 00000000..f9261bcb --- /dev/null +++ b/kmailcvt/filters.h @@ -0,0 +1,145 @@ +/*************************************************************************** + filters.h - description + ------------------- + begin : Fri Jun 30 2000 + copyright : (C) 2000 by Hans Dijkema + email : kmailcvt@hum.org + ***************************************************************************/ + +/*************************************************************************** + * * + * 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 FILTERS_H +#define FILTERS_H + +#ifndef MAX_LINE +#define MAX_LINE 4096 +#endif + +#include +#include +#include +#include +#include + +#include "kimportpagedlg.h" + +class FilterInfo +{ + public: + FilterInfo(KImportPageDlg *dlg, TQWidget *parent, bool _removeDupMsg); + ~FilterInfo(); + + void setStatusMsg( const TQString& status ); + void setFrom( const TQString& from ); + void setTo( const TQString& to ); + void setCurrent( const TQString& current ); + void setCurrent( int percent = 0 ); + void setOverall( int percent = 0 ); + void addLog( const TQString& log ); + void clear(); + void alert( const TQString& message ); + static void terminateASAP(); + bool shouldTerminate(); + + TQWidget *parent() { return m_parent; } + bool removeDupMsg; + + private: + KImportPageDlg *m_dlg; + TQWidget *m_parent; + static bool s_terminateASAP; +}; + +class Filter +{ + public: + Filter( const TQString& name, const TQString& author, + const TQString& info = TQString() ); + virtual ~Filter() {} + virtual void import( FilterInfo* ) = 0; + TQString author() const { return m_author; } + TQString name() const { return m_name; } + TQString info() const { return m_info; } + + virtual bool needsSecondPage(); + + int count_duplicates; //to count all duplicate messages + + protected: + void showKMailImportArchiveDialog( FilterInfo* info ); + bool addMessage( FilterInfo* info, + const TQString& folder, + const TQString& msgFile, + const TQString& msgStatusFlags = TQString()); + bool addMessage_fastImport( FilterInfo* info, + const TQString& folder, + const TQString& msgFile, + const TQString& msgStatusFlags = TQString()); + private: + TQString m_name; + TQString m_author; + TQString m_info; +}; + + + +/** +* Glorified TQString[N] for (a) understandability (b) older gcc compatibility. +*/ +template class FolderStructureBase +{ +public: + typedef TQString NString[size]; + /** Constructor. Need a default constructor for TQValueList. */ + FolderStructureBase() {} ; + + /** Constructor. Turn N TQStrings into a folder structure + * description. + */ + FolderStructureBase(const NString &s) + { + for(unsigned int i=0; i -#include -#include -#include -#include - -#include "kimportpagedlg.h" - -class FilterInfo -{ - public: - FilterInfo(KImportPageDlg *dlg, TQWidget *parent, bool _removeDupMsg); - ~FilterInfo(); - - void setStatusMsg( const TQString& status ); - void setFrom( const TQString& from ); - void setTo( const TQString& to ); - void setCurrent( const TQString& current ); - void setCurrent( int percent = 0 ); - void setOverall( int percent = 0 ); - void addLog( const TQString& log ); - void clear(); - void alert( const TQString& message ); - static void terminateASAP(); - bool shouldTerminate(); - - TQWidget *parent() { return m_parent; } - bool removeDupMsg; - - private: - KImportPageDlg *m_dlg; - TQWidget *m_parent; - static bool s_terminateASAP; -}; - -class Filter -{ - public: - Filter( const TQString& name, const TQString& author, - const TQString& info = TQString() ); - virtual ~Filter() {} - virtual void import( FilterInfo* ) = 0; - TQString author() const { return m_author; } - TQString name() const { return m_name; } - TQString info() const { return m_info; } - - virtual bool needsSecondPage(); - - int count_duplicates; //to count all duplicate messages - - protected: - void showKMailImportArchiveDialog( FilterInfo* info ); - bool addMessage( FilterInfo* info, - const TQString& folder, - const TQString& msgFile, - const TQString& msgStatusFlags = TQString()); - bool addMessage_fastImport( FilterInfo* info, - const TQString& folder, - const TQString& msgFile, - const TQString& msgStatusFlags = TQString()); - private: - TQString m_name; - TQString m_author; - TQString m_info; -}; - - - -/** -* Glorified TQString[N] for (a) understandability (b) older gcc compatibility. -*/ -template class FolderStructureBase -{ -public: - typedef TQString NString[size]; - /** Constructor. Need a default constructor for TQValueList. */ - FolderStructureBase() {} ; - - /** Constructor. Turn N TQStrings into a folder structure - * description. - */ - FolderStructureBase(const NString &s) - { - for(unsigned int i=0; i #include #include -#include "filters.hxx" +#include "filters.h" KMailCVT::KMailCVT(TQWidget *parent, const char *name) : KWizard(parent, name, true) { diff --git a/kmailcvt/kselfilterpage.cpp b/kmailcvt/kselfilterpage.cpp index 7d97fcfd..118124f7 100644 --- a/kmailcvt/kselfilterpage.cpp +++ b/kmailcvt/kselfilterpage.cpp @@ -19,23 +19,23 @@ #include #include #include -#include "filters.hxx" +#include "filters.h" -#include "filter_mbox.hxx" -#include "filter_oe.hxx" -#include "filter_outlook.hxx" -#include "filter_pmail.hxx" -#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 "filter_kmail_maildir.hxx" -#include "filter_kmail_archive.hxx" -#include "filter_sylpheed.hxx" -#include "filter_thebat.hxx" -#include "filter_lnotes.hxx" +#include "filter_mbox.h" +#include "filter_oe.h" +#include "filter_outlook.h" +#include "filter_pmail.h" +#include "filter_plain.h" +#include "filter_evolution.h" +#include "filter_mailapp.h" +#include "filter_evolution_v2.h" +#include "filter_opera.h" +#include "filter_thunderbird.h" +#include "filter_kmail_maildir.h" +#include "filter_kmail_archive.h" +#include "filter_sylpheed.h" +#include "filter_thebat.h" +#include "filter_lnotes.h" #include "kselfilterpage.h" -- cgit v1.2.3