File indexing completed on 2024-12-22 04:57:00
0001 /* 0002 SPDX-FileCopyrightText: 2015-2017 Krzysztof Nowicki <krissn@op.pl> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "ewscreatefolderrequest.h" 0008 0009 #include "ewsclient_debug.h" 0010 0011 EwsCreateFolderRequest::EwsCreateFolderRequest(EwsClient &client, QObject *parent) 0012 : EwsRequest(client, parent) 0013 { 0014 } 0015 0016 EwsCreateFolderRequest::~EwsCreateFolderRequest() 0017 { 0018 } 0019 0020 void EwsCreateFolderRequest::start() 0021 { 0022 QString reqString; 0023 QXmlStreamWriter writer(&reqString); 0024 0025 startSoapDocument(writer); 0026 0027 writer.writeStartElement(ewsMsgNsUri, QStringLiteral("CreateFolder")); 0028 0029 writer.writeStartElement(ewsMsgNsUri, QStringLiteral("ParentFolderId")); 0030 mParentFolderId.writeFolderIds(writer); 0031 writer.writeEndElement(); 0032 0033 writer.writeStartElement(ewsMsgNsUri, QStringLiteral("Folders")); 0034 for (const EwsFolder &folder : std::as_const(mFolders)) { 0035 folder.write(writer); 0036 } 0037 writer.writeEndElement(); 0038 0039 writer.writeEndElement(); 0040 0041 endSoapDocument(writer); 0042 0043 qCDebugNC(EWSCLI_REQUEST_LOG) << QStringLiteral("Starting CreateFolder request (%1 folders, parent %2)").arg(mFolders.size()).arg(mParentFolderId.id()); 0044 0045 qCDebug(EWSCLI_PROTO_LOG) << reqString; 0046 0047 prepare(reqString); 0048 0049 doSend(); 0050 } 0051 0052 bool EwsCreateFolderRequest::parseResult(QXmlStreamReader &reader) 0053 { 0054 return parseResponseMessage(reader, QStringLiteral("CreateFolder"), [this](QXmlStreamReader &reader) { 0055 return parseItemsResponse(reader); 0056 }); 0057 } 0058 0059 bool EwsCreateFolderRequest::parseItemsResponse(QXmlStreamReader &reader) 0060 { 0061 Response resp(reader); 0062 if (resp.responseClass() == EwsResponseUnknown) { 0063 return false; 0064 } 0065 0066 if (EWSCLI_REQUEST_LOG().isDebugEnabled()) { 0067 if (resp.isSuccess()) { 0068 qCDebug(EWSCLI_REQUEST_LOG) << QStringLiteral("Got CreateFolder response - OK"); 0069 } else { 0070 qCDebug(EWSCLI_REQUEST_LOG) << QStringLiteral("Got CreateFolder response - %1").arg(resp.responseMessage()); 0071 } 0072 } 0073 mResponses.append(resp); 0074 return true; 0075 } 0076 0077 EwsCreateFolderRequest::Response::Response(QXmlStreamReader &reader) 0078 : EwsRequest::Response(reader) 0079 { 0080 if (mClass == EwsResponseParseError) { 0081 return; 0082 } 0083 0084 while (reader.readNextStartElement()) { 0085 if (reader.namespaceUri() != ewsMsgNsUri && reader.namespaceUri() != ewsTypeNsUri) { 0086 setErrorMsg(QStringLiteral("Unexpected namespace in %1 element: %2").arg(QStringLiteral("ResponseMessage"), reader.namespaceUri().toString())); 0087 return; 0088 } 0089 0090 if (reader.name() == QLatin1StringView("Folders")) { 0091 if (reader.readNextStartElement()) { 0092 EwsFolder folder(reader); 0093 if (!folder.isValid()) { 0094 return; 0095 } 0096 mId = folder[EwsFolderFieldFolderId].value<EwsId>(); 0097 0098 // Finish the Folders element. 0099 reader.skipCurrentElement(); 0100 } 0101 } else if (!readResponseElement(reader)) { 0102 setErrorMsg(QStringLiteral("Failed to read EWS request - invalid response element.")); 0103 return; 0104 } 0105 } 0106 } 0107 0108 #include "moc_ewscreatefolderrequest.cpp"