Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "tiamo/phpas2",
"name": "ayrel/phpas2",
"description": "PHPAS2 is a php-based implementation of the EDIINT AS2 standard",
"version": "1.3.4",
"version": "1.3.4.1",
"authors": [
{
"name": "Vladyslav K",
Expand Down
45 changes: 42 additions & 3 deletions src/MimePart.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ class MimePart implements \Psr\Http\Message\MessageInterface
const ENCODING_QUOTEDPRINTABLE = 'quoted-printable';
const ENCODING_BASE64 = 'base64';

/**s
* @var string
*/
private $rawMessage;

/**
* @var string
*/
Expand All @@ -43,9 +48,14 @@ class MimePart implements \Psr\Http\Message\MessageInterface
* @param array $headers
* @param null $body
*/
public function __construct($headers = [], $body = null)
public function __construct($headers = [], $body = null, $rawMessage = null)
{
if (null !== $rawMessage) {
$this->rawMessage = $rawMessage;
}

$this->setHeaders((array)$headers);

if (!is_null($body)) {
$this->setBody($body);
}
Expand All @@ -71,7 +81,7 @@ public static function fromRequest(\Psr\Http\Message\RequestInterface $request)
public static function fromString($rawMessage)
{
$payload = Utils::parseMessage($rawMessage);
return new static($payload['headers'], $payload['body']);
return new static($payload['headers'], $payload['body'], $rawMessage);
}

/**
Expand Down Expand Up @@ -259,7 +269,15 @@ public function setBody($body)
if ($boundary) {
$separator = '--' . preg_quote($boundary, '/');
// Get multi-part content
if (preg_match('/' . $separator . '\r?\n(.+?)\r?\n' . $separator . '--/s', $body, $matches)) {

if (preg_match(
'/' .
$separator .
'\r?\n(.+?)\r?\n' .
$separator . '--/s',
$this->getRawBody() ? $this->getRawBody() : $body,
$matches
)) {
$parts = preg_split('/\r?\n' . $separator . '\r?\n/', $matches[1]);
foreach ($parts as $part) {
$this->addPart($part);
Expand All @@ -272,13 +290,34 @@ public function setBody($body)
return $this;
}

public function getRawBody()
{
if (null===$this->rawMessage) {
return null;
}

$lines = preg_split('/(\\r?\\n)/', $this->rawMessage, -1, PREG_SPLIT_DELIM_CAPTURE);

for ($i = 0, $totalLines = count($lines); $i < $totalLines; $i += 2) {
$line = $lines[$i];
if (empty($line)) {
if ($i < $totalLines - 1) {
return implode('', array_slice($lines, $i + 2));
}
}
}
}

/**
* Serialize to string
*
* @return string
*/
public function toString()
{
if ($this->rawMessage) {
return $this->rawMessage;
}
return $this->getHeaderLines() . self::EOL . $this->getBody();
}

Expand Down
25 changes: 25 additions & 0 deletions tests/MimePartTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php
/**
* Created by PhpStorm.
* User: frjlros
* Date: 09/08/19
* Time: 13:24
*/

namespace AS2\Tests;


use AS2\CryptoHelper;
use AS2\MimePart;

class MimePartTest extends \PHPUnit_Framework_TestCase
{
public function testMicCalculation()
{
$contents = file_get_contents(__DIR__.DIRECTORY_SEPARATOR.'resources'.DIRECTORY_SEPARATOR."mic-calculation");
$this->assertEquals(
"rqrsInCnD6/dLvr5UO1ng0YGuqaG1wETIMTunzc77a0=, sha256",
CryptoHelper::calculateMIC($contents, 'sha256')
);
}
}
36 changes: 36 additions & 0 deletions tests/resources/mic-calculation
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
Content-Type: application/octet-stream;
name=b9e89bc0-98e6-11e9-b9b5-9ed6995f3d54
Content-Transfer-Encoding: binary
Content-Disposition: attachment;
filename=b9e89bc0-98e6-11e9-b9b5-9ed6995f3d54

EDI_DC40 1000000000012983439711 3024 ORDERS05 ORDERS EDIENG SAPIXZ KU 1010298 FIT-BIS LILF0002020205 20190626132947 EE 5D12D247C56F9CD0E1008000995F33DE 000000046065483220190626132946
E2EDK01005 100000000001298343900000100000001 EUREUR1.00000 K146 NB 4503949291 0002020205
E2EDK14 1000000000012983439000002000000020140012
E2EDK14 100000000001298343900000300000002009GM2
E2EDK14 100000000001298343900000400000002013NB
E2EDK14 1000000000012983439000005000000020110012
E2EDK03 10000000000129834390000060000000201220190626
E2EDK03 10000000000129834390000070000000201120190626
E2EDKA1003 100000000001298343900000800000002AG 1010298 DW 2445 +43.50.620.2409 Sarah Pargfrieder 0012 ENGEL AUSTRIA GmbH GM2
E2EDKA1003 100000000001298343900000900000002LF 0002020205 D Hr. Reiter DE
E2EDK02 1000000000012983439000010000000020014503949291 20190626132946
E2EDK17 100000000001298343900001100000002001DDPWerk gem�� Lieferadresse
E2EDK17 100000000001298343900001200000002002 Werk gem�� Lieferadresse
E2EDK18 10000000000129834390000130000000200125 3.000
E2EDP01008 10000000000129834390000140000000200010 0010 420.000 KGM420.000 KGM 2120 1000 890.4 KGM W002 MV 1 1 0011 L000
E2EDP20001 100000000001298343900001500001403420.000 0.000 20190724
E2EDPA1003 100000000001298343900001600001403WE 0011 L000 LP05 D
E2EDP19002 1000000000012983439000017000014030023000859
E2EDP19002 10000000000129834390000180000140300100218-0075 RUNDSTAHL 75 DIN1013 1.8550+QT
E2EDP19002 100000000001298343900001900001403900
E2EDP35000 100000000001298343900002000001403903L000 LP05
E2EDPT1001 100000000001298343900002100001403BESTD DE
E2EDPT2001 100000000001298343900002200002104RUNDSTAHL 75 *
E2EDPT2001 100000000001298343900002300002104DIN 1013-1.8550.05 /
E2EDPT2001 100000000001298343900002400002104(34 CRALNI 7 V) NACH /
E2EDPT2001 100000000001298343900002500002104DIN 17211 - LIEFERART 5 /
E2EDPT2001 100000000001298343900002600002104MAX.STANGENLAENGE 6.300MM /
E2EDPT1001 100000000001298343900002700001403F04 D DE
E2EDPT2001 100000000001298343900002800002704L000 LP05 *
E2EDS01 100000000001298343900002900000002002890.4 EUR