- Add pop mail search CLI command with pagination support - Create internal/labels package with types and API client - Add folder list/create/update/delete CLI commands - Add label list/create/update/delete/apply/remove CLI commands - Register folder and label commands in root.go - Fix gopenpgp v2 API mismatches in pgp.go (NewPlainMessage, Armor, KeyRing.Encrypt/Decrypt, SessionKey) - Fix NewSessionManager error handling across cmd files - Fix variable shadowing bug in mail/client.go
74 lines
1.7 KiB
Go
74 lines
1.7 KiB
Go
package cmd
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
|
|
"github.com/frenocorp/pop/internal/auth"
|
|
"github.com/frenocorp/pop/internal/config"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
func loginCmd() *cobra.Command {
|
|
cmd := &cobra.Command{
|
|
Use: "login",
|
|
Short: "Log in to ProtonMail",
|
|
Long: `Authenticate with ProtonMail API and store session credentials.`,
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
cfgMgr := config.NewConfigManager()
|
|
cfg, err := cfgMgr.Load()
|
|
if err != nil {
|
|
return fmt.Errorf("failed to load config: %w", err)
|
|
}
|
|
|
|
manager, err := auth.NewSessionManager()
|
|
if err != nil {
|
|
return fmt.Errorf("failed to create session manager: %w", err)
|
|
}
|
|
|
|
return manager.LoginInteractive(cfg.APIBaseURL)
|
|
},
|
|
}
|
|
|
|
return cmd
|
|
}
|
|
|
|
func logoutCmd() *cobra.Command {
|
|
cmd := &cobra.Command{
|
|
Use: "logout",
|
|
Short: "Log out from ProtonMail",
|
|
Long: `Clear stored session credentials.`,
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
manager, err := auth.NewSessionManager()
|
|
if err != nil {
|
|
return fmt.Errorf("failed to create session manager: %w", err)
|
|
}
|
|
return manager.Logout()
|
|
},
|
|
}
|
|
|
|
return cmd
|
|
}
|
|
|
|
func sessionCmd() *cobra.Command {
|
|
cmd := &cobra.Command{
|
|
Use: "session",
|
|
Short: "Show current session info",
|
|
Long: `Display current authentication session details.`,
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
manager, err := auth.NewSessionManager()
|
|
if err != nil {
|
|
return fmt.Errorf("failed to create session manager: %w", err)
|
|
}
|
|
session, err := manager.GetSession()
|
|
if err != nil {
|
|
return fmt.Errorf("no active session: %w", err)
|
|
}
|
|
fmt.Fprintf(os.Stdout, "Session: %s\n", session.UID)
|
|
return nil
|
|
},
|
|
}
|
|
|
|
return cmd
|
|
}
|