From ee5f0dac80926eac52c38a13a03a2c3fb3b24def Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Revol?= Date: Sat, 29 Oct 2011 17:35:11 +0000 Subject: [PATCH] Applied patch from jalopeura on ticket #7458 and reworked it to use the BMailDaemon::MarkAsRead() method when an account id exists. Added a TODO note about using menu labels in tests while they could someday be translated. Replaced some hardcoded strings with the proper defines. Made the add-on also apply partial emails, I suppose it's the intent. Works for me. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@42972 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/add-ons/tracker/mark_as/Jamfile | 6 ++-- src/add-ons/tracker/mark_as/MarkAs.cpp | 38 +++++++++++++++++++-- src/add-ons/tracker/mark_as/MarkAs.rdef | 3 +- src/add-ons/tracker/mark_as/MarkAsRead.cpp | 31 ++++++++++++++--- src/add-ons/tracker/mark_as/MarkAsRead.rdef | 3 +- 5 files changed, 70 insertions(+), 11 deletions(-) diff --git a/src/add-ons/tracker/mark_as/Jamfile b/src/add-ons/tracker/mark_as/Jamfile index 62ccad3cad..0a22ea12b0 100644 --- a/src/add-ons/tracker/mark_as/Jamfile +++ b/src/add-ons/tracker/mark_as/Jamfile @@ -2,15 +2,17 @@ SubDir HAIKU_TOP src add-ons tracker mark_as ; SetSubDirSupportedPlatformsBeOSCompatible ; +UsePrivateHeaders mail ; + AddResources Mark\ as… : MarkAs.rdef ; AddResources Mark\ as\ Read-R : MarkAsRead.rdef ; Addon Mark\ as… : MarkAs.cpp - : be tracker $(TARGET_LIBSUPC++) + : be tracker $(TARGET_LIBSUPC++) libmail.so ; Addon Mark\ as\ Read-R : MarkAsRead.cpp - : be tracker $(TARGET_LIBSUPC++) + : be tracker $(TARGET_LIBSUPC++) libmail.so ; diff --git a/src/add-ons/tracker/mark_as/MarkAs.cpp b/src/add-ons/tracker/mark_as/MarkAs.cpp index a81c7af3ba..3f8bfb3b95 100644 --- a/src/add-ons/tracker/mark_as/MarkAs.cpp +++ b/src/add-ons/tracker/mark_as/MarkAs.cpp @@ -7,9 +7,12 @@ #include #include +#include #include #include #include +#include +#include #include #include #include @@ -84,6 +87,7 @@ process_refs(entry_ref dir, BMessage* message, void* /*reserved*/) return; BString status = item->Label(); + //TODO:This won't work anymore when the menu gets translated! Use index! entry_ref ref; for (int i = 0; message->FindRef("refs", i, &ref) == B_OK; i++) { @@ -92,13 +96,41 @@ process_refs(entry_ref dir, BMessage* message, void* /*reserved*/) if (node.InitCheck() == B_OK && node.ReadAttrString("BEOS:TYPE", &type) == B_OK - && type == "text/x-email") { + && (type == B_MAIL_TYPE || type == B_PARTIAL_MAIL_TYPE)) { BString previousStatus; + read_flags previousRead; + + // Update the MAIL:read flag + if (status == "New") { + if (read_read_attr(node, previousRead) != B_OK || + previousRead != B_UNREAD) + write_read_attr(node, B_UNREAD); + } + else if (status == "Read") { + // if we're marking it via the add-on, we haven't really read it + // so use B_SEEN instead of B_READ + // Check both B_SEEN and B_READ + // (so we don't overwrite B_READ with B_SEEN) + if (read_read_attr(node, previousRead) != B_OK || + (previousRead != B_SEEN && previousRead != B_READ)) { + int32 account; + if (node.ReadAttr(B_MAIL_ATTR_ACCOUNT_ID, B_INT32_TYPE, + 0LL, &account, sizeof(account)) == sizeof(account)) + BMailDaemon::MarkAsRead(account, ref, B_SEEN); + else + write_read_attr(node, B_SEEN); + } + } + // ignore "Replied"; no matching MAIL:read status + // We want to keep the previous behavior of updating the status + // string, but write_read_attr will only change the status string + // if it's one of "New", "Seen", or "Read" (and not, for example, + // "Replied"), so we change the status string here // Only update the attribute if there is an actual change - if (node.ReadAttrString("MAIL:status", &previousStatus) != B_OK + if (node.ReadAttrString(B_MAIL_ATTR_STATUS, &previousStatus) != B_OK || previousStatus != status) - node.WriteAttrString("MAIL:status", &status); + node.WriteAttrString(B_MAIL_ATTR_STATUS, &status); } } } diff --git a/src/add-ons/tracker/mark_as/MarkAs.rdef b/src/add-ons/tracker/mark_as/MarkAs.rdef index 76168d9d3f..4c70b6abb9 100644 --- a/src/add-ons/tracker/mark_as/MarkAs.rdef +++ b/src/add-ons/tracker/mark_as/MarkAs.rdef @@ -1,7 +1,8 @@ resource app_signature "application/x-vnd.Haiku-MarkAs"; resource file_types message { - "types" = "text/x-email" + "types" = "text/x-email", + "types" = "text/x-partial-email" }; resource app_version { diff --git a/src/add-ons/tracker/mark_as/MarkAsRead.cpp b/src/add-ons/tracker/mark_as/MarkAsRead.cpp index 6c37376be8..ee79b46c4f 100644 --- a/src/add-ons/tracker/mark_as/MarkAsRead.cpp +++ b/src/add-ons/tracker/mark_as/MarkAsRead.cpp @@ -5,12 +5,14 @@ */ +#include #include +#include +#include #include #include #include - extern "C" void process_refs(entry_ref dir, BMessage* message, void* /*reserved*/) { @@ -21,14 +23,35 @@ process_refs(entry_ref dir, BMessage* message, void* /*reserved*/) if (node.InitCheck() == B_OK && node.ReadAttrString("BEOS:TYPE", &type) == B_OK - && type == "text/x-email") { + && (type == B_MAIL_TYPE || type == B_PARTIAL_MAIL_TYPE)) { BString previousStatus; BString status("Read"); + read_flags previousRead; + // if we're marking it via the add-on, we haven't really read it + // so use B_SEEN instead of B_READ + read_flags read = B_SEEN; + + // Update the MAIL:read status to match + // Check both B_SEEN and B_READ + // (so we don't overwrite B_READ with B_SEEN) + if (read_read_attr(node, previousRead) != B_OK || + (previousRead != B_SEEN && previousRead != B_READ)) { + int32 account; + if (node.ReadAttr(B_MAIL_ATTR_ACCOUNT_ID, B_INT32_TYPE, + 0LL, &account, sizeof(account)) == sizeof(account)) + BMailDaemon::MarkAsRead(account, ref, read); + else + write_read_attr(node, read); + } + // We want to keep the previous behavior of updating the status + // string, but write_read_attr will only change the status string + // if it's one of "New", "Seen", or "Read" (and not, for example, + // "Replied"), so we change the status string here // Only update the attribute if there is an actual change - if (node.ReadAttrString("MAIL:status", &previousStatus) != B_OK + if (node.ReadAttrString(B_MAIL_ATTR_STATUS, &previousStatus) != B_OK || previousStatus != status) - node.WriteAttrString("MAIL:status", &status); + node.WriteAttrString(B_MAIL_ATTR_STATUS, &status); } } } diff --git a/src/add-ons/tracker/mark_as/MarkAsRead.rdef b/src/add-ons/tracker/mark_as/MarkAsRead.rdef index 03eef69129..8ebf49e3de 100644 --- a/src/add-ons/tracker/mark_as/MarkAsRead.rdef +++ b/src/add-ons/tracker/mark_as/MarkAsRead.rdef @@ -1,7 +1,8 @@ resource app_signature "application/x-vnd.Haiku-MarkAsRead"; resource file_types message { - "types" = "text/x-email" + "types" = "text/x-email", + "types" = "text/x-partial-email" }; resource app_version {