BPicture: Fix archive constructor.
[haiku.git] / src / kits / mail / MailDaemon.cpp
bloba1778c0ff85759985cc1490f4dd07b6f238600b7
1 /*
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.
6 */
9 #include <MailDaemon.h>
11 #include <List.h>
12 #include <MailSettings.h>
13 #include <Messenger.h>
14 #include <Message.h>
15 #include <Roster.h>
17 #include <MailPrivate.h>
20 using namespace BPrivate;
23 BMailDaemon::BMailDaemon()
25 fDaemon(B_MAIL_DAEMON_SIGNATURE)
30 BMailDaemon::~BMailDaemon()
35 bool
36 BMailDaemon::IsRunning()
38 return fDaemon.IsValid();
42 status_t
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);
54 status_t
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);
66 status_t
67 BMailDaemon::SendQueuedMail()
69 if (!fDaemon.IsValid())
70 return B_MAIL_NO_DAEMON;
72 return fDaemon.SendMessage(kMsgSendMessages);
76 int32
77 BMailDaemon::CountNewMessages(bool waitForFetchCompletion)
79 if (!fDaemon.IsValid())
80 return B_MAIL_NO_DAEMON;
82 BMessage reply;
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");
94 status_t
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);
109 status_t
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);
120 BMessage reply;
121 return fDaemon.SendMessage(&message, &reply);
125 status_t
126 BMailDaemon::Quit()
128 if (!fDaemon.IsValid())
129 return B_MAIL_NO_DAEMON;
131 return fDaemon.SendMessage(B_QUIT_REQUESTED);
135 status_t
136 BMailDaemon::Launch()
138 status_t status = be_roster->Launch(B_MAIL_DAEMON_SIGNATURE);
139 if (status == B_OK)
140 fDaemon = BMessenger(B_MAIL_DAEMON_SIGNATURE);
142 return status;