From 392fcc0ce6f52fe1be18995da33f97c7d62eed6e Mon Sep 17 00:00:00 2001 From: Karol Kosek Date: Thu, 24 Aug 2023 09:07:15 +0200 Subject: [PATCH] Mail: Get message date using INTERNALDATE Parsing mail headers and its date format is a rather tedious task, especially if you want to support the obsolete syntax, so let's ask the server to do it for us! This will convert the date to our local time and display it in a sortable and fixed-width format "%Y-%m-%d %H:%M:%S". --- Userland/Applications/Mail/MailWidget.cpp | 26 ++++++----------------- 1 file changed, 6 insertions(+), 20 deletions(-) diff --git a/Userland/Applications/Mail/MailWidget.cpp b/Userland/Applications/Mail/MailWidget.cpp index 6eafd2ad48a..902803b5b11 100644 --- a/Userland/Applications/Mail/MailWidget.cpp +++ b/Userland/Applications/Mail/MailWidget.cpp @@ -288,9 +288,12 @@ void MailWidget::selected_mailbox() .type = IMAP::FetchCommand::DataItemType::PeekBody, .section = IMAP::FetchCommand::DataItem::Section { .type = IMAP::FetchCommand::DataItem::SectionType::HeaderFields, - .headers = { { "Date", "Subject", "From" } }, + .headers = { { "Subject", "From" } }, }, }, + IMAP::FetchCommand::DataItem { + .type = IMAP::FetchCommand::DataItemType::InternalDate, + }, IMAP::FetchCommand::DataItem { .type = IMAP::FetchCommand::DataItemType::Flags, }, @@ -312,6 +315,7 @@ void MailWidget::selected_mailbox() auto sequence_number = fetch_data.get(); auto& response_data = fetch_data.get(); auto& body_data = response_data.body_data(); + auto& internal_date = response_data.internal_date(); auto seen = !response_data.flags().find_if([](StringView value) { return value.equals_ignoring_ascii_case("\\Seen"sv); }).is_end(); @@ -328,13 +332,6 @@ void MailWidget::selected_mailbox() return header_iterator != data_item.section->headers->end(); }; - auto date_iterator = body_data.find_if([&data_item_has_header](Tuple>& 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>& data) { auto const data_item = data.get<0>(); return data_item_has_header(data_item, "Subject"); @@ -378,18 +375,7 @@ 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)"; - } + DeprecatedString date = internal_date.to_deprecated_string(); auto& subject_iterator_value = subject_iterator->get<1>().value(); auto subject_index = subject_iterator_value.find("Subject:"sv);