1/*2Maddy Mail Server - Composable all-in-one email server.3Copyright © 2019-2020 Max Mazurov <fox.cpp@disroot.org>, Maddy Mail Server contributors45This program is free software: you can redistribute it and/or modify6it under the terms of the GNU General Public License as published by7the Free Software Foundation, either version 3 of the License, or8(at your option) any later version.910This program is distributed in the hope that it will be useful,11but WITHOUT ANY WARRANTY; without even the implied warranty of12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the13GNU General Public License for more details.1415You should have received a copy of the GNU General Public License16along with this program. If not, see <https://www.gnu.org/licenses/>.17*/1819package ctl2021import (22 "fmt"2324 imapbackend "github.com/emersion/go-imap/backend"25 "github.com/foxcpp/maddy/framework/module"26 "github.com/urfave/cli/v2"27)2829// Copied from go-imap-backend-tests.3031// AppendLimitUser is extension for backend.User interface which allows to32// set append limit value for testing and administration purposes.33type AppendLimitUser interface {34 imapbackend.AppendLimitUser3536 // SetMessageLimit sets new value for limit.37 // nil pointer means no limit.38 SetMessageLimit(val *uint32) error39}4041func imapAcctAppendlimit(be module.Storage, ctx *cli.Context) error {42 username := ctx.Args().First()43 if username == "" {44 return cli.Exit("Error: USERNAME is required", 2)45 }4647 u, err := be.GetIMAPAcct(username)48 if err != nil {49 return err50 }51 userAL, ok := u.(AppendLimitUser)52 if !ok {53 return cli.Exit("Error: module.Storage does not support per-user append limit", 2)54 }5556 if ctx.IsSet("value") {57 val := ctx.Int("value")5859 var err error60 if val == -1 {61 err = userAL.SetMessageLimit(nil)62 } else {63 val32 := uint32(val)64 err = userAL.SetMessageLimit(&val32)65 }66 if err != nil {67 return err68 }69 } else {70 lim := userAL.CreateMessageLimit()71 if lim == nil {72 fmt.Println("No limit")73 } else {74 fmt.Println(*lim)75 }76 }7778 return nil79}