MailImporter

filterplain.cpp
1/*
2 filterplain.cpp - Plain mail import
3
4 SPDX-FileCopyrightText: 2002 Laurence Anderson <l.d.anderson@warwick.ac.uk>
5
6 SPDX-License-Identifier: GPL-2.0-or-later
7*/
8
9#include "filterplain.h"
10
11#include <KLocalizedString>
12
13#include <QFileDialog>
14
15using namespace MailImporter;
16
17FilterPlain::FilterPlain()
18 : Filter(i18n("Import Plain Text Emails"),
19 i18n("Laurence Anderson <p>( Filter accelerated by Danny Kukawka )</p>"),
20 i18n("<p>Select the directory containing the emails on your system. "
21 "The emails are placed in a folder with the same name as the "
22 "directory they were in, prefixed by PLAIN-</p>"
23 "<p>This filter will import all .msg, .eml and .txt emails.</p>"))
24{
25}
26
27FilterPlain::~FilterPlain()
28{
29}
30
31void FilterPlain::import()
32{
33 // Select directory containing plain text emails
34 const QString mailDir = QFileDialog::getExistingDirectory(filterInfo()->parentWidget(), QString(), QDir::homePath());
35 importMails(mailDir);
36}
37
38void FilterPlain::importMails(const QString &mailDir)
39{
40 if (mailDir.isEmpty()) { // No directory selected
41 filterInfo()->alert(i18n("No directory selected."));
42 return;
43 }
44 QDir dir(mailDir);
45 const QStringList files =
46 dir.entryList(QStringList() << QStringLiteral("*.[eE][mM][lL]") << QStringLiteral("*.[tT][xX][tT]") << QStringLiteral("*.[mM][sS][gG]"),
49 // Count total number of files to be processed
50 filterInfo()->addInfoLogEntry(i18n("Counting files..."));
51 int totalFiles = files.count();
52 if (files.isEmpty()) {
53 filterInfo()->addErrorLogEntry(i18n("No files found for import."));
54 } else {
55 filterInfo()->addInfoLogEntry(i18n("Importing new mail files..."));
57 const QString destName = QStringLiteral("PLAIN-%1").arg(dir.dirName());
58 int currentFile = 0;
59 for (QStringList::ConstIterator mailFile = files.constBegin(); mailFile != end; ++mailFile) {
60 const QString dirRealPath = dir.filePath(*mailFile);
61 filterInfo()->setFrom(dirRealPath);
62 filterInfo()->setTo(destName);
63 filterInfo()->setCurrent(0);
64 if (!importMessage(destName, dirRealPath, filterInfo()->removeDupMessage())) {
65 filterInfo()->addErrorLogEntry(i18n("Could not import %1", *mailFile));
66 }
67
68 filterInfo()->setCurrent(100);
69 filterInfo()->setOverall(100 * ++currentFile / totalFiles);
70 if (filterInfo()->shouldTerminate()) {
71 break;
72 }
73 }
74
75 filterInfo()->addInfoLogEntry(i18n("Finished importing emails from %1", mailDir));
76 if (countDuplicates() > 0) {
77 filterInfo()->addInfoLogEntry(i18np("1 duplicate message not imported", "%1 duplicate messages not imported", countDuplicates()));
78 }
79 if (filterInfo()->shouldTerminate()) {
80 filterInfo()->addInfoLogEntry(i18n("Finished import, canceled by user."));
81 }
82 }
83 clearCountDuplicate();
84}
QString i18np(const char *singular, const char *plural, const TYPE &arg...)
QString i18n(const char *text, const TYPE &arg...)
QAction * end(const QObject *recvr, const char *slot, QObject *parent)
KIOCORE_EXPORT QString dir(const QString &fileClass)
QString homePath()
QString getExistingDirectory(QWidget *parent, const QString &caption, const QString &dir, Options options)
const_iterator constBegin() const const
const_iterator constEnd() const const
qsizetype count() const const
bool isEmpty() const const
QString arg(Args &&... args) const const
bool isEmpty() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 22 2024 12:08:31 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.