mirror of
https://github.com/decke/smtprelay.git
synced 2025-12-25 15:52:29 -07:00
Compare commits
52 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
085052b96a | ||
|
|
2753d3670d | ||
|
|
68ddb8cbc0 | ||
|
|
0b6eff0eeb | ||
|
|
51ed156dad | ||
|
|
d4aedd2453 | ||
|
|
47361c9df0 | ||
|
|
ab9ddfc8aa | ||
|
|
e722c8288e | ||
|
|
c42bc9b3bb | ||
|
|
cafbc78e74 | ||
|
|
d20e3d201c | ||
|
|
11696737ee | ||
|
|
cc8d678e18 | ||
|
|
2a6a0ef76d | ||
|
|
dfdefc5e7d | ||
|
|
3c4f79dc89 | ||
|
|
82db571b02 | ||
|
|
a06d7a6296 | ||
|
|
a971995458 | ||
|
|
b8b668bbbb | ||
|
|
66f76ccae7 | ||
|
|
e2a4d646d9 | ||
|
|
9fdd6040bd | ||
|
|
5d00ff36f0 | ||
|
|
db79ed0ea9 | ||
|
|
40942a7f83 | ||
|
|
2795ce3230 | ||
|
|
307ce547ec | ||
|
|
ea911a0aaa | ||
|
|
99b72e32f1 | ||
|
|
a2f92daa41 | ||
|
|
b5dc7d1c5b | ||
|
|
2358b735b1 | ||
|
|
e4736a7544 | ||
|
|
ccaf614b6b | ||
|
|
effa1c9192 | ||
|
|
ddfd61bfd1 | ||
|
|
b6cbf2f82b | ||
|
|
687c793203 | ||
|
|
dfd7620a64 | ||
|
|
21eb505b7b | ||
|
|
0d4e43e723 | ||
|
|
27d21b2a5b | ||
|
|
f6a325289d | ||
|
|
233833b85b | ||
|
|
fae99cff0c | ||
|
|
ec27e905b7 | ||
|
|
1e65705bb8 | ||
|
|
5b6451b584 | ||
|
|
391c468f81 | ||
|
|
074cf4e1d9 |
45
.github/workflows/codeql-analysis.yml
vendored
45
.github/workflows/codeql-analysis.yml
vendored
@@ -1,44 +1,53 @@
|
|||||||
|
# For most projects, this workflow file will not need changing; you simply need
|
||||||
|
# to commit it to your repository.
|
||||||
|
#
|
||||||
|
# You may wish to alter this file to override the set of languages analyzed,
|
||||||
|
# or to provide custom queries or build logic.
|
||||||
|
#
|
||||||
|
# ******** NOTE ********
|
||||||
|
# We have attempted to detect the languages in your repository. Please check
|
||||||
|
# the `language` matrix defined below to confirm you have the correct set of
|
||||||
|
# supported CodeQL languages.
|
||||||
|
#
|
||||||
name: "CodeQL"
|
name: "CodeQL"
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: [master]
|
|
||||||
pull_request:
|
pull_request:
|
||||||
# The branches below must be a subset of the branches above
|
# The branches below must be a subset of the branches above
|
||||||
branches: [master]
|
branches: [master]
|
||||||
schedule:
|
schedule:
|
||||||
- cron: '0 15 * * 5'
|
- cron: '0 15 * * 5'
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
analyze:
|
analyze:
|
||||||
name: Analyze
|
name: Analyze
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
permissions:
|
||||||
|
actions: read
|
||||||
|
contents: read
|
||||||
|
security-events: write
|
||||||
|
|
||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
# Override automatic language detection by changing the below list
|
language: [ 'go' ]
|
||||||
# Supported options are ['csharp', 'cpp', 'go', 'java', 'javascript', 'python']
|
|
||||||
language: ['go']
|
|
||||||
# Learn more...
|
|
||||||
# https://docs.github.com/en/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#overriding-automatic-language-detection
|
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Harden Runner
|
||||||
uses: actions/checkout@v4
|
uses: step-security/harden-runner@0634a2670c59f64b4a01f0f96f84700a4088b9f0 # v2.12.0
|
||||||
with:
|
with:
|
||||||
# We must fetch at least the immediate parents so that if this is
|
egress-policy: audit
|
||||||
# a pull request then we can checkout the head.
|
|
||||||
fetch-depth: 2
|
|
||||||
|
|
||||||
# If this run was triggered by a pull request event, then checkout
|
- name: Checkout repository
|
||||||
# the head of the pull request instead of the merge commit.
|
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
||||||
- run: git checkout HEAD^2
|
|
||||||
if: ${{ github.event_name == 'pull_request' }}
|
|
||||||
|
|
||||||
# Initializes the CodeQL tools for scanning.
|
# Initializes the CodeQL tools for scanning.
|
||||||
- name: Initialize CodeQL
|
- name: Initialize CodeQL
|
||||||
uses: github/codeql-action/init@v3
|
uses: github/codeql-action/init@fca7ace96b7d713c7035871441bd52efbe39e27e # v3.28.19
|
||||||
with:
|
with:
|
||||||
languages: ${{ matrix.language }}
|
languages: ${{ matrix.language }}
|
||||||
# If you wish to specify custom queries, you can do so here or in a config file.
|
# If you wish to specify custom queries, you can do so here or in a config file.
|
||||||
@@ -49,7 +58,7 @@ jobs:
|
|||||||
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
# 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)
|
# If this step fails, then you should remove it and run the build manually (see below)
|
||||||
- name: Autobuild
|
- name: Autobuild
|
||||||
uses: github/codeql-action/autobuild@v3
|
uses: github/codeql-action/autobuild@fca7ace96b7d713c7035871441bd52efbe39e27e # v3.28.19
|
||||||
|
|
||||||
# ℹ️ Command-line programs to run using the OS shell.
|
# ℹ️ Command-line programs to run using the OS shell.
|
||||||
# 📚 https://git.io/JvXDl
|
# 📚 https://git.io/JvXDl
|
||||||
@@ -63,4 +72,4 @@ jobs:
|
|||||||
# make release
|
# make release
|
||||||
|
|
||||||
- name: Perform CodeQL Analysis
|
- name: Perform CodeQL Analysis
|
||||||
uses: github/codeql-action/analyze@v3
|
uses: github/codeql-action/analyze@fca7ace96b7d713c7035871441bd52efbe39e27e # v3.28.19
|
||||||
|
|||||||
27
.github/workflows/dependency-review.yml
vendored
Normal file
27
.github/workflows/dependency-review.yml
vendored
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
# Dependency Review Action
|
||||||
|
#
|
||||||
|
# This Action will scan dependency manifest files that change as part of a Pull Request,
|
||||||
|
# surfacing known-vulnerable versions of the packages declared or updated in the PR.
|
||||||
|
# Once installed, if the workflow run is marked as required,
|
||||||
|
# PRs introducing known-vulnerable packages will be blocked from merging.
|
||||||
|
#
|
||||||
|
# Source repository: https://github.com/actions/dependency-review-action
|
||||||
|
name: 'Dependency Review'
|
||||||
|
on: [pull_request]
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
dependency-review:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Harden Runner
|
||||||
|
uses: step-security/harden-runner@0634a2670c59f64b4a01f0f96f84700a4088b9f0 # v2.12.0
|
||||||
|
with:
|
||||||
|
egress-policy: audit
|
||||||
|
|
||||||
|
- name: 'Checkout Repository'
|
||||||
|
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
||||||
|
- name: 'Dependency Review'
|
||||||
|
uses: actions/dependency-review-action@da24556b548a50705dd671f47852072ea4c105d9 # v4.7.1
|
||||||
12
.github/workflows/go.yml
vendored
12
.github/workflows/go.yml
vendored
@@ -1,13 +1,21 @@
|
|||||||
name: Go
|
name: Go
|
||||||
on: [push, pull_request]
|
on: [push, pull_request]
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
|
|
||||||
build:
|
build:
|
||||||
name: Build
|
name: Build
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- name: Harden Runner
|
||||||
- uses: actions/setup-go@v5
|
uses: step-security/harden-runner@0634a2670c59f64b4a01f0f96f84700a4088b9f0 # v2.12.0
|
||||||
|
with:
|
||||||
|
egress-policy: audit
|
||||||
|
|
||||||
|
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
||||||
|
- uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0
|
||||||
with:
|
with:
|
||||||
go-version: 'stable'
|
go-version: 'stable'
|
||||||
|
|
||||||
|
|||||||
20
.github/workflows/release.yaml
vendored
20
.github/workflows/release.yaml
vendored
@@ -4,9 +4,8 @@ on:
|
|||||||
release:
|
release:
|
||||||
types: [created]
|
types: [created]
|
||||||
|
|
||||||
permissions:
|
# Declare default permissions as read only.
|
||||||
contents: write
|
permissions: read-all
|
||||||
packages: write
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
releases-matrix:
|
releases-matrix:
|
||||||
@@ -16,19 +15,28 @@ jobs:
|
|||||||
matrix:
|
matrix:
|
||||||
goos: [freebsd, linux, windows]
|
goos: [freebsd, linux, windows]
|
||||||
goarch: [amd64, arm64]
|
goarch: [amd64, arm64]
|
||||||
|
permissions:
|
||||||
|
contents: write
|
||||||
|
packages: write
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- name: Harden Runner
|
||||||
|
uses: step-security/harden-runner@0634a2670c59f64b4a01f0f96f84700a4088b9f0 # v2.12.0
|
||||||
|
with:
|
||||||
|
egress-policy: audit
|
||||||
|
|
||||||
|
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
||||||
|
|
||||||
- name: Set APP_VERSION env
|
- name: Set APP_VERSION env
|
||||||
run: echo APP_VERSION=$(echo ${GITHUB_REF} | rev | cut -d'/' -f 1 | rev ) >> ${GITHUB_ENV}
|
run: echo APP_VERSION=$(echo ${GITHUB_REF} | rev | cut -d'/' -f 1 | rev ) >> ${GITHUB_ENV}
|
||||||
- name: Set BUILD_TIME env
|
- name: Set BUILD_TIME env
|
||||||
run: echo BUILD_TIME=$(date) >> ${GITHUB_ENV}
|
run: echo BUILD_TIME=$(date) >> ${GITHUB_ENV}
|
||||||
|
|
||||||
- uses: wangyoucao577/go-release-action@v1
|
- uses: wangyoucao577/go-release-action@481a2c1a0f1be199722e3e9b74d7199acafc30a8 # v1.53
|
||||||
with:
|
with:
|
||||||
github_token: ${{ secrets.GITHUB_TOKEN }}
|
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
goos: ${{ matrix.goos }}
|
goos: ${{ matrix.goos }}
|
||||||
goarch: ${{ matrix.goarch }}
|
goarch: ${{ matrix.goarch }}
|
||||||
goversion: "1.22"
|
goversion: "1.24"
|
||||||
extra_files: LICENSE README.md smtprelay.ini
|
extra_files: LICENSE README.md smtprelay.ini
|
||||||
ldflags: -s -w -X "main.appVersion=${{ env.APP_VERSION }}" -X "main.buildTime=${{ env.BUILD_TIME }}"
|
ldflags: -s -w -X "main.appVersion=${{ env.APP_VERSION }}" -X "main.buildTime=${{ env.BUILD_TIME }}"
|
||||||
|
|||||||
81
.github/workflows/scorecards.yml
vendored
Normal file
81
.github/workflows/scorecards.yml
vendored
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
# 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
|
||||||
|
# policy, and support documentation.
|
||||||
|
|
||||||
|
name: Scorecard supply-chain security
|
||||||
|
on:
|
||||||
|
# For Branch-Protection check. Only the default branch is supported. See
|
||||||
|
# https://github.com/ossf/scorecard/blob/main/docs/checks.md#branch-protection
|
||||||
|
branch_protection_rule:
|
||||||
|
# To guarantee Maintained check is occasionally updated. See
|
||||||
|
# https://github.com/ossf/scorecard/blob/main/docs/checks.md#maintained
|
||||||
|
schedule:
|
||||||
|
- cron: '20 7 * * 2'
|
||||||
|
push:
|
||||||
|
branches: ["master"]
|
||||||
|
|
||||||
|
# Declare default permissions as read only.
|
||||||
|
permissions: read-all
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
analysis:
|
||||||
|
name: Scorecard analysis
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
permissions:
|
||||||
|
# Needed to upload the results to code-scanning dashboard.
|
||||||
|
security-events: write
|
||||||
|
# Needed to publish results and get a badge (see publish_results below).
|
||||||
|
id-token: write
|
||||||
|
contents: read
|
||||||
|
actions: read
|
||||||
|
# To allow GraphQL ListCommits to work
|
||||||
|
issues: read
|
||||||
|
pull-requests: read
|
||||||
|
# To detect SAST tools
|
||||||
|
checks: read
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Harden Runner
|
||||||
|
uses: step-security/harden-runner@0634a2670c59f64b4a01f0f96f84700a4088b9f0 # v2.12.0
|
||||||
|
with:
|
||||||
|
egress-policy: audit
|
||||||
|
|
||||||
|
- name: "Checkout code"
|
||||||
|
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
||||||
|
with:
|
||||||
|
persist-credentials: false
|
||||||
|
|
||||||
|
- name: "Run analysis"
|
||||||
|
uses: ossf/scorecard-action@05b42c624433fc40578a4040d5cf5e36ddca8cde # v2.4.2
|
||||||
|
with:
|
||||||
|
results_file: results.sarif
|
||||||
|
results_format: sarif
|
||||||
|
# (Optional) "write" PAT token. Uncomment the `repo_token` line below if:
|
||||||
|
# - you want to enable the Branch-Protection check on a *public* repository, or
|
||||||
|
# - you are installing Scorecards on a *private* repository
|
||||||
|
# To create the PAT, follow the steps in https://github.com/ossf/scorecard-action#authentication-with-pat.
|
||||||
|
# repo_token: ${{ secrets.SCORECARD_TOKEN }}
|
||||||
|
|
||||||
|
# Public repositories:
|
||||||
|
# - Publish results to OpenSSF REST API for easy access by consumers
|
||||||
|
# - Allows the repository to include the Scorecard badge.
|
||||||
|
# - See https://github.com/ossf/scorecard-action#publishing-results.
|
||||||
|
# For private repositories:
|
||||||
|
# - `publish_results` will always be set to `false`, regardless
|
||||||
|
# of the value entered here.
|
||||||
|
publish_results: true
|
||||||
|
|
||||||
|
# Upload the results as artifacts (optional). Commenting out will disable uploads of run results in SARIF
|
||||||
|
# format to the repository Actions tab.
|
||||||
|
- name: "Upload artifact"
|
||||||
|
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
|
||||||
|
with:
|
||||||
|
name: SARIF file
|
||||||
|
path: results.sarif
|
||||||
|
retention-days: 5
|
||||||
|
|
||||||
|
# Upload the results to GitHub's code scanning dashboard.
|
||||||
|
- name: "Upload to code-scanning"
|
||||||
|
uses: github/codeql-action/upload-sarif@fca7ace96b7d713c7035871441bd52efbe39e27e # v3.28.19
|
||||||
|
with:
|
||||||
|
sarif_file: results.sarif
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
# smtprelay
|
# smtprelay
|
||||||
|
|
||||||
[](https://goreportcard.com/report/github.com/decke/smtprelay)
|
[](https://goreportcard.com/report/github.com/decke/smtprelay)
|
||||||
|
[](https://scorecard.dev/viewer/?uri=github.com/decke/smtprelay)
|
||||||
|
|
||||||
Simple Golang based SMTP relay/proxy server that accepts mail via SMTP
|
Simple Golang based SMTP relay/proxy server that accepts mail via SMTP
|
||||||
and forwards it directly to another SMTP server.
|
and forwards it directly to another SMTP server.
|
||||||
|
|||||||
51
SECURITY.md
Normal file
51
SECURITY.md
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
# smtprelay Security Policy
|
||||||
|
|
||||||
|
This document outlines security procedures and general policies for the
|
||||||
|
smtprelay project.
|
||||||
|
|
||||||
|
## Supported Versions
|
||||||
|
|
||||||
|
The latest release is the only supported release.
|
||||||
|
|
||||||
|
|
||||||
|
## Disclosing a security issue
|
||||||
|
|
||||||
|
The smtprelay maintainers take all security issues in the project seriously.
|
||||||
|
Thank you for improving the security of the project! We appreciate your
|
||||||
|
dedication to responsible disclosure and will make every effort to acknowledge
|
||||||
|
your contributions.
|
||||||
|
|
||||||
|
smtprelay leverages GitHub's private vulnerability reporting.
|
||||||
|
|
||||||
|
To learn more about this feature and how to submit a vulnerability report,
|
||||||
|
review [GitHub's documentation on private reporting](https://docs.github.com/code-security/security-advisories/guidance-on-reporting-and-writing-information-about-vulnerabilities/privately-reporting-a-security-vulnerability).
|
||||||
|
|
||||||
|
Here are some helpful details to include in your report:
|
||||||
|
|
||||||
|
- a detailed description of the issue
|
||||||
|
- the steps required to reproduce the issue
|
||||||
|
- versions of the project that may be affected by the issue
|
||||||
|
- if known, any mitigations for the issue
|
||||||
|
|
||||||
|
A maintainer will acknowledge the report within three (3) business days, and
|
||||||
|
will send a more detailed response within an additional three (3) business days
|
||||||
|
indicating the next steps in handling your report.
|
||||||
|
|
||||||
|
After the initial reply to your report, the maintainers will endeavor to keep
|
||||||
|
you informed of the progress towards a fix and full announcement, and may ask
|
||||||
|
for additional information or guidance.
|
||||||
|
|
||||||
|
## Vulnerability management
|
||||||
|
|
||||||
|
When the maintainers receive a disclosure report, they will coordinate the
|
||||||
|
fix and release process, which involves the following steps:
|
||||||
|
|
||||||
|
- confirming the issue
|
||||||
|
- determining affected versions of the project
|
||||||
|
- auditing code to find any potential similar problems
|
||||||
|
- preparing fixes for all releases under maintenance
|
||||||
|
|
||||||
|
## Suggesting changes
|
||||||
|
|
||||||
|
If you have suggestions on how this process could be improved please submit an
|
||||||
|
issue or pull request.
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
|
|
||||||
To run the hasher, do like this
|
|
||||||
|
|
||||||
```bash
|
|
||||||
$ go run hasher.go hunter2
|
|
||||||
```
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"golang.org/x/crypto/bcrypt"
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
if len(os.Args) != 2 {
|
|
||||||
fmt.Fprintln(os.Stderr, "Usage: hasher PASSWORD")
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
password := os.Args[1]
|
|
||||||
|
|
||||||
hash, err := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Fprintln(os.Stderr, "Error generating hash: %s", err)
|
|
||||||
}
|
|
||||||
fmt.Println(string(hash))
|
|
||||||
}
|
|
||||||
8
go.mod
8
go.mod
@@ -5,17 +5,17 @@ require (
|
|||||||
github.com/google/uuid v1.6.0
|
github.com/google/uuid v1.6.0
|
||||||
github.com/peterbourgon/ff/v3 v3.4.0
|
github.com/peterbourgon/ff/v3 v3.4.0
|
||||||
github.com/sirupsen/logrus v1.9.3
|
github.com/sirupsen/logrus v1.9.3
|
||||||
github.com/stretchr/testify v1.9.0
|
github.com/stretchr/testify v1.10.0
|
||||||
golang.org/x/crypto v0.23.0
|
golang.org/x/crypto v0.38.0
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||||
github.com/kr/pretty v0.3.1 // indirect
|
github.com/kr/pretty v0.3.1 // indirect
|
||||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||||
golang.org/x/sys v0.20.0 // indirect
|
golang.org/x/sys v0.33.0 // indirect
|
||||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
|
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
|
||||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||||
)
|
)
|
||||||
|
|
||||||
go 1.20
|
go 1.24.3
|
||||||
|
|||||||
12
go.sum
12
go.sum
@@ -24,13 +24,13 @@ github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ
|
|||||||
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
|
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
|
||||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||||
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
|
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
|
||||||
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||||
golang.org/x/crypto v0.23.0 h1:dIJU/v2J8Mdglj/8rJ6UUOM3Zc9zLZxVZwwxMooUSAI=
|
golang.org/x/crypto v0.38.0 h1:jt+WWG8IZlBnVbomuhg2Mdq0+BBQaHbtqHEFEigjUV8=
|
||||||
golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8=
|
golang.org/x/crypto v0.38.0/go.mod h1:MvrbAqul58NNYPKnOra203SB9vpuZW0e+RRZV+Ggqjw=
|
||||||
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y=
|
golang.org/x/sys v0.33.0 h1:q3i8TbbEz+JRD9ywIRlyRAQbM0qF7hu24q3teo2hbuw=
|
||||||
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
golang.org/x/sys v0.33.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
|
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
|
||||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
|
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
|
||||||
|
|||||||
2
main.go
2
main.go
@@ -234,7 +234,7 @@ func mailHandler(peer smtpd.Peer, env smtpd.Envelope) error {
|
|||||||
"err_msg": err.Msg,
|
"err_msg": err.Msg,
|
||||||
}).Error("delivery failed")
|
}).Error("delivery failed")
|
||||||
default:
|
default:
|
||||||
smtpError = smtpd.Error{Code: 554, Message: "Forwarding failed"}
|
smtpError = smtpd.Error{Code: 421, Message: "Forwarding failed"}
|
||||||
|
|
||||||
logger.WithError(err).
|
logger.WithError(err).
|
||||||
Error("delivery failed")
|
Error("delivery failed")
|
||||||
|
|||||||
24
smtp.go
24
smtp.go
@@ -49,7 +49,7 @@ type Client struct {
|
|||||||
helloError error // the error from the hello
|
helloError error // the error from the hello
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dial returns a new Client connected to an SMTP server at addr.
|
// Dial returns a new [Client] connected to an SMTP server at addr.
|
||||||
// The addr must include a port, as in "mail.example.com:smtp".
|
// The addr must include a port, as in "mail.example.com:smtp".
|
||||||
func Dial(addr string) (*Client, error) {
|
func Dial(addr string) (*Client, error) {
|
||||||
conn, err := net.Dial("tcp", addr)
|
conn, err := net.Dial("tcp", addr)
|
||||||
@@ -60,7 +60,7 @@ func Dial(addr string) (*Client, error) {
|
|||||||
return NewClient(conn, host)
|
return NewClient(conn, host)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewClient returns a new Client using an existing connection and host as a
|
// NewClient returns a new [Client] using an existing connection and host as a
|
||||||
// server name to be used when authenticating.
|
// server name to be used when authenticating.
|
||||||
func NewClient(conn net.Conn, host string) (*Client, error) {
|
func NewClient(conn net.Conn, host string) (*Client, error) {
|
||||||
text := textproto.NewConn(conn)
|
text := textproto.NewConn(conn)
|
||||||
@@ -167,7 +167,7 @@ func (c *Client) StartTLS(config *tls.Config) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TLSConnectionState returns the client's TLS connection state.
|
// TLSConnectionState returns the client's TLS connection state.
|
||||||
// The return values are their zero values if StartTLS did
|
// The return values are their zero values if [Client.StartTLS] did
|
||||||
// not succeed.
|
// not succeed.
|
||||||
func (c *Client) TLSConnectionState() (state tls.ConnectionState, ok bool) {
|
func (c *Client) TLSConnectionState() (state tls.ConnectionState, ok bool) {
|
||||||
tc, ok := c.conn.(*tls.Conn)
|
tc, ok := c.conn.(*tls.Conn)
|
||||||
@@ -207,7 +207,7 @@ func (c *Client) Auth(a smtp.Auth) error {
|
|||||||
}
|
}
|
||||||
resp64 := make([]byte, encoding.EncodedLen(len(resp)))
|
resp64 := make([]byte, encoding.EncodedLen(len(resp)))
|
||||||
encoding.Encode(resp64, resp)
|
encoding.Encode(resp64, resp)
|
||||||
code, msg64, err := c.cmd(0, strings.TrimSpace(fmt.Sprintf("AUTH %s %s", mech, resp64)))
|
code, msg64, err := c.cmd(0, "%s", strings.TrimSpace(fmt.Sprintf("AUTH %s %s", mech, resp64)))
|
||||||
for err == nil {
|
for err == nil {
|
||||||
var msg []byte
|
var msg []byte
|
||||||
switch code {
|
switch code {
|
||||||
@@ -233,7 +233,7 @@ func (c *Client) Auth(a smtp.Auth) error {
|
|||||||
}
|
}
|
||||||
resp64 = make([]byte, encoding.EncodedLen(len(resp)))
|
resp64 = make([]byte, encoding.EncodedLen(len(resp)))
|
||||||
encoding.Encode(resp64, resp)
|
encoding.Encode(resp64, resp)
|
||||||
code, msg64, err = c.cmd(0, string(resp64))
|
code, msg64, err = c.cmd(0, "%s", resp64)
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -242,7 +242,7 @@ func (c *Client) Auth(a smtp.Auth) error {
|
|||||||
// If the server supports the 8BITMIME extension, Mail adds the BODY=8BITMIME
|
// If the server supports the 8BITMIME extension, Mail adds the BODY=8BITMIME
|
||||||
// parameter. If the server supports the SMTPUTF8 extension, Mail adds the
|
// parameter. If the server supports the SMTPUTF8 extension, Mail adds the
|
||||||
// SMTPUTF8 parameter.
|
// SMTPUTF8 parameter.
|
||||||
// This initiates a mail transaction and is followed by one or more Rcpt calls.
|
// This initiates a mail transaction and is followed by one or more [Client.Rcpt] calls.
|
||||||
func (c *Client) Mail(from string) error {
|
func (c *Client) Mail(from string) error {
|
||||||
if err := validateLine(from); err != nil {
|
if err := validateLine(from); err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -264,8 +264,8 @@ func (c *Client) Mail(from string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Rcpt issues a RCPT command to the server using the provided email address.
|
// Rcpt issues a RCPT command to the server using the provided email address.
|
||||||
// A call to Rcpt must be preceded by a call to Mail and may be followed by
|
// A call to Rcpt must be preceded by a call to [Client.Mail] and may be followed by
|
||||||
// a Data call or another Rcpt call.
|
// a [Client.Data] call or another Rcpt call.
|
||||||
func (c *Client) Rcpt(to string) error {
|
func (c *Client) Rcpt(to string) error {
|
||||||
if err := validateLine(to); err != nil {
|
if err := validateLine(to); err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -288,7 +288,7 @@ func (d *dataCloser) Close() error {
|
|||||||
// Data issues a DATA command to the server and returns a writer that
|
// Data issues a DATA command to the server and returns a writer that
|
||||||
// can be used to write the mail headers and body. The caller should
|
// can be used to write the mail headers and body. The caller should
|
||||||
// close the writer before calling any more methods on c. A call to
|
// close the writer before calling any more methods on c. A call to
|
||||||
// Data must be preceded by one or more calls to Rcpt.
|
// Data must be preceded by one or more calls to [Client.Rcpt].
|
||||||
func (c *Client) Data() (io.WriteCloser, error) {
|
func (c *Client) Data() (io.WriteCloser, error) {
|
||||||
_, _, err := c.cmd(354, "DATA")
|
_, _, err := c.cmd(354, "DATA")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -445,9 +445,7 @@ func (c *Client) Noop() error {
|
|||||||
|
|
||||||
// Quit sends the QUIT command and closes the connection to the server.
|
// Quit sends the QUIT command and closes the connection to the server.
|
||||||
func (c *Client) Quit() error {
|
func (c *Client) Quit() error {
|
||||||
if err := c.hello(); err != nil {
|
c.hello() // ignore error; we're quitting anyhow
|
||||||
return err
|
|
||||||
}
|
|
||||||
_, _, err := c.cmd(221, "QUIT")
|
_, _, err := c.cmd(221, "QUIT")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -455,7 +453,7 @@ func (c *Client) Quit() error {
|
|||||||
return c.Text.Close()
|
return c.Text.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
// validateLine checks to see if a line has CR or LF as per RFC 5321
|
// validateLine checks to see if a line has CR or LF as per RFC 5321.
|
||||||
func validateLine(line string) error {
|
func validateLine(line string) error {
|
||||||
if strings.ContainsAny(line, "\n\r") {
|
if strings.ContainsAny(line, "\n\r") {
|
||||||
return errors.New("smtp: A line must not contain CR or LF")
|
return errors.New("smtp: A line must not contain CR or LF")
|
||||||
|
|||||||
@@ -83,7 +83,7 @@
|
|||||||
; authentication before they can send mail.
|
; authentication before they can send mail.
|
||||||
; File format: username bcrypt-hash [email[,email[,...]]]
|
; File format: username bcrypt-hash [email[,email[,...]]]
|
||||||
; username: The SMTP auth username
|
; username: The SMTP auth username
|
||||||
; bcrypt-hash: The bcrypt hash of the pasword (generate with "./hasher password")
|
; bcrypt-hash: The bcrypt hash of the pasword
|
||||||
; email: Comma-separated list of allowed "from" addresses:
|
; email: Comma-separated list of allowed "from" addresses:
|
||||||
; - If omitted, user can send from any address
|
; - If omitted, user can send from any address
|
||||||
; - If @domain.com is given, user can send from any address @domain.com
|
; - If @domain.com is given, user can send from any address @domain.com
|
||||||
|
|||||||
Reference in New Issue
Block a user