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:
40
cmd/mail.go
40
cmd/mail.go
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user