1
0
mirror of https://github.com/directorz/mailfull-go.git synced 2025-12-17 17:47:04 +00:00

Implement set/unset a CatchAllUser

This commit is contained in:
teru
2016-08-10 19:45:23 +09:00
parent a7602a3180
commit bb0e30ac18

View File

@@ -2,6 +2,7 @@ package mailfull
import (
"bufio"
"fmt"
"os"
"path/filepath"
)
@@ -65,3 +66,45 @@ func (r *Repository) CatchAllUser(domainName string) (*CatchAllUser, error) {
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
}