forked from chrm-software/cryptmee
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mailreaderthread.cpp
63 lines (50 loc) · 1.64 KB
/
mailreaderthread.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include "mailreaderthread.h"
#include <QDirIterator>
#include <QTextStream>
#include <QDateTime>
#include <QDebug>
MailReaderThread::MailReaderThread(QString _path, QObject *parent) :
QThread(parent)
{
this->path = _path;
this->fromLastDays = 31;
}
void MailReaderThread::run()
{
QDirIterator it(this->path, QStringList() << "*", QDir::Files, QDirIterator::Subdirectories);
this->allPGPMails.clear();
int lineCnt = 0;
while (it.hasNext()) {
QFile file(it.next());
// Check only newer files
if(it.fileInfo().created().daysTo(QDateTime::currentDateTime()) > this->fromLastDays) {
qDebug() << "MailReaderThread::run(): File too old: " << it.fileInfo().created().daysTo(QDateTime::currentDateTime()) << ". " << this->fromLastDays;
continue;
}
if (file.open(QIODevice::ReadOnly)) {
QString line;
QTextStream in(&file);
lineCnt = 0;
while (!in.atEnd()) {
// Break after 500 lines
lineCnt++;
if(lineCnt > 500)
break;
line = in.readLine();
if (line.contains("-BEGIN PGP MESSAGE-")) {
this->allPGPMails << file.fileName();
break;
}
}
file.close();
} else {
qDebug() << "*** Can't open file: " << file.fileName();
emit errorOccuredThread();
}
}
emit readyThread();
}
QStringList MailReaderThread::getAllMails()
{
return this->allPGPMails;
}