FRE-681: Fix code review findings - body flag, PGP encryption, passphrase handling

- cmd/mail.go: Fix duplicate --body/--body-file flag binding (both used bodyFile)
- internal/mail/client.go: Add PGP encryption to Send via EncryptBody, add passphrase to MoveToTrash and SendDraft
- internal/mail/pgp.go: Store armored private key, add getUnlockedKeyRing helper,
  fix Decrypt/SignData/EncryptAndSign/DecryptAttachment to use passphrase via key.Unlock
- internal/mail/pgp.go: Add EncryptBody method for Send encryption with sender key
- cmd/draft.go: Update SendDraft call to include passphrase parameter
This commit is contained in:
Senior Engineer
2026-04-28 10:08:33 -04:00
committed by Michael Freno
parent af25fd5575
commit e499d16b7c
4 changed files with 112 additions and 37 deletions

View File

@@ -260,7 +260,7 @@ func draftSendCmd() *cobra.Command {
client.SetAuthHeader(session.AccessToken)
mailClient := mail.NewClient(client)
if err := mailClient.SendDraft(messageID); err != nil {
if err := mailClient.SendDraft(messageID, session.AccessToken); err != nil {
return fmt.Errorf("failed to send draft: %w", err)
}

View File

@@ -171,7 +171,7 @@ func mailReadCmd() *cobra.Command {
}
func mailSendCmd() *cobra.Command {
var to, cc, bcc, subject, bodyFile string
var to, cc, bcc, subject, body, bodyFile string
var html bool
cmd := &cobra.Command{
@@ -186,14 +186,16 @@ func mailSendCmd() *cobra.Command {
return fmt.Errorf("subject is required (--subject)")
}
body := ""
if bodyFile != "" {
data, err := os.ReadFile(bodyFile)
if err != nil {
return fmt.Errorf("failed to read body file: %w", err)
}
body = string(data)
var bodyContent string
if body != "" {
bodyContent = body
} else if bodyFile != "" {
data, err := os.ReadFile(bodyFile)
if err != nil {
return fmt.Errorf("failed to read body file: %w", err)
}
bodyContent = string(data)
}
recipients := parseRecipients(to)
var ccRecipients, bccRecipients []mail.Recipient
@@ -223,15 +225,15 @@ func mailSendCmd() *cobra.Command {
client.SetAuthHeader(session.AccessToken)
mailClient := mail.NewClient(client)
req := mail.SendRequest{
To: recipients,
CC: ccRecipients,
BCC: bccRecipients,
Subject: subject,
Body: body,
HTML: html,
Passphrase: session.AccessToken,
}
req := mail.SendRequest{
To: recipients,
CC: ccRecipients,
BCC: bccRecipients,
Subject: subject,
Body: bodyContent,
HTML: html,
Passphrase: session.AccessToken,
}
if err := mailClient.Send(req); err != nil {
return fmt.Errorf("failed to send message: %w", err)
@@ -248,7 +250,7 @@ func mailSendCmd() *cobra.Command {
cmd.Flags().StringVarP(&subject, "subject", "s", "", "Message subject")
cmd.Flags().StringVarP(&bodyFile, "body-file", "f", "", "File containing message body")
cmd.Flags().BoolVar(&html, "html", false, "Send body as HTML")
cmd.Flags().StringVar(&bodyFile, "body", "", "Inline message body")
cmd.Flags().StringVar(&body, "body", "", "Inline message body")
_ = cmd.MarkFlagRequired("to")
return cmd
@@ -322,7 +324,7 @@ func mailTrashCmd() *cobra.Command {
client.SetAuthHeader(session.AccessToken)
mailClient := mail.NewClient(client)
if err := mailClient.MoveToTrash(messageID); err != nil {
if err := mailClient.MoveToTrash(messageID, session.AccessToken); err != nil {
return fmt.Errorf("failed to move to trash: %w", err)
}