Skip to content

Commit 951ddbc

Browse files
committed
Merge branch 'getdelegate'
2 parents 247163a + d5de82e commit 951ddbc

File tree

5 files changed

+120
-2
lines changed

5 files changed

+120
-2
lines changed

exch/ews/ews.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ const std::unordered_map<std::string, EWSPlugin::Handler> EWSPlugin::requestMap
239239
{"FindItem", process<Structures::mFindItemRequest>},
240240
{"GetAppManifests", process<Structures::mGetAppManifestsRequest>},
241241
{"GetAttachment", process<Structures::mGetAttachmentRequest>},
242+
{"GetDelegate", process<Structures::mGetDelegateRequest>},
242243
{"GetEvents", process<Structures::mGetEventsRequest>},
243244
{"GetFolder", process<Structures::mGetFolderRequest>},
244245
{"GetInboxRules", process<Structures::mGetInboxRulesRequest>},

exch/ews/requests.cpp

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// This file is part of Gromox.
44
#include <algorithm>
55
#include <fstream>
6+
#include <unordered_set>
67
#include <variant>
78
#include <sys/stat.h>
89
#include <sys/wait.h>
@@ -11,6 +12,7 @@
1112
#include <gromox/clock.hpp>
1213
#include <gromox/config_file.hpp>
1314
#include <gromox/eid_array.hpp>
15+
#include <gromox/fileio.h>
1416
#include <gromox/mysql_adaptor.hpp>
1517
#include <gromox/rop_util.hpp>
1618
#include <gromox/util.hpp>
@@ -188,6 +190,64 @@ void process(mConvertIdRequest&& request, XMLElement* response, EWSContext& ctx)
188190
data.serialize(response);
189191
}
190192

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+
191251
/**
192252
* @brief Process CreateFolder
193253
*

exch/ews/requests.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ EWSFUNC(mFindFolderRequest);
2626
EWSFUNC(mFindItemRequest);
2727
EWSFUNC(mGetAppManifestsRequest);
2828
EWSFUNC(mGetAttachmentRequest);
29+
EWSFUNC(mGetDelegateRequest);
2930
EWSFUNC(mGetEventsRequest);
3031
EWSFUNC(mGetFolderRequest);
3132
EWSFUNC(mGetInboxRulesRequest);

exch/ews/serialization.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1780,6 +1780,28 @@ void mGetUserConfigurationResponse::serialize(XMLElement* xml) const
17801780
XMLDUMPM(ResponseMessages);
17811781
}
17821782

1783+
void tDelegateUser::serialize(XMLElement* xml) const
1784+
{
1785+
XMLDUMPT(UserId);
1786+
}
1787+
1788+
mGetDelegateRequest::mGetDelegateRequest(const XMLElement* xml) :
1789+
XMLINIT(Mailbox),
1790+
XMLINIT(UserIds),
1791+
XMLINIT(IncludePermissions)
1792+
{}
1793+
1794+
void mDelegateUserResponseMessage::serialize(XMLElement* xml) const
1795+
{
1796+
mResponseMessageType::serialize(xml);
1797+
XMLDUMPT(DelegateUser);
1798+
}
1799+
1800+
void mGetDelegateResponse::serialize(XMLElement* xml) const
1801+
{
1802+
XMLDUMPM(ResponseMessages);
1803+
}
1804+
17831805
void mGetUserOofSettingsResponse::serialize(XMLElement* xml) const
17841806
{
17851807
XMLDUMPM(ResponseMessage);

exch/ews/structures.hpp

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1076,12 +1076,21 @@ struct tUserId {
10761076
//<xs:element name="SID" type="xs:string" minOccurs="0" maxOccurs="1" />
10771077
std::optional<std::string> PrimarySmtpAddress;
10781078
std::optional<std::string> DisplayName;
1079-
std::optional<Enum::DistinguishedUserType> DistinguishedUser;
1080-
//<xs:element name="ExternalUserIdentity" type="xs:string" minOccurs="0" maxOccurs="1" />
1079+
std::optional<Enum::DistinguishedUserType> DistinguishedUser;
1080+
//<xs:element name="ExternalUserIdentity" type="xs:string" minOccurs="0" maxOccurs="1" />
10811081

10821082
void serialize(tinyxml2::XMLElement*) const;
10831083
};
10841084

1085+
/**
1086+
* Types.xsd:6909
1087+
*/
1088+
struct tDelegateUser {
1089+
tUserId UserId;
1090+
1091+
void serialize(tinyxml2::XMLElement*) const;
1092+
};
1093+
10851094
/**
10861095
* Types.xsd:6773
10871096
*/
@@ -3943,6 +3952,31 @@ struct mGetUserConfigurationResponse {
39433952
void serialize(tinyxml2::XMLElement*) const;
39443953
};
39453954

3955+
/**
3956+
* Messages.xsd:2321
3957+
*/
3958+
struct mGetDelegateRequest {
3959+
explicit mGetDelegateRequest(const tinyxml2::XMLElement*);
3960+
3961+
tMailbox Mailbox;
3962+
std::optional<std::vector<tUserId>> UserIds;
3963+
std::optional<bool> IncludePermissions;
3964+
};
3965+
3966+
struct mDelegateUserResponseMessage : public mResponseMessageType {
3967+
static constexpr char NAME[] = "DelegateUserResponseMessageType";
3968+
3969+
tDelegateUser DelegateUser;
3970+
3971+
void serialize(tinyxml2::XMLElement*) const;
3972+
};
3973+
3974+
struct mGetDelegateResponse {
3975+
std::vector<mDelegateUserResponseMessage> ResponseMessages;
3976+
3977+
void serialize(tinyxml2::XMLElement*) const;
3978+
};
3979+
39463980
/**
39473981
* @brief Get inbox rules request
39483982
*

0 commit comments

Comments
 (0)