guido+sievemgr@1: // Copyright (C) 2020 Guido Berhoerster guido+sievemgr@0: // guido+sievemgr@0: // Permission is hereby granted, free of charge, to any person obtaining guido+sievemgr@0: // a copy of this software and associated documentation files (the guido+sievemgr@0: // "Software"), to deal in the Software without restriction, including guido+sievemgr@0: // without limitation the rights to use, copy, modify, merge, publish, guido+sievemgr@0: // distribute, sublicense, and/or sell copies of the Software, and to guido+sievemgr@0: // permit persons to whom the Software is furnished to do so, subject to guido+sievemgr@0: // the following conditions: guido+sievemgr@0: // guido+sievemgr@0: // The above copyright notice and this permission notice shall be included guido+sievemgr@0: // in all copies or substantial portions of the Software. guido+sievemgr@0: // guido+sievemgr@0: // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, guido+sievemgr@0: // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF guido+sievemgr@0: // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. guido+sievemgr@0: // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY guido+sievemgr@0: // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, guido+sievemgr@0: // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE guido+sievemgr@0: // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. guido+sievemgr@0: guido+sievemgr@0: package main guido+sievemgr@0: guido+sievemgr@0: import ( guido+sievemgr@0: "net" guido+sievemgr@0: ) guido+sievemgr@0: guido+sievemgr@0: func init() { guido+sievemgr@0: cmdDelete.Flag.StringVar(&username, "u", "", "Set the username") guido+sievemgr@0: cmdDelete.Flag.StringVar(&passwordFilename, "P", "", guido+sievemgr@0: "Set the name of the password file") guido+sievemgr@0: } guido+sievemgr@0: guido+sievemgr@0: var cmdDelete = &command{ guido+sievemgr@0: UsageLine: "delete [options] host[:port] name", guido+sievemgr@0: Run: runDelete, guido+sievemgr@0: } guido+sievemgr@0: guido+sievemgr@0: func runDelete(cmd *command, args []string) error { guido+sievemgr@0: if len(args) != 2 { guido+sievemgr@0: return usageError("invalid number of arguments") guido+sievemgr@0: } guido+sievemgr@0: guido+sievemgr@0: host, port, err := parseHostPort(args[0]) guido+sievemgr@0: if err != nil { guido+sievemgr@0: return err guido+sievemgr@0: } guido+sievemgr@0: guido+sievemgr@0: scriptName := args[1] guido+sievemgr@0: guido+sievemgr@0: username, password, err := usernamePassword(host, port, username, guido+sievemgr@0: passwordFilename) guido+sievemgr@0: if err != nil { guido+sievemgr@0: return err guido+sievemgr@0: } guido+sievemgr@0: guido+sievemgr@0: c, err := dialPlainAuth(net.JoinHostPort(host, port), username, guido+sievemgr@0: password) guido+sievemgr@0: if err != nil { guido+sievemgr@0: return err guido+sievemgr@0: } guido+sievemgr@0: defer c.Logout() guido+sievemgr@0: guido+sievemgr@0: if err := c.DeleteScript(scriptName); err != nil { guido+sievemgr@0: return err guido+sievemgr@0: } guido+sievemgr@0: guido+sievemgr@0: return nil guido+sievemgr@0: }