diff --git a/cmd/mailbox.go b/cmd/mailbox.go index 0c7fb82..2a500a6 100644 --- a/cmd/mailbox.go +++ b/cmd/mailbox.go @@ -7,6 +7,7 @@ import ( var ( quota int storageBasePath string + displayName string ) var mailboxCmd = &cobra.Command{ diff --git a/cmd/mailboxAdd.go b/cmd/mailboxAdd.go index 7cf48a9..31dd707 100644 --- a/cmd/mailboxAdd.go +++ b/cmd/mailboxAdd.go @@ -24,7 +24,7 @@ var mailboxAddCmd = &cobra.Command{ } if len(args[1]) < passwordMinLength { - return errors.New("[PLAIN_PASSWORD] length to short (min length " + strconv.Itoa(passwordMinLength) + ")") + return errors.New("[PLAIN_PASSWORD] length too short (min length " + strconv.Itoa(passwordMinLength) + ")") } return nil @@ -37,7 +37,7 @@ var mailboxAddCmd = &cobra.Command{ defer server.Close() mailboxEmail, password := args[0], args[1] - err = server.MailboxAdd(mailboxEmail, password, quota, storageBasePath) + err = server.MailboxAdd(mailboxEmail, password, quota, storageBasePath, displayName) if err != nil { fatal("%v\n", err) } @@ -51,6 +51,7 @@ func init() { mailboxAddCmd.Flags().IntVarP("a, "quota", "q", 2048, "Quota (default 2048 MB)") mailboxAddCmd.Flags().StringVarP(&storageBasePath, "storage-path", "s", "/var/vmail/vmail1", "Storage base path") + mailboxAddCmd.Flags().StringVarP(&displayName, "name", "n", "", "Display Name") mailboxAddCmd.SetUsageTemplate(usageTemplate("mailbox add [MAILBOX_EMAIL] [PLAIN_PASSWORD]", printFlags)) } diff --git a/cmd/mailboxInfo.go b/cmd/mailboxInfo.go index 388d11e..1bafa58 100644 --- a/cmd/mailboxInfo.go +++ b/cmd/mailboxInfo.go @@ -72,6 +72,7 @@ func printMailboxInfo(mailbox iredmail.Mailbox, prettyPrint bool) { table.SetColumnColor(tablewriter.Colors{tablewriter.Bold}, tablewriter.Colors{}) } + table.Append([]string{"Display Name", mailbox.Name}) table.Append([]string{"Quota", fmt.Sprintf("%v MB", strconv.Itoa(mailbox.Quota))}) if len(mailbox.MailboxAliases) > 0 { diff --git a/cmd/mailboxList.go b/cmd/mailboxList.go index 929431b..eb33675 100644 --- a/cmd/mailboxList.go +++ b/cmd/mailboxList.go @@ -50,10 +50,10 @@ func printUserList(mailboxes iredmail.Mailboxes) { } table := tablewriter.NewWriter(os.Stdout) - table.SetHeader([]string{"Mailbox", "Quota (MB)"}) + table.SetHeader([]string{"Display Name", "Mailbox", "Quota (MB)"}) for _, m := range mailboxes { - table.Append([]string{m.Email, strconv.Itoa(m.Quota)}) + table.Append([]string{m.Name, m.Email, strconv.Itoa(m.Quota)}) } table.Render() } diff --git a/cmd/mailboxUpdate.go b/cmd/mailboxUpdate.go index 6fa8388..6710b0b 100644 --- a/cmd/mailboxUpdate.go +++ b/cmd/mailboxUpdate.go @@ -31,8 +31,8 @@ var ( // mailboxUpdateCmd represents the 'mailbox update' command var mailboxUpdateCmd = &cobra.Command{ Use: "update", - Short: "Update keep-copy and quota", - Long: `Update keep-copy and quota. + Short: "Update keep-copy, password, quota, and name", + Long: `Update keep-copy, password, quota, and name. -k, --keep-copy: If mailboxes with forwardings should not keep a copy of the forwarded email use "--keep-copy no". @@ -74,6 +74,15 @@ Set quota "--quota 4096" (in MB).`, updated = true } + if cmd.Flag("name").Changed { + err = server.MailboxSetName(mailboxEmail, displayName) + if err != nil { + fatal("%v\n", err) + } + info("Updating quota...\n") + updated = true + } + if cmd.Flag("keep-copy").Changed { err := server.MailboxSetKeepCopy(mailboxEmail, keepCopyInMailbox == "yes") if err != nil { @@ -86,7 +95,7 @@ Set quota "--quota 4096" (in MB).`, if cmd.Flag("password").Changed { pw := cmd.Flag("password").Value.String() if len(pw) < passwordMinLength { - fatal("password length to short (min length " + strconv.Itoa(passwordMinLength) + ")") + fatal("password length too short (min length " + strconv.Itoa(passwordMinLength) + ")") } err := server.MailboxSetPassword(mailboxEmail, pw) if err != nil { @@ -110,6 +119,7 @@ func init() { mailboxUpdateCmd.Flags().IntVarP("a, "quota", "q", 2048, "Sets quota (in MB)") mailboxUpdateCmd.Flags().StringVarP(&keepCopyInMailbox, "keep-copy", "k", "yes", "Sets keep-copy of forwardings") mailboxUpdateCmd.Flags().StringP("password", "p", "", "Set password") + mailboxUpdateCmd.Flags().StringVarP(&displayName, "name", "n", "", "Display Name") mailboxUpdateCmd.SetUsageTemplate(usageTemplate("mailbox update [MAILBOX_EMAIL]", printFlags)) } diff --git a/iredmail/mailbox.go b/iredmail/mailbox.go index 2d8a486..4cb613f 100644 --- a/iredmail/mailbox.go +++ b/iredmail/mailbox.go @@ -129,9 +129,13 @@ func (s *Server) Mailbox(mailboxEmail string) (Mailbox, error) { } // MailboxAdd adds a new mailbox -func (s *Server) MailboxAdd(mailboxEmail, password string, quota int, storageBasePath string) error { +func (s *Server) MailboxAdd(mailboxEmail, password string, quota int, storageBasePath string, displayName string) error { name, domain := parseEmail(mailboxEmail) + if displayName != "" { + name = displayName + } + m := Mailbox{ Email: mailboxEmail, Name: name, @@ -200,7 +204,7 @@ func (s *Server) MailboxAdd(mailboxEmail, password string, quota int, storageBas return err } -// MailboxDelete delets a mailbox +// MailboxDelete deletes a mailbox func (s *Server) MailboxDelete(mailboxEmail string) error { mailboxExists, err := s.mailboxExists(mailboxEmail) if err != nil { @@ -254,6 +258,21 @@ func (s *Server) MailboxSetQuota(mailboxEmail string, quota int) error { return err } + +// MailboxSetName sets the mailbox display name +func (s *Server) MailboxSetName(mailboxEmail string, displayName string) error { + sqlQuery := `UPDATE mailbox + SET name = ? + WHERE username = ?;` + _, err := s.DB.Exec(sqlQuery, displayName, mailboxEmail) + if err != nil { + return err + } + + return err +} + + // MailboxSetKeepCopy sets the keep-copy behavior if forwardings exist func (s *Server) MailboxSetKeepCopy(mailboxEmail string, keepCopyInMailbox bool) error { mailboxExists, err := s.mailboxExists(mailboxEmail) diff --git a/iredmail/mailboxAlias.go b/iredmail/mailboxAlias.go index b621ff8..d10f0a3 100644 --- a/iredmail/mailboxAlias.go +++ b/iredmail/mailboxAlias.go @@ -82,7 +82,7 @@ func (s *Server) MailboxAliasDelete(aliasEmail string) error { return err } -// MailboxAliasDeleteAll delets all mailbox aliases of a mailbox +// MailboxAliasDeleteAll deletes all mailbox aliases of a mailbox func (s *Server) MailboxAliasDeleteAll(mailboxEmail string) error { sqlQuery := "DELETE FROM forwardings WHERE forwarding = ? AND is_forwarding = 0 AND is_alias = 1 AND is_list = 0;" _, err := s.DB.Exec(sqlQuery, mailboxEmail) diff --git a/iredmail/version.go b/iredmail/version.go index 8ae3c73..8d95ae8 100644 --- a/iredmail/version.go +++ b/iredmail/version.go @@ -13,11 +13,11 @@ import ( const ( // Version of iredmail-cli - Version = "0.2.8" + Version = "0.2.9" releaseFile = "/etc/iredmail-release" - supportedReleaseMin = "0.9.8" - supportedReleaseMax = "0.9.8" + supportedReleaseMin = "1.0.0" + supportedReleaseMax = "1.2.0" ) var ( @@ -40,7 +40,7 @@ func GetIredMailVersion() (iredMailVersion, error) { return version, err } - re := regexp.MustCompile(`^\d\.\d\.\d\s*MYSQL\s*edition`) + re := regexp.MustCompile(`^\d\.\d\.\d\s*(MYSQL|MARIADB)\s*edition`) versionLine := re.FindString(string(file)) if versionLine == "" {