From a64bd5649d3aa752ef4672e72a2415861546997d Mon Sep 17 00:00:00 2001 From: Clemens Zeidler Date: Mon, 21 Mar 2011 09:13:12 +0000 Subject: [PATCH] Write MAIL:name, MAIL:thread and MAIL:account attribute. The account id is now stored in MAIL:account_id. This requires to re-download all mails to write the correct attribute (sorry). Fixes #7375. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@41062 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- headers/os/mail/E-mail.h | 3 ++ .../inbound_protocols/pop3/pop3.cpp | 2 +- src/apps/mail/MailWindow.cpp | 2 +- src/kits/mail/HaikuMailFormatFilter.cpp | 49 +++++++++++++++---- src/kits/mail/HaikuMailFormatFilter.h | 2 + src/kits/mail/MailMessage.cpp | 13 +++-- src/servers/mail/MailDaemon.cpp | 6 +-- 7 files changed, 57 insertions(+), 20 deletions(-) diff --git a/headers/os/mail/E-mail.h b/headers/os/mail/E-mail.h index 72662586c4..d64695d1c3 100644 --- a/headers/os/mail/E-mail.h +++ b/headers/os/mail/E-mail.h @@ -29,6 +29,9 @@ struct entry_ref; #define B_MAIL_ATTR_HEADER "MAIL:header_length" // int32 #define B_MAIL_ATTR_CONTENT "MAIL:content_length" // int32 #define B_MAIL_ATTR_READ "MAIL:read" // int32 +#define B_MAIL_ATTR_THREAD "MAIL:thread" // string +#define B_MAIL_ATTR_ACCOUNT "MAIL:account" // string +#define B_MAIL_ATTR_ACCOUNT_ID "MAIL:account_id" // int32 // read flags diff --git a/src/add-ons/mail_daemon/inbound_protocols/pop3/pop3.cpp b/src/add-ons/mail_daemon/inbound_protocols/pop3/pop3.cpp index e856b729fd..7a7684eec4 100644 --- a/src/add-ons/mail_daemon/inbound_protocols/pop3/pop3.cpp +++ b/src/add-ons/mail_daemon/inbound_protocols/pop3/pop3.cpp @@ -603,7 +603,7 @@ POP3Protocol::CheckForDeletedMessages() entry_ref entry; fido.SetVolume(&volume); - fido.PushAttr("MAIL:account"); + fido.PushAttr(B_MAIL_ATTR_ACCOUNT_ID); fido.PushInt32(fAccountSettings.AccountID()); fido.PushOp(B_EQ); diff --git a/src/apps/mail/MailWindow.cpp b/src/apps/mail/MailWindow.cpp index 43e4dfcb9b..1b42d3ea84 100644 --- a/src/apps/mail/MailWindow.cpp +++ b/src/apps/mail/MailWindow.cpp @@ -804,7 +804,7 @@ TMailWindow::MarkMessageRead(entry_ref* message, read_flags flag) return; int32 account; - if (node.ReadAttr("MAIL:account", B_INT32_TYPE, 0, &account, + if (node.ReadAttr(B_MAIL_ATTR_ACCOUNT_ID, B_INT32_TYPE, 0, &account, sizeof(account)) < 0) account = -1; diff --git a/src/kits/mail/HaikuMailFormatFilter.cpp b/src/kits/mail/HaikuMailFormatFilter.cpp index 99418e7850..24da45c795 100644 --- a/src/kits/mail/HaikuMailFormatFilter.cpp +++ b/src/kits/mail/HaikuMailFormatFilter.cpp @@ -35,12 +35,15 @@ static const mail_header_field gDefaultFields[] = { "Delivery-Date", B_MAIL_ATTR_WHEN, B_TIME_TYPE }, { "Reply-To", B_MAIL_ATTR_REPLY, B_STRING_TYPE }, { "Subject", B_MAIL_ATTR_SUBJECT, B_STRING_TYPE }, - { "X-Priority", B_MAIL_ATTR_PRIORITY, B_STRING_TYPE }, // Priorities with prefered - { "Priority", B_MAIL_ATTR_PRIORITY, B_STRING_TYPE }, // one first - the numeric - { "X-Msmail-Priority", B_MAIL_ATTR_PRIORITY, B_STRING_TYPE }, // one (has more levels). + { "X-Priority", B_MAIL_ATTR_PRIORITY, B_STRING_TYPE }, + // Priorities with prefered + { "Priority", B_MAIL_ATTR_PRIORITY, B_STRING_TYPE }, + // one first - the numeric + { "X-Msmail-Priority", B_MAIL_ATTR_PRIORITY, B_STRING_TYPE }, + // one (has more levels). { "Mime-Version", B_MAIL_ATTR_MIME, B_STRING_TYPE }, { "STATUS", B_MAIL_ATTR_STATUS, B_STRING_TYPE }, - { "THREAD", "MAIL:thread", B_STRING_TYPE }, //---Not supposed to be used for this (we add it in Parser), but why not? + { "THREAD", B_MAIL_ATTR_THREAD, B_STRING_TYPE }, { "NAME", B_MAIL_ATTR_NAME, B_STRING_TYPE }, { NULL, NULL, 0 } }; @@ -51,7 +54,8 @@ HaikuMailFormatFilter::HaikuMailFormatFilter(MailProtocol& protocol, : MailFilter(protocol, NULL), - fAccountId(settings->AccountID()) + fAccountId(settings->AccountID()), + fAccountName(settings->Name()) { const BMessage* outboundSettings = &settings->OutboundSettings().Settings(); if (outboundSettings->FindString("destination", &fOutboundDirectory) @@ -68,7 +72,8 @@ HaikuMailFormatFilter::HeaderFetched(const entry_ref& ref, BFile* file) BMessage attributes; // TODO attributes.AddInt32(B_MAIL_ATTR_CONTENT, length); - attributes.AddInt32("MAIL:account", fAccountId); + attributes.AddInt32(B_MAIL_ATTR_ACCOUNT_ID, fAccountId); + attributes.AddString(B_MAIL_ATTR_ACCOUNT, fAccountName); BString header; off_t size; @@ -102,16 +107,16 @@ HaikuMailFormatFilter::HeaderFetched(const entry_ref& ref, BFile* file) } } - (*file) << attributes; - + BString senderName = _ExtractName(attributes.FindString(B_MAIL_ATTR_FROM)); + attributes.AddString(B_MAIL_ATTR_NAME, senderName); // Generate a file name for the incoming message. See also // Message::RenderTo which does a similar thing for outgoing messages. - - BString name = attributes.FindString("MAIL:subject"); + BString name = attributes.FindString(B_MAIL_ATTR_SUBJECT); SubjectToThread(name); // Extract the core subject words. if (name.Length() <= 0) name = "No Subject"; + attributes.AddString(B_MAIL_ATTR_THREAD, name); if (name[0] == '.') name.Prepend ("_"); // Avoid hidden files, starting with a dot. @@ -171,6 +176,8 @@ HaikuMailFormatFilter::HeaderFetched(const entry_ref& ref, BFile* file) fMailProtocol.FileRenamed(ref, to); } + (*file) << attributes; + BNodeInfo info(file); info.SetType(B_PARTIAL_MAIL_TYPE); } @@ -205,3 +212,25 @@ HaikuMailFormatFilter::_SetFileName(const entry_ref& ref, const BString& name) BEntry entry(&ref); return entry.Rename(name); } + + +BString +HaikuMailFormatFilter::_ExtractName(const BString& from) +{ + BString name; + + int32 emailStart = from.FindFirst("<"); + if (emailStart < 0) + name = from; + + from.CopyInto(name, 0, emailStart); + name.Trim(); + if (name.Length() < 2) + return from; + + if (name[name.Length() - 1] == '\"') + name.Truncate(name.Length() - 1, true); + if (name[0] == '\"') + name.Remove(0, 1); + return name; +} diff --git a/src/kits/mail/HaikuMailFormatFilter.h b/src/kits/mail/HaikuMailFormatFilter.h index adde70acc4..c72ec779a4 100644 --- a/src/kits/mail/HaikuMailFormatFilter.h +++ b/src/kits/mail/HaikuMailFormatFilter.h @@ -26,8 +26,10 @@ public: private: status_t _SetFileName(const entry_ref& ref, const BString& name); + BString _ExtractName(const BString& from); int32 fAccountId; + BString fAccountName; BString fOutboundDirectory; }; diff --git a/src/kits/mail/MailMessage.cpp b/src/kits/mail/MailMessage.cpp index f210ff13d6..12e147d58f 100644 --- a/src/kits/mail/MailMessage.cpp +++ b/src/kits/mail/MailMessage.cpp @@ -636,10 +636,13 @@ BEmailMessage::RetrieveTextBody(BMailComponent *component) status_t -BEmailMessage::SetToRFC822(BPositionIO *mail_file, size_t length, bool parse_now) +BEmailMessage::SetToRFC822(BPositionIO *mail_file, size_t length, + bool parse_now) { - if (BFile *file = dynamic_cast(mail_file)) - file->ReadAttr("MAIL:account",B_INT32_TYPE,0,&_account_id,sizeof(_account_id)); + if (BFile *file = dynamic_cast(mail_file)) { + file->ReadAttr(B_MAIL_ATTR_ACCOUNT_ID, B_INT32_TYPE, 0, &_account_id, + sizeof(_account_id)); + } mail_file->Seek(0,SEEK_END); length = mail_file->Position(); @@ -806,8 +809,8 @@ BEmailMessage::RenderToRFC822(BPositionIO *file) attributed->WriteAttr(B_MAIL_ATTR_FLAGS, B_INT32_TYPE, 0, &flags, sizeof(int32)); - attributed->WriteAttr("MAIL:account", B_INT32_TYPE, 0, &_account_id, - sizeof(int32)); + attributed->WriteAttr(B_MAIL_ATTR_ACCOUNT_ID, B_INT32_TYPE, 0, + &_account_id, sizeof(int32)); } return B_OK; diff --git a/src/servers/mail/MailDaemon.cpp b/src/servers/mail/MailDaemon.cpp index 22dd336110..f980450b2f 100644 --- a/src/servers/mail/MailDaemon.cpp +++ b/src/servers/mail/MailDaemon.cpp @@ -193,7 +193,7 @@ MailDaemonApp::RefsReceived(BMessage* message) continue; int32 account; - if (node.ReadAttr("MAIL:account", B_INT32_TYPE, 0, &account, + if (node.ReadAttr(B_MAIL_ATTR_ACCOUNT_ID, B_INT32_TYPE, 0, &account, sizeof(account)) < 0) continue; @@ -724,7 +724,7 @@ MailDaemonApp::SendPendingMessages(BMessage* msg) query.PushOp(B_EQ); if (account >= 0) { - query.PushAttr("MAIL:account"); + query.PushAttr(B_MAIL_ATTR_ACCOUNT_ID); query.PushInt32(account); query.PushOp(B_EQ); query.PushOp(B_AND); @@ -744,7 +744,7 @@ MailDaemonApp::SendPendingMessages(BMessage* msg) continue; int32 messageAccount; - if (node.ReadAttr("MAIL:account", B_INT32_TYPE, 0, + if (node.ReadAttr(B_MAIL_ATTR_ACCOUNT_ID, B_INT32_TYPE, 0, &messageAccount, sizeof(int32)) < 0) messageAccount = -1;