xref: /haiku/src/kits/mail/c_mail_api.cpp (revision 820dca4df6c7bf955c46e8f6521b9408f50b2900)
1 /* C-mail API - compatibility function (stubs) for the old mail kit
2 **
3 ** Copyright 2001 Dr. Zoidberg Enterprises. All rights reserved.
4 ** Copyright 2011 Clemens Zeidler. All rights reserved.
5 */
6 
7 
8 #include <stdlib.h>
9 #include <string.h>
10 
11 #include <Directory.h>
12 #include <E-mail.h>
13 #include <File.h>
14 #include <FindDirectory.h>
15 #include <List.h>
16 #include <Path.h>
17 
18 #include <crypt.h>
19 #include <MailDaemon.h>
20 #include <MailMessage.h>
21 #include <MailSettings.h>
22 
23 
24 _EXPORT status_t
25 check_for_mail(int32 * incoming_count)
26 {
27 	status_t err = BMailDaemon::CheckMail(true);
28 	if (err < B_OK)
29 		return err;
30 
31 	if (incoming_count != NULL)
32 		*incoming_count = BMailDaemon::CountNewMessages(true);
33 
34 	return B_OK;
35 }
36 
37 
38 _EXPORT status_t
39 send_queued_mail(void)
40 {
41 	return BMailDaemon::SendQueuedMail();
42 }
43 
44 
45 _EXPORT int32
46 count_pop_accounts(void)
47 {
48 	BMailAccounts accounts;
49 	return accounts.CountAccounts();
50 }
51 
52 
53 _EXPORT status_t
54 get_mail_notification(mail_notification *notification)
55 {
56 	notification->alert = true;
57 	notification->beep = false;
58 	return B_OK;
59 }
60 
61 
62 _EXPORT status_t
63 set_mail_notification(mail_notification *, bool)
64 {
65 	return B_NO_REPLY;
66 }
67 
68 
69 _EXPORT status_t
70 get_pop_account(mail_pop_account* account, int32 index)
71 {
72 	BMailAccounts accounts;
73 	BMailAccountSettings* accountSettings = accounts.AccountAt(index);
74 	if (accountSettings == NULL)
75 		return B_BAD_INDEX;
76 
77 	const BMessage& settings = accountSettings->InboundSettings().Settings();
78 	strcpy(account->pop_name, settings.FindString("username"));
79 	strcpy(account->pop_host, settings.FindString("server"));
80 	strcpy(account->real_name, accountSettings->RealName());
81 	strcpy(account->reply_to, accountSettings->ReturnAddress());
82 
83 	const char *password, *passwd;
84 	password = settings.FindString("password");
85 	passwd = get_passwd(&settings, "cpasswd");
86 	if (passwd)
87 		password = passwd;
88 	strcpy(account->pop_password, password);
89 
90 	free((char *)passwd);
91 	return B_OK;
92 }
93 
94 
95 _EXPORT status_t
96 set_pop_account(mail_pop_account *, int32, bool)
97 {
98 	return B_NO_REPLY;
99 }
100 
101 
102 _EXPORT status_t
103 get_smtp_host(char* buffer)
104 {
105 	BMailAccounts accounts;
106 	BMailAccountSettings* account = accounts.AccountAt(
107 		BMailSettings().DefaultOutboundAccount());
108 	if (account == NULL)
109 		return B_ERROR;
110 
111 	const BMessage& settings = account->OutboundSettings().Settings();
112 
113 	if (settings.HasString("server"))
114 		strcpy(buffer,settings.FindString("server"));
115 	else
116 		return B_NAME_NOT_FOUND;
117 
118 	return B_OK;
119 }
120 
121 
122 _EXPORT status_t
123 set_smtp_host(char * /* host */, bool /* save */)
124 {
125 	return B_NO_REPLY;
126 }
127 
128 
129 _EXPORT status_t
130 forward_mail(entry_ref *ref, const char *recipients, bool now)
131 {
132 	BFile file(ref, O_RDONLY);
133 	status_t status = file.InitCheck();
134 	if (status < B_OK)
135 		return status;
136 
137 	BEmailMessage mail(&file);
138 	mail.SetTo(recipients);
139 
140 	return mail.Send(now);
141 }
142