Loading NOTES.md +3 −2 Original line number Diff line number Diff line Loading @@ -29,7 +29,7 @@ repl.commands? * Implement each command. * Next: folder commands - ~~CREATE~~, ~~REMOVE~~, MODIFY, ~~INDEX~~, ~~SELECT~~ * Messages: ~~ADD~~, CURRENT, DIRECTORY, BACK, CHANGE, FIRST, REMOVE, NEXT, READ * Messages: ~~ADD~~, CURRENT, ~~DIRECTORY~~, BACK, CHANGE, FIRST, REMOVE, NEXT, ~~READ~~ * Messages edit: CHANGE, REPLY, FORWARD * Moving messages: COPY, MOVE * Compound commands: SET and SHOW Loading Loading @@ -60,7 +60,8 @@ repl.commands? * Commands for a local mail system? * Commands to connect to Mattermost or mastodon? * Commands to manage users. * `SHOW VERSION` - use [this](https://github.com/earthboundkid/versioninfo) * `SHOW VERSION` - versioninfo doesn't work; what else? * Check db version; notify user if it changes; refuse to write to db if it has. ## Module links Loading dclish/dclish.go +4 −0 Original line number Diff line number Diff line Loading @@ -140,6 +140,10 @@ func (c Commands) ParseAndRun(line string) error { } cmd.Args = []string{} if len(words) == 1 { if len(cmd.Args) < cmd.MinArgs { fmt.Println("ERROR: Not enough args.") return nil } return cmd.Action(cmd) } // TODO: need to clean this up. Loading editor/tview.go +14 −0 Original line number Diff line number Diff line Loading @@ -10,6 +10,20 @@ import ( // Editor is the editor for text files. func Editor(placeholder, title string) (string, error) { theme := tview.Theme{ PrimitiveBackgroundColor: tcell.ColorDefault, ContrastBackgroundColor: tcell.ColorDefault, MoreContrastBackgroundColor: tcell.ColorDefault, BorderColor: tcell.ColorDefault, TitleColor: tcell.ColorDefault, GraphicsColor: tcell.ColorDefault, PrimaryTextColor: tcell.ColorDefault, SecondaryTextColor: tcell.ColorDefault, TertiaryTextColor: tcell.ColorDefault, InverseTextColor: tcell.ColorDefault, ContrastSecondaryTextColor: tcell.ColorDefault, } tview.Styles = theme app := tview.NewApplication() textArea := tview.NewTextArea(). Loading folders/folders.go +19 −0 Original line number Diff line number Diff line Loading @@ -4,6 +4,7 @@ package folders import ( "errors" "fmt" "strings" "github.com/jmoiron/sqlx" ) Loading Loading @@ -34,6 +35,10 @@ type FolderCreateOptions struct { // CreateFolder creates a new folder. func (s *Store) CreateFolder(name string, options FolderCreateOptions) error { if !IsAlphaNum(name) { return errors.New("Folder can only have letters and numbers") } name = strings.ToUpper(name) _, err := s.db.Exec( `INSERT INTO folders (name, always, brief, description, notify, owner, readnew, Loading @@ -52,6 +57,7 @@ func (s *Store) CreateFolder(name string, options FolderCreateOptions) error { options.Expire, options.Visibility, ) // TODO: turn _ into rows and make sure it was added. // TODO: process this error a bit more to give a better error message. return err } Loading Loading @@ -102,6 +108,19 @@ func (s *Store) ListFolder(user string, _ FolderListOptions) ([]FolderListRow, e return flr, nil } // FindFolder finds a folder based on the prefix. func (s *Store) FindFolder(name string) string { var folder string s.db.Get(&folder, "SELECT name FROM folders where name = $1", name) if folder != "" { return folder } s.db.Get(&folder, `SELECT name FROM folders where name LIKE $1 ORDER BY name LIMIT 1`, name+"%") return folder } // IsFolderAccess checks if a user can access a folder. func (s *Store) IsFolderAccess(name, user string) bool { found := 0 Loading folders/messages.go +36 −6 Original line number Diff line number Diff line Loading @@ -2,6 +2,7 @@ package folders import ( "errors" "fmt" "strings" "time" Loading Loading @@ -66,16 +67,45 @@ func (m *Message) String() string { // ReadMessage reads a message for a user. func (s *Store) ReadMessage(login, folder string, msgid int) (*Message, error) { msg := &Message{} err := s.db.Get(msg, s.db.Get(msg, `SELECT id, folder, author, subject, message, expiration, create_at, update_at FROM messages WHERE folder = $1, id = $2`, folder, msgid) if err != nil { return nil, err FROM messages WHERE folder = $1 AND id = $2`, folder, msgid) if msg.ID != msgid || msgid == 0 { return nil, errors.New("Specified message was not found") } // TODO: replace _ with rows and check. _, err = s.db.Exec( s.db.Exec( "INSERT INTO read (login, folder, msgid) VALUES ($1, $2, $3)", login, folder, msgid) return msg, err return msg, nil } // ListMessagesOptions has the options for a ListMessages call. type ListMessagesOptions struct { // TODO: is this needed? Maybe for message order? } // ListMessages lists messages. func (s *Store) ListMessages(folder string, options *ListMessagesOptions) ([]Message, error) { messages := []Message{} if options != nil { return messages, errors.New("TODO: options aren't implemented") } rows, err := s.db.Queryx( `SELECT id, folder, author, subject, message, expiration, create_at, update_at FROM messages WHERE folder = $1`, folder) if err != nil { return messages, nil } for rows.Next() { msg := Message{} err = rows.StructScan(&msg) if err != nil { return []Message{}, nil } messages = append(messages, msg) } return messages, nil } Loading
NOTES.md +3 −2 Original line number Diff line number Diff line Loading @@ -29,7 +29,7 @@ repl.commands? * Implement each command. * Next: folder commands - ~~CREATE~~, ~~REMOVE~~, MODIFY, ~~INDEX~~, ~~SELECT~~ * Messages: ~~ADD~~, CURRENT, DIRECTORY, BACK, CHANGE, FIRST, REMOVE, NEXT, READ * Messages: ~~ADD~~, CURRENT, ~~DIRECTORY~~, BACK, CHANGE, FIRST, REMOVE, NEXT, ~~READ~~ * Messages edit: CHANGE, REPLY, FORWARD * Moving messages: COPY, MOVE * Compound commands: SET and SHOW Loading Loading @@ -60,7 +60,8 @@ repl.commands? * Commands for a local mail system? * Commands to connect to Mattermost or mastodon? * Commands to manage users. * `SHOW VERSION` - use [this](https://github.com/earthboundkid/versioninfo) * `SHOW VERSION` - versioninfo doesn't work; what else? * Check db version; notify user if it changes; refuse to write to db if it has. ## Module links Loading
dclish/dclish.go +4 −0 Original line number Diff line number Diff line Loading @@ -140,6 +140,10 @@ func (c Commands) ParseAndRun(line string) error { } cmd.Args = []string{} if len(words) == 1 { if len(cmd.Args) < cmd.MinArgs { fmt.Println("ERROR: Not enough args.") return nil } return cmd.Action(cmd) } // TODO: need to clean this up. Loading
editor/tview.go +14 −0 Original line number Diff line number Diff line Loading @@ -10,6 +10,20 @@ import ( // Editor is the editor for text files. func Editor(placeholder, title string) (string, error) { theme := tview.Theme{ PrimitiveBackgroundColor: tcell.ColorDefault, ContrastBackgroundColor: tcell.ColorDefault, MoreContrastBackgroundColor: tcell.ColorDefault, BorderColor: tcell.ColorDefault, TitleColor: tcell.ColorDefault, GraphicsColor: tcell.ColorDefault, PrimaryTextColor: tcell.ColorDefault, SecondaryTextColor: tcell.ColorDefault, TertiaryTextColor: tcell.ColorDefault, InverseTextColor: tcell.ColorDefault, ContrastSecondaryTextColor: tcell.ColorDefault, } tview.Styles = theme app := tview.NewApplication() textArea := tview.NewTextArea(). Loading
folders/folders.go +19 −0 Original line number Diff line number Diff line Loading @@ -4,6 +4,7 @@ package folders import ( "errors" "fmt" "strings" "github.com/jmoiron/sqlx" ) Loading Loading @@ -34,6 +35,10 @@ type FolderCreateOptions struct { // CreateFolder creates a new folder. func (s *Store) CreateFolder(name string, options FolderCreateOptions) error { if !IsAlphaNum(name) { return errors.New("Folder can only have letters and numbers") } name = strings.ToUpper(name) _, err := s.db.Exec( `INSERT INTO folders (name, always, brief, description, notify, owner, readnew, Loading @@ -52,6 +57,7 @@ func (s *Store) CreateFolder(name string, options FolderCreateOptions) error { options.Expire, options.Visibility, ) // TODO: turn _ into rows and make sure it was added. // TODO: process this error a bit more to give a better error message. return err } Loading Loading @@ -102,6 +108,19 @@ func (s *Store) ListFolder(user string, _ FolderListOptions) ([]FolderListRow, e return flr, nil } // FindFolder finds a folder based on the prefix. func (s *Store) FindFolder(name string) string { var folder string s.db.Get(&folder, "SELECT name FROM folders where name = $1", name) if folder != "" { return folder } s.db.Get(&folder, `SELECT name FROM folders where name LIKE $1 ORDER BY name LIMIT 1`, name+"%") return folder } // IsFolderAccess checks if a user can access a folder. func (s *Store) IsFolderAccess(name, user string) bool { found := 0 Loading
folders/messages.go +36 −6 Original line number Diff line number Diff line Loading @@ -2,6 +2,7 @@ package folders import ( "errors" "fmt" "strings" "time" Loading Loading @@ -66,16 +67,45 @@ func (m *Message) String() string { // ReadMessage reads a message for a user. func (s *Store) ReadMessage(login, folder string, msgid int) (*Message, error) { msg := &Message{} err := s.db.Get(msg, s.db.Get(msg, `SELECT id, folder, author, subject, message, expiration, create_at, update_at FROM messages WHERE folder = $1, id = $2`, folder, msgid) if err != nil { return nil, err FROM messages WHERE folder = $1 AND id = $2`, folder, msgid) if msg.ID != msgid || msgid == 0 { return nil, errors.New("Specified message was not found") } // TODO: replace _ with rows and check. _, err = s.db.Exec( s.db.Exec( "INSERT INTO read (login, folder, msgid) VALUES ($1, $2, $3)", login, folder, msgid) return msg, err return msg, nil } // ListMessagesOptions has the options for a ListMessages call. type ListMessagesOptions struct { // TODO: is this needed? Maybe for message order? } // ListMessages lists messages. func (s *Store) ListMessages(folder string, options *ListMessagesOptions) ([]Message, error) { messages := []Message{} if options != nil { return messages, errors.New("TODO: options aren't implemented") } rows, err := s.db.Queryx( `SELECT id, folder, author, subject, message, expiration, create_at, update_at FROM messages WHERE folder = $1`, folder) if err != nil { return messages, nil } for rows.Next() { msg := Message{} err = rows.StructScan(&msg) if err != nil { return []Message{}, nil } messages = append(messages, msg) } return messages, nil }