Files
3f5b3cdd98 feat: add configurable SMTP HELO hostname (#2146)
* feat: add configurable SMTP HELO hostname

Allow the SMTP HELO/EHLO hostname to be configured separately from
the SMTP server hostname.

This is useful when the SMTP server requires clients to identify
themselves with a fully qualified hostname different from the server
address.

* chore: remove vendored dependency changes

* Bump go-pkgz/notify to v1.4.0 and document SMTP_HELO_HOST

The HELOHost field lands in go-pkgz/notify v1.4.0, so the branch needs the
bump to compile; v1.3.0 in master has no such field. The example module is
tidied alongside, as any change to backend/go.mod requires.

Documents the parameter in the parameters table and, separately, in the email
setup page: what it does, that leaving it unset keeps the previous `localhost`
greeting, and the case it exists for, a relay refusing the greeting under
Postfix `reject_non_fqdn_helo_hostname`.

Also records the current limit: verification emails for email authentication
go through go-pkgz/auth's own sender, which has no equivalent setting, so the
greeting there is unchanged.

* Bump go-pkgz/auth to v2.2.0 and apply SMTP_HELO_HOST to verification email

The verification email sender had no way to set the greeting, so a relay that
refuses the HELO would accept notifications and still reject sign-in emails.
EmailParams gains HELOHost in go-pkgz/auth v2.2.0, so the same SMTP_HELO_HOST
now drives both paths.

The example module is tidied alongside, as any change to backend/go.mod
requires.

---------

Co-authored-by: oli <someone@somewhere.tld>
Co-authored-by: Dmitry Verkhoturov <paskal.07@gmail.com>
2026-08-19 02:52:39 -05:00

126 lines
3.7 KiB
Go

package stats
// MovingMedian calculates the rolling median of the input over a trailing
// window. Only fully-populated windows produce output, so the result has
// len(input)-window+1 entries and entry i is the median of input[i : i+window].
// The window must satisfy 1 <= window <= len(input) or ErrBounds is
// returned. An empty input returns ErrEmptyInput.
func MovingMedian(input Float64Data, window int) ([]float64, error) {
if input.Len() == 0 {
return nil, ErrEmptyInput
}
if window < 1 || window > input.Len() {
return nil, ErrBounds
}
output := make([]float64, input.Len()-window+1)
for i := range output {
// Median cannot fail here since every window is non-empty
median, _ := Median(input[i : i+window])
output[i] = median
}
return output, nil
}
// MovingMin calculates the rolling minimum of the input over a trailing
// window. Only fully-populated windows produce output, so the result has
// len(input)-window+1 entries and entry i is the minimum of
// input[i : i+window]. The window must satisfy 1 <= window <= len(input) or
// ErrBounds is returned. An empty input returns ErrEmptyInput.
func MovingMin(input Float64Data, window int) ([]float64, error) {
if input.Len() == 0 {
return nil, ErrEmptyInput
}
if window < 1 || window > input.Len() {
return nil, ErrBounds
}
output := make([]float64, input.Len()-window+1)
for i := range output {
// Min cannot fail here since every window is non-empty
min, _ := Min(input[i : i+window])
output[i] = min
}
return output, nil
}
// MovingMax calculates the rolling maximum of the input over a trailing
// window. Only fully-populated windows produce output, so the result has
// len(input)-window+1 entries and entry i is the maximum of
// input[i : i+window]. The window must satisfy 1 <= window <= len(input) or
// ErrBounds is returned. An empty input returns ErrEmptyInput.
func MovingMax(input Float64Data, window int) ([]float64, error) {
if input.Len() == 0 {
return nil, ErrEmptyInput
}
if window < 1 || window > input.Len() {
return nil, ErrBounds
}
output := make([]float64, input.Len()-window+1)
for i := range output {
// Max cannot fail here since every window is non-empty
max, _ := Max(input[i : i+window])
output[i] = max
}
return output, nil
}
// MovingSum calculates the rolling sum of the input over a trailing
// window. Only fully-populated windows produce output, so the result has
// len(input)-window+1 entries and entry i is the sum of input[i : i+window].
// The window must satisfy 1 <= window <= len(input) or ErrBounds is
// returned. An empty input returns ErrEmptyInput.
func MovingSum(input Float64Data, window int) ([]float64, error) {
if input.Len() == 0 {
return nil, ErrEmptyInput
}
if window < 1 || window > input.Len() {
return nil, ErrBounds
}
output := make([]float64, input.Len()-window+1)
for i := range output {
// Sum cannot fail here since every window is non-empty
sum, _ := Sum(input[i : i+window])
output[i] = sum
}
return output, nil
}
// MovingMedian returns the rolling median of the data over a trailing window
func (f Float64Data) MovingMedian(window int) ([]float64, error) {
return MovingMedian(f, window)
}
// MovingMin returns the rolling minimum of the data over a trailing window
func (f Float64Data) MovingMin(window int) ([]float64, error) {
return MovingMin(f, window)
}
// MovingMax returns the rolling maximum of the data over a trailing window
func (f Float64Data) MovingMax(window int) ([]float64, error) {
return MovingMax(f, window)
}
// MovingSum returns the rolling sum of the data over a trailing window
func (f Float64Data) MovingSum(window int) ([]float64, error) {
return MovingSum(f, window)
}