diff --git a/src/main.cpp b/src/main.cpp index c25cdd84f..b78b5819d 100755 --- a/src/main.cpp +++ b/src/main.cpp @@ -183,8 +183,8 @@ int main(int argc, char* argv[]) { multi->setContentType(QHttpMultiPart::ContentType::MixedType); p1.setRawHeader("Content-Type", "application/http"); p2.setRawHeader("Content-Type", "application/http"); - p1.setBody("GET /gmail/v1/users/me/messages\r\n"); - p2.setBody("GET /gmail/v1/users/me/labels\r\n"); + p1.setBody("GET /gmail/v1/users/me/messages/15f3427a9f6d2728\r\n"); + p2.setBody("GET /gmail/v1/users/me/messages/15f259a2c353589b\r\n"); multi->append(p1); multi->append(p2); QNetworkRequest req; @@ -210,7 +210,8 @@ int main(int argc, char* argv[]) { QObject::connect(srv, &OAuth2Service::tokensRetrieveError, [](QString err, QString desc) { int a = 5; }); - srv->login();*/ + srv->login(); + */ // Enter global event loop. return Application::exec(); diff --git a/src/services/gmail/definitions.h b/src/services/gmail/definitions.h index 2e8a20bcd..f33db5582 100755 --- a/src/services/gmail/definitions.h +++ b/src/services/gmail/definitions.h @@ -10,8 +10,10 @@ #define GMAIL_API_LABELS_LIST "https://www.googleapis.com/gmail/v1/users/me/labels" #define GMAIL_API_MSGS_LIST "https://www.googleapis.com/gmail/v1/users/me/messages" -#define GMAIL_DEFAULT_BATCH_SIZE 100 +#define GMAIL_DEFAULT_BATCH_SIZE 50 #define GMAIL_MAX_BATCH_SIZE 999 #define GMAIL_MIN_BATCH_SIZE 20 +#define GMAIL_CONTENT_TYPE_HTTP "application/http" + #endif // GMAIL_DEFINITIONS_H diff --git a/src/services/gmail/network/gmailnetworkfactory.cpp b/src/services/gmail/network/gmailnetworkfactory.cpp index 713c788f6..1397d7464 100755 --- a/src/services/gmail/network/gmailnetworkfactory.cpp +++ b/src/services/gmail/network/gmailnetworkfactory.cpp @@ -16,6 +16,7 @@ #include "services/gmail/gmailfeed.h" #include "services/gmail/gmailserviceroot.h" +#include #include #include #include @@ -329,6 +330,38 @@ void GmailNetworkFactory::onAuthFailed() { } bool GmailNetworkFactory::obtainAndDecodeFullMessages(const QList& lite_messages) { + QHttpMultiPart* multi = new QHttpMultiPart(); + + multi->setContentType(QHttpMultiPart::ContentType::MixedType); + + foreach (const Message& msg, lite_messages) { + QHttpPart part; + + part.setRawHeader(HTTP_HEADERS_CONTENT_TYPE, GMAIL_CONTENT_TYPE_HTTP); + QString full_msg_endpoint = QString("GET /gmail/v1/users/me/messages/%1\r\n").arg(msg.m_customId); + + part.setBody(full_msg_endpoint.toUtf8()); + multi->append(part); + } + + QEventLoop loop; + QNetworkRequest req; + auto bearer = m_oauth2->bearer(); + + req.setRawHeader(QString("Authorization").toLocal8Bit(), bearer.toLocal8Bit()); + req.setUrl(QUrl::fromUserInput("https://www.googleapis.com/batch")); + auto* repl = SilentNetworkAccessManager::instance()->post(req, multi); + + connect(repl, &QNetworkReply::finished, &loop, &QEventLoop::quit); + loop.exec(); + + auto resp = repl->readAll(); + auto aa = repl->error(); + + multi->deleteLater(); + repl->deleteLater(); + IOFactory::writeTextFile("b.html", resp); + return false; }