Commit Graph

554 Commits

Author SHA1 Message Date
Marcus Bointon 1db5c74f76
Use existing function to check for test config 2025-04-09 14:35:24 +02:00
Arnt Gulbrandsen d31cb27117
Adjust eai regex to disallow emoji and letters/numbers.
Update a few tests to match the recent changes.

Use the eai validator (unless another is being used) for addresses such as
info@müller-schmidt.de, for which PHPMailer may not choose to use SMTPUTF8.
2025-04-09 14:13:35 +02:00
Marcus Bointon 29a04c283a
Consistent quotes 2025-04-09 14:13:09 +02:00
Arnt Gulbrandsen e588719eec
Send unencoded UTF8 in subject/body text when SMTPUTF8 allows that. 2025-04-09 14:12:59 +02:00
Arnt Gulbrandsen 2f0af94d33
Set UseSMTPUTF8 fully automatically when needed
This makes SMTPUTF8 support the default when the user chooses to use UTF-8
as charset, without affecting code that uses ISO 8859-1.
2025-04-09 14:12:59 +02:00
Marcus Bointon c6d62ac4af
Comment 2025-04-09 14:12:55 +02:00
Marcus Bointon 7cda202270
Check explicit validation 2025-04-09 14:12:51 +02:00
Marcus Bointon bfd4c3db1a
Choose a validator that should fail 2025-04-09 14:12:45 +02:00
Marcus Bointon 321aeb200d
Typo 2025-04-09 14:12:42 +02:00
Marcus Bointon c1c3b24e9c
Unicode is a proper name 2025-04-09 14:12:35 +02:00
Marcus Bointon 37e54ed3ed
CS 2025-04-09 14:12:08 +02:00
Arnt Gulbrandsen 9278e5774a
Add support for RFC6530, using it only when required.
This adds the ability to send email to addresses like grå@grå.org, but
preserves phpmailer's old behaviour for all addresses that worked before
(such as info@grå.org).
2025-04-09 10:59:48 +02:00
Marcus Bointon cd219181e9
Update test strings after #3148 2025-03-23 21:39:24 +01:00
Marcus Bointon 611235697c
CS 2024-10-21 11:42:14 +02:00
Marcus Bointon 5fc8d634b5
Clarify comment 2024-10-21 11:36:38 +02:00
Marcus Bointon 182f7b9158
Use rfc-editor.org for all docs links 2024-10-15 22:20:47 +02:00
jrfnl 6028776a63
PHPMailerTest::testGivenIdnAddress...(): set test requirements
As per the discussion in 3092, this commit removes the `fakefunctions.php` file and adds explicit requirements for the `PHPMailerTest::testGivenIdnAddress_addAddress_returns_true()` test method.

Closes 3092
2024-09-12 09:11:34 +02:00
jrfnl 78146fb172
DKIMTest::testDKIMSignOpenSSLNotAvailable(): fix the test
As things were, the `DKIMTest::testDKIMSignOpenSSLNotAvailable()` could not pass as the `DKIMTest` class sets the `USE_EXCEPTIONS` class constant to `true`, which means the method would fail on an exception.

As this test is specifically about testing the behaviour when exceptions are _disabled_, the test needs to be in its own test class, which sets `USE_EXCEPTIONS` to `false`.

That should allow the test to run properly and to pass.
2024-09-11 21:05:02 +02:00
jrfnl 10f76cd790
DKIMTest: make exception expectation more specific
As things were, the `DKIMTest::testDKIMSignOpenSSLNotAvailableException()` test _could_ potentially pass even when another `Exception` than the `PHPMailer\PHPMailer\Exception` was being thrown, as _all_ exceptions extend the PHP native `Exception` class.
Now this risk is not that high, as there is also a check on the exception message, but still.

Making the exception expectation more specific (by changing the import `use` statement), should still make the test more stable.
2024-09-11 21:05:02 +02:00
Marcus Bointon 683d3730fc
Restore trailing space 2024-04-01 22:55:32 +02:00
Marcus Bointon 8f98ddf086
Restore trailing space 2024-04-01 22:41:15 +02:00
Marcus Bointon dfa731a087
Check broken links, update for HTTPS everywhere 2024-04-01 20:48:10 +02:00
Marcus Bointon d5615bffb4
Merge pull request #2986 from frankforte/custom-headers
Improvements for `clearCustomHeader` and `replaceCustomerHeader`
2023-11-25 23:02:29 +01:00
Frank Forte 8a91dd64f4 Code formatting for custom header methods. 2023-11-25 13:48:53 -05:00
Frank Forte b0ffd67775 Update replaceCustomerHeader to remove duplicates. Improve clearCustomHeader and relaceCustomHeader to handle name: value. 2023-11-25 12:37:07 -05:00
Marcus Bointon 3104b10d73
Merge pull request #2852 from mta59066/xclient
XCLIENT implementation
2023-11-23 09:12:59 +01:00
Frank Forte 174653aa27 Add methods to update or clear custom headers by name. 2023-11-22 11:35:33 -05:00
Marcus Bointon e88da8d679
Fix test 2023-08-29 10:26:30 +02:00
Marcus Bointon fa59bf6cb1
Don't use setAccessible in PHP >= 8.1 2023-08-23 16:04:36 +02:00
Marcus Bointon 267d4e5793
Avoid deprecation warning in PHP 8.3 2023-08-23 16:04:03 +02:00
Oleg Voronkovich 8bd07461d1 Fix typo in test method name 2023-03-03 18:37:37 +03:00
Oleg Voronkovich 25269b6431 Fix typo: Mailformed -> Malformed 2023-03-03 18:34:19 +03:00
Oleg Voronkovich 7ba61cf0f0 Use DSNConfigurator::mailer() shorcut instead of PHPMailer::fromDSN() 2023-03-03 18:23:59 +03:00
Oleg Voronkovich 1e560e0afd Fix CS 2023-03-03 18:05:12 +03:00
Oleg Voronkovich 067ff6e7c0 Fix CS 2023-02-20 21:58:48 +03:00
Oleg Voronkovich ecc11e3bf5 Add shortcut PHPMailer::fromDSN() 2023-02-20 20:32:16 +03:00
Oleg Voronkovich 10a9c18716 Improve code 2023-02-20 20:09:11 +03:00
Oleg Voronkovich c54e14ebbe Support query string options 2023-02-20 19:51:15 +03:00
Oleg Voronkovich 4ee7bfaf96 Improve tests 2023-02-20 18:46:15 +03:00
Oleg Voronkovich 52aebc52d5 Implement SMTP(s) configuration 2023-02-20 18:28:17 +03:00
Oleg Voronkovich 53442cc3f0 Implement base configuration 2023-02-20 17:47:19 +03:00
Oleg Voronkovich 2fc807cf0c Implment DSN parsing 2023-02-20 17:22:49 +03:00
Mehmet Tolga Avcioglu 08d74eb04b improve xclient 2023-01-06 16:03:08 +03:00
Mehmet Tolga Avcioglu 82dd9a01fb improve xclient 2023-01-06 15:59:03 +03:00
Mehmet Tolga Avcioglu 6384753f6e protected xclient variable and added tests 2023-01-04 14:13:07 +03:00
campbell-m d1abc8d93a Addresses comment of @jrfnl 2022-12-22 21:45:11 +00:00
campbell-m 98a1af8ec7 Adds a test for addrFormat(). 2022-12-22 20:26:23 +00:00
Marcus Bointon f34724c468
CS 2022-12-05 10:02:50 +01:00
Marcus Bointon c033268049
Break out setting MIME boundaries into a protected method, fixes #2511 2022-12-05 10:01:24 +01:00
Marcus Bointon 12e5c0c6f6
Drop MIME preamble to match common email client behaviour, see #1352 2022-12-05 09:24:58 +01:00
Marcus Bointon 3228f11fb4
Don't strip non-break trailing whitespace during simple DKIM canonicalisation, fixes #2837 2022-12-05 08:37:57 +01:00
Czirkos Zoltan c6e066d061 Fix bugs in POP3 test
runfakepopserver.sh expects fakepopserver.sh to be in the working
directory, therefore the tests in PopBeforeSmtpTest have to chdir()
to the test directory first.

The line in fakepopserver.sh echoing Bye needed -en arguments for
echo to process character escapes.
2022-10-26 20:18:42 +02:00
Czirkos Zoltan b4b493c8f3 Avoid POP3 client error message when TCP connection failed
The disconnect() method throws a TypeError when the TCP
connection cannot be created. Error and trace:

fgets(): Argument #1 ($stream) must be of type resource, bool given

phpmailer/phpmailer/src/POP3.php(372): fgets()
phpmailer/phpmailer/src/POP3.php(345): PHPMailer\PHPMailer\POP3->getResponse()
phpmailer/phpmailer/src/POP3.php(230): PHPMailer\PHPMailer\POP3->disconnect()
PHPMailer\PHPMailer\POP3->authorise()

Reproduce with:

include __DIR__ . "/POP3.php";
\PHPMailer\PHPMailer\POP3::popBeforeSmtp('doesnotexist', 110);
2022-10-26 18:41:16 +02:00
Marcus Bointon 91c442fccd
Add failing test for #2786 2022-10-04 11:02:03 +02:00
JT Smith b894719a4c
Fixing auto-formatting 2022-10-03 12:23:05 -06:00
JT Smith ef36a69e0e Typofixes 2022-10-03 12:21:21 -06:00
Marcus Bointon 375d77cef7
CS 2022-06-29 11:10:48 +02:00
Marcus Bointon c4a787bff7
CS 2022-06-29 11:09:55 +02:00
Marcus Bointon a4d8cf15ce
Add tests for #2723 2022-06-29 11:04:13 +02:00
Marcus Bointon bf99c202a9
Avoid passing null to functions, fixes #2667 2022-04-12 10:05:58 +02:00
Marcus Bointon 76b348ebac
Fix test order 2022-03-08 22:39:06 +01:00
Marcus Bointon a3028ab03b
This wasn't actually testing BCC-only addressing! 2022-03-08 22:37:13 +01:00
Marcus Bointon 3525f1b6da
Give up on that test config 2022-02-28 16:03:27 +01:00
Marcus Bointon 70c20c6324
Rearrange tests to deal with version issues 2022-02-28 15:48:25 +01:00
Marcus Bointon 03649a2ffb
CS 2022-02-28 15:11:05 +01:00
Marcus Bointon ec421d0680
CS 2022-02-28 15:09:27 +01:00
Marcus Bointon d8002e5482
Add simple OAuthTokenProvider tests 2022-02-28 15:06:17 +01:00
Marcus Bointon a24029b108
Add corrected @covers tag 2022-02-18 18:21:21 +01:00
Marcus Bointon a876f998bd
Avoid PHPUnit 4.8 issue in PHP 5.5! 2022-02-16 20:03:35 +01:00
Marcus Bointon 6f6ce4f34a
Add XMailer tests 2022-02-16 19:32:38 +01:00
jrfnl d5a5ad19cd CS: minor cleanup
PHPCS 3.6.2 added a sniff for a PSR-12 rule which was previously not strictly checked: "No blank line after the opening brace of a class".

This fixes the newly flagged issues.
2021-12-18 04:08:22 +01:00
Fonata 844c1fc933
Declare object variable $Smtp for PHP 8.2 compatibility
In PHP 8.2 dynamic property are deprecated.
2021-12-08 18:53:21 +01:00
Julien BERNARD 3c81f485df Fix #2563: Provide the right flags to IDN methods for email addresses conversion 2021-11-19 13:19:50 -05: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 99937ed637
Fixes #2470 and #2471 2021-08-18 10:35:47 +02: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
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 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
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
Marcus Bointon d16053c51c
Merge pull request #2440 from jrfnl/feature/parseaddresses-bug-fix-1-missing-extension-check
PHPMailer::parseAddresses(): bug fix [1] - extension availability not checked (consistently)
2021-07-12 21:26:26 +02:00
Ikko Ashimine 4c1adf79f3
EncodeQTest: fix typo
containg -> contains
2021-07-12 23:10:59 +09:00
jrfnl 63da073183 SetTest: add `@covers` tag 2021-07-12 15:24:18 +02:00
jrfnl 8fe8b5634c SetTest::testSetValidProperty(): add additional test case
This commit:
* Adds one extra test case.
* Documents why there is no test case for a `private` property.
2021-07-12 15:24:16 +02:00