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