0
0
mirror of https://github.com/PHPMailer/PHPMailer.git synced 2024-09-20 01:52:15 +02:00
Commit Graph

2019 Commits

Author SHA1 Message Date
Marcus Bointon
ef4081ea99
Line breaks in translations are not supported as of 6.5.0 2021-10-22 15:37:35 +02:00
Blaž Oražem
56051ae53d Fix some more styles 2021-10-11 16:41:36 +02:00
Blaž Oražem
3b01c7675c Fix styles 2021-10-11 16:38:00 +02:00
Blaž Oražem
a7acec2ae7 Slovenian language update 2021-10-11 16:07:16 +02:00
Marcus Bointon
cbfe93b75a
CS 2021-10-04 17:20:23 +02:00
Marcus Bointon
ca09c748ea
Merge pull request #2519 from miken32/master
POP3 cleanup
2021-10-04 17:15:39 +02:00
Michael Newton
c01d14b8be
don't wait for checkResponse result before failing 2021-10-04 08:44:43 -06:00
Michael Newton
dc854c4671
capture server response to QUIT command
and properly set `$connected` property to false
2021-10-04 08:40:32 -06:00
Marcus Bointon
be98d62e36
Merge pull request #2510 from jrfnl/feature/phpunit-update-config
PHPUnit: update configuration
2021-09-26 22:35:36 +02:00
jrfnl
8732627d40 PHPUnit: update configuration
PHPUnit just released version 9.5.10 and 8.5.21.

This contains a particular (IMO breaking) change:

> * PHPUnit no longer converts PHP deprecations to exceptions by default (configure `convertDeprecationsToExceptions="true"` to enable this)

Let's unpack this:

Previously (PHPUnit < 9.5.10/8.5.21), if PHPUnit would encounter a PHP native deprecation notice, it would:
1. Show a test which causes a deprecation notice to be thrown as **"errored"**,
2. Show the **first** deprecation notice it encountered and
3. PHPUnit would exit with a **non-0 exit code** (2), which will fail a CI build.

As of PHPUnit 9.5.10/8.5.21, if PHPUnit encounters a PHP native deprecation notice, it will no longer do so. Instead PHPUnit will:
1. Show a test which causes a PHP deprecation notice to be thrown as **"risky"**,
2. Show the **all** deprecation notices it encountered and
3. PHPUnit will exit with a **0 exit code**, which will show a CI build as passing.

This commit reverts PHPUnit to the previous behaviour by adding `convertDeprecationsToExceptions="true"` to the PHPUnit configuration.

Refs:
* https://github.com/sebastianbergmann/phpunit/blob/9.5/ChangeLog-8.5.md
* https://github.com/sebastianbergmann/phpunit/blob/9.5/ChangeLog-9.5.md
2021-09-25 19:08:59 +02:00
Marcus Bointon
40a12618ea
Garbage removal! 2021-08-29 19:41:57 +02:00
Marcus Bointon
dd803df5ad
Remove invalid default from address (and name)! Fixes #2396 2021-08-18 11:14:16 +02:00
Marcus Bointon
fd06e7614a
Remove wrong tests 2021-08-18 11:05:30 +02:00
Marcus Bointon
c5d0f48730
Not needed 2021-08-18 11:05:17 +02:00
Marcus Bointon
a99b249d42
6.5.1 2021-08-18 10:39:34 +02:00
Marcus Bointon
5d7f077daa
CS 2021-08-18 10:37:43 +02:00
Marcus Bointon
99937ed637
Fixes #2470 and #2471 2021-08-18 10:35:47 +02:00
Marcus Bointon
a4548d7ebe
Merge pull request #2472 from Arisophy/master
Japanese messages
2021-08-17 15:03:33 +02:00
Arisophy
942da89fc2
Update LocalizationTest.php
Restore the leading space.
2021-08-17 20:59:17 +09:00
Arisophy
8de64a0ba1
Update phpmailer.lang-ja.php
Restore the leading space.
2021-08-17 20:56:49 +09:00
Arisophy
ecb661448f
Update phpmailer.lang-ja.php
Add author
2021-08-17 11:43:22 +09:00
Arisophy
3f358ab478
Update LocalizationTest.php
Remove extra whitespace
2021-08-17 11:40:28 +09:00
Arisophy
de0a1e1af6
Update phpmailer.lang-ja.php 2021-08-15 15:43:19 +09:00
Marcus Bointon
620c2a66c5
Merge pull request #2451 from jrfnl/feature/tests-add-tests-html2text
Tests: introduce dedicated tests for the `PHPMailer::html2text()` method
2021-07-16 12:10:14 +02:00
Marcus Bointon
9243b4bb0e
Merge pull request #2452 from jrfnl/feature/2418-improve-and-test-localization
PHPMailer::setLanguage(): various fixes + add tests for localization
2021-07-13 19:39:51 +02:00
jrfnl
5e833628dc Tests: introduce dedicated tests for the PHPMailer::html2text() method
So far, this method did not have dedicated tests.

The test file this commit introduces, tests all aspects of the method as well as documents the current behaviour of the method for specific, outlier situations.
2021-07-13 19:17:45 +02:00
jrfnl
9825cacc20 PHPMailerTest: remove setLanguage() test
... which wasn't actually testing anything at all.
2021-07-13 19:04:27 +02:00
jrfnl
913fb552ab Tests: introduce dedicated tests for text localization
So far, the methods related to text localization - `PHPMailer::setLanguage()`, `PHPMailer::getTranslations()` and `PHPMailer::lang()` - did not have dedicated tests.

The test file this commit introduces, tests all aspects of these methods, including the changes introduced in response to 2418 and 2419, as well as documents the current behaviour of the methods for specific, outlier situations.
2021-07-13 19:04:27 +02:00
jrfnl
4ba13807a4 PHPMailer::setLanguage(): allow for "lang(_script)?(_country)?" codes
Language codes which were "language-script" based were not accepted by the regex used, which meant that the `sr_latn` script could never be loaded.

After discussion in 2418, it was decided to support "script" in a language code and to support it like so:
```
2-character language code [_] optional 4-character script code [_] optional 2-character country code
```

This combines the annotation forms of the following known standards:
* https://unicode-org.github.io/cldr-staging/charts/37/summary/root.html
* https://docs.oracle.com/cd/E23824_01/html/E26033/glset.html
* http://www.loc.gov/standards/iso639-2/php/code_list.php

This means that all of the below codes will now pass the language code validation:
```
sr
sr_latn
sr_rs
sr_latn_rs
```

But not:
```
sr_rs_latn
```

This commit applies the above change and also adjusts the "language code fall back" logic to take language codes with a script code into account.
Note: if the requested full "language-script-country" code is not available, "language-country" will take precedence over "language-script" for the fallback logic to find the appropriate translation file.

Related to 2418 - observation 4
2021-07-13 19:04:27 +02:00
jrfnl
3635e97510 PHPMailer::setLanguage(): fix "lang_country" codes do not fall back to "lang"
When the  `$langCode` is passed as "language code - country code" and no translation is found for the specified country variant, the localization would automatically fall back to English, even when there was a viable translation available in the "parent" language, i.e. just based on the _language code_.

This commit changes the logic in the `PHPMailer::setLanguage()` method for when a "lang-country" code is passed.
It will now try and find a "lang-country" file first, if not found, it will try to find a file for just the "lang" and only if that could also not be found, it will fall back to English.

Related to 2418 - observation 2

Includes using named subpatterns in the regex to make the regex self-documenting.

Includes removing a commented out line of code which is superseded anyway.
2021-07-13 19:04:27 +02:00
jrfnl
aaf18fd5b2 PHPMailer::setLanguage(): match language codes case-insensitively
For "language code - country code" locale notations, it is common for the "country code" part to be provided in uppercase, like `pt_BR`.

The method currently did not allow for that correctly. The regex check would accept the language code, but then fail to find the file on *nix based systems as the file names are all in lowercase and non-Windows file systems are generally case-sensitive. Which means that in effect, the method, ended up falling back to the default language (English).

The change in this commit makes the handling of the provided `$langcode` case-tolerant.

Note: the language code used in the file names for the language files is still expected to always be lowercase, including for language files in custom paths!

Related to 2418 - observation 1
2021-07-13 19:04:27 +02:00
jrfnl
9182613398 PHPMailer::setLanguage(): make return value consistent
The return value of the method was inconsistent as it could return `true` even when the requested language was not loaded/set.

Previously, the method would:
* Return `false` when a `$langcode` was matched against the regex, but the file couldn't be loaded.
* Return `true` in all other cases, including when a `$langcode` other than `'en'` was passed, but it didn't match the regex, which meant that effectively the requested language was ignored and English was loaded anyway, but the function would still return `true`.

This has now been changed to:
* Return `true` when the requested language was loaded, whether `'en'` or another language.
* Return `false` when the requested language wasn't loaded and the language defaulted to English.

Related to https://github.com/PHPMailer/PHPMailer/issues/2418#issuecomment-876240778
2021-07-13 19:04:27 +02:00
Marcus Bointon
5c64f7e2d8
Merge pull request #2449 from jrfnl/feature/parseaddresses-bug-fix-2-mbstring-needs-charset
PHPMailer::parseAddresses(): bug fix [2] - Mbstring encoding
2021-07-13 09:46:07 +02:00
jrfnl
228338fe7e PHPMailer::parseAddresses(): bug fix [2] - Mbstring encoding
The `mb_decode_mimeheader()` function uses the Mbstring internal encoding to decode.

In PHP 5.5, the default internal encoding was `ISO-8859-1`.
As of PHP 5.6, the default internal encoding was changed to use the value from the `default_charset` ini setting. Additionally, in UTF-8, the value for `default_charset` was changed to `UTF-8`.

This means that when the charset is not explicitly set, the `mb_decode_mimeheader()` function may return garbled nonsense if the charset used to _encode_ does not match the charset per PHP's `default_charset` or - in PHP 5.5 - the Mbstring internal_encoding default.

So far, this wasn't making tests fail because of some hard-coded ini settings being passed in the CI.
However, changing the default ini values creates an assumption that that configuration will be used on all servers on which the PHPMailer code will be run.
This assumption is undocumented (not in the Readme or mentioned elsewhere) and will in most cases be incorrect.

The non-default ini values change the behaviour of PHP and were the cause of test failures against PHP 5.5 which I've been seeing for some of the new tests I've been creating.
Removing the changes fixes those errors, but exposes failing tests in the existing tests for `PHPMailer::parseAddresses()`.

These undocumented _changes_ to the default PHP configuration were **required** for PHPMailer to be able to parse the addresses successfully. As this library is open source and used in a wide variety of environments, those kind of assumptions can not safely be made.

So.... the hard-coded ini settings in the CI configuration ought to be removed.

This then causes the tests for the `PHPMailer::parseAddresses()` function to start failing on PHP 5.5.
> Note: the tests are only failing on PHP 5.5 as the test case causing the failure uses a UTF-8 encoded name and as of PHP 5.6, the default encoding used in PHP is UTF-8, which matches.
> If a test case would be added with a name encoded in a different charset, the tests would also start failing on PHP 5.6+.

To fix those failures and to make the code PHP cross-version compatible, including with PHP installs configured to use a different `default_encoding`:
* We need to make sure that the Mbstring "internal encoding" is set correctly based on the Charset used for PHPMailer.
* And then need to _reset_ the internal encoding after the use of the `mb_decode_mimeheader()` to prevent any impact of this change on the wider application context in which PHPMailer may be used.

As the `PHPMailer::parseAddresses()` method is `static`, it does not have access to the (non-static) `PHPMailer::$charSet` variable.
Knowing that, I've elected to add an additional, optional variable to the `PHPMailer::parseAddresses()` method to allow for passing in the charset and have set the default value for the parameter to be in line with the default value of the `PHPMailer::$charSet` variable.

I have adjusted existing method calls to this method to explicitly pass the charset.
Both of the adjusted function calls are in the "postSend" part of the PHPMailer logic when the charset will be known and final, so can be safely passed.

I've also made minimal changes to the unit test file to allow for passing the charset in the tests.

This implementation is based on the assumption that names can be encoded in different charsets.
If the name encoding only happens when the charset is UTF-8, the new function parameter can be removed and the charset can be set to UTF-8 directly.

As I'm not completely read-in on the RFC specs for the address header being parsed and when encoding happens, I'd like a second opinion on the currently chosen implementation.

If this is the correct way to go, then additional tests need to be added to safeguard that things works correctly when a different encoding is used.
If the encoding only happens for UTF-8, the implementation can be simplified.

Update: the current implementation is correct and a `@todo` note has been added to add more tests with different encodings during a next iteration on these tests.

Refs:
* https://www.php.net/manual/en/migration56.deprecated.php#migration56.deprecated.iconv-mbstring-encoding
* https://php-legacy-docs.zend.com/manual/php5/en/ini.core#ini.default-charset
2021-07-13 05:49:19 +02:00
Marcus Bointon
7cc67dd1dc
Merge pull request #2450 from jrfnl/feature/tests-reorganize-33
Tests: move (get|set|clear)ReplyTo tests to own file
2021-07-12 22:35:14 +02:00
jrfnl
2723a83d32 MailTransportTest: remove reply-to addressing testing
As noted in 2380, the addressing tests do not belong in the mail transport tests and as the `ReplyToGetSetClearTest` now covers this extensively, the assertions can be removed from the `MailTransportTest`.
2021-07-12 22:15:24 +02:00
jrfnl
4fa30cd710 ReplyToGetSetClearTest: add new test to verify clearing of reply-tos 2021-07-12 22:15:22 +02:00
jrfnl
35e76a2fa8 ReplyToGetSetClearTest: improve "extensions not available" test
The "fakefunctions" are all nice and dandy to get past the `idnSupported()` check, but if either of these functions is not _really_ available, the actual behaviour of the `PHPMailer::addReplyTo()` function is to _fail_ (on the address validation call in `PHPMailer::addAnAddress()`) and return `false`.

In other words, this test was nonsensical as it tested for something which can, and should, never happen.

With this in mind, the test has been rewritten to reflect the *real* behaviour when either Mbstring or the `idn_to_ascii` function is not available.
2021-07-12 22:15:19 +02:00
jrfnl
535f6338a9 ReplyToGetSetClearTest: improve the test with duplicate IDN addresses
This commit:
* Renames the `testDuplicateIDNRemoved()` method to `testNoDuplicateReplyToAddresses()`.
* Removes the call to `clearReplyTos()` at the start of the function as it is redundant. Each test gets a fresh instance of the PHPMailer class.
* Adds a number of additional assertions to the method to test the enqueuing and duplication removal in more depth.
* Ensures that all assertions are accompanied by a "failure" message so it can more easily be determined which assertion failed (in case of failure).

Includes adding `@covers` tags for the test.
2021-07-12 22:15:17 +02:00
jrfnl
06244ad942 ReplyToGetSetClearTest: improve the conversion and enqueuing test
This commit:
* Renames the `testConvertEncoding()` method to `testEnqueueAndAddIdnAddress()`.
* Removes the call to `clearReplyTos()` at the start of the function as it is redundant. Each test gets a fresh instance of the PHPMailer class.
* Adds a number of additional assertions to the method to test the enqueuing in more depth.

Includes adding `@covers` tags for the test.
2021-07-12 22:15:16 +02:00
jrfnl
465a067017 ReplyToGetSetClearTest::testReplyToInMessageHeader(): add additional test cases
... to test that the header gets set correctly when multiple reply-to addresses have been set, as well as when a reply-to address has been set without a name.
2021-07-12 22:15:08 +02:00
jrfnl
faf8d9fadf ReplyToGetSetClearTest: test the reply-to message header gets set correctly
This commit:
* Renames the `testLowPriority()` method to `testReplyToInMessageHeader()`.
    This test method was originally basically testing two things: the priority and the reply to header being set. For this class, it now just focusses on the reply to header, so letting the name reflect that.
* Enhances the test by actually testing that the reply-to header is correctly found in the fully composed message.
* Breaks out the test case to a data provider to allow for adding additional test cases more easily.
2021-07-12 22:15:07 +02:00
jrfnl
5396226be7 ReplyToGetSetClearTest: add extra setting failure test
... to test that passing an invalid email address in combination with an instance of the `PHPMailer` class which was instantiated with `$exceptions = true` results in an exception.

Includes adding `@covers` tags for this specific method.
2021-07-12 22:15:06 +02:00
jrfnl
e27f649456 ReplyToGetSetClearTest::testAddReplyToInvalidAddressNonIDN(): add additional test case
... which should be handled correctly based on the code.
2021-07-12 22:15:04 +02:00
jrfnl
ce91079a56 ReplyToGetSetClearTest::testAddReplyToValidAddressNonIdn(): add additional test cases
This commit:
* Adds two extra test cases.
* Adds handling to allow the "expected" registered values (and key) being different from the original input values.
2021-07-12 22:15:02 +02:00
jrfnl
6ba19a260f ReplyToGetSetClearTest: test the setting of reply-to address in more depth
This commit:
* Splits the primary tests previously contained in the `testAddressing()` method into two distinct test methods, each using a data provider to allow for adding additional test cases more easily.
* Enhances the tests by not only testing the return value of the `addReplyTo()` method, but also verifying that the `ReplyTo property has been set correctly and contains the expected information.

Includes adding `@covers` tags for these specific methods.
2021-07-12 22:15:01 +02:00
jrfnl
badac1cb8e ReplyToGetSetClearTest: replace testSkipping with @requires 2021-07-12 22:14:59 +02:00
jrfnl
6ab33cf975 ReplyToGetSetClearTest: switch to preSend()
The actual "dequeueing" and adding of `ReplyTo` addresses with IDNs happens within `preSend()`, so this test doesn't actually need to call `send()`.
2021-07-12 22:14:58 +02:00
jrfnl
51ce7d54b3 Tests/reorganize: move (get|set|clear)ReplyTo tests to own file
Note: this doesn't move the complete tests from the original test file, just select parts of the test methods.
2021-07-12 22:14:56 +02:00
Marcus Bointon
f5f7f10e59
Merge pull request #2445 from jrfnl/feature/tests-reorganize-32
Tests: move property setting tests to own file
2021-07-12 21:27:45 +02:00