forked from foxcpp/maddy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
imapAccounts.go
73 lines (60 loc) · 1.76 KB
/
imapAccounts.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package maddy
import (
"fmt"
"net/http"
"os"
"github.com/emersion/go-imap"
echo "github.com/labstack/echo/v4"
)
func createImapAccount(c echo.Context) error {
err := imapAcctCreate(c.Param("id"))
if err != nil {
return err
}
return c.NoContent(http.StatusCreated)
}
func deleteImapAccount(c echo.Context) error {
err := imapAcctRemove(c.Param("id"))
if err != nil {
return err
}
return c.NoContent(http.StatusOK)
}
func imapAcctCreate(username string) error {
if err := imapDb.CreateIMAPAcct(username); err != nil {
return err
}
act, err := imapDb.GetIMAPAcct(username)
if err != nil {
return fmt.Errorf("failed to get user: %w", err)
}
suu, ok := act.(SpecialUseUser)
if !ok {
fmt.Fprintf(os.Stderr, "Note: Storage backend does not support SPECIAL-USE IMAP extension")
}
createMbox := func(name, specialUseAttr string) error {
if suu == nil {
return act.CreateMailbox(name)
}
return suu.CreateMailboxSpecial(name, specialUseAttr)
}
if err := createMbox(mailboxes.SentName, imap.SentAttr); err != nil {
fmt.Fprintf(os.Stderr, "Failed to create sent folder: %v", err)
}
if err := createMbox(mailboxes.TrashName, imap.TrashAttr); err != nil {
fmt.Fprintf(os.Stderr, "Failed to create trash folder: %v", err)
}
if err := createMbox(mailboxes.JunkName, imap.JunkAttr); err != nil {
fmt.Fprintf(os.Stderr, "Failed to create junk folder: %v", err)
}
if err := createMbox(mailboxes.DraftsName, imap.DraftsAttr); err != nil {
fmt.Fprintf(os.Stderr, "Failed to create drafts folder: %v", err)
}
if err := createMbox(mailboxes.ArchiveName, imap.ArchiveAttr); err != nil {
fmt.Fprintf(os.Stderr, "Failed to create archive folder: %v", err)
}
return nil
}
func imapAcctRemove(username string) error {
return imapDb.DeleteIMAPAcct(username)
}