Fix account name in mail.

Work in progress: fetch next partial downloaded message.



git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@40504 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Clemens Zeidler
2011-02-15 02:19:49 +00:00
parent 9c4e0ece54
commit df0ad9c12a
9 changed files with 69 additions and 48 deletions
+1
View File
@@ -41,6 +41,7 @@ enum mail_flags {
}; };
#define B_MAIL_TYPE "text/x-email" // mime type #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, // WARNING: Everything past this point is deprecated. See MailMessage.h,
+2 -1
View File
@@ -15,6 +15,7 @@ const uint32 kMsgAccountsChanged = 'macc';
const uint32 kMsgSetStatusWindowMode = 'shst'; const uint32 kMsgSetStatusWindowMode = 'shst';
const uint32 kMsgCountNewMessages = 'mnum'; const uint32 kMsgCountNewMessages = 'mnum';
const uint32 kMsgMarkMessageAsRead = 'mmar'; const uint32 kMsgMarkMessageAsRead = 'mmar';
const uint32 kMsgFetchBody = 'mfeb';
class BMailDaemon { class BMailDaemon {
@@ -27,7 +28,7 @@ public:
bool waitForFetchCompletion = false); bool waitForFetchCompletion = false);
static status_t MarkAsRead(int32 account, const entry_ref& ref, static status_t MarkAsRead(int32 account, const entry_ref& ref,
bool read = true); bool read = true);
static status_t FetchBody(const entry_ref& ref);
static status_t Quit(); static status_t Quit();
}; };
+1 -2
View File
@@ -63,8 +63,7 @@ class BEmailMessage : public BMailContainer {
void SendViaAccount(const char *account_name); void SendViaAccount(const char *account_name);
void SendViaAccount(int32 account); void SendViaAccount(int32 account);
int32 Account() const; int32 Account() const;
status_t GetAccountName(char *account,int32 maxLength) const; status_t GetAccountName(BString& accountName) const;
status_t GetAccountName(BString *account) const;
virtual status_t AddComponent(BMailComponent *component); virtual status_t AddComponent(BMailComponent *component);
virtual status_t RemoveComponent(BMailComponent *component); virtual status_t RemoveComponent(BMailComponent *component);
+3 -2
View File
@@ -730,8 +730,9 @@ THeaderView::LoadMessage(BEmailMessage *mail)
if (fAccountTo != NULL) if (fAccountTo != NULL)
fAccountTo->SetText(mail->To()); fAccountTo->SetText(mail->To());
if (fAccount != NULL && mail->GetAccountName(string,sizeof(string)) == B_OK) BString accountName;
fAccount->SetText(string); if (fAccount != NULL && mail->GetAccountName(accountName) == B_OK)
fAccount->SetText(accountName);
return B_OK; return B_OK;
} }
+10 -4
View File
@@ -788,7 +788,8 @@ TMailWindow::GetTrackerWindowFile(entry_ref *ref, bool next) const
if (BNodeInfo(&node).GetType(fileType) != B_OK) if (BNodeInfo(&node).GetType(fileType) != B_OK)
return false; 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; foundRef = true;
} }
@@ -1504,8 +1505,8 @@ TMailWindow::MessageReceived(BMessage *msg)
if (fRef != NULL) { if (fRef != NULL) {
entry_ref nextRef = *fRef; entry_ref nextRef = *fRef;
if (GetTrackerWindowFile(&nextRef, (msg->what == M_NEXTMSG))) { if (GetTrackerWindowFile(&nextRef, (msg->what == M_NEXTMSG))) {
TMailWindow *window TMailWindow *window = static_cast<TMailApp *>(be_app)
= static_cast<TMailApp *>(be_app)->FindWindow(nextRef); ->FindWindow(nextRef);
if (window == NULL) { if (window == NULL) {
if (fAutoMarkRead) if (fAutoMarkRead)
SetCurrentMessageRead(); SetCurrentMessageRead();
@@ -2820,9 +2821,14 @@ TMailWindow::OpenMessage(entry_ref *ref, uint32 characterSetForDecoding)
BNodeInfo fileInfo(&file); BNodeInfo fileInfo(&file);
fileInfo.GetType(mimeType); 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 // Check if it's a draft file, which contains only the text, and has the
// from, to, bcc, attachments listed as attributes. // from, to, bcc, attachments listed as attributes.
if (!strcmp(kDraftType, mimeType)) { if (strcmp(kDraftType, mimeType) == 0) {
BNode node(fRef); BNode node(fRef);
off_t size; off_t size;
BString string; BString string;
+16 -1
View File
@@ -82,7 +82,22 @@ BMailDaemon::MarkAsRead(int32 account, const entry_ref& ref, bool read)
message.AddRef("ref", &ref); message.AddRef("ref", &ref);
message.AddBool("read", read); 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);
} }
+29 -35
View File
@@ -389,8 +389,8 @@ BEmailMessage::GetName(BString *name) const
void void
BEmailMessage::SendViaAccountFrom(BEmailMessage *message) BEmailMessage::SendViaAccountFrom(BEmailMessage *message)
{ {
char name[B_FILE_NAME_LENGTH]; BString name;
if (message->GetAccountName(name, B_FILE_NAME_LENGTH) < B_OK) { if (message->GetAccountName(name) < B_OK) {
// just return the message with the default account // just return the message with the default account
return; return;
} }
@@ -435,31 +435,26 @@ BEmailMessage::Account() const
status_t status_t
BEmailMessage::GetAccountName(char *account,int32 maxLength) const BEmailMessage::GetAccountName(BString& accountName) const
{ {
if (account == NULL || maxLength <= 0) BFile *file = dynamic_cast<BFile *>(fData);
return B_BAD_VALUE; if (!file)
return B_ERROR;
if (BFile *file = dynamic_cast<BFile *>(fData)) { int32 accountId;
status_t status = file->ReadAttr(B_MAIL_ATTR_ACCOUNT,B_STRING_TYPE,0,account,maxLength); size_t read = file->ReadAttr(B_MAIL_ATTR_ACCOUNT, B_INT32_TYPE, 0,
account[maxLength - 1] = '\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_OK;
return B_ERROR;
}
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;
} }
@@ -798,22 +793,21 @@ BEmailMessage::RenderToRFC822(BPositionIO *file)
attributed->WriteAttrString(B_MAIL_ATTR_PRIORITY,&attr); attributed->WriteAttrString(B_MAIL_ATTR_PRIORITY,&attr);
} }
attr = "Pending"; attr = "Pending";
attributed->WriteAttrString(B_MAIL_ATTR_STATUS,&attr); attributed->WriteAttrString(B_MAIL_ATTR_STATUS, &attr);
attr = "1.0"; attr = "1.0";
attributed->WriteAttrString(B_MAIL_ATTR_MIME,&attr); attributed->WriteAttrString(B_MAIL_ATTR_MIME, &attr);
BMailAccounts accounts;
BMailAccountSettings* account = accounts.AccountByID(_account_id); attributed->WriteAttr(B_MAIL_ATTR_ACCOUNT, B_INT32_TYPE, 0,
if (account) &_account_id, sizeof(int32));
attr = account->Name();
else
attr = "";
attributed->WriteAttrString(B_MAIL_ATTR_ACCOUNT,&attr);
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; 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; return B_OK;
+3 -3
View File
@@ -406,9 +406,9 @@ status_t
InboundProtocol::MarkMessageAsRead(const entry_ref& ref, bool read) InboundProtocol::MarkMessageAsRead(const entry_ref& ref, bool read)
{ {
BNode node(&ref); BNode node(&ref);
BString statusString = (read == true) ? "Read" : "New"; const char* statusString = (read == true) ? "Read" : "New";
if (node.WriteAttr("MAIL:status", B_STRING_TYPE, 0, statusString.String(), if (node.WriteAttr(B_MAIL_ATTR_STATUS, B_STRING_TYPE, 0, statusString,
statusString.Length()) < 0) strlen(statusString)) < 0)
return B_ERROR; return B_ERROR;
return B_OK; return B_OK;
} }
+4
View File
@@ -437,6 +437,10 @@ MailDaemonApp::MessageReceived(BMessage* msg)
break; break;
} }
case kMsgFetchBody:
RefsReceived(msg);
break;
case 'lkch': // status window look changed case 'lkch': // status window look changed
case 'wsch': // workspace changed case 'wsch': // workspace changed
fMailStatusWindow->PostMessage(msg); fMailStatusWindow->PostMessage(msg);