Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ pm-cli mail list --json # JSON output

```bash
pm-cli mail read 123 # Read message #123
pm-cli mail read 123 -m Archive # Read from a specific mailbox
pm-cli mail read 123 --json # JSON output with body
pm-cli mail read 123 --headers # Include all headers
pm-cli mail read 123 --html # Output HTML body
Expand Down
2 changes: 2 additions & 0 deletions docs/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ pm-cli mail read <id> [flags]
**Flags:**
| Flag | Description |
|------|-------------|
| `-m, --mailbox` | Mailbox name (defaults to configured mailbox) |
| `--raw` | Show raw MIME source |
| `--headers` | Include all headers |
| `--attachments` | List attachments only |
Expand All @@ -158,6 +159,7 @@ pm-cli mail read <id> [flags]
**Examples:**
```bash
pm-cli mail read 123
pm-cli mail read 123 -m Archive
pm-cli mail read 123 --headers
pm-cli mail read 123 --raw
pm-cli mail read 123 --html # View HTML content
Expand Down
1 change: 1 addition & 0 deletions internal/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ type MailListCmd struct {

type MailReadCmd struct {
ID string `arg:"" help:"Message ID or sequence number"`
Mailbox string `help:"Mailbox name" short:"m"`
Raw bool `help:"Show raw message"`
Headers bool `help:"Include all headers"`
Attachments bool `help:"List attachments"`
Expand Down
4 changes: 4 additions & 0 deletions internal/cli/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ func TestMailListCmdDefaults(t *testing.T) {
func TestMailReadCmdOptions(t *testing.T) {
cmd := MailReadCmd{
ID: "123",
Mailbox: "Archive",
Raw: true,
Headers: true,
Attachments: true,
Expand All @@ -130,6 +131,9 @@ func TestMailReadCmdOptions(t *testing.T) {
if cmd.ID != "123" {
t.Errorf("ID = %q, want %q", cmd.ID, "123")
}
if cmd.Mailbox != "Archive" {
t.Errorf("Mailbox = %q, want %q", cmd.Mailbox, "Archive")
}
if !cmd.Raw {
t.Error("Raw should be true")
}
Expand Down
4 changes: 4 additions & 0 deletions internal/cli/help.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,15 @@ func extractMailCommands() CommandSchema {
{Name: "id", Type: "string", Required: true, Description: "Message ID or sequence number"},
},
Flags: []FlagSchema{
{Name: "--mailbox", Short: "-m", Type: "string", Description: "Mailbox name (defaults to configured mailbox)"},
{Name: "--raw", Type: "bool", Description: "Show raw message"},
{Name: "--headers", Type: "bool", Description: "Include all headers"},
{Name: "--attachments", Type: "bool", Description: "List attachments only"},
{Name: "--html", Type: "bool", Description: "Output HTML body instead of plain text"},
},
Examples: []string{
"pm-cli mail read 123",
"pm-cli mail read 123 -m Archive",
"pm-cli mail read 123 --json",
"pm-cli mail read 123 --raw",
},
Expand Down
9 changes: 7 additions & 2 deletions internal/cli/mail.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ func (c *MailReadCmd) Run(ctx *Context) error {
return fmt.Errorf("not configured - run 'pm-cli config init' first")
}

mailbox := c.Mailbox
if mailbox == "" {
mailbox = ctx.Config.Defaults.Mailbox
}

client, err := imap.NewClient(ctx.Config)
if err != nil {
return err
Expand All @@ -138,7 +143,7 @@ func (c *MailReadCmd) Run(ctx *Context) error {

// Handle --attachments flag: list attachments only
if c.Attachments {
attachments, err := client.GetAttachments(ctx.Config.Defaults.Mailbox, c.ID)
attachments, err := client.GetAttachments(mailbox, c.ID)
if err != nil {
return err
}
Expand Down Expand Up @@ -170,7 +175,7 @@ func (c *MailReadCmd) Run(ctx *Context) error {
return nil
}

msg, err := client.GetMessage(ctx.Config.Defaults.Mailbox, c.ID)
msg, err := client.GetMessage(mailbox, c.ID)
if err != nil {
return err
}
Expand Down