mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 16:27:35 +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:
parent
f74380eecf
commit
fc54bd03f9
3 changed files with 33 additions and 3 deletions
|
@ -24,6 +24,8 @@ ErrorOr<String> InboxModel::column_name(int column_index) const
|
|||
return "From"_string;
|
||||
case Subject:
|
||||
return "Subject"_string;
|
||||
case Date:
|
||||
return "Date"_string;
|
||||
default:
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
@ -37,6 +39,12 @@ GUI::Variant InboxModel::data(GUI::ModelIndex const& index, GUI::ModelRole role)
|
|||
return value.from;
|
||||
if (index.column() == Column::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 {};
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
struct InboxEntry {
|
||||
DeprecatedString from;
|
||||
DeprecatedString subject;
|
||||
DeprecatedString date;
|
||||
};
|
||||
|
||||
class InboxModel final : public GUI::Model {
|
||||
|
@ -20,6 +21,7 @@ public:
|
|||
enum Column {
|
||||
From,
|
||||
Subject,
|
||||
Date,
|
||||
__Count
|
||||
};
|
||||
|
||||
|
|
|
@ -286,7 +286,7 @@ void MailWidget::selected_mailbox()
|
|||
.type = IMAP::FetchCommand::DataItemType::PeekBody,
|
||||
.section = IMAP::FetchCommand::DataItem::Section {
|
||||
.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();
|
||||
};
|
||||
|
||||
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 const data_item = data.get<0>();
|
||||
return data_item_has_header(data_item, "Subject");
|
||||
|
@ -364,6 +371,19 @@ void MailWidget::selected_mailbox()
|
|||
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_index = subject_iterator_value.find("Subject:"sv);
|
||||
DeprecatedString subject;
|
||||
|
@ -374,7 +394,7 @@ void MailWidget::selected_mailbox()
|
|||
}
|
||||
|
||||
if (subject.is_empty())
|
||||
subject = "(no subject)";
|
||||
subject = "(No subject)";
|
||||
|
||||
auto& from_iterator_value = from_iterator->get<1>().value();
|
||||
auto from_index = from_iterator_value.find("From:"sv);
|
||||
|
@ -390,7 +410,7 @@ void MailWidget::selected_mailbox()
|
|||
if (from.is_empty())
|
||||
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());
|
||||
|
||||
active_inbox_entries.append(inbox_entry);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue