1 /***************************************************************************
2 filter_lnotes.cxx - Lotus Notes Structured Text mail import
4 begin : Wed Feb 16, 2005
5 copyright : (C) 2005 by Robert Rockers
6 email : kconfigure@rockerssoft.com
7 ***************************************************************************/
9 /***************************************************************************
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
16 ***************************************************************************/
20 #include <kfiledialog.h>
21 #include <ktemporaryfile.h>
25 #include "filter_lnotes.h"
26 using namespace MailImporter
;
28 /** Default constructor. */
29 FilterLNotes::FilterLNotes() :
30 Filter( i18n("Import Lotus Notes Emails"),
32 i18n("<p><b>Lotus Notes Structured Text mail import filter</b></p>"
33 "<p>This filter will import Structure Text files from an exported Lotus Notes email "
34 "client into KMail. Use this filter if you want to import mails from Lotus or other "
35 "mailers that use Lotus Notes' Structured Text format.</p>"
36 "<p><b>Note:</b> Since it is possible to recreate the folder structure, the imported "
37 "messages will be stored in subfolders named by the files they came from under: "
38 "\"LNotes-Import\" in your local folder.</p>"))
45 FilterLNotes::~FilterLNotes()
50 * Recursive import of The Bat! maildir.
51 * @param info Information storage for the operation.
53 void FilterLNotes::import() {
55 const QStringList filenames
= KFileDialog::getOpenFileNames( QDir::homePath(), "*|" + i18n("All Files (*)"),
56 filterInfo()->parent() );
57 if (filenames
.isEmpty()) {
58 filterInfo()->alert(i18n("No files selected."));
65 totalFiles
= filenames
.count();
66 filterInfo()->setOverall(0);
68 // See filter_mbox.cxx for better reference.
69 QStringList::ConstIterator end
= filenames
.constEnd();
70 for ( QStringList::ConstIterator filename
= filenames
.constBegin(); filename
!= end
; ++filename
) {
73 filterInfo()->addInfoLogEntry( i18n("Importing emails from %1", *filename
) );
74 ImportLNotes( *filename
);
75 filterInfo()->setOverall( 100 * currentFile
/ totalFiles
);
76 if ( filterInfo()->shouldTerminate() )
82 * Import the files within a Folder.
83 * @param file The name of the file to import.
85 void FilterLNotes::ImportLNotes(const QString
&file
) {
87 // See Filter_pmail.cxx for better reference
89 // Format of a Lotus Notes 5 Structured Text Document w form feed
90 // Each email begins with a custom Header Principal:
91 // The Message ends with a 0c character
96 if (! f
.open( QIODevice::ReadOnly
) ) {
97 filterInfo()->alert( i18n("Unable to open %1, skipping", file
) );
103 KTemporaryFile
*tempfile
= 0;
106 QFileInfo
filenameInfo( file
);
107 QString
folder(i18nc("Define folder name where we import lotus note mails", "LNotes-Import") +QLatin1Char('/') + filenameInfo
.completeBaseName());
108 filterInfo()->setTo(folder
);
110 // State machine to read the data in. The fgetc usage is probably terribly slow ...
111 while (f
.getChar(&ch
)) {
115 // open temp output file
117 filterInfo()->setCurrent(i18n("Message %1", n
++));
118 if ( filterInfo()->shouldTerminate() )
121 tempfile
= new KTemporaryFile
;
122 tempfile
->setAutoRemove(false);
126 // inside a message state
129 // close file, send it
132 if(filterInfo()->removeDupMessage())
133 addMessage( folder
, tempfile
->fileName() );
135 addMessage_fastImport( folder
, tempfile
->fileName() );
137 tempfile
->setAutoRemove(true);
140 int currentPercentage
= (int) ( ( (float) f
.pos() / filenameInfo
.size() ) * 100 );
141 filterInfo()->setCurrent( currentPercentage
);
142 if ( filterInfo()->shouldTerminate() )
150 tempfile
->putChar(ch
);
158 // did Folder end without 0x1a at the end?
162 if(filterInfo()->removeDupMessage())
163 addMessage( folder
, tempfile
->fileName() );
165 addMessage_fastImport( folder
, tempfile
->fileName() );
168 tempfile
->setAutoRemove(true);