-
Notifications
You must be signed in to change notification settings - Fork 1
Add Inbound Email API commands #10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mklocek
wants to merge
7
commits into
main
Choose a base branch
from
inbound-v2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
1a6715a
Add inbound folders and inboxes commands
mklocek ba84703
Add inbound messages and threads commands
mklocek 98e2cc7
Surface inbound fields on existing commands
mklocek c98e2e0
Add inbound command tests
mklocek 9388c5b
Document inbound commands
mklocek 61c1402
Fix webhook create flag help
mklocek 16cba72
Surface pagination cursor in list output
mklocek File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| package cmdutil | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "regexp" | ||
| "strings" | ||
| ) | ||
|
|
||
| // EmailAddr represents an email address with an optional display name. | ||
| type EmailAddr struct { | ||
| Email string `json:"email"` | ||
| Name string `json:"name,omitempty"` | ||
| } | ||
|
|
||
| var emailAddrRe = regexp.MustCompile(`^(.+?)\s*<([^>]+)>$`) | ||
|
|
||
| // ParseEmailAddr parses an email address string in either "email" or "Name <email>" format. | ||
| func ParseEmailAddr(s string) (EmailAddr, error) { | ||
| s = strings.TrimSpace(s) | ||
| if s == "" { | ||
| return EmailAddr{}, fmt.Errorf("empty email address") | ||
| } | ||
|
|
||
| // Try "Name <email>" format. | ||
| if matches := emailAddrRe.FindStringSubmatch(s); matches != nil { | ||
| return EmailAddr{ | ||
| Name: strings.TrimSpace(matches[1]), | ||
| Email: strings.TrimSpace(matches[2]), | ||
| }, nil | ||
| } | ||
|
|
||
| // Plain email address. | ||
| return EmailAddr{Email: s}, nil | ||
| } | ||
|
|
||
| // ParseEmailAddrs parses a slice of email address strings. | ||
| func ParseEmailAddrs(addrs []string) ([]EmailAddr, error) { | ||
| result := make([]EmailAddr, 0, len(addrs)) | ||
| for _, s := range addrs { | ||
| addr, err := ParseEmailAddr(s) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("invalid email address %q: %w", s, err) | ||
| } | ||
| result = append(result, addr) | ||
| } | ||
| return result, nil | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| package folders | ||
|
|
||
| import ( | ||
| "context" | ||
|
|
||
| "github.com/mailtrap/mailtrap-cli/internal/client" | ||
| "github.com/mailtrap/mailtrap-cli/internal/cmdutil" | ||
| "github.com/mailtrap/mailtrap-cli/internal/output" | ||
| "github.com/spf13/cobra" | ||
| ) | ||
|
|
||
| func NewCmdCreate(f *cmdutil.Factory) *cobra.Command { | ||
| var name string | ||
|
|
||
| cmd := &cobra.Command{ | ||
| Use: "create", | ||
| Short: "Create an inbound folder", | ||
| RunE: func(cmd *cobra.Command, args []string) error { | ||
| if err := cmdutil.RequireFlag("name", name); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| c, err := f.NewClient() | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| body := map[string]interface{}{"name": name} | ||
|
|
||
| var resp InboundFolder | ||
| if err := c.Post(context.Background(), client.BaseGeneral, "/api/inbound/folders", body, &resp); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| return output.Print(f.IOStreams.Out, cmdutil.GetOutputFormat(), resp, folderColumns) | ||
| }, | ||
| } | ||
|
|
||
| cmd.Flags().StringVar(&name, "name", "", "Folder name (required)") | ||
|
|
||
| return cmd | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| package folders | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
|
|
||
| "github.com/mailtrap/mailtrap-cli/internal/client" | ||
| "github.com/mailtrap/mailtrap-cli/internal/cmdutil" | ||
| "github.com/spf13/cobra" | ||
| ) | ||
|
|
||
| func NewCmdDelete(f *cmdutil.Factory) *cobra.Command { | ||
| var folderID string | ||
|
|
||
| cmd := &cobra.Command{ | ||
| Use: "delete", | ||
| Short: "Delete an inbound folder", | ||
| RunE: func(cmd *cobra.Command, args []string) error { | ||
| if err := cmdutil.RequireFlag("id", folderID); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| c, err := f.NewClient() | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| path := fmt.Sprintf("/api/inbound/folders/%s", folderID) | ||
|
|
||
| if err := c.Delete(context.Background(), client.BaseGeneral, path, nil); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| fmt.Fprintln(f.IOStreams.Out, "Inbound folder deleted successfully.") | ||
| return nil | ||
| }, | ||
| } | ||
|
|
||
| cmd.Flags().StringVar(&folderID, "id", "", "Folder ID (required)") | ||
|
|
||
| return cmd | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| package folders | ||
|
|
||
| import ( | ||
| "github.com/mailtrap/mailtrap-cli/internal/cmdutil" | ||
| "github.com/spf13/cobra" | ||
| ) | ||
|
|
||
| // NewCmdFolders creates the `inbound folders` command group. | ||
| func NewCmdFolders(f *cmdutil.Factory) *cobra.Command { | ||
| cmd := &cobra.Command{ | ||
| Use: "folders", | ||
| Short: "Manage inbound folders", | ||
| } | ||
|
|
||
| cmd.AddCommand(NewCmdList(f)) | ||
| cmd.AddCommand(NewCmdGet(f)) | ||
| cmd.AddCommand(NewCmdCreate(f)) | ||
| cmd.AddCommand(NewCmdUpdate(f)) | ||
| cmd.AddCommand(NewCmdDelete(f)) | ||
|
|
||
| return cmd | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.