[haiku-commits] r40504 - in haiku/trunk: headers/os/mail src/apps/mail src/kits/mail src/servers/mail

  • From: clemens.zeidler@xxxxxxxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Tue, 15 Feb 2011 03:19:50 +0100 (CET)

Author: czeidler
Date: 2011-02-15 03:19:49 +0100 (Tue, 15 Feb 2011)
New Revision: 40504
Changeset: http://dev.haiku-os.org/changeset/40504

Modified:
   haiku/trunk/headers/os/mail/E-mail.h
   haiku/trunk/headers/os/mail/MailDaemon.h
   haiku/trunk/headers/os/mail/MailMessage.h
   haiku/trunk/src/apps/mail/Header.cpp
   haiku/trunk/src/apps/mail/MailWindow.cpp
   haiku/trunk/src/kits/mail/MailDaemon.cpp
   haiku/trunk/src/kits/mail/MailMessage.cpp
   haiku/trunk/src/kits/mail/MailProtocol.cpp
   haiku/trunk/src/servers/mail/MailDaemon.cpp
Log:
Fix account name in mail.
Work in progress: fetch next partial downloaded message.



Modified: haiku/trunk/headers/os/mail/E-mail.h
===================================================================
--- haiku/trunk/headers/os/mail/E-mail.h        2011-02-15 02:00:58 UTC (rev 
40503)
+++ haiku/trunk/headers/os/mail/E-mail.h        2011-02-15 02:19:49 UTC (rev 
40504)
@@ -41,6 +41,7 @@
 };
 
 #define B_MAIL_TYPE                            "text/x-email"                  
// mime type
+#define B_PARTIAL_MAIL_TYPE            "text/x-partial-email"  // mime type
 
 
 // WARNING: Everything past this point is deprecated. See MailMessage.h,

Modified: haiku/trunk/headers/os/mail/MailDaemon.h
===================================================================
--- haiku/trunk/headers/os/mail/MailDaemon.h    2011-02-15 02:00:58 UTC (rev 
40503)
+++ haiku/trunk/headers/os/mail/MailDaemon.h    2011-02-15 02:19:49 UTC (rev 
40504)
@@ -15,6 +15,7 @@
 const uint32 kMsgSetStatusWindowMode = 'shst';
 const uint32 kMsgCountNewMessages = 'mnum';
 const uint32 kMsgMarkMessageAsRead = 'mmar';
+const uint32 kMsgFetchBody = 'mfeb';
 
 
 class BMailDaemon {
@@ -27,7 +28,7 @@
                                                                        bool 
waitForFetchCompletion = false);
        static status_t                         MarkAsRead(int32 account, const 
entry_ref& ref,
                                                                        bool 
read = true);
-
+       static status_t                         FetchBody(const entry_ref& ref);
        static status_t                         Quit();
 };
 

Modified: haiku/trunk/headers/os/mail/MailMessage.h
===================================================================
--- haiku/trunk/headers/os/mail/MailMessage.h   2011-02-15 02:00:58 UTC (rev 
40503)
+++ haiku/trunk/headers/os/mail/MailMessage.h   2011-02-15 02:19:49 UTC (rev 
40504)
@@ -63,8 +63,7 @@
                void SendViaAccount(const char *account_name);
                void SendViaAccount(int32 account);
                int32 Account() const;
-               status_t GetAccountName(char *account,int32 maxLength) const;
-               status_t GetAccountName(BString *account) const;
+               status_t GetAccountName(BString& accountName) const;
 
                virtual status_t AddComponent(BMailComponent *component);
                virtual status_t RemoveComponent(BMailComponent *component);

Modified: haiku/trunk/src/apps/mail/Header.cpp
===================================================================
--- haiku/trunk/src/apps/mail/Header.cpp        2011-02-15 02:00:58 UTC (rev 
40503)
+++ haiku/trunk/src/apps/mail/Header.cpp        2011-02-15 02:19:49 UTC (rev 
40504)
@@ -730,8 +730,9 @@
        if (fAccountTo != NULL)
                fAccountTo->SetText(mail->To());
 
-       if (fAccount != NULL && mail->GetAccountName(string,sizeof(string)) == 
B_OK)
-               fAccount->SetText(string);
+       BString accountName;
+       if (fAccount != NULL && mail->GetAccountName(accountName) == B_OK)
+               fAccount->SetText(accountName);
 
        return B_OK;
 }

Modified: haiku/trunk/src/apps/mail/MailWindow.cpp
===================================================================
--- haiku/trunk/src/apps/mail/MailWindow.cpp    2011-02-15 02:00:58 UTC (rev 
40503)
+++ haiku/trunk/src/apps/mail/MailWindow.cpp    2011-02-15 02:19:49 UTC (rev 
40504)
@@ -788,7 +788,8 @@
                if (BNodeInfo(&node).GetType(fileType) != B_OK)
                        return false;
 
-               if (strcasecmp(fileType,"text/x-email") == 0)
+               if (strcasecmp(fileType, B_MAIL_TYPE) == 0
+                       || strcasecmp(fileType, B_PARTIAL_MAIL_TYPE) == 0)
                        foundRef = true;
        }
 
@@ -1504,8 +1505,8 @@
                        if (fRef != NULL) {
                                entry_ref nextRef = *fRef;
                                if (GetTrackerWindowFile(&nextRef, (msg->what 
== M_NEXTMSG))) {
-                                       TMailWindow *window
-                                               = static_cast<TMailApp 
*>(be_app)->FindWindow(nextRef);
+                                       TMailWindow *window = 
static_cast<TMailApp *>(be_app)
+                                               ->FindWindow(nextRef);
                                        if (window == NULL) {
                                                if (fAutoMarkRead)
                                                        SetCurrentMessageRead();
@@ -2820,9 +2821,14 @@
        BNodeInfo fileInfo(&file);
        fileInfo.GetType(mimeType);
 
+       if (strcmp(mimeType, B_PARTIAL_MAIL_TYPE) == 0) {
+               BMailDaemon::FetchBody(*ref);
+               fileInfo.GetType(mimeType);
+       }
+
        // Check if it's a draft file, which contains only the text, and has the
        // from, to, bcc, attachments listed as attributes.
-       if (!strcmp(kDraftType, mimeType)) {
+       if (strcmp(kDraftType, mimeType) == 0) {
                BNode node(fRef);
                off_t size;
                BString string;

Modified: haiku/trunk/src/kits/mail/MailDaemon.cpp
===================================================================
--- haiku/trunk/src/kits/mail/MailDaemon.cpp    2011-02-15 02:00:58 UTC (rev 
40503)
+++ haiku/trunk/src/kits/mail/MailDaemon.cpp    2011-02-15 02:19:49 UTC (rev 
40504)
@@ -82,11 +82,26 @@
        message.AddRef("ref", &ref);
        message.AddBool("read", read);
 
-       return daemon.SendMessage(&message);    
+       return daemon.SendMessage(&message);
 }
 
 
 status_t
+BMailDaemon::FetchBody(const entry_ref& ref)
+{
+       BMessenger daemon("application/x-vnd.Be-POST");
+       if (!daemon.IsValid())
+               return B_MAIL_NO_DAEMON;
+
+       BMessage message(kMsgFetchBody);
+       message.AddRef("refs", &ref);
+
+       BMessage reply;
+       return daemon.SendMessage(&message, &reply);
+}
+
+
+status_t
 BMailDaemon::Quit()
 {
        BMessenger daemon("application/x-vnd.Be-POST");

Modified: haiku/trunk/src/kits/mail/MailMessage.cpp
===================================================================
--- haiku/trunk/src/kits/mail/MailMessage.cpp   2011-02-15 02:00:58 UTC (rev 
40503)
+++ haiku/trunk/src/kits/mail/MailMessage.cpp   2011-02-15 02:19:49 UTC (rev 
40504)
@@ -389,8 +389,8 @@
 void
 BEmailMessage::SendViaAccountFrom(BEmailMessage *message)
 {
-       char name[B_FILE_NAME_LENGTH];
-       if (message->GetAccountName(name, B_FILE_NAME_LENGTH) < B_OK) {
+       BString name;
+       if (message->GetAccountName(name) < B_OK) {
                // just return the message with the default account
                return;
        }
@@ -435,35 +435,30 @@
 
 
 status_t
-BEmailMessage::GetAccountName(char *account,int32 maxLength) const
+BEmailMessage::GetAccountName(BString& accountName) const
 {
-       if (account == NULL || maxLength <= 0)
-               return B_BAD_VALUE;
+       BFile *file = dynamic_cast<BFile *>(fData);
+       if (!file)
+               return B_ERROR;
 
-       if (BFile *file = dynamic_cast<BFile *>(fData)) {
-               status_t status = 
file->ReadAttr(B_MAIL_ATTR_ACCOUNT,B_STRING_TYPE,0,account,maxLength);
-               account[maxLength - 1] = '\0';
+       int32 accountId;
+       size_t read = file->ReadAttr(B_MAIL_ATTR_ACCOUNT, B_INT32_TYPE, 0,
+               &accountId, sizeof(int32));
+       if (read < sizeof(int32))
+               return B_ERROR;
 
-               return status >= 0 ? B_OK : status;
-       }
+       BMailAccounts accounts;
+       BMailAccountSettings* account =  accounts.AccountByID(accountId);
+       if (account)
+               accountName = account->Name();
+       else
+               accountName = "";
 
-       // ToDo: try to get account name out of the chain lists
-       return B_ERROR;
+       return B_OK;
 }
 
 
 status_t
-BEmailMessage::GetAccountName(BString *account) const
-{
-       char *buffer = account->LockBuffer(B_FILE_NAME_LENGTH);
-       status_t status = GetAccountName(buffer,B_FILE_NAME_LENGTH);
-       account->UnlockBuffer();
-
-       return status;
-}
-
-
-status_t
 BEmailMessage::AddComponent(BMailComponent *component)
 {
        status_t status = B_OK;
@@ -798,22 +793,21 @@
                        attributed->WriteAttrString(B_MAIL_ATTR_PRIORITY,&attr);
                }
                attr = "Pending";
-               attributed->WriteAttrString(B_MAIL_ATTR_STATUS,&attr);
+               attributed->WriteAttrString(B_MAIL_ATTR_STATUS, &attr);
                attr = "1.0";
-               attributed->WriteAttrString(B_MAIL_ATTR_MIME,&attr);
-               BMailAccounts accounts;
-               BMailAccountSettings* account =  
accounts.AccountByID(_account_id);
-               if (account)
-                       attr = account->Name();
-               else
-                       attr = "";
-               attributed->WriteAttrString(B_MAIL_ATTR_ACCOUNT,&attr);
+               attributed->WriteAttrString(B_MAIL_ATTR_MIME, &attr);
+               
+               attributed->WriteAttr(B_MAIL_ATTR_ACCOUNT, B_INT32_TYPE, 0,
+                       &_account_id, sizeof(int32));
 
-               
attributed->WriteAttr(B_MAIL_ATTR_WHEN,B_TIME_TYPE,0,&creationTime,sizeof(int32));
+               attributed->WriteAttr(B_MAIL_ATTR_WHEN, B_TIME_TYPE, 0, 
&creationTime,
+                       sizeof(int32));
                int32 flags = B_MAIL_PENDING | B_MAIL_SAVE;
-               
attributed->WriteAttr(B_MAIL_ATTR_FLAGS,B_INT32_TYPE,0,&flags,sizeof(int32));
+               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("MAIL:account", B_INT32_TYPE, 0, 
&_account_id,
+                       sizeof(int32));
        }
 
        return B_OK;

Modified: haiku/trunk/src/kits/mail/MailProtocol.cpp
===================================================================
--- haiku/trunk/src/kits/mail/MailProtocol.cpp  2011-02-15 02:00:58 UTC (rev 
40503)
+++ haiku/trunk/src/kits/mail/MailProtocol.cpp  2011-02-15 02:19:49 UTC (rev 
40504)
@@ -406,9 +406,9 @@
 InboundProtocol::MarkMessageAsRead(const entry_ref& ref, bool read)
 {
        BNode node(&ref);
-       BString statusString = (read == true) ? "Read" : "New";
-       if (node.WriteAttr("MAIL:status", B_STRING_TYPE, 0, 
statusString.String(),
-               statusString.Length()) < 0)
+       const char* statusString = (read == true) ? "Read" : "New";
+       if (node.WriteAttr(B_MAIL_ATTR_STATUS, B_STRING_TYPE, 0, statusString,
+               strlen(statusString)) < 0)
                return B_ERROR;
        return B_OK;
 }

Modified: haiku/trunk/src/servers/mail/MailDaemon.cpp
===================================================================
--- haiku/trunk/src/servers/mail/MailDaemon.cpp 2011-02-15 02:00:58 UTC (rev 
40503)
+++ haiku/trunk/src/servers/mail/MailDaemon.cpp 2011-02-15 02:19:49 UTC (rev 
40504)
@@ -437,6 +437,10 @@
                        break;
                }
 
+               case kMsgFetchBody:
+                       RefsReceived(msg);
+                       break;
+
                case 'lkch':    // status window look changed
                case 'wsch':    // workspace changed
                        fMailStatusWindow->PostMessage(msg);


Other related posts:

  • » [haiku-commits] r40504 - in haiku/trunk: headers/os/mail src/apps/mail src/kits/mail src/servers/mail - clemens . zeidler