Skip to content

Commit 41a9a97

Browse files
authored
Update PostalTransport.php
1 parent 307400e commit 41a9a97

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

src/PostalTransport.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,12 @@ private function symfonyToPostal(Email $symfonyMessage): SendMessage
9898
$postalMessage->subject($symfonyMessage->getSubject());
9999
}
100100

101+
if ($symfonyMessage->getHeaders()) {
102+
foreach (parseHeadersToKeyValue($symfonyMessage->getHeaders()->toArray()) as $key => $value) {
103+
$postalMessage->header($key, $value);
104+
}
105+
}
106+
101107
if ($symfonyMessage->getTextBody()) {
102108
$postalMessage->plainBody($symfonyMessage->getTextBody());
103109
}
@@ -182,6 +188,29 @@ private function getNewSendMessage(): SendMessage
182188
return new SendMessage();
183189
}
184190

191+
function parseHeadersToKeyValue(array $headers): array
192+
{
193+
$parsedHeaders = [];
194+
195+
foreach ($headers as $header) {
196+
$colonPos = strpos($header, ':');
197+
198+
if ($colonPos !== false) {
199+
$key = trim(substr($header, 0, $colonPos));
200+
$value = trim(substr($header, $colonPos + 1));
201+
202+
if (isset($parsedHeaders[$key])) {
203+
$parsedHeaders[$key] .= ' ' . $value;
204+
} else {
205+
$parsedHeaders[$key] = $value;
206+
}
207+
}
208+
}
209+
210+
return $parsedHeaders;
211+
}
212+
213+
185214
/**
186215
* Get the string representation of the transport.
187216
*/

0 commit comments

Comments
 (0)