Compare commits

...

12 commits

Author SHA1 Message Date
c9523e85ae
Merge pull request #287 from wneessen/wneessen-patch-1
Update doc.go
2024-08-16 10:49:50 +02:00
5454f44f67
Update doc.go
Bump version to 0.4.3
2024-08-16 10:49:36 +02:00
cfc8023a6d
Merge pull request #285 from wneessen/bug/284_fix-cicd-pipeline
Fix CI/CD pipeline
2024-08-16 10:38:45 +02:00
8b69fa92ae
Update Go version in SonarQube workflow
Bump Go version from 1.22.x to 1.23.x in the SonarQube GitHub Actions workflow. This ensures compatibility with the latest features and improvements in Go.
2024-08-16 10:30:20 +02:00
e61d1689f6
Update Go version in golangci-lint workflow
Change Go version from 1.22 to 1.23 in the GitHub Actions workflow configuration for golangci-lint. This ensures compatibility with the latest Go features and improvements.
2024-08-16 10:29:21 +02:00
801a93459e
Update workflow to support Go 1.23
This commit adjusts the GitHub Actions workflow to include Go 1.23 in the matrix of supported versions. It also updates conditional steps for sendmail installation and coverage upload to reflect the new Go version.
2024-08-16 10:28:52 +02:00
2801193074
Update FreeBSD version in CI configuration
Changed the CI configuration to use FreeBSD 13.3 instead of 13.2. This update ensures that the CI runs with the latest available FreeBSD image, improving compatibility and performance.
2024-08-16 10:25:22 +02:00
8efdf49d3d
Merge pull request #283 from wneessen/bug/279_fix-linter-errors
Fix linter errors
2024-08-16 10:22:21 +02:00
e288bcae5e
Update GolangCI config to go 1.23 and exclude examples
Upgraded the Go version in GolangCI configuration from 1.22 to 1.23. Added the "examples" directory to the exclusion list for linting.
2024-08-16 10:17:31 +02:00
590dfe97e7
Refactor error handling for nil template pointers
Replace fmt.Errorf with errors.New for consistency in error handling. This change ensures a more streamlined and uniform error reporting approach across the codebase. Also updated a test case from t.Errorf to t.Error for better readability.
2024-08-16 10:16:53 +02:00
84b5ebcebc
Merge pull request #282 from lipangeng/main
Support lowercase username and password challenge
2024-08-16 09:57:49 +02:00
李盼庚
647ff86b29 Support lowercase username and password challenge 2024-08-16 15:46:16 +08:00
10 changed files with 25 additions and 22 deletions

View file

@ -6,9 +6,9 @@ freebsd_task:
name: FreeBSD
matrix:
- name: FreeBSD 13.2
- name: FreeBSD 13.3
freebsd_instance:
image_family: freebsd-13-2
image_family: freebsd-13-3
- name: FreeBSD 14.0
freebsd_instance:
image_family: freebsd-14-0

View file

@ -36,7 +36,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
go: [1.18, 1.19, '1.20', '1.21', '1.22']
go: ['1.20', '1.21', '1.22', '1.23']
steps:
- name: Harden Runner
uses: step-security/harden-runner@5c7944e73c4c2a096b17a9cb74d65b6c2bbafbde # v2.9.1
@ -50,14 +50,14 @@ jobs:
with:
go-version: ${{ matrix.go }}
- name: Install sendmail
if: matrix.go == '1.22' && matrix.os == 'ubuntu-latest'
if: matrix.go == '1.23' && matrix.os == 'ubuntu-latest'
run: |
sudo apt-get -y install sendmail; which sendmail
- name: Run Tests
run: |
go test -v -race --coverprofile=coverage.coverprofile --covermode=atomic ./...
- name: Upload coverage to Codecov
if: success() && matrix.go == '1.22' && matrix.os == 'ubuntu-latest'
if: success() && matrix.go == '1.23' && matrix.os == 'ubuntu-latest'
uses: codecov/codecov-action@e28ff129e5465c2c0dcc6f003fc735cb6ae0c673 # v4.5.0
with:
token: ${{ secrets.CODECOV_TOKEN }} # not required for public repos

View file

@ -26,7 +26,7 @@ jobs:
- uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2
with:
go-version: '1.22'
go-version: '1.23'
- uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
- name: golangci-lint
uses: golangci/golangci-lint-action@aaa42aa0628b4ae2578232a66b541047968fac86 # v6.1.0

View file

@ -38,7 +38,7 @@ jobs:
- name: Setup Go
uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2
with:
go-version: '1.22.x'
go-version: '1.23.x'
- name: Run unit Tests
run: |

View file

@ -3,8 +3,9 @@
## SPDX-License-Identifier: MIT
[run]
go = "1.22"
go = "1.23"
tests = true
exclude-dirs = ["examples"]
[linters]
enable = ["stylecheck", "whitespace", "containedctx", "contextcheck", "decorder",

View file

@ -5,7 +5,7 @@
package mail
import (
"fmt"
"errors"
"io"
)
@ -26,7 +26,7 @@ var newlineBytes = []byte(SingleNewLine)
// line length is reached
func (l *Base64LineBreaker) Write(data []byte) (numBytes int, err error) {
if l.out == nil {
err = fmt.Errorf(ErrNoOutWriter)
err = errors.New(ErrNoOutWriter)
return
}
if l.used+len(data) < MaxBodyLength {

2
doc.go
View file

@ -6,4 +6,4 @@
package mail
// VERSION is used in the default user agent string
const VERSION = "0.4.2"
const VERSION = "0.4.3"

12
msg.go
View file

@ -743,7 +743,7 @@ func (m *Msg) SetBodyWriter(
// The content type will be set to text/html automatically
func (m *Msg) SetBodyHTMLTemplate(tpl *ht.Template, data interface{}, opts ...PartOption) error {
if tpl == nil {
return fmt.Errorf(errTplPointerNil)
return errors.New(errTplPointerNil)
}
buffer := bytes.Buffer{}
if err := tpl.Execute(&buffer, data); err != nil {
@ -758,7 +758,7 @@ func (m *Msg) SetBodyHTMLTemplate(tpl *ht.Template, data interface{}, opts ...Pa
// The content type will be set to text/plain automatically
func (m *Msg) SetBodyTextTemplate(tpl *tt.Template, data interface{}, opts ...PartOption) error {
if tpl == nil {
return fmt.Errorf(errTplPointerNil)
return errors.New(errTplPointerNil)
}
buf := bytes.Buffer{}
if err := tpl.Execute(&buf, data); err != nil {
@ -790,7 +790,7 @@ func (m *Msg) AddAlternativeWriter(
// The content type will be set to text/html automatically
func (m *Msg) AddAlternativeHTMLTemplate(tpl *ht.Template, data interface{}, opts ...PartOption) error {
if tpl == nil {
return fmt.Errorf(errTplPointerNil)
return errors.New(errTplPointerNil)
}
buffer := bytes.Buffer{}
if err := tpl.Execute(&buffer, data); err != nil {
@ -805,7 +805,7 @@ func (m *Msg) AddAlternativeHTMLTemplate(tpl *ht.Template, data interface{}, opt
// The content type will be set to text/plain automatically
func (m *Msg) AddAlternativeTextTemplate(tpl *tt.Template, data interface{}, opts ...PartOption) error {
if tpl == nil {
return fmt.Errorf(errTplPointerNil)
return errors.New(errTplPointerNil)
}
buffer := bytes.Buffer{}
if err := tpl.Execute(&buffer, data); err != nil {
@ -1314,7 +1314,7 @@ func fileFromReadSeeker(name string, reader io.ReadSeeker) *File {
// fileFromHTMLTemplate returns a File pointer form a given html/template.Template
func fileFromHTMLTemplate(name string, tpl *ht.Template, data interface{}) (*File, error) {
if tpl == nil {
return nil, fmt.Errorf(errTplPointerNil)
return nil, errors.New(errTplPointerNil)
}
buffer := bytes.Buffer{}
if err := tpl.Execute(&buffer, data); err != nil {
@ -1326,7 +1326,7 @@ func fileFromHTMLTemplate(name string, tpl *ht.Template, data interface{}) (*Fil
// fileFromTextTemplate returns a File pointer form a given text/template.Template
func fileFromTextTemplate(name string, tpl *tt.Template, data interface{}) (*File, error) {
if tpl == nil {
return nil, fmt.Errorf(errTplPointerNil)
return nil, errors.New(errTplPointerNil)
}
buffer := bytes.Buffer{}
if err := tpl.Execute(&buffer, data); err != nil {

View file

@ -122,7 +122,7 @@ func TestMsgWriter_writeMsg(t *testing.T) {
em += fmt.Sprintf("* incorrect %q field", ea[e])
}
em += fmt.Sprintf("\n\nFull message:\n%s", ms)
t.Errorf(em)
t.Error(em)
}
}

View file

@ -21,12 +21,14 @@ const (
//
// See: https://learn.microsoft.com/en-us/openspecs/exchange_server_protocols/ms-xlogin/.
LoginXUsernameChallenge = "Username:"
LoginXUsernameLowerChallenge = "username:"
// LoginXPasswordChallenge represents the Password Challenge response sent by the SMTP server per the AUTH LOGIN
// extension.
//
// See: https://learn.microsoft.com/en-us/openspecs/exchange_server_protocols/ms-xlogin/.
LoginXPasswordChallenge = "Password:"
LoginXPasswordLowerChallenge = "password:"
// LoginXDraftUsernameChallenge represents the Username Challenge response sent by the SMTP server per the IETF
// draft AUTH LOGIN extension. It should be noted this extension is an expired draft which was never formally
@ -76,9 +78,9 @@ func (a *loginAuth) Start(server *ServerInfo) (string, []byte, error) {
func (a *loginAuth) Next(fromServer []byte, more bool) ([]byte, error) {
if more {
switch string(fromServer) {
case LoginXUsernameChallenge, LoginXDraftUsernameChallenge:
case LoginXUsernameChallenge, LoginXUsernameLowerChallenge, LoginXDraftUsernameChallenge:
return []byte(a.username), nil
case LoginXPasswordChallenge, LoginXDraftPasswordChallenge:
case LoginXPasswordChallenge, LoginXPasswordLowerChallenge, LoginXDraftPasswordChallenge:
return []byte(a.password), nil
default:
return nil, fmt.Errorf("unexpected server response: %s", string(fromServer))