mirror of
https://github.com/wneessen/go-mail.git
synced 2024-11-22 13:50:49 +01:00
Compare commits
1 commit
13e5a7423c
...
c99b6e24c5
Author | SHA1 | Date | |
---|---|---|---|
|
c99b6e24c5 |
25 changed files with 2252 additions and 3708 deletions
2
.github/FUNDING.yml
vendored
2
.github/FUNDING.yml
vendored
|
@ -1,6 +1,6 @@
|
|||
# SPDX-FileCopyrightText: 2022 Winni Neessen <winni@neessen.dev>
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
# SPDX-License-Identifier: CC0-1.0
|
||||
|
||||
github: wneessen
|
||||
ko_fi: winni
|
||||
|
|
2
.github/ISSUE_TEMPLATE/bug_report.yml
vendored
2
.github/ISSUE_TEMPLATE/bug_report.yml
vendored
|
@ -1,6 +1,6 @@
|
|||
# SPDX-FileCopyrightText: 2022 Winni Neessen <winni@neessen.dev>
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
# SPDX-License-Identifier: CC0-1.0
|
||||
|
||||
name: Bug Report
|
||||
description: Create a report to help us improve
|
||||
|
|
2
.github/ISSUE_TEMPLATE/config.yml
vendored
2
.github/ISSUE_TEMPLATE/config.yml
vendored
|
@ -1,6 +1,6 @@
|
|||
# SPDX-FileCopyrightText: 2022 Winni Neessen <winni@neessen.dev>
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
# SPDX-License-Identifier: CC0-1.0
|
||||
|
||||
blank_issues_enabled: false
|
||||
contact_links:
|
||||
|
|
2
.github/ISSUE_TEMPLATE/feature_request.yml
vendored
2
.github/ISSUE_TEMPLATE/feature_request.yml
vendored
|
@ -1,6 +1,6 @@
|
|||
# SPDX-FileCopyrightText: 2022 Winni Neessen <winni@neessen.dev>
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
# SPDX-License-Identifier: CC0-1.0
|
||||
|
||||
name: Feature request
|
||||
description: Suggest an idea for this project
|
||||
|
|
2
.github/dependabot.yml
vendored
2
.github/dependabot.yml
vendored
|
@ -1,6 +1,6 @@
|
|||
# SPDX-FileCopyrightText: 2022-2023 The go-mail Authors
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
# SPDX-License-Identifier: CC0-1.0
|
||||
|
||||
version: 2
|
||||
updates:
|
||||
|
|
8
.github/workflows/codeql-analysis.yml
vendored
8
.github/workflows/codeql-analysis.yml
vendored
|
@ -1,6 +1,6 @@
|
|||
# SPDX-FileCopyrightText: 2022 Winni Neessen <winni@neessen.dev>
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
# SPDX-License-Identifier: CC0-1.0
|
||||
|
||||
# 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@4f3212b61783c3c68e8309a0f18a699764811cda # v3.27.1
|
||||
uses: github/codeql-action/init@662472033e021d55d94146f66f6058822b0b39fd # v3.27.0
|
||||
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@4f3212b61783c3c68e8309a0f18a699764811cda # v3.27.1
|
||||
uses: github/codeql-action/autobuild@662472033e021d55d94146f66f6058822b0b39fd # v3.27.0
|
||||
|
||||
# ℹ️ 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@4f3212b61783c3c68e8309a0f18a699764811cda # v3.27.1
|
||||
uses: github/codeql-action/analyze@662472033e021d55d94146f66f6058822b0b39fd # v3.27.0
|
||||
|
|
4
.github/workflows/scorecards.yml
vendored
4
.github/workflows/scorecards.yml
vendored
|
@ -1,6 +1,6 @@
|
|||
# SPDX-FileCopyrightText: 2022-2023 The go-mail Authors
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
# SPDX-License-Identifier: CC0-1.0
|
||||
|
||||
# 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@4f3212b61783c3c68e8309a0f18a699764811cda # v3.27.1
|
||||
uses: github/codeql-action/upload-sarif@662472033e021d55d94146f66f6058822b0b39fd # v3.27.0
|
||||
with:
|
||||
sarif_file: results.sarif
|
||||
|
|
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -1,6 +1,6 @@
|
|||
# SPDX-FileCopyrightText: 2022 Winni Neessen <winni@neessen.dev>
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
# SPDX-License-Identifier: CC0-1.0
|
||||
|
||||
# Binaries for programs and plugins
|
||||
*.exe
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<!--
|
||||
SPDX-FileCopyrightText: 2022 Winni Neessen <winni@neessen.dev>
|
||||
|
||||
SPDX-License-Identifier: MIT
|
||||
SPDX-License-Identifier: CC0-1.0
|
||||
-->
|
||||
|
||||
# Contributor Covenant Code of Conduct
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<!--
|
||||
SPDX-FileCopyrightText: 2022-2023 The go-mail Authors
|
||||
|
||||
SPDX-License-Identifier: MIT
|
||||
SPDX-License-Identifier: CC0-1.0
|
||||
-->
|
||||
|
||||
# How to contribute
|
||||
|
|
121
LICENSES/CC0-1.0.txt
Normal file
121
LICENSES/CC0-1.0.txt
Normal file
|
@ -0,0 +1,121 @@
|
|||
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.
|
14
README.md
14
README.md
|
@ -1,7 +1,7 @@
|
|||
<!--
|
||||
SPDX-FileCopyrightText: 2022-2023 The go-mail Authors
|
||||
|
||||
SPDX-License-Identifier: MIT
|
||||
SPDX-License-Identifier: CC0-1.0
|
||||
-->
|
||||
|
||||
# go-mail - Easy to use, yet comprehensive library for sending mails with Go
|
||||
|
@ -39,16 +39,10 @@ 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] Implicit SSL/TLS support
|
||||
* [X] Explicit STARTTLS support with different policies
|
||||
* [X] Explicit SSL/TLS support
|
||||
* [X] Implicit StartTLS support with different policies
|
||||
* [X] Makes use of contexts for a better control flow and timeout/cancelation handling
|
||||
* [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] SMTP Auth support (LOGIN, PLAIN, CRAM-MD, XOAUTH2, SCRAM-SHA-1(-PLUS), SCRAM-SHA-256(-PLUS))
|
||||
* [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
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<!--
|
||||
SPDX-FileCopyrightText: 2022-2023 The go-mail Authors
|
||||
|
||||
SPDX-License-Identifier: MIT
|
||||
SPDX-License-Identifier: CC0-1.0
|
||||
-->
|
||||
|
||||
# Security Policy
|
||||
|
|
|
@ -2803,7 +2803,7 @@ func TestClient_sendSingleMsg(t *testing.T) {
|
|||
t.Errorf("expected ErrGetSender, got %s", sendErr.Reason)
|
||||
}
|
||||
})
|
||||
t.Run("fail with no recipient addresses", func(t *testing.T) {
|
||||
t.Run("fail with no recepient addresses", func(t *testing.T) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
PortAdder.Add(1)
|
||||
|
|
|
@ -1,19 +1,19 @@
|
|||
# SPDX-FileCopyrightText: 2022-2023 The go-mail Authors
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
# SPDX-License-Identifier: CC0-1.0
|
||||
|
||||
coverage:
|
||||
status:
|
||||
project:
|
||||
default:
|
||||
target: 95%
|
||||
target: 90%
|
||||
threshold: 2%
|
||||
base: auto
|
||||
if_ci_failed: error
|
||||
only_pulls: false
|
||||
patch:
|
||||
default:
|
||||
target: 95%
|
||||
target: 90%
|
||||
base: auto
|
||||
if_ci_failed: error
|
||||
threshold: 2%
|
||||
|
|
12
msg_test.go
12
msg_test.go
|
@ -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-separated
|
||||
{`"<\"@\\".!.#%$@domain.tld`, false}, // Quote is escaped and dot-separated which would be RFC822 compliant, but not RFC5322 compliant
|
||||
{`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}, // 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-existent file", func(t *testing.T) {
|
||||
t.Run("AttachFile with non-existant file", func(t *testing.T) {
|
||||
message := NewMsg()
|
||||
if message == nil {
|
||||
t.Fatal("message is nil")
|
||||
}
|
||||
message.AttachFile("testdata/non-existent-file.txt")
|
||||
message.AttachFile("testdata/non-existant-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-existent file", func(t *testing.T) {
|
||||
t.Run("EmbedFile with non-existant file", func(t *testing.T) {
|
||||
message := NewMsg()
|
||||
if message == nil {
|
||||
t.Fatal("message is nil")
|
||||
}
|
||||
message.EmbedFile("testdata/non-existent-file.txt")
|
||||
message.EmbedFile("testdata/non-existant-file.txt")
|
||||
embeds := message.GetEmbeds()
|
||||
if len(embeds) != 0 {
|
||||
t.Fatalf("failed to retrieve attachments list")
|
||||
|
|
|
@ -324,7 +324,7 @@ func TestMsgWriter_addFiles(t *testing.T) {
|
|||
}
|
||||
}
|
||||
if !strings.Contains(buffer.String(), `Content-Disposition: attachment; filename="attachment.txt"`) {
|
||||
t.Errorf("Content-Disposition header not found for attachment. Mail: %s", buffer.String())
|
||||
t.Errorf("Content-Dispositon 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-Disposition header not found for attachment. Mail: %s", buffer.String())
|
||||
t.Errorf("Content-Dispositon 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-Disposition header not found for attachment. Mail: %s", buffer.String())
|
||||
t.Errorf("Content-Dispositon 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-Disposition header not found for attachment. Mail: %s", buffer.String())
|
||||
t.Errorf("Content-Dispositon 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-Disposition header not found for attachment. Mail: %s", buffer.String())
|
||||
t.Errorf("Content-Dispositon 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-Disposition header not found for attachment. Mail: %s", buffer.String())
|
||||
t.Errorf("Content-Dispositon header not found for attachment. Mail: %s", buffer.String())
|
||||
}
|
||||
switch runtime.GOOS {
|
||||
case "freebsd":
|
||||
|
|
|
@ -174,12 +174,6 @@ 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) {
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -154,7 +154,7 @@ func (a *scramAuth) initialClientMessage() ([]byte, error) {
|
|||
connState := a.tlsConnState
|
||||
bindData := connState.TLSUnique
|
||||
|
||||
// crypto/tls: no tls-unique channel binding value for this tls connection, possibly due to missing
|
||||
// crypto/tl: 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,7 +308,10 @@ 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("failed to normalize string: %w", err)
|
||||
return "", fmt.Errorf("failled to normalize string: %w", err)
|
||||
}
|
||||
if s == "" {
|
||||
return "", errors.New("normalized string is empty")
|
||||
}
|
||||
return s, nil
|
||||
}
|
||||
|
|
|
@ -587,9 +587,7 @@ 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.
|
||||
|
@ -622,9 +620,6 @@ 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)
|
||||
}
|
||||
|
|
|
@ -1,59 +0,0 @@
|
|||
// 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)
|
||||
}
|
||||
})
|
||||
}
|
5236
smtp/smtp_test.go
5236
smtp/smtp_test.go
File diff suppressed because it is too large
Load diff
|
@ -1,6 +1,6 @@
|
|||
# SPDX-FileCopyrightText: 2022-2023 The go-mail Authors
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
# SPDX-License-Identifier: CC0-1.0
|
||||
|
||||
sonar.projectKey=go-mail
|
||||
sonar.go.coverage.reportPaths=cov.out
|
||||
|
|
Loading…
Reference in a new issue