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 _EXPORT status_t 17 BMailDaemon::CheckMail(bool send_queued_mail,const char *account) 18 { 19 BMessenger daemon("application/x-vnd.Be-POST"); 20 if (!daemon.IsValid()) 21 return B_MAIL_NO_DAEMON; 22 23 BMessage message(send_queued_mail ? 'mbth' : 'mnow'); 24 if (account != NULL) { 25 BList list; 26 27 GetInboundMailChains(&list); 28 for (int32 i = list.CountItems();i-- > 0;) { 29 BMailChain *chain = (BMailChain *)list.ItemAt(i); 30 31 if (!strcmp(chain->Name(),account)) 32 message.AddInt32("chain",chain->ID()); 33 34 delete chain; 35 } 36 37 if (send_queued_mail) { 38 list.MakeEmpty(); 39 GetOutboundMailChains(&list); 40 for (int32 i = list.CountItems();i-- > 0;) { 41 BMailChain *chain = (BMailChain *)list.ItemAt(i); 42 43 if (!strcmp(chain->Name(),account)) 44 message.AddInt32("chain",chain->ID()); 45 46 delete chain; 47 } 48 } 49 } 50 daemon.SendMessage(&message); 51 52 return B_OK; 53 } 54 55 56 _EXPORT status_t BMailDaemon::SendQueuedMail() { 57 BMessenger daemon("application/x-vnd.Be-POST"); 58 if (!daemon.IsValid()) 59 return B_MAIL_NO_DAEMON; 60 61 daemon.SendMessage('msnd'); 62 63 return B_OK; 64 } 65 66 _EXPORT int32 BMailDaemon::CountNewMessages(bool wait_for_fetch_completion) { 67 BMessenger daemon("application/x-vnd.Be-POST"); 68 if (!daemon.IsValid()) 69 return B_MAIL_NO_DAEMON; 70 71 BMessage reply; 72 BMessage first('mnum'); 73 74 if (wait_for_fetch_completion) 75 first.AddBool("wait_for_fetch_done",true); 76 77 daemon.SendMessage(&first,&reply); 78 79 return reply.FindInt32("num_new_messages"); 80 } 81 82 _EXPORT status_t BMailDaemon::Quit() { 83 BMessenger daemon("application/x-vnd.Be-POST"); 84 if (!daemon.IsValid()) 85 return B_MAIL_NO_DAEMON; 86 87 daemon.SendMessage(B_QUIT_REQUESTED); 88 89 return B_OK; 90 } 91 92