Skip to content
39 changes: 39 additions & 0 deletions src/Controller/Api/MailArchiveController.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,45 @@ public function __construct(
private readonly EmlFileManager $emlFileManager,
) {}

#[Route(path: '/api/_action/frosh-mail-archive/fetch-eml-headers', name: 'api.action.frosh-mail-archive.fetch-eml-headers')]
public function fetchEmlHeaders(Request $request, Context $context): JsonResponse
{
$mailId = $request->request->get('mailId');

if (!\is_string($mailId)) {
throw MailArchiveException::parameterMissing('mailId');
}

$mailArchive = $this->froshMailArchiveRepository->search(new Criteria([$mailId]), $context)->first();
if (!$mailArchive instanceof MailArchiveEntity) {
throw MailArchiveException::notFound();
}

$mainRequest = $this->requestStack->getMainRequest();
if (!$mainRequest instanceof Request) {
throw new \RuntimeException('Cannot get mainRequest');
}

$mainRequest->attributes->set(PlatformRequest::ATTRIBUTE_SALES_CHANNEL_ID, $mailArchive->getSalesChannelId());

$emlPath = $mailArchive->getEmlPath();
if ($emlPath === null) {
return new JsonResponse([]);
}

$emlMessage = $this->emlFileManager->getEmlAsMessage($emlPath);
if ($emlMessage === false) {
return new JsonResponse([]);
}

$headers = [];
foreach ($emlMessage->getAllHeaders() as $header) {
$headers[$header->getName()] = $header->getValue();
}

return new JsonResponse($headers);
}

#[Route(path: '/api/_action/frosh-mail-archive/resend-mail', name: 'api.action.frosh-mail-archive.resend-mail')]
public function resend(Request $request, Context $context): JsonResponse
{
Expand Down
15 changes: 15 additions & 0 deletions src/Resources/app/administration/src/init/api_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,21 @@ class ApiClient extends ApiService {
super(httpClient, loginService, apiEndpoint);
}

fetchEmlHeaders(mailId) {
const headers = this.getBasicHeaders({});

return this.httpClient
.post(`_action/${this.getApiBasePath()}/fetch-eml-headers`, {
mailId,
}, {
...this.basicConfig,
headers
})
.then((response) => {
return ApiService.handleResponse(response);
});
}

resendMail(mailId) {
const headers = this.getBasicHeaders({});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@
<dt>{{ $tc('frosh-mail-archive.detail.metadata.subject') }}</dt>
<dd>{{ archive.subject }}</dd>
</sw-description-list>
<sw-description-list>
<dt>{{ $tc('frosh-mail-archive.detail.metadata.cc') }}</dt>
<dd>{{ emlHeaders.Cc ?? '-' }}</dd>
</sw-description-list>
<sw-description-list>
<dt>{{ $tc('frosh-mail-archive.detail.metadata.bcc') }}</dt>
<dd>{{ emlHeaders.Bcc ?? '-' }}</dd>
</sw-description-list>
<sw-description-list>
<dt>{{ $tc('frosh-mail-archive.detail.metadata.sentDate') }}</dt>
<dd>{{ createdAtDate }}</dd>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Component.register('frosh-mail-archive-detail', {
data() {
return {
archive: null,
emlHeaders: {},
resendIsLoading: false,
resendIsSuccessful: false,
downloadIsLoading: false,
Expand Down Expand Up @@ -113,6 +114,10 @@ Component.register('frosh-mail-archive-detail', {
this.repository.get(this.archiveId, Shopware.Context.api, criteria).then(archive => {
this.archive = archive;
})

this.froshMailArchiveService.fetchEmlHeaders(this.archiveId).then(headers => {
this.emlHeaders = headers;
})
},
getContent(html) {
return 'data:text/html;base64,' + btoa(unescape(encodeURIComponent(html.replace(/[\u00A0-\u2666]/g, function (c) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
"sentDate": "Versanddatum",
"sender": "Absender",
"receiver": "Empfänger",
"cc": "CC",
"bcc": "BCC",
"subject": "Betreff",
"salesChannel": "Verkaufskanal",
"customer": "Kunde",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
"sentDate": "Sent date",
"sender": "Sender",
"receiver": "Recipients",
"cc": "CC",
"bcc": "BCC",
"subject": "Subject",
"salesChannel": "Sales Channel",
"customer": "Customer",
Expand Down