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
41 changes: 41 additions & 0 deletions internal/cmd/gmail_auto_from_env_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package cmd

import (
"encoding/json"
"testing"
)

func TestGmailAutoFromAddressedAliasEnvDefaults(t *testing.T) {
t.Setenv("GOG_GMAIL_AUTO_FROM_ADDRESSED_ALIAS", "1")

tests := []struct {
name string
args []string
}{
{name: "reply", args: []string{"gmail", "reply", "m1", "--body", "hello"}},
{name: "reply all", args: []string{"gmail", "reply-all", "m1", "--body", "hello"}},
{name: "draft create", args: []string{"gmail", "drafts", "create", "--to", "you@example.com", "--subject", "subject", "--body", "hello"}},
{name: "draft update", args: []string{"gmail", "drafts", "update", "d1", "--subject", "subject", "--body", "hello"}},
}

for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
args := append([]string{"--json", "--dry-run"}, tc.args...)
result := executeWithTestRuntime(t, args, nil)
if result.err != nil {
t.Fatalf("Execute: %v\nstderr=%q", result.err, result.stderr)
}
var output struct {
Request struct {
AutoFromAddressedAlias bool `json:"auto_from_addressed_alias"`
} `json:"request"`
}
if err := json.Unmarshal([]byte(result.stdout), &output); err != nil {
t.Fatalf("decode: %v\nout=%q", err, result.stdout)
}
if !output.Request.AutoFromAddressedAlias {
t.Fatalf("environment default was not applied: %s", result.stdout)
}
})
}
}
4 changes: 2 additions & 2 deletions internal/cmd/gmail_drafts.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ type GmailDraftsCreateCmd struct {
Quote bool `name:"quote" help:"Include quoted original message in reply (requires --reply-to-message-id or --thread-id)"`
Attach []string `name:"attach" help:"Attachment file path (repeatable)"`
From string `name:"from" help:"Send from this email address (must be a verified send-as alias)"`
AutoFromAddressedAlias bool `name:"auto-from-addressed-alias" help:"When --from is omitted, reply from the verified send-as alias addressed by the original message"`
AutoFromAddressedAlias bool `name:"auto-from-addressed-alias" help:"When --from is omitted, reply from the verified send-as alias addressed by the original message" env:"GOG_GMAIL_AUTO_FROM_ADDRESSED_ALIAS"`
}

type draftComposeInput struct {
Expand Down Expand Up @@ -784,7 +784,7 @@ type GmailDraftsUpdateCmd struct {
//nolint:lll // flag help text
ClearReplyContext bool `name:"clear-reply-context" help:"Strip In-Reply-To/References from the draft, making it a standalone message. By default an update preserves the draft's existing reply headers."`
From string `name:"from" help:"Send from this email address (must be a verified send-as alias)"`
AutoFromAddressedAlias bool `name:"auto-from-addressed-alias" help:"When --from is omitted, reply from the verified send-as alias addressed by the original message"`
AutoFromAddressedAlias bool `name:"auto-from-addressed-alias" help:"When --from is omitted, reply from the verified send-as alias addressed by the original message" env:"GOG_GMAIL_AUTO_FROM_ADDRESSED_ALIAS"`
}

func (c *GmailDraftsUpdateCmd) Run(ctx context.Context, flags *RootFlags) error {
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/gmail_reply_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type GmailReplyOptions struct {
NoQuote bool `name:"no-quote" help:"Do not include the original message below the reply"`
Attach []string `name:"attach" sep:"none" help:"Attachment file path (repeatable)"`
From string `name:"from" help:"Send from this email address (must be a verified send-as alias)"`
AutoFromAddressedAlias bool `name:"auto-from-addressed-alias" help:"When --from is omitted, reply from the verified send-as alias addressed by the original message"`
AutoFromAddressedAlias bool `name:"auto-from-addressed-alias" help:"When --from is omitted, reply from the verified send-as alias addressed by the original message" env:"GOG_GMAIL_AUTO_FROM_ADDRESSED_ALIAS"`

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Honor the environment setting in gmail forward

When GOG_GMAIL_AUTO_FROM_ADDRESSED_ALIAS=true is used with gog gmail forward, the setting is never read despite the commit describing forward as supported: GmailForwardCmd has only a From field, and gmail_forward.go:61 resolves the sender directly from c.From before fetching the original message. Consequently forwards still use the default identity rather than the verified alias to which the original was addressed; add the equivalent flag and alias-selection path to GmailForwardCmd, or remove forward from the promised scope.

Useful? React with 👍 / 👎.

Signature bool `name:"signature" help:"Append the Gmail signature from the active send-as address"`
SignatureFrom string `name:"signature-from" help:"Append the Gmail signature from this send-as email address"`
SignatureFile string `name:"signature-file" help:"Append a local signature file (plain text or HTML)"`
Expand Down