mirror of
https://github.com/directorz/mailfull-go.git
synced 2025-12-18 18:17:03 +00:00
Implement set/unset a CatchAllUser
This commit is contained in:
@@ -2,6 +2,7 @@ package mailfull
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
)
|
)
|
||||||
@@ -65,3 +66,45 @@ func (r *Repository) CatchAllUser(domainName string) (*CatchAllUser, error) {
|
|||||||
|
|
||||||
return catchAllUser, nil
|
return catchAllUser, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CatchAllUserSet sets a CatchAllUser to the input Domain.
|
||||||
|
func (r *Repository) CatchAllUserSet(domainName string, catchAllUser *CatchAllUser) error {
|
||||||
|
existUser, err := r.User(domainName, catchAllUser.Name())
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if existUser == nil {
|
||||||
|
return ErrUserNotExist
|
||||||
|
}
|
||||||
|
|
||||||
|
file, err := os.OpenFile(filepath.Join(r.DirMailDataPath, domainName, FileNameCatchAllUser), os.O_RDWR|os.O_TRUNC, 0666)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer file.Close()
|
||||||
|
|
||||||
|
if _, err := fmt.Fprintf(file, "%s\n", catchAllUser.Name()); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// CatchAllUserUnset removes a CatchAllUser from the input Domain.
|
||||||
|
func (r *Repository) CatchAllUserUnset(domainName string) error {
|
||||||
|
existDomain, err := r.Domain(domainName)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if existDomain == nil {
|
||||||
|
return ErrDomainNotExist
|
||||||
|
}
|
||||||
|
|
||||||
|
file, err := os.OpenFile(filepath.Join(r.DirMailDataPath, domainName, FileNameCatchAllUser), os.O_RDWR|os.O_TRUNC, 0666)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
file.Close()
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user