Other(debug): Dump raw SMTP input to user's home dir

This commit is contained in:
James Houlahan
2023-01-19 13:30:28 +01:00
parent c70674471e
commit 59a29da054
3 changed files with 23 additions and 6 deletions

View File

@ -67,7 +67,9 @@ func (user *User) sendMail(authID string, from string, to []string, r io.Reader)
} }
// If running a QA build, dump to disk. // If running a QA build, dump to disk.
debugDumpToDisk(b) if err := debugDumpToDisk(b); err != nil {
user.log.WithError(err).Warn("Failed to dump message to disk")
}
// Compute the hash of the message (to match it against SMTP messages). // Compute the hash of the message (to match it against SMTP messages).
hash, err := getMessageHash(b) hash, err := getMessageHash(b)

View File

@ -20,16 +20,29 @@
package user package user
import ( import (
"fmt"
"os" "os"
"path/filepath"
"time" "time"
) )
func debugDumpToDisk(b []byte) { func debugDumpToDisk(b []byte) error {
if os.Getenv("BRIDGE_SMTP_DEBUG") == "" { if os.Getenv("BRIDGE_SMTP_DEBUG") == "" {
return return nil
} }
if err := os.WriteFile(time.Now().Format(time.RFC3339Nano)+"_smtp_debug.eml", b, 0600); err != nil { home, err := os.UserHomeDir()
panic(err) if err != nil {
return fmt.Errorf("failed to get user home dir: %w", err)
} }
if err := os.WriteFile(filepath.Join(home, getFileName()), b, 0600); err != nil {
return fmt.Errorf("failed to write message file: %w", err)
}
return nil
}
func getFileName() string {
return time.Now().Format(time.RFC3339Nano) + "_smtp_debug.eml"
} }

View File

@ -19,4 +19,6 @@
package user package user
func debugDumpToDisk(b []byte) {} func debugDumpToDisk(b []byte) error {
return nil
}