From 0132c30edafe1798cd736bd41d0a92bbc6576805 Mon Sep 17 00:00:00 2001 From: Karol Kosek Date: Tue, 29 Aug 2023 15:44:13 +0200 Subject: [PATCH] Mail: Fetch mails with their sequence number The FETCH response doesn't have return the sequence in order, or at very least one of my mail providers doesn't do it. --- Userland/Applications/Mail/InboxModel.cpp | 2 ++ Userland/Applications/Mail/InboxModel.h | 6 ++++++ Userland/Applications/Mail/MailWidget.cpp | 6 +++--- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/Userland/Applications/Mail/InboxModel.cpp b/Userland/Applications/Mail/InboxModel.cpp index 055c817077..750a4bc142 100644 --- a/Userland/Applications/Mail/InboxModel.cpp +++ b/Userland/Applications/Mail/InboxModel.cpp @@ -57,5 +57,7 @@ GUI::Variant InboxModel::data(GUI::ModelIndex const& index, GUI::ModelRole role) if (!value.seen) return Gfx::FontDatabase::default_font().bold_variant(); } + if (role == static_cast(InboxModelCustomRole::Sequence)) + return value.sequence_number; return {}; } diff --git a/Userland/Applications/Mail/InboxModel.h b/Userland/Applications/Mail/InboxModel.h index 3a97c5aa8c..62e862c463 100644 --- a/Userland/Applications/Mail/InboxModel.h +++ b/Userland/Applications/Mail/InboxModel.h @@ -11,12 +11,18 @@ #include struct InboxEntry { + u32 sequence_number; DeprecatedString from; DeprecatedString subject; DeprecatedString date; bool seen; }; +enum class InboxModelCustomRole { + __DONOTUSE = (int)GUI::ModelRole::Custom, + Sequence, +}; + class InboxModel final : public GUI::Model { public: enum Column { diff --git a/Userland/Applications/Mail/MailWidget.cpp b/Userland/Applications/Mail/MailWidget.cpp index a6f60499cb..6eafd2ad48 100644 --- a/Userland/Applications/Mail/MailWidget.cpp +++ b/Userland/Applications/Mail/MailWidget.cpp @@ -309,6 +309,7 @@ void MailWidget::selected_mailbox() int i = 0; for (auto& fetch_data : fetch_response.data().fetch_data()) { + auto sequence_number = fetch_data.get(); auto& response_data = fetch_data.get(); auto& body_data = response_data.body_data(); @@ -420,7 +421,7 @@ void MailWidget::selected_mailbox() if (from.is_empty()) from = "(Unknown sender)"; - InboxEntry inbox_entry { from, subject, date, seen }; + InboxEntry inbox_entry { sequence_number, from, subject, date, seen }; m_statusbar->set_text(String::formatted("[{}]: Loading entry {}", mailbox.name, ++i).release_value_but_fixme_should_propagate_errors()); active_inbox_entries.append(inbox_entry); @@ -438,8 +439,7 @@ void MailWidget::selected_email_to_load() if (!index.is_valid()) return; - // IMAP is 1-based. - int id_of_email_to_load = index.row() + 1; + int id_of_email_to_load = index.data(static_cast(InboxModelCustomRole::Sequence)).as_u32(); m_statusbar->set_text("Fetching message..."_string);