Blob


1 package mailmux
3 import (
4 "errors"
5 )
7 // User represents a mailmux user.
8 type User struct {
9 // The name should be a valid email address.
10 name string
11 password Password
12 }
14 type Password []byte
16 // A UserStore provides storage and authentication of users.
17 type UserStore interface {
18 // Change creates or updates the named user with the new password.
19 Change(name string, new Password) error
20 // Lookup returns the User with name.
21 // The error should be ErrUnknownUser if the user is not found.
22 Lookup(name string) (User, error)
23 // Delete removes the user from the store.
24 Delete(name string) error
25 // Authenticate authenticates the user identified by username with pw.
26 // error is non-nil if the password is incorrect or on any other error.
27 Authenticate(username string, pw Password) error
28 }
30 type ticket []byte
32 var testTicket = []byte(`TEST NOT REAL`)
34 var (
35 ErrUserExist = errors.New("user already exists")
36 ErrUnknownUser = errors.New("unknown user")
37 )
39 // verified checks whether ownership of username's address has
40 // been confirmed.
41 // func (store *astore) verified(username string) (bool, error) {
42 // _, err := store.Lookup(username)
43 // if errors.Is(err, ErrUnknownUser) {
44 // return false, err
45 // }
46 //
47 // _, err = os.Stat(path.Join(store.confirmDir, username))
48 // if err == nil {
49 // return false, nil
50 // }
51 // if errors.Is(err, fs.ErrNotExist) {
52 // return true, nil
53 // }
54 // return false, fmt.Errorf("check confirm file: %w", err)
55 // }
57 // verify attempts to verify the username using the given token.
58 // func (store *astore) verify(username string, tok token) error {
59 // f, err := os.Open(path.Join(store.confirmDir, username))
60 // if errors.Is(err, fs.ErrNotExist) {
61 // return ErrUnknownUser
62 // } else if err != nil {
63 // return err
64 // }
65 // defer f.Close()
66 // b, err := io.ReadAll(f)
67 // if err != nil {
68 // return err
69 // }
70 // if bytes.Equal(b, []byte(tok)) {
71 // return os.Remove(path.Join(store.confirmDir, username))
72 // }
73 // return errors.New("mismatched token")
74 // }
76 func SendConfirmationMail(from, to string, tik ticket) error {
77 return nil
78 // From: $from
79 // To: $to
80 // Subject: Confirm address ownership
81 //
82 // Thanks for signing up to mailmux.net!
83 // Confirm ownership of $address by accessing the following link:
84 // https://mailmux.net/confirm?username=test@example.com&token=abcd12345
85 // Alternatively, go to https://mailmux.net/confirm
86 // enter your email address and your token:
87 // abcd12345
88 //
89 // If you have not signed up for mailmux.net, please
90 // let us know by forwarding this mail to abuse@mailmux.net.
91 // Thank you for helping us fight spam!
92 }