Other(debug): Dump raw SMTP input to user's home dir
This commit is contained in:
parent
c70674471e
commit
59a29da054
|
@ -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.
|
||||
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).
|
||||
hash, err := getMessageHash(b)
|
||||
|
|
|
@ -20,16 +20,29 @@
|
|||
package user
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"time"
|
||||
)
|
||||
|
||||
func debugDumpToDisk(b []byte) {
|
||||
func debugDumpToDisk(b []byte) error {
|
||||
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 {
|
||||
panic(err)
|
||||
home, err := os.UserHomeDir()
|
||||
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"
|
||||
}
|
||||
|
|
|
@ -19,4 +19,6 @@
|
|||
|
||||
package user
|
||||
|
||||
func debugDumpToDisk(b []byte) {}
|
||||
func debugDumpToDisk(b []byte) error {
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue