-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathPMaildMail.cpp
More file actions
97 lines (75 loc) · 1.78 KB
/
PMaildMail.cpp
File metadata and controls
97 lines (75 loc) · 1.78 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#include "PMaildMail.hpp"
#include "PMaildCore.hpp"
PMaildMail::PMaildMail(PMaildCore *_core, const PMaildUser &_user, const QVariantMap &_info) {
core = _core;
user = _user;
info = _info;
}
PMaildMail::PMaildMail() {
core = NULL;
}
quint64 PMaildMail::getId() const {
if (isNull()) return 0;
return info.value("mailid").toLongLong();
}
bool PMaildMail::isNull() const {
return core == NULL;
}
bool PMaildMail::isDeleted() const {
if (isNull()) return false;
if (!flags.contains("deleted")) return false;
return flags.value("deleted");
}
quint64 PMaildMail::getSize() const {
if (isNull()) return 0;
return info.value("size").toLongLong();
}
QString PMaildMail::getUniqName() const {
if (isNull()) return QString();
return info.value("uniqname").toString();
}
QString PMaildMail::getFilePath() const {
QDir dir = user.getPath();
return dir.filePath(getUniqName());
}
bool PMaildMail::erase() {
if (!core->eraseMail(*this)) return false;
QFile f(getFilePath());
f.remove();
return true;
}
PMaildUser PMaildMail::getUser() {
return user;
}
const PMaildUser PMaildMail::getUser() const {
return user;
}
QByteArray PMaildMail::readAll() {
QFile f(getFilePath());
if (!f.open(QIODevice::ReadOnly)) return QByteArray();
return f.readAll(); // ~QFile will close it
}
QByteArray PMaildMail::readLines(int lines) {
// limit to header + lines lines
QByteArray res;
QFile f(getFilePath());
if (!f.open(QIODevice::ReadOnly)) return QByteArray();
bool headers = true;
while(true) {
QByteArray line = f.readLine();
if (line == "") break;
if (headers) {
res.append(line);
if (line.trimmed() == "")
headers = false;
continue;
}
if (--lines <= 0) break;
res.append(line);
}
return res;
}
bool PMaildMail::unsetFlag(const QString &) {
// TODO
return false;
}