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:
parent
9c4e0ece54
commit
df0ad9c12a
@ -41,6 +41,7 @@ enum mail_flags {
|
||||
};
|
||||
|
||||
#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,
|
||||
|
@ -15,6 +15,7 @@ const uint32 kMsgAccountsChanged = 'macc';
|
||||
const uint32 kMsgSetStatusWindowMode = 'shst';
|
||||
const uint32 kMsgCountNewMessages = 'mnum';
|
||||
const uint32 kMsgMarkMessageAsRead = 'mmar';
|
||||
const uint32 kMsgFetchBody = 'mfeb';
|
||||
|
||||
|
||||
class BMailDaemon {
|
||||
@ -27,7 +28,7 @@ public:
|
||||
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();
|
||||
};
|
||||
|
||||
|
@ -63,8 +63,7 @@ class BEmailMessage : public BMailContainer {
|
||||
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);
|
||||
|
@ -730,8 +730,9 @@ THeaderView::LoadMessage(BEmailMessage *mail)
|
||||
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;
|
||||
}
|
||||
|
@ -788,7 +788,8 @@ TMailWindow::GetTrackerWindowFile(entry_ref *ref, bool next) const
|
||||
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 @@ TMailWindow::MessageReceived(BMessage *msg)
|
||||
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 @@ TMailWindow::OpenMessage(entry_ref *ref, uint32 characterSetForDecoding)
|
||||
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;
|
||||
|
@ -82,7 +82,22 @@ BMailDaemon::MarkAsRead(int32 account, const entry_ref& ref, bool read)
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
|
@ -389,8 +389,8 @@ BEmailMessage::GetName(BString *name) const
|
||||
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,31 +435,26 @@ BEmailMessage::Account() const
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
@ -798,22 +793,21 @@ BEmailMessage::RenderToRFC822(BPositionIO *file)
|
||||
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;
|
||||
|
@ -406,9 +406,9 @@ status_t
|
||||
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;
|
||||
}
|
||||
|
@ -437,6 +437,10 @@ MailDaemonApp::MessageReceived(BMessage* msg)
|
||||
break;
|
||||
}
|
||||
|
||||
case kMsgFetchBody:
|
||||
RefsReceived(msg);
|
||||
break;
|
||||
|
||||
case 'lkch': // status window look changed
|
||||
case 'wsch': // workspace changed
|
||||
fMailStatusWindow->PostMessage(msg);
|
||||
|
Loading…
x
Reference in New Issue
Block a user