mail_daemon: cleanup, 30s auto check startup delay.

* Refactored new message retrieval a bit, so that the notification strings
  aren't duplicated.
* The daemon now waits 30 seconds before doing the first mail check.
This commit is contained in:
Axel Dörfler
2015-01-06 15:26:14 +01:00
parent 29e5da6f20
commit 8705e1f6e7
6 changed files with 78 additions and 92 deletions
-33
View File
@@ -3205,39 +3205,6 @@ BMessage::SetString(const char* name, const char* value)
} }
const char*
BMessage::GetString(const char *name, const char *defaultValue) const
{
return GetString(name, 0, defaultValue);
}
const char*
BMessage::GetString(const char *name, int32 index,
const char *defaultValue) const
{
const char* value;
if (FindString(name, index, &value) == B_OK)
return value;
return defaultValue;
}
status_t
BMessage::SetString(const char *name, const BString& value)
{
return SetData(name, B_STRING_TYPE, value.String(), value.Length() + 1);
}
status_t
BMessage::SetString(const char *name, const char* value)
{
return SetData(name, B_STRING_TYPE, value, strlen(value) + 1);
}
status_t status_t
BMessage::SetData(const char* name, type_code type, const void* data, BMessage::SetData(const char* name, type_code type, const void* data,
ssize_t numBytes) ssize_t numBytes)
+2 -3
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2004-2012, Haiku Inc. All rights reserved. * Copyright 2004-2015, Haiku Inc. All rights reserved.
* Copyright 2001-2003 Dr. Zoidberg Enterprises. All rights reserved. * Copyright 2001-2003 Dr. Zoidberg Enterprises. All rights reserved.
* *
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
@@ -79,7 +79,7 @@ BMailSettings::Reload()
// Try directories from most specific to least // Try directories from most specific to least
directory_which which[] = { directory_which which[] = {
B_USER_SETTINGS_DIRECTORY, B_USER_SETTINGS_DIRECTORY,
B_COMMON_SETTINGS_DIRECTORY}; B_SYSTEM_SETTINGS_DIRECTORY};
status_t status = B_ENTRY_NOT_FOUND; status_t status = B_ENTRY_NOT_FOUND;
for (size_t i = 0; i < sizeof(which) / sizeof(which[0]); i++) { for (size_t i = 0; i < sizeof(which) / sizeof(which[0]); i++) {
@@ -434,7 +434,6 @@ BMailAddOnSettings::Load(const BMessage& message)
if (!path.IsAbsolute()) { if (!path.IsAbsolute()) {
directory_which which[] = { directory_which which[] = {
B_USER_ADDONS_DIRECTORY, B_USER_ADDONS_DIRECTORY,
B_COMMON_ADDONS_DIRECTORY,
B_SYSTEM_ADDONS_DIRECTORY B_SYSTEM_ADDONS_DIRECTORY
}; };
+1 -2
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2007-2011, Haiku, Inc. All rights reserved. * Copyright 2007-2015, Haiku, Inc. All rights reserved.
* Copyright 2011, Clemens Zeidler <haiku@clemens-zeidler.de> * Copyright 2011, Clemens Zeidler <haiku@clemens-zeidler.de>
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
@@ -204,7 +204,6 @@ AutoConfigView::_GetSMTPAddonRef(entry_ref *ref)
{ {
directory_which which[] = { directory_which which[] = {
B_USER_ADDONS_DIRECTORY, B_USER_ADDONS_DIRECTORY,
B_COMMON_ADDONS_DIRECTORY,
B_BEOS_ADDONS_DIRECTORY B_BEOS_ADDONS_DIRECTORY
}; };
-1
View File
@@ -35,7 +35,6 @@ FilterList::Reload()
std::set<BString> knownNames; std::set<BString> knownNames;
directory_which which[] = {B_USER_ADDONS_DIRECTORY, directory_which which[] = {B_USER_ADDONS_DIRECTORY,
B_COMMON_ADDONS_DIRECTORY,
B_SYSTEM_ADDONS_DIRECTORY}; B_SYSTEM_ADDONS_DIRECTORY};
for (size_t i = 0; i < sizeof(which) / sizeof(which[0]); i++) { for (size_t i = 0; i < sizeof(which) / sizeof(which[0]); i++) {
BPath path; BPath path;
+71 -51
View File
@@ -40,8 +40,13 @@
#define B_TRANSLATION_CONTEXT "MailDaemon" #define B_TRANSLATION_CONTEXT "MailDaemon"
static const uint32 kMsgStartAutoCheck = 'stAC';
static const uint32 kMsgAutoCheck = 'moto'; static const uint32 kMsgAutoCheck = 'moto';
static const bigtime_t kStartAutoCheckDelay = 30000000;
// Wait 30 seconds before the first auto check - this usually lets the
// boot process settle down, and give the network a chance to come up.
struct send_mails_info { struct send_mails_info {
send_mails_info() send_mails_info()
@@ -213,53 +218,20 @@ MailDaemonApplication::ReadyToRun()
InstallDeskbarIcon(); InstallDeskbarIcon();
_InitAccounts(); _InitAccounts();
_UpdateAutoCheck(fSettingsFile.AutoCheckInterval());
BVolume volume; // Start auto mail check with a delay
BVolumeRoster roster; BMessage startAutoCheck(kMsgStartAutoCheck);
BMessageRunner::StartSending(this, &startAutoCheck,
kStartAutoCheckDelay, 1);
fNewMessages = 0; _InitNewMessagesCount();
while (roster.GetNextVolume(&volume) == B_OK) {
BQuery* query = new BQuery;
query->SetTarget(this);
query->SetVolume(&volume);
query->PushAttr(B_MAIL_ATTR_STATUS);
query->PushString("New");
query->PushOp(B_EQ);
query->PushAttr("BEOS:TYPE");
query->PushString("text/x-email");
query->PushOp(B_EQ);
query->PushAttr("BEOS:TYPE");
query->PushString("text/x-partial-email");
query->PushOp(B_EQ);
query->PushOp(B_OR);
query->PushOp(B_AND);
query->Fetch();
BEntry entry;
while (query->GetNextEntry(&entry) == B_OK)
fNewMessages++;
fQueries.AddItem(query);
}
BString string;
if (fNewMessages > 0) {
BMessageFormat format(B_TRANSLATE(
"{0, plural, one{One new message} other{# new messages}}"));
format.Format(string, fNewMessages);
} else
string = B_TRANSLATE("No new messages");
fCentralBeep = false; fCentralBeep = false;
fNotification = new BNotification(B_INFORMATION_NOTIFICATION); fNotification = new BNotification(B_INFORMATION_NOTIFICATION);
fNotification->SetGroup(B_TRANSLATE("Mail status")); fNotification->SetGroup(B_TRANSLATE("Mail status"));
fNotification->SetTitle(string);
fNotification->SetMessageID("daemon_status"); fNotification->SetMessageID("daemon_status");
_UpdateNewMessagesNotification();
app_info info; app_info info;
be_roster->GetAppInfo(B_MAIL_DAEMON_SIGNATURE, &info); be_roster->GetAppInfo(B_MAIL_DAEMON_SIGNATURE, &info);
@@ -268,7 +240,7 @@ MailDaemonApplication::ReadyToRun()
BIconUtils::GetVectorIcon(&node, "BEOS:ICON", &icon); BIconUtils::GetVectorIcon(&node, "BEOS:ICON", &icon);
fNotification->SetIcon(&icon); fNotification->SetIcon(&icon);
fLEDAnimation = new LEDAnimation; fLEDAnimation = new LEDAnimation();
SetPulseRate(1000000); SetPulseRate(1000000);
} }
@@ -305,6 +277,10 @@ void
MailDaemonApplication::MessageReceived(BMessage* msg) MailDaemonApplication::MessageReceived(BMessage* msg)
{ {
switch (msg->what) { switch (msg->what) {
case kMsgStartAutoCheck:
_UpdateAutoCheckRunner();
break;
case kMsgAutoCheck: case kMsgAutoCheck:
// TODO: check whether internet is up and running! // TODO: check whether internet is up and running!
// supposed to fall through // supposed to fall through
@@ -322,7 +298,7 @@ MailDaemonApplication::MessageReceived(BMessage* msg)
case kMsgSettingsUpdated: case kMsgSettingsUpdated:
fSettingsFile.Reload(); fSettingsFile.Reload();
_UpdateAutoCheck(fSettingsFile.AutoCheckInterval()); _UpdateAutoCheckRunner();
break; break;
case kMsgAccountsChanged: case kMsgAccountsChanged:
@@ -435,16 +411,8 @@ MailDaemonApplication::MessageReceived(BMessage* msg)
break; break;
} }
BString string; _UpdateNewMessagesNotification();
if (fNewMessages > 0) {
static BMessageFormat format(B_TRANSLATE(
"{0, plural, one{# new message.} other{# new messages.}}"));
format.Format(string, fNewMessages);
} else
string << B_TRANSLATE("No new messages.");
fNotification->SetTitle(string.String());
if (fNotifyMode != B_MAIL_SHOW_STATUS_WINDOW_NEVER) if (fNotifyMode != B_MAIL_SHOW_STATUS_WINDOW_NEVER)
fNotification->Send(); fNotification->Send();
break; break;
@@ -826,8 +794,60 @@ MailDaemonApplication::_OutboundProtocol(int32 account)
void void
MailDaemonApplication::_UpdateAutoCheck(bigtime_t interval) MailDaemonApplication::_InitNewMessagesCount()
{ {
BVolume volume;
BVolumeRoster roster;
fNewMessages = 0;
while (roster.GetNextVolume(&volume) == B_OK) {
BQuery* query = new BQuery;
query->SetTarget(this);
query->SetVolume(&volume);
query->PushAttr(B_MAIL_ATTR_STATUS);
query->PushString("New");
query->PushOp(B_EQ);
query->PushAttr("BEOS:TYPE");
query->PushString("text/x-email");
query->PushOp(B_EQ);
query->PushAttr("BEOS:TYPE");
query->PushString("text/x-partial-email");
query->PushOp(B_EQ);
query->PushOp(B_OR);
query->PushOp(B_AND);
query->Fetch();
BEntry entry;
while (query->GetNextEntry(&entry) == B_OK)
fNewMessages++;
fQueries.AddItem(query);
}
}
void
MailDaemonApplication::_UpdateNewMessagesNotification()
{
BString title;
if (fNewMessages > 0) {
BMessageFormat format(B_TRANSLATE(
"{0, plural, one{One new message} other{# new messages}}"));
format.Format(title, fNewMessages);
} else
title = B_TRANSLATE("No new messages");
fNotification->SetTitle(title.String());
}
void
MailDaemonApplication::_UpdateAutoCheckRunner()
{
bigtime_t interval = fSettingsFile.AutoCheckInterval();
if (interval > 0) { if (interval > 0) {
if (fAutoCheckRunner != NULL) { if (fAutoCheckRunner != NULL) {
fAutoCheckRunner->SetInterval(interval); fAutoCheckRunner->SetInterval(interval);
+4 -2
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2007-2012, Haiku, Inc. All rights reserved. * Copyright 2007-2013, Haiku, Inc. All rights reserved.
* Copyright 2001-2002 Dr. Zoidberg Enterprises. All rights reserved. * Copyright 2001-2002 Dr. Zoidberg Enterprises. All rights reserved.
* Copyright 2011, Clemens Zeidler <haiku@clemens-zeidler.de> * Copyright 2011, Clemens Zeidler <haiku@clemens-zeidler.de>
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
@@ -78,7 +78,9 @@ private:
BInboundMailProtocol* _InboundProtocol(int32 account); BInboundMailProtocol* _InboundProtocol(int32 account);
BOutboundMailProtocol* _OutboundProtocol(int32 account); BOutboundMailProtocol* _OutboundProtocol(int32 account);
void _UpdateAutoCheck(bigtime_t interval); void _InitNewMessagesCount();
void _UpdateNewMessagesNotification();
void _UpdateAutoCheckRunner();
void _AddMessage(send_mails_info& info, void _AddMessage(send_mails_info& info,
const BEntry& entry, const BNode& node); const BEntry& entry, const BNode& node);