|
3 | 3 | // This file is part of Gromox. |
4 | 4 | #include <algorithm> |
5 | 5 | #include <fstream> |
| 6 | +#include <unordered_set> |
6 | 7 | #include <variant> |
7 | 8 | #include <sys/stat.h> |
8 | 9 | #include <sys/wait.h> |
|
11 | 12 | #include <gromox/clock.hpp> |
12 | 13 | #include <gromox/config_file.hpp> |
13 | 14 | #include <gromox/eid_array.hpp> |
| 15 | +#include <gromox/fileio.h> |
14 | 16 | #include <gromox/mysql_adaptor.hpp> |
15 | 17 | #include <gromox/rop_util.hpp> |
16 | 18 | #include <gromox/util.hpp> |
@@ -188,6 +190,64 @@ void process(mConvertIdRequest&& request, XMLElement* response, EWSContext& ctx) |
188 | 190 | data.serialize(response); |
189 | 191 | } |
190 | 192 |
|
| 193 | +/** |
| 194 | + * @brief Process GetDelegate |
| 195 | + * |
| 196 | + * Reads the delegate configuration of a mailbox and returns the delegates |
| 197 | + * stored in the delegates.txt file. Only basic information (primary SMTP |
| 198 | + * address) is returned for each delegate. |
| 199 | + * |
| 200 | + * @param request Request data |
| 201 | + * @param response XMLElement to store response in |
| 202 | + * @param ctx Request context |
| 203 | +*/ |
| 204 | +void process(mGetDelegateRequest&& request, XMLElement* response, const EWSContext& ctx) |
| 205 | +{ |
| 206 | + response->SetName("m:GetDelegateResponse"); |
| 207 | + |
| 208 | + ctx.normalize(request.Mailbox); |
| 209 | + |
| 210 | + mGetDelegateResponse data; |
| 211 | + |
| 212 | + std::vector<std::string> delegate_list; |
| 213 | + std::string maildir = ctx.get_maildir(request.Mailbox); |
| 214 | + auto path = maildir + "/config/delegates.txt"; |
| 215 | + auto err = read_file_by_line(path.c_str(), delegate_list); |
| 216 | + if (err != 0) { |
| 217 | + data.serialize(response); |
| 218 | + return; |
| 219 | + } |
| 220 | + |
| 221 | + std::unordered_set<std::string> requested; |
| 222 | + if (request.UserIds) { |
| 223 | + for (auto &&uid : *request.UserIds) |
| 224 | + if (uid.PrimarySmtpAddress) |
| 225 | + requested.insert(std::move(*uid.PrimarySmtpAddress)); |
| 226 | + } |
| 227 | + |
| 228 | + std::unordered_set<std::string> found; |
| 229 | + for (const auto &deleg : delegate_list) { |
| 230 | + if (requested.empty() || requested.contains(deleg)) { |
| 231 | + auto &msg = data.ResponseMessages.emplace_back(); |
| 232 | + msg.success(); |
| 233 | + msg.DelegateUser.UserId.PrimarySmtpAddress.emplace(deleg); |
| 234 | + found.insert(deleg); |
| 235 | + } |
| 236 | + } |
| 237 | + |
| 238 | + if (!requested.empty()) { |
| 239 | + for (const auto &req : requested) { |
| 240 | + if (!found.contains(req)) { |
| 241 | + auto &msg = data.ResponseMessages.emplace_back(); |
| 242 | + msg.error("ErrorDelegateNotFound", "Delegate not found"); |
| 243 | + msg.DelegateUser.UserId.PrimarySmtpAddress.emplace(req); |
| 244 | + } |
| 245 | + } |
| 246 | + } |
| 247 | + |
| 248 | + data.serialize(response); |
| 249 | +} |
| 250 | + |
191 | 251 | /** |
192 | 252 | * @brief Process CreateFolder |
193 | 253 | * |
|
0 commit comments