1 /* 2 * Copyright 2009, Axel Dörfler, axeld@pinc-software.de. 3 * Copyright 2006, Ryan Leavengood, leavengood@gmail.com. All rights reserved. 4 * Distributed under the terms of the MIT License. 5 */ 6 7 8 #include <E-mail.h> 9 #include <Entry.h> 10 #include <MailDaemon.h> 11 #include <mail_util.h> 12 #include <Message.h> 13 #include <Node.h> 14 #include <String.h> 15 16 extern "C" void 17 process_refs(entry_ref dir, BMessage* message, void* /*reserved*/) 18 { 19 entry_ref ref; 20 for (int i = 0; message->FindRef("refs", i, &ref) == B_OK; i++) { 21 BNode node(&ref); 22 BString type; 23 24 if (node.InitCheck() == B_OK 25 && node.ReadAttrString("BEOS:TYPE", &type) == B_OK 26 && (type == B_MAIL_TYPE || type == B_PARTIAL_MAIL_TYPE)) { 27 BString previousStatus; 28 BString status("Read"); 29 read_flags previousRead; 30 // if we're marking it via the add-on, we haven't really read it 31 // so use B_SEEN instead of B_READ 32 read_flags read = B_SEEN; 33 34 // Update the MAIL:read status to match 35 // Check both B_SEEN and B_READ 36 // (so we don't overwrite B_READ with B_SEEN) 37 if (read_read_attr(node, previousRead) != B_OK || 38 (previousRead != B_SEEN && previousRead != B_READ)) { 39 int32 account; 40 if (node.ReadAttr(B_MAIL_ATTR_ACCOUNT_ID, B_INT32_TYPE, 41 0LL, &account, sizeof(account)) == sizeof(account)) 42 BMailDaemon::MarkAsRead(account, ref, read); 43 else 44 write_read_attr(node, read); 45 } 46 47 // We want to keep the previous behavior of updating the status 48 // string, but write_read_attr will only change the status string 49 // if it's one of "New", "Seen", or "Read" (and not, for example, 50 // "Replied"), so we change the status string here 51 // Only update the attribute if there is an actual change 52 if (node.ReadAttrString(B_MAIL_ATTR_STATUS, &previousStatus) != B_OK 53 || previousStatus != status) 54 node.WriteAttrString(B_MAIL_ATTR_STATUS, &status); 55 } 56 } 57 } 58 59