Compare commits

..

60 commits

Author SHA1 Message Date
Alysson Ribeiro
13e5a7423c
Merge 1fc030afe4 into 6c06c459da 2024-11-11 15:59:50 -05:00
6c06c459da
Update README.md SMTP features and TLS support details
Revised the documentation for greater clarity: swapped the listed items for explicit and implicit SSL/TLS support, and detailed the supported SMTP authentication mechanisms in an itemized format. This ensures users understand all available options and configurations more clearly.
2024-11-11 20:23:42 +01:00
ccc104973e
Merge pull request #363 from wneessen/simplify-license
Remove CC0-1.0 license
2024-11-11 20:19:34 +01:00
935a523fa7
Change license to MIT
Updated SPDX identifiers from CC0-1.0 to MIT across multiple files, including `.github`, `CONTRIBUTING.md`, `README.md`, and more. Deleted the `LICENSES/CC0-1.0.txt` file as it is no longer relevant.
2024-11-11 20:16:09 +01:00
26f1ed3102
Merge pull request #362 from wneessen/fix-spelling
Fix spelling in some tests
2024-11-11 20:12:46 +01:00
29794fd6ad
Fix typo in Content-Disposition header in tests
Corrected multiple instances of the misspelled "Content-Dispositon" to "Content-Disposition" in the msgwriter_test.go file. This ensures that the error messages in the tests are accurate and improve code readability.
2024-11-11 20:08:58 +01:00
c7438a974c
Fix typos: change "non-existant" to "non-existent"
Corrected multiple instances of the word "non-existant" to "non-existent" in test descriptions to improve code clarity and accuracy. This change affects both smtp_test.go and msg_test.go files.
2024-11-11 20:07:55 +01:00
79d4c6fd07
Correct spelling errors in email validation comments
Fixed the spelling of "dot-separated" in comment explanations to ensure clarity. This makes the comments more accurate and easier to understand.
2024-11-11 20:06:47 +01:00
ad86c7ac4f
Correct typo in test name
The test name had a typo in the word "recipient." This commit corrects "recepient" to "recipient" to improve code readability and maintain consistency in naming conventions. This change does not modify any functional behavior of the tests.
2024-11-11 20:06:07 +01:00
580ef5ed48
Merge pull request #361 from wneessen/smtp-client-tests
SMTP client tests overhaul
2024-11-11 19:57:31 +01:00
800c266ccb
Refactor test server code for thread safety
Moved serverProps outside goroutines to improve code readability and maintainability. Added a RWMutex to serverProps to ensure thread-safe access to EchoBuffer, preventing race conditions during concurrent writes.
2024-11-11 19:53:14 +01:00
f7bdd8fffc
Refactor error variable in smtp test
Renamed 'err' to 'berr' to avoid shadowing outer variable. This change ensures clearer error handling and avoids potential issues with variable scope and readability in the smtp_test.go file.
2024-11-11 19:21:50 +01:00
77175a2952
Refactor and relocate JSON logger tests for Go 1.21 compliance
Removed JSON logger tests from smtp_test.go and relocated them to a new file smtp_121_test.go, ensuring compliance with Go 1.21. This change maintains test integrity while organizing tests by Go version compatibility.
2024-11-11 19:15:13 +01:00
08034e6ff8
Refactor echoBuffer parameter handling in tests
Removed redundant mutex and streamlined anonymous goroutine syntax for test server setup by passing echoBuffer directly as a parameter. This change reduces unnecessary use of shared resources and simplifies the test code structure and fixes potential race conditions
2024-11-11 18:58:31 +01:00
2156fbc01e
Add mutex lock to handle concurrent SMTP test server connections
Introduced a mutex to the SMTP test server properties to ensure thread-safe access when handling connections. This prevents race conditions and improves the reliability of the test server under concurrent load.
2024-11-11 18:51:14 +01:00
61353d51e5
Fix variable declarations in test cases
Changed variable declarations from '=' to ':=' to properly handle errors within the SMTP test cases. This ensures that errors are correctly captured and reported when writing to the EchoBuffer.
2024-11-11 18:43:48 +01:00
1d19290e1c
Merge branch 'main' into smtp-client-tests 2024-11-11 18:36:00 +01:00
7da30e09e1
Refactor smtp tests to improve clarity and error handling
Removed unused variables and improved error handling in smtp_test.go. Adjusted to capture only error in auth.Next() calls, ensuring accurate validation. Added necessary error checks after creating new client connections to prevent test failures.
2024-11-11 18:35:10 +01:00
c58aa35454
Add tests for Client debug logging behavior
Introduce unit tests to verify the behavior of the debug logging in the Client. Confirm that logs are correctly produced when debug mode is enabled and appropriately suppressed when it is disabled.
2024-11-11 18:25:39 +01:00
3b9085e19d
Add tests for GetTLSConnectionState method in SMTP client
This commit introduces four test cases for the GetTLSConnectionState method. These tests cover scenarios with a valid TLS connection, no connection, a non-TLS connection, and a non-TLS connection with the TLS flag set on the client. This ensures comprehensive validation of the method's behavior across different states.
2024-11-11 18:17:36 +01:00
007d214c68
Add comprehensive tests for SMTP client functionality
Introduce new tests to verify behaviors of client methods including SetLogAuthData, SetDSNRcptNotifyOption, SetDSNMailReturnOption, HasConnection, and UpdateDeadline. Ensure these tests cover various scenarios such as successful operations, edge cases, and failure conditions.
2024-11-11 18:08:56 +01:00
8fbd94a675
Add nil check in UpdateDeadline method
Ensure that the connection is not nil before setting the deadline in the UpdateDeadline method. This prevents a potential runtime panic when attempting to set a deadline on a nil connection.
2024-11-11 18:07:31 +01:00
5e3d14f842
Add tests for Client's SetLogger method
This commit introduces unit tests for the Client's SetLogger method. It verifies the correct logger type is set and ensures setting a nil logger does not override an existing logger.
2024-11-11 17:49:07 +01:00
9412f31874
Lock mutex when setting the logger
Add mutex locking to ensure thread-safety when setting the logger in the `smtp` package. This prevents potential race conditions and ensures that the logger is updated consistently in concurrent operations.
2024-11-11 17:47:59 +01:00
59f2778a38
Add tests for Client's SetDebugLog method
These tests verify the behavior of the SetDebugLog method in various scenarios such as enabling and disabling debug logging and ensuring the logger type is as expected. This improves the robustness and reliability of the debug logging functionality in the Client class.
2024-11-11 17:44:31 +01:00
2cc670659e
Remove obsolete SMTP client tests
Deleted multiple outdated and redundant tests from the SMTP client test suite to streamline and improve the maintainability of the test codebase. This change focuses on removing tests that are no longer relevant or have been superseded by other methods.
2024-11-11 17:36:24 +01:00
2d384a7d37
Add unit tests for SMTP client extensions, reset, and noop
Introduced new unit tests to verify the SMTP client's behavior with extensions, reset, and noop commands under various server conditions. Updated server response handling to correctly manage feature sets when they are empty.
2024-11-11 17:29:43 +01:00
1bfec504ed
Add new SMTP test cases for various failure scenarios
This commit introduces multiple test cases to handle SMTP failure scenarios such as invalid host, newline in addresses, EHLO/HELO failures, and malformed data injections. Additionally, it includes improvements in error handling for these specific conditions.
2024-11-11 17:12:15 +01:00
87accd289e
Fix formatting in smtp_test.go and add new test cases
Corrected indentation inconsistencies in the smtp_test.go file. Added multiple test cases to verify the failure scenarios for `SendMail` under various conditions including invalid hostnames, newlines in the address fields, and server failures during EHLO/HELO, STARTTLS, and authentication stages.
2024-11-11 16:41:44 +01:00
de3493ee9c
Merge pull request #360 from wneessen/dependabot/github_actions/github/codeql-action-3.27.1
Bump github/codeql-action from 3.27.0 to 3.27.1
2024-11-11 16:09:11 +01:00
dependabot[bot]
5d977e7206
Bump github/codeql-action from 3.27.0 to 3.27.1
Bumps [github/codeql-action](https://github.com/github/codeql-action) from 3.27.0 to 3.27.1.
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](662472033e...4f3212b617)

---
updated-dependencies:
- dependency-name: github/codeql-action
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-11-11 13:21:05 +00:00
c6da393676
Add echo buffer to SMTP server tests
Refactored SMTP server tests to use an echo buffer for capturing responses. This allows for better validation of command responses without relying on error messages. Additionally, added a new test case to validate a full SendMail transaction with TLS and authentication.
2024-11-11 13:31:25 +01:00
c3252626e3
Reverted change made in 3fffcd15f6 2024-11-11 13:31:02 +01:00
3fffcd15f6
Remove deprecated test hook for STARTTLS
The testHookStartTLS variable and its related conditional code have been removed from the smtp.go file. This cleanup streamlines the TLS initiation process and removes unnecessary test-specific hooks no longer in use.
2024-11-11 12:54:39 +01:00
e9c7bdbb4e
Refactor TLS config initialization in tests
Replace repetitive TLS configuration code with a reusable `getTLSConfig` helper function for consistency and maintainability. Additionally, update port configuration and add new tests for mail data transmission.
2024-11-11 12:54:10 +01:00
75bfdd2855
Update smtp tests to use t.Fatalf for critical failures
Changed `t.Errorf` to `t.Fatalf` in multiple instances within the test cases. This ensures that the tests halt immediately upon a critical failure, improving test reliability and debugging clarity.
2024-11-11 12:28:52 +01:00
d446b491e2
Add client cleanup to SMTP tests and new TestClient_Rcpt
Update SMTP tests to use t.Cleanup for client cleanup to ensure proper resource release. Introduce a new test, TestClient_Rcpt, to verify recipient address handling under various conditions.
2024-11-10 14:31:18 +01:00
0d8d097ae1
Add tests for DSN, 8BITMIME, and SMTPUTF8 support in SMTP
Introduce new test cases to verify the SMTP server's ability to handle DSN, 8BITMIME, and SMTPUTF8 features. These tests ensure correct response behavior when these features are supported by the server.
2024-11-10 14:10:50 +01:00
0df228178a
Add extensive client tests for Mail, Verify, and Auth commands
Introduce new tests for the SMTP client covering scenarios for Mail, Verify, and Auth commands to ensure correct behavior under various conditions. Updated `simpleSMTPServer` implementation to handle more cases including VRFY and SMTPUTF8.
2024-11-10 14:06:05 +01:00
b7ffce62aa
Add TLS connection state tests for SMTP client
Introduce tests to verify TLS connection state handling in the SMTP client. Ensure that normal TLS connections return a valid state, and non-TLS connections do not wrongly indicate a TLS state.
2024-11-09 15:22:23 +01:00
8f28babc47
Add tests for Client StartTLS functionality
Introduce new tests to cover the Client's behavior when initiating a STARTTLS session under different conditions: normal operation, failure on EHLO/HELO, and a server not supporting STARTTLS. This ensures robustness in handling STARTTLS interactions.
2024-11-09 14:58:23 +01:00
50505e1339
Add test for Client cmd failure on textproto command
This commit introduces a new test case for the `Client`'s `cmd` method to ensure it fails correctly when the `textproto` command encounters a broken writer. It also adds a `failWriter` struct that simulates a write failure to facilitate this testing scenario.
2024-11-09 14:26:44 +01:00
af7964450a
Add test cases for invalid HELO/EHLO commands
Add tests to ensure HELO/EHLO commands fail with empty name, newline in name, and double execution. This improves validation and robustness of the SMTP client implementation.
2024-11-09 14:01:02 +01:00
cefaa0d4ee
Refactor SMTP test cases for improved clarity and coverage
Consolidate and organize SMTP test cases by removing obsolete tests and adding focused, detailed tests for CRAM-MD5 and new client behaviors. This ensures clearer test structure and better coverage of edge cases.
2024-11-09 13:44:14 +01:00
92ab51b13d
Add comprehensive tests for scramAuth error handling
Introduce new test cases to validate the error handling of the scramAuth methods. These tests cover scenarios such as invalid characters in usernames, empty inputs, and edge cases like broken rand.Reader.
2024-11-09 00:06:33 +01:00
c6d416f142
Fix typo in the tls-unique channel binding comment
Corrected "crypto/tl" to "crypto/tls" in the comment for better clarity and accuracy. This typo fix ensures that the code comments correctly reference the relevant Go package.
2024-11-08 23:05:31 +01:00
a1efa1a1ca
Remove redundant empty string check in SCRAM normalization
The existing check for an empty normalized string is unnecessary because the OpaqueString profile in precis already throws an error if an empty string is returned: https://cs.opensource.google/go/x/text/+/master:secure/precis/profiles.go;l=66
2024-11-08 22:44:10 +01:00
d6f256c29e
Fix typo in error message in normalizeString function
Corrected the spelling of "failed" in the error handling branch of the normalizeString function within smtp/auth_scram.go. This change addresses a minor typographical error to ensure the error message is clear and accurate.
2024-11-08 22:30:46 +01:00
d4c6cb506c
Add SCRAM authentication tests to smtp package
Added comprehensive unit tests for SCRAM-SHA-1, SCRAM-SHA-256, and their PLUS variants. Implemented a test server to simulate various SCRAM authentication scenarios and validate both success and failure cases.
2024-11-08 16:53:09 +01:00
c656226fd3
Add XOAuth2 authentication tests to SMTP package
Introduces two tests for XOAuth2 authentication in the SMTP package. The first test ensures successful authentication with valid credentials, while the second test verifies that authentication fails with incorrect settings.
2024-11-08 15:51:17 +01:00
1af17f14e1
Add cleanup to close client connections in tests
This commit enhances the cleanup process in the SMTP tests by adding t.Cleanup to close client connections. Additionally, it rewrites the TestXOAuth2 function to include more detailed sub-tests, enhancing test granularity and readability.
2024-11-08 15:11:47 +01:00
7b8a24f34a
Merge branch 'main' into smtp-client-tests 2024-11-08 14:42:58 +01:00
b03fbb4ae8
Add test server for SMTP authentication
Added a simple SMTP test server with basic features like PLAIN, LOGIN, and NOENC authentication. It can start, handle connections, and simulate authentication success or failure. Included support for TLS with a generated localhost certificate.
2024-11-07 22:42:23 +01:00
4221d48644
Update login authentication test cases in smtp_test.go
Renamed the test functions and improved the test structure for login authentication checks. Added subtests to provide clear descriptions and enhance error checking.
2024-11-07 21:31:24 +01:00
410343496c
Refactor and expand TestLoginAuth
Rename and uncomment TestLoginAuth with more test cases, ensuring coverage for successful and failed authentication scenarios, including checks for unencrypted logins and server response errors. This improves test robustness and coverage.
2024-11-07 21:14:52 +01:00
2391010e3a
Rename parameter for consistency in auth functions
Updated the parameter name `allowUnEnc` to `allowUnenc` in both `LoginAuth` and `PlainAuth` functions to maintain consistent naming conventions. This change improves code readability and follows standard naming practices.
2024-11-07 20:58:20 +01:00
e42b022076
Merge branch 'main' into smtp-client-tests 2024-11-07 20:50:59 +01:00
3cfd20576d
Rename and expand TestPlainAuth_noEnc with additional checks
Refactor the test function `TestPlainAuth_noEnc` to include subtests for better organization and add more comprehensive error handling. This improves clarity and robustness by verifying various authentication scenarios and expected outcomes.
2024-11-03 16:13:54 +01:00
99c4378107
Refactor and streamline authentication tests
Improved the structure and readability of the authentication tests by using subtests for each scenario, ensuring better isolation and clearer failure reporting. Removed unnecessary imports and redundant code, reducing complexity and enhancing maintainability.
2024-11-01 19:22:28 +01:00
a3fe2f88d5
Add test for MessageID on nil SendError
This test ensures that when MessageID is called on a nil SendError, it returns an empty string. This additional check helps verify the correct behavior of the MessageID method under nil conditions.
2024-11-01 18:47:21 +01:00
25 changed files with 3774 additions and 2318 deletions

2
.github/FUNDING.yml vendored
View file

@ -1,6 +1,6 @@
# SPDX-FileCopyrightText: 2022 Winni Neessen <winni@neessen.dev>
#
# SPDX-License-Identifier: CC0-1.0
# SPDX-License-Identifier: MIT
github: wneessen
ko_fi: winni

View file

@ -1,6 +1,6 @@
# SPDX-FileCopyrightText: 2022 Winni Neessen <winni@neessen.dev>
#
# SPDX-License-Identifier: CC0-1.0
# SPDX-License-Identifier: MIT
name: Bug Report
description: Create a report to help us improve

View file

@ -1,6 +1,6 @@
# SPDX-FileCopyrightText: 2022 Winni Neessen <winni@neessen.dev>
#
# SPDX-License-Identifier: CC0-1.0
# SPDX-License-Identifier: MIT
blank_issues_enabled: false
contact_links:

View file

@ -1,6 +1,6 @@
# SPDX-FileCopyrightText: 2022 Winni Neessen <winni@neessen.dev>
#
# SPDX-License-Identifier: CC0-1.0
# SPDX-License-Identifier: MIT
name: Feature request
description: Suggest an idea for this project

View file

@ -1,6 +1,6 @@
# SPDX-FileCopyrightText: 2022-2023 The go-mail Authors
#
# SPDX-License-Identifier: CC0-1.0
# SPDX-License-Identifier: MIT
version: 2
updates:

View file

@ -1,6 +1,6 @@
# SPDX-FileCopyrightText: 2022 Winni Neessen <winni@neessen.dev>
#
# SPDX-License-Identifier: CC0-1.0
# SPDX-License-Identifier: MIT
# For most projects, this workflow file will not need changing; you simply need
# to commit it to your repository.
@ -54,7 +54,7 @@ jobs:
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@662472033e021d55d94146f66f6058822b0b39fd # v3.27.0
uses: github/codeql-action/init@4f3212b61783c3c68e8309a0f18a699764811cda # v3.27.1
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
@ -65,7 +65,7 @@ jobs:
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@662472033e021d55d94146f66f6058822b0b39fd # v3.27.0
uses: github/codeql-action/autobuild@4f3212b61783c3c68e8309a0f18a699764811cda # v3.27.1
# Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl
@ -79,4 +79,4 @@ jobs:
# make release
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@662472033e021d55d94146f66f6058822b0b39fd # v3.27.0
uses: github/codeql-action/analyze@4f3212b61783c3c68e8309a0f18a699764811cda # v3.27.1

View file

@ -1,6 +1,6 @@
# SPDX-FileCopyrightText: 2022-2023 The go-mail Authors
#
# SPDX-License-Identifier: CC0-1.0
# SPDX-License-Identifier: MIT
# This workflow uses actions that are not certified by GitHub. They are provided
# by a third-party and are governed by separate terms of service, privacy
@ -75,6 +75,6 @@ jobs:
# Upload the results to GitHub's code scanning dashboard.
- name: "Upload to code-scanning"
uses: github/codeql-action/upload-sarif@662472033e021d55d94146f66f6058822b0b39fd # v3.27.0
uses: github/codeql-action/upload-sarif@4f3212b61783c3c68e8309a0f18a699764811cda # v3.27.1
with:
sarif_file: results.sarif

2
.gitignore vendored
View file

@ -1,6 +1,6 @@
# SPDX-FileCopyrightText: 2022 Winni Neessen <winni@neessen.dev>
#
# SPDX-License-Identifier: CC0-1.0
# SPDX-License-Identifier: MIT
# Binaries for programs and plugins
*.exe

View file

@ -1,7 +1,7 @@
<!--
SPDX-FileCopyrightText: 2022 Winni Neessen <winni@neessen.dev>
SPDX-License-Identifier: CC0-1.0
SPDX-License-Identifier: MIT
-->
# Contributor Covenant Code of Conduct

View file

@ -1,7 +1,7 @@
<!--
SPDX-FileCopyrightText: 2022-2023 The go-mail Authors
SPDX-License-Identifier: CC0-1.0
SPDX-License-Identifier: MIT
-->
# How to contribute

View file

@ -1,121 +0,0 @@
Creative Commons Legal Code
CC0 1.0 Universal
CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE
LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN
ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS
INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES
REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS
PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM
THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED
HEREUNDER.
Statement of Purpose
The laws of most jurisdictions throughout the world automatically confer
exclusive Copyright and Related Rights (defined below) upon the creator
and subsequent owner(s) (each and all, an "owner") of an original work of
authorship and/or a database (each, a "Work").
Certain owners wish to permanently relinquish those rights to a Work for
the purpose of contributing to a commons of creative, cultural and
scientific works ("Commons") that the public can reliably and without fear
of later claims of infringement build upon, modify, incorporate in other
works, reuse and redistribute as freely as possible in any form whatsoever
and for any purposes, including without limitation commercial purposes.
These owners may contribute to the Commons to promote the ideal of a free
culture and the further production of creative, cultural and scientific
works, or to gain reputation or greater distribution for their Work in
part through the use and efforts of others.
For these and/or other purposes and motivations, and without any
expectation of additional consideration or compensation, the person
associating CC0 with a Work (the "Affirmer"), to the extent that he or she
is an owner of Copyright and Related Rights in the Work, voluntarily
elects to apply CC0 to the Work and publicly distribute the Work under its
terms, with knowledge of his or her Copyright and Related Rights in the
Work and the meaning and intended legal effect of CC0 on those rights.
1. Copyright and Related Rights. A Work made available under CC0 may be
protected by copyright and related or neighboring rights ("Copyright and
Related Rights"). Copyright and Related Rights include, but are not
limited to, the following:
i. the right to reproduce, adapt, distribute, perform, display,
communicate, and translate a Work;
ii. moral rights retained by the original author(s) and/or performer(s);
iii. publicity and privacy rights pertaining to a person's image or
likeness depicted in a Work;
iv. rights protecting against unfair competition in regards to a Work,
subject to the limitations in paragraph 4(a), below;
v. rights protecting the extraction, dissemination, use and reuse of data
in a Work;
vi. database rights (such as those arising under Directive 96/9/EC of the
European Parliament and of the Council of 11 March 1996 on the legal
protection of databases, and under any national implementation
thereof, including any amended or successor version of such
directive); and
vii. other similar, equivalent or corresponding rights throughout the
world based on applicable law or treaty, and any national
implementations thereof.
2. Waiver. To the greatest extent permitted by, but not in contravention
of, applicable law, Affirmer hereby overtly, fully, permanently,
irrevocably and unconditionally waives, abandons, and surrenders all of
Affirmer's Copyright and Related Rights and associated claims and causes
of action, whether now known or unknown (including existing as well as
future claims and causes of action), in the Work (i) in all territories
worldwide, (ii) for the maximum duration provided by applicable law or
treaty (including future time extensions), (iii) in any current or future
medium and for any number of copies, and (iv) for any purpose whatsoever,
including without limitation commercial, advertising or promotional
purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each
member of the public at large and to the detriment of Affirmer's heirs and
successors, fully intending that such Waiver shall not be subject to
revocation, rescission, cancellation, termination, or any other legal or
equitable action to disrupt the quiet enjoyment of the Work by the public
as contemplated by Affirmer's express Statement of Purpose.
3. Public License Fallback. Should any part of the Waiver for any reason
be judged legally invalid or ineffective under applicable law, then the
Waiver shall be preserved to the maximum extent permitted taking into
account Affirmer's express Statement of Purpose. In addition, to the
extent the Waiver is so judged Affirmer hereby grants to each affected
person a royalty-free, non transferable, non sublicensable, non exclusive,
irrevocable and unconditional license to exercise Affirmer's Copyright and
Related Rights in the Work (i) in all territories worldwide, (ii) for the
maximum duration provided by applicable law or treaty (including future
time extensions), (iii) in any current or future medium and for any number
of copies, and (iv) for any purpose whatsoever, including without
limitation commercial, advertising or promotional purposes (the
"License"). The License shall be deemed effective as of the date CC0 was
applied by Affirmer to the Work. Should any part of the License for any
reason be judged legally invalid or ineffective under applicable law, such
partial invalidity or ineffectiveness shall not invalidate the remainder
of the License, and in such case Affirmer hereby affirms that he or she
will not (i) exercise any of his or her remaining Copyright and Related
Rights in the Work or (ii) assert any associated claims and causes of
action with respect to the Work, in either case contrary to Affirmer's
express Statement of Purpose.
4. Limitations and Disclaimers.
a. No trademark or patent rights held by Affirmer are waived, abandoned,
surrendered, licensed or otherwise affected by this document.
b. Affirmer offers the Work as-is and makes no representations or
warranties of any kind concerning the Work, express, implied,
statutory or otherwise, including without limitation warranties of
title, merchantability, fitness for a particular purpose, non
infringement, or the absence of latent or other defects, accuracy, or
the present or absence of errors, whether or not discoverable, all to
the greatest extent permissible under applicable law.
c. Affirmer disclaims responsibility for clearing rights of other persons
that may apply to the Work or any use thereof, including without
limitation any person's Copyright and Related Rights in the Work.
Further, Affirmer disclaims responsibility for obtaining any necessary
consents, permissions or other rights required for any use of the
Work.
d. Affirmer understands and acknowledges that Creative Commons is not a
party to this document and has no duty or obligation with respect to
this CC0 or use of the Work.

View file

@ -1,7 +1,7 @@
<!--
SPDX-FileCopyrightText: 2022-2023 The go-mail Authors
SPDX-License-Identifier: CC0-1.0
SPDX-License-Identifier: MIT
-->
# go-mail - Easy to use, yet comprehensive library for sending mails with Go
@ -39,10 +39,16 @@ Here are some highlights of go-mail's featureset:
* [X] Very small dependency footprint (mainly Go Stdlib and Go extended packages)
* [X] Modern, idiomatic Go
* [X] Sane and secure defaults
* [X] Explicit SSL/TLS support
* [X] Implicit StartTLS support with different policies
* [X] Implicit SSL/TLS support
* [X] Explicit STARTTLS support with different policies
* [X] Makes use of contexts for a better control flow and timeout/cancelation handling
* [X] SMTP Auth support (LOGIN, PLAIN, CRAM-MD, XOAUTH2, SCRAM-SHA-1(-PLUS), SCRAM-SHA-256(-PLUS))
* [X] SMTP Auth support
* [X] CRAM-MD5
* [X] LOGIN
* [X] PLAIN
* [X] SCRAM-SHA-1/SCRAM-SHA-1-PLUS
* [X] SCRAM-SHA-256/SCRAM-SHA-256-PLUS
* [X] XOAUTH2
* [X] RFC5322 compliant mail address validation
* [X] Support for common mail header field generation (Message-ID, Date, Bulk-Precedence, Priority, etc.)
* [X] Concurrency-safe reusing the same SMTP connection to send multiple mails

View file

@ -1,7 +1,7 @@
<!--
SPDX-FileCopyrightText: 2022-2023 The go-mail Authors
SPDX-License-Identifier: CC0-1.0
SPDX-License-Identifier: MIT
-->
# Security Policy

View file

@ -2803,7 +2803,7 @@ func TestClient_sendSingleMsg(t *testing.T) {
t.Errorf("expected ErrGetSender, got %s", sendErr.Reason)
}
})
t.Run("fail with no recepient addresses", func(t *testing.T) {
t.Run("fail with no recipient addresses", func(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
PortAdder.Add(1)

View file

@ -1,19 +1,19 @@
# SPDX-FileCopyrightText: 2022-2023 The go-mail Authors
#
# SPDX-License-Identifier: CC0-1.0
# SPDX-License-Identifier: MIT
coverage:
status:
project:
default:
target: 90%
target: 95%
threshold: 2%
base: auto
if_ci_failed: error
only_pulls: false
patch:
default:
target: 90%
target: 95%
base: auto
if_ci_failed: error
threshold: 2%

View file

@ -126,8 +126,8 @@ var (
{`" "@domain.tld`, true}, // Still valid, since quoted
{`"<\"@\".!#%$@domain.tld"`, false}, // Quoting with illegal characters is not allowed
{`<\"@\\".!#%$@domain.tld`, false}, // Still a bunch of random illegal characters
{`hi"@"there@domain.tld`, false}, // Quotes must be dot-seperated
{`"<\"@\\".!.#%$@domain.tld`, false}, // Quote is escaped and dot-seperated which would be RFC822 compliant, but not RFC5322 compliant
{`hi"@"there@domain.tld`, false}, // Quotes must be dot-separated
{`"<\"@\\".!.#%$@domain.tld`, false}, // Quote is escaped and dot-separated which would be RFC822 compliant, but not RFC5322 compliant
{`hi\ there@domain.tld`, false}, // Spaces must be quoted
{"hello@tld", true}, // TLD is enough
{`你好@域名.顶级域名`, true}, // We speak RFC6532
@ -4527,12 +4527,12 @@ func TestMsg_AttachFile(t *testing.T) {
t.Errorf("expected message body to be %s, got: %s", "This is a test attachment", got)
}
})
t.Run("AttachFile with non-existant file", func(t *testing.T) {
t.Run("AttachFile with non-existent file", func(t *testing.T) {
message := NewMsg()
if message == nil {
t.Fatal("message is nil")
}
message.AttachFile("testdata/non-existant-file.txt")
message.AttachFile("testdata/non-existent-file.txt")
attachments := message.GetAttachments()
if len(attachments) != 0 {
t.Fatalf("failed to retrieve attachments list")
@ -4997,12 +4997,12 @@ func TestMsg_EmbedFile(t *testing.T) {
t.Errorf("expected message body to be %s, got: %s", "This is a test embed", got)
}
})
t.Run("EmbedFile with non-existant file", func(t *testing.T) {
t.Run("EmbedFile with non-existent file", func(t *testing.T) {
message := NewMsg()
if message == nil {
t.Fatal("message is nil")
}
message.EmbedFile("testdata/non-existant-file.txt")
message.EmbedFile("testdata/non-existent-file.txt")
embeds := message.GetEmbeds()
if len(embeds) != 0 {
t.Fatalf("failed to retrieve attachments list")

View file

@ -324,7 +324,7 @@ func TestMsgWriter_addFiles(t *testing.T) {
}
}
if !strings.Contains(buffer.String(), `Content-Disposition: attachment; filename="attachment.txt"`) {
t.Errorf("Content-Dispositon header not found for attachment. Mail: %s", buffer.String())
t.Errorf("Content-Disposition header not found for attachment. Mail: %s", buffer.String())
}
switch runtime.GOOS {
case "freebsd":
@ -357,7 +357,7 @@ func TestMsgWriter_addFiles(t *testing.T) {
}
}
if !strings.Contains(buffer.String(), `Content-Disposition: attachment; filename="attachment"`) {
t.Errorf("Content-Dispositon header not found for attachment. Mail: %s", buffer.String())
t.Errorf("Content-Disposition header not found for attachment. Mail: %s", buffer.String())
}
if !strings.Contains(buffer.String(), `Content-Type: application/octet-stream; name="attachment"`) {
t.Errorf("Content-Type header not found for attachment. Mail: %s", buffer.String())
@ -383,7 +383,7 @@ func TestMsgWriter_addFiles(t *testing.T) {
}
}
if !strings.Contains(buffer.String(), `Content-Disposition: attachment; filename="attachment.txt"`) {
t.Errorf("Content-Dispositon header not found for attachment. Mail: %s", buffer.String())
t.Errorf("Content-Disposition header not found for attachment. Mail: %s", buffer.String())
}
if !strings.Contains(buffer.String(), `Content-Type: application/octet-stream; name="attachment.txt"`) {
t.Errorf("Content-Type header not found for attachment. Mail: %s", buffer.String())
@ -402,7 +402,7 @@ func TestMsgWriter_addFiles(t *testing.T) {
t.Errorf("attachment not found in mail message. Mail: %s", buffer.String())
}
if !strings.Contains(buffer.String(), `Content-Disposition: attachment; filename="attachment.txt"`) {
t.Errorf("Content-Dispositon header not found for attachment. Mail: %s", buffer.String())
t.Errorf("Content-Disposition header not found for attachment. Mail: %s", buffer.String())
}
switch runtime.GOOS {
case "freebsd":
@ -438,7 +438,7 @@ func TestMsgWriter_addFiles(t *testing.T) {
}
}
if !strings.Contains(buffer.String(), `Content-Disposition: attachment; filename="attachment.txt"`) {
t.Errorf("Content-Dispositon header not found for attachment. Mail: %s", buffer.String())
t.Errorf("Content-Disposition header not found for attachment. Mail: %s", buffer.String())
}
switch runtime.GOOS {
case "freebsd":
@ -478,7 +478,7 @@ func TestMsgWriter_addFiles(t *testing.T) {
}
}
if !strings.Contains(buffer.String(), `Content-Disposition: attachment; filename="attachment.txt"`) {
t.Errorf("Content-Dispositon header not found for attachment. Mail: %s", buffer.String())
t.Errorf("Content-Disposition header not found for attachment. Mail: %s", buffer.String())
}
switch runtime.GOOS {
case "freebsd":

View file

@ -174,6 +174,12 @@ func TestSendError_MessageID(t *testing.T) {
t.Errorf("sendError expected empty message-id, got: %s", sendErr.MessageID())
}
})
t.Run("TestSendError_MessageID on nil error should return empty", func(t *testing.T) {
var sendErr *SendError
if sendErr.MessageID() != "" {
t.Error("expected empty message-id on nil-senderror")
}
})
}
func TestSendError_Msg(t *testing.T) {

View file

@ -36,8 +36,8 @@ type loginAuth struct {
// LoginAuth will only send the credentials if the connection is using TLS
// or is connected to localhost. Otherwise authentication will fail with an
// error, without sending the credentials.
func LoginAuth(username, password, host string, allowUnEnc bool) Auth {
return &loginAuth{username, password, host, 0, allowUnEnc}
func LoginAuth(username, password, host string, allowUnenc bool) Auth {
return &loginAuth{username, password, host, 0, allowUnenc}
}
// Start begins the SMTP authentication process by validating server's TLS status and hostname.

View file

@ -28,8 +28,8 @@ type plainAuth struct {
// PlainAuth will only send the credentials if the connection is using TLS
// or is connected to localhost. Otherwise authentication will fail with an
// error, without sending the credentials.
func PlainAuth(identity, username, password, host string, allowUnEnc bool) Auth {
return &plainAuth{identity, username, password, host, allowUnEnc}
func PlainAuth(identity, username, password, host string, allowUnenc bool) Auth {
return &plainAuth{identity, username, password, host, allowUnenc}
}
func (a *plainAuth) Start(server *ServerInfo) (string, []byte, error) {

View file

@ -154,7 +154,7 @@ func (a *scramAuth) initialClientMessage() ([]byte, error) {
connState := a.tlsConnState
bindData := connState.TLSUnique
// crypto/tl: no tls-unique channel binding value for this tls connection, possibly due to missing
// crypto/tls: no tls-unique channel binding value for this tls connection, possibly due to missing
// extended master key support and/or resumed connection
// RFC9266:122 tls-unique not defined for tls 1.3 and later
if bindData == nil || connState.Version >= tls.VersionTLS13 {
@ -308,10 +308,7 @@ func (a *scramAuth) normalizeUsername() (string, error) {
func (a *scramAuth) normalizeString(s string) (string, error) {
s, err := precis.OpaqueString.String(s)
if err != nil {
return "", fmt.Errorf("failled to normalize string: %w", err)
}
if s == "" {
return "", errors.New("normalized string is empty")
return "", fmt.Errorf("failed to normalize string: %w", err)
}
return s, nil
}

View file

@ -587,7 +587,9 @@ func (c *Client) SetLogger(l log.Logger) {
if l == nil {
return
}
c.mutex.Lock()
c.logger = l
c.mutex.Unlock()
}
// SetLogAuthData enables logging of authentication data in the Client.
@ -620,6 +622,9 @@ func (c *Client) HasConnection() bool {
func (c *Client) UpdateDeadline(timeout time.Duration) error {
c.mutex.Lock()
defer c.mutex.Unlock()
if c.conn == nil {
return errors.New("smtp: client has no connection")
}
if err := c.conn.SetDeadline(time.Now().Add(timeout)); err != nil {
return fmt.Errorf("smtp: failed to update deadline: %w", err)
}

59
smtp/smtp_121_test.go Normal file
View file

@ -0,0 +1,59 @@
// SPDX-FileCopyrightText: Copyright 2010 The Go Authors. All rights reserved.
// SPDX-FileCopyrightText: Copyright (c) 2022-2023 The go-mail Authors
//
// Original net/smtp code from the Go stdlib by the Go Authors.
// Use of this source code is governed by a BSD-style
// LICENSE file that can be found in this directory.
//
// go-mail specific modifications by the go-mail Authors.
// Licensed under the MIT License.
// See [PROJECT ROOT]/LICENSES directory for more information.
//
// SPDX-License-Identifier: BSD-3-Clause AND MIT
//go:build go1.21
// +build go1.21
package smtp
import (
"fmt"
"os"
"strings"
"testing"
"github.com/wneessen/go-mail/log"
)
func TestClient_SetDebugLog_JSON(t *testing.T) {
t.Run("set debug loggging to on should not override logger", func(t *testing.T) {
client := &Client{logger: log.NewJSON(os.Stderr, log.LevelDebug)}
client.SetDebugLog(true)
if !client.debug {
t.Fatalf("expected debug log to be true")
}
if client.logger == nil {
t.Fatalf("expected logger to be defined")
}
if !strings.EqualFold(fmt.Sprintf("%T", client.logger), "*log.JSONlog") {
t.Errorf("expected logger to be of type *log.JSONlog, got: %T", client.logger)
}
})
}
func TestClient_SetLogger_JSON(t *testing.T) {
t.Run("set logger to JSONlog logger", func(t *testing.T) {
client := &Client{}
client.SetLogger(log.NewJSON(os.Stderr, log.LevelDebug))
if !strings.EqualFold(fmt.Sprintf("%T", client.logger), "*log.JSONlog") {
t.Errorf("expected logger to be of type *log.JSONlog, got: %T", client.logger)
}
})
t.Run("nil logger should just return and not set/override", func(t *testing.T) {
client := &Client{logger: log.NewJSON(os.Stderr, log.LevelDebug)}
client.SetLogger(nil)
if !strings.EqualFold(fmt.Sprintf("%T", client.logger), "*log.JSONlog") {
t.Errorf("expected logger to be of type *log.JSONlog, got: %T", client.logger)
}
})
}

File diff suppressed because it is too large Load diff

View file

@ -1,6 +1,6 @@
# SPDX-FileCopyrightText: 2022-2023 The go-mail Authors
#
# SPDX-License-Identifier: CC0-1.0
# SPDX-License-Identifier: MIT
sonar.projectKey=go-mail
sonar.go.coverage.reportPaths=cov.out