diff options
| author | Shulhan <ms@kilabit.info> | 2023-09-13 22:05:30 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2023-09-13 23:17:40 +0700 |
| commit | 435bb123ad81c9f38791df6c03006e6ddbcbc70d (patch) | |
| tree | ba94bec40c92ed3cf4ee3fa7eb61bf939b4fa712 /lib/smtp/mail_tx_example_test.go | |
| parent | def105e93b21c3acd8e746dde1e43f69059b02ed (diff) | |
| download | pakakeh.go-435bb123ad81c9f38791df6c03006e6ddbcbc70d.tar.xz | |
lib/ascii: replace package "math/rand" with "crypto/rand"
Since Go 1.20 the "math/rand.Seed" is considered deprecated (the initial
value of rand is seeded automatically, not zero).
Now, it is the time to replace "math/rand" with more secure random number
generator, from "crypto/rand".
This changes affect tests in package "lib/email", "lib/http", and
"lib/stmp".
Diffstat (limited to 'lib/smtp/mail_tx_example_test.go')
| -rw-r--r-- | lib/smtp/mail_tx_example_test.go | 30 |
1 files changed, 16 insertions, 14 deletions
diff --git a/lib/smtp/mail_tx_example_test.go b/lib/smtp/mail_tx_example_test.go index e5207bc0..d240b53d 100644 --- a/lib/smtp/mail_tx_example_test.go +++ b/lib/smtp/mail_tx_example_test.go @@ -8,7 +8,6 @@ import ( "bytes" "fmt" "log" - "os" "regexp" "time" @@ -40,8 +39,6 @@ func ExampleNewMailTx() { mboxes []*email.Mailbox msg *email.Message mailtx *smtp.MailTx - reDate *regexp.Regexp - hostname string data []byte err error ) @@ -76,21 +73,26 @@ func ExampleNewMailTx() { fmt.Printf("Tx Recipients: %s\n", mailtx.Recipients) // In order to make the example Output works, we need to replace all - // CRLF with LF, "date:" with the system timezone, and message-id - // hostname with fixed "hostname". - data = bytes.ReplaceAll(mailtx.Data, []byte("\r\n"), []byte("\n")) + // CRLF with LF, "date:" with the system timezone, and message-id. - //fmt.Printf("timeNowUtc: %s\n", timeNowUtc) - //fmt.Printf("dateNowUtc: %s\n", dateNowUtc) + data = bytes.ReplaceAll(mailtx.Data, []byte("\r\n"), []byte("\n")) - reDate = regexp.MustCompile(`^date: Wed(.*) \+....`) + var ( + reDate = regexp.MustCompile(`^date: Wed(.*) \+....`) + ) data = reDate.ReplaceAll(data, []byte(`date: `+dateNowUtc)) - hostname, err = os.Hostname() - if err != nil { - log.Fatal(err) - } - data = bytes.Replace(data, []byte(hostname), []byte("hostname"), 1) + var ( + msgID = msg.Header.ID() + fixedID = `1645600000.QoqDPQfz@hostname` + ) + data = bytes.Replace(data, []byte(msgID), []byte(fixedID), 1) + + var ( + msgBoundary = msg.Header.Boundary() + fixedBoundary = `QoqDPQfzDVkv5R49vrA78GmqPmlfmBHf` + ) + data = bytes.ReplaceAll(data, []byte(msgBoundary), []byte(fixedBoundary)) fmt.Printf("Tx Data:\n%s", data) //Output: |
