2 * Copyright 2004-2012, Haiku Inc. All Rights Reserved.
3 * Copyright 2001-2002 Dr. Zoidberg Enterprises. All rights reserved.
5 * Distributed under the terms of the MIT License.
9 #include <MailDaemon.h>
12 #include <MailSettings.h>
13 #include <Messenger.h>
17 #include <MailPrivate.h>
20 using namespace BPrivate
;
23 BMailDaemon::BMailDaemon()
25 fDaemon(B_MAIL_DAEMON_SIGNATURE
)
30 BMailDaemon::~BMailDaemon()
36 BMailDaemon::IsRunning()
38 return fDaemon
.IsValid();
43 BMailDaemon::CheckMail(int32 accountID
)
45 if (!fDaemon
.IsValid())
46 return B_MAIL_NO_DAEMON
;
48 BMessage
message(kMsgCheckMessage
);
49 message
.AddInt32("account", accountID
);
50 return fDaemon
.SendMessage(&message
);
55 BMailDaemon::CheckAndSendQueuedMail(int32 accountID
)
57 if (!fDaemon
.IsValid())
58 return B_MAIL_NO_DAEMON
;
60 BMessage
message(kMsgCheckAndSend
);
61 message
.AddInt32("account", accountID
);
62 return fDaemon
.SendMessage(&message
);
67 BMailDaemon::SendQueuedMail()
69 if (!fDaemon
.IsValid())
70 return B_MAIL_NO_DAEMON
;
72 return fDaemon
.SendMessage(kMsgSendMessages
);
77 BMailDaemon::CountNewMessages(bool waitForFetchCompletion
)
79 if (!fDaemon
.IsValid())
80 return B_MAIL_NO_DAEMON
;
83 BMessage
first(kMsgCountNewMessages
);
85 if (waitForFetchCompletion
)
86 first
.AddBool("wait_for_fetch_done",true);
88 fDaemon
.SendMessage(&first
, &reply
);
90 return reply
.FindInt32("num_new_messages");
95 BMailDaemon::MarkAsRead(int32 account
, const entry_ref
& ref
, read_flags flag
)
97 if (!fDaemon
.IsValid())
98 return B_MAIL_NO_DAEMON
;
100 BMessage
message(kMsgMarkMessageAsRead
);
101 message
.AddInt32("account", account
);
102 message
.AddRef("ref", &ref
);
103 message
.AddInt32("read", flag
);
105 return fDaemon
.SendMessage(&message
);
110 BMailDaemon::FetchBody(const entry_ref
& ref
, BMessenger
* listener
)
112 if (!fDaemon
.IsValid())
113 return B_MAIL_NO_DAEMON
;
115 BMessage
message(kMsgFetchBody
);
116 message
.AddRef("refs", &ref
);
117 if (listener
!= NULL
)
118 message
.AddMessenger("target", *listener
);
121 return fDaemon
.SendMessage(&message
, &reply
);
128 if (!fDaemon
.IsValid())
129 return B_MAIL_NO_DAEMON
;
131 return fDaemon
.SendMessage(B_QUIT_REQUESTED
);
136 BMailDaemon::Launch()
138 status_t status
= be_roster
->Launch(B_MAIL_DAEMON_SIGNATURE
);
140 fDaemon
= BMessenger(B_MAIL_DAEMON_SIGNATURE
);