emailQt/Email.cpp

57 lines
1.4 KiB
C++
Raw Normal View History

2024-03-08 12:10:58 -05:00
#include "Email.hpp"
Email::Email(const std::string &str, size_t uid)
: QListWidgetItem(nullptr, QListWidgetItem::UserType), uid{uid} {
setString(str);
}
Email::Email(Email const &e)
2024-12-19 18:51:41 -05:00
: QListWidgetItem(nullptr, QListWidgetItem::UserType),
uid{e.uid},
titleS(e.titleS),
messageS(e.messageS),
rawMessageS(e.rawMessageS) {
setText(QString::fromStdString(titleS));
2024-03-08 12:10:58 -05:00
}
void Email::setString(const std::string &str) {
std::stringstream ss(str);
std::string line;
2024-12-19 18:51:41 -05:00
rawMessageS.clear();
2024-03-08 12:10:58 -05:00
while (std::getline(ss, line)) {
2024-12-19 18:51:41 -05:00
rawMessageS.append(line);
2024-03-08 12:10:58 -05:00
if (line.starts_with("Subject:"))
titleS = line.substr(9);
else if (line.starts_with("Content-Type:"))
parseEmailBody(ss, line);
}
setText(QString::fromStdString(titleS));
}
const std::string &Email::title() const {
return titleS;
}
const std::string &Email::message() const {
return messageS;
}
2024-12-19 18:51:41 -05:00
const std::string &Email::raw() const {
return rawMessageS;
}
2024-03-08 12:10:58 -05:00
bool Email::operator<(QListWidgetItem const &other) const {
auto a{dynamic_cast<const Email &>(other)};
return this->uid < a.uid;
}
void Email::parseEmailBody(std::stringstream &ss, std::string &line) {
if (!line.contains("text/plain"))
return;
while (std::getline(ss, line) && !(line.starts_with("--"))) {
messageS.append(line);
}
}