From f51fbfa43ee1c3226ca523ed613a59423fceaaff Mon Sep 17 00:00:00 2001 From: Mohamed Radwan Date: Tue, 21 Feb 2023 17:20:48 +0200 Subject: [PATCH 1/6] adding snipping attribute to mail --- src/Services/Message/Mail.php | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/Services/Message/Mail.php b/src/Services/Message/Mail.php index 34dbdc6..bd2b8a4 100644 --- a/src/Services/Message/Mail.php +++ b/src/Services/Message/Mail.php @@ -71,6 +71,11 @@ class Mail extends GmailConnection public $parts; + /** + * @var + */ + public $snippet; + /** * @var Google_Service_Gmail */ @@ -130,6 +135,7 @@ protected function setMessage(\Google_Service_Gmail_Message $message) $this->threadId = $message->getThreadId(); $this->historyId = $message->getHistoryId(); $this->payload = $message->getPayload(); + $this->snippet = $message->getSnippet(); if ($this->payload) { $this->parts = collect($this->payload->getParts()); } @@ -231,6 +237,18 @@ public function getReplyTo() return $this->getFrom($replyTo ? $replyTo : $this->getHeader('From')); } + /** + * Returns the Snippet from the email + * + * @return string + */ + public function getSnippet() + { + + + return $this->snippet; + } + /** * Returns array of name and email of each recipient * @@ -407,7 +425,6 @@ public function getPlainTextBody($raw = false) public function getBody($type = 'text/plain') { $parts = $this->getAllParts($this->parts); - try { if (!$parts->isEmpty()) { foreach ($parts as $part) { From f4af7e957c29dc580a613ff3b621973c4b781430 Mon Sep 17 00:00:00 2001 From: Mohamed Radwan Date: Tue, 21 Feb 2023 19:42:42 +0200 Subject: [PATCH 2/6] added getLabel to HasLabel Trait --- src/Traits/HasLabels.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/Traits/HasLabels.php b/src/Traits/HasLabels.php index b4e40f5..1df36ea 100644 --- a/src/Traits/HasLabels.php +++ b/src/Traits/HasLabels.php @@ -56,4 +56,18 @@ public function firstOrCreateLabel($userEmail, $newLabel) return $service->users_labels->create($userEmail, $newLabel); } + + /** + * List the labels in the user's mailbox. + * + * @param $userEmail + * + * @return \Google\Service\Gmail\Label + */ + public function getLabel($userEmail, $id) + { + $service = new Google_Service_Gmail($this); + + return $service->users_labels->get($userEmail, $id); + } } \ No newline at end of file From 6bbdd5f6bc6c5e4098b5a2b84469c123d1c3196b Mon Sep 17 00:00:00 2001 From: Mohamed Radwan Date: Thu, 23 Feb 2023 21:48:18 +0200 Subject: [PATCH 3/6] update replyable to follow symfony mime --- src/Traits/Replyable.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Traits/Replyable.php b/src/Traits/Replyable.php index 876ac07..7642798 100644 --- a/src/Traits/Replyable.php +++ b/src/Traits/Replyable.php @@ -359,7 +359,6 @@ public function setHeader($header, $value) $headers = $this->symfonyEmail->getHeaders(); $headers->addTextHeader($header, $value); - } private function setReplySubject() @@ -401,16 +400,18 @@ public abstract function getUser(); private function getMessageBody() { $body = new Google_Service_Gmail_Message(); - $this->symfonyEmail ->from($this->fromAddress()) ->to($this->toAddress()) - ->cc($this->returnCopies($this->cc)) - ->bcc($this->returnCopies($this->bcc)) ->subject($this->subject) ->html($this->message) ->priority($this->priority); - + if (!empty($this->cc)) { + $this->symfonyEmail->cc($this->returnCopies($this->cc)); + } + if (!empty($this->bcc)) { + $this->symfonyEmail->bcc($this->returnCopies($this->bcc)); + } foreach ($this->attachments as $file) { $this->symfonyEmail->attachFromPath($file); } @@ -438,7 +439,7 @@ public function returnCopies($cc) return $final; } - return []; + return ""; } public function toAddress() @@ -472,7 +473,6 @@ private function base64_encode($data) public function send() { $body = $this->getMessageBody(); - $this->setMessage($this->service->users_messages->send('me', $body, $this->parameters)); return $this; From 03a68ab4ea7b8ba864b929041a706070853b3097 Mon Sep 17 00:00:00 2001 From: Mohamed Radwan Date: Thu, 4 May 2023 15:19:41 +0300 Subject: [PATCH 4/6] make condition to save file or not --- src/GmailConnection.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/GmailConnection.php b/src/GmailConnection.php index 16810c1..f411881 100644 --- a/src/GmailConnection.php +++ b/src/GmailConnection.php @@ -183,7 +183,7 @@ public function saveAccessToken(array $config) * @return array|string * @throws \Exception */ - public function makeToken() + public function makeToken($saveFile = true) { if (!$this->check()) { $request = Request::capture(); @@ -197,7 +197,11 @@ public function makeToken() $accessToken['email'] = $me->emailAddress; } } - $this->setBothAccessToken($accessToken); + if ($saveFile) { + $this->setBothAccessToken($accessToken); + } else { + $this->setAccessToken($accessToken); + } return $accessToken; } else { From 907013be933b8ea7d0b805907f68df6c829a4295 Mon Sep 17 00:00:00 2001 From: Mohamed Radwan Date: Thu, 4 May 2023 15:20:14 +0300 Subject: [PATCH 5/6] comment preload for attachment becase it get unauthorized --- src/Services/Message/Mail.php | 47 ++++++++++++++++------------------- 1 file changed, 22 insertions(+), 25 deletions(-) diff --git a/src/Services/Message/Mail.php b/src/Services/Message/Mail.php index bd2b8a4..6b1ff14 100644 --- a/src/Services/Message/Mail.php +++ b/src/Services/Message/Mail.php @@ -59,10 +59,10 @@ class Mail extends GmailConnection */ public $threadId; - /** - * @var - */ - public $historyId; + /** + * @var + */ + public $historyId; /** * @var \Google_Service_Gmail_MessagePart @@ -71,17 +71,17 @@ class Mail extends GmailConnection public $parts; - /** - * @var - */ - public $snippet; + /** + * @var + */ + public $snippet; /** * @var Google_Service_Gmail */ public $service; - /** + /** * SingleMessage constructor. * * @param \Google_Service_Gmail_Message $message @@ -135,7 +135,7 @@ protected function setMessage(\Google_Service_Gmail_Message $message) $this->threadId = $message->getThreadId(); $this->historyId = $message->getHistoryId(); $this->payload = $message->getPayload(); - $this->snippet = $message->getSnippet(); + $this->snippet = $message->getSnippet(); if ($this->payload) { $this->parts = collect($this->payload->getParts()); } @@ -237,17 +237,17 @@ public function getReplyTo() return $this->getFrom($replyTo ? $replyTo : $this->getHeader('From')); } - /** - * Returns the Snippet from the email - * - * @return string - */ - public function getSnippet() - { + /** + * Returns the Snippet from the email + * + * @return string + */ + public function getSnippet() + { - return $this->snippet; - } + return $this->snippet; + } /** * Returns array of name and email of each recipient @@ -366,7 +366,6 @@ public function formatEmailList($emails) $item['name'] = str_replace("\"", '', $name ?: null); $all[] = $item; - } return $all; @@ -548,11 +547,9 @@ public function getAttachments($preload = false) foreach ($parts as $part) { if (!empty($part->body->attachmentId)) { $attachment = (new Attachment($part->body->attachmentId, $part, $this->userId)); - - if ($preload) { - $attachment = $attachment->getData(); - } - + // if ($preload) { + // $attachment = $attachment->getData(); + // } $attachments->push($attachment); } } From 4691c8a2879e5d3518e35f718595e15596f7561a Mon Sep 17 00:00:00 2001 From: Mohamed Radwan Date: Thu, 4 May 2023 17:32:11 +0300 Subject: [PATCH 6/6] fix issues --- src/GmailConnection.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/GmailConnection.php b/src/GmailConnection.php index f411881..f2903fb 100644 --- a/src/GmailConnection.php +++ b/src/GmailConnection.php @@ -57,7 +57,9 @@ public function checkPreviouslyLoggedIn() $fileName = $this->getFileName(); $file = "gmail/tokens/$fileName.json"; $allowJsonEncrypt = $this->_config['gmail.allow_json_encrypt']; - + if (!empty($this->configObject)) { + return !empty($this->configObject['access_token']); + } if (Storage::disk('local')->exists($file)) { if ($allowJsonEncrypt) { $savedConfigToken = json_decode(decrypt(Storage::disk('local')->get($file)), true);