From 62b95f35576ea9b9178b900f9480fed0466211a2 Mon Sep 17 00:00:00 2001 From: yehudah Date: Wed, 4 Apr 2018 19:17:51 +0000 Subject: notification & new gmail client --- .../PostmanGmailApiModuleZendMailTransport.php | 38 +++++++++++++++++++--- 1 file changed, 34 insertions(+), 4 deletions(-) (limited to 'Postman/Postman-Mail/PostmanGmailApiModuleZendMailTransport.php') diff --git a/Postman/Postman-Mail/PostmanGmailApiModuleZendMailTransport.php b/Postman/Postman-Mail/PostmanGmailApiModuleZendMailTransport.php index 58b5e5a..4cf9b31 100644 --- a/Postman/Postman-Mail/PostmanGmailApiModuleZendMailTransport.php +++ b/Postman/Postman-Mail/PostmanGmailApiModuleZendMailTransport.php @@ -181,19 +181,48 @@ if (! class_exists ( 'PostmanGmailApiModuleZendMailTransport' )) { * @todo Rename this to sendMail, it's a public method... */ public function _sendMail() { - + // Prepare the message in message/rfc822 $message = $this->header . Postman_Zend_Mime::LINEEND . $this->body; $this->message = $message; - + // The message needs to be encoded in Base64URL $encodedMessage = rtrim ( strtr ( base64_encode ( $message ), '+/', '-_' ), '=' ); - $googleApiMessage = new Postman_Google_Service_Gmail_Message (); + $googleApiMessage = new Google_Service_Gmail_Message (); $googleApiMessage->setRaw ( $encodedMessage ); $googleService = $this->_config [self::SERVICE_OPTION]; + $googleClient = $googleService->getClient(); + //$googleService = new Google_Service_Gmail($googleClient); + $result = array (); try { - $result = $googleService->users_messages->send ( 'me', $googleApiMessage ); + $googleClient->setDefer(true); + $result = $googleService->users_messages->send ( 'me', $googleApiMessage, array('uploadType' => 'resumable') ); + + $chunkSizeBytes = 1 * 1024 * 1024; + + // create mediafile upload + $media = new Google_Http_MediaFileUpload( + $googleClient, + $result, + 'message/rfc822', + $message, + true, + $chunkSizeBytes + ); + $media->setFileSize(strlen($message)); + + $status = false; + while (! $status) { + $status = $media->nextChunk(); + } + $result = false; + + // Reset to the client to execute requests immediately in the future. + $googleClient->setDefer(false); + + $googleMessageId = $status->getId(); + if ($this->logger->isInfo ()) { $this->logger->info ( sprintf ( 'Message %d accepted for delivery', PostmanState::getInstance ()->getSuccessfulDeliveries () + 1 ) ); } @@ -207,6 +236,7 @@ if (! class_exists ( 'PostmanGmailApiModuleZendMailTransport' )) { throw $e; } } + public function getMessage() { return $this->message; } -- cgit v1.2.3