* Removed BONE PPP support.
* Coding style cleanup. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@33600 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
+263
-239
@@ -1,7 +1,12 @@
|
|||||||
/* main - the daemon's inner workings
|
/*
|
||||||
**
|
* Copyright 2009, Axel Dörfler, [email protected].
|
||||||
** Copyright 2001 Dr. Zoidberg Enterprises. All rights reserved.
|
* Copyright 2001 Dr. Zoidberg Enterprises. All rights reserved.
|
||||||
*/
|
*
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
//! The daemon's inner workings
|
||||||
|
|
||||||
|
|
||||||
#include <Application.h>
|
#include <Application.h>
|
||||||
@@ -40,17 +45,6 @@
|
|||||||
|
|
||||||
#include <MDRLanguage.h>
|
#include <MDRLanguage.h>
|
||||||
|
|
||||||
#ifndef HAIKU_TARGET_PLATFORM_BEOS // BONE and later have these, R5 doesn't.
|
|
||||||
#define BONE_SERIAL_PPP_GET_STATUS 0xbe230501
|
|
||||||
#define BSPPP_CONNECTED 4
|
|
||||||
typedef struct {
|
|
||||||
char if_name[32];
|
|
||||||
int connection_status;
|
|
||||||
status_t last_error;
|
|
||||||
int connect_speed;
|
|
||||||
} bsppp_status_t;
|
|
||||||
#include <unistd.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
using std::map;
|
using std::map;
|
||||||
|
|
||||||
@@ -59,66 +53,70 @@ typedef struct glorbal {
|
|||||||
BStringList msgs;
|
BStringList msgs;
|
||||||
} snuzzwut;
|
} snuzzwut;
|
||||||
|
|
||||||
BMailStatusWindow *status;
|
|
||||||
|
static BMailStatusWindow* sStatus;
|
||||||
|
|
||||||
|
|
||||||
class MailDaemonApp : public BApplication {
|
class MailDaemonApp : public BApplication {
|
||||||
public:
|
public:
|
||||||
MailDaemonApp(void);
|
MailDaemonApp();
|
||||||
virtual ~MailDaemonApp();
|
virtual ~MailDaemonApp();
|
||||||
|
|
||||||
virtual void MessageReceived(BMessage *msg);
|
virtual void MessageReceived(BMessage* message);
|
||||||
virtual void RefsReceived(BMessage *a_message);
|
virtual void RefsReceived(BMessage* message);
|
||||||
|
|
||||||
virtual void Pulse();
|
virtual void Pulse();
|
||||||
virtual bool QuitRequested();
|
virtual bool QuitRequested();
|
||||||
virtual void ReadyToRun();
|
virtual void ReadyToRun();
|
||||||
|
|
||||||
void InstallDeskbarIcon();
|
void InstallDeskbarIcon();
|
||||||
void RemoveDeskbarIcon();
|
void RemoveDeskbarIcon();
|
||||||
|
|
||||||
void RunChains(BList &list,BMessage *msg);
|
void RunChains(BList& list, BMessage* message);
|
||||||
void SendPendingMessages(BMessage *msg);
|
void SendPendingMessages(BMessage* message);
|
||||||
void GetNewMessages(BMessage *msg);
|
void GetNewMessages(BMessage* message);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void UpdateAutoCheck(bigtime_t interval);
|
void _UpdateAutoCheck(bigtime_t interval);
|
||||||
|
|
||||||
BMessageRunner *auto_check;
|
BMessageRunner* fAutoCheckRunner;
|
||||||
BMailSettings settings_file;
|
BMailSettings fSettingsFile;
|
||||||
|
|
||||||
int32 new_messages;
|
int32 fNewMessages;
|
||||||
bool central_beep;
|
bool fCentralBeep;
|
||||||
// TRUE to do a beep when the status window closes. This happens
|
// TRUE to do a beep when the status window closes. This happens
|
||||||
// when all mail has been received, so you get one beep for
|
// when all mail has been received, so you get one beep for
|
||||||
// everything rather than individual beeps for each mail account.
|
// everything rather than individual beeps for each mail
|
||||||
// Set to TRUE by the 'mcbp' message that the mail Notification
|
// account.
|
||||||
// filter sends us, cleared when the beep is done.
|
// Set to TRUE by the 'mcbp' message that the mail Notification
|
||||||
BList fetch_done_respondents;
|
// filter sends us, cleared when the beep is done.
|
||||||
|
BList fFetchDoneRespondents;
|
||||||
|
BList fQueries;
|
||||||
|
|
||||||
BList queries;
|
LEDAnimation* fLEDAnimation;
|
||||||
LEDAnimation *led;
|
|
||||||
|
|
||||||
BString alert_string;
|
BString fAlertString;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
MailDaemonApp::MailDaemonApp(void)
|
MailDaemonApp::MailDaemonApp()
|
||||||
: BApplication("application/x-vnd.Be-POST")
|
:
|
||||||
|
BApplication("application/x-vnd.Be-POST")
|
||||||
{
|
{
|
||||||
status = new BMailStatusWindow(BRect(40, 400, 360, 400), "Mail Status",
|
sStatus = new BMailStatusWindow(BRect(40, 400, 360, 400), "Mail Status",
|
||||||
settings_file.ShowStatusWindow());
|
fSettingsFile.ShowStatusWindow());
|
||||||
auto_check = NULL;
|
fAutoCheckRunner = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
MailDaemonApp::~MailDaemonApp()
|
MailDaemonApp::~MailDaemonApp()
|
||||||
{
|
{
|
||||||
delete auto_check;
|
delete fAutoCheckRunner;
|
||||||
|
|
||||||
for (int32 i = 0; i < queries.CountItems(); i++)
|
for (int32 i = 0; i < fQueries.CountItems(); i++)
|
||||||
delete ((BQuery *)(queries.ItemAt(i)));
|
delete (BQuery*)fQueries.ItemAt(i);
|
||||||
|
|
||||||
delete led;
|
delete fLEDAnimation;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -127,17 +125,17 @@ MailDaemonApp::ReadyToRun()
|
|||||||
{
|
{
|
||||||
InstallDeskbarIcon();
|
InstallDeskbarIcon();
|
||||||
|
|
||||||
UpdateAutoCheck(settings_file.AutoCheckInterval());
|
_UpdateAutoCheck(fSettingsFile.AutoCheckInterval());
|
||||||
|
|
||||||
BVolume volume;
|
BVolume volume;
|
||||||
BVolumeRoster roster;
|
BVolumeRoster roster;
|
||||||
|
|
||||||
new_messages = 0;
|
fNewMessages = 0;
|
||||||
|
|
||||||
while (roster.GetNextVolume(&volume) == B_OK) {
|
while (roster.GetNextVolume(&volume) == B_OK) {
|
||||||
//{char name[255];volume.GetName(name);printf("Volume: %s\n",name);}
|
//{char name[255];volume.GetName(name);printf("Volume: %s\n",name);}
|
||||||
|
|
||||||
BQuery *query = new BQuery;
|
BQuery* query = new BQuery;
|
||||||
|
|
||||||
query->SetTarget(this);
|
query->SetTarget(this);
|
||||||
query->SetVolume(&volume);
|
query->SetVolume(&volume);
|
||||||
@@ -155,38 +153,39 @@ MailDaemonApp::ReadyToRun()
|
|||||||
query->Fetch();
|
query->Fetch();
|
||||||
|
|
||||||
BEntry entry;
|
BEntry entry;
|
||||||
for (; query->GetNextEntry(&entry) == B_OK; new_messages++);
|
while (query->GetNextEntry(&entry) == B_OK)
|
||||||
|
fNewMessages++;
|
||||||
|
|
||||||
queries.AddItem(query);
|
fQueries.AddItem(query);
|
||||||
}
|
}
|
||||||
|
|
||||||
BString string;
|
BString string;
|
||||||
MDR_DIALECT_CHOICE(
|
MDR_DIALECT_CHOICE(
|
||||||
if (new_messages > 0)
|
if (fNewMessages > 0)
|
||||||
string << new_messages;
|
string << fNewMessages;
|
||||||
else
|
else
|
||||||
string << "No";
|
string << "No";
|
||||||
if (new_messages != 1)
|
if (fNewMessages != 1)
|
||||||
string << " new messages.";
|
string << " new messages.";
|
||||||
else
|
else
|
||||||
string << " new message.";,
|
string << " new message.";,
|
||||||
if (new_messages > 0)
|
if (fNewMessages > 0)
|
||||||
string << new_messages << " 通の未読メッセージがあります ";
|
string << fNewMessages << " 通の未読メッセージがあります ";
|
||||||
else
|
else
|
||||||
string << "未読メッセージはありません";
|
string << "未読メッセージはありません";
|
||||||
);
|
);
|
||||||
central_beep = false;
|
fCentralBeep = false;
|
||||||
status->SetDefaultMessage(string);
|
sStatus->SetDefaultMessage(string);
|
||||||
|
|
||||||
led = new LEDAnimation;
|
fLEDAnimation = new LEDAnimation;
|
||||||
SetPulseRate(1000000);
|
SetPulseRate(1000000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
MailDaemonApp::RefsReceived(BMessage *message)
|
MailDaemonApp::RefsReceived(BMessage* message)
|
||||||
{
|
{
|
||||||
status->Activate(true);
|
sStatus->Activate(true);
|
||||||
|
|
||||||
entry_ref ref;
|
entry_ref ref;
|
||||||
for (int32 i = 0; message->FindRef("refs", i, &ref) == B_OK; i++) {
|
for (int32 i = 0; message->FindRef("refs", i, &ref) == B_OK; i++) {
|
||||||
@@ -203,185 +202,186 @@ MailDaemonApp::RefsReceived(BMessage *message)
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
int32 size;
|
int32 size;
|
||||||
if (node.ReadAttr("MAIL:fullsize", B_SIZE_T_TYPE, 0, &size, sizeof(size)) < 0)
|
if (node.ReadAttr("MAIL:fullsize", B_SIZE_T_TYPE, 0, &size,
|
||||||
|
sizeof(size)) < 0) {
|
||||||
size = -1;
|
size = -1;
|
||||||
|
}
|
||||||
|
|
||||||
BPath path(&ref);
|
BPath path(&ref);
|
||||||
BMailChainRunner *runner = GetMailChainRunner(id, status);
|
BMailChainRunner* runner = GetMailChainRunner(id, sStatus);
|
||||||
runner->GetSingleMessage(uid.String(), size, &path);
|
if (runner != NULL)
|
||||||
|
runner->GetSingleMessage(uid.String(), size, &path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
MailDaemonApp::UpdateAutoCheck(bigtime_t interval)
|
MailDaemonApp::_UpdateAutoCheck(bigtime_t interval)
|
||||||
{
|
{
|
||||||
if (interval > 0) {
|
if (interval > 0) {
|
||||||
if (auto_check != NULL) {
|
if (fAutoCheckRunner != NULL) {
|
||||||
auto_check->SetInterval(interval);
|
fAutoCheckRunner->SetInterval(interval);
|
||||||
auto_check->SetCount(-1);
|
fAutoCheckRunner->SetCount(-1);
|
||||||
} else
|
} else
|
||||||
auto_check = new BMessageRunner(be_app_messenger,new BMessage('moto'),interval);
|
fAutoCheckRunner = new BMessageRunner(be_app_messenger,
|
||||||
|
new BMessage('moto'), interval);
|
||||||
} else {
|
} else {
|
||||||
delete auto_check;
|
delete fAutoCheckRunner;
|
||||||
auto_check = NULL;
|
fAutoCheckRunner = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
MailDaemonApp::MessageReceived(BMessage *msg)
|
MailDaemonApp::MessageReceived(BMessage* msg)
|
||||||
{
|
{
|
||||||
switch (msg->what) {
|
switch (msg->what) {
|
||||||
case 'moto':
|
case 'moto':
|
||||||
if (settings_file.CheckOnlyIfPPPUp()) {
|
if (fSettingsFile.CheckOnlyIfPPPUp()) {
|
||||||
#ifndef HAIKU_TARGET_PLATFORM_BEOS
|
// TODO: check whether internet is up and running!
|
||||||
int s = socket(AF_INET, SOCK_DGRAM, 0);
|
|
||||||
bsppp_status_t status;
|
|
||||||
|
|
||||||
strcpy(status.if_name, "ppp0");
|
|
||||||
if (ioctl(s, BONE_SERIAL_PPP_GET_STATUS, &status, sizeof(status)) != 0) {
|
|
||||||
close(s);
|
|
||||||
break;
|
|
||||||
} else {
|
|
||||||
if (status.connection_status != BSPPP_CONNECTED) {
|
|
||||||
close(s);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
close (s);
|
|
||||||
#else
|
|
||||||
if (find_thread("tty_thread") <= 0)
|
|
||||||
break;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
// supposed to fall through
|
// supposed to fall through
|
||||||
case 'mbth': // check & send messages
|
case 'mbth': // check & send messages
|
||||||
msg->what = 'msnd';
|
msg->what = 'msnd';
|
||||||
PostMessage(msg); //'msnd');
|
PostMessage(msg);
|
||||||
// supposed to fall trough
|
// supposed to fall trough
|
||||||
case 'mnow': // check messages
|
case 'mnow': // check messages
|
||||||
GetNewMessages(msg);
|
GetNewMessages(msg);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'msnd': // send messages
|
case 'msnd': // send messages
|
||||||
SendPendingMessages(msg);
|
SendPendingMessages(msg);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'mrrs':
|
case 'mrrs':
|
||||||
settings_file.Reload();
|
fSettingsFile.Reload();
|
||||||
UpdateAutoCheck(settings_file.AutoCheckInterval());
|
_UpdateAutoCheck(fSettingsFile.AutoCheckInterval());
|
||||||
status->SetShowCriterion(settings_file.ShowStatusWindow());
|
sStatus->SetShowCriterion(fSettingsFile.ShowStatusWindow());
|
||||||
break;
|
break;
|
||||||
case 'shst': // when to show the status window
|
case 'shst': // when to show the status window
|
||||||
{
|
{
|
||||||
int32 mode;
|
int32 mode;
|
||||||
if (msg->FindInt32("ShowStatusWindow",&mode) == B_OK)
|
if (msg->FindInt32("ShowStatusWindow", &mode) == B_OK)
|
||||||
status->SetShowCriterion(mode);
|
sStatus->SetShowCriterion(mode);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case 'lkch': // status window look changed
|
case 'lkch': // status window look changed
|
||||||
case 'wsch': // workspace changed
|
case 'wsch': // workspace changed
|
||||||
status->PostMessage(msg);
|
sStatus->PostMessage(msg);
|
||||||
break;
|
break;
|
||||||
case 'stwg': //----StaT Window Gone
|
|
||||||
{
|
|
||||||
BMessage *msg, reply('mnuc');
|
|
||||||
reply.AddInt32("num_new_messages",new_messages);
|
|
||||||
|
|
||||||
while((msg = (BMessage *)fetch_done_respondents.RemoveItem(0L))) {
|
case 'stwg': // Status window gone
|
||||||
|
{
|
||||||
|
BMessage reply('mnuc');
|
||||||
|
reply.AddInt32("num_new_messages", fNewMessages);
|
||||||
|
|
||||||
|
while ((msg = (BMessage*)fFetchDoneRespondents.RemoveItem(0L))) {
|
||||||
msg->SendReply(&reply);
|
msg->SendReply(&reply);
|
||||||
delete msg;
|
delete msg;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (alert_string != B_EMPTY_STRING) {
|
if (fAlertString != B_EMPTY_STRING) {
|
||||||
alert_string.Truncate(alert_string.Length()-1);
|
fAlertString.Truncate(fAlertString.Length() - 1);
|
||||||
BAlert *alert = new BAlert(MDR_DIALECT_CHOICE ("New Messages","新着メッセージ"), alert_string.String(), "OK", NULL, NULL, B_WIDTH_AS_USUAL);
|
BAlert* alert = new BAlert(MDR_DIALECT_CHOICE("New Messages",
|
||||||
|
"新着メッセージ"), fAlertString.String(), "OK", NULL, NULL,
|
||||||
|
B_WIDTH_AS_USUAL);
|
||||||
alert->SetFeel(B_NORMAL_WINDOW_FEEL);
|
alert->SetFeel(B_NORMAL_WINDOW_FEEL);
|
||||||
alert->Go(NULL);
|
alert->Go(NULL);
|
||||||
alert_string = B_EMPTY_STRING;
|
fAlertString = B_EMPTY_STRING;
|
||||||
}
|
}
|
||||||
if (central_beep) {
|
|
||||||
|
if (fCentralBeep) {
|
||||||
system_beep("New E-mail");
|
system_beep("New E-mail");
|
||||||
central_beep = false;
|
fCentralBeep = false;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case 'mcbp':
|
case 'mcbp':
|
||||||
if (new_messages > 0) {
|
if (fNewMessages > 0)
|
||||||
central_beep = true;
|
fCentralBeep = true;
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case 'mnum': //----Number of new messages
|
|
||||||
{
|
case 'mnum': // Number of new messages
|
||||||
BMessage reply('mnuc' /* Mail NU message Count */);
|
{
|
||||||
|
BMessage reply('mnuc'); // Mail New message Count
|
||||||
if (msg->FindBool("wait_for_fetch_done")) {
|
if (msg->FindBool("wait_for_fetch_done")) {
|
||||||
fetch_done_respondents.AddItem(DetachCurrentMessage());
|
fFetchDoneRespondents.AddItem(DetachCurrentMessage());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
reply.AddInt32("num_new_messages",new_messages);
|
reply.AddInt32("num_new_messages", fNewMessages);
|
||||||
msg->SendReply(&reply);
|
msg->SendReply(&reply);
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case 'mblk': //-----Mail BLinK
|
}
|
||||||
if (new_messages > 0)
|
|
||||||
led->Start();
|
case 'mblk': // Mail Blink
|
||||||
|
if (fNewMessages > 0)
|
||||||
|
fLEDAnimation->Start();
|
||||||
break;
|
break;
|
||||||
case 'enda': //-----End Auto Check
|
|
||||||
delete auto_check;
|
case 'enda': // End Auto Check
|
||||||
auto_check = NULL;
|
delete fAutoCheckRunner;
|
||||||
|
fAutoCheckRunner = NULL;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'numg':
|
case 'numg':
|
||||||
{
|
{
|
||||||
int32 num_messages = msg->FindInt32("num_messages");
|
int32 numMessages = msg->FindInt32("num_messages");
|
||||||
MDR_DIALECT_CHOICE (
|
MDR_DIALECT_CHOICE(
|
||||||
alert_string << num_messages << " new message";
|
fAlertString << numMessages << " new message";
|
||||||
if (num_messages > 1)
|
if (numMessages > 1)
|
||||||
alert_string << 's';
|
fAlertString << 's';
|
||||||
|
|
||||||
alert_string << " for " << msg->FindString("chain_name") << '\n';,
|
fAlertString << " for " << msg->FindString("chain_name")
|
||||||
|
<< '\n';,
|
||||||
|
|
||||||
alert_string << msg->FindString("chain_name") << "より\n" << num_messages
|
fAlertString << msg->FindString("chain_name") << "より\n"
|
||||||
<< " 通のメッセージが届きました ";
|
<< numMessages << " 通のメッセージが届きました ";
|
||||||
);
|
);
|
||||||
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case B_QUERY_UPDATE:
|
case B_QUERY_UPDATE:
|
||||||
{
|
{
|
||||||
int32 what;
|
int32 what;
|
||||||
msg->FindInt32("opcode",&what);
|
msg->FindInt32("opcode", &what);
|
||||||
switch (what) {
|
switch (what) {
|
||||||
case B_ENTRY_CREATED:
|
case B_ENTRY_CREATED:
|
||||||
new_messages++;
|
fNewMessages++;
|
||||||
break;
|
break;
|
||||||
case B_ENTRY_REMOVED:
|
case B_ENTRY_REMOVED:
|
||||||
new_messages--;
|
fNewMessages--;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
BString string;
|
BString string;
|
||||||
|
|
||||||
MDR_DIALECT_CHOICE (
|
MDR_DIALECT_CHOICE(
|
||||||
if (new_messages > 0)
|
if (fNewMessages > 0)
|
||||||
string << new_messages;
|
string << fNewMessages;
|
||||||
else
|
else
|
||||||
string << "No";
|
string << "No";
|
||||||
if (new_messages != 1)
|
if (fNewMessages != 1)
|
||||||
string << " new messages.";
|
string << " new messages.";
|
||||||
else
|
else
|
||||||
string << " new message.";,
|
string << " new message.";,
|
||||||
if (new_messages > 0)
|
|
||||||
string << new_messages << " 通の未読メッセージがあります";
|
if (fNewMessages > 0)
|
||||||
|
string << fNewMessages << " 通の未読メッセージがあります";
|
||||||
else
|
else
|
||||||
string << "未読メッセージはありません";
|
string << "未読メッセージはありません";
|
||||||
);
|
);
|
||||||
|
|
||||||
status->SetDefaultMessage(string.String());
|
sStatus->SetDefaultMessage(string.String());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
default:
|
||||||
|
BApplication::MessageReceived(msg);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
BApplication::MessageReceived(msg);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -396,7 +396,8 @@ MailDaemonApp::InstallDeskbarIcon()
|
|||||||
|
|
||||||
status_t status = roster.FindApp("application/x-vnd.Be-POST", &ref);
|
status_t status = roster.FindApp("application/x-vnd.Be-POST", &ref);
|
||||||
if (status < B_OK) {
|
if (status < B_OK) {
|
||||||
fprintf(stderr, "Can't find application to tell deskbar: %s\n", strerror(status));
|
fprintf(stderr, "Can't find application to tell deskbar: %s\n",
|
||||||
|
strerror(status));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -428,17 +429,17 @@ MailDaemonApp::QuitRequested()
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
MailDaemonApp::RunChains(BList &list, BMessage *msg)
|
MailDaemonApp::RunChains(BList& list, BMessage* msg)
|
||||||
{
|
{
|
||||||
BMailChain *chain;
|
BMailChain* chain;
|
||||||
|
|
||||||
int32 index = 0, id;
|
int32 index = 0, id;
|
||||||
for (; msg->FindInt32("chain", index, &id) == B_OK; index++) {
|
for (; msg->FindInt32("chain", index, &id) == B_OK; index++) {
|
||||||
for (int32 i = 0; i < list.CountItems(); i++) {
|
for (int32 i = 0; i < list.CountItems(); i++) {
|
||||||
chain = (BMailChain *)list.ItemAt(i);
|
chain = (BMailChain*)list.ItemAt(i);
|
||||||
|
|
||||||
if (chain->ID() == (unsigned)id) {
|
if (chain->ID() == (unsigned)id) {
|
||||||
chain->RunChain(status, true, false, true);
|
chain->RunChain(sStatus, true, false, true);
|
||||||
list.RemoveItem(i); // the chain runner deletes the chain
|
list.RemoveItem(i); // the chain runner deletes the chain
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -448,20 +449,20 @@ MailDaemonApp::RunChains(BList &list, BMessage *msg)
|
|||||||
if (index == 0) {
|
if (index == 0) {
|
||||||
// invoke all chains
|
// invoke all chains
|
||||||
for (int32 i = 0; i < list.CountItems(); i++) {
|
for (int32 i = 0; i < list.CountItems(); i++) {
|
||||||
chain = (BMailChain *)list.ItemAt(i);
|
chain = (BMailChain*)list.ItemAt(i);
|
||||||
|
|
||||||
chain->RunChain(status, true, false, true);
|
chain->RunChain(sStatus, true, false, true);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// delete unused chains
|
// delete unused chains
|
||||||
for (int32 i = list.CountItems(); i-- > 0;)
|
for (int32 i = list.CountItems(); i-- > 0;)
|
||||||
delete (BMailChain *)list.RemoveItem(i);
|
delete (BMailChain*)list.RemoveItem(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
MailDaemonApp::GetNewMessages(BMessage *msg)
|
MailDaemonApp::GetNewMessages(BMessage* msg)
|
||||||
{
|
{
|
||||||
BList list;
|
BList list;
|
||||||
GetInboundMailChains(&list);
|
GetInboundMailChains(&list);
|
||||||
@@ -471,7 +472,7 @@ MailDaemonApp::GetNewMessages(BMessage *msg)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
MailDaemonApp::SendPendingMessages(BMessage *msg)
|
MailDaemonApp::SendPendingMessages(BMessage* msg)
|
||||||
{
|
{
|
||||||
BVolumeRoster roster;
|
BVolumeRoster roster;
|
||||||
BVolume volume;
|
BVolume volume;
|
||||||
@@ -489,32 +490,32 @@ MailDaemonApp::SendPendingMessages(BMessage *msg)
|
|||||||
|
|
||||||
query.PushOp(B_OR);
|
query.PushOp(B_OR);
|
||||||
|
|
||||||
int32 chain_id = -1;
|
int32 chainID = -1;
|
||||||
|
|
||||||
if (msg->FindInt32("chain",&chain_id) == B_OK) {
|
if (msg->FindInt32("chain", &chainID) == B_OK) {
|
||||||
query.PushAttr("MAIL:chain");
|
query.PushAttr("MAIL:chain");
|
||||||
query.PushInt32(chain_id);
|
query.PushInt32(chainID);
|
||||||
query.PushOp(B_EQ);
|
query.PushOp(B_EQ);
|
||||||
query.PushOp(B_AND);
|
query.PushOp(B_AND);
|
||||||
} else {
|
} else
|
||||||
chain_id = -1;
|
chainID = -1;
|
||||||
}
|
|
||||||
|
|
||||||
if (!msg->HasString("message_path")) {
|
if (!msg->HasString("message_path")) {
|
||||||
if (chain_id == -1) {
|
if (chainID == -1) {
|
||||||
map <int32, snuzzwut *> messages;
|
map<int32, snuzzwut*> messages;
|
||||||
|
|
||||||
query.Fetch();
|
query.Fetch();
|
||||||
BEntry entry;
|
BEntry entry;
|
||||||
BPath path;
|
BPath path;
|
||||||
BNode node;
|
BNode node;
|
||||||
int32 chain, default_chain(BMailSettings().DefaultOutboundChainID());
|
int32 chain;
|
||||||
|
int32 defaultChain(BMailSettings().DefaultOutboundChainID());
|
||||||
off_t size;
|
off_t size;
|
||||||
|
|
||||||
while (query.GetNextEntry(&entry) == B_OK) {
|
while (query.GetNextEntry(&entry) == B_OK) {
|
||||||
while (node.SetTo(&entry) == B_BUSY) snooze(100);
|
while (node.SetTo(&entry) == B_BUSY) snooze(100);
|
||||||
if (node.ReadAttr("MAIL:chain",B_INT32_TYPE,0,&chain,4) < B_OK)
|
if (node.ReadAttr("MAIL:chain",B_INT32_TYPE,0,&chain,4) < B_OK)
|
||||||
chain = default_chain;
|
chain = defaultChain;
|
||||||
entry.GetPath(&path);
|
entry.GetPath(&path);
|
||||||
node.GetSize(&size);
|
node.GetSize(&size);
|
||||||
if (messages[chain] == NULL) {
|
if (messages[chain] == NULL) {
|
||||||
@@ -526,12 +527,15 @@ MailDaemonApp::SendPendingMessages(BMessage *msg)
|
|||||||
messages[chain]->bytes += size;
|
messages[chain]->bytes += size;
|
||||||
}
|
}
|
||||||
|
|
||||||
map<int32,snuzzwut *>::iterator iter = messages.begin();
|
map<int32, snuzzwut*>::iterator iter = messages.begin();
|
||||||
map<int32,snuzzwut *>::iterator end = messages.end();
|
map<int32, snuzzwut*>::iterator end = messages.end();
|
||||||
while (iter != end) {
|
while (iter != end) {
|
||||||
if ((iter->first > 0) && (BMailChain(iter->first).ChainDirection() == outbound)) {
|
if (iter->first > 0 && BMailChain(iter->first)
|
||||||
BMailChainRunner *runner = GetMailChainRunner(iter->first,status);
|
.ChainDirection() == outbound) {
|
||||||
runner->GetMessages(&messages[iter->first]->msgs,messages[iter->first]->bytes);
|
BMailChainRunner* runner
|
||||||
|
= GetMailChainRunner(iter->first, sStatus);
|
||||||
|
runner->GetMessages(&messages[iter->first]->msgs,
|
||||||
|
messages[iter->first]->bytes);
|
||||||
delete messages[iter->first];
|
delete messages[iter->first];
|
||||||
runner->Stop();
|
runner->Stop();
|
||||||
}
|
}
|
||||||
@@ -556,19 +560,25 @@ MailDaemonApp::SendPendingMessages(BMessage *msg)
|
|||||||
bytes += size;
|
bytes += size;
|
||||||
}
|
}
|
||||||
|
|
||||||
BMailChainRunner *runner = GetMailChainRunner(chain_id,status);
|
BMailChainRunner* runner
|
||||||
runner->GetMessages(&ids,bytes);
|
= GetMailChainRunner(chainID, sStatus);
|
||||||
|
runner->GetMessages(&ids, bytes);
|
||||||
runner->Stop();
|
runner->Stop();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const char *path;
|
const char* path;
|
||||||
msg->FindString("message_path",&path);
|
if (msg->FindString("message_path", &path) != B_OK)
|
||||||
|
return;
|
||||||
|
|
||||||
|
off_t size;
|
||||||
|
if (BNode(path).GetSize(&size) != B_OK)
|
||||||
|
return;
|
||||||
|
|
||||||
BStringList ids;
|
BStringList ids;
|
||||||
ids += path;
|
ids += path;
|
||||||
off_t size;
|
|
||||||
BNode(path).GetSize(&size);
|
BMailChainRunner* runner = GetMailChainRunner(chainID, sStatus);
|
||||||
BMailChainRunner *runner = GetMailChainRunner(chain_id,status);
|
runner->GetMessages(&ids, size);
|
||||||
runner->GetMessages(&ids,size);
|
|
||||||
runner->Stop();
|
runner->Stop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -579,21 +589,23 @@ void
|
|||||||
MailDaemonApp::Pulse()
|
MailDaemonApp::Pulse()
|
||||||
{
|
{
|
||||||
bigtime_t idle = idle_time();
|
bigtime_t idle = idle_time();
|
||||||
if (led->IsRunning() && (idle < 100000))
|
if (fLEDAnimation->IsRunning() && idle < 100000)
|
||||||
led->Stop();
|
fLEDAnimation->Stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark -
|
// #pragma mark -
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
makeIndices()
|
makeIndices()
|
||||||
{
|
{
|
||||||
const char *stringIndices[] = { B_MAIL_ATTR_ACCOUNT,B_MAIL_ATTR_CC,
|
const char* stringIndices[] = {
|
||||||
B_MAIL_ATTR_FROM,B_MAIL_ATTR_NAME,
|
B_MAIL_ATTR_ACCOUNT, B_MAIL_ATTR_CC, B_MAIL_ATTR_FROM, B_MAIL_ATTR_NAME,
|
||||||
B_MAIL_ATTR_PRIORITY,B_MAIL_ATTR_REPLY,
|
B_MAIL_ATTR_PRIORITY, B_MAIL_ATTR_REPLY, B_MAIL_ATTR_STATUS,
|
||||||
B_MAIL_ATTR_STATUS,B_MAIL_ATTR_SUBJECT,
|
B_MAIL_ATTR_SUBJECT, B_MAIL_ATTR_TO, B_MAIL_ATTR_THREAD,
|
||||||
B_MAIL_ATTR_TO,B_MAIL_ATTR_THREAD, NULL};
|
NULL
|
||||||
|
};
|
||||||
|
|
||||||
// add mail indices for all devices capable of querying
|
// add mail indices for all devices capable of querying
|
||||||
|
|
||||||
@@ -601,7 +613,8 @@ makeIndices()
|
|||||||
dev_t device;
|
dev_t device;
|
||||||
while ((device = next_dev(&cookie)) >= B_OK) {
|
while ((device = next_dev(&cookie)) >= B_OK) {
|
||||||
fs_info info;
|
fs_info info;
|
||||||
if (fs_stat_dev(device,&info) < 0 || (info.flags & B_FS_HAS_QUERY) == 0)
|
if (fs_stat_dev(device, &info) < 0
|
||||||
|
|| (info.flags & B_FS_HAS_QUERY) == 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Work-around for misbehaviour of earlier versions - should be
|
// Work-around for misbehaviour of earlier versions - should be
|
||||||
@@ -613,28 +626,30 @@ makeIndices()
|
|||||||
&& indexInfo.type == B_STRING_TYPE)
|
&& indexInfo.type == B_STRING_TYPE)
|
||||||
fs_remove_index(device, B_MAIL_ATTR_FLAGS);
|
fs_remove_index(device, B_MAIL_ATTR_FLAGS);
|
||||||
|
|
||||||
for (int32 i = 0;stringIndices[i];i++)
|
for (int32 i = 0; stringIndices[i]; i++)
|
||||||
fs_create_index(device,stringIndices[i],B_STRING_TYPE,0);
|
fs_create_index(device, stringIndices[i], B_STRING_TYPE, 0);
|
||||||
|
|
||||||
fs_create_index(device,"MAIL:draft", B_INT32_TYPE, 0);
|
fs_create_index(device, "MAIL:draft", B_INT32_TYPE, 0);
|
||||||
fs_create_index(device,B_MAIL_ATTR_WHEN,B_INT32_TYPE,0);
|
fs_create_index(device, B_MAIL_ATTR_WHEN, B_INT32_TYPE, 0);
|
||||||
fs_create_index(device,B_MAIL_ATTR_FLAGS,B_INT32_TYPE,0);
|
fs_create_index(device, B_MAIL_ATTR_FLAGS, B_INT32_TYPE, 0);
|
||||||
fs_create_index(device,"MAIL:chain",B_INT32_TYPE,0);
|
fs_create_index(device, "MAIL:chain", B_INT32_TYPE, 0);
|
||||||
fs_create_index(device,"MAIL:pending_chain",B_INT32_TYPE,0);
|
fs_create_index(device, "MAIL:pending_chain", B_INT32_TYPE, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
addAttribute(BMessage &msg,const char *name,const char *publicName,int32 type = B_STRING_TYPE,bool viewable = true,bool editable = false,int32 width = 200)
|
addAttribute(BMessage& msg, const char* name, const char* publicName,
|
||||||
|
int32 type = B_STRING_TYPE, bool viewable = true, bool editable = false,
|
||||||
|
int32 width = 200)
|
||||||
{
|
{
|
||||||
msg.AddString("attr:name",name);
|
msg.AddString("attr:name", name);
|
||||||
msg.AddString("attr:public_name",publicName);
|
msg.AddString("attr:public_name", publicName);
|
||||||
msg.AddInt32("attr:type",type);
|
msg.AddInt32("attr:type", type);
|
||||||
msg.AddBool("attr:viewable",viewable);
|
msg.AddBool("attr:viewable", viewable);
|
||||||
msg.AddBool("attr:editable",editable);
|
msg.AddBool("attr:editable", editable);
|
||||||
msg.AddInt32("attr:width",width);
|
msg.AddInt32("attr:width", width);
|
||||||
msg.AddInt32("attr:alignment",B_ALIGN_LEFT);
|
msg.AddInt32("attr:alignment", B_ALIGN_LEFT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -645,15 +660,15 @@ makeMimeType(bool remakeMIMETypes)
|
|||||||
// do a full rebuild from nothing, or just add on the new attributes that
|
// do a full rebuild from nothing, or just add on the new attributes that
|
||||||
// we support which the regular BeOS mail daemon didn't have.
|
// we support which the regular BeOS mail daemon didn't have.
|
||||||
|
|
||||||
const char *types[2] = {"text/x-email","text/x-partial-email"};
|
const char* types[2] = {"text/x-email", "text/x-partial-email"};
|
||||||
BMimeType mime;
|
BMimeType mime;
|
||||||
BMessage info;
|
BMessage info;
|
||||||
|
|
||||||
for (int i = 0; i < 2; i++) {
|
for (size_t i = 0; i < sizeof(types) / sizeof(types[0]); i++) {
|
||||||
info.MakeEmpty();
|
info.MakeEmpty();
|
||||||
mime.SetTo(types[i]);
|
mime.SetTo(types[i]);
|
||||||
if (mime.InitCheck() != B_OK) {
|
if (mime.InitCheck() != B_OK) {
|
||||||
fputs("could not init mime type.\n",stderr);
|
fputs("could not init mime type.\n", stderr);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -664,17 +679,20 @@ makeMimeType(bool remakeMIMETypes)
|
|||||||
|
|
||||||
// Set up the list of e-mail related attributes that Tracker will
|
// Set up the list of e-mail related attributes that Tracker will
|
||||||
// let you display in columns for e-mail messages.
|
// let you display in columns for e-mail messages.
|
||||||
addAttribute(info,B_MAIL_ATTR_NAME,"Name");
|
addAttribute(info, B_MAIL_ATTR_NAME, "Name");
|
||||||
addAttribute(info,B_MAIL_ATTR_SUBJECT,"Subject");
|
addAttribute(info, B_MAIL_ATTR_SUBJECT, "Subject");
|
||||||
addAttribute(info,B_MAIL_ATTR_TO,"To");
|
addAttribute(info, B_MAIL_ATTR_TO, "To");
|
||||||
addAttribute(info,B_MAIL_ATTR_CC,"Cc");
|
addAttribute(info, B_MAIL_ATTR_CC, "Cc");
|
||||||
addAttribute(info,B_MAIL_ATTR_FROM,"From");
|
addAttribute(info, B_MAIL_ATTR_FROM, "From");
|
||||||
addAttribute(info,B_MAIL_ATTR_REPLY,"Reply To");
|
addAttribute(info, B_MAIL_ATTR_REPLY, "Reply To");
|
||||||
addAttribute(info,B_MAIL_ATTR_STATUS,"Status");
|
addAttribute(info, B_MAIL_ATTR_STATUS, "Status");
|
||||||
addAttribute(info,B_MAIL_ATTR_PRIORITY,"Priority",B_STRING_TYPE,true,true,40);
|
addAttribute(info, B_MAIL_ATTR_PRIORITY, "Priority", B_STRING_TYPE,
|
||||||
addAttribute(info,B_MAIL_ATTR_WHEN,"When",B_TIME_TYPE,true,false,150);
|
true, true, 40);
|
||||||
addAttribute(info,B_MAIL_ATTR_THREAD,"Thread");
|
addAttribute(info, B_MAIL_ATTR_WHEN, "When", B_TIME_TYPE, true,
|
||||||
addAttribute(info,B_MAIL_ATTR_ACCOUNT,"Account",B_STRING_TYPE,true,false,100);
|
false, 150);
|
||||||
|
addAttribute(info, B_MAIL_ATTR_THREAD, "Thread");
|
||||||
|
addAttribute(info, B_MAIL_ATTR_ACCOUNT, "Account", B_STRING_TYPE,
|
||||||
|
true, false, 100);
|
||||||
mime.SetAttrInfo(&info);
|
mime.SetAttrInfo(&info);
|
||||||
|
|
||||||
if (i == 0) {
|
if (i == 0) {
|
||||||
@@ -687,26 +705,32 @@ makeMimeType(bool remakeMIMETypes)
|
|||||||
mime.SetPreferredApp("application/x-vnd.Be-POST");
|
mime.SetPreferredApp("application/x-vnd.Be-POST");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Just add the e-mail related attribute types we use to the MIME system.
|
// Just add the e-mail related attribute types we use to the MIME
|
||||||
|
// system.
|
||||||
mime.GetAttrInfo(&info);
|
mime.GetAttrInfo(&info);
|
||||||
bool hasAccount = false, hasThread = false, hasSize = false;
|
bool hasAccount = false;
|
||||||
const char *result;
|
bool hasThread = false;
|
||||||
for (int32 index = 0;info.FindString("attr:name",index,&result) == B_OK;index++) {
|
bool hasSize = false;
|
||||||
if (!strcmp(result,B_MAIL_ATTR_ACCOUNT))
|
const char* result;
|
||||||
|
for (int32 index = 0; info.FindString("attr:name", index, &result)
|
||||||
|
== B_OK; index++) {
|
||||||
|
if (!strcmp(result, B_MAIL_ATTR_ACCOUNT))
|
||||||
hasAccount = true;
|
hasAccount = true;
|
||||||
if (!strcmp(result,B_MAIL_ATTR_THREAD))
|
if (!strcmp(result, B_MAIL_ATTR_THREAD))
|
||||||
hasThread = true;
|
hasThread = true;
|
||||||
if (!strcmp(result,"MAIL:fullsize"))
|
if (!strcmp(result, "MAIL:fullsize"))
|
||||||
hasSize = true;
|
hasSize = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!hasAccount)
|
if (!hasAccount) {
|
||||||
addAttribute(info,B_MAIL_ATTR_ACCOUNT,"Account",B_STRING_TYPE,true,false,100);
|
addAttribute(info, B_MAIL_ATTR_ACCOUNT, "Account",
|
||||||
|
B_STRING_TYPE, true, false, 100);
|
||||||
|
}
|
||||||
if (!hasThread)
|
if (!hasThread)
|
||||||
addAttribute(info,B_MAIL_ATTR_THREAD,"Thread");
|
addAttribute(info, B_MAIL_ATTR_THREAD, "Thread");
|
||||||
/*if (!hasSize)
|
/*if (!hasSize)
|
||||||
addAttribute(info,"MAIL:fullsize","Message Size",B_SIZE_T_TYPE,true,false,100);*/
|
addAttribute(info,"MAIL:fullsize","Message Size",B_SIZE_T_TYPE,true,false,100);*/
|
||||||
//--- Tracker can't display SIZT attributes. What a pain.
|
// TODO: Tracker can't display SIZT attributes. What a pain.
|
||||||
if (!hasAccount || !hasThread/* || !hasSize*/)
|
if (!hasAccount || !hasThread/* || !hasSize*/)
|
||||||
mime.SetAttrInfo(&info);
|
mime.SetAttrInfo(&info);
|
||||||
}
|
}
|
||||||
@@ -716,7 +740,7 @@ makeMimeType(bool remakeMIMETypes)
|
|||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, const char **argv)
|
main(int argc, const char** argv)
|
||||||
{
|
{
|
||||||
bool remakeMIMETypes = false;
|
bool remakeMIMETypes = false;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user