xref: /haiku/src/kits/mail/c_mail_api.cpp (revision bc3955fea5b07e2e94a27fc05e4bb58fe6f0319b)
1 /* C-mail API - compatibility function (stubs) for the old mail kit
2 **
3 ** Copyright 2001 Dr. Zoidberg Enterprises. All rights reserved.
4 */
5 
6 
7 #include <E-mail.h>
8 #include <FindDirectory.h>
9 #include <Path.h>
10 #include <File.h>
11 #include <Directory.h>
12 #include <List.h>
13 
14 #include <string.h>
15 
16 #include <MailDaemon.h>
17 #include <MailSettings.h>
18 #include <MailMessage.h>
19 #include <crypt.h>
20 
21 
22 _EXPORT status_t check_for_mail(int32 * incoming_count)
23 {
24 	status_t err = BMailDaemon::CheckMail(true);
25 	if (err < B_OK)
26 		return err;
27 
28 	if (incoming_count != NULL)
29 		*incoming_count = BMailDaemon::CountNewMessages(true);
30 
31 	return B_OK;
32 }
33 
34 _EXPORT status_t send_queued_mail(void)
35 {
36 	return BMailDaemon::SendQueuedMail();
37 }
38 
39 _EXPORT int32 count_pop_accounts(void)
40 {
41 	BPath path;
42 	status_t status = find_directory(B_USER_SETTINGS_DIRECTORY,&path);
43 	if (status < B_OK)
44 		return 0;
45 
46 	path.Append("Mail/chains/inbound");
47 	BDirectory dir(path.Path());
48 	return dir.CountEntries();
49 }
50 
51 _EXPORT status_t get_mail_notification(mail_notification *notification)
52 {
53 	notification->alert = true;
54 	notification->beep = false;
55 	return B_OK;
56 }
57 
58 _EXPORT status_t set_mail_notification(mail_notification *, bool)
59 {
60 	return B_NO_REPLY;
61 }
62 
63 _EXPORT status_t get_pop_account(mail_pop_account* account, int32 index)
64 {
65 	status_t err = B_OK;
66 	const char *password, *passwd;
67 	BMessage settings;
68 
69 	BList chains;
70 	GetInboundMailChains(&chains);
71 
72 	BMailChain *chain = (BMailChain *)(chains.ItemAt(index));
73 	if (chain == NULL) {
74 		err = B_BAD_INDEX;
75 		goto clean_up; //------Eek! A goto!
76 	}
77 
78 	chain->GetFilter(0,&settings);
79 	strcpy(account->pop_name,settings.FindString("username"));
80 	strcpy(account->pop_host,settings.FindString("server"));
81 	strcpy(account->real_name,chain->MetaData()->FindString("real_name"));
82 	strcpy(account->reply_to,chain->MetaData()->FindString("reply_to"));
83 
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 	//-------Note that we don't do the scheduling flags
91 
92   clean_up:
93 	for (int32 i = 0; i < chains.CountItems(); i++)
94 		delete (BMailChain *)chains.ItemAt(i);
95 
96 	return err;
97 }
98 
99 _EXPORT status_t set_pop_account(mail_pop_account *, int32, bool)
100 {
101 	return B_NO_REPLY;
102 }
103 
104 _EXPORT status_t get_smtp_host(char* buffer)
105 {
106 	BMailChain chain(BMailSettings().DefaultOutboundChainID());
107 	status_t err = chain.InitCheck();
108 	if (err < B_OK)
109 		return err;
110 
111 	BMessage settings;
112 	err = chain.GetFilter(chain.CountFilters() - 1,&settings);
113 	if (err < B_OK)
114 		return err;
115 
116 	if (settings.HasString("server"))
117 		strcpy(buffer,settings.FindString("server"));
118 	else
119 		return B_NAME_NOT_FOUND;
120 
121 	return B_OK;
122 }
123 
124 _EXPORT status_t set_smtp_host(char * /* host */, bool /* save */)
125 {
126 	return B_NO_REPLY;
127 }
128 
129 _EXPORT status_t forward_mail(entry_ref *ref, const char *recipients, bool now)
130 {
131 	BFile file(ref, O_RDONLY);
132 	status_t status = file.InitCheck();
133 	if (status < B_OK)
134 		return status;
135 
136 	BEmailMessage mail(&file);
137 	mail.SetTo(recipients);
138 
139 	return mail.Send(now);
140 }
141 
142