1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 16:07:47 +00:00

Mail: Fetch and display date in e-mail list

Added a third column to show date of e-mail, as sent from the IMAP
server.
This commit is contained in:
Valtteri Koskivuori 2023-07-25 23:32:24 +03:00 committed by Andrew Kaster
parent f74380eecf
commit fc54bd03f9
3 changed files with 33 additions and 3 deletions

View file

@ -24,6 +24,8 @@ ErrorOr<String> InboxModel::column_name(int column_index) const
return "From"_string; return "From"_string;
case Subject: case Subject:
return "Subject"_string; return "Subject"_string;
case Date:
return "Date"_string;
default: default:
VERIFY_NOT_REACHED(); VERIFY_NOT_REACHED();
} }
@ -37,6 +39,12 @@ GUI::Variant InboxModel::data(GUI::ModelIndex const& index, GUI::ModelRole role)
return value.from; return value.from;
if (index.column() == Column::Subject) if (index.column() == Column::Subject)
return value.subject; return value.subject;
if (index.column() == Column::Date)
return value.date;
}
if (role == GUI::ModelRole::TextAlignment) {
if (index.column() == Column::Date)
return Gfx::TextAlignment::CenterRight;
} }
return {}; return {};
} }

View file

@ -13,6 +13,7 @@
struct InboxEntry { struct InboxEntry {
DeprecatedString from; DeprecatedString from;
DeprecatedString subject; DeprecatedString subject;
DeprecatedString date;
}; };
class InboxModel final : public GUI::Model { class InboxModel final : public GUI::Model {
@ -20,6 +21,7 @@ public:
enum Column { enum Column {
From, From,
Subject, Subject,
Date,
__Count __Count
}; };

View file

@ -286,7 +286,7 @@ void MailWidget::selected_mailbox()
.type = IMAP::FetchCommand::DataItemType::PeekBody, .type = IMAP::FetchCommand::DataItemType::PeekBody,
.section = IMAP::FetchCommand::DataItem::Section { .section = IMAP::FetchCommand::DataItem::Section {
.type = IMAP::FetchCommand::DataItem::SectionType::HeaderFields, .type = IMAP::FetchCommand::DataItem::SectionType::HeaderFields,
.headers = { { "Subject", "From" } }, .headers = { { "Date", "Subject", "From" } },
}, },
}, },
}, },
@ -321,6 +321,13 @@ void MailWidget::selected_mailbox()
return header_iterator != data_item.section->headers->end(); return header_iterator != data_item.section->headers->end();
}; };
auto date_iterator = body_data.find_if([&data_item_has_header](Tuple<IMAP::FetchCommand::DataItem, Optional<DeprecatedString>>& data) {
auto const data_item = data.get<0>();
return data_item_has_header(data_item, "Date");
});
VERIFY(date_iterator != body_data.end());
auto subject_iterator = body_data.find_if([&data_item_has_header](Tuple<IMAP::FetchCommand::DataItem, Optional<DeprecatedString>>& data) { auto subject_iterator = body_data.find_if([&data_item_has_header](Tuple<IMAP::FetchCommand::DataItem, Optional<DeprecatedString>>& data) {
auto const data_item = data.get<0>(); auto const data_item = data.get<0>();
return data_item_has_header(data_item, "Subject"); return data_item_has_header(data_item, "Subject");
@ -364,6 +371,19 @@ void MailWidget::selected_mailbox()
return builder.to_deprecated_string(); return builder.to_deprecated_string();
}; };
auto& date_iterator_value = date_iterator->get<1>().value();
auto date_index = date_iterator_value.find("Date:"sv);
DeprecatedString date;
if (date_index.has_value()) {
auto potential_date = date_iterator_value.substring(date_index.value());
auto date_parts = potential_date.split_limit(':', 2);
date = parse_and_unfold(date_parts.last());
}
if (date.is_empty()) {
date = "(Unknown date)";
}
auto& subject_iterator_value = subject_iterator->get<1>().value(); auto& subject_iterator_value = subject_iterator->get<1>().value();
auto subject_index = subject_iterator_value.find("Subject:"sv); auto subject_index = subject_iterator_value.find("Subject:"sv);
DeprecatedString subject; DeprecatedString subject;
@ -374,7 +394,7 @@ void MailWidget::selected_mailbox()
} }
if (subject.is_empty()) if (subject.is_empty())
subject = "(no subject)"; subject = "(No subject)";
auto& from_iterator_value = from_iterator->get<1>().value(); auto& from_iterator_value = from_iterator->get<1>().value();
auto from_index = from_iterator_value.find("From:"sv); auto from_index = from_iterator_value.find("From:"sv);
@ -390,7 +410,7 @@ void MailWidget::selected_mailbox()
if (from.is_empty()) if (from.is_empty())
from = "(Unknown sender)"; from = "(Unknown sender)";
InboxEntry inbox_entry { from, subject }; InboxEntry inbox_entry { from, subject, date };
m_statusbar->set_text(String::formatted("[{}]: Loading entry {}", mailbox.name, ++i).release_value_but_fixme_should_propagate_errors()); m_statusbar->set_text(String::formatted("[{}]: Loading entry {}", mailbox.name, ++i).release_value_but_fixme_should_propagate_errors());
active_inbox_entries.append(inbox_entry); active_inbox_entries.append(inbox_entry);