status_t BEmailMessage::Send(bool sendNow) { BMailAccounts accounts; BMailAccountSettings* account = accounts.AccountByID(_account_id); if (!account || !account->HasOutbound()) { account = accounts.AccountByID( BMailSettings().DefaultOutboundAccount()); if (!account) return B_ERROR; SendViaAccount(account->AccountID()); } BString path; if (account->OutboundSettings().Settings().FindString("path", &path) != B_OK) { BPath defaultMailOutPath; if (find_directory(B_USER_DIRECTORY, &defaultMailOutPath) != B_OK || defaultMailOutPath.Append("mail/out") != B_OK) path = "/boot/home/mail/out"; else path = defaultMailOutPath.Path(); } create_directory(path.String(), 0777); BDirectory directory(path.String()); BEntry message; status_t status = RenderTo(&directory, &message); if (status >= B_OK && sendNow) { BMailSettings settings_file; if (settings_file.SendOnlyIfPPPUp()) { // TODO! } BMessenger daemon(B_MAIL_DAEMON_SIGNATURE); if (!daemon.IsValid()) return B_MAIL_NO_DAEMON; BMessage msg('msnd'); msg.AddInt32("account",_account_id); BPath path; message.GetPath(&path); msg.AddString("message_path",path.Path()); daemon.SendMessage(&msg); } return status; }
void BEmailMessage::SendViaAccount(int32 account) { _account_id = account; BMailAccounts accounts; BMailAccountSettings* accountSettings = accounts.AccountByID(_account_id); BString from; if (accountSettings) { from << '\"' << accountSettings->RealName() << "\" <" << accountSettings->ReturnAddress() << '>'; } SetFrom(from); }
void MailDaemonApp::_ReloadAccounts(BMessage* message) { type_code typeFound; int32 countFound; message->GetInfo("account", &typeFound, &countFound); if (typeFound != B_INT32_TYPE) return; // reload accounts BMailAccounts accounts; for (int i = 0; i < countFound; i++) { int32 account = message->FindInt32("account", i); AccountMap::const_iterator it = fAccounts.find(account); if (it != fAccounts.end()) _RemoveAccount(it); BMailAccountSettings* settings = accounts.AccountByID(account); if (settings) _InitAccount(*settings); } }
status_t BEmailMessage::GetAccountName(BString& accountName) const { BFile *file = dynamic_cast<BFile *>(fData); if (file == NULL) return B_ERROR; 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; BMailAccounts accounts; BMailAccountSettings* account = accounts.AccountByID(accountId); if (account) accountName = account->Name(); else accountName = ""; return B_OK; }
BEmailMessage * BEmailMessage::ReplyMessage(mail_reply_to_mode replyTo, bool accountFromMail, const char *quoteStyle) { BEmailMessage *reply = new BEmailMessage; // Set ReplyTo: if (replyTo == B_MAIL_REPLY_TO_ALL) { reply->SetTo(From()); BList list; get_address_list(list, CC(), extract_address); get_address_list(list, To(), extract_address); // Filter out the sender BMailAccounts accounts; BMailAccountSettings* account = accounts.AccountByID(Account()); BString sender; if (account) sender = account->ReturnAddress(); extract_address(sender); BString cc; for (int32 i = list.CountItems(); i-- > 0;) { char *address = (char *)list.RemoveItem((int32)0); // add everything which is not the sender and not already in the list if (sender.ICompare(address) && cc.FindFirst(address) < 0) { if (cc.Length() > 0) cc << ", "; cc << address; } free(address); } if (cc.Length() > 0) reply->SetCC(cc.String()); } else if (replyTo == B_MAIL_REPLY_TO_SENDER || ReplyTo() == NULL) reply->SetTo(From()); else reply->SetTo(ReplyTo()); // Set special "In-Reply-To:" header (used for threading) const char *messageID = _body ? _body->HeaderField("Message-Id") : NULL; if (messageID != NULL) reply->SetHeaderField("In-Reply-To", messageID); // quote body text reply->SetBodyTextTo(BodyText()); if (quoteStyle) reply->Body()->Quote(quoteStyle); // Set the subject (and add a "Re:" if needed) BString string = Subject(); if (string.ICompare("re:", 3) != 0) string.Prepend("Re: "); reply->SetSubject(string.String()); // set the matching outbound chain if (accountFromMail) reply->SendViaAccountFrom(this); return reply; }