diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a1b046f..d586a0b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,85 +11,85 @@ jobs: strategy: fail-fast: false matrix: - php-version: ['7.2', '7.4', '8.0'] + php-version: ['8.0'] prefer-lowest: [''] include: - php-version: '7.2' prefer-lowest: 'prefer-lowest' steps: - - uses: actions/checkout@v2 - with: - fetch-depth: 1 - - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - php-version: ${{ matrix.php-version }} - extensions: mbstring, intl - coverage: pcov - - - name: Get composer cache directory - id: composer-cache - run: echo "::set-output name=dir::$(composer config cache-files-dir)" - - - name: Get date part for cache key - id: key-date - run: echo "::set-output name=date::$(date +'%Y-%m')" - - - name: Cache composer dependencies - uses: actions/cache@v2 - with: - path: ${{ steps.composer-cache.outputs.dir }} - key: ${{ runner.os }}-composer-${{ steps.key-date.outputs.date }}-${{ hashFiles('composer.json') }}-${{ matrix.prefer-lowest }} - - - name: Composer install - run: | - if [[ ${{ matrix.php-version }} == '8.0' ]]; then - composer install --ignore-platform-reqs - elif ${{ matrix.prefer-lowest == 'prefer-lowest' }}; then - composer update --prefer-lowest --prefer-stable - else - composer install - fi - - - name: Run PHPUnit - run: | - if [[ ${{ matrix.php-version }} == '7.4' ]]; then - vendor/bin/phpunit --coverage-clover=coverage.xml - else - vendor/bin/phpunit - fi - - - name: Code Coverage Report - if: success() && matrix.php-version == '7.4' - uses: codecov/codecov-action@v1 + - uses: actions/checkout@v2 + with: + fetch-depth: 1 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-version }} + extensions: mbstring, intl + coverage: pcov + + - name: Get composer cache directory + id: composer-cache + run: echo "::set-output name=dir::$(composer config cache-files-dir)" + + - name: Get date part for cache key + id: key-date + run: echo "::set-output name=date::$(date +'%Y-%m')" + + - name: Cache composer dependencies + uses: actions/cache@v2 + with: + path: ${{ steps.composer-cache.outputs.dir }} + key: ${{ runner.os }}-composer-${{ steps.key-date.outputs.date }}-${{ hashFiles('composer.json') }}-${{ matrix.prefer-lowest }} + + - name: Composer install + run: | + if [[ ${{ matrix.php-version }} == '8.0' ]]; then + composer install --ignore-platform-reqs + elif ${{ matrix.prefer-lowest == 'prefer-lowest' }}; then + composer update --prefer-lowest --prefer-stable + else + composer install + fi + + - name: Run PHPUnit + run: | + if [[ ${{ matrix.php-version }} == '7.4' ]]; then + vendor/bin/phpunit --coverage-clover=coverage.xml + else + vendor/bin/phpunit + fi + + - name: Code Coverage Report + if: success() && matrix.php-version == '7.4' + uses: codecov/codecov-action@v1 validation: name: Coding Standard & Static Analysis runs-on: ubuntu-18.04 steps: - - uses: actions/checkout@v2 - with: - fetch-depth: 1 + - uses: actions/checkout@v2 + with: + fetch-depth: 1 - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - php-version: '7.4' - extensions: mbstring, intl - coverage: none - tools: psalm:~4.1.0 + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: '7.4' + extensions: mbstring, intl + coverage: none + tools: psalm:~4.1.0 - - name: Composer Install - run: composer stan-setup + - name: Composer Install + run: composer stan-setup - - name: Run phpstan - run: composer phpstan + - name: Run phpstan + run: composer phpstan - - name: Run phpcs - run: composer cs-check + - name: Run phpcs + run: composer cs-check # - name: Run psalm - # run: psalm --output-format=github \ No newline at end of file + # run: psalm --output-format=github diff --git a/README.md b/README.md index 261a753..3e2bfa5 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,14 @@ This plugin provides email delivery using [SendGrid](https://sendgrid.com/). -This branch is for use with CakePHP 5.0+. For CakePHP 4, please use cake-4.x branch. +This branch is for use with **CakePHP 5.0+**. For other versions of CakePHP, please use the following version map. + + +| SendGrid Plugin | Branch | CakePHP Core| +| --- | --- | --- | +| 1.x **[EOL]** | [cake-3.x](https://github.com/sprintcube/cakephp-sendgrid/tree/cake-3.x) | 3.4+ | +| 4.x | [cake-4.x](https://github.com/sprintcube/cakephp-sendgrid/tree/cake-4.x) | 4.0+ | +| 5.x (in progress) | [master](https://github.com/sprintcube/cakephp-sendgrid/tree/master) | 5.0+ | ## Requirements @@ -171,7 +178,7 @@ You will need to login to your SendGrid Account and configure your domain and th https://app.sendgrid.com/settings/mail_settings/webhook_settings The return url needs to be set to -* https://YOUR DOMAIN/send-grid/webhook +* https://YOURDOMAIN/send-grid/webhook The CSRF protection middleware needs to allow posts to the webhooks controller in Application.php diff --git a/src/Controller/AppController.php b/src/Controller/AppController.php index 5803c41..cac3c3e 100644 --- a/src/Controller/AppController.php +++ b/src/Controller/AppController.php @@ -1,10 +1,23 @@ request->getBody()->rewind(); $payload = $this->request->getBody()->getContents(); - // Log::debug($payload); + // Log::debug($payload); if (!isset($config['verification_key'])) { if (isset($config['debug']) && $config['debug'] == 'true') { @@ -85,7 +98,7 @@ public function index() $this->viewBuilder()->setOption('serialize', "error"); return; } - + $publicKey = PublicKey::fromString($config['verification_key']); $timestampedPayload = $this->request->getHeaderLine($this::TIMESTAMP) . $payload; @@ -126,5 +139,4 @@ public function index() $this->set('OK', "OK"); $this->viewBuilder()->setOption('serialize', "OK"); } - } diff --git a/src/Mailer/SendGridMailer.php b/src/Mailer/SendGridMailer.php index 14c3830..e33b283 100644 --- a/src/Mailer/SendGridMailer.php +++ b/src/Mailer/SendGridMailer.php @@ -1,4 +1,5 @@ _reqParams['reply_to'] = (object)['email' => key($replyTo), 'name' => $replyTo[key($replyTo)]]; - } else { $this->_reqParams['reply_to'] = (object)['email' => key($replyTo)]; - } + } } $emails = []; @@ -207,6 +206,10 @@ protected function _prepareEmailAddresses(Message $message) ]; } + if (empty($emails['to'])) { + throw new SendGridApiException('Missing to email address.'); + } + foreach ($message->getCc() as $ccEmail => $ccName) { $emails['cc'][] = [ 'email' => $ccEmail,