emailQt/Email.cpp

47 lines
1.1 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)
: QListWidgetItem(e), uid{e.uid}, titleS(e.titleS), messageS(e.messageS) {
setString(titleS);
}
void Email::setString(const std::string &str) {
std::stringstream ss(str);
std::string line;
while (std::getline(ss, line)) {
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;
}
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);
}
}