1 /* Daemon - talking to the mail daemon 2 ** 3 ** Copyright 2001-2002 Dr. Zoidberg Enterprises. All rights reserved. 4 */ 5 6 7 #include <Messenger.h> 8 #include <Message.h> 9 #include <List.h> 10 11 #include <MailDaemon.h> 12 #include <MailSettings.h> 13 14 #include <string.h> 15 16 17 status_t 18 BMailDaemon::CheckMail(int32 accountID) 19 { 20 BMessenger daemon("application/x-vnd.Be-POST"); 21 if (!daemon.IsValid()) 22 return B_MAIL_NO_DAEMON; 23 24 BMessage message(kMsgCheckMessage); 25 message.AddInt32("account", accountID); 26 return daemon.SendMessage(&message); 27 } 28 29 30 status_t 31 BMailDaemon::CheckAndSendQueuedMail(int32 accountID) 32 { 33 BMessenger daemon("application/x-vnd.Be-POST"); 34 if (!daemon.IsValid()) 35 return B_MAIL_NO_DAEMON; 36 37 BMessage message(kMsgCheckAndSend); 38 message.AddInt32("account", accountID); 39 return daemon.SendMessage(&message); 40 } 41 42 43 status_t 44 BMailDaemon::SendQueuedMail() 45 { 46 BMessenger daemon("application/x-vnd.Be-POST"); 47 if (!daemon.IsValid()) 48 return B_MAIL_NO_DAEMON; 49 50 return daemon.SendMessage(kMsgSendMessages); 51 } 52 53 54 int32 55 BMailDaemon::CountNewMessages(bool wait_for_fetch_completion) 56 { 57 BMessenger daemon("application/x-vnd.Be-POST"); 58 if (!daemon.IsValid()) 59 return B_MAIL_NO_DAEMON; 60 61 BMessage reply; 62 BMessage first(kMsgCountNewMessages); 63 64 if (wait_for_fetch_completion) 65 first.AddBool("wait_for_fetch_done",true); 66 67 daemon.SendMessage(&first, &reply); 68 69 return reply.FindInt32("num_new_messages"); 70 } 71 72 73 status_t 74 BMailDaemon::MarkAsRead(int32 account, const entry_ref& ref, read_flags flag) 75 { 76 BMessenger daemon("application/x-vnd.Be-POST"); 77 if (!daemon.IsValid()) 78 return B_MAIL_NO_DAEMON; 79 80 BMessage message(kMsgMarkMessageAsRead); 81 message.AddInt32("account", account); 82 message.AddRef("ref", &ref); 83 message.AddInt32("read", flag); 84 85 return daemon.SendMessage(&message); 86 } 87 88 89 status_t 90 BMailDaemon::FetchBody(const entry_ref& ref, BMessenger* listener) 91 { 92 BMessenger daemon("application/x-vnd.Be-POST"); 93 if (!daemon.IsValid()) 94 return B_MAIL_NO_DAEMON; 95 96 BMessage message(kMsgFetchBody); 97 message.AddRef("refs", &ref); 98 if (listener != NULL) 99 message.AddMessenger("target", *listener); 100 101 BMessage reply; 102 return daemon.SendMessage(&message, &reply); 103 } 104 105 106 status_t 107 BMailDaemon::Quit() 108 { 109 BMessenger daemon("application/x-vnd.Be-POST"); 110 if (!daemon.IsValid()) 111 return B_MAIL_NO_DAEMON; 112 113 return daemon.SendMessage(B_QUIT_REQUESTED); 114 } 115