Skip to content
Open
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
8 changes: 8 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# See https://php.watch/articles/composer-gitattributes
/.github export-ignore
/tests export-ignore

/.gitignore export-ignore
/.gitattributes export-ignore
/phpunit.xml.dist export-ignore
/.php-cs-fixer.dist.php export-ignore
80 changes: 80 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# This file was heavily based on the ci-file from SymfonyCasts/verify-email-bundle
#
# See https://github.com/SymfonyCasts/verify-email-bundle
# https://github.com/SymfonyCasts/verify-email-bundle/blob/main/.github/workflows/ci.yml

name: CI
on:
push:
branches: ['main','master']
pull_request:

jobs:
lint:
name: Lint
runs-on: ubuntu-22.04

steps:
- name: "Checkout code"
uses: "actions/checkout@v4"

- name: "Install PHP"
uses: "shivammathur/setup-php@v2"
with:
coverage: "none"
php-version: "8.1"

- name: "Validate composer.json"
run: "composer validate --strict --no-check-lock"

- name: "Validate php-files"
run: "php -l src && php -l tests"

- name: "Composer install"
uses: "ramsey/composer-install@v3"
with:
composer-options: "--prefer-stable"
dependency-versions: 'highest'

- name: "PHP-CS-Fixer"
run: "vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.dist.php --dry-run"

- name: "PHPStan"
run: "vendor/bin/phpstan analyze"

tests:
name: "Tests ${{ matrix.php-version }} ${{ matrix.dependency-versions }}"
runs-on: ubuntu-22.04
needs: lint

strategy:
fail-fast: false
matrix:
# normal, highest, non-dev installs
php-version: ['8.1', '8.2', '8.3', '8.4']
composer-options: ['--prefer-stable']
dependency-versions: ['highest']
include:
# testing lowest PHP version with lowest dependencies
- php-version: '8.1'
dependency-versions: 'lowest'
composer-options: '--prefer-lowest'

steps:
- name: "Checkout code"
uses: "actions/checkout@v4"

- name: "Install PHP"
uses: "shivammathur/setup-php@v2"
with:
coverage: "none"
php-version: "${{ matrix.php-version }}"

- name: "Composer install"
uses: "ramsey/composer-install@v3"
with:
dependency-versions: "${{ matrix.dependency-versions }}"
composer-options: "--prefer-dist --no-progress"

- name: Unit Tests
run: vendor/bin/phpunit
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
.vscode/
vendor/
composer.lock
.phpunit.result.cache
.phpunit.result.cache
.php-cs-fixer.cache
19 changes: 19 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php declare(strict_types=1);

$finder = (new PhpCsFixer\Finder())
->in(__DIR__)
->exclude('vendor')
->exclude('tools')
;

return (new PhpCsFixer\Config())
->setRules([
'@Symfony' => true,
'yoda_style' => false,
'standardize_increment' => false,
'binary_operator_spaces' => [
'default' => 'align_single_space_minimal',
],
])
->setFinder($finder)
;
11 changes: 8 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "Pure PHP library for reading and manipulating Microsoft Outlook .msg messages (MAPI documents)",
"license": "MIT",
"require": {
"php": "^7.1||^8.0",
"php": "^8.1",
"ext-bcmath": "*",
"ext-mbstring": "*",
"pear/ole": "^1.0",
Expand All @@ -13,8 +13,10 @@
},
"require-dev": {
"swiftmailer/swiftmailer": "^6.1",
"phpunit/phpunit": "^8.3",
"pear/pear-core-minimal": "^1.10"
"phpunit/phpunit": "^10.0",
"pear/pear-core-minimal": "^1.10.10",
"friendsofphp/php-cs-fixer": "^3.64",
"phpstan/phpstan": "^2.0"
},
"suggest": {
"swiftmailer/swiftmailer": "Conversion to MIME (eml file) message format"
Expand All @@ -29,5 +31,8 @@
"psr-4": {
"Hfig\\MAPI\\Tests\\": "tests/MAPI"
}
},
"conflict": {
"pear/console_getopt": "<1.4.3"
}
}
5 changes: 5 additions & 0 deletions phpstan.dist.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
parameters:
level: 5
paths:
- src
- tests
9 changes: 8 additions & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
<phpunit bootstrap="vendor/autoload.php">
<phpunit bootstrap="vendor/autoload.php"
displayDetailsOnTestsThatTriggerWarnings="true"
displayDetailsOnTestsThatTriggerErrors="true"
displayDetailsOnTestsThatTriggerDeprecations="true">
<testsuites>
<testsuite name="main">
<directory>tests</directory>
</testsuite>
</testsuites>
<php>
<ini name="display_errors" value="1"/>
<ini name="error_reporting" value="-1"/>
</php>
</phpunit>
72 changes: 35 additions & 37 deletions src/MAPI/Item/Attachment.php
Original file line number Diff line number Diff line change
@@ -1,37 +1,35 @@
<?php

namespace Hfig\MAPI\Item;

abstract class Attachment extends MapiObject
{
protected $embedded_msg = null;
protected $embedded_ole = null;

public function getFilename()
{
return $this->properties['attach_long_filename'] ?? $this->properties['attach_filename'] ?? '';
}

public function getData()
{
return $this->embedded_msg ?? $this->embedded_ole ?? $this->properties['attach_data'] ?? null;
}

public function copyToStream($stream)
{
if ($this->embedded_ole) {
return $this->storeEmbeddedOle($stream);
}
fwrite($stream, $this->getData() ?? '');
}

protected function storeEmbeddedOle($stream): void
{
// this is very untested...
//throw new \RuntimeException('Saving an OLE Compound Document is not supported');

$this->embedded_ole->saveToStream($stream);
}


}
<?php

namespace Hfig\MAPI\Item;

abstract class Attachment extends MapiObject
{
protected $embedded_msg;
protected $embedded_ole;

public function getFilename()
{
return $this->properties['attach_long_filename'] ?? $this->properties['attach_filename'] ?? '';
}

public function getData()
{
return $this->embedded_msg ?? $this->embedded_ole ?? $this->properties['attach_data'] ?? null;
}

public function copyToStream($stream): void
{
if ($this->embedded_ole) {
$this->storeEmbeddedOle($stream);
}
fwrite($stream, $this->getData() ?? '');
}

protected function storeEmbeddedOle($stream): void
{
// this is very untested...
// throw new \RuntimeException('Saving an OLE Compound Document is not supported');

$this->embedded_ole->saveToStream($stream);
}
}
9 changes: 2 additions & 7 deletions src/MAPI/Item/MapiObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,7 @@

class MapiObject
{
protected $properties;

public function __construct($properties)
public function __construct(protected $properties)
{
$this->properties = $properties;
}


}
}
25 changes: 13 additions & 12 deletions src/MAPI/Item/Message.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
<?php

namespace Hfig\MAPI\Item;

//# IMessage essentially, but there's also stuff like IMAPIFolder etc. so, for this to form
//# basis for PST Item, it'd need to be more general.

abstract class Message extends MapiObject
{
abstract public function getAttachments();
abstract public function getRecipients();
}
<?php

namespace Hfig\MAPI\Item;

// # IMessage essentially, but there's also stuff like IMAPIFolder etc. so, for this to form
// # basis for PST Item, it'd need to be more general.

abstract class Message extends MapiObject
{
abstract public function getAttachments();

abstract public function getRecipients();
}
Loading