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
This commit is contained in:
François Revol 2011-10-29 17:35:11 +00:00
parent 4d9b54c175
commit ee5f0dac80
5 changed files with 70 additions and 11 deletions

View File

@ -2,15 +2,17 @@ SubDir HAIKU_TOP src add-ons tracker mark_as ;
SetSubDirSupportedPlatformsBeOSCompatible ; SetSubDirSupportedPlatformsBeOSCompatible ;
UsePrivateHeaders mail ;
AddResources Mark\ as… : MarkAs.rdef ; AddResources Mark\ as… : MarkAs.rdef ;
AddResources Mark\ as\ Read-R : MarkAsRead.rdef ; AddResources Mark\ as\ Read-R : MarkAsRead.rdef ;
Addon Mark\ as… : Addon Mark\ as… :
MarkAs.cpp MarkAs.cpp
: be tracker $(TARGET_LIBSUPC++) : be tracker $(TARGET_LIBSUPC++) libmail.so
; ;
Addon Mark\ as\ Read-R : Addon Mark\ as\ Read-R :
MarkAsRead.cpp MarkAsRead.cpp
: be tracker $(TARGET_LIBSUPC++) : be tracker $(TARGET_LIBSUPC++) libmail.so
; ;

View File

@ -7,9 +7,12 @@
#include <new> #include <new>
#include <Directory.h> #include <Directory.h>
#include <E-mail.h>
#include <Entry.h> #include <Entry.h>
#include <FindDirectory.h> #include <FindDirectory.h>
#include <InterfaceDefs.h> #include <InterfaceDefs.h>
#include <MailDaemon.h>
#include <mail_util.h>
#include <MenuItem.h> #include <MenuItem.h>
#include <Message.h> #include <Message.h>
#include <Node.h> #include <Node.h>
@ -84,6 +87,7 @@ process_refs(entry_ref dir, BMessage* message, void* /*reserved*/)
return; return;
BString status = item->Label(); BString status = item->Label();
//TODO:This won't work anymore when the menu gets translated! Use index!
entry_ref ref; entry_ref ref;
for (int i = 0; message->FindRef("refs", i, &ref) == B_OK; i++) { 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 if (node.InitCheck() == B_OK
&& node.ReadAttrString("BEOS:TYPE", &type) == 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 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 // 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) || previousStatus != status)
node.WriteAttrString("MAIL:status", &status); node.WriteAttrString(B_MAIL_ATTR_STATUS, &status);
} }
} }
} }

View File

@ -1,7 +1,8 @@
resource app_signature "application/x-vnd.Haiku-MarkAs"; resource app_signature "application/x-vnd.Haiku-MarkAs";
resource file_types message { resource file_types message {
"types" = "text/x-email" "types" = "text/x-email",
"types" = "text/x-partial-email"
}; };
resource app_version { resource app_version {

View File

@ -5,12 +5,14 @@
*/ */
#include <E-mail.h>
#include <Entry.h> #include <Entry.h>
#include <MailDaemon.h>
#include <mail_util.h>
#include <Message.h> #include <Message.h>
#include <Node.h> #include <Node.h>
#include <String.h> #include <String.h>
extern "C" void extern "C" void
process_refs(entry_ref dir, BMessage* message, void* /*reserved*/) 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 if (node.InitCheck() == B_OK
&& node.ReadAttrString("BEOS:TYPE", &type) == 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 previousStatus;
BString status("Read"); 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 // 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) || previousStatus != status)
node.WriteAttrString("MAIL:status", &status); node.WriteAttrString(B_MAIL_ATTR_STATUS, &status);
} }
} }
} }

View File

@ -1,7 +1,8 @@
resource app_signature "application/x-vnd.Haiku-MarkAsRead"; resource app_signature "application/x-vnd.Haiku-MarkAsRead";
resource file_types message { resource file_types message {
"types" = "text/x-email" "types" = "text/x-email",
"types" = "text/x-partial-email"
}; };
resource app_version { resource app_version {