#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(nullptr, QListWidgetItem::UserType), uid{e.uid}, titleS(e.titleS), messageS(e.messageS), rawMessageS(e.rawMessageS) { setText(QString::fromStdString(titleS)); } void Email::setString(const std::string &str) { std::stringstream ss(str); std::string line; rawMessageS.clear(); while (std::getline(ss, line)) { rawMessageS.append(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; } const std::string &Email::raw() const { return rawMessageS; } bool Email::operator<(QListWidgetItem const &other) const { auto a{dynamic_cast(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); } }