Skip to content

Commit a852b5c

Browse files
committed
Fixed new swift mail
1 parent 585c39f commit a852b5c

File tree

1 file changed

+54
-39
lines changed

1 file changed

+54
-39
lines changed

src/Traits/Replyable.php

Lines changed: 54 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Dacastro4\LaravelGmail\Services\Message\Mail;
66
use Google_Service_Gmail;
77
use Google_Service_Gmail_Message;
8+
use Symfony\Component\Mime\Address;
89
use Symfony\Component\Mime\Email;
910
use Illuminate\Container\Container;
1011
use Illuminate\Mail\Markdown;
@@ -401,49 +402,63 @@ private function getMessageBody()
401402
{
402403
$body = new Google_Service_Gmail_Message();
403404

404-
if ($this->from) {
405-
$this->symfonyEmail->from($this->from, ($this->nameFrom ? $this->nameFrom : ''));
406-
}
407-
408-
if ($this->to) {
409-
$this->symfonyEmail->to($this->to, ($this->nameTo ? $this->nameTo : ''));
410-
}
411-
412-
if ($this->cc) {
413-
if (is_array($this->cc)) {
414-
foreach ($this->cc as $emailCc => $nameCc) {
415-
$this->symfonyEmail->addCc($emailCc, $nameCc);
416-
}
417-
} else {
418-
$this->symfonyEmail->cc($this->cc, ($this->nameCc ? $this->nameCc : ''));
419-
}
420-
}
421-
422-
$bccString = "";
423-
if ($this->bcc) {
424-
if (is_array($this->bcc)) {
425-
foreach ($this->bcc as $emailBcc => $nameBcc) {
426-
$bccString .= "Bcc: " . $nameBcc . " <" . $emailBcc . ">\r\n";
427-
}
428-
} else {
429-
$bccString .= "Bcc: " . ($this->nameBcc ? $this->nameBcc . " " : "") . "<" . $this->bcc . ">\r\n";
430-
}
431-
}
432-
433-
$this->symfonyEmail->subject($this->subject)
434-
->html($this->message)
435-
->priority($this->priority)
436-
;
437-
438-
foreach ($this->attachments as $file) {
439-
$this->symfonyEmail->attachFromPath($file);
440-
}
441-
442-
$body->setRaw($this->base64_encode($bccString . $this->symfonyEmail->toString()));
405+
$this->symfonyEmail
406+
->from($this->fromAddress())
407+
->to($this->toAddress())
408+
->cc($this->returnCopies($this->cc))
409+
->bcc($this->returnCopies($this->bcc))
410+
->subject($this->subject)
411+
->html($this->message)
412+
->priority($this->priority);
413+
414+
foreach ($this->attachments as $file) {
415+
$this->symfonyEmail->attachFromPath($file);
416+
}
417+
418+
$body->setRaw($this->base64_encode($this->symfonyEmail->toString()));
443419

444420
return $body;
445421
}
446422

423+
/**
424+
* @param array|string $cc
425+
* @return array|string
426+
*/
427+
public function returnCopies($cc)
428+
{
429+
if ($cc) {
430+
$final = $this->cc;
431+
432+
if (is_array($this->cc)) {
433+
foreach ($this->cc as $emailCc => $nameCc) {
434+
$final[] = new Address($emailCc, $nameCc);
435+
}
436+
}
437+
438+
return $final;
439+
}
440+
441+
return [];
442+
}
443+
444+
public function toAddress()
445+
{
446+
if ($this->to) {
447+
return new Address($this->to, $this->nameTo ?: '');
448+
}
449+
450+
return [];
451+
}
452+
453+
public function fromAddress()
454+
{
455+
if ($this->from) {
456+
return new Address($this->from, $this->nameFrom ?: '');
457+
}
458+
459+
return [];
460+
}
461+
447462
private function base64_encode($data)
448463
{
449464
return rtrim(strtr(base64_encode($data), ['+' => '-', '/' => '_']), '=');

0 commit comments

Comments
 (0)