Skip to content

Commit

Permalink
Additional testing.
Browse files Browse the repository at this point in the history
  • Loading branch information
tomshaw committed Mar 30, 2024
1 parent b7a7e87 commit 73457db
Showing 1 changed file with 23 additions and 14 deletions.
37 changes: 23 additions & 14 deletions src/Api/GoogleMail.php
Original file line number Diff line number Diff line change
Expand Up @@ -334,32 +334,41 @@ public function send(): Message
return $this->service->users_messages->send('me', $msg);
}

/**
* Builds an email message string.
*
* @param string $fromEmail The sender's email address.
* @param string $fromName The sender's name.
* @param string $toEmail The recipient's email address.
* @param string $toName The recipient's name.
* @param string $ccListString The list of CC recipients as a string.
* @param string $subject The subject of the email.
* @param string $message The body of the email.
* @return string Returns the built message as a string.
*/
protected function buildMessage(string $fromEmail, string $fromName, string $toEmail, string $toName, string $ccListString, string $subject, string $message): string
{
$headers = "From: $fromName <$fromEmail>\r\n";
$headers .= "To: $toName <$toEmail>\r\n";
if (count($this->getCC())) {
$headers .= "CC: {$ccListString}\r\n";
}
$headers .= 'Subject: =?utf-8?B?'.base64_encode($subject)."?=\r\n";
$headers .= "Subject: $subject\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=utf-8\r\n";
$headers .= 'Content-Transfer-Encoding: 8bit'."\r\n\r\n";
$headers .= $message;

return base64_encode($headers);
}

protected function buildMessageBinary(string $fromEmail, string $fromName, string $toEmail, string $toName, string $ccListString, string $subject, string $message, string $contentType): string
{
$headers = "From: $fromName <$fromEmail>\r\n";
$headers .= "To: $toName <$toEmail>\r\n";
if (count($this->getCC())) {
$headers .= "CC: {$ccListString}\r\n";
}
$headers .= 'Subject: =?utf-8?B?'.base64_encode($subject)."?=\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: $contentType\r\n";
$headers .= "Content-Transfer-Encoding: base64\r\n\r\n";

$encodedMessage = rtrim(strtr(base64_encode($message), '+/', '-_'), '=');
$encodedMessage = base64_encode($message);

return $headers.$encodedMessage;
}

protected function encodeUrlSafeMessage(string $message): string
{
return rtrim(strtr(base64_encode($message), '+/', '-_'), '=');
}
}

0 comments on commit 73457db

Please sign in to comment.