BPicture: Fix archive constructor.
[haiku.git] / src / kits / mail / c_mail_api.cpp
blob59facf910fbd15654b67d675570264c9714d17d7
1 /*
2 * Copyright 2004-2012, Haiku, Inc. All rights reserved.
3 * Copyright 2001, Dr. Zoidberg Enterprises. All rights reserved.
4 * Copyright 2011, Clemens Zeidler. All rights reserved.
6 * Distributed under the terms of the MIT License.
7 */
10 //! C-mail API - compatibility function (stubs) for the old mail kit
13 #include <stdlib.h>
14 #include <string.h>
16 #include <Directory.h>
17 #include <E-mail.h>
18 #include <File.h>
19 #include <FindDirectory.h>
20 #include <List.h>
21 #include <Path.h>
23 #include <crypt.h>
24 #include <MailDaemon.h>
25 #include <MailMessage.h>
26 #include <MailSettings.h>
29 _EXPORT status_t
30 check_for_mail(int32* _incomingCount)
32 status_t status = BMailDaemon().CheckMail();
33 if (status != B_OK)
34 return status;
36 if (_incomingCount != NULL)
37 *_incomingCount = BMailDaemon().CountNewMessages(true);
39 return B_OK;
43 _EXPORT status_t
44 send_queued_mail(void)
46 return BMailDaemon().SendQueuedMail();
50 _EXPORT int32
51 count_pop_accounts(void)
53 BMailAccounts accounts;
54 return accounts.CountAccounts();
58 _EXPORT status_t
59 get_mail_notification(mail_notification *notification)
61 notification->alert = true;
62 notification->beep = false;
63 return B_OK;
67 _EXPORT status_t
68 set_mail_notification(mail_notification *, bool)
70 return B_NO_REPLY;
74 _EXPORT status_t
75 get_pop_account(mail_pop_account* account, int32 index)
77 BMailAccounts accounts;
78 BMailAccountSettings* accountSettings = accounts.AccountAt(index);
79 if (accountSettings == NULL)
80 return B_BAD_INDEX;
82 const BMessage& settings = accountSettings->InboundSettings();
83 strcpy(account->pop_name, settings.FindString("username"));
84 strcpy(account->pop_host, settings.FindString("server"));
85 strcpy(account->real_name, accountSettings->RealName());
86 strcpy(account->reply_to, accountSettings->ReturnAddress());
88 const char* encryptedPassword = get_passwd(&settings, "cpasswd");
89 const char* password = encryptedPassword;
90 if (password == NULL)
91 password = settings.FindString("password");
92 strcpy(account->pop_password, password);
94 delete[] encryptedPassword;
95 return B_OK;
99 _EXPORT status_t
100 set_pop_account(mail_pop_account *, int32, bool)
102 return B_NO_REPLY;
106 _EXPORT status_t
107 get_smtp_host(char* buffer)
109 BMailAccounts accounts;
110 BMailAccountSettings* account = accounts.AccountAt(
111 BMailSettings().DefaultOutboundAccount());
112 if (account == NULL)
113 return B_ERROR;
115 const BMessage& settings = account->OutboundSettings();
117 if (!settings.HasString("server"))
118 return B_NAME_NOT_FOUND;
120 strcpy(buffer, settings.FindString("server"));
121 return B_OK;
125 _EXPORT status_t
126 set_smtp_host(char * /* host */, bool /* save */)
128 return B_NO_REPLY;
132 _EXPORT status_t
133 forward_mail(entry_ref *ref, const char *recipients, bool now)
135 BFile file(ref, O_RDONLY);
136 status_t status = file.InitCheck();
137 if (status < B_OK)
138 return status;
140 BEmailMessage mail(&file);
141 mail.SetTo(recipients);
143 return mail.Send(now);